FreeRTOS-Cpp
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
FreeRTOS::QueueBase< T > Class Template Reference

Base class that provides the standard queue interface to FreeRTOS::Queue and FreeRTOS::StaticQueue. More...

#include <FreeRTOS/Queue.hpp>

Inheritance diagram for FreeRTOS::QueueBase< T >:
Inheritance graph
[legend]

Public Member Functions

 QueueBase (const QueueBase &)=delete
 
QueueBaseoperator= (const QueueBase &)=delete
 
bool isValid () const
 Function that checks if the underlying queue handle is not NULL. This should be used to ensure a queue has been created correctly. More...
 
bool sendToBack (const T &item, const TickType_t ticksToWait=portMAX_DELAY) const
 Function that calls xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) More...
 
bool sendToBackFromISR (bool &higherPriorityTaskWoken, const T &item) const
 Function that calls xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) More...
 
bool sendToBackFromISR (const T &item) const
 Function that calls xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) More...
 
bool sendToFront (const T &item, const TickType_t ticksToWait=portMAX_DELAY) const
 Function that calls xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) More...
 
bool sendToFrontFromISR (bool &higherPriorityTaskWoken, const T &item) const
 Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) More...
 
bool sendToFrontFromISR (const T &item) const
 Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) More...
 
std::optional< T > receive (const TickType_t ticksToWait=portMAX_DELAY) const
 Function that calls BaseType_t xQueueReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait ) More...
 
std::optional< T > receiveFromISR (bool &higherPriorityTaskWoken) const
 Function that calls BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxHigherPriorityTaskWoken ) More...
 
std::optional< T > receiveFromISR () const
 Function that calls BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxHigherPriorityTaskWoken ) More...
 
UBaseType_t messagesWaiting () const
 Function that calls UBaseType_t uxQueueMessagesWaiting( QueueHandle_t xQueue ) More...
 
UBaseType_t messagesWaitingFromISR () const
 Function that calls UBaseType_t uxQueueMessagesWaitingFromISR( QueueHandle_t xQueue ) More...
 
UBaseType_t spacesAvailable () const
 Function that calls UBaseType_t uxQueueSpacesAvailable( QueueHandle_t xQueue ) More...
 
void reset () const
 Function that calls BaseType_t xQueueReset( QueueHandle_t xQueue ) More...
 
void overwrite (const T &item) const
 Function that calls BaseType_t xQueueOverwrite( QueueHandle_t xQueue, const void * pvItemToQueue ) More...
 
void overwriteFromISR (bool &higherPriorityTaskWoken, const T &item) const
 Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken ) More...
 
void overwriteFromISR (const T &item) const
 Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken ) More...
 
std::optional< T > peek (const TickType_t ticksToWait=portMAX_DELAY) const
 Function that calls BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) More...
 
std::optional< T > peekFromISR () const
 Function that calls BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void *pvBuffer ) More...
 
void addToRegistry (const char *name) const
 Function that calls void vQueueAddToRegistry( QueueHandle_t xQueue, char *pcQueueName ) More...
 
void unregister () const
 Function that calls void vQueueUnregisterQueue( QueueHandle_t xQueue ) More...
 
const char * getName () const
 Function that calls const char *pcQueueGetName( QueueHandle_t xQueue ) More...
 
bool isFullFromISR () const
 Function that calls BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) More...
 
bool isEmptyFromISR () const
 Function that calls BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) More...
 

Static Public Member Functions

static void * operator new (size_t, void *ptr)
 
static void * operator new[] (size_t, void *ptr)
 
static void * operator new (size_t)=delete
 
static void * operator new[] (size_t)=delete
 

Private Member Functions

 QueueBase ()=default
 Construct a new QueueBase object. More...
 
 ~QueueBase ()
 Destroy the QueueBase object by calling void vQueueDelete( QueueHandle_t xQueue ) More...
 
 QueueBase (QueueBase &&) noexcept=default
 
QueueBaseoperator= (QueueBase &&) noexcept=default
 

Private Attributes

QueueHandle_t handle = NULL
 Handle used to refer to the queue when using the FreeRTOS interface.
 

