1.2.21.14 1.3.25.14 1.4.21.14 1.5.25.14 1.6.22.14 1.7.23.14 1.9.19.14 1.29.23.14 1.30.18.14 1.31.18.14 1.32.26.14 1.33.16.14 1.37.18.14 1.38.21.14 1.39.18.14 1.40.20.14 SERCOMx_USART_ReadThresholdSet Function

C

/* x = SERCOM instance number */

/* Ring buffer mode */

void SERCOMx_USART_ReadThresholdSet(uint32_t nBytesThreshold)

Summary

This API allows the application to set a threshold level on the number of bytes of data available in the receive buffer

Description

This API allows the application to set a threshold level on the number of bytes of data available in the receive buffer. Once the threshold is reached a notification is given to the application if it is enabled.

Precondition

SERCOMx_USART_Initialize must have been called for the associated SERCOM_USART instance.

Parameters

Param Description
nBytesThreshold Threshold value for number of bytes available in the receivebuffer after which a notification must be given

Returns

None

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 ring 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