1.1.9.1 How the Library Works

The USART driver library is a multi-client, multi-instance buffer queue model based driver interface.

Abstraction Model

The following diagram illustrates the model used by the USART Driver.

  • Note: Queue is not present in Synchronous mode of the driver.

drv_usart_abstraction_model

Working Flow

  • The USART driver is built on top of the USART/UART peripheral library. The peripheral library must be configured to run in non-blocking (interrupts enabled) mode.

  • The USART driver can be used with DMA for data Transfer/Receive

  • The USART driver is capable of supporting multiple instances of the USART/UART peripheral. Also, there can be multiple clients to a USART driver instance.

USART driver is capable of working in both Asynchronous and Synchronous modes.

USART driver in Asynchronous mode

Asynchronous mode APIs are non-blocking in nature. These APIs submit a request and return back to the application.

Typically, if there are no on-going or pending requests in the driver's transfer queue, then the transfer is started by the API and completed from the peripheral interrupt. If there is an on-going transfer or one or more requests pending in the driver's transfer queue, then the request is added to the queue and executed when all the pending requests are complete. The size of the transfer queue is configurable using MCC based on application needs.

The transfer APIs provide a transfer handle back to the application. If the driver was unable to accept the request, then the transfer handle will be set to NULL. This usually happens if the transfer queue is full or if invalid argruments are passed to the API. Application must check the value of the transfer handle to ensure the request was accepted successfully. Transfer handle can be used to identify/track the request.

Application can either register a callback to get notified when the transfer is complete or poll the status of the request by calling the DRV_USART_BufferStatusGet() API. Asynchronous mode APIs are available in both bare-metal and RTOS mode.

USART driver in Synchronous mode

Synchronous mode APIs are blocking in nature. These APIs block until the transfer/request is complete. Synchronous mode APIs are only supported in RTOS mode. These APIs initate the transfer and then block on a semaphore while the transfer is in progress, thereby allowing other ready tasks to run. Once the transfer is complete, the semaphore is given (from the peripheral interrupt's context) thereby unblocking the calling task. The return value usually provides the status of the transfer.