4.3.1 Queue
Queues offer inter-task communication of a user-definable fixed length. The
developer specifies the message length when creating the queue. This is done by
calling QueueHandle_t queueName = xQueueCreate(queueLength,
elementSize)
. The input parameter queueLength
specifies the number of elements the queue can hold. elementSize
specifies the size of each element in bytes. All elements in the queue must be of
equal size. When the queue is created, tasks can communicate with each other by
sending and receiving data through the queue. The queue is of FIFO structure
(first in/first out) such that the receiver will always receive the item that was
first inserted.
xQueueSend(queueName, *itemToQueue, ticksToWait)
xQueueReceive(queueName, *buffer, ticksToWait)
The last argument, ticksToWait
, specifies how long the
sending task should block when waiting for available space in a full queue.
Similarly, it specifies how long a receiving task will block when waiting to
receive any elements from an empty queue. The define
portMAX_DELAY
can be used here. If
INCLUDE_vTaskSuspend
in the configuration file is set to 1,
then portMAX_DELAY
will cause the task to block indefinitely
(without a time-out). If set to 0, the blocking time will be 0xFFFF.
If the send and receive functions are to be called form an ISR,
xQueueSendFromISR()
and
xQueueReceiveFromISR()
must be used.