EasyManua.ls Logo

Espressif ESP32-S2 - Page 960

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
be multiple different writers then the application writer must place each call to a writing API function (such as
xMessageBufferSend()) 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
xMessageBufferRead()) inside a critical section and set the receive block time to 0.
Use xMessageBufferSend() to write to a message buffer from a task. Use xMessageBufferSendFromISR() to
write to a message buffer from an interrupt service routine (ISR).
Example use:
void vAFunction( MessageBufferHandle_t xMessageBuffer )
{
size_t xBytesSent;
uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
char *pcStringToSend = "String to send";
const TickType_t x100ms = pdMS_TO_TICKS( 100 );
// Send an array to the message buffer, blocking for a maximum of 100ms to
// wait for enough space to be available in the message buffer.
xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) ucArrayToSend,
,sizeof( ucArrayToSend ), x100ms );
if( xBytesSent != sizeof( ucArrayToSend ) )
{
// The call to xMessageBufferSend() times out before there was enough
// space in the buffer for the data to be written.
}
// Send the string to the message buffer. Return immediately if there is
// not enough space in the buffer.
xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) pcStringToSend,
,strlen( pcStringToSend ), 0 );
if( xBytesSent != strlen( pcStringToSend ) )
{
// The string could not be added to the message buffer because there was
// not enough free space in the buffer.
}
}
Return The number of bytes written to the message buffer. If the call to xMessageBufferSend() times out
before there was enough space to write the message into the message buffer then zero is returned. If the
call did not time out then xDataLengthBytes is returned.
Parameters
xMessageBuffer: The handle of the message buffer to which a message is being sent.
pvTxData: A pointer to the message that is to be copied into the message buffer.
xDataLengthBytes: The length of the message. That is, the number of bytes to copy from
pvTxData into the message buffer. When a message is written to the message buffer an additional
sizeof( size_t ) bytes are also written to store the messages length. sizeof( size_t ) is typically 4
bytes on a 32-bit architecture, so on most 32-bit architecture setting xDataLengthBytes to 20 will
reduce the free space in the message buffer by 24 bytes (20 bytes of message data and 4 bytes to
hold the message length).
xTicksToWait: The maximum amount of time the calling task should remain in the Blocked
state to wait for enough space to become available in the message buffer, should the message buffer
have insufficient space when xMessageBufferSend() is called. The calling task will never block 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 INCLUDE_vTaskSuspend is
set to 1 in FreeRTOSConfig.h. Tasks do not use any CPU time when they are in the Blocked state.
xMessageBufferSendFromISR(xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriority-
TaskWoken)
Espressif Systems 949
Submit Document Feedback
Release v4.4

Table of Contents