1.24.23.19 UARTx_ReadCountGet Function

C

/* x = UART instance number */

/* Non-blocking and ring buffer mode */

size_t UARTx_ReadCountGet( void )

Summary

Non-blocking mode

Gets the byte count of processed bytes for a given UART read operation

Ring buffer mode

Returns the number of bytes available in the internal receive buffer of the PLIB

Description

Non-blocking mode

This function gets the count of processed bytes for an on-going or last completed UART Read operation. This function can be used to track the progress of the non-blocking read operation. In case of an error, this function can be used to track the number of bytes that were received before the error occurred.

Ring buffer mode

This function returns the number of bytes available in the receive buffer

Precondition

UARTx_Initialize must have been called for the associated UART instance.

Parameters

None.

Returns

Non-blocking mode

Returns count of bytes completed/processed to the current Receive buffer. In 9-bit mode, it returns the number of 9-bit data processed.

Ring buffer mode

The API returns the number of bytes pending to be read out from the receive buffer. If 9-bit mode is enabled, then the API returns the number of 9-bit data pending to be read out from the receive buffer.

Example

Non-blocking mode

size_t count;

count = UART1_ReadCountGet();

if(count < COUNT_EXPECTED)
{
    //More bytes are expected, wait
}

Ring buffer mode

uint8_t rxBuffer[100];
uint32_t nBytesAvailable;

nBytesAvailable = UART1_ReadCountGet();

if (nBytesAvailable != 0)
{
    UART1_Read((uint8_t*)rxBuffer, nBytesAvailable)
}

Remarks

None