1.21.22.28 UART_RING_BUFFER_CALLBACK Typedef

C

/* Ring buffer mode */

typedef void (* UART_RING_BUFFER_CALLBACK)(UART_EVENT event, uintptr_t context );

Summary

Defines the data type and function signature for the UART peripheral callback function in the ring buffer mode.

Description

This data type defines the function signature for the UART peripheral callback function in the ring buffer mode. The UART peripheral will call back the client's function with this signature when the UART buffer event has occurred.

Precondition

UARTx_Initialize must have been called for the given UART peripheral instance. Callback must have been registered using UARTx_WriteCallbackRegister or UARTx_ReadCallbackRegister routines and event notifications are enabled using the UARTx_WriteNotificationEnable or UARTx_ReadNotificationEnable routines.

Parameters

Param Description
event Indicates the event for which the callback is called
context Allows the caller to provide a context value (usually a pointerto the callers context for multiple clients).

Returns

None.

Example

uint8_t txBuffer[50];
uint8_t rxBuffer[10];

volatile bool txThresholdEventReceived = false;
volatile bool rxThresholdEventReceived = false;
volatile uint32_t nBytesRead = 0;

void usartWriteEventHandler(UART_EVENT event, uintptr_t context )
{
    txThresholdEventReceived = true;
}

void usartReadEventHandler(UART_EVENT event, uintptr_t context )
{
    uint32_t nBytesAvailable = 0;
    
    if (event == UART_EVENT_READ_THRESHOLD_REACHED)
    {
        nBytesAvailable = UART1_ReadCountGet();
        
        nBytesRead += UART1_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable);
    }
}

//----------------------------------------------------------//

// Register a callback for write events
UART1_WriteCallbackRegister(usartWriteEventHandler, (uintptr_t) NULL);

// Set TX threshold - TX buffer is empty
UART1_WriteThresholdSet(UART1_WriteBufferSizeGet());

// Enable notifications. Enables notification when threshold condition is reached
UART1_WriteNotificationEnable(true, false);

// Register a callback for read events
UART1_ReadCallbackRegister(usartReadEventHandler, (uintptr_t) NULL);

// Set RX threshold - when 5 characters are available in the receive buffer
UART1_ReadThresholdSet(5);

// Enable RX event notifications
UART1_ReadNotificationEnable(true, false);

Remarks

None