1.27.5.14 FLEXCOMx_USART_ReadNotificationEnable Function

C

/* x = FLEXCOM instance number */

/* Ring buffer mode */

bool FLEXCOMx_USART_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

FLEXCOMx_USART_Initialize must have been called for the associated FLEXCOM_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 disables persistent 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(FLEXCOM_USART_EVENT event, uintptr_t context )
{
    uint32_t nBytesAvailable = 0;
    
    if (event == FLEXCOM_USART_EVENT_READ_THRESHOLD_REACHED)
    {
        // Receiver should have the thershold number of bytes in the receive buffer
        nBytesAvailable = FLEXCOM0_USART_ReadCountGet();
        
        nBytesRead += FLEXCOM0_USART_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable);
    }
}

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

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

// Set a threshold value to receive a callback after every 10 characters are received
FLEXCOM0_USART_ReadThresholdSet(10);

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

Remarks

None