1.1.13.34 1.8.24.26 1.10.23.28 1.11.23.28 1.12.24.28 1.13.22.28 1.14.17.28 1.15.18.28 1.16.25.28 1.17.20.28 1.18.21.28 1.19.21.28 1.20.25.28 1.21.26.28 1.22.28.28 1.23.27.28 1.24.23.28 1.27.26.26 1.34.26.26 1.35.20.26 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