1.34.27.28 1.35.21.28 USART_RING_BUFFER_CALLBACK Typedef
C
/* Ring buffer mode */ typedef void (* USART_RING_BUFFER_CALLBACK)(USART_EVENT event, uintptr_t context );
Summary
Defines the data type and function signature for the USART peripheral callback function in the ring buffer mode.
Description
This data type defines the function signature for the USART peripheral callback function in the ring buffer mode. The USART peripheral will call back the client's function with this signature when the USART buffer event has occurred.
Precondition
USARTx_Initialize must have been called for the given USART peripheral instance. Callback must have been registered using USARTx_WriteCallbackRegister or USARTx_ReadCallbackRegister routines and event notifications are enabled using the USARTx_WriteNotificationEnable or USARTx_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(USART_EVENT event, uintptr_t context ) { txThresholdEventReceived = true; } void usartReadEventHandler(USART_EVENT event, uintptr_t context ) { uint32_t nBytesAvailable = 0; if (event == USART_EVENT_READ_THRESHOLD_REACHED) { nBytesAvailable = USART1_ReadCountGet(); nBytesRead += USART1_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable); } } //----------------------------------------------------------// // Register a callback for write events USART1_WriteCallbackRegister(usartWriteEventHandler, (uintptr_t) NULL); // Set TX threshold - TX buffer is empty USART1_WriteThresholdSet(USART1_WriteBufferSizeGet()); // Enable notifications. Enables notification when threshold condition is reached USART1_WriteNotificationEnable(true, false); // Register a callback for read events USART1_ReadCallbackRegister(usartReadEventHandler, (uintptr_t) NULL); // Set RX threshold - when 5 characters are available in the receive buffer USART1_ReadThresholdSet(5); // Enable RX event notifications USART1_ReadNotificationEnable(true, false);
Remarks
None.