Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_uart.h
1 #ifndef _BC_UART_H
2 #define _BC_UART_H
3 
4 #include <bc_tick.h>
5 #include <bc_fifo.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
23 
25 
27 
28 typedef enum
29 {
32 
35 
38 
41 
44 
47 
49 
51 
53 
54 #define _BC_UART_SETTING_DATA_BITS_7 0x07 << 4
55 #define _BC_UART_SETTING_DATA_BITS_8 0x08 << 4
56 
57 #define _BC_UART_SETTING_PARITY_NONE 0x00 << 2
58 #define _BC_UART_SETTING_PARITY_EVEN 0x02 << 2
59 #define _BC_UART_SETTING_PARITY_ODD 0x03 << 2
60 
61 #define _BC_UART_SETTING_STOP_BIT_1 0x00
62 #define _BC_UART_SETTING_STOP_BIT_2 0x02
63 #define _BC_UART_SETTING_STOP_BIT_15 0x03
64 
66 
67 typedef enum
68 {
70  BC_UART_SETTING_8N1 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_1,
71 
73  BC_UART_SETTING_8E1 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_EVEN | _BC_UART_SETTING_STOP_BIT_1,
74 
76  BC_UART_SETTING_8O1 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_ODD | _BC_UART_SETTING_STOP_BIT_1,
77 
79  BC_UART_SETTING_8N2 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_2,
80 
82  BC_UART_SETTING_8E2 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_EVEN | _BC_UART_SETTING_STOP_BIT_2,
83 
85  BC_UART_SETTING_8O2 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_2,
86 
88  BC_UART_SETTING_8N1_5 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_15,
89 
91  BC_UART_SETTING_8E1_5 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_EVEN | _BC_UART_SETTING_STOP_BIT_15,
92 
94  BC_UART_SETTING_8O1_5 = _BC_UART_SETTING_DATA_BITS_8 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_15,
95 
97  BC_UART_SETTING_7N1 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_1,
98 
100  BC_UART_SETTING_7E1 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_EVEN | _BC_UART_SETTING_STOP_BIT_1,
101 
103  BC_UART_SETTING_7O1 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_ODD | _BC_UART_SETTING_STOP_BIT_1,
104 
106  BC_UART_SETTING_7N2 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_2,
107 
109  BC_UART_SETTING_7E2 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_EVEN | _BC_UART_SETTING_STOP_BIT_2,
110 
112  BC_UART_SETTING_7O2 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_2,
113 
115  BC_UART_SETTING_7N1_5 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_15,
116 
118  BC_UART_SETTING_7E1_5 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_EVEN | _BC_UART_SETTING_STOP_BIT_15,
119 
121  BC_UART_SETTING_7O1_5 = _BC_UART_SETTING_DATA_BITS_7 | _BC_UART_SETTING_PARITY_NONE | _BC_UART_SETTING_STOP_BIT_15
122 
124 
126 
127 typedef enum
128 {
131 
134 
137 
139 
143 
144 void bc_uart_init(bc_uart_channel_t channel, bc_uart_baudrate_t baudrate, bc_uart_setting_t setting);
145 
148 
149 void bc_uart_deinit(bc_uart_channel_t channel);
150 
156 
157 size_t bc_uart_write(bc_uart_channel_t channel, const void *buffer, size_t length);
158 
165 
166 size_t bc_uart_read(bc_uart_channel_t channel, void *buffer, size_t length, bc_tick_t timeout);
167 
172 
173 void bc_uart_set_event_handler(bc_uart_channel_t channel, void (*event_handler)(bc_uart_channel_t, bc_uart_event_t, void *), void *event_param);
174 
179 
180 void bc_uart_set_async_fifo(bc_uart_channel_t channel, bc_fifo_t *write_fifo, bc_fifo_t *read_fifo);
181 
187 
188 size_t bc_uart_async_write(bc_uart_channel_t channel, const void *buffer, size_t length);
189 
195 
197 
202 
204 
210 
211 size_t bc_uart_async_read(bc_uart_channel_t channel, void *buffer, size_t length);
212 
214 
215 #endif // _BC_UART_H
UART channel UART2.
Definition: bc_uart.h:22
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
bc_uart_channel_t
UART channels.
Definition: bc_uart.h:13
Event is writting done.
Definition: bc_uart.h:130
UART baudrat 19200 bps.
Definition: bc_uart.h:34
8E1_5: 8 data bits, even parity bit, 1.5 stop bit
Definition: bc_uart.h:91
Structure of FIFO instance.
Definition: bc_fifo.h:12
8E1: 8 data bits, even parity bit, 1 stop bit
Definition: bc_uart.h:73
7E1_5: 7 data bits, even parity bit, 1.5 stop bit
Definition: bc_uart.h:118
bc_uart_setting_t
UART setting.
Definition: bc_uart.h:67
7N1_5: 7 data bits, none parity bit, 1.5 stop bits
Definition: bc_uart.h:115
8O1: 8 data bits, odd parity bit, 1 stop bit
Definition: bc_uart.h:76
bool bc_uart_async_read_start(bc_uart_channel_t channel, bc_tick_t timeout)
Start async reading.
Definition: bc_uart.c:475
Event is reading done.
Definition: bc_uart.h:133
Event is timeout.
Definition: bc_uart.h:136
8N1: 8 data bits, none parity bit, 1 stop bit
Definition: bc_uart.h:70
UART channel UART0.
Definition: bc_uart.h:16
8N1_5: 8 data bits, none parity bit, 1.5 stop bits
Definition: bc_uart.h:88
void bc_uart_init(bc_uart_channel_t channel, bc_uart_baudrate_t baudrate, bc_uart_setting_t setting)
Initialize UART channel.
Definition: bc_uart.c:53
bc_uart_event_t
Callback events.
Definition: bc_uart.h:127
UART channel UART1.
Definition: bc_uart.h:19
size_t bc_uart_read(bc_uart_channel_t channel, void *buffer, size_t length, bc_tick_t timeout)
Read data from UART channel (blocking call)
Definition: bc_uart.c:372
void bc_uart_deinit(bc_uart_channel_t channel)
Deinitialize UART channel.
Definition: bc_uart.c:248
8O2: 8 data bits, odd parity bit, 2 stop bit
Definition: bc_uart.h:85
7O1: 7 data bits, odd parity bit, 1 stop bit
Definition: bc_uart.h:103
8O1_5: 8 data bits, odd parity bit, 1.5 stop bit
Definition: bc_uart.h:94
bool bc_uart_async_read_cancel(bc_uart_channel_t channel)
Cancel async reading.
Definition: bc_uart.c:531
8N2: 8 data bits, none parity bit, 2 stop bits
Definition: bc_uart.h:79
size_t bc_uart_async_write(bc_uart_channel_t channel, const void *buffer, size_t length)
Add data to be transmited in async mode.
Definition: bc_uart.c:428
void bc_uart_set_async_fifo(bc_uart_channel_t channel, bc_fifo_t *write_fifo, bc_fifo_t *read_fifo)
Set buffers for async transfers.
Definition: bc_uart.c:422
void bc_uart_set_event_handler(bc_uart_channel_t channel, void(*event_handler)(bc_uart_channel_t, bc_uart_event_t, void *), void *event_param)
Set callback function.
Definition: bc_uart.c:416
UART baudrat 9600 bps.
Definition: bc_uart.h:31
7O2: 7 data bits, odd parity bit, 2 stop bit
Definition: bc_uart.h:112
7O1_5: 7 data bits, odd parity bit, 1.5 stop bit
Definition: bc_uart.h:121
UART baudrat 38400 bps.
Definition: bc_uart.h:37
size_t bc_uart_write(bc_uart_channel_t channel, const void *buffer, size_t length)
Write data to UART channel (blocking call)
Definition: bc_uart.c:330
bc_uart_baudrate_t
UART baudrate.
Definition: bc_uart.h:28
7N2: 7 data bits, none parity bit, 2 stop bits
Definition: bc_uart.h:106
size_t bc_uart_async_read(bc_uart_channel_t channel, void *buffer, size_t length)
Get data that has been received in async mode.
Definition: bc_uart.c:571
UART baudrat 57600 bps.
Definition: bc_uart.h:40
7E2: 7 data bits, even parity bit, 2 stop bit
Definition: bc_uart.h:109
UART baudrat 921600 bps.
Definition: bc_uart.h:46
8E2: 8 data bits, even parity bit, 2 stop bit
Definition: bc_uart.h:82
UART baudrat 115200 bps.
Definition: bc_uart.h:43
7N1: 7 data bits, none parity bit, 1 stop bit
Definition: bc_uart.h:97
7E1: 7 data bits, even parity bit, 1 stop bit
Definition: bc_uart.h:100