UART HAL API

Module: HAL (AM13E230X) API

More…

Structures

Name

struct

Uart_Hal_TxStatusType
TX status.

struct

Uart_Hal_RxStatusType
RX status.

struct

Uart_Hal_InitParamsType
UART HW initialization parameters.

struct

Uart_Hal_InstanceType
UART HW instance structure. Should not be modified by application directly.

Types

Name

enum

Uart_Hal_ParityType { UART_HAL_PARITY_NONE = 0U, UART_HAL_PARITY_EVEN = 1U, UART_HAL_PARITY_ODD = 2U, UART_HAL_PARITY_STICK_ONE = 3U, UART_HAL_PARITY_STICK_ZERO = 4U}
Parity type.

enum

Uart_Hal_DataSizeType { UART_HAL_DATASIZE_5_BITS = 0U, UART_HAL_DATASIZE_6_BITS = 1U, UART_HAL_DATASIZE_7_BITS = 2U, UART_HAL_DATASIZE_8_BITS = 3U}
Size of data bits.

enum

Uart_Hal_StopBitsType { UART_HAL_STOPBITS_ONE = 0U, UART_HAL_STOPBITS_TWO = 1U}
Number of stop bits.

enum

Uart_Hal_StateType { UART_HAL_STATE_UNCONFIGURED, UART_HAL_STATE_READY, UART_HAL_STATE_TRANSMIT, UART_HAL_STATE_RECEIVE}
List of state of the module.

Functions

Name

sint32

Uart_Hal_InitParamsSetDefault(Uart_Hal_InitParamsType * paramsPtr)
Initialize params.

sint32

Uart_Hal_Init(Uart_Hal_InstanceType * instancePtr, const Uart_Hal_InitParamsType * paramsPtr)
Initialize a UART HW instance.

sint32

Uart_Hal_TxPolling(Uart_Hal_InstanceType * instancePtr, const uint8 * bufferPtr, uint32 sizeInBytes)
Tx a buffer of data in polling mode.

sint32

Uart_Hal_RxPolling(Uart_Hal_InstanceType * instancePtr, uint8 * bufferPtr, uint32 sizeInBytes)
Rx a buffer of data in polling mode.

sint32

Uart_Hal_TxInterrupt(Uart_Hal_InstanceType * instancePtr, const uint8 * bufferPtr, uint32 sizeInBytes)
Tx a buffer of data in interrupt mode.

sint32

Uart_Hal_RxInterrupt(Uart_Hal_InstanceType * instancePtr, uint8 * bufferPtr, uint32 sizeInBytes)
Rx a buffer of data in interrupt mode.

sint32

Uart_Hal_TxDma(Uart_Hal_InstanceType * instancePtr, const uint8 * bufferPtr, uint32 sizeInBytes)
Tx a buffer of data in DMA mode.

sint32

Uart_Hal_RxDma(Uart_Hal_InstanceType * instancePtr, uint8 * bufferPtr, uint32 sizeInBytes)
Rx a buffer of data in DMA mode.

sint32

Uart_Hal_TxAbortDma(Uart_Hal_InstanceType * instancePtr)
Abort TX operation. Only valid in DMA mode.

sint32

Uart_Hal_RxAbortDma(Uart_Hal_InstanceType * instancePtr)
Abort RX operation. Only valid in DMA mode.

sint32

Uart_Hal_TxAbort(Uart_Hal_InstanceType * instancePtr)
Abort TX operation. Only valid in polling and interrupt mode.

sint32

Uart_Hal_RxAbort(Uart_Hal_InstanceType * instancePtr)
Abort RX operation. Only valid in polling and interrupt mode.

sint32

Uart_Hal_TxContinuePolling(Uart_Hal_InstanceType * instancePtr, Uart_Hal_TxStatusType * statusPtr)
Continue TX polling and get transfer status. Only valid in polling mode.

sint32

Uart_Hal_RxContinuePolling(Uart_Hal_InstanceType * instancePtr, Uart_Hal_RxStatusType * statusPtr)
Continue RX polling and get transfer status. Only valid in polling mode.

sint32

