1.42.3.17 FLEXCOMx_USART_ReadCountGet Function
C
/* x = FLEXCOM instance number */
/* Non-blocking and ring buffer mode */
size_t FLEXCOMx_USART_ReadCountGet( void )
Summary
Non-blocking mode
Gets the byte count of processed bytes for a given USART 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 USART 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
FLEXCOMx_USART_Initialize must have been called for the associated USART 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 = FLEXCOM0_USART_ReadCountGet(); if(count < COUNT_EXPECTED) { //More bytes are expected, wait }
Ring buffer mode
uint8_t rxBuffer[100]; uint32_t nBytesAvailable; nBytesAvailable = FLEXCOM0_USART_ReadCountGet(); if (nBytesAvailable != 0) { FLEXCOM0_USART_Read((uint8_t*)rxBuffer, nBytesAvailable) }
Remarks
None