|
|
| MessageBufferBase (const MessageBufferBase &)=delete |
| |
|
MessageBufferBase & | operator= (const MessageBufferBase &)=delete |
| |
| bool | isValid () const |
| | Function that checks if the underlying message buffer handle is not NULL. This should be used to ensure a message buffer has been created correctly.
|
| |
| size_t | send (const void *data, const size_t length, const TickType_t ticksToWait=portMAX_DELAY) const |
| | Function that calls size_t xMessageBufferSend(
MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t
xDataLengthBytes, TickType_t xTicksToWait )
|
| |
| size_t | sendFromISR (bool &higherPriorityTaskWoken, const void *data, const size_t length) const |
| | Function that calls size_t xMessageBufferSendFromISR(
MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t
xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
|
| |
| size_t | sendFromISR (const void *data, const size_t length) const |
| | Function that calls size_t xMessageBufferSendFromISR(
MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t
xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
|
| |
| size_t | receive (void *buffer, const size_t bufferLength, const TickType_t ticksToWait=portMAX_DELAY) const |
| | Function that calls size_t xMessageBufferReceive(
MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t
xBufferLengthBytes, TickType_t xTicksToWait )
|
| |
| size_t | receiveFromISR (bool &higherPriorityTaskWoken, void *buffer, const size_t bufferLength) const |
| | Function that calls size_t xMessageBufferReceiveFromISR(
MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t
xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
|
| |
| size_t | receiveFromISR (void *buffer, const size_t bufferLength) const |
| | Function that calls size_t xMessageBufferReceiveFromISR(
MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t
xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
|
| |
| size_t | spacesAvailable () const |
| | Function that calls size_t xMessageBufferSpacesAvailable(
MessageBufferHandle_t xMessageBuffer )
|
| |
| bool | reset () const |
| | Function that calls BaseType_t xMessageBufferReset(
MessageBufferHandle_t xMessageBuffer )
|
| |
| bool | isEmpty () const |
| | Function that calls BaseType_t xMessageBufferIsEmpty(
MessageBufferHandle_t xMessageBuffer )
|
| |
| bool | isFull () const |
| | Function that calls BaseType_t xMessageBufferIsFull(
MessageBufferHandle_t xMessageBuffer )
|
| |
Base class that provides the standard message buffer interface to FreeRTOS::MessageBuffer and FreeRTOS::StaticMessageBuffer.
- Note
- This class is not intended to be instantiated by the user. Use FreeRTOS::MessageBuffer or FreeRTOS::StaticMessageBuffer.
- Warning
- 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 send()) 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 read()) inside a critical section and set the receive block time to 0.
| size_t FreeRTOS::MessageBufferBase::send |
( |
const void * |
data, |
|
|
const size_t |
length, |
|
|
const TickType_t |
ticksToWait = portMAX_DELAY |
|
) |
| const |
|
inline |
Function that calls size_t xMessageBufferSend(
MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t
xDataLengthBytes, TickType_t xTicksToWait )
MessageBuffer.hpp
- See also
- https://www.freertos.org/xMessageBufferSend.html
Sends a discrete message to the message buffer. The message can be any length that fits within the buffer's free space, and is copied into the buffer.
Use send() to write to a message buffer from a task. Use sendFromISR() to write to a message buffer from an interrupt service routine (ISR).
- Parameters
-
| data | A pointer to the message that is to be copied into the message buffer. |
| length | The length of the message. That is, the number of bytes to copy from data 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 length 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). |
| ticksToWait | 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 send() is called. The calling task will never block if ticksToWait 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 ticksToWait 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. |
- Returns
- size_t The number of bytes written to the message buffer. If the call to send() 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 length is returned.
Example Usage
#include <FreeRTOS/MessageBuffer.hpp>
#include <FreeRTOS/Task.hpp>
#include <cstring>
public:
MyTask() : messageBuffer(100) {}
void taskFunction() final;
};
void MyTask::taskFunction() {
size_t xBytesSent;
uint8_t ucArrayToSend[] = {0, 1, 2, 3};
char const *pcStringToSend = "String to send";
xBytesSent = messageBuffer.
send(ucArrayToSend,
sizeof(ucArrayToSend),
pdMS_TO_TICKS(100));
if (xBytesSent != sizeof(ucArrayToSend)) {
}
xBytesSent = messageBuffer.send(pcStringToSend, strlen(pcStringToSend), 0);
if (xBytesSent != strlen(pcStringToSend)) {
}
}
size_t send(const void *data, const size_t length, const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls size_t xMessageBufferSend( MessageBufferHandle_t xMessageBuffer,...
Definition MessageBuffer.hpp:137
| size_t FreeRTOS::MessageBufferBase::sendFromISR |
( |
bool & |
higherPriorityTaskWoken, |
|
|
const void * |
data, |
|
|
const size_t |
length |
|
) |
| const |
|
inline |
Function that calls size_t xMessageBufferSendFromISR(
MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t
xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
MessageBuffer.hpp
- See also
- https://www.freertos.org/xMessageBufferSendFromISR.html
Interrupt safe version of the API function that sends a discrete message to the message buffer. The message can be any length that fits within the buffer's free space, and is copied into the buffer.
Use send() to write to a message buffer from a task. Use sendFromISR() to write to a message buffer from an interrupt service routine (ISR).
- Parameters
-
| higherPriorityTaskWoken | It is possible that a message buffer will have a task blocked on it waiting for data. Calling sendFromISR() can make data available, and so cause a task that was waiting for data to leave the Blocked state. If calling sendFromISR() 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, sendFromISR() will set higherPriorityTaskWoken to true. If sendFromISR() sets this value to true, 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. higherPriorityTaskWoken should be set to false before it is passed into the function. See the code example below for an example. |
| data | A pointer to the message that is to be copied into the message buffer. |
| length | The length of the message. That is, the number of bytes to copy from data 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 length 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). |
- Returns
- size_t The number of bytes actually written to the message buffer. If the message buffer didn't have enough free space for the message to be stored then 0 is returned, otherwise length is returned.
Example Usage
#include <FreeRTOS/Kernel.hpp>
#include <FreeRTOS/MessageBuffer.hpp>
#include <FreeRTOS/Task.hpp>
#include <cstring>
public:
MyTask() : messageBuffer(100) {}
void taskFunction() final;
};
MyTask task;
void anInterruptServiceRoutine() {
char const *pcStringToSend = "String to send";
bool higherPriorityTaskWoken = false;
size_t xBytesSent = task.messageBuffer.sendFromISR(
higherPriorityTaskWoken, pcStringToSend, sizeof(pcStringToSend));
if (xBytesSent != sizeof(pcStringToSend)) {
}
}