1.14.17.16 UARTx_ReadNotificationEnable Function

C

/* x = UART instance number */

/* Ring buffer mode */
bool UARTx_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

UARTx_Initialize must have been called for the associated UART 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(UART_EVENT event, uintptr_t context )
{
    uint32_t nBytesAvailable = 0;
    
    if (event == UART_EVENT_READ_THRESHOLD_REACHED)
    {
        // Receiver should have the thershold number of bytes in the receive buffer
        nBytesAvailable = UART1_ReadCountGet();
        
        nBytesRead += UART1_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable);
    }
}

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

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

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

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

Remarks

None