28 #ifndef FREERTOS_QUEUE_HPP
29 #define FREERTOS_QUEUE_HPP
55 template <
class, UBaseType_t>
61 static void*
operator new(size_t,
void* ptr) {
return ptr; }
62 static void*
operator new[](size_t,
void* ptr) {
return ptr; }
63 static void*
operator new(size_t) =
delete;
64 static void*
operator new[](size_t) =
delete;
103 const TickType_t ticksToWait = portMAX_DELAY)
const {
104 return (xQueueSendToBack(
handle, &item, ticksToWait) == pdTRUE);
126 const T& item)
const {
127 BaseType_t taskWoken = pdFALSE;
129 (xQueueSendToBackFromISR(
handle, &item, &taskWoken) == pdPASS);
130 if (taskWoken == pdTRUE) {
131 higherPriorityTaskWoken =
true;
147 return (xQueueSendToBackFromISR(
handle, &item, NULL) == pdPASS);
171 const TickType_t ticksToWait = portMAX_DELAY)
const {
172 return (xQueueSendToFront(
handle, &item, ticksToWait) == pdTRUE);
194 const T& item)
const {
195 BaseType_t taskWoken = pdFALSE;
197 (xQueueSendToFrontFromISR(
handle, &item, &taskWoken) == pdPASS);
198 if (taskWoken == pdTRUE) {
199 higherPriorityTaskWoken =
true;
215 return (xQueueSendToFrontFromISR(
handle, &item, NULL) == pdPASS);
243 const TickType_t ticksToWait = portMAX_DELAY)
const {
245 return (xQueueReceive(
handle, &buffer, ticksToWait) == pdTRUE)
246 ? std::optional<T>(buffer)
273 BaseType_t taskWoken = pdFALSE;
274 bool result = (xQueueReceiveFromISR(
handle, &buffer, &taskWoken) == pdTRUE);
275 if (taskWoken == pdTRUE) {
276 higherPriorityTaskWoken =
true;
278 return result ? std::optional<T>(buffer) : std::nullopt;
294 return (xQueueReceiveFromISR(
handle, &buffer, NULL) == pdTRUE)
295 ? std::optional<T>(buffer)
312 return uxQueueMessagesWaiting(
handle);
329 return uxQueueMessagesWaitingFromISR(
handle);
345 return uxQueueSpacesAvailable(
handle);
411 const T& item)
const {
412 BaseType_t taskWoken = pdFALSE;
413 xQueueOverwriteFromISR(
handle, &item, &taskWoken);
414 if (taskWoken == pdTRUE) {
415 higherPriorityTaskWoken =
true;
431 xQueueOverwriteFromISR(
handle, &item, NULL);
464 const TickType_t ticksToWait = portMAX_DELAY)
const {
466 return (xQueuePeek(
handle, &buffer, ticksToWait) == pdTRUE)
467 ? std::optional<T>(buffer)
492 return (xQueuePeekFromISR(
handle, &buffer) == pdTRUE)
493 ? std::optional<T>(buffer)
527 vQueueAddToRegistry(
handle, name);
579 return (xQueueIsQueueFullFromISR(
handle) == pdTRUE);
597 return (xQueueIsQueueEmptyFromISR(
handle) == pdTRUE);
634 #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
669 explicit Queue(
const UBaseType_t length) {
670 this->
handle = xQueueCreate(length,
sizeof(T));
683 #if (configSUPPORT_STATIC_ALLOCATION == 1)
697 template <
class T, UBaseType_t N>
718 this->
handle = xQueueCreateStatic(N,
sizeof(T), storage, &staticQueue);
729 StaticQueue_t staticQueue;
730 uint8_t storage[N * sizeof(T)];
Base class that provides the standard queue interface to FreeRTOS::Queue and FreeRTOS::StaticQueue.
Definition: Queue.hpp:50
bool sendToBackFromISR(bool &higherPriorityTaskWoken, const T &item) const
Function that calls xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition: Queue.hpp:125
const char * getName() const
Function that calls const char *pcQueueGetName( QueueHandle_t xQueue )
Definition: Queue.hpp:562
bool isFullFromISR() const
Function that calls BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
Definition: Queue.hpp:578
bool sendToFrontFromISR(const T &item) const
Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition: Queue.hpp:214
std::optional< T > peekFromISR() const
Function that calls BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void *pvBuffer )
Definition: Queue.hpp:490
void overwriteFromISR(bool &higherPriorityTaskWoken, const T &item) const
Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQue...
Definition: Queue.hpp:410
QueueHandle_t handle
Handle used to refer to the queue when using the FreeRTOS interface.
Definition: Queue.hpp:631
bool sendToBackFromISR(const T &item) const
Function that calls xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition: Queue.hpp:146
void reset() const
Function that calls BaseType_t xQueueReset( QueueHandle_t xQueue )
Definition: Queue.hpp:358
UBaseType_t messagesWaitingFromISR() const
Function that calls UBaseType_t uxQueueMessagesWaitingFromISR( QueueHandle_t xQueue )
Definition: Queue.hpp:328
UBaseType_t messagesWaiting() const
Function that calls UBaseType_t uxQueueMessagesWaiting( QueueHandle_t xQueue )
Definition: Queue.hpp:311
UBaseType_t spacesAvailable() const
Function that calls UBaseType_t uxQueueSpacesAvailable( QueueHandle_t xQueue )
Definition: Queue.hpp:344
std::optional< T > peek(const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer,...
Definition: Queue.hpp:463
QueueBase()=default
Construct a new QueueBase object.
void addToRegistry(const char *name) const
Function that calls void vQueueAddToRegistry( QueueHandle_t xQueue, char *pcQueueName )
Definition: Queue.hpp:526
void unregister() const
Function that calls void vQueueUnregisterQueue( QueueHandle_t xQueue )
Definition: Queue.hpp:545
void overwriteFromISR(const T &item) const
Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQue...
Definition: Queue.hpp:430
bool sendToBack(const T &item, const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait )
Definition: Queue.hpp:102
std::optional< T > receiveFromISR() const
Function that calls BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer,...
Definition: Queue.hpp:292
void overwrite(const T &item) const
Function that calls BaseType_t xQueueOverwrite( QueueHandle_t xQueue, const void * pvItemToQueue )
Definition: Queue.hpp:382
bool sendToFrontFromISR(bool &higherPriorityTaskWoken, const T &item) const
Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition: Queue.hpp:193
bool isEmptyFromISR() const
Function that calls BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )
Definition: Queue.hpp:596
std::optional< T > receive(const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls BaseType_t xQueueReceive( QueueHandle_t xQueue, void *pvBuffer,...
Definition: Queue.hpp:242
bool sendToFront(const T &item, const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait )
Definition: Queue.hpp:170
bool isValid() const
Function that checks if the underlying queue handle is not NULL. This should be used to ensure a queu...
Definition: Queue.hpp:75
~QueueBase()
Destroy the QueueBase object by calling void vQueueDelete( QueueHandle_t xQueue )
Definition: Queue.hpp:623
std::optional< T > receiveFromISR(bool &higherPriorityTaskWoken) const
Function that calls BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer,...
Definition: Queue.hpp:271
Class that encapsulates the functionality of a FreeRTOS queue.
Definition: Queue.hpp:649
Queue(const UBaseType_t length)
Construct a new Queue object by calling QueueHandle_t xQueueCreate( UBaseType_t uxQueueLength,...
Definition: Queue.hpp:669
Class that encapsulates the functionality of a FreeRTOS queue.
Definition: Queue.hpp:698
StaticQueue()
Construct a new StaticQueue object by calling QueueHandle_t xQueueCreateStatic( UBaseType_t uxQueueLe...
Definition: Queue.hpp:717