1.40.20.15 SERCOMx_USART_ReadNotificationEnable Function

C

/* x = SERCOM instance number */

/* Ring buffer mode */

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

SERCOMx_USART_Initialize must have been called for the associated SERCOM_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(SERCOM_USART_EVENT event, uintptr_t context )
{
    uint32_t nBytesAvailable = 0;
    
    if (event == SERCOM_USART_EVENT_READ_THRESHOLD_REACHED)
    {
        // Receiver should have the thershold number of bytes in the receive buffer
        nBytesAvailable = SERCOM0_USART_ReadCountGet();
        
        nBytesRead += SERCOM0_USART_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable);
    }
}

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

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

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

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

Remarks

None