no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
no_os_uart.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef _NO_OS_UART_H_
34#define _NO_OS_UART_H_
35
36#include <stdint.h>
37#include <stdbool.h>
38#include "no_os_lf256fifo.h"
39
40#define UART_MAX_NUMBER 10
41
58
75
86
93
117
124 void *mutex;
126 uint8_t device_id;
128 uint32_t irq_id;
130 struct lf256fifo *rx_fifo;
132 uint32_t baud_rate;
135 void *extra;
136};
137
145 int32_t (*init)(struct no_os_uart_desc **, struct no_os_uart_init_param *);
147 int32_t (*read)(struct no_os_uart_desc *, uint8_t *, uint32_t);
149 int32_t (*write)(struct no_os_uart_desc *, const uint8_t *, uint32_t);
151 int32_t (*read_nonblocking)(struct no_os_uart_desc *, uint8_t *, uint32_t);
153 int32_t (*write_nonblocking)(struct no_os_uart_desc *, const uint8_t *,
154 uint32_t);
156 int32_t (*remove)(struct no_os_uart_desc *);
158 uint32_t (*get_errors)(struct no_os_uart_desc *);
159};
160
161/* Read data from UART. Blocking function */
162int32_t no_os_uart_read(struct no_os_uart_desc *desc, uint8_t *data,
163 uint32_t bytes_number);
164
165/* Write data to UART. Blocking function */
166int32_t no_os_uart_write(struct no_os_uart_desc *desc, const uint8_t *data,
167 uint32_t bytes_number);
168
169/* Read data from UART. Non blocking function */
170int32_t no_os_uart_read_nonblocking(struct no_os_uart_desc *desc, uint8_t *data,
171 uint32_t bytes_number);
172
173/* Write data to UART. Non blocking function*/
175 const uint8_t *data,
176 uint32_t bytes_number);
177
178/* Initialize the UART communication peripheral. */
179int32_t no_os_uart_init(struct no_os_uart_desc **desc,
180 struct no_os_uart_init_param *param);
181
182/* Free the resources allocated by no_os_uart_init(). */
183int32_t no_os_uart_remove(struct no_os_uart_desc *desc);
184
185/* Check if UART errors occurred. */
186uint32_t no_os_uart_get_errors(struct no_os_uart_desc *desc);
187
188/* Make stdio to use this UART. */
189void no_os_uart_stdio(struct no_os_uart_desc *desc);
190
191#endif // _NO_OS_UART_H_
SPSC lock-free fifo of fixed size (256), specialized for UART.
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:52
no_os_uart_size
UART character size (number of data bits) options.
Definition no_os_uart.h:46
@ NO_OS_UART_CS_9
Definition no_os_uart.h:56
@ NO_OS_UART_CS_6
Definition no_os_uart.h:50
@ NO_OS_UART_CS_7
Definition no_os_uart.h:52
@ NO_OS_UART_CS_5
Definition no_os_uart.h:48
@ NO_OS_UART_CS_8
Definition no_os_uart.h:54
no_os_uart_parity
UART parity options.
Definition no_os_uart.h:63
@ NO_OS_UART_PAR_MARK
Definition no_os_uart.h:67
@ NO_OS_UART_PAR_EVEN
Definition no_os_uart.h:73
@ NO_OS_UART_PAR_ODD
Definition no_os_uart.h:71
@ NO_OS_UART_PAR_NO
Definition no_os_uart.h:65
@ NO_OS_UART_PAR_SPACE
Definition no_os_uart.h:69
uint32_t no_os_uart_get_errors(struct no_os_uart_desc *desc)
Check if errors occurred on UART.
Definition no_os_uart.c:100
no_os_uart_stop
UART number of stop bits options.
Definition no_os_uart.h:80
@ NO_OS_UART_STOP_2_BIT
Definition no_os_uart.h:84
@ NO_OS_UART_STOP_1_BIT
Definition no_os_uart.h:82
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:81
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:144
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:196
void no_os_uart_stdio(struct no_os_uart_desc *desc)
Definition no_os_uart.c:216
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:118
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:170
Stucture holding the UART descriptor.
Definition no_os_uart.h:122
const struct no_os_uart_platform_ops * platform_ops
Definition no_os_uart.h:133
uint32_t baud_rate
Definition no_os_uart.h:132
uint32_t irq_id
Definition no_os_uart.h:128
void * mutex
Definition no_os_uart.h:124
struct lf256fifo * rx_fifo
Definition no_os_uart.h:130
void * extra
Definition no_os_uart.h:135
uint8_t device_id
Definition no_os_uart.h:126
Structure holding the parameters for UART initialization.
Definition no_os_uart.h:98
enum no_os_uart_parity parity
Definition no_os_uart.h:110
bool asynchronous_rx
Definition no_os_uart.h:104
void * extra
Definition no_os_uart.h:115
uint32_t irq_id
Definition no_os_uart.h:102
uint8_t device_id
Definition no_os_uart.h:100
uint32_t baud_rate
Definition no_os_uart.h:106
const struct no_os_uart_platform_ops * platform_ops
Definition no_os_uart.h:113
enum no_os_uart_stop stop
Definition no_os_uart.h:112
enum no_os_uart_size size
Definition no_os_uart.h:108
Structure holding UART function pointers that point to the platform specific function.
Definition no_os_uart.h:143
int32_t(* init)(struct no_os_uart_desc **, struct no_os_uart_init_param *)
Definition no_os_uart.h:145
int32_t(* write)(struct no_os_uart_desc *, const uint8_t *, uint32_t)
Definition no_os_uart.h:149
int32_t(* write_nonblocking)(struct no_os_uart_desc *, const uint8_t *, uint32_t)
Definition no_os_uart.h:153
uint32_t(* get_errors)(struct no_os_uart_desc *)
Definition no_os_uart.h:158
int32_t(* read_nonblocking)(struct no_os_uart_desc *, uint8_t *, uint32_t)
Definition no_os_uart.h:151
int32_t(* read)(struct no_os_uart_desc *, uint8_t *, uint32_t)
Definition no_os_uart.h:147
int32_t(* remove)(struct no_os_uart_desc *)
Definition no_os_uart.h:156