-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
73 lines (60 loc) · 1.45 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (c) 2022 Lucas Dietrich <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <avrtos/avrtos.h>
#include <avrtos/debug.h>
#include <avrtos/drivers/gpio.h>
#include <avrtos/drivers/usart.h>
#include <avrtos/logging.h>
#include <avrtos/misc/led.h>
#define LOG_LEVEL LOG_LEVEL_DBG
K_MSGQ_DEFINE(usart_msgq, 1u, 16u);
static void thread_usart(void *arg);
static void thread_led(void *arg);
K_THREAD_DEFINE(th_usart, thread_usart, 164u, K_COOPERATIVE, NULL, 'X');
K_THREAD_DEFINE(th_led, thread_led, 164u, K_COOPERATIVE, NULL, 'L');
ISR(USART0_RX_vect)
{
const char c = USART0_DEVICE->UDRn;
k_msgq_put(&usart_msgq, &c, K_NO_WAIT);
}
int main(void)
{
const struct usart_config usart_config = {
.baudrate = USART_BAUD_115200,
.receiver = 1u,
.transmitter = 1u,
.mode = USART_MODE_ASYNCHRONOUS,
.parity = USART_PARITY_NONE,
.stopbits = USART_STOP_BITS_1,
.databits = USART_DATA_BITS_8,
.speed_mode = USART_SPEED_MODE_NORMAL,
};
ll_usart_init(USART0_DEVICE, &usart_config);
ll_usart_enable_rx_isr(USART0_DEVICE);
led_init();
LOG_INF("Application started");
k_thread_dump_all();
k_stop();
}
static void thread_usart(void *arg)
{
char c;
for (;;) {
if (k_msgq_get(&usart_msgq, &c, K_FOREVER) >= 0) {
k_show_uptime();
LOG_INF("<inf> Received: %c", c);
}
}
}
static void thread_led(void *arg)
{
for (;;) {
k_show_uptime();
led_toggle();
LOG_DBG("<dbg> toggled LED");
k_sleep(K_MSEC(500u));
}
}