Chapter 2. API Reference
on it waiting for data. Calling xMessageBufferSendFromISR() can make data available, and so cause
a task that was waiting for data to leave the Blocked state. If calling xMessageBufferSendFromISR()
causes a task to leave the Blocked state, and the unblocked task has a priority higher than the currently
executing task (the task that was interrupted), then, internally, xMessageBufferSendFromISR() will
set *pxHigherPriorityTaskWoken to pdTRUE. If xMessageBufferSendFromISR() sets this value to
pdTRUE, then normally a context switch should be performed before the interrupt is exited. This
will ensure that the interrupt returns directly to the highest priority Ready state task. *pxHigher-
PriorityTaskWoken should be set to pdFALSE before it is passed into the function. See the code
example below for an example.
xMessageBufferReceive(xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait)
Receives a discrete message from a message buffer. Messages can be of variable length and are copied out of
the 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
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 xMessageBufferReceive() to read from a message buffer from a task. Use xMessageBufferReceive-
FromISR() to read from a message buffer from an interrupt service routine (ISR).
Example use:
void vAFunction( MessageBuffer_t xMessageBuffer )
{
uint8_t ucRxData[
size_t xReceivedBytes;
const TickType_t xBlockTime
//
Receive the
//
state (so
not
//
a message to become
xReceivedBytes
if( xReceivedBytes
{
//
A ucRxData contains a message that
//
the message
}
}
Return The length, in bytes, of the message read from the message buffer, if any. If xMessageBufferReceive()
times out before a message became available then zero is returned. If the length of the message is greater
than xBufferLengthBytes then the message will be left in the message buffer and zero is returned.
Parameters
• xMessageBuffer: The handle of the message buffer from which a message is being received.
• pvRxData: A pointer to the buffer into which the received message is to be copied.
• xBufferLengthBytes: The length of the buffer pointed to by the pvRxData parameter. This
sets the maximum length of the message that can be received. If xBufferLengthBytes is too small
to hold the next message then the message will be left in the message buffer and 0 will be returned.
• xTicksToWait: The maximum amount of time the task should remain in the Blocked state to
wait for a message, should the message buffer be empty. xMessageBufferReceive() will return im-
mediately if xTicksToWait is zero and the message buffer is empty. The block time is specified
Espressif Systems
20
];
=
pdMS_TO_TICKS(
next
message
from
the
using
any
CPU processing time)
available.
=
xMessageBufferReceive( xMessageBuffer,
>
0
)
here....
Submit Document Feedback
20
);
message
buffer.
for
a maximum of 100ms
( void
*
) ucRxData,
sizeof( ucRxData ),
xBlockTime );
is
xReceivedBytes
951
Wait
in
the Blocked
for
long.
Process
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?