Uart_Hal_GetTxCurrentState(const Uart_Hal_InstanceType * instancePtr, Uart_Hal_StateType * statePtr)
Get the current TX state.

sint32

Uart_Hal_GetRxCurrentState(const Uart_Hal_InstanceType * instancePtr, Uart_Hal_StateType * statePtr)
Get the current RX state.

sint32

Uart_Hal_GetRxStatus(const Uart_Hal_InstanceType * instancePtr, Uart_Hal_RxStatusType * statusPtr)
Get the current RX transfer status.

void

Uart_Hal_TxCompleteCallback(Uart_Hal_InstanceType * instancePtr, Uart_Hal_TxStatusType * statusPtr, void * userArgsPtr)
Callback that is called when TX completes. Only valid in interrupt or DMA mode.

void

Uart_Hal_RxCompleteCallback(Uart_Hal_InstanceType * instancePtr, Uart_Hal_RxStatusType * statusPtr, void * userArgsPtr)
Callback that is called when RX completes. Only valid in interrupt or DMA mode.

sint32

Uart_Hal_ClearRxFIFO(const Uart_Hal_InstanceType * instancePtr)
Clear Rx FIFO.

sint32

Uart_Hal_DeInit(Uart_Hal_InstanceType * instancePtr)
De-initialize a UART HW instance.

void

Uart_Hal_InterruptHandler(Uart_Hal_InstanceType * instancePtr)
Interrupt handler.

void

Uart_Hal_DmaInterruptHandler(Uart_Hal_InstanceType * instancePtr)
DMA interrupt handler.

Defines

Name

UART_HAL_ERROR_NONE
No error.

UART_HAL_ERROR_INVALID_INSTANCE
Invalid instance pointer.

UART_HAL_ERROR_INVALID_PARAMS
Invalid parameters.

UART_HAL_ERROR_UNSUPPORTED_FEATURE
Unsupported feature.

UART_HAL_ERROR_HW_BUSY
Hardware busy.

UART_HAL_PARITY_TYPE_COUNT
Number of parity enum values.

UART_HAL_DATASIZE_TYPE_COUNT
Number of data size enum values.

UART_HAL_STOPBITS_TYPE_COUNT
Number of stop bits enum values.

Detailed Description

Note: All transfer APIs are non-blocking unless specified otherwise, i.e. they do not wait for the RX/TX operation to complete.

For a given UART instance, the APIs to use depends on the TX or RX operation mode selected during Uart_Hal_Init(). Only APIs valid in an operation mode should be used by the application, else behaviour is undefined.

UART RX/TX APIs can be used in below operation modes

Types Documentation

enum Uart_Hal_ParityType

Enumerator

Value

Description

UART_HAL_PARITY_NONE

0U

None Parity

UART_HAL_PARITY_EVEN

1U

Even Parity

UART_HAL_PARITY_ODD

2U

Odd Parity

UART_HAL_PARITY_STICK_ONE

3U

Sticky One Parity

UART_HAL_PARITY_STICK_ZERO

4U

Sticky Zero Parity

Parity type.

enum Uart_Hal_DataSizeType

Enumerator

Value

Description

UART_HAL_DATASIZE_5_BITS

0U

5 Data Bits

UART_HAL_DATASIZE_6_BITS

1U

6 Data Bits

UART_HAL_DATASIZE_7_BITS

2U

7 Data Bits

UART_HAL_DATASIZE_8_BITS

3U

8 Data Bits

Size of data bits.

enum Uart_Hal_StopBitsType

Enumerator

Value

Description

UART_HAL_STOPBITS_ONE

0U

1 Stop Bits

UART_HAL_STOPBITS_TWO

1U

2 Stop Bits

Number of stop bits.

enum Uart_Hal_StateType

Enumerator

Value

Description

UART_HAL_STATE_UNCONFIGURED

UART Module is unconfigured

UART_HAL_STATE_READY

UART Module is initialized and ready for use

UART_HAL_STATE_TRANSMIT

UART Module is transmitting out the data

UART_HAL_STATE_RECEIVE

UART Module is receiving data

List of state of the module.

Functions Documentation

function Uart_Hal_InitParamsSetDefault

sint32 Uart_Hal_InitParamsSetDefault(
    Uart_Hal_InitParamsType * paramsPtr
)

Initialize params.

function Uart_Hal_Init

sint32 Uart_Hal_Init(
    Uart_Hal_InstanceType * instancePtr,
    const Uart_Hal_InitParamsType * paramsPtr
)

Initialize a UART HW instance.

function Uart_Hal_TxPolling

sint32 Uart_Hal_TxPolling(
    Uart_Hal_InstanceType * instancePtr,
    const uint8 * bufferPtr,
    uint32 sizeInBytes
)

Tx a buffer of data in polling mode.

function Uart_Hal_RxPolling

sint32 Uart_Hal_RxPolling(
    Uart_Hal_InstanceType * instancePtr,
    uint8 * bufferPtr,
    uint32 sizeInBytes
)

Rx a buffer of data in polling mode.

function Uart_Hal_TxInterrupt

sint32 Uart_Hal_TxInterrupt(
    Uart_Hal_InstanceType * instancePtr,
    const uint8 * bufferPtr,
    uint32 sizeInBytes
)

Tx a buffer of data in interrupt mode.

function Uart_Hal_RxInterrupt

sint32 Uart_Hal_RxInterrupt(
    Uart_Hal_InstanceType * instancePtr,
    uint8 * bufferPtr,
    uint32 sizeInBytes
)

Rx a buffer of data in interrupt mode.

function Uart_Hal_TxDma

sint32 Uart_Hal_TxDma(
    Uart_Hal_InstanceType * instancePtr,
    const uint8 * bufferPtr,
    uint32 sizeInBytes
)

Tx a buffer of data in DMA mode.

function Uart_Hal_RxDma

sint32 Uart_Hal_RxDma(
    Uart_Hal_InstanceType * instancePtr,
    uint8 * bufferPtr,
    uint32 sizeInBytes
)

Rx a buffer of data in DMA mode.

function Uart_Hal_TxAbortDma

sint32 Uart_Hal_TxAbortDma(
    Uart_Hal_InstanceType * instancePtr
)

Abort TX operation. Only valid in DMA mode.

function Uart_Hal_RxAbortDma

sint32 Uart_Hal_RxAbortDma(
    Uart_Hal_InstanceType * instancePtr
)

Abort RX operation. Only valid in DMA mode.

function Uart_Hal_TxAbort

sint32 Uart_Hal_TxAbort(
    Uart_Hal_InstanceType * instancePtr
)

Abort TX operation. Only valid in polling and interrupt mode.

function Uart_Hal_RxAbort

sint32 Uart_Hal_RxAbort(
    Uart_Hal_InstanceType * instancePtr
)

Abort RX operation. Only valid in polling and interrupt mode.

function Uart_Hal_TxContinuePolling

sint32 Uart_Hal_TxContinuePolling(
    Uart_Hal_InstanceType * instancePtr,
    Uart_Hal_TxStatusType * statusPtr
)

Continue TX polling and get transfer status. Only valid in polling mode.

This function transmits remaining bytes to the FIFO and updates the status.

If TX state is not UART_HAL_STATE_TRANSMIT, i.e. transmit is not in progress then UART_HAL_ERROR_UNSUPPORTED_FEATURE is returned.

function Uart_Hal_RxContinuePolling

sint32 Uart_Hal_RxContinuePolling(
    Uart_Hal_InstanceType * instancePtr,
    Uart_Hal_RxStatusType * statusPtr
)

Continue RX polling and get transfer status. Only valid in polling mode.

This function reads available data from the FIFO into the buffer and updates the status.

If RX state is not UART_HAL_STATE_RECEIVE, i.e. receive is not in progress then UART_HAL_ERROR_UNSUPPORTED_FEATURE is returned.

function Uart_Hal_GetTxCurrentState

sint32 Uart_Hal_GetTxCurrentState(
    const Uart_Hal_InstanceType * instancePtr,
    Uart_Hal_StateType * statePtr
)

Get the current TX state.

function Uart_Hal_GetRxCurrentState

sint32 Uart_Hal_GetRxCurrentState(
    const Uart_Hal_InstanceType * instancePtr,
    Uart_Hal_StateType * statePtr
)

