Software implemented UART. More...

Detailed Description

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. More...
 
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. More...
 
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. More...
 
void soft_uart_poweron (soft_uart_t uart)
 Power on the given UART device. More...
 
void soft_uart_poweroff (soft_uart_t uart)
 Power off the given UART device. More...
 

Function Documentation

◆ soft_uart_init()

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:

  • 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]uartUART device to initialize
[in]baudratedesired symbol rate in baud
[in]rx_cbreceive callback, executed in interrupt context once for every byte that is received (RX buffer filled), set to NULL for TX only mode
[in]argoptional 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()

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.

Parameters
[in]uartUART device to configure
[in]data_bitsnumber of data bits in a UART frame
[in]parityparity mode
[in]stop_bitsnumber of stop bits in a UART frame
Returns
UART_OK on success
UART_NOMODE on other errors

◆ soft_uart_poweroff()

void soft_uart_poweroff ( soft_uart_t  uart)

Power off the given UART device.

Parameters
[in]uartthe UART device to power off

◆ soft_uart_poweron()

void soft_uart_poweron ( soft_uart_t  uart)

Power on the given UART device.

Parameters
[in]uartthe 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]uartUART device to use for transmission
[in]datadata buffer to send
[in]lennumber of bytes to send