EasyManua.ls Logo

Espressif ESP32-S2 - Page 953

Espressif ESP32-S2
1695 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 2. API Reference
void vAFunction( StreamBuffer_t xStreamBuffer )
{
uint8_t ucRxData[ 20 ];
size_t xReceivedBytes;
const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
// Receive up to another sizeof( ucRxData ) bytes from the stream buffer.
// Wait in the Blocked state (so not using any CPU processing time) for a
// maximum of 100ms for the full sizeof( ucRxData ) number of bytes to be
// available.
xReceivedBytes = xStreamBufferReceive( xStreamBuffer,
( void * ) ucRxData,
sizeof( ucRxData ),
xBlockTime );
if( xReceivedBytes > 0 )
{
// A ucRxData contains another xRecievedBytes bytes of data, which can
// be processed here....
}
}
Return The number of bytes actually read from the stream buffer, which will be less than xBufferLengthBytes
if the call to xStreamBufferReceive() timed out before xBufferLengthBytes were available.
Parameters
xStreamBuffer: The handle of the stream buffer from which bytes are to be received.
pvRxData: A pointer to the buffer into which the received bytes will be copied.
xBufferLengthBytes: The length of the buffer pointed to by the pvRxData parameter. This
sets the maximum number of bytes to receive in one call. xStreamBufferReceive will return as many
bytes as possible up to a maximum set by xBufferLengthBytes.
xTicksToWait: The maximum amount of time the task should remain in the Blocked state to
wait for data to become available if the stream buffer is empty. xStreamBufferReceive() will return
immediately if xTicksToWait is zero. The block time is specified in tick periods, so the absolute
time it represents is dependent on the tick frequency. The macro pdMS_TO_TICKS() can be used
to convert a time specified in milliseconds into a time specified in ticks. Setting xTicksToWait
to portMAX_DELAY will cause the task to wait indefinitely (without timing out), provided IN-
CLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. A task does not use any CPU time when
it is in the Blocked state.
size_t xStreamBufferReceiveFromISR(StreamBuerHandle_t xStreamBuer, void *pvRxData,
size_t xBuerLengthBytes, BaseType_t *const pxHigher-
PriorityTaskWoken)
An interrupt safe version of the API function that receives bytes from a stream buffer.
Use xStreamBufferReceive() to read bytes from a stream buffer from a task. Use xStreamBufferReceive-
FromISR() to read bytes from a stream buffer from an interrupt service routine (ISR).
Example use:
// A stream buffer that has already been created.
StreamBuffer_t xStreamBuffer;
void vAnInterruptServiceRoutine( void )
{
uint8_t ucRxData[ 20 ];
size_t xReceivedBytes;
BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
// Receive the next stream from the stream buffer.
xReceivedBytes = xStreamBufferReceiveFromISR( xStreamBuffer,
( void * ) ucRxData,
(continues on next page)
Espressif Systems 942
Submit Document Feedback
Release v4.4

Table of Contents