Software implemented UART. More...
Software implemented UART.
This module provides a software implemented Universal Asynchronous Receiver Transmitter. It is intended to be used in situation where hardware UART is not available. The signatures of the functions are similar to the functions declared in uart.h
Currently sending and receiving is not possible at the same time, so loopback operation is not possible.
Files | |
file | soft_uart.h |
Software UART port descriptor definition. | |
file | soft_uart_params.h |
Software UART configuration. | |
Data Structures | |
struct | soft_uart_conf_t |
Software UART port descriptor. More... | |
Macros | |
#define | SOFT_UART_FLAG_INVERT_TX 0x1 |
invert the level of the TX signal | |
#define | SOFT_UART_FLAG_INVERT_RX 0x2 |
invert the level of the RX signal | |
Typedefs | |
typedef unsigned | soft_uart_t |
Software UART type definition. | |
Functions | |
int | soft_uart_init (soft_uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) |
Initialize a given UART device. | |
int | soft_uart_mode (soft_uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity, uart_stop_bits_t stop_bits) |
Setup parity, data and stop bits for a given UART device. | |
void | soft_uart_write (soft_uart_t uart, const uint8_t *data, size_t len) |
Write data from the given buffer to the specified UART device. | |
void | soft_uart_poweron (soft_uart_t uart) |
Power on the given UART device. | |
void | soft_uart_poweroff (soft_uart_t uart) |
Power off the given UART device. | |
#define SOFT_UART_FLAG_INVERT_RX 0x2 |
invert the level of the RX signal
Definition at line 48 of file soft_uart.h.
#define SOFT_UART_FLAG_INVERT_TX 0x1 |
invert the level of the TX signal
Definition at line 43 of file soft_uart.h.
typedef unsigned soft_uart_t |
Software UART type definition.
Definition at line 66 of file soft_uart.h.
int soft_uart_init | ( | soft_uart_t | uart, |
uint32_t | baudrate, | ||
uart_rx_cb_t | rx_cb, | ||
void * | arg | ||
) |
Initialize a given UART device.
The UART device will be initialized with the following configuration:
If no callback parameter is given (rx_cb := NULL), the UART will be initialized in TX only mode.
[in] | uart | UART device to initialize |
[in] | baudrate | desired symbol rate in baud |
[in] | rx_cb | receive callback, executed in interrupt context once for every byte that is received (RX buffer filled), set to NULL for TX only mode |
[in] | arg | optional context passed to the callback functions |
int soft_uart_mode | ( | soft_uart_t | uart, |
uart_data_bits_t | data_bits, | ||
uart_parity_t | parity, | ||
uart_stop_bits_t | stop_bits | ||
) |
Setup parity, data and stop bits for a given UART device.
[in] | uart | UART device to configure |
[in] | data_bits | number of data bits in a UART frame |
[in] | parity | parity mode |
[in] | stop_bits | number of stop bits in a UART frame |
void soft_uart_poweroff | ( | soft_uart_t | uart | ) |
Power off the given UART device.
[in] | uart | the UART device to power off |
void soft_uart_poweron | ( | soft_uart_t | uart | ) |
Power on the given UART device.
[in] | uart | the UART device to power on |
void soft_uart_write | ( | soft_uart_t | uart, |
const uint8_t * | data, | ||
size_t | len | ||
) |
Write data from the given buffer to the specified UART device.
This function is blocking, as it will only return after len
bytes from the given buffer have been send. The way this data is send is up to the implementation: active waiting, interrupt driven, DMA, etc.
[in] | uart | UART device to use for transmission |
[in] | data | data buffer to send |
[in] | len | number of bytes to send |