Friends

template<class >
class Queue
 
template<class , UBaseType_t >
class StaticQueue
 

Detailed Description

template<class T>
class FreeRTOS::QueueBase< T >

Base class that provides the standard queue interface to FreeRTOS::Queue and FreeRTOS::StaticQueue.

Note
This class is not intended to be instantiated by the user. Use FreeRTOS::Queue or FreeRTOS::StaticQueue.
Template Parameters
TType to be stored in the queue.

Constructor & Destructor Documentation

◆ QueueBase()

template<class T >
FreeRTOS::QueueBase< T >::QueueBase ( )
privatedefault

Construct a new QueueBase object.

Queue.hpp

Note
Default constructor is deliberately private as this class is not intended to be instantiated or derived from by the user. Use FreeRTOS::Queue or FreeRTOS::StaticQueue.

◆ ~QueueBase()

template<class T >
FreeRTOS::QueueBase< T >::~QueueBase ( )
inlineprivate

Destroy the QueueBase object by calling void vQueueDelete( QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/a00018.html#vQueueDelete

Delete a queue - freeing all the memory allocated for storing of items placed on the queue.

Member Function Documentation

◆ addToRegistry()

template<class T >
void FreeRTOS::QueueBase< T >::addToRegistry ( const char *  name) const
inline

Function that calls void vQueueAddToRegistry( QueueHandle_t xQueue, char *pcQueueName )

Queue.hpp

See also
https://www.freertos.org/vQueueAddToRegistry.html

The registry is provided as a means for kernel aware debuggers to locate queues, semaphores and mutexes. Call addToRegistry() add a queue, semaphore or mutex handle to the registry if you want the handle to be available to a kernel aware debugger. If you are not using a kernel aware debugger then this function can be ignored.

configQUEUE_REGISTRY_SIZE defines the maximum number of handles the registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0 within FreeRTOSConfig.h for the registry to be available. Its value does not effect the number of queues, semaphores and mutexes that can be created - just the number that the registry can hold.

If addToRegistry() is called more than once for the same queue, the registry will store the name parameter from the most recent call to addToRegistry().

Parameters
nameThe name to be associated with the handle. This is the name that the kernel aware debugger will display. The queue registry only stores a pointer to the string - so the string must be persistent (global or preferably in ROM/Flash), not on the stack.

◆ getName()

template<class T >
const char* FreeRTOS::QueueBase< T >::getName ( ) const
inline

Function that calls const char *pcQueueGetName( QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/pcQueueGetName.html

The queue registry is provided as a means for kernel aware debuggers to locate queues, semaphores and mutexes. Call getName() to look up and return the name of a queue in the queue registry from the queue's handle.

Returns
If the queue referenced by the queue is in the queue registry, then the text name of the queue is returned, otherwise NULL is returned.

◆ isEmptyFromISR()

template<class T >
bool FreeRTOS::QueueBase< T >::isEmptyFromISR ( ) const
inline

Function that calls BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/a00018.html#xQueueIsQueueEmptyFromISR

Queries a queue to determine if the queue is empty. This function should only be used in an ISR.

Return values
trueif the queue is empty.
falseif the queue is not empty.

◆ isFullFromISR()

template<class T >
bool FreeRTOS::QueueBase< T >::isFullFromISR ( ) const
inline

Function that calls BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/a00018.html#xQueueIsQueueFullFromISR

Queries a queue to determine if the queue is empty. This function should only be used in an ISR.

Returns
true if the queue is full.
false if the queue is not full.

◆ isValid()

template<class T >
bool FreeRTOS::QueueBase< T >::isValid ( ) const
inline

Function that checks if the underlying queue handle is not NULL. This should be used to ensure a queue has been created correctly.

Queue.hpp

Return values
truethe handle is not NULL.
falsethe handle is NULL.

◆ messagesWaiting()

template<class T >
UBaseType_t FreeRTOS::QueueBase< T >::messagesWaiting ( ) const
inline

Function that calls UBaseType_t uxQueueMessagesWaiting( QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/a00018.html#ucQueueMessagesWaiting

Return the number of messages stored in a queue.

Return values
UBaseType_tThe number of messages available in the queue.

◆ messagesWaitingFromISR()

template<class T >
UBaseType_t FreeRTOS::QueueBase< T >::messagesWaitingFromISR ( ) const
inline

Function that calls UBaseType_t uxQueueMessagesWaitingFromISR( QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/a00018.html#ucQueueMessagesWaitingFromISR

A version of messagesWaiting() that can be called from an ISR. Return the number of messages stored in a queue.

Return values
UBaseType_tThe number of messages available in the queue.

◆ overwrite()

template<class T >
void FreeRTOS::QueueBase< T >::overwrite ( const T &  item) const
inline

Function that calls BaseType_t xQueueOverwrite( QueueHandle_t xQueue, const void * pvItemToQueue )

Queue.hpp

See also
https://www.freertos.org/xQueueOverwrite.html

Only for use with queues that have a length of one - so the queue is either empty or full.

Post an item on a queue. If the queue is already full then overwrite the value held in the queue. The item is queued by copy, not by reference.

This function must not be called from an interrupt service routine. See overwriteFromISR() for an alternative which may be used in an ISR.

Parameters
itemA reference to the item that is to be placed on the queue.

Example Usage

#include <FreeRTOS/Queue.hpp>
#include <FreeRTOS/Task.hpp>
class MyTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
void MyTask::taskFunction() {
// Create a queue to hold one unsigned long value. It is strongly recommended
// *not* to use overwrite() on queues that can contain more than one value,
// and doing so will trigger an assertion if configASSERT() is defined.
if (!queue.isValid()) {
// Queue was not created and must not be used.
}
// Write the value 10 to the queue using overwrite().
queue.overwrite(10);
// Peeking the queue should now return 10, but leave the value 10 in the
// queue. A block time of zero is used as it is known that the queue holds a
// value.
if (queue.peek().value() != 10) {
// Error, unless another task removed the value.
}
// The queue is still full. Use overwrite() to overwrite the value held in
// the queue with 100.
queue.overwrite(100);
// This time read from the queue, leaving the queue empty once more. A block
// time of 0 is used again. The value read should be the last value written,
// even though the queue was already full when the value was written.
if (queue.receive().value() != 100) {
// Error unless another task is using the same queue.
}
// ...
}
Class that encapsulates the functionality of a FreeRTOS queue.
Definition: Queue.hpp:649
Class that encapsulates the functionality of a FreeRTOS task.
Definition: Task.hpp:1323

◆ overwriteFromISR() [1/2]

template<class T >
void FreeRTOS::QueueBase< T >::overwriteFromISR ( bool &  higherPriorityTaskWoken,
const T &  item 
) const
inline

Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken )

Queue.hpp

See also
https://www.freertos.org/xQueueOverwriteFromISR.html

A version of overwrite() that can be used in an interrupt service routine (ISR).

Only for use with queues that can hold a single item - so the queue is either empty or full.

Post an item on a queue. If the queue is already full then overwrite the value held in the queue. The item is queued by copy, not by reference.

Parameters
higherPriorityTaskWokenA reference that will be set to true if sending to the queue caused a task to unblock, and the unblocked task has a priority higher than the currently running task.
itemA reference to the item that is to be placed on the queue.

Example Usage

#include <FreeRTOS/Kernel.hpp>
#include <FreeRTOS/Queue.hpp>
// Create a queue to hold one unsigned long value. It is strongly recommended
// not to use overwriteFromISR() on queues that can contain more than one value,
// and doing so will trigger an assertion if configASSERT() is defined.
void anInterruptHandler() {
bool higherPriorityTaskWoken = false;
// Write the value 10 to the queue using overwriteFromISR().
queue.overwriteFromISR(higherPriorityTaskWoken, 10);
// The queue is full, but calling overwriteFromISR() again will still pass
// because the value held in the queue will be overwritten with the new value.
queue.overwriteFromISR(higherPriorityTaskWoken, 100);
// Reading from the queue will now return 100.
// ...
if (higherPriorityTaskWoken) {
// Writing to the queue caused a task to unblock and the unblocked task has
// a priority higher than or equal to the priority of the currently
// executing task (the task this interrupt interrupted). Perform a context
// switch so this interrupt returns directly to the unblocked task.
}
}
void overwriteFromISR(bool &higherPriorityTaskWoken, const T &item) const
Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQue...
Definition: Queue.hpp:410
Class that encapsulates the functionality of a FreeRTOS queue.
Definition: Queue.hpp:698
void yield()
Function that calls taskYIELD()
Definition: Kernel.hpp:153

◆ overwriteFromISR() [2/2]

template<class T >
void FreeRTOS::QueueBase< T >::overwriteFromISR ( const T &  item) const
inline

Function that calls BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, const void * pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken )

Queue.hpp

See also
https://www.freertos.org/xQueueOverwriteFromISR.html

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ peek()

template<class T >
std::optional<T> FreeRTOS::QueueBase< T >::peek ( const TickType_t  ticksToWait = portMAX_DELAY) const
inline

Function that calls BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )

Queue.hpp

See also
https://www.freertos.org/xQueuePeek.html

Receive an item from a queue without removing the item from the queue.

Successfully received items remain on the queue so will be returned again by the next call, or a call to receive().

This function must not be used in an interrupt service routine. See peekFromISR() for an alternative that can be called from an interrupt service routine.

Parameters
ticksToWaitThe maximum amount of time the task should block waiting for an item to receive should the queue be empty at the time of the call. Setting ticksToWait to 0 will cause the function to return immediately if the queue is empty. The time is defined in tick periods so the constant portTICK_PERIOD_MS should be used to convert to real time if this is required.
Returns
std::optional<T> Object from the queue. User should check that the value is present.

Example Usage

#include <FreeRTOS/Queue.hpp>
#include <FreeRTOS/Task.hpp>
class MyTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
class MyDifferentTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
class Message {
public:
char ucMessageID;
char ucData[20];
} xMessage;
// Queue used to send and receive pointers to Message objects.
void MyTask::taskFunction() {
// Send a pointer to a Message object. Don't block if the queue is already
// full.
pointerQueue.sendToBack(&xMessage);
// ... Rest of task code goes here.
}
void MyDifferentTask::taskFunction() {
// Peek a message on the created queue. Block for 10 ticks if a message is
// not immediately available.
if (auto messagePointer = pointerQueue.peek(10)) {
// messagePointer now points to the xMessage variable posted by MyTask, but
// the item still remains on the queue.
}
// ... Rest of task code goes here.
}
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
bool sendToBack(const T &item, const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait )
Definition: Queue.hpp:102

◆ peekFromISR()

template<class T >
std::optional<T> FreeRTOS::QueueBase< T >::peekFromISR ( ) const
inline

Function that calls BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void *pvBuffer )

