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
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

Type Definitions

Name Definition
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 1200u
ATMO_UART_BaudRate_2400 2400u
ATMO_UART_BaudRate_4800 4800u
ATMO_UART_BaudRate_9600 9600u
ATMO_UART_BaudRate_19200 19200u
ATMO_UART_BaudRate_38400 38400u
ATMO_UART_BaudRate_57600 57600u
ATMO_UART_BaudRate_115200 115200u
ATMO_UART_BaudRate_230400 230400u
ATMO_UART_BaudRate_460800 460800u
ATMO_UART_BaudRate_921600 921600u

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 non-blocking transmit event.

Name Value Description
ATMO_UART_TxEvent_Unknown 0x0000u  
ATMO_UART_TxEvent_Complete 0x0001u Transfer complete

enum ATMO_UART_RxEvent_t

UART non-blocking 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)

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, 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 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_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_RegisterByteReceivedAbilityHandle(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_RegisterByteReceivedCbFunc(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