UART Driver
The UART driver is used for access and control of an end device’s basic UART functionality. This includes reading and writing on UART, flushing and checking available Tx (transfer) and Rx (receive) lines, and registering callbacks from Tx and Rx.
Data Structures
ATMO_UART_Peripheral_t
Uart Peripheral Configuration
Member Name |
Type |
Description |
baudRate |
ATMO_UART_BaudRate_t |
|
numDataBits |
ATMO_UART_NumDataBits_t |
|
numStopBits |
ATMO_UART_NumStopBits_t |
|
parity |
ATMO_UART_Parity_t |
|
flowControl |
ATMO_UART_FlowControl_t |
|
customBuffer |
uint8_t * |
|
customBufferSize |
uint32_t |
|
isBinaryData |
bool |
Is the data binary (as opposed to ASCII characters) |
rxBuffer |
bool |
Do you want the UART drive to buffer received bytes? If set to true, splitRegex must be populated |
rxTrim |
bool |
If rxBuffer is true, do you want the UART driver to trim whitespace from the ends of the received string? |
splitRegex |
char |
Regular expression that determines when buffer is sent. When the data in the RX buffer matches this string, the data will be sent. Regex lib used is |
Type Definitions
Name |
Definition |
Description |
ATMO_UART_DriverInstance_t |
typedef struct ATMO_UART_DriverInstance_t ATMO_UART_DriverInstance_t |
|
Enumerations
enum
ATMO_UART_BaudRate_t
UART Baud Rate
Name |
Value |
ATMO_UART_BaudRate_1200 |
1200UL |
ATMO_UART_BaudRate_2400 |
2400UL |
ATMO_UART_BaudRate_4800 |
4800UL |
ATMO_UART_BaudRate_9600 |
9600UL |
ATMO_UART_BaudRate_19200 |
19200UL |
ATMO_UART_BaudRate_38400 |
38400UL |
ATMO_UART_BaudRate_57600 |
57600UL |
ATMO_UART_BaudRate_115200 |
115200UL |
ATMO_UART_BaudRate_230400 |
230400UL |
ATMO_UART_BaudRate_460800 |
460800UL |
ATMO_UART_BaudRate_921600 |
921600UL |
enum
ATMO_UART_NumDataBits_t
Number of data bits per frame
Name |
Value |
ATMO_UART_NumDataBits_5 |
0x05u |
ATMO_UART_NumDataBits_6 |
0x06u |
ATMO_UART_NumDataBits_7 |
0x07u |
ATMO_UART_NumDataBits_8 |
0x08u |
ATMO_UART_NumDataBits_9 |
0x09u |
enum
ATMO_UART_NumStopBits_t
Number of stop bits
Name |
Value |
ATMO_UART_NumStopBits_1 |
0x01u |
ATMO_UART_NumStopBits_2 |
0x02u |
enum
ATMO_UART_Parity_t
UART Parity
Name |
Value |
ATMO_UART_Parity_None |
0x00u |
ATMO_UART_Parity_Odd |
0x01u |
ATMO_UART_Parity_Even |
0x02u |
ATMO_UART_Parity_Mark |
0x03u |
ATMO_UART_Parity_Space |
0x04u |
enum
ATMO_UART_FlowControl_t
Flow control mode
Name |
Value |
ATMO_UART_FlowControl_None |
0x00u |
ATMO_UART_FlowControl_RTS_CTS |
0x01u |
ATMO_UART_FlowControl_Xon_Xoff |
0x02u |
enum
ATMO_UART_Status_t
UART Driver Return Enumerations
Name |
Value |
Description |
ATMO_UART_Status_Success |
0x00u |
Operation was successful |
ATMO_UART_Status_Fail |
0x01u |
Operation failed |
ATMO_UART_Status_Initialized |
0x02u |
Peripheral already initialized |
ATMO_UART_Status_Invalid |
0x03u |
Invalid operation |
ATMO_UART_Status_NotSupported |
0x04u |
Feature not supported by platform |
ATMO_UART_Status_Unknown |
0x05u |
Some other status not defined |
ATMO_UART_Status_Busy |
0x06u |
Transfer in progress |
ATMO_UART_Status_Timeout |
0x07u |
Transfer timed out |
ATMO_UART_Status_Idle |
0x08u |
|
enum
ATMO_UART_TxEvent_t
Uart Nonblocking Transmit Event
Name |
Value |
Description |
ATMO_UART_TxEvent_Unknown |
0x0000u |
|
ATMO_UART_TxEvent_Complete |
0x0001u |
Transfer Complete |
enum
ATMO_UART_RxEvent_t
Uart Nonblocking Receive Event
Name |
Value |
Description |
ATMO_UART_RxEvent_Unknown |
0x0000u |
|
ATMO_UART_RxEvent_Complete |
0x0001u |
Transfer Complete |
Functions
ATMO_Status_t ATMO_UART_AddDriverInstance(const ATMO_UART_DriverInstance_t *driverInstance, ATMO_DriverInstanceData_t *driverInstanceData, ATMO_DriverInstanceHandle_t *instanceNumber)
This routine will add an instance of a driver for UART into the UART driver handler.
Parameter |
Direction |
Type |
instanceNumber |
N/A |
ATMO_DriverInstanceHandle_t * |
driverInstanceData |
N/A |
ATMO_DriverInstanceData_t * |
driverInstance |
N/A |
const ATMO_UART_DriverInstance_t * |
Return Type |
ATMO_Status_t |
ATMO_UART_Status_t ATMO_UART_Init(ATMO_DriverInstanceHandle_t instance)
This routine initializes the UART peripheral.
Parameter |
Direction |
Type |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_DeInit(ATMO_DriverInstanceHandle_t instance)
This routine de-initializes the UART peripheral.
Parameter |
Direction |
Type |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_SetConfiguration(ATMO_DriverInstanceHandle_t instance, const ATMO_UART_Peripheral_t *config)
This routine configures the specified UART peripheral instance. It is similar to the init function except the peripheral configuration settings are passed in via the config structure.
Parameter |
Direction |
Type |
config |
N/A |
const ATMO_UART_Peripheral_t * |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_GetConfiguration(ATMO_DriverInstanceHandle_t instance, ATMO_UART_Peripheral_t *config)
This routine retrieves the current configuration of the specified UART peripheral instance.
Parameter |
Direction |
Type |
config |
N/A |
ATMO_UART_Peripheral_t * |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_WriteBlocking(ATMO_DriverInstanceHandle_t instance, const char *buffer, uint32_t length, uint32_t *numBytesSent, uint16_t timeoutMs)
This routine will send one or more bytes via the specified UART peripheral. This is a blocking function and will not return until all data has been sent. In the even of a buffer overflow, the actual number of bytes transferred will be returned in numBytesSent.
Parameter |
Direction |
Type |
timeoutMs |
N/A |
uint16_t |
numBytesSent |
N/A |
uint32_t * |
length |
N/A |
uint32_t |
buffer |
N/A |
const char * |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_ReadBlocking(ATMO_DriverInstanceHandle_t instance, char *buffer, uint32_t length, uint32_t *numBytesReceived, uint16_t timeoutMs)
This routine will read one or more bytes from the specified UART peripheral receive buffer. This is a blocking function and will not return until the specified number of characters have been received or the timeout expires.
Parameter |
Direction |
Type |
timeoutMs |
N/A |
uint16_t |
numBytesReceived |
N/A |
uint32_t * |
length |
N/A |
uint32_t |
buffer |
N/A |
char * |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_NumRxBytesAvailable(ATMO_DriverInstanceHandle_t instance, unsigned int *bytesAvailable)
Retrieve the number of bytes waiting to be read.
Parameter |
Direction |
Type |
bytesAvailable |
N/A |
unsigned int * |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_FlushTx(ATMO_DriverInstanceHandle_t instance)
This routine will empty the contents of the UART Tx buffer.
Parameter |
Direction |
Type |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_FlushRx(ATMO_DriverInstanceHandle_t instance)
This routine will empty the contents of the UART Rx buffer.
Parameter |
Direction |
Type |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_CheckForData(ATMO_DriverInstanceHandle_t instance)
Poll the UART system for new data. May not be implemented for every platform.
Parameter |
Direction |
Type |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_RegisterRxAbilityHandle(ATMO_DriverInstanceHandle_t instance, unsigned int abilityHandle)
This routine will register or unregister a user-defined callback function for the specified UART peripheral instance.
Parameter |
Direction |
Type |
abilityHandle |
N/A |
unsigned int |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_RegisterRxCbFunc(ATMO_DriverInstanceHandle_t instance, ATMO_Callback_t cbFunc)
This routine will register or unregister a user-defined callback function for the specified UART peripheral instance.
Parameter |
Direction |
Type |
cbFunc |
N/A |
ATMO_Callback_t |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_ReadAvailableData(ATMO_DriverInstanceHandle_t instance, uint8_t *buffer, unsigned int bufferLen, unsigned int *numBytesRead)
Read all available data in the UART RX FIFO.
Parameter |
Direction |
Type |
numBytesRead |
N/A |
unsigned int * |
bufferLen |
N/A |
unsigned int |
buffer |
N/A |
uint8_t * |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
ATMO_UART_Status_t ATMO_UART_WriteStringBlocking(ATMO_DriverInstanceHandle_t instance, const char *buffer)
Simple function to write a string to the UART.
Parameter |
Direction |
Type |
buffer |
N/A |
const char * |
instance |
N/A |
ATMO_DriverInstanceHandle_t |
Return Type |
ATMO_UART_Status_t |
void ATMO_UART_GetDefaultConfig(ATMO_UART_Peripheral_t *config)
Get default UART device configuration - 8 Data bits, 1 stop bit, 115200 baud rate, no parity, no flow control.
Parameter |
Direction |
Type |
config |
N/A |
ATMO_UART_Peripheral_t * |