1.25.5.27 1.26.4.27 DBGU_RING_BUFFER_CALLBACK Typedef

C

/* Ring buffer mode */

typedef void (* DBGU_RING_BUFFER_CALLBACK)(DBGU_EVENT event, uintptr_t context );

Summary

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

Description

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

Precondition

DBGU_Initialize must have been called for the given DBGU peripheral instance. Callback must have been registered using DBGU_WriteCallbackRegister or DBGU_ReadCallbackRegister routines and event notifications are enabled using the DBGU_WriteNotificationEnable or DBGU_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(DBGU_EVENT event, uintptr_t context )
{
    txThresholdEventReceived = true;
}

void usartReadEventHandler(DBGU_EVENT event, uintptr_t context )
{
    uint32_t nBytesAvailable = 0;
    
    if (event == DBGU_EVENT_READ_THRESHOLD_REACHED)
    {
        nBytesAvailable = DBGU_ReadCountGet();
        
        nBytesRead += DBGU_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable);
    }
}

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

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

// Set TX threshold - TX buffer is empty
DBGU_WriteThresholdSet(DBGU_WriteBufferSizeGet());

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

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

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

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

Remarks

None