1.34.27.14 USARTx_ReadThresholdSet Function

C

/* x = USART instance number */

/* Ring buffer mode */
void USARTx_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

USARTx_Initialize must have been called for the associated USART instance.

Parameters

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

Returns

None

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