Queue.hpp

See also
https://www.freertos.org/xQueuePeekFromISR.html

A version of peek() that can be called from an interrupt service routine (ISR).

Receive an item from a queue without removing the item from the queue.

Successfully received items remain on the queue so will be returned again by the next call, or a call to receive().

Returns
std::optional<T> Object from the queue. User should check that the value is present.

◆ receive()

template<class T >
std::optional<T> FreeRTOS::QueueBase< T >::receive ( const TickType_t  ticksToWait = portMAX_DELAY) const
inline

Function that calls BaseType_t xQueueReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait )

Queue.hpp

See also
https://www.freertos.org/a00118.html

Receive an item from a queue. This function must not be used in an interrupt service routine. See receiveFromISR() for an alternative that can.

Parameters
ticksToWaitThe maximum amount of time the task should block waiting for an item to receive should the queue be empty at the time of the call. Setting ticksToWait to 0 will cause the function to return immediately if the queue is empty. The time is defined in tick periods so the constant portTICK_PERIOD_MS should be used to convert to real time if this is required.
Returns
std::optional<T> Object from the queue. User should check that the value is present.

Example Usage

#include <FreeRTOS/Queue.hpp>
#include <FreeRTOS/Task.hpp>
#include <algorithm>
class MyTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
class MyDifferentTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
// Define a variable of type Message. The examples below demonstrate how to
// pass the whole variable through the queue, and as the structure is moderately
// large, also how to pass a reference to the variable through a queue.
class Message {
public:
char ucMessageID;
char ucData[20];
} xMessage;
// Queue used to send and receive complete Message objects.
// Queue used to send and receive pointers to Message objects.
void MyTask::taskFunction() {
xMessage.ucMessageID = static_cast<char>(0xab);
std::fill_n(xMessage.ucData, 20, 0x12);
// Send the entire object to the queue created to hold 10 objects.
structQueue.sendToBack(xMessage);
// Send the address of Message to the queue created to hold 10 pointers.
pointerQueue.sendToBack(&xMessage);
// ... Rest of task code goes here.
}
void MyDifferentTask::taskFunction() {
// Receive a message from the created queue to hold a Message object. Block
// for 10 ticks if a message is not immediately available. The value is read
// into a message variable, so after calling receive() message will hold a
// copy of xMessage.
if (auto message = structQueue.receive(10)) {
// message now contains a copy of xMessage.
}
// Receive a message from the created queue to hold pointers. Block for 10
// ticks if a message is not immediately available. The value is read into a
// pointer variable, and as the value received is the address of the xMessage
// variable, after this call messagePointer will point to xMessage.
if (auto messagePointer = pointerQueue.receive(10)) {
// messagePointer now points to xMessage.
}
// ... Rest of task code goes here.
}
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

