blob: db176e552af581a69b0d3728222b85b48cc42edc [file] [log] [blame]
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001/*
Paul Bartell08dc6f62021-05-25 21:44:10 -07002 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
Paul Bartelladfc5332021-05-25 21:46:15 -07003 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07004 *
Paul Bartell3a413d12021-05-26 16:16:27 -07005 * SPDX-License-Identifier: MIT
6 *
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07007 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
alfred gedeon0b0a2062020-08-20 14:59:28 -070024 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
alfred gedeon9a1ebfe2020-08-17 16:16:11 -070026 *
27 */
28
29
30#ifndef QUEUE_H
31#define QUEUE_H
32
33#ifndef INC_FREERTOS_H
34 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
35#endif
36
37/* *INDENT-OFF* */
38#ifdef __cplusplus
39 extern "C" {
40#endif
41/* *INDENT-ON* */
42
43#include "task.h"
44
45/**
46 * Type by which queues are referenced. For example, a call to xQueueCreate()
47 * returns an QueueHandle_t variable that can then be used as a parameter to
48 * xQueueSend(), xQueueReceive(), etc.
49 */
50struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
51typedef struct QueueDefinition * QueueHandle_t;
52
53/**
54 * Type by which queue sets are referenced. For example, a call to
55 * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
56 * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
57 */
58typedef struct QueueDefinition * QueueSetHandle_t;
59
60/**
61 * Queue sets can contain both queues and semaphores, so the
62 * QueueSetMemberHandle_t is defined as a type to be used where a parameter or
63 * return value can be either an QueueHandle_t or an SemaphoreHandle_t.
64 */
65typedef struct QueueDefinition * QueueSetMemberHandle_t;
66
67/* For internal use only. */
68#define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
69#define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
70#define queueOVERWRITE ( ( BaseType_t ) 2 )
71
72/* For internal use only. These definitions *must* match those in queue.c. */
73#define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
74#define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
75#define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
76#define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
77#define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
78#define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
79
80/**
81 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +080082 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -070083 * QueueHandle_t xQueueCreate(
84 * UBaseType_t uxQueueLength,
85 * UBaseType_t uxItemSize
86 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +080087 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -070088 *
89 * Creates a new queue instance, and returns a handle by which the new queue
90 * can be referenced.
91 *
92 * Internally, within the FreeRTOS implementation, queues use two blocks of
93 * memory. The first block is used to hold the queue's data structures. The
94 * second block is used to hold items placed into the queue. If a queue is
95 * created using xQueueCreate() then both blocks of memory are automatically
96 * dynamically allocated inside the xQueueCreate() function. (see
alfred gedeona0381462020-08-21 11:30:39 -070097 * https://www.FreeRTOS.org/a00111.html). If a queue is created using
alfred gedeon9a1ebfe2020-08-17 16:16:11 -070098 * xQueueCreateStatic() then the application writer must provide the memory that
99 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
100 * be created without using any dynamic memory allocation.
101 *
alfred gedeon0b0a2062020-08-20 14:59:28 -0700102 * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700103 *
104 * @param uxQueueLength The maximum number of items that the queue can contain.
105 *
106 * @param uxItemSize The number of bytes each item in the queue will require.
107 * Items are queued by copy, not by reference, so this is the number of bytes
108 * that will be copied for each posted item. Each item on the queue must be
109 * the same size.
110 *
111 * @return If the queue is successfully create then a handle to the newly
112 * created queue is returned. If the queue cannot be created then 0 is
113 * returned.
114 *
115 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800116 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700117 * struct AMessage
118 * {
119 * char ucMessageID;
120 * char ucData[ 20 ];
121 * };
122 *
123 * void vATask( void *pvParameters )
124 * {
125 * QueueHandle_t xQueue1, xQueue2;
126 *
127 * // Create a queue capable of containing 10 uint32_t values.
128 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
129 * if( xQueue1 == 0 )
130 * {
131 * // Queue was not created and must not be used.
132 * }
133 *
134 * // Create a queue capable of containing 10 pointers to AMessage structures.
135 * // These should be passed by pointer as they contain a lot of data.
136 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
137 * if( xQueue2 == 0 )
138 * {
139 * // Queue was not created and must not be used.
140 * }
141 *
142 * // ... Rest of task code.
143 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800144 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700145 * \defgroup xQueueCreate xQueueCreate
146 * \ingroup QueueManagement
147 */
148#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
149 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
150#endif
151
152/**
153 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800154 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700155 * QueueHandle_t xQueueCreateStatic(
156 * UBaseType_t uxQueueLength,
157 * UBaseType_t uxItemSize,
Zim Kalinowski0b1e9d72021-08-13 09:15:57 +0800158 * uint8_t *pucQueueStorage,
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700159 * StaticQueue_t *pxQueueBuffer
160 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800161 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700162 *
163 * Creates a new queue instance, and returns a handle by which the new queue
164 * can be referenced.
165 *
166 * Internally, within the FreeRTOS implementation, queues use two blocks of
167 * memory. The first block is used to hold the queue's data structures. The
168 * second block is used to hold items placed into the queue. If a queue is
169 * created using xQueueCreate() then both blocks of memory are automatically
170 * dynamically allocated inside the xQueueCreate() function. (see
alfred gedeona0381462020-08-21 11:30:39 -0700171 * https://www.FreeRTOS.org/a00111.html). If a queue is created using
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700172 * xQueueCreateStatic() then the application writer must provide the memory that
173 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
174 * be created without using any dynamic memory allocation.
175 *
alfred gedeon0b0a2062020-08-20 14:59:28 -0700176 * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700177 *
178 * @param uxQueueLength The maximum number of items that the queue can contain.
179 *
180 * @param uxItemSize The number of bytes each item in the queue will require.
181 * Items are queued by copy, not by reference, so this is the number of bytes
182 * that will be copied for each posted item. Each item on the queue must be
183 * the same size.
184 *
Zim Kalinowski0b1e9d72021-08-13 09:15:57 +0800185 * @param pucQueueStorage If uxItemSize is not zero then
186 * pucQueueStorage must point to a uint8_t array that is at least large
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700187 * enough to hold the maximum number of items that can be in the queue at any
188 * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
Zim Kalinowski0b1e9d72021-08-13 09:15:57 +0800189 * zero then pucQueueStorage can be NULL.
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700190 *
191 * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
192 * will be used to hold the queue's data structure.
193 *
194 * @return If the queue is created then a handle to the created queue is
195 * returned. If pxQueueBuffer is NULL then NULL is returned.
196 *
197 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800198 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700199 * struct AMessage
200 * {
201 * char ucMessageID;
202 * char ucData[ 20 ];
203 * };
204 *
205 #define QUEUE_LENGTH 10
206 #define ITEM_SIZE sizeof( uint32_t )
207 *
208 * // xQueueBuffer will hold the queue structure.
209 * StaticQueue_t xQueueBuffer;
210 *
211 * // ucQueueStorage will hold the items posted to the queue. Must be at least
212 * // [(queue length) * ( queue item size)] bytes long.
213 * uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
214 *
215 * void vATask( void *pvParameters )
216 * {
Zim Kalinowski0b1e9d72021-08-13 09:15:57 +0800217 * QueueHandle_t xQueue1;
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700218 *
219 * // Create a queue capable of containing 10 uint32_t values.
220 * xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
221 * ITEM_SIZE // The size of each item in the queue
222 * &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
223 * &xQueueBuffer ); // The buffer that will hold the queue structure.
224 *
225 * // The queue is guaranteed to be created successfully as no dynamic memory
226 * // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
227 *
228 * // ... Rest of task code.
229 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800230 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700231 * \defgroup xQueueCreateStatic xQueueCreateStatic
232 * \ingroup QueueManagement
233 */
234#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
235 #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
236#endif /* configSUPPORT_STATIC_ALLOCATION */
237
238/**
239 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800240 * @code{c}
Darian9488ba22023-03-23 06:27:57 +0800241 * BaseType_t xQueueGetStaticBuffers( QueueHandle_t xQueue,
242 * uint8_t ** ppucQueueStorage,
243 * StaticQueue_t ** ppxStaticQueue );
244 * @endcode
245 *
246 * Retrieve pointers to a statically created queue's data structure buffer
247 * and storage area buffer. These are the same buffers that are supplied
248 * at the time of creation.
249 *
250 * @param xQueue The queue for which to retrieve the buffers.
251 *
252 * @param ppucQueueStorage Used to return a pointer to the queue's storage
253 * area buffer.
254 *
255 * @param ppxStaticQueue Used to return a pointer to the queue's data
256 * structure buffer.
257 *
258 * @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
259 *
260 * \defgroup xQueueGetStaticBuffers xQueueGetStaticBuffers
261 * \ingroup QueueManagement
262 */
263#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
264 #define xQueueGetStaticBuffers( xQueue, ppucQueueStorage, ppxStaticQueue ) xQueueGenericGetStaticBuffers( ( xQueue ), ( ppucQueueStorage ), ( ppxStaticQueue ) )
265#endif /* configSUPPORT_STATIC_ALLOCATION */
266
267/**
268 * queue. h
269 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700270 * BaseType_t xQueueSendToToFront(
271 * QueueHandle_t xQueue,
272 * const void *pvItemToQueue,
273 * TickType_t xTicksToWait
274 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800275 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700276 *
277 * Post an item to the front of a queue. The item is queued by copy, not by
278 * reference. This function must not be called from an interrupt service
279 * routine. See xQueueSendFromISR () for an alternative which may be used
280 * in an ISR.
281 *
282 * @param xQueue The handle to the queue on which the item is to be posted.
283 *
284 * @param pvItemToQueue A pointer to the item that is to be placed on the
285 * queue. The size of the items the queue will hold was defined when the
286 * queue was created, so this many bytes will be copied from pvItemToQueue
287 * into the queue storage area.
288 *
289 * @param xTicksToWait The maximum amount of time the task should block
290 * waiting for space to become available on the queue, should it already
291 * be full. The call will return immediately if this is set to 0 and the
292 * queue is full. The time is defined in tick periods so the constant
293 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
294 *
295 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
296 *
297 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800298 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700299 * struct AMessage
300 * {
301 * char ucMessageID;
302 * char ucData[ 20 ];
303 * } xMessage;
304 *
305 * uint32_t ulVar = 10UL;
306 *
307 * void vATask( void *pvParameters )
308 * {
309 * QueueHandle_t xQueue1, xQueue2;
310 * struct AMessage *pxMessage;
311 *
312 * // Create a queue capable of containing 10 uint32_t values.
313 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
314 *
315 * // Create a queue capable of containing 10 pointers to AMessage structures.
316 * // These should be passed by pointer as they contain a lot of data.
317 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
318 *
319 * // ...
320 *
321 * if( xQueue1 != 0 )
322 * {
323 * // Send an uint32_t. Wait for 10 ticks for space to become
324 * // available if necessary.
325 * if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
326 * {
327 * // Failed to post the message, even after 10 ticks.
328 * }
329 * }
330 *
331 * if( xQueue2 != 0 )
332 * {
333 * // Send a pointer to a struct AMessage object. Don't block if the
334 * // queue is already full.
335 * pxMessage = & xMessage;
336 * xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
337 * }
338 *
339 * // ... Rest of task code.
340 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800341 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700342 * \defgroup xQueueSend xQueueSend
343 * \ingroup QueueManagement
344 */
345#define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \
346 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
347
348/**
349 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800350 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700351 * BaseType_t xQueueSendToBack(
352 * QueueHandle_t xQueue,
353 * const void *pvItemToQueue,
354 * TickType_t xTicksToWait
355 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800356 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700357 *
358 * This is a macro that calls xQueueGenericSend().
359 *
360 * Post an item to the back of a queue. The item is queued by copy, not by
361 * reference. This function must not be called from an interrupt service
362 * routine. See xQueueSendFromISR () for an alternative which may be used
363 * in an ISR.
364 *
365 * @param xQueue The handle to the queue on which the item is to be posted.
366 *
367 * @param pvItemToQueue A pointer to the item that is to be placed on the
368 * queue. The size of the items the queue will hold was defined when the
369 * queue was created, so this many bytes will be copied from pvItemToQueue
370 * into the queue storage area.
371 *
372 * @param xTicksToWait The maximum amount of time the task should block
373 * waiting for space to become available on the queue, should it already
374 * be full. The call will return immediately if this is set to 0 and the queue
375 * is full. The time is defined in tick periods so the constant
376 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
377 *
378 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
379 *
380 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800381 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700382 * struct AMessage
383 * {
384 * char ucMessageID;
385 * char ucData[ 20 ];
386 * } xMessage;
387 *
388 * uint32_t ulVar = 10UL;
389 *
390 * void vATask( void *pvParameters )
391 * {
392 * QueueHandle_t xQueue1, xQueue2;
393 * struct AMessage *pxMessage;
394 *
395 * // Create a queue capable of containing 10 uint32_t values.
396 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
397 *
398 * // Create a queue capable of containing 10 pointers to AMessage structures.
399 * // These should be passed by pointer as they contain a lot of data.
400 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
401 *
402 * // ...
403 *
404 * if( xQueue1 != 0 )
405 * {
406 * // Send an uint32_t. Wait for 10 ticks for space to become
407 * // available if necessary.
408 * if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
409 * {
410 * // Failed to post the message, even after 10 ticks.
411 * }
412 * }
413 *
414 * if( xQueue2 != 0 )
415 * {
416 * // Send a pointer to a struct AMessage object. Don't block if the
417 * // queue is already full.
418 * pxMessage = & xMessage;
419 * xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
420 * }
421 *
422 * // ... Rest of task code.
423 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800424 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700425 * \defgroup xQueueSend xQueueSend
426 * \ingroup QueueManagement
427 */
428#define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
429 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
430
431/**
432 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800433 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700434 * BaseType_t xQueueSend(
435 * QueueHandle_t xQueue,
436 * const void * pvItemToQueue,
437 * TickType_t xTicksToWait
438 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800439 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700440 *
441 * This is a macro that calls xQueueGenericSend(). It is included for
442 * backward compatibility with versions of FreeRTOS.org that did not
443 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
444 * equivalent to xQueueSendToBack().
445 *
446 * Post an item on a queue. The item is queued by copy, not by reference.
447 * This function must not be called from an interrupt service routine.
448 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
449 *
450 * @param xQueue The handle to the queue on which the item is to be posted.
451 *
452 * @param pvItemToQueue A pointer to the item that is to be placed on the
453 * queue. The size of the items the queue will hold was defined when the
454 * queue was created, so this many bytes will be copied from pvItemToQueue
455 * into the queue storage area.
456 *
457 * @param xTicksToWait The maximum amount of time the task should block
458 * waiting for space to become available on the queue, should it already
459 * be full. The call will return immediately if this is set to 0 and the
460 * queue is full. The time is defined in tick periods so the constant
461 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
462 *
463 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
464 *
465 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800466 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700467 * struct AMessage
468 * {
469 * char ucMessageID;
470 * char ucData[ 20 ];
471 * } xMessage;
472 *
473 * uint32_t ulVar = 10UL;
474 *
475 * void vATask( void *pvParameters )
476 * {
477 * QueueHandle_t xQueue1, xQueue2;
478 * struct AMessage *pxMessage;
479 *
480 * // Create a queue capable of containing 10 uint32_t values.
481 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
482 *
483 * // Create a queue capable of containing 10 pointers to AMessage structures.
484 * // These should be passed by pointer as they contain a lot of data.
485 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
486 *
487 * // ...
488 *
489 * if( xQueue1 != 0 )
490 * {
491 * // Send an uint32_t. Wait for 10 ticks for space to become
492 * // available if necessary.
493 * if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
494 * {
495 * // Failed to post the message, even after 10 ticks.
496 * }
497 * }
498 *
499 * if( xQueue2 != 0 )
500 * {
501 * // Send a pointer to a struct AMessage object. Don't block if the
502 * // queue is already full.
503 * pxMessage = & xMessage;
504 * xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
505 * }
506 *
507 * // ... Rest of task code.
508 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800509 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700510 * \defgroup xQueueSend xQueueSend
511 * \ingroup QueueManagement
512 */
513#define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
514 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
515
516/**
517 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800518 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700519 * BaseType_t xQueueOverwrite(
520 * QueueHandle_t xQueue,
521 * const void * pvItemToQueue
522 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800523 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700524 *
525 * Only for use with queues that have a length of one - so the queue is either
526 * empty or full.
527 *
528 * Post an item on a queue. If the queue is already full then overwrite the
529 * value held in the queue. The item is queued by copy, not by reference.
530 *
531 * This function must not be called from an interrupt service routine.
532 * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
533 *
534 * @param xQueue The handle of the queue to which the data is being sent.
535 *
536 * @param pvItemToQueue A pointer to the item that is to be placed on the
537 * queue. The size of the items the queue will hold was defined when the
538 * queue was created, so this many bytes will be copied from pvItemToQueue
539 * into the queue storage area.
540 *
541 * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
542 * therefore has the same return values as xQueueSendToFront(). However, pdPASS
543 * is the only value that can be returned because xQueueOverwrite() will write
544 * to the queue even when the queue is already full.
545 *
546 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800547 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700548 *
549 * void vFunction( void *pvParameters )
550 * {
551 * QueueHandle_t xQueue;
552 * uint32_t ulVarToSend, ulValReceived;
553 *
554 * // Create a queue to hold one uint32_t value. It is strongly
555 * // recommended *not* to use xQueueOverwrite() on queues that can
556 * // contain more than one value, and doing so will trigger an assertion
557 * // if configASSERT() is defined.
558 * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
559 *
560 * // Write the value 10 to the queue using xQueueOverwrite().
561 * ulVarToSend = 10;
562 * xQueueOverwrite( xQueue, &ulVarToSend );
563 *
564 * // Peeking the queue should now return 10, but leave the value 10 in
565 * // the queue. A block time of zero is used as it is known that the
566 * // queue holds a value.
567 * ulValReceived = 0;
568 * xQueuePeek( xQueue, &ulValReceived, 0 );
569 *
570 * if( ulValReceived != 10 )
571 * {
572 * // Error unless the item was removed by a different task.
573 * }
574 *
575 * // The queue is still full. Use xQueueOverwrite() to overwrite the
576 * // value held in the queue with 100.
577 * ulVarToSend = 100;
578 * xQueueOverwrite( xQueue, &ulVarToSend );
579 *
580 * // This time read from the queue, leaving the queue empty once more.
581 * // A block time of 0 is used again.
582 * xQueueReceive( xQueue, &ulValReceived, 0 );
583 *
584 * // The value read should be the last value written, even though the
585 * // queue was already full when the value was written.
586 * if( ulValReceived != 100 )
587 * {
588 * // Error!
589 * }
590 *
591 * // ...
592 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800593 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700594 * \defgroup xQueueOverwrite xQueueOverwrite
595 * \ingroup QueueManagement
596 */
597#define xQueueOverwrite( xQueue, pvItemToQueue ) \
598 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
599
600
601/**
602 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800603 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700604 * BaseType_t xQueueGenericSend(
605 * QueueHandle_t xQueue,
606 * const void * pvItemToQueue,
607 * TickType_t xTicksToWait
608 * BaseType_t xCopyPosition
609 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800610 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700611 *
612 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
613 * xQueueSendToBack() are used in place of calling this function directly.
614 *
615 * Post an item on a queue. The item is queued by copy, not by reference.
616 * This function must not be called from an interrupt service routine.
617 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
618 *
619 * @param xQueue The handle to the queue on which the item is to be posted.
620 *
621 * @param pvItemToQueue A pointer to the item that is to be placed on the
622 * queue. The size of the items the queue will hold was defined when the
623 * queue was created, so this many bytes will be copied from pvItemToQueue
624 * into the queue storage area.
625 *
626 * @param xTicksToWait The maximum amount of time the task should block
627 * waiting for space to become available on the queue, should it already
628 * be full. The call will return immediately if this is set to 0 and the
629 * queue is full. The time is defined in tick periods so the constant
630 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
631 *
632 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
633 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
634 * at the front of the queue (for high priority messages).
635 *
636 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
637 *
638 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800639 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700640 * struct AMessage
641 * {
642 * char ucMessageID;
643 * char ucData[ 20 ];
644 * } xMessage;
645 *
646 * uint32_t ulVar = 10UL;
647 *
648 * void vATask( void *pvParameters )
649 * {
650 * QueueHandle_t xQueue1, xQueue2;
651 * struct AMessage *pxMessage;
652 *
653 * // Create a queue capable of containing 10 uint32_t values.
654 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
655 *
656 * // Create a queue capable of containing 10 pointers to AMessage structures.
657 * // These should be passed by pointer as they contain a lot of data.
658 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
659 *
660 * // ...
661 *
662 * if( xQueue1 != 0 )
663 * {
664 * // Send an uint32_t. Wait for 10 ticks for space to become
665 * // available if necessary.
666 * if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
667 * {
668 * // Failed to post the message, even after 10 ticks.
669 * }
670 * }
671 *
672 * if( xQueue2 != 0 )
673 * {
674 * // Send a pointer to a struct AMessage object. Don't block if the
675 * // queue is already full.
676 * pxMessage = & xMessage;
677 * xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
678 * }
679 *
680 * // ... Rest of task code.
681 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800682 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700683 * \defgroup xQueueSend xQueueSend
684 * \ingroup QueueManagement
685 */
686BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
687 const void * const pvItemToQueue,
688 TickType_t xTicksToWait,
689 const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
690
691/**
692 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800693 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700694 * BaseType_t xQueuePeek(
695 * QueueHandle_t xQueue,
696 * void * const pvBuffer,
697 * TickType_t xTicksToWait
David Chalcoebda4932020-08-18 16:28:02 -0700698 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800699 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700700 *
701 * Receive an item from a queue without removing the item from the queue.
702 * The item is received by copy so a buffer of adequate size must be
703 * provided. The number of bytes copied into the buffer was defined when
704 * the queue was created.
705 *
706 * Successfully received items remain on the queue so will be returned again
707 * by the next call, or a call to xQueueReceive().
708 *
709 * This macro must not be used in an interrupt service routine. See
710 * xQueuePeekFromISR() for an alternative that can be called from an interrupt
711 * service routine.
712 *
713 * @param xQueue The handle to the queue from which the item is to be
714 * received.
715 *
716 * @param pvBuffer Pointer to the buffer into which the received item will
717 * be copied.
718 *
719 * @param xTicksToWait The maximum amount of time the task should block
720 * waiting for an item to receive should the queue be empty at the time
721 * of the call. The time is defined in tick periods so the constant
722 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
723 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
724 * is empty.
725 *
726 * @return pdTRUE if an item was successfully received from the queue,
727 * otherwise pdFALSE.
728 *
729 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800730 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700731 * struct AMessage
732 * {
733 * char ucMessageID;
734 * char ucData[ 20 ];
735 * } xMessage;
736 *
737 * QueueHandle_t xQueue;
738 *
739 * // Task to create a queue and post a value.
740 * void vATask( void *pvParameters )
741 * {
742 * struct AMessage *pxMessage;
743 *
744 * // Create a queue capable of containing 10 pointers to AMessage structures.
745 * // These should be passed by pointer as they contain a lot of data.
746 * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
747 * if( xQueue == 0 )
748 * {
749 * // Failed to create the queue.
750 * }
751 *
752 * // ...
753 *
754 * // Send a pointer to a struct AMessage object. Don't block if the
755 * // queue is already full.
756 * pxMessage = & xMessage;
757 * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
758 *
759 * // ... Rest of task code.
760 * }
761 *
762 * // Task to peek the data from the queue.
763 * void vADifferentTask( void *pvParameters )
764 * {
765 * struct AMessage *pxRxedMessage;
766 *
767 * if( xQueue != 0 )
768 * {
769 * // Peek a message on the created queue. Block for 10 ticks if a
770 * // message is not immediately available.
771 * if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
772 * {
773 * // pcRxedMessage now points to the struct AMessage variable posted
774 * // by vATask, but the item still remains on the queue.
775 * }
776 * }
777 *
778 * // ... Rest of task code.
779 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800780 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700781 * \defgroup xQueuePeek xQueuePeek
782 * \ingroup QueueManagement
783 */
784BaseType_t xQueuePeek( QueueHandle_t xQueue,
785 void * const pvBuffer,
786 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
787
788/**
789 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800790 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700791 * BaseType_t xQueuePeekFromISR(
792 * QueueHandle_t xQueue,
793 * void *pvBuffer,
David Chalcoebda4932020-08-18 16:28:02 -0700794 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800795 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700796 *
797 * A version of xQueuePeek() that can be called from an interrupt service
798 * routine (ISR).
799 *
800 * Receive an item from a queue without removing the item from the queue.
801 * The item is received by copy so a buffer of adequate size must be
802 * provided. The number of bytes copied into the buffer was defined when
803 * the queue was created.
804 *
805 * Successfully received items remain on the queue so will be returned again
806 * by the next call, or a call to xQueueReceive().
807 *
808 * @param xQueue The handle to the queue from which the item is to be
809 * received.
810 *
811 * @param pvBuffer Pointer to the buffer into which the received item will
812 * be copied.
813 *
814 * @return pdTRUE if an item was successfully received from the queue,
815 * otherwise pdFALSE.
816 *
817 * \defgroup xQueuePeekFromISR xQueuePeekFromISR
818 * \ingroup QueueManagement
819 */
820BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
821 void * const pvBuffer ) PRIVILEGED_FUNCTION;
822
823/**
824 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800825 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700826 * BaseType_t xQueueReceive(
827 * QueueHandle_t xQueue,
828 * void *pvBuffer,
829 * TickType_t xTicksToWait
David Chalcoebda4932020-08-18 16:28:02 -0700830 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800831 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700832 *
833 * Receive an item from a queue. The item is received by copy so a buffer of
834 * adequate size must be provided. The number of bytes copied into the buffer
835 * was defined when the queue was created.
836 *
837 * Successfully received items are removed from the queue.
838 *
839 * This function must not be used in an interrupt service routine. See
840 * xQueueReceiveFromISR for an alternative that can.
841 *
842 * @param xQueue The handle to the queue from which the item is to be
843 * received.
844 *
845 * @param pvBuffer Pointer to the buffer into which the received item will
846 * be copied.
847 *
848 * @param xTicksToWait The maximum amount of time the task should block
849 * waiting for an item to receive should the queue be empty at the time
850 * of the call. xQueueReceive() will return immediately if xTicksToWait
851 * is zero and the queue is empty. The time is defined in tick periods so the
852 * constant portTICK_PERIOD_MS should be used to convert to real time if this is
853 * required.
854 *
855 * @return pdTRUE if an item was successfully received from the queue,
856 * otherwise pdFALSE.
857 *
858 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800859 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700860 * struct AMessage
861 * {
862 * char ucMessageID;
863 * char ucData[ 20 ];
864 * } xMessage;
865 *
866 * QueueHandle_t xQueue;
867 *
868 * // Task to create a queue and post a value.
869 * void vATask( void *pvParameters )
870 * {
871 * struct AMessage *pxMessage;
872 *
873 * // Create a queue capable of containing 10 pointers to AMessage structures.
874 * // These should be passed by pointer as they contain a lot of data.
875 * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
876 * if( xQueue == 0 )
877 * {
878 * // Failed to create the queue.
879 * }
880 *
881 * // ...
882 *
883 * // Send a pointer to a struct AMessage object. Don't block if the
884 * // queue is already full.
885 * pxMessage = & xMessage;
886 * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
887 *
888 * // ... Rest of task code.
889 * }
890 *
891 * // Task to receive from the queue.
892 * void vADifferentTask( void *pvParameters )
893 * {
894 * struct AMessage *pxRxedMessage;
895 *
896 * if( xQueue != 0 )
897 * {
898 * // Receive a message on the created queue. Block for 10 ticks if a
899 * // message is not immediately available.
900 * if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
901 * {
902 * // pcRxedMessage now points to the struct AMessage variable posted
903 * // by vATask.
904 * }
905 * }
906 *
907 * // ... Rest of task code.
908 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800909 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700910 * \defgroup xQueueReceive xQueueReceive
911 * \ingroup QueueManagement
912 */
913BaseType_t xQueueReceive( QueueHandle_t xQueue,
914 void * const pvBuffer,
915 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
916
917/**
918 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800919 * @code{c}
David Chalcoebda4932020-08-18 16:28:02 -0700920 * UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800921 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700922 *
923 * Return the number of messages stored in a queue.
924 *
925 * @param xQueue A handle to the queue being queried.
926 *
927 * @return The number of messages available in the queue.
928 *
929 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
930 * \ingroup QueueManagement
931 */
932UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
933
934/**
935 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800936 * @code{c}
David Chalcoebda4932020-08-18 16:28:02 -0700937 * UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800938 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700939 *
940 * Return the number of free spaces available in a queue. This is equal to the
941 * number of items that can be sent to the queue before the queue becomes full
942 * if no items are removed.
943 *
944 * @param xQueue A handle to the queue being queried.
945 *
946 * @return The number of spaces available in the queue.
947 *
948 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
949 * \ingroup QueueManagement
950 */
951UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
952
953/**
954 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800955 * @code{c}
David Chalcoebda4932020-08-18 16:28:02 -0700956 * void vQueueDelete( QueueHandle_t xQueue );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800957 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700958 *
959 * Delete a queue - freeing all the memory allocated for storing of items
960 * placed on the queue.
961 *
962 * @param xQueue A handle to the queue to be deleted.
963 *
964 * \defgroup vQueueDelete vQueueDelete
965 * \ingroup QueueManagement
966 */
967void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
968
969/**
970 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800971 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700972 * BaseType_t xQueueSendToFrontFromISR(
973 * QueueHandle_t xQueue,
974 * const void *pvItemToQueue,
975 * BaseType_t *pxHigherPriorityTaskWoken
976 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +0800977 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -0700978 *
979 * This is a macro that calls xQueueGenericSendFromISR().
980 *
981 * Post an item to the front of a queue. It is safe to use this macro from
982 * within an interrupt service routine.
983 *
984 * Items are queued by copy not reference so it is preferable to only
985 * queue small items, especially when called from an ISR. In most cases
986 * it would be preferable to store a pointer to the item being queued.
987 *
988 * @param xQueue The handle to the queue on which the item is to be posted.
989 *
990 * @param pvItemToQueue A pointer to the item that is to be placed on the
991 * queue. The size of the items the queue will hold was defined when the
992 * queue was created, so this many bytes will be copied from pvItemToQueue
993 * into the queue storage area.
994 *
995 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
996 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
997 * to unblock, and the unblocked task has a priority higher than the currently
998 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
999 * a context switch should be requested before the interrupt is exited.
1000 *
1001 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1002 * errQUEUE_FULL.
1003 *
1004 * Example usage for buffered IO (where the ISR can obtain more than one value
1005 * per call):
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001006 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001007 * void vBufferISR( void )
1008 * {
1009 * char cIn;
mikisamad5b24132022-02-14 07:47:52 +08001010 * BaseType_t xHigherPriorityTaskWoken;
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001011 *
1012 * // We have not woken a task at the start of the ISR.
1013 * xHigherPriorityTaskWoken = pdFALSE;
1014 *
1015 * // Loop until the buffer is empty.
1016 * do
1017 * {
1018 * // Obtain a byte from the buffer.
1019 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1020 *
1021 * // Post the byte.
1022 * xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1023 *
1024 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1025 *
1026 * // Now the buffer is empty we can switch context if necessary.
1027 * if( xHigherPriorityTaskWoken )
1028 * {
1029 * taskYIELD ();
1030 * }
1031 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001032 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001033 *
1034 * \defgroup xQueueSendFromISR xQueueSendFromISR
1035 * \ingroup QueueManagement
1036 */
1037#define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1038 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
1039
1040
1041/**
1042 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001043 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001044 * BaseType_t xQueueSendToBackFromISR(
1045 * QueueHandle_t xQueue,
1046 * const void *pvItemToQueue,
1047 * BaseType_t *pxHigherPriorityTaskWoken
1048 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001049 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001050 *
1051 * This is a macro that calls xQueueGenericSendFromISR().
1052 *
1053 * Post an item to the back of a queue. It is safe to use this macro from
1054 * within an interrupt service routine.
1055 *
1056 * Items are queued by copy not reference so it is preferable to only
1057 * queue small items, especially when called from an ISR. In most cases
1058 * it would be preferable to store a pointer to the item being queued.
1059 *
1060 * @param xQueue The handle to the queue on which the item is to be posted.
1061 *
1062 * @param pvItemToQueue A pointer to the item that is to be placed on the
1063 * queue. The size of the items the queue will hold was defined when the
1064 * queue was created, so this many bytes will be copied from pvItemToQueue
1065 * into the queue storage area.
1066 *
1067 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
1068 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1069 * to unblock, and the unblocked task has a priority higher than the currently
1070 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
1071 * a context switch should be requested before the interrupt is exited.
1072 *
1073 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1074 * errQUEUE_FULL.
1075 *
1076 * Example usage for buffered IO (where the ISR can obtain more than one value
1077 * per call):
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001078 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001079 * void vBufferISR( void )
1080 * {
1081 * char cIn;
1082 * BaseType_t xHigherPriorityTaskWoken;
1083 *
1084 * // We have not woken a task at the start of the ISR.
1085 * xHigherPriorityTaskWoken = pdFALSE;
1086 *
1087 * // Loop until the buffer is empty.
1088 * do
1089 * {
1090 * // Obtain a byte from the buffer.
1091 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1092 *
1093 * // Post the byte.
1094 * xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1095 *
1096 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1097 *
1098 * // Now the buffer is empty we can switch context if necessary.
1099 * if( xHigherPriorityTaskWoken )
1100 * {
1101 * taskYIELD ();
1102 * }
1103 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001104 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001105 *
1106 * \defgroup xQueueSendFromISR xQueueSendFromISR
1107 * \ingroup QueueManagement
1108 */
1109#define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1110 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1111
1112/**
1113 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001114 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001115 * BaseType_t xQueueOverwriteFromISR(
1116 * QueueHandle_t xQueue,
1117 * const void * pvItemToQueue,
1118 * BaseType_t *pxHigherPriorityTaskWoken
1119 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001120 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001121 *
1122 * A version of xQueueOverwrite() that can be used in an interrupt service
1123 * routine (ISR).
1124 *
1125 * Only for use with queues that can hold a single item - so the queue is either
1126 * empty or full.
1127 *
1128 * Post an item on a queue. If the queue is already full then overwrite the
1129 * value held in the queue. The item is queued by copy, not by reference.
1130 *
1131 * @param xQueue The handle to the queue on which the item is to be posted.
1132 *
1133 * @param pvItemToQueue A pointer to the item that is to be placed on the
1134 * queue. The size of the items the queue will hold was defined when the
1135 * queue was created, so this many bytes will be copied from pvItemToQueue
1136 * into the queue storage area.
1137 *
1138 * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
1139 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1140 * to unblock, and the unblocked task has a priority higher than the currently
1141 * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
1142 * a context switch should be requested before the interrupt is exited.
1143 *
1144 * @return xQueueOverwriteFromISR() is a macro that calls
1145 * xQueueGenericSendFromISR(), and therefore has the same return values as
1146 * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
1147 * returned because xQueueOverwriteFromISR() will write to the queue even when
1148 * the queue is already full.
1149 *
1150 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001151 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001152 *
1153 * QueueHandle_t xQueue;
1154 *
1155 * void vFunction( void *pvParameters )
1156 * {
1157 * // Create a queue to hold one uint32_t value. It is strongly
1158 * // recommended *not* to use xQueueOverwriteFromISR() on queues that can
1159 * // contain more than one value, and doing so will trigger an assertion
1160 * // if configASSERT() is defined.
1161 * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
1162 * }
1163 *
1164 * void vAnInterruptHandler( void )
1165 * {
1166 * // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
1167 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
1168 * uint32_t ulVarToSend, ulValReceived;
1169 *
1170 * // Write the value 10 to the queue using xQueueOverwriteFromISR().
1171 * ulVarToSend = 10;
1172 * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1173 *
1174 * // The queue is full, but calling xQueueOverwriteFromISR() again will still
1175 * // pass because the value held in the queue will be overwritten with the
1176 * // new value.
1177 * ulVarToSend = 100;
1178 * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1179 *
1180 * // Reading from the queue will now return 100.
1181 *
1182 * // ...
1183 *
1184 * if( xHigherPrioritytaskWoken == pdTRUE )
1185 * {
1186 * // Writing to the queue caused a task to unblock and the unblocked task
1187 * // has a priority higher than or equal to the priority of the currently
1188 * // executing task (the task this interrupt interrupted). Perform a context
1189 * // switch so this interrupt returns directly to the unblocked task.
1190 * portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
1191 * }
1192 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001193 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001194 * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
1195 * \ingroup QueueManagement
1196 */
1197#define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1198 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1199
1200/**
1201 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001202 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001203 * BaseType_t xQueueSendFromISR(
1204 * QueueHandle_t xQueue,
1205 * const void *pvItemToQueue,
1206 * BaseType_t *pxHigherPriorityTaskWoken
1207 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001208 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001209 *
1210 * This is a macro that calls xQueueGenericSendFromISR(). It is included
1211 * for backward compatibility with versions of FreeRTOS.org that did not
1212 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
1213 * macros.
1214 *
1215 * Post an item to the back of a queue. It is safe to use this function from
1216 * within an interrupt service routine.
1217 *
1218 * Items are queued by copy not reference so it is preferable to only
1219 * queue small items, especially when called from an ISR. In most cases
1220 * it would be preferable to store a pointer to the item being queued.
1221 *
1222 * @param xQueue The handle to the queue on which the item is to be posted.
1223 *
1224 * @param pvItemToQueue A pointer to the item that is to be placed on the
1225 * queue. The size of the items the queue will hold was defined when the
1226 * queue was created, so this many bytes will be copied from pvItemToQueue
1227 * into the queue storage area.
1228 *
1229 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
1230 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1231 * to unblock, and the unblocked task has a priority higher than the currently
1232 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
1233 * a context switch should be requested before the interrupt is exited.
1234 *
1235 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1236 * errQUEUE_FULL.
1237 *
1238 * Example usage for buffered IO (where the ISR can obtain more than one value
1239 * per call):
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001240 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001241 * void vBufferISR( void )
1242 * {
1243 * char cIn;
1244 * BaseType_t xHigherPriorityTaskWoken;
1245 *
1246 * // We have not woken a task at the start of the ISR.
1247 * xHigherPriorityTaskWoken = pdFALSE;
1248 *
1249 * // Loop until the buffer is empty.
1250 * do
1251 * {
1252 * // Obtain a byte from the buffer.
1253 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1254 *
1255 * // Post the byte.
1256 * xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1257 *
1258 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1259 *
1260 * // Now the buffer is empty we can switch context if necessary.
1261 * if( xHigherPriorityTaskWoken )
1262 * {
1263 * // Actual macro used here is port specific.
1264 * portYIELD_FROM_ISR ();
1265 * }
1266 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001267 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001268 *
1269 * \defgroup xQueueSendFromISR xQueueSendFromISR
1270 * \ingroup QueueManagement
1271 */
1272#define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1273 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1274
1275/**
1276 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001277 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001278 * BaseType_t xQueueGenericSendFromISR(
1279 * QueueHandle_t xQueue,
1280 * const void *pvItemToQueue,
1281 * BaseType_t *pxHigherPriorityTaskWoken,
1282 * BaseType_t xCopyPosition
1283 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001284 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001285 *
1286 * It is preferred that the macros xQueueSendFromISR(),
1287 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1288 * of calling this function directly. xQueueGiveFromISR() is an
1289 * equivalent for use by semaphores that don't actually copy any data.
1290 *
1291 * Post an item on a queue. It is safe to use this function from within an
1292 * interrupt service routine.
1293 *
1294 * Items are queued by copy not reference so it is preferable to only
1295 * queue small items, especially when called from an ISR. In most cases
1296 * it would be preferable to store a pointer to the item being queued.
1297 *
1298 * @param xQueue The handle to the queue on which the item is to be posted.
1299 *
1300 * @param pvItemToQueue A pointer to the item that is to be placed on the
1301 * queue. The size of the items the queue will hold was defined when the
1302 * queue was created, so this many bytes will be copied from pvItemToQueue
1303 * into the queue storage area.
1304 *
1305 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1306 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1307 * to unblock, and the unblocked task has a priority higher than the currently
1308 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
1309 * a context switch should be requested before the interrupt is exited.
1310 *
1311 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1312 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1313 * at the front of the queue (for high priority messages).
1314 *
1315 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1316 * errQUEUE_FULL.
1317 *
1318 * Example usage for buffered IO (where the ISR can obtain more than one value
1319 * per call):
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001320 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001321 * void vBufferISR( void )
1322 * {
1323 * char cIn;
1324 * BaseType_t xHigherPriorityTaskWokenByPost;
1325 *
1326 * // We have not woken a task at the start of the ISR.
1327 * xHigherPriorityTaskWokenByPost = pdFALSE;
1328 *
1329 * // Loop until the buffer is empty.
1330 * do
1331 * {
1332 * // Obtain a byte from the buffer.
1333 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1334 *
1335 * // Post each byte.
1336 * xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1337 *
1338 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1339 *
1340 * // Now the buffer is empty we can switch context if necessary. Note that the
1341 * // name of the yield function required is port specific.
1342 * if( xHigherPriorityTaskWokenByPost )
1343 * {
1344 * portYIELD_FROM_ISR();
1345 * }
1346 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001347 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001348 *
1349 * \defgroup xQueueSendFromISR xQueueSendFromISR
1350 * \ingroup QueueManagement
1351 */
1352BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
1353 const void * const pvItemToQueue,
1354 BaseType_t * const pxHigherPriorityTaskWoken,
1355 const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1356BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
1357 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1358
1359/**
1360 * queue. h
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001361 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001362 * BaseType_t xQueueReceiveFromISR(
1363 * QueueHandle_t xQueue,
1364 * void *pvBuffer,
1365 * BaseType_t *pxTaskWoken
1366 * );
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001367 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001368 *
1369 * Receive an item from a queue. It is safe to use this function from within an
1370 * interrupt service routine.
1371 *
1372 * @param xQueue The handle to the queue from which the item is to be
1373 * received.
1374 *
1375 * @param pvBuffer Pointer to the buffer into which the received item will
1376 * be copied.
1377 *
phelter8cd54512023-02-23 10:05:04 -08001378 * @param pxHigherPriorityTaskWoken A task may be blocked waiting for space to
1379 * become available on the queue. If xQueueReceiveFromISR causes such a task
1380 * to unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001381 * remain unchanged.
1382 *
1383 * @return pdTRUE if an item was successfully received from the queue,
1384 * otherwise pdFALSE.
1385 *
1386 * Example usage:
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001387 * @code{c}
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001388 *
1389 * QueueHandle_t xQueue;
1390 *
1391 * // Function to create a queue and post some values.
1392 * void vAFunction( void *pvParameters )
1393 * {
1394 * char cValueToPost;
1395 * const TickType_t xTicksToWait = ( TickType_t )0xff;
1396 *
1397 * // Create a queue capable of containing 10 characters.
1398 * xQueue = xQueueCreate( 10, sizeof( char ) );
1399 * if( xQueue == 0 )
1400 * {
1401 * // Failed to create the queue.
1402 * }
1403 *
1404 * // ...
1405 *
1406 * // Post some characters that will be used within an ISR. If the queue
1407 * // is full then this task will block for xTicksToWait ticks.
1408 * cValueToPost = 'a';
1409 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1410 * cValueToPost = 'b';
1411 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1412 *
1413 * // ... keep posting characters ... this task may block when the queue
1414 * // becomes full.
1415 *
1416 * cValueToPost = 'c';
1417 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1418 * }
1419 *
1420 * // ISR that outputs all the characters received on the queue.
1421 * void vISR_Routine( void )
1422 * {
1423 * BaseType_t xTaskWokenByReceive = pdFALSE;
1424 * char cRxedChar;
1425 *
1426 * while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1427 * {
1428 * // A character was received. Output the character now.
1429 * vOutputCharacter( cRxedChar );
1430 *
1431 * // If removing the character from the queue woke the task that was
Robert Bergercf685052022-04-26 00:11:51 +03001432 * // posting onto the queue xTaskWokenByReceive will have been set to
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001433 * // pdTRUE. No matter how many times this loop iterates only one
1434 * // task will be woken.
1435 * }
1436 *
Robert Bergercf685052022-04-26 00:11:51 +03001437 * if( xTaskWokenByReceive != ( char ) pdFALSE;
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001438 * {
1439 * taskYIELD ();
1440 * }
1441 * }
Zim Kalinowskif8ada392021-09-08 03:03:12 +08001442 * @endcode
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001443 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
1444 * \ingroup QueueManagement
1445 */
1446BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
1447 void * const pvBuffer,
1448 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1449
1450/*
1451 * Utilities to query queues that are safe to use from an ISR. These utilities
Jon Enzabd887c2022-01-07 10:45:58 -08001452 * should be used only from within an ISR, or within a critical section.
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001453 */
1454BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1455BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1456UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1457
1458/*
Aniruddha Kanhered3c289f2023-06-02 11:03:40 -07001459 * The functions defined above are for passing data to and from tasks. The
1460 * functions below are the equivalents for passing data to and from
1461 * co-routines.
1462 *
1463 * These functions are called from the co-routine macro implementation and
1464 * should not be called directly from application code. Instead use the macro
1465 * wrappers defined within croutine.h.
1466 */
1467BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue,
1468 const void * pvItemToQueue,
1469 BaseType_t xCoRoutinePreviouslyWoken );
1470BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue,
1471 void * pvBuffer,
1472 BaseType_t * pxTaskWoken );
1473BaseType_t xQueueCRSend( QueueHandle_t xQueue,
1474 const void * pvItemToQueue,
1475 TickType_t xTicksToWait );
1476BaseType_t xQueueCRReceive( QueueHandle_t xQueue,
1477 void * pvBuffer,
1478 TickType_t xTicksToWait );
1479
1480/*
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001481 * For internal use only. Use xSemaphoreCreateMutex(),
1482 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1483 * these functions directly.
1484 */
1485QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1486QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
1487 StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1488QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
1489 const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1490QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
1491 const UBaseType_t uxInitialCount,
1492 StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1493BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
1494 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1495TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1496TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1497
1498/*
1499 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1500 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1501 */
1502BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
1503 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1504BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
1505
1506/*
1507 * Reset a queue back to its original empty state. The return value is now
1508 * obsolete and is always set to pdPASS.
1509 */
Monika Singh11c72bc2022-08-19 15:51:57 +05301510#define xQueueReset( xQueue ) xQueueGenericReset( ( xQueue ), pdFALSE )
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001511
1512/*
1513 * The registry is provided as a means for kernel aware debuggers to
1514 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1515 * a queue, semaphore or mutex handle to the registry if you want the handle
1516 * to be available to a kernel aware debugger. If you are not using a kernel
1517 * aware debugger then this function can be ignored.
1518 *
1519 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1520 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1521 * within FreeRTOSConfig.h for the registry to be available. Its value
Tobias Nießen364f0e52022-01-31 20:12:47 +01001522 * does not affect the number of queues, semaphores and mutexes that can be
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001523 * created - just the number that the registry can hold.
1524 *
Paul Bartella22b4382021-04-09 17:06:58 -07001525 * If vQueueAddToRegistry is called more than once with the same xQueue
1526 * parameter, the registry will store the pcQueueName parameter from the
1527 * most recent call to vQueueAddToRegistry.
1528 *
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001529 * @param xQueue The handle of the queue being added to the registry. This
1530 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1531 * handles can also be passed in here.
1532 *
Zim Kalinowski0b1e9d72021-08-13 09:15:57 +08001533 * @param pcQueueName The name to be associated with the handle. This is the
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001534 * name that the kernel aware debugger will display. The queue registry only
1535 * stores a pointer to the string - so the string must be persistent (global or
1536 * preferably in ROM/Flash), not on the stack.
1537 */
1538#if ( configQUEUE_REGISTRY_SIZE > 0 )
1539 void vQueueAddToRegistry( QueueHandle_t xQueue,
1540 const char * pcQueueName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1541#endif
1542
1543/*
1544 * The registry is provided as a means for kernel aware debuggers to
1545 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1546 * a queue, semaphore or mutex handle to the registry if you want the handle
1547 * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1548 * remove the queue, semaphore or mutex from the register. If you are not using
1549 * a kernel aware debugger then this function can be ignored.
1550 *
1551 * @param xQueue The handle of the queue being removed from the registry.
1552 */
1553#if ( configQUEUE_REGISTRY_SIZE > 0 )
1554 void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1555#endif
1556
1557/*
1558 * The queue registry is provided as a means for kernel aware debuggers to
1559 * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
1560 * up and return the name of a queue in the queue registry from the queue's
1561 * handle.
1562 *
1563 * @param xQueue The handle of the queue the name of which will be returned.
1564 * @return If the queue is in the registry then a pointer to the name of the
1565 * queue is returned. If the queue is not in the registry then NULL is
1566 * returned.
1567 */
1568#if ( configQUEUE_REGISTRY_SIZE > 0 )
1569 const char * pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1570#endif
1571
1572/*
Carl Lundinacee77b2020-09-16 11:17:39 -07001573 * Generic version of the function used to create a queue using dynamic memory
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001574 * allocation. This is called by other functions and macros that create other
1575 * RTOS objects that use the queue structure as their base.
1576 */
1577#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1578 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
1579 const UBaseType_t uxItemSize,
1580 const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1581#endif
1582
1583/*
Carl Lundinacee77b2020-09-16 11:17:39 -07001584 * Generic version of the function used to create a queue using dynamic memory
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001585 * allocation. This is called by other functions and macros that create other
1586 * RTOS objects that use the queue structure as their base.
1587 */
1588#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1589 QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
1590 const UBaseType_t uxItemSize,
1591 uint8_t * pucQueueStorage,
1592 StaticQueue_t * pxStaticQueue,
1593 const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1594#endif
1595
1596/*
Darian9488ba22023-03-23 06:27:57 +08001597 * Generic version of the function used to retrieve the buffers of statically
1598 * created queues. This is called by other functions and macros that retrieve
1599 * the buffers of other statically created RTOS objects that use the queue
1600 * structure as their base.
1601 */
1602#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1603 BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
1604 uint8_t ** ppucQueueStorage,
1605 StaticQueue_t ** ppxStaticQueue ) PRIVILEGED_FUNCTION;
1606#endif
1607
1608/*
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001609 * Queue sets provide a mechanism to allow a task to block (pend) on a read
1610 * operation from multiple queues or semaphores simultaneously.
1611 *
1612 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1613 * function.
1614 *
1615 * A queue set must be explicitly created using a call to xQueueCreateSet()
1616 * before it can be used. Once created, standard FreeRTOS queues and semaphores
1617 * can be added to the set using calls to xQueueAddToSet().
1618 * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1619 * or semaphores contained in the set is in a state where a queue read or
1620 * semaphore take operation would be successful.
1621 *
alfred gedeond4282092020-09-21 15:49:55 -07001622 * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001623 * for reasons why queue sets are very rarely needed in practice as there are
1624 * simpler methods of blocking on multiple objects.
1625 *
1626 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1627 * mutex holder to inherit the priority of the blocked task.
1628 *
1629 * Note 3: An additional 4 bytes of RAM is required for each space in a every
1630 * queue added to a queue set. Therefore counting semaphores that have a high
1631 * maximum count value should not be added to a queue set.
1632 *
1633 * Note 4: A receive (in the case of a queue) or take (in the case of a
1634 * semaphore) operation must not be performed on a member of a queue set unless
1635 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1636 *
1637 * @param uxEventQueueLength Queue sets store events that occur on
1638 * the queues and semaphores contained in the set. uxEventQueueLength specifies
1639 * the maximum number of events that can be queued at once. To be absolutely
1640 * certain that events are not lost uxEventQueueLength should be set to the
1641 * total sum of the length of the queues added to the set, where binary
1642 * semaphores and mutexes have a length of 1, and counting semaphores have a
1643 * length set by their maximum count value. Examples:
1644 * + If a queue set is to hold a queue of length 5, another queue of length 12,
1645 * and a binary semaphore, then uxEventQueueLength should be set to
1646 * (5 + 12 + 1), or 18.
1647 * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1648 * should be set to (1 + 1 + 1 ), or 3.
1649 * + If a queue set is to hold a counting semaphore that has a maximum count of
1650 * 5, and a counting semaphore that has a maximum count of 3, then
1651 * uxEventQueueLength should be set to (5 + 3), or 8.
1652 *
1653 * @return If the queue set is created successfully then a handle to the created
1654 * queue set is returned. Otherwise NULL is returned.
1655 */
1656QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1657
1658/*
1659 * Adds a queue or semaphore to a queue set that was previously created by a
1660 * call to xQueueCreateSet().
1661 *
1662 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1663 * function.
1664 *
1665 * Note 1: A receive (in the case of a queue) or take (in the case of a
1666 * semaphore) operation must not be performed on a member of a queue set unless
1667 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1668 *
1669 * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1670 * the queue set (cast to an QueueSetMemberHandle_t type).
1671 *
1672 * @param xQueueSet The handle of the queue set to which the queue or semaphore
1673 * is being added.
1674 *
1675 * @return If the queue or semaphore was successfully added to the queue set
1676 * then pdPASS is returned. If the queue could not be successfully added to the
1677 * queue set because it is already a member of a different queue set then pdFAIL
1678 * is returned.
1679 */
1680BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1681 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1682
1683/*
1684 * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1685 * be removed from a set if the queue or semaphore is empty.
1686 *
1687 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1688 * function.
1689 *
1690 * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1691 * from the queue set (cast to an QueueSetMemberHandle_t type).
1692 *
1693 * @param xQueueSet The handle of the queue set in which the queue or semaphore
1694 * is included.
1695 *
1696 * @return If the queue or semaphore was successfully removed from the queue set
1697 * then pdPASS is returned. If the queue was not in the queue set, or the
1698 * queue (or semaphore) was not empty, then pdFAIL is returned.
1699 */
1700BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1701 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1702
1703/*
1704 * xQueueSelectFromSet() selects from the members of a queue set a queue or
1705 * semaphore that either contains data (in the case of a queue) or is available
1706 * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1707 * allows a task to block (pend) on a read operation on all the queues and
1708 * semaphores in a queue set simultaneously.
1709 *
1710 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1711 * function.
1712 *
alfred gedeond4282092020-09-21 15:49:55 -07001713 * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001714 * for reasons why queue sets are very rarely needed in practice as there are
1715 * simpler methods of blocking on multiple objects.
1716 *
1717 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1718 * mutex holder to inherit the priority of the blocked task.
1719 *
1720 * Note 3: A receive (in the case of a queue) or take (in the case of a
1721 * semaphore) operation must not be performed on a member of a queue set unless
1722 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1723 *
1724 * @param xQueueSet The queue set on which the task will (potentially) block.
1725 *
1726 * @param xTicksToWait The maximum time, in ticks, that the calling task will
1727 * remain in the Blocked state (with other tasks executing) to wait for a member
1728 * of the queue set to be ready for a successful queue read or semaphore take
1729 * operation.
1730 *
1731 * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1732 * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1733 * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1734 * in the queue set that is available, or NULL if no such queue or semaphore
1735 * exists before before the specified block time expires.
1736 */
1737QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
1738 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1739
1740/*
1741 * A version of xQueueSelectFromSet() that can be used from an ISR.
1742 */
1743QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1744
1745/* Not public API functions. */
1746void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
1747 TickType_t xTicksToWait,
1748 const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1749BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
1750 BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1751void vQueueSetQueueNumber( QueueHandle_t xQueue,
1752 UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1753UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1754uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
kar-rahul-aws97050a12023-07-13 16:51:04 +05301755UBaseType_t uxQueueGetQueueItemSize( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
kar-rahul-awscdd36782023-08-18 14:24:44 +05301756UBaseType_t uxQueueGetQueueLength( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
alfred gedeon9a1ebfe2020-08-17 16:16:11 -07001757
1758/* *INDENT-OFF* */
1759#ifdef __cplusplus
1760 }
1761#endif
1762/* *INDENT-ON* */
1763
1764#endif /* QUEUE_H */