1.26.5.28 FLEXCOM_USART_RING_BUFFER_CALLBACK Typedef

C

/* Ring buffer mode */

typedef void (* FLEXCOM_USART_RING_BUFFER_CALLBACK)(FLEXCOM_USART_EVENT event, uintptr_t context )

Summary

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

Description

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

Precondition

FLEXCOMx_USART_Initialize must have been called for the given FLEXCOM_USART peripheral instance. Callback must have been registered using FLEXCOMx_USART_WriteCallbackRegister or FLEXCOMx_USART_ReadCallbackRegister routines and event notifications are enabled using the FLEXCOMx_USART_WriteNotificationEnable or FLEXCOMx_USART_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 pointer to 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(FLEXCOM_USART_EVENT event, uintptr_t context )
{
    txThresholdEventReceived = true;
}

void usartReadEventHandler(FLEXCOM_USART_EVENT event, uintptr_t context )
{
    uint32_t nBytesAvailable = 0;
    
    if (event == FLEXCOM_USART_EVENT_READ_THRESHOLD_REACHED)
    {
        nBytesAvailable = FLEXCOM0_USART_ReadCountGet();
        
        nBytesRead += FLEXCOM0_USART_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable);
    }
}

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

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

// Set TX threshold - TX buffer is empty
FLEXCOM0_USART_WriteThresholdSet(FLEXCOM0_USART_WriteBufferSizeGet());

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

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

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

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

Remarks

None.