◆ receiveFromISR() [1/2]

template<class T >
std::optional<T> FreeRTOS::QueueBase< T >::receiveFromISR ( ) const
inline

Function that calls BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxHigherPriorityTaskWoken )

Queue.hpp

See also
https://www.freertos.org/a00120.html

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ receiveFromISR() [2/2]

template<class T >
std::optional<T> FreeRTOS::QueueBase< T >::receiveFromISR ( bool &  higherPriorityTaskWoken) const
inline

Function that calls BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxHigherPriorityTaskWoken )

Queue.hpp

See also
https://www.freertos.org/a00120.html

Receive an item from a queue. It is safe to use this function from within an interrupt service routine.

Parameters
higherPriorityTaskWokenA reference that will be set to true if sending to the queue caused a task to unblock, and the unblocked task has a priority higher than the currently running task.
Returns
std::optional<T> Object from the queue. User should check that the value is present.

Example Usage

#include <FreeRTOS/Kernel.hpp>
#include <FreeRTOS/Queue.hpp>
#include <FreeRTOS/Task.hpp>
// Fake interface to send data to.
void sendCharacter(char c) {}
class MyTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
// Queue that holds 10 characters.
FreeRTOS::Queue<char> queue(10);
void MyTask::taskFunction() {
constexpr TickType_t ticksToWait = 0xff;
if (!queue.isValid()) {
// Failed to create the queue.
}
// Post some characters that will be used within an ISR. If the queue is full
// then this task will block for ticksToWait ticks.
queue.sendToBack('a', ticksToWait);
queue.sendToBack('b', ticksToWait);
// ... keep posting characters ... this task may block when the queue becomes
// full.
queue.sendToBack('c', ticksToWait);
}
// ISR that outputs all the characters received on the queue.
void ISR_Routine() {
bool taskWokenByReceive = false;
while (auto character = queue.receiveFromISR(taskWokenByReceive)) {
// A character was received. Output the character now.
sendCharacter(character.value());
}
// If removing the character from the queue woke the task that was posting
// onto the queue taskWokenByReceive will have been set to true. No matter
// how many times this loop iterates only one task will be woken.
if (taskWokenByReceive) {
// We should switch context so the ISR returns to a different task.
// NOTE: How this is done depends on the port you are using. Check the
// documentation and examples for your port.
}
}

