28#ifndef FREERTOS_QUEUE_HPP
29#define FREERTOS_QUEUE_HPP
55 template <
class, UBaseType_t>
61 static void*
operator new(size_t) =
delete;
62 static void*
operator new[](size_t) =
delete;
64 static void*
operator new(size_t,
void* ptr) {
68 static void*
operator new[](size_t,
void* ptr) {
111 const TickType_t ticksToWait = portMAX_DELAY)
const {
112 return (xQueueSendToBack(
handle, &item, ticksToWait) == pdTRUE);
134 const T& item)
const {
135 BaseType_t taskWoken = pdFALSE;
137 (xQueueSendToBackFromISR(
handle, &item, &taskWoken) == pdPASS);
138 if (taskWoken == pdTRUE) {
139 higherPriorityTaskWoken =
true;
155 return (xQueueSendToBackFromISR(
handle, &item, NULL) == pdPASS);
179 const TickType_t ticksToWait = portMAX_DELAY)
const {
180 return (xQueueSendToFront(
handle, &item, ticksToWait) == pdTRUE);
202 const T& item)
const {
203 BaseType_t taskWoken = pdFALSE;
205 (xQueueSendToFrontFromISR(
handle, &item, &taskWoken) == pdPASS);
206 if (taskWoken == pdTRUE) {
207 higherPriorityTaskWoken =
true;
223 return (xQueueSendToFrontFromISR(
handle, &item, NULL) == pdPASS);
251 const TickType_t ticksToWait = portMAX_DELAY)
const {
253 return (xQueueReceive(
handle, &buffer, ticksToWait) == pdTRUE)
254 ? std::optional<T>(buffer)
281 BaseType_t taskWoken = pdFALSE;
282 bool result = (xQueueReceiveFromISR(
handle, &buffer, &taskWoken) == pdTRUE);
283 if (taskWoken == pdTRUE) {
284 higherPriorityTaskWoken =
true;
286 return result ? std::optional<T>(buffer) : std::nullopt;
302 return (xQueueReceiveFromISR(
handle, &buffer, NULL) == pdTRUE)
303 ? std::optional<T>(buffer)
320 return uxQueueMessagesWaiting(
handle);
337 return uxQueueMessagesWaitingFromISR(
handle);
353 return uxQueueSpacesAvailable(
handle);
393 xQueueOverwrite(
handle, &item);
423 const T& item)
const {
424 BaseType_t taskWoken = pdFALSE;
425 xQueueOverwriteFromISR(
handle, &item, &taskWoken);
426 if (taskWoken == pdTRUE) {
427 higherPriorityTaskWoken =
true;
443 xQueueOverwriteFromISR(
handle, &item, NULL);
476 const TickType_t ticksToWait = portMAX_DELAY)
const {
478 return (xQueuePeek(
handle, &buffer, ticksToWait) == pdTRUE)
479 ? std::optional<T>(buffer)
504 return (xQueuePeekFromISR(
handle, &buffer) == pdTRUE)
505 ? std::optional<T>(buffer)
539 vQueueAddToRegistry(
handle, name);
558 vQueueUnregisterQueue(
handle);
577 return pcQueueGetName(
handle);
595 return (xQueueIsQueueFullFromISR(
handle) == pdTRUE);
613 return (xQueueIsQueueEmptyFromISR(
handle) == pdTRUE);
640 vQueueDelete(this->
handle);
652#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
687 explicit Queue(
const UBaseType_t length) {
688 this->
handle = xQueueCreate(length,
sizeof(T));
701#if (configSUPPORT_STATIC_ALLOCATION == 1)
715template <
class T, UBaseType_t N>
736 this->handle = xQueueCreateStatic(N,
sizeof(T), storage, &staticQueue);
747 StaticQueue_t staticQueue;
748 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:133
bool isFullFromISR() const
Function that calls BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
Definition Queue.hpp:594
bool sendToFrontFromISR(const T &item) const
Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition Queue.hpp:222
std::optional< T > peekFromISR() const
Function that calls BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void *pvBuffer )
Definition Queue.hpp:502
void overwriteFromISR(bool &higherPriorityTaskWoken, const T &item) const
Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQue...
Definition Queue.hpp:422
QueueHandle_t handle
Handle used to refer to the queue when using the FreeRTOS interface.
Definition Queue.hpp:649
bool sendToBackFromISR(const T &item) const
Function that calls xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition Queue.hpp:154
void reset() const
Function that calls BaseType_t xQueueReset( QueueHandle_t xQueue )
Definition Queue.hpp:366
UBaseType_t messagesWaitingFromISR() const
Function that calls UBaseType_t uxQueueMessagesWaitingFromISR( QueueHandle_t xQueue )
Definition Queue.hpp:336
std::optional< T > receiveFromISR(bool &higherPriorityTaskWoken) const
Function that calls BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer,...
Definition Queue.hpp:279
UBaseType_t messagesWaiting() const
Function that calls UBaseType_t uxQueueMessagesWaiting( QueueHandle_t xQueue )
Definition Queue.hpp:319
UBaseType_t spacesAvailable() const
Function that calls UBaseType_t uxQueueSpacesAvailable( QueueHandle_t xQueue )
Definition Queue.hpp:352
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:250
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:538
std::optional< T > receiveFromISR() const
Function that calls BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer,...
Definition Queue.hpp:300
void unregister() const
Function that calls void vQueueUnregisterQueue( QueueHandle_t xQueue )
Definition Queue.hpp:557
void overwriteFromISR(const T &item) const
Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQue...
Definition Queue.hpp:442
bool sendToBack(const T &item, const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait )
Definition Queue.hpp:110
const char * getName() const
Function that calls const char *pcQueueGetName( QueueHandle_t xQueue )
Definition Queue.hpp:576
void overwrite(const T &item) const
Function that calls BaseType_t xQueueOverwrite( QueueHandle_t xQueue, const void * pvItemToQueue )
Definition Queue.hpp:392
bool sendToFrontFromISR(bool &higherPriorityTaskWoken, const T &item) const
Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition Queue.hpp:201
bool isEmptyFromISR() const
Function that calls BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )
Definition Queue.hpp:612
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:475
bool sendToFront(const T &item, const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait )
Definition Queue.hpp:178
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:81
~QueueBase()
Destroy the QueueBase object by calling void vQueueDelete( QueueHandle_t xQueue )
Definition Queue.hpp:639
Class that encapsulates the functionality of a FreeRTOS queue.
Definition Queue.hpp:667
Queue(const UBaseType_t length)
Construct a new Queue object by calling QueueHandle_t xQueueCreate( UBaseType_t uxQueueLength,...
Definition Queue.hpp:687
Class that encapsulates the functionality of a FreeRTOS queue.
Definition Queue.hpp:716
StaticQueue()
Construct a new StaticQueue object by calling QueueHandle_t xQueueCreateStatic( UBaseType_t uxQueueLe...
Definition Queue.hpp:735