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.
|
typedef unsigned | soft_uart_t |
| Software UART type definition.
|
|
◆ soft_uart_init()
Initialize a given UART device.
The UART device will be initialized with the following configuration:
- 8 data bits
- no parity
- 1 stop bit
- baudrate as given
If no callback parameter is given (rx_cb := NULL), the UART will be initialized in TX only mode.
- Parameters
-
[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 |
- Returns
- UART_OK on success
-
UART_NODEV on invalid UART device
-
UART_NOBAUD on inapplicable baudrate
-
UART_INTERR on other errors
◆ soft_uart_mode()
Setup parity, data and stop bits for a given UART device.
- Parameters
-
[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 |
- Returns
- UART_OK on success
-
UART_NOMODE on other errors
◆ soft_uart_poweroff()
Power off the given UART device.
- Parameters
-
[in] | uart | the UART device to power off |
◆ soft_uart_poweron()
Power on the given UART device.
- Parameters
-
[in] | uart | the UART device to power on |
◆ soft_uart_write()
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.
- Parameters
-
[in] | uart | UART device to use for transmission |
[in] | data | data buffer to send |
[in] | len | number of bytes to send |