◆ reset()

template<class T >
void FreeRTOS::QueueBase< T >::reset ( ) const
inline

Function that calls BaseType_t xQueueReset( QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/a00018.html#xQueueReset

Resets a queue to its original empty state.

◆ sendToBack()

template<class T >
bool FreeRTOS::QueueBase< T >::sendToBack ( const T &  item,
const TickType_t  ticksToWait = portMAX_DELAY 
) const
inline

Function that calls xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait )

Queue.hpp

See also
https://www.freertos.org/a00117.html

Post an item to the back of a queue. The item is queued by copy, not by reference. This function must not be called from an interrupt service routine. See FreeRTOS::Queue::sendToBackFromISR() for an alternative which may be used in an ISR.

Parameters
itemA reference to the item that is to be placed on the queue.
ticksToWaitThe maximum amount of time the task should block waiting for space to become available on the queue, should it already be full. The call will return immediately if this is set to 0 and the queue is full. The time is defined in tick periods so the constant portTICK_PERIOD_MS should be used to convert to real time if this is required.
Return values
trueif the item was successfully posted.
falseotherwise.

Example Usage

#include <FreeRTOS/Queue.hpp>
#include <FreeRTOS/Task.hpp>
class MyTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
class Message {
public:
char ucMessageID;
char ucData[20];
} xMessage;
const uint64_t ulVar = 10UL;
void MyTask::taskFunction() {
// Create a queue capable of containing 10 unsigned long values.
// Create a queue capable of containing 10 pointers to Message objects. These
// should be passed by pointer as they contain a lot of data
// ...
if (queue1.isValid()) {
// Send an unsigned long. Wait for 10 ticks for space to become available
// if necessary.
if (!queue1.sendToBack(ulVar, 10)) {
// Failed to post the message, even after 10 ticks.
}
}
if (queue2.isValid()) {
// Send a pointer to a Message object. Don't block if the queue is already
// full.
queue2.sendToBack(&xMessage, 0);
}
// Rest of task code.
}

