no-OS
uart.h
Go to the documentation of this file.
1 /***************************************************************************/
39 #ifndef UART_H_
40 #define UART_H_
41 
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 
46 #include <stdint.h>
47 
48 /******************************************************************************/
49 /*************************** Types Declarations *******************************/
50 /******************************************************************************/
51 
56 enum uart_size {
67 };
68 
84 };
85 
90 enum uart_stop {
95 };
96 
103  uint8_t device_id;
105  uint32_t baud_rate;
113  void *extra;
114 };
115 
120 struct uart_desc {
122  uint8_t device_id;
124  uint32_t baud_rate;
126  void (*callback)(void *callback_ctx, uint32_t event,
127  void *extra);
131  void *extra;
132 };
133 
134 /******************************************************************************/
135 /************************ Functions Declarations ******************************/
136 /******************************************************************************/
137 
138 /* Read data from UART. Blocking function */
139 int32_t uart_read(struct uart_desc *desc, uint8_t *data, uint32_t bytes_number);
140 
141 /* Write data to UART. Blocking function */
142 int32_t uart_write(struct uart_desc *desc, const uint8_t *data,
143  uint32_t bytes_number);
144 
145 /* Read data from UART. Non blocking function */
146 int32_t uart_read_nonblocking(struct uart_desc *desc, uint8_t *data,
147  uint32_t bytes_number);
148 
149 /* Write data to UART. Non blocking function*/
150 int32_t uart_write_nonblocking(struct uart_desc *desc, const uint8_t *data,
151  uint32_t bytes_number);
152 
153 /* Initialize the UART communication peripheral. */
154 int32_t uart_init(struct uart_desc **desc, struct uart_init_param *param);
155 
156 /* Free the resources allocated by uart_init(). */
157 int32_t uart_remove(struct uart_desc *desc);
158 
159 /* Check if UART errors occurred. */
160 uint32_t uart_get_errors(struct uart_desc *desc);
161 
162 #endif /* UART_H_ */
uart_init_param::parity
enum uart_parity parity
Definition: uart.h:109
uart_write_nonblocking
int32_t uart_write_nonblocking(struct uart_desc *desc, const uint8_t *data, uint32_t bytes_number)
Submit writting buffer to the UART driver.
Definition: uart.c:402
uart_remove
int32_t uart_remove(struct uart_desc *desc)
Free the resources allocated by uart_init()
Definition: uart.c:509
uart_init_param::extra
void * extra
Definition: uart.h:113
UART_PAR_MARK
@ UART_PAR_MARK
Definition: uart.h:77
UART_CS_8
@ UART_CS_8
Definition: uart.h:64
uart_get_errors
uint32_t uart_get_errors(struct uart_desc *desc)
Free the resources allocated by uart_init()
Definition: uart.c:530
uart_init_param::device_id
uint8_t device_id
Definition: uart.h:103
UART_PAR_NO
@ UART_PAR_NO
Definition: uart.h:75
uart_desc::extra
void * extra
Definition: uart.h:131
uart_init_param::stop
enum uart_stop stop
Definition: uart.h:111
uart_init_param::size
enum uart_size size
Definition: uart.h:107
UART_STOP_2
@ UART_STOP_2
Definition: uart.h:94
UART_STOP_1
@ UART_STOP_1
Definition: uart.h:92
uart_init
int32_t uart_init(struct uart_desc **desc, struct uart_init_param *param)
Initialize the UART communication peripheral.
Definition: uart.c:441
uart_size
uart_size
UART character size (number of data bits) options.
Definition: uart.h:56
UART_PAR_ODD
@ UART_PAR_ODD
Definition: uart.h:81
uart_desc::baud_rate
uint32_t baud_rate
Definition: uart.h:124
uart_desc::callback
void(* callback)(void *callback_ctx, uint32_t event, void *extra)
Definition: uart.h:126
UART_CS_6
@ UART_CS_6
Definition: uart.h:60
UART_CS_9
@ UART_CS_9
Definition: uart.h:66
UART_CS_7
@ UART_CS_7
Definition: uart.h:62
uart_read
int32_t uart_read(struct uart_desc *desc, uint8_t *data, uint32_t bytes_number)
Read data from UART. Blocking function.
Definition: uart.c:271
uart_desc
Stucture holding the UART descriptor.
Definition: uart.h:120
UART_CS_5
@ UART_CS_5
Definition: uart.h:58
uart_stop
uart_stop
UART number of stop bits options.
Definition: uart.h:90
uart_read_nonblocking
int32_t uart_read_nonblocking(struct uart_desc *desc, uint8_t *data, uint32_t bytes_number)
Submit reading buffer to the UART driver.
Definition: uart.c:365
uart_init_param
Structure holding the parameters for UART initialization.
Definition: uart.h:101
uart_init_param::baud_rate
uint32_t baud_rate
Definition: uart.h:105
uart_desc::device_id
uint8_t device_id
Definition: uart.h:122
uart_write
int32_t uart_write(struct uart_desc *desc, const uint8_t *data, uint32_t bytes_number)
Write data to UART. Blocking function.
Definition: uart.c:318
UART_PAR_EVEN
@ UART_PAR_EVEN
Definition: uart.h:83
uart_parity
uart_parity
UART parity options.
Definition: uart.h:73
UART_PAR_SPACE
@ UART_PAR_SPACE
Definition: uart.h:79
uart_desc::callback_ctx
void * callback_ctx
Definition: uart.h:129