1.2.21.1 1.3.25.1 1.4.21.1 1.5.25.1 1.6.22.1 1.7.23.1 1.9.19.1 1.29.23.1 1.30.18.1 1.31.18.1 1.32.26.1 1.33.16.1 1.37.18.1 1.38.21.1 1.39.18.1 1.40.20.1 SERCOMx_USART_WriteThresholdSet Function

C

/* x = SERCOM instance number */

/* Ring buffer mode */

void SERCOMx_USART_WriteThresholdSet(uint32_t nBytesThreshold)

Summary

This API allows the application to set a threshold level on the number of free space available in the transmit buffer

Description

This API allows the application to set a threshold level on the number of free space available in the transmit 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 free space in the transmit buffer after which a notification must be given

Returns

None

Example

uint8_t txBuffer[10];

volatile bool txThresholdEventReceived = false;

void usartWriteEventHandler(SERCOM_USART_EVENT event, uintptr_t context )
{
    txThresholdEventReceived = true;
}

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

// Register a callback for write events
SERCOM0_USART_WriteCallbackRegister(usartWriteEventHandler, (uintptr_t) NULL);

// Set TX threshold - 10 or more bytes of free space in the transmit buffer
SERCOM0_USART_WriteThresholdSet(10);

// Enable notifications. Disable persistent notifications.
SERCOM0_USART_WriteNotificationEnable(true, false);

// First time transmit 5 bytes
SERCOM0_USART_Write((uint8_t*)txBuffer, 5);

if (txThresholdEventReceived == true)
{
    // Transmit buffer has space for 10 or more characters
    SERCOM0_USART_Write((uint8_t*)txBuffer, 10);
}

Remarks

None