no-OS
no_os_uart.h
Go to the documentation of this file.
1 /***************************************************************************/
39 #ifndef _NO_OS_UART_H_
40 #define _NO_OS_UART_H_
41 
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 
46 #include <stdint.h>
47 #include <stdbool.h>
48 #include "no_os_lf256fifo.h"
49 
50 /******************************************************************************/
51 /********************** Macros and Constants Definitions **********************/
52 /******************************************************************************/
53 
54 #define UART_MAX_NUMBER 10
55 
56 /******************************************************************************/
57 /*************************** Types Declarations *******************************/
58 /******************************************************************************/
59 
75 };
76 
92 };
93 
103 };
104 
111 
118  uint8_t device_id;
120  uint32_t irq_id;
124  uint32_t baud_rate;
133  void *extra;
134 };
135 
142  void *mutex;
144  uint8_t device_id;
146  uint32_t irq_id;
148  struct lf256fifo *rx_fifo;
150  uint32_t baud_rate;
153  void *extra;
154 };
155 
163  int32_t (*init)(struct no_os_uart_desc **, struct no_os_uart_init_param *);
165  int32_t (*read)(struct no_os_uart_desc *, uint8_t *, uint32_t);
167  int32_t (*write)(struct no_os_uart_desc *, const uint8_t *, uint32_t);
169  int32_t (*read_nonblocking)(struct no_os_uart_desc *, uint8_t *, uint32_t);
171  int32_t (*write_nonblocking)(struct no_os_uart_desc *, const uint8_t *,
172  uint32_t);
174  int32_t (*remove)(struct no_os_uart_desc *);
176  uint32_t (*get_errors)(struct no_os_uart_desc *);
177 };
178 
179 /******************************************************************************/
180 /************************ Functions Declarations ******************************/
181 /******************************************************************************/
182 
183 /* Read data from UART. Blocking function */
184 int32_t no_os_uart_read(struct no_os_uart_desc *desc, uint8_t *data,
185  uint32_t bytes_number);
186 
187 /* Write data to UART. Blocking function */
188 int32_t no_os_uart_write(struct no_os_uart_desc *desc, const uint8_t *data,
189  uint32_t bytes_number);
190 
191 /* Read data from UART. Non blocking function */
192 int32_t no_os_uart_read_nonblocking(struct no_os_uart_desc *desc, uint8_t *data,
193  uint32_t bytes_number);
194 
195 /* Write data to UART. Non blocking function*/
196 int32_t no_os_uart_write_nonblocking(struct no_os_uart_desc *desc,
197  const uint8_t *data,
198  uint32_t bytes_number);
199 
200 /* Initialize the UART communication peripheral. */
201 int32_t no_os_uart_init(struct no_os_uart_desc **desc,
202  struct no_os_uart_init_param *param);
203 
204 /* Free the resources allocated by no_os_uart_init(). */
205 int32_t no_os_uart_remove(struct no_os_uart_desc *desc);
206 
207 /* Check if UART errors occurred. */
208 uint32_t no_os_uart_get_errors(struct no_os_uart_desc *desc);
209 
210 /* Make stdio to use this UART. */
211 void no_os_uart_stdio(struct no_os_uart_desc *desc);
212 
213 #endif // _NO_OS_UART_H_
no_os_uart_desc::platform_ops
const struct no_os_uart_platform_ops * platform_ops
Definition: no_os_uart.h:151
no_os_uart_init_param::parity
enum no_os_uart_parity parity
Definition: no_os_uart.h:128
no_os_uart_platform_ops
Structure holding UART function pointers that point to the platform specific function.
Definition: no_os_uart.h:161
no_os_uart_write
int32_t no_os_uart_write(struct no_os_uart_desc *desc, const uint8_t *data, uint32_t bytes_number)
Write to UART.
Definition: no_os_uart.c:150
no_os_uart_init_param::extra
void * extra
Definition: no_os_uart.h:133
no_os_uart_stdio
void no_os_uart_stdio(struct no_os_uart_desc *desc)
Definition: no_os_uart.c:222
NO_OS_UART_STOP_1_BIT
@ NO_OS_UART_STOP_1_BIT
Definition: no_os_uart.h:100
no_os_uart_desc::mutex
void * mutex
Definition: no_os_uart.h:142
no_os_uart_init_param::size
enum no_os_uart_size size
Definition: no_os_uart.h:126
no_os_uart_platform_ops::remove
int32_t(* remove)(struct no_os_uart_desc *)
Definition: no_os_uart.h:174
no_os_uart_read
int32_t no_os_uart_read(struct no_os_uart_desc *desc, uint8_t *data, uint32_t bytes_number)
Read data from UART.
Definition: no_os_uart.c:124
no_os_uart_platform_ops::init
int32_t(* init)(struct no_os_uart_desc **, struct no_os_uart_init_param *)
Definition: no_os_uart.h:163
no_os_uart_desc::baud_rate
uint32_t baud_rate
Definition: no_os_uart.h:150
NO_OS_UART_CS_5
@ NO_OS_UART_CS_5
Definition: no_os_uart.h:66
no_os_uart_size
no_os_uart_size
UART character size (number of data bits) options.
Definition: no_os_uart.h:64
no_os_uart_init_param::irq_id
uint32_t irq_id
Definition: no_os_uart.h:120
no_os_uart_platform_ops::get_errors
uint32_t(* get_errors)(struct no_os_uart_desc *)
Definition: no_os_uart.h:176
no_os_uart_desc::device_id
uint8_t device_id
Definition: no_os_uart.h:144
no_os_uart_parity
no_os_uart_parity
UART parity options.
Definition: no_os_uart.h:81
no_os_uart_remove
int32_t no_os_uart_remove(struct no_os_uart_desc *desc)
Free the resources allocated by no_os_uart_init().
Definition: no_os_uart.c:87
no_os_uart_get_errors
uint32_t no_os_uart_get_errors(struct no_os_uart_desc *desc)
Check if errors occurred on UART.
Definition: no_os_uart.c:106
no_os_uart_desc
Stucture holding the UART descriptor.
Definition: no_os_uart.h:140
no_os_uart_init_param::asynchronous_rx
bool asynchronous_rx
Definition: no_os_uart.h:122
no_os_uart_platform_ops::write
int32_t(* write)(struct no_os_uart_desc *, const uint8_t *, uint32_t)
Definition: no_os_uart.h:167
no_os_uart_desc::extra
void * extra
Definition: no_os_uart.h:153
NO_OS_UART_STOP_2_BIT
@ NO_OS_UART_STOP_2_BIT
Definition: no_os_uart.h:102
no_os_uart_desc::rx_fifo
struct lf256fifo * rx_fifo
Definition: no_os_uart.h:148
NO_OS_UART_PAR_SPACE
@ NO_OS_UART_PAR_SPACE
Definition: no_os_uart.h:87
no_os_uart_init_param::baud_rate
uint32_t baud_rate
Definition: no_os_uart.h:124
no_os_uart_init_param::stop
enum no_os_uart_stop stop
Definition: no_os_uart.h:130
NO_OS_UART_CS_9
@ NO_OS_UART_CS_9
Definition: no_os_uart.h:74
NO_OS_UART_PAR_EVEN
@ NO_OS_UART_PAR_EVEN
Definition: no_os_uart.h:91
no_os_lf256fifo.h
SPSC lock-free fifo of fixed size (256), specialized for UART.
no_os_uart_platform_ops::read_nonblocking
int32_t(* read_nonblocking)(struct no_os_uart_desc *, uint8_t *, uint32_t)
Definition: no_os_uart.h:169
no_os_uart_read_nonblocking
int32_t no_os_uart_read_nonblocking(struct no_os_uart_desc *desc, uint8_t *data, uint32_t bytes_number)
Read data from UART non-blocking.
Definition: no_os_uart.c:176
no_os_uart_desc::irq_id
uint32_t irq_id
Definition: no_os_uart.h:146
NO_OS_UART_CS_7
@ NO_OS_UART_CS_7
Definition: no_os_uart.h:70
no_os_uart_init_param::platform_ops
const struct no_os_uart_platform_ops * platform_ops
Definition: no_os_uart.h:131
NO_OS_UART_CS_6
@ NO_OS_UART_CS_6
Definition: no_os_uart.h:68
no_os_uart_init
int32_t no_os_uart_init(struct no_os_uart_desc **desc, struct no_os_uart_init_param *param)
Initialize the UART communication peripheral.
Definition: no_os_uart.c:58
no_os_uart_init_param
Structure holding the parameters for UART initialization.
Definition: no_os_uart.h:116
NO_OS_UART_PAR_NO
@ NO_OS_UART_PAR_NO
Definition: no_os_uart.h:83
no_os_uart_stop
no_os_uart_stop
UART number of stop bits options.
Definition: no_os_uart.h:98
no_os_uart_init_param::device_id
uint8_t device_id
Definition: no_os_uart.h:118
no_os_uart_platform_ops::write_nonblocking
int32_t(* write_nonblocking)(struct no_os_uart_desc *, const uint8_t *, uint32_t)
Definition: no_os_uart.h:171
NO_OS_UART_PAR_MARK
@ NO_OS_UART_PAR_MARK
Definition: no_os_uart.h:85
NO_OS_UART_PAR_ODD
@ NO_OS_UART_PAR_ODD
Definition: no_os_uart.h:89
no_os_uart_write_nonblocking
int32_t no_os_uart_write_nonblocking(struct no_os_uart_desc *desc, const uint8_t *data, uint32_t bytes_number)
Write to UART non-blocking.
Definition: no_os_uart.c:202
NO_OS_UART_CS_8
@ NO_OS_UART_CS_8
Definition: no_os_uart.h:72
no_os_uart_platform_ops::read
int32_t(* read)(struct no_os_uart_desc *, uint8_t *, uint32_t)
Definition: no_os_uart.h:165