1.35.21.15 USARTx_ReadNotificationEnable Function
C
/* x = USART instance number */
/* Ring buffer mode */
bool USARTx_ReadNotificationEnable(bool isEnabled, bool isPersistent)
Summary
This API lets the application turn the receive notifications on/off
Description
This API allows the application to enable or disable receive notifications. Further the application can choose to get notified persistently until the threshold condition is true. For example, if the receive threshold is set to 5, a notification is given when the internal receive buffer has 5 bytes. If persistent notification is turned off, the application is notified only once when there are 5 unread bytes in the receive buffer. However, if persistent notification is turned on, the application is notified every time a byte is received and the receive buffer has 5 or more unread characters. In this case, the notification will be stopped, when the application reads data out from the receive buffer and the number of bytes pedning in the receive buffer becomes less than 5.
Precondition
USARTx_Initialize must have been called for the associated USART instance.
Parameters
Param | Description |
---|---|
isEnabled | A true value turns on notification, false value turns off notification |
isPersistent | A true value turns on persistent notification. A false value disablespersistent notifications |
Returns
The API returns the previous state of notifications. A true value indicates notifications were previously enabled; false value indicates notifications were perviously disabled.
Example
uint8_t rxBuffer[50]; uint32_t nBytes; void usartReadEventHandler(USART_EVENT event, uintptr_t context ) { uint32_t nBytesAvailable = 0; if (event == USART_EVENT_READ_THRESHOLD_REACHED) { // Receiver should have the thershold number of bytes in the receive buffer nBytesAvailable = USART1_ReadCountGet(); nBytesRead += USART1_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable); } } //----------------------------------------------------------// // Register a callback for read events USART1_ReadCallbackRegister(usartReadEventHandler, (uintptr_t) NULL); // Set a threshold value to receive a callback after every 10 characters are received USART1_ReadThresholdSet(10); // Enable RX event notifications USART1_ReadNotificationEnable(true, false);
Remarks
None