FreeRTOS-Cpp
|
Base class that provides the standard message buffer interface to FreeRTOS::MessageBuffer and FreeRTOS::StaticMessageBuffer. More...
#include <FreeRTOS/MessageBuffer.hpp>
Public Member Functions | |
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. More... | |
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 ) More... | |
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 ) More... | |
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 ) More... | |
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 ) More... | |
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 ) More... | |
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 ) More... | |
size_t | spacesAvailable () const |
Function that calls size_t xMessageBufferSpacesAvailable( MessageBufferHandle_t xMessageBuffer ) More... | |
bool | reset () const |
Function that calls BaseType_t xMessageBufferReset( MessageBufferHandle_t xMessageBuffer ) More... | |
bool | isEmpty () const |
Function that calls BaseType_t xMessageBufferIsEmpty( MessageBufferHandle_t xMessageBuffer ) More... | |
bool | isFull () const |
Function that calls BaseType_t xMessageBufferIsFull( MessageBufferHandle_t xMessageBuffer ) More... | |
Private Member Functions | |
~MessageBufferBase () | |
Destroy the MessageBufferBase object by calling void vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer ) More... | |
MessageBufferBase (MessageBufferBase &&) noexcept=default | |
MessageBufferBase & | operator= (MessageBufferBase &&) noexcept=default |
Private Attributes | |
MessageBufferHandle_t | handle = NULL |
Friends | |
class | MessageBuffer |
template<size_t > | |
class | StaticMessageBuffer |
Base class that provides the standard message buffer interface to FreeRTOS::MessageBuffer and FreeRTOS::StaticMessageBuffer.
|
inlineprivate |
Destroy the MessageBufferBase object by calling void vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer )
Delete a queue - freeing all the memory allocated for storing of items placed on the queue.
|
inline |
Function that calls BaseType_t xMessageBufferIsEmpty( MessageBufferHandle_t xMessageBuffer )
Queries a message buffer to see if it is empty. A message buffer is empty if it does not contain any messages.
true | If the message buffer is empty. |
false | Otherwise. |
|
inline |
Function that calls BaseType_t xMessageBufferIsFull( MessageBufferHandle_t xMessageBuffer )
Queries a message buffer to see if it is full. A message buffer is full if it cannot accept any more messages, of any size, until space is made available by a message being removed from the message buffer.
true | If the message buffer is full. |
false | Otherwise. |
|
inline |
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.
true | If the handle is not NULL. |
false | If the handle is NULL. |
|
inline |
Function that calls size_t xMessageBufferReceive( MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait )
Use receive() to read from a message buffer from a task. UsereceiveFromISR() to read from a message buffer from an interrupt service routine (ISR).
buffer | A pointer to the buffer into which the received message is to be copied. |
bufferLength | The length of the buffer pointed to by the buffer parameter. This sets the maximum length of the message that can be received. If bufferLength is too small to hold the next message then the message will be left in the message buffer and 0 will be returned. |
ticksToWait | The maximum amount of time the task should remain in the Blocked state to wait for a message, should the message buffer be empty. receive() will return immediately if ticksToWait is zero and the message buffer is empty. 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. |
Example Usage
|
inline |
Function that calls size_t xMessageBufferReceiveFromISR( MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
Use receive() to read from a message buffer from a task. UsereceiveFromISR() to read from a message buffer from an interrupt service routine (ISR).
higherPriorityTaskWoken | It is possible that a message buffer will have a task blocked on it waiting for space to become available. Calling receiveFromISR() can make space available, and so cause a task that is waiting for space to leave the Blocked state. If calling receiveFromISR() 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, receiveFromISR() will set higherPriorityTaskWoken to true. If receiveFromISR() sets this value to true, then normally a context switch should be performed before the interrupt is exited. That will ensure 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. |
buffer | A pointer to the buffer into which the received message is to be copied. |
bufferLength | The length of the buffer pointed to by the buffer parameter. This sets the maximum length of the message that can be received. If bufferLength is too small to hold the next message then the message will be left in the message buffer and 0 will be returned. |
Example Usage
|
inline |
Function that calls size_t xMessageBufferReceiveFromISR( MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Function that calls BaseType_t xMessageBufferReset( MessageBufferHandle_t xMessageBuffer )
Resets a message buffer to its initial, empty, state. Any data that was in the message buffer is discarded. A message buffer can only be reset if there are no tasks blocked waiting to either send to or receive from the message buffer.
true | If the message buffer is reset. |
false | If there was a task blocked waiting to send to or read from the message buffer then the message buffer will not be reset. |
|
inline |
Function that calls size_t xMessageBufferSend( MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait )
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).
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. |
Example Usage
|
inline |
Function that calls size_t xMessageBufferSendFromISR( MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
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).
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). |
Example Usage
|
inline |
Function that calls size_t xMessageBufferSendFromISR( MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Function that calls size_t xMessageBufferSpacesAvailable( MessageBufferHandle_t xMessageBuffer )
Queries a message buffer to see how much free space it contains, which is equal to the amount of data that can be sent to the message buffer before it is full. The returned value is 4 bytes larger than the maximum message size that can be sent to the message buffer.