Espressif ESP32-S2 Programming Manual page 960

Table of Contents

Advertisement

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[]
char *pcStringToSend
const TickType_t x100ms
//
Send an array to the message buffer, blocking
//
wait
for
enough space to be available
xBytesSent
=
xMessageBufferSend( xMessageBuffer, ( void
sizeof( ucArrayToSend ), x100ms );
if( xBytesSent
{
//
The call to xMessageBufferSend() times out before there was enough
//
space
in
}
//
Send the string to the message
//
not
enough space
xBytesSent
=
xMessageBufferSend( xMessageBuffer, ( void
strlen( pcStringToSend ),
if( xBytesSent
{
//
The string could
//
not
enough free space
}
}
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 message's 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-
Espressif Systems
=
{ 0, 1, 2,
=
"String to
send";
=
pdMS_TO_TICKS(
!=
sizeof( ucArrayToSend ) )
the buffer
for
the data to be
buffer.
in
the
buffer.
0
);
!=
strlen( pcStringToSend ) )
not
be added to the message buffer because there was
in
the
TaskWoken)
Submit Document Feedback
3
};
100
);
for
a maximum of 100ms to
in
the message
written.
Return immediately
buffer.
949
buffer.
*
)
ucArrayToSend,␣
if
there
is
*
)
pcStringToSend,␣
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF