Midnight Sun Firmware
Loading...
Searching...
No Matches
UART

UART library. More...

Classes

struct  UartSettings
 UART Settings. More...
 

Macros

#define UART_MAX_BUFFER_LEN   256U
 Maximum size permitted for a UART transaction.
 
#define UART_TIMEOUT_MS   1U
 Maximum time permitted for a UART transaction.
 

Enumerations

enum  UartPort { UART_PORT_1 = 0 , UART_PORT_2 , NUM_UART_PORTS }
 UART Port selection.
 
enum  UartFlowControl { UART_FLOW_CONTROL_NONE , UART_FLOW_CONTROL_RTS , UART_FLOW_CONTROL_CTS , UART_FLOW_CONTROL_RTS_CTS }
 UART Flow control selection. More...
 

Functions

StatusCode uart_init (UartPort uart, UartSettings *settings)
 Initialize UART instance, assuming standard 8 bits 1 stop bit. More...
 
StatusCode uart_rx (UartPort uart, uint8_t *data, size_t len)
 Receive data from the UART port. More...
 
StatusCode uart_tx (UartPort uart, uint8_t *data, size_t len)
 Transmit data from the UART port. More...
 

Detailed Description

UART library.

Enumeration Type Documentation

◆ UartFlowControl

UART Flow control selection.

Flow control is a method of synchronizing UART communication between 2 devices. For most applications, this can be set to UART_FLOW_CONTROL_NONE.

Enumerator
UART_FLOW_CONTROL_NONE 

Disable flow control

UART_FLOW_CONTROL_RTS 

Enable request-to-send flow control

UART_FLOW_CONTROL_CTS 

Enable clear-to-send flow control

UART_FLOW_CONTROL_RTS_CTS 

Enable both request-to-send and clear-to-send flow control

Function Documentation

◆ uart_init()

StatusCode uart_init ( UartPort  uart,
UartSettings settings 
)

Initialize UART instance, assuming standard 8 bits 1 stop bit.

Parameters
uartSpecifies which UART port to initialize
settingsPointer to UART initialization settings
Returns
STATUS_CODE_OK if initialization succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_INTERNAL_ERROR if HAL initialization fails STATUS_CODE_RESOURCE_EXHAUSTED if already initialized

◆ uart_rx()

StatusCode uart_rx ( UartPort  uart,
uint8_t *  data,
size_t  len 
)

Receive data from the UART port.

Receives length bytes of data from UART RX queue. Receives up to UART_MAX_BUFFER_LEN.

Parameters
uartSpecifies which UART port to read from
dataPointer to the data buffer
lenLength of data to receive
Returns
STATUS_CODE_OK if receiving succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_INTERNAL_ERROR if HAL receiving fails STATUS_CODE_TIMEOUT if receiving takes too long

◆ uart_tx()

StatusCode uart_tx ( UartPort  uart,
uint8_t *  data,
size_t  len 
)

Transmit data from the UART port.

Sends length bytes of data from UART TX queue to specified UART port. Sends up to UART_MAX_BUFFER_LEN.

Parameters
uartSpecifies which UART port to read from
dataPointer to the data buffer
lenLength of data to receive
Returns
STATUS_CODE_OK if transmission succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_INTERNAL_ERROR if HAL transmission fails STATUS_CODE_TIMEOUT if transmission takes too long