Get the current RX state.

function Uart_Hal_GetRxStatus

sint32 Uart_Hal_GetRxStatus(
    const Uart_Hal_InstanceType * instancePtr,
    Uart_Hal_RxStatusType * statusPtr
)

Get the current RX transfer status.

function Uart_Hal_TxCompleteCallback

void Uart_Hal_TxCompleteCallback(
    Uart_Hal_InstanceType * instancePtr,
    Uart_Hal_TxStatusType * statusPtr,
    void * userArgsPtr
)

Callback that is called when TX completes. Only valid in interrupt or DMA mode.

function Uart_Hal_RxCompleteCallback

void Uart_Hal_RxCompleteCallback(
    Uart_Hal_InstanceType * instancePtr,
    Uart_Hal_RxStatusType * statusPtr,
    void * userArgsPtr
)

Callback that is called when RX completes. Only valid in interrupt or DMA mode.

function Uart_Hal_ClearRxFIFO

sint32 Uart_Hal_ClearRxFIFO(
    const Uart_Hal_InstanceType * instancePtr
)

Clear Rx FIFO.

function Uart_Hal_DeInit

sint32 Uart_Hal_DeInit(
    Uart_Hal_InstanceType * instancePtr
)

De-initialize a UART HW instance.

Disable the HW and any enabled interrupts at the UART HW. Interrupts at CPU should be disabled by the application before calling this API.

function Uart_Hal_InterruptHandler

void Uart_Hal_InterruptHandler(
    Uart_Hal_InstanceType * instancePtr
)

Interrupt handler.

After Uart_Hal_Init(), a function should be registered in NVIC which would then call this function. Do not register this function directly in NVIC. When polling is enabled as part of Uart_Hal_Init(), the interrupt handler should not be registered.

The interrupt handler will call one of below callbacks, depending on the conditions detected within the interrupt handler. The interrupt handler will also clear status and interrupt bits as needed for correct operation.

In each of the callbacks, user arguments passed during initialization are passed back to the user.

The callbacks need to be implemented by the application else there will be a linker error.

The supported callbacks are,

function Uart_Hal_DmaInterruptHandler

void Uart_Hal_DmaInterruptHandler(
    Uart_Hal_InstanceType * instancePtr
)

DMA interrupt handler.

After Uart_Hal_Init(), a function should be registered in the DMA interrupt line in NVIC which would then call this function. Do not register this function directly in NVIC for the UART interrupt. This handler is specifically for DMA events related to UART.

The handler will check the DMA status and call the appropriate UART HAL callback (Tx or Rx complete) if the DMA transfer was for UART data and has completed or encountered an error. The user arguments passed during Uart_Hal_Init() are passed back to the user in the callback.

Macros Documentation

define UART_HAL_ERROR_NONE

#define UART_HAL_ERROR_NONE (0)

No error.

define UART_HAL_ERROR_INVALID_INSTANCE

#define UART_HAL_ERROR_INVALID_INSTANCE (1)

Invalid instance pointer.

define UART_HAL_ERROR_INVALID_PARAMS

#define UART_HAL_ERROR_INVALID_PARAMS (2)

Invalid parameters.

define UART_HAL_ERROR_UNSUPPORTED_FEATURE

#define UART_HAL_ERROR_UNSUPPORTED_FEATURE (3)

Unsupported feature.

define UART_HAL_ERROR_HW_BUSY

#define UART_HAL_ERROR_HW_BUSY (4)

Hardware busy.

define UART_HAL_PARITY_TYPE_COUNT

#define UART_HAL_PARITY_TYPE_COUNT ((uint32)UART_HAL_PARITY_STICK_ZERO + 1U)

Number of parity enum values.

define UART_HAL_DATASIZE_TYPE_COUNT

#define UART_HAL_DATASIZE_TYPE_COUNT ((uint32)UART_HAL_DATASIZE_8_BITS + 1U)

Number of data size enum values.

define UART_HAL_STOPBITS_TYPE_COUNT

#define UART_HAL_STOPBITS_TYPE_COUNT ((uint32)UART_HAL_STOPBITS_TWO + 1U)

Number of stop bits enum values.