1.34.27.1 USARTx_WriteThresholdSet Function

C

/* x = USART instance number */

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

USARTx_Initialize must have been called for the associated USART instance.

Parameters

Param Description
nBytesThreshold Threshold value for free space in the transmit buffer afterwhich a notification must be given

Returns

None

Example

uint8_t txBuffer[10];

volatile bool txThresholdEventReceived = false;

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

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

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

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

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

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

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

Remarks

None