◆ sendToBackFromISR() [1/2]

template<class T >
bool FreeRTOS::QueueBase< T >::sendToBackFromISR ( bool &  higherPriorityTaskWoken,
const T &  item 
) const
inline

Function that calls xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )

Queue.hpp

See also
https://www.freertos.org/xQueueSendToBackFromISR.html
Parameters
higherPriorityTaskWokenA reference that will be set to true if sending to the queue caused a task to unblock, and the unblocked task has a priority higher than the currently running task.
itemA reference to the item that is to be placed on the queue.
Return values
trueif the item was successfully posted
falseotherwise.

Example Usage

#include <FreeRTOS/Kernel.hpp>
#include <FreeRTOS/Queue.hpp>
// Fake interface to get data from.
char getByte() { return 'A'; }
size_t getBytesRemaining() { return 0; }
// Queue that holds 10 characters.
void bufferISR() {
// We have not woken a task at the start of the ISR.
bool higherPriorityTaskWoken = false;
// Loop until the buffer is empty.
do {
// Obtain a byte from the buffer and post the byte.
rxQueue.sendToBackFromISR(higherPriorityTaskWoken, getByte());
} while (getBytesRemaining() > 0);
// Now the buffer is empty we can switch context if necessary.
if (higherPriorityTaskWoken) {
}
}
bool sendToBackFromISR(bool &higherPriorityTaskWoken, const T &item) const
Function that calls xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition: Queue.hpp:125

◆ sendToBackFromISR() [2/2]

template<class T >
bool FreeRTOS::QueueBase< T >::sendToBackFromISR ( const T &  item) const
inline

Function that calls xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )

Queue.hpp

See also
https://www.freertos.org/xQueueSendToBackFromISR.html

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ sendToFront()

template<class T >
bool FreeRTOS::QueueBase< T >::sendToFront ( const T &  item,
const TickType_t  ticksToWait = portMAX_DELAY 
) const
inline

Function that calls xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait )

Queue.hpp

See also
https://www.freertos.org/xQueueSendToFront.html
Parameters
itemA reference to the item that is to be placed on the queue.
ticksToWaitThe maximum amount of time the task should block waiting for space to become available on the queue, should it already be full. The call will return immediately if this is set to 0 and the queue is full. The time is defined in tick periods so the constant portTICK_PERIOD_MS should be used to convert to real time if this is required.
Return values
trueif the item was successfully posted.
falseotherwise.

Example Usage

#include <FreeRTOS/Queue.hpp>
#include <FreeRTOS/Task.hpp>
class MyTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
class Message {
public:
char ucMessageID;
char ucData[20];
} xMessage;
uint64_t ulVar = 10UL;
void MyTask::taskFunction() {
// Create a queue capable of containing 10 unsigned long values.
// Create a queue capable of containing 10 pointers to Message objects. These
// should be passed by pointer as they contain a lot of data
// ...
if (queue1.isValid()) {
// Send an unsigned long. Wait for 10 ticks for space to become available
// if necessary.
if (!queue1.sendToFront(ulVar, 10)) {
// Failed to post the message, even after 10 ticks.
}
}
if (queue2.isValid()) {
// Send a pointer to a Message object. Don't block if the queue is already
// full.
queue2.sendToFront(&xMessage, 0);
}
// Rest of task code.
}

◆ sendToFrontFromISR() [1/2]

template<class T >
bool FreeRTOS::QueueBase< T >::sendToFrontFromISR ( bool &  higherPriorityTaskWoken,
const T &  item 
) const
inline

Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )

Queue.hpp

See also
https://www.freertos.org/xQueueSendToFrontFromISR.html
Parameters
higherPriorityTaskWokenA reference that will be set to true if sending to the queue caused a task to unblock, and the unblocked task has a priority higher than the currently running task.
itemA reference to the item that is to be placed on the queue.
Return values
trueif the item was successfully posted
falseotherwise.

Example Usage

#include <FreeRTOS/Kernel.hpp>
#include <FreeRTOS/Queue.hpp>
constexpr char emergencyMessage = 'E';
// Fake interface to get data from.
char getByte() { return 'A'; }
size_t getBytesRemaining() { return 0; }
// Queue that holds 10 characters.
void bufferISR() {
// We have not woken a task at the start of the ISR.
bool higherPriorityTaskWoken = false;
// Obtain a byte from the buffer.
char cIn = getByte();
if (cIn == emergencyMessage) {
// Post the byte to the front of the queue.
rxQueue.sendToFrontFromISR(higherPriorityTaskWoken, cIn);
} else {
// Post the byte to the back of the queue.
rxQueue.sendToBackFromISR(higherPriorityTaskWoken, cIn);
}
// Did sending to the queue unblock a higher priority task?
if (higherPriorityTaskWoken) {
}
}
bool sendToFrontFromISR(bool &higherPriorityTaskWoken, const T &item) const
Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )
Definition: Queue.hpp:193

◆ sendToFrontFromISR() [2/2]

template<class T >
bool FreeRTOS::QueueBase< T >::sendToFrontFromISR ( const T &  item) const
inline

Function that calls xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken )

Queue.hpp

See also
https://www.freertos.org/xQueueSendToFrontFromISR.html

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ spacesAvailable()

template<class T >
UBaseType_t FreeRTOS::QueueBase< T >::spacesAvailable ( ) const
inline

Function that calls UBaseType_t uxQueueSpacesAvailable( QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/a00018.html#uxQueueSpacesAvailable

Return the number of free spaces in a queue.

Return values
UBaseType_tThe number of free spaces available in the queue.

◆ unregister()

template<class T >
void FreeRTOS::QueueBase< T >::unregister ( ) const
inline

Function that calls void vQueueUnregisterQueue( QueueHandle_t xQueue )

Queue.hpp

See also
https://www.freertos.org/vQueueUnregisterQueue.html

The registry is provided as a means for kernel aware debuggers to locate queues, semaphores and mutexes. Call addToRegistry() add a queue, semaphore or mutex handle to the registry if you want the handle to be available to a kernel aware debugger, and unregister() to remove the queue, semaphore or mutex from the register. If you are not using a kernel aware debugger then this function can be ignored.


The documentation for this class was generated from the following file: