EasyManua.ls Logo

Espressif ESP32-S2 - Page 951

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
(continued from previous page)
// space in the buffer for the data to be written, but it did
// successfully write xBytesSent bytes.
}
// Send the string to the stream buffer. Return immediately if there is not
// enough space in the buffer.
xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) pcStringToSend,
,strlen( pcStringToSend ), 0 );
if( xBytesSent != strlen( pcStringToSend ) )
{
// The entire string could not be added to the stream buffer because
// there was not enough free space in the buffer, but xBytesSent bytes
// were sent. Could try again to send the remaining bytes.
}
}
Return The number of bytes written to the stream buffer. If a task times out before it can write all xDataL-
engthBytes into the buffer it will still write as many bytes as possible.
Parameters
xStreamBuffer: The handle of the stream buffer to which a stream is being sent.
pvTxData: A pointer to the buffer that holds the bytes to be copied into the stream buffer.
xDataLengthBytes: The maximum number of bytes to copy from pvTxData into the stream
buffer.
xTicksToWait: The maximum amount of time the task should remain in the Blocked state to wait
for enough space to become available in the stream buffer, should the stream buffer contain too little
space to hold the another xDataLengthBytes bytes. 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 xTick-
sToWait to portMAX_DELAY will cause the task to wait indefinitely (without timing out), provided
INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. If a task times out before it can write
all xDataLengthBytes into the buffer it will still write as many bytes as possible. A task does not use
any CPU time when it is in the blocked state.
size_t xStreamBufferSendFromISR(StreamBuerHandle_t xStreamBuer, const void *pvTxData,
size_t xDataLengthBytes, BaseType_t *const pxHigherPriori-
tyTaskWoken)
Interrupt safe version of the API function that sends a stream of bytes to the stream buffer.
***NOTE***: Uniquely among FreeRTOS objects, the stream buffer implementation (so also the message
buffer implementation, as message buffers are built on top of stream buffers) assumes there is only one task
or interrupt that will write to the buffer (the writer), and only one task or interrupt that will read from the
buffer (the reader). It is safe for the writer and reader to be different tasks or interrupts, but, unlike other
FreeRTOS objects, it is not safe to have multiple different writers or multiple different readers. If there are to
be multiple different writers then the application writer must place each call to a writing API function (such
as xStreamBufferSend()) inside a critical section and set the send block time to 0. Likewise, if there are to be
multiple different readers then the application writer must place each call to a reading API function (such as
xStreamBufferReceive()) inside a critical section and set the receive block time to 0.
Use xStreamBufferSend() to write to a stream buffer from a task. Use xStreamBufferSendFromISR() to write
to a stream buffer from an interrupt service routine (ISR).
Example use:
// A stream buffer that has already been created.
StreamBufferHandle_t xStreamBuffer;
void vAnInterruptServiceRoutine( void )
{
size_t xBytesSent;
char *pcStringToSend = "String to send";
(continues on next page)
Espressif Systems 940
Submit Document Feedback
Release v4.4

Table of Contents