2 * FreeRTOS Kernel V10.5.1
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * 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:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
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.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
33 #ifndef INC_FREERTOS_H
34 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
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.
50 struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
51 typedef struct QueueDefinition * QueueHandle_t;
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.
58 typedef struct QueueDefinition * QueueSetHandle_t;
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.
65 typedef struct QueueDefinition * QueueSetMemberHandle_t;
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 )
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 )
83 * QueueHandle_t xQueueCreate(
84 * UBaseType_t uxQueueLength,
85 * UBaseType_t uxItemSize
89 * Creates a new queue instance, and returns a handle by which the new queue
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
97 * https://www.FreeRTOS.org/a00111.html). If a queue is created using
98 * 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.
102 * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
104 * @param uxQueueLength The maximum number of items that the queue can contain.
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
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
123 * void vATask( void *pvParameters )
125 * QueueHandle_t xQueue1, xQueue2;
127 * // Create a queue capable of containing 10 uint32_t values.
128 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
131 * // Queue was not created and must not be used.
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 * ) );
139 * // Queue was not created and must not be used.
142 * // ... Rest of task code.
145 * \defgroup xQueueCreate xQueueCreate
146 * \ingroup QueueManagement
148 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
149 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
155 * QueueHandle_t xQueueCreateStatic(
156 * UBaseType_t uxQueueLength,
157 * UBaseType_t uxItemSize,
158 * uint8_t *pucQueueStorage,
159 * StaticQueue_t *pxQueueBuffer
163 * Creates a new queue instance, and returns a handle by which the new queue
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
171 * https://www.FreeRTOS.org/a00111.html). If a queue is created using
172 * 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.
176 * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
178 * @param uxQueueLength The maximum number of items that the queue can contain.
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
185 * @param pucQueueStorage If uxItemSize is not zero then
186 * pucQueueStorage must point to a uint8_t array that is at least large
187 * 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
189 * zero then pucQueueStorage can be NULL.
191 * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
192 * will be used to hold the queue's data structure.
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.
205 #define QUEUE_LENGTH 10
206 #define ITEM_SIZE sizeof( uint32_t )
208 * // xQueueBuffer will hold the queue structure.
209 * StaticQueue_t xQueueBuffer;
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 ];
215 * void vATask( void *pvParameters )
217 * QueueHandle_t xQueue1;
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.
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.
228 * // ... Rest of task code.
231 * \defgroup xQueueCreateStatic xQueueCreateStatic
232 * \ingroup QueueManagement
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 */
241 * BaseType_t xQueueSendToToFront(
242 * QueueHandle_t xQueue,
243 * const void *pvItemToQueue,
244 * TickType_t xTicksToWait
248 * Post an item to the front of a queue. The item is queued by copy, not by
249 * reference. This function must not be called from an interrupt service
250 * routine. See xQueueSendFromISR () for an alternative which may be used
253 * @param xQueue The handle to the queue on which the item is to be posted.
255 * @param pvItemToQueue A pointer to the item that is to be placed on the
256 * queue. The size of the items the queue will hold was defined when the
257 * queue was created, so this many bytes will be copied from pvItemToQueue
258 * into the queue storage area.
260 * @param xTicksToWait The maximum amount of time the task should block
261 * waiting for space to become available on the queue, should it already
262 * be full. The call will return immediately if this is set to 0 and the
263 * queue is full. The time is defined in tick periods so the constant
264 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
266 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
276 * uint32_t ulVar = 10UL;
278 * void vATask( void *pvParameters )
280 * QueueHandle_t xQueue1, xQueue2;
281 * struct AMessage *pxMessage;
283 * // Create a queue capable of containing 10 uint32_t values.
284 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
286 * // Create a queue capable of containing 10 pointers to AMessage structures.
287 * // These should be passed by pointer as they contain a lot of data.
288 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
294 * // Send an uint32_t. Wait for 10 ticks for space to become
295 * // available if necessary.
296 * if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
298 * // Failed to post the message, even after 10 ticks.
304 * // Send a pointer to a struct AMessage object. Don't block if the
305 * // queue is already full.
306 * pxMessage = & xMessage;
307 * xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
310 * // ... Rest of task code.
313 * \defgroup xQueueSend xQueueSend
314 * \ingroup QueueManagement
316 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \
317 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
322 * BaseType_t xQueueSendToBack(
323 * QueueHandle_t xQueue,
324 * const void *pvItemToQueue,
325 * TickType_t xTicksToWait
329 * This is a macro that calls xQueueGenericSend().
331 * Post an item to the back of a queue. The item is queued by copy, not by
332 * reference. This function must not be called from an interrupt service
333 * routine. See xQueueSendFromISR () for an alternative which may be used
336 * @param xQueue The handle to the queue on which the item is to be posted.
338 * @param pvItemToQueue A pointer to the item that is to be placed on the
339 * queue. The size of the items the queue will hold was defined when the
340 * queue was created, so this many bytes will be copied from pvItemToQueue
341 * into the queue storage area.
343 * @param xTicksToWait The maximum amount of time the task should block
344 * waiting for space to become available on the queue, should it already
345 * be full. The call will return immediately if this is set to 0 and the queue
346 * is full. The time is defined in tick periods so the constant
347 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
349 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
359 * uint32_t ulVar = 10UL;
361 * void vATask( void *pvParameters )
363 * QueueHandle_t xQueue1, xQueue2;
364 * struct AMessage *pxMessage;
366 * // Create a queue capable of containing 10 uint32_t values.
367 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
369 * // Create a queue capable of containing 10 pointers to AMessage structures.
370 * // These should be passed by pointer as they contain a lot of data.
371 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
377 * // Send an uint32_t. Wait for 10 ticks for space to become
378 * // available if necessary.
379 * if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
381 * // Failed to post the message, even after 10 ticks.
387 * // Send a pointer to a struct AMessage object. Don't block if the
388 * // queue is already full.
389 * pxMessage = & xMessage;
390 * xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
393 * // ... Rest of task code.
396 * \defgroup xQueueSend xQueueSend
397 * \ingroup QueueManagement
399 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
400 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
405 * BaseType_t xQueueSend(
406 * QueueHandle_t xQueue,
407 * const void * pvItemToQueue,
408 * TickType_t xTicksToWait
412 * This is a macro that calls xQueueGenericSend(). It is included for
413 * backward compatibility with versions of FreeRTOS.org that did not
414 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
415 * equivalent to xQueueSendToBack().
417 * Post an item on a queue. The item is queued by copy, not by reference.
418 * This function must not be called from an interrupt service routine.
419 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
421 * @param xQueue The handle to the queue on which the item is to be posted.
423 * @param pvItemToQueue A pointer to the item that is to be placed on the
424 * queue. The size of the items the queue will hold was defined when the
425 * queue was created, so this many bytes will be copied from pvItemToQueue
426 * into the queue storage area.
428 * @param xTicksToWait The maximum amount of time the task should block
429 * waiting for space to become available on the queue, should it already
430 * be full. The call will return immediately if this is set to 0 and the
431 * queue is full. The time is defined in tick periods so the constant
432 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
434 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
444 * uint32_t ulVar = 10UL;
446 * void vATask( void *pvParameters )
448 * QueueHandle_t xQueue1, xQueue2;
449 * struct AMessage *pxMessage;
451 * // Create a queue capable of containing 10 uint32_t values.
452 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
454 * // Create a queue capable of containing 10 pointers to AMessage structures.
455 * // These should be passed by pointer as they contain a lot of data.
456 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
462 * // Send an uint32_t. Wait for 10 ticks for space to become
463 * // available if necessary.
464 * if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
466 * // Failed to post the message, even after 10 ticks.
472 * // Send a pointer to a struct AMessage object. Don't block if the
473 * // queue is already full.
474 * pxMessage = & xMessage;
475 * xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
478 * // ... Rest of task code.
481 * \defgroup xQueueSend xQueueSend
482 * \ingroup QueueManagement
484 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
485 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
490 * BaseType_t xQueueOverwrite(
491 * QueueHandle_t xQueue,
492 * const void * pvItemToQueue
496 * Only for use with queues that have a length of one - so the queue is either
499 * Post an item on a queue. If the queue is already full then overwrite the
500 * value held in the queue. The item is queued by copy, not by reference.
502 * This function must not be called from an interrupt service routine.
503 * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
505 * @param xQueue The handle of the queue to which the data is being sent.
507 * @param pvItemToQueue A pointer to the item that is to be placed on the
508 * queue. The size of the items the queue will hold was defined when the
509 * queue was created, so this many bytes will be copied from pvItemToQueue
510 * into the queue storage area.
512 * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
513 * therefore has the same return values as xQueueSendToFront(). However, pdPASS
514 * is the only value that can be returned because xQueueOverwrite() will write
515 * to the queue even when the queue is already full.
520 * void vFunction( void *pvParameters )
522 * QueueHandle_t xQueue;
523 * uint32_t ulVarToSend, ulValReceived;
525 * // Create a queue to hold one uint32_t value. It is strongly
526 * // recommended *not* to use xQueueOverwrite() on queues that can
527 * // contain more than one value, and doing so will trigger an assertion
528 * // if configASSERT() is defined.
529 * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
531 * // Write the value 10 to the queue using xQueueOverwrite().
533 * xQueueOverwrite( xQueue, &ulVarToSend );
535 * // Peeking the queue should now return 10, but leave the value 10 in
536 * // the queue. A block time of zero is used as it is known that the
537 * // queue holds a value.
539 * xQueuePeek( xQueue, &ulValReceived, 0 );
541 * if( ulValReceived != 10 )
543 * // Error unless the item was removed by a different task.
546 * // The queue is still full. Use xQueueOverwrite() to overwrite the
547 * // value held in the queue with 100.
549 * xQueueOverwrite( xQueue, &ulVarToSend );
551 * // This time read from the queue, leaving the queue empty once more.
552 * // A block time of 0 is used again.
553 * xQueueReceive( xQueue, &ulValReceived, 0 );
555 * // The value read should be the last value written, even though the
556 * // queue was already full when the value was written.
557 * if( ulValReceived != 100 )
565 * \defgroup xQueueOverwrite xQueueOverwrite
566 * \ingroup QueueManagement
568 #define xQueueOverwrite( xQueue, pvItemToQueue ) \
569 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
575 * BaseType_t xQueueGenericSend(
576 * QueueHandle_t xQueue,
577 * const void * pvItemToQueue,
578 * TickType_t xTicksToWait
579 * BaseType_t xCopyPosition
583 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
584 * xQueueSendToBack() are used in place of calling this function directly.
586 * Post an item on a queue. The item is queued by copy, not by reference.
587 * This function must not be called from an interrupt service routine.
588 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
590 * @param xQueue The handle to the queue on which the item is to be posted.
592 * @param pvItemToQueue A pointer to the item that is to be placed on the
593 * queue. The size of the items the queue will hold was defined when the
594 * queue was created, so this many bytes will be copied from pvItemToQueue
595 * into the queue storage area.
597 * @param xTicksToWait The maximum amount of time the task should block
598 * waiting for space to become available on the queue, should it already
599 * be full. The call will return immediately if this is set to 0 and the
600 * queue is full. The time is defined in tick periods so the constant
601 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
603 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
604 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
605 * at the front of the queue (for high priority messages).
607 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
617 * uint32_t ulVar = 10UL;
619 * void vATask( void *pvParameters )
621 * QueueHandle_t xQueue1, xQueue2;
622 * struct AMessage *pxMessage;
624 * // Create a queue capable of containing 10 uint32_t values.
625 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
627 * // Create a queue capable of containing 10 pointers to AMessage structures.
628 * // These should be passed by pointer as they contain a lot of data.
629 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
635 * // Send an uint32_t. Wait for 10 ticks for space to become
636 * // available if necessary.
637 * if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
639 * // Failed to post the message, even after 10 ticks.
645 * // Send a pointer to a struct AMessage object. Don't block if the
646 * // queue is already full.
647 * pxMessage = & xMessage;
648 * xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
651 * // ... Rest of task code.
654 * \defgroup xQueueSend xQueueSend
655 * \ingroup QueueManagement
657 BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
658 const void * const pvItemToQueue,
659 TickType_t xTicksToWait,
660 const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
665 * BaseType_t xQueuePeek(
666 * QueueHandle_t xQueue,
667 * void * const pvBuffer,
668 * TickType_t xTicksToWait
672 * Receive an item from a queue without removing the item from the queue.
673 * The item is received by copy so a buffer of adequate size must be
674 * provided. The number of bytes copied into the buffer was defined when
675 * the queue was created.
677 * Successfully received items remain on the queue so will be returned again
678 * by the next call, or a call to xQueueReceive().
680 * This macro must not be used in an interrupt service routine. See
681 * xQueuePeekFromISR() for an alternative that can be called from an interrupt
684 * @param xQueue The handle to the queue from which the item is to be
687 * @param pvBuffer Pointer to the buffer into which the received item will
690 * @param xTicksToWait The maximum amount of time the task should block
691 * waiting for an item to receive should the queue be empty at the time
692 * of the call. The time is defined in tick periods so the constant
693 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
694 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
697 * @return pdTRUE if an item was successfully received from the queue,
708 * QueueHandle_t xQueue;
710 * // Task to create a queue and post a value.
711 * void vATask( void *pvParameters )
713 * struct AMessage *pxMessage;
715 * // Create a queue capable of containing 10 pointers to AMessage structures.
716 * // These should be passed by pointer as they contain a lot of data.
717 * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
720 * // Failed to create the queue.
725 * // Send a pointer to a struct AMessage object. Don't block if the
726 * // queue is already full.
727 * pxMessage = & xMessage;
728 * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
730 * // ... Rest of task code.
733 * // Task to peek the data from the queue.
734 * void vADifferentTask( void *pvParameters )
736 * struct AMessage *pxRxedMessage;
740 * // Peek a message on the created queue. Block for 10 ticks if a
741 * // message is not immediately available.
742 * if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
744 * // pcRxedMessage now points to the struct AMessage variable posted
745 * // by vATask, but the item still remains on the queue.
749 * // ... Rest of task code.
752 * \defgroup xQueuePeek xQueuePeek
753 * \ingroup QueueManagement
755 BaseType_t xQueuePeek( QueueHandle_t xQueue,
756 void * const pvBuffer,
757 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
762 * BaseType_t xQueuePeekFromISR(
763 * QueueHandle_t xQueue,
768 * A version of xQueuePeek() that can be called from an interrupt service
771 * Receive an item from a queue without removing the item from the queue.
772 * The item is received by copy so a buffer of adequate size must be
773 * provided. The number of bytes copied into the buffer was defined when
774 * the queue was created.
776 * Successfully received items remain on the queue so will be returned again
777 * by the next call, or a call to xQueueReceive().
779 * @param xQueue The handle to the queue from which the item is to be
782 * @param pvBuffer Pointer to the buffer into which the received item will
785 * @return pdTRUE if an item was successfully received from the queue,
788 * \defgroup xQueuePeekFromISR xQueuePeekFromISR
789 * \ingroup QueueManagement
791 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
792 void * const pvBuffer ) PRIVILEGED_FUNCTION;
797 * BaseType_t xQueueReceive(
798 * QueueHandle_t xQueue,
800 * TickType_t xTicksToWait
804 * Receive an item from a queue. The item is received by copy so a buffer of
805 * adequate size must be provided. The number of bytes copied into the buffer
806 * was defined when the queue was created.
808 * Successfully received items are removed from the queue.
810 * This function must not be used in an interrupt service routine. See
811 * xQueueReceiveFromISR for an alternative that can.
813 * @param xQueue The handle to the queue from which the item is to be
816 * @param pvBuffer Pointer to the buffer into which the received item will
819 * @param xTicksToWait The maximum amount of time the task should block
820 * waiting for an item to receive should the queue be empty at the time
821 * of the call. xQueueReceive() will return immediately if xTicksToWait
822 * is zero and the queue is empty. The time is defined in tick periods so the
823 * constant portTICK_PERIOD_MS should be used to convert to real time if this is
826 * @return pdTRUE if an item was successfully received from the queue,
837 * QueueHandle_t xQueue;
839 * // Task to create a queue and post a value.
840 * void vATask( void *pvParameters )
842 * struct AMessage *pxMessage;
844 * // Create a queue capable of containing 10 pointers to AMessage structures.
845 * // These should be passed by pointer as they contain a lot of data.
846 * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
849 * // Failed to create the queue.
854 * // Send a pointer to a struct AMessage object. Don't block if the
855 * // queue is already full.
856 * pxMessage = & xMessage;
857 * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
859 * // ... Rest of task code.
862 * // Task to receive from the queue.
863 * void vADifferentTask( void *pvParameters )
865 * struct AMessage *pxRxedMessage;
869 * // Receive a message on the created queue. Block for 10 ticks if a
870 * // message is not immediately available.
871 * if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
873 * // pcRxedMessage now points to the struct AMessage variable posted
878 * // ... Rest of task code.
881 * \defgroup xQueueReceive xQueueReceive
882 * \ingroup QueueManagement
884 BaseType_t xQueueReceive( QueueHandle_t xQueue,
885 void * const pvBuffer,
886 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
891 * UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
894 * Return the number of messages stored in a queue.
896 * @param xQueue A handle to the queue being queried.
898 * @return The number of messages available in the queue.
900 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
901 * \ingroup QueueManagement
903 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
908 * UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
911 * Return the number of free spaces available in a queue. This is equal to the
912 * number of items that can be sent to the queue before the queue becomes full
913 * if no items are removed.
915 * @param xQueue A handle to the queue being queried.
917 * @return The number of spaces available in the queue.
919 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
920 * \ingroup QueueManagement
922 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
927 * void vQueueDelete( QueueHandle_t xQueue );
930 * Delete a queue - freeing all the memory allocated for storing of items
931 * placed on the queue.
933 * @param xQueue A handle to the queue to be deleted.
935 * \defgroup vQueueDelete vQueueDelete
936 * \ingroup QueueManagement
938 void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
943 * BaseType_t xQueueSendToFrontFromISR(
944 * QueueHandle_t xQueue,
945 * const void *pvItemToQueue,
946 * BaseType_t *pxHigherPriorityTaskWoken
950 * This is a macro that calls xQueueGenericSendFromISR().
952 * Post an item to the front of a queue. It is safe to use this macro from
953 * within an interrupt service routine.
955 * Items are queued by copy not reference so it is preferable to only
956 * queue small items, especially when called from an ISR. In most cases
957 * it would be preferable to store a pointer to the item being queued.
959 * @param xQueue The handle to the queue on which the item is to be posted.
961 * @param pvItemToQueue A pointer to the item that is to be placed on the
962 * queue. The size of the items the queue will hold was defined when the
963 * queue was created, so this many bytes will be copied from pvItemToQueue
964 * into the queue storage area.
966 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
967 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
968 * to unblock, and the unblocked task has a priority higher than the currently
969 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
970 * a context switch should be requested before the interrupt is exited.
972 * @return pdTRUE if the data was successfully sent to the queue, otherwise
975 * Example usage for buffered IO (where the ISR can obtain more than one value
978 * void vBufferISR( void )
981 * BaseType_t xHigherPriorityTaskWoken;
983 * // We have not woken a task at the start of the ISR.
984 * xHigherPriorityTaskWoken = pdFALSE;
986 * // Loop until the buffer is empty.
989 * // Obtain a byte from the buffer.
990 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
993 * xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
995 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
997 * // Now the buffer is empty we can switch context if necessary.
998 * if( xHigherPriorityTaskWoken )
1005 * \defgroup xQueueSendFromISR xQueueSendFromISR
1006 * \ingroup QueueManagement
1008 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1009 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
1015 * BaseType_t xQueueSendToBackFromISR(
1016 * QueueHandle_t xQueue,
1017 * const void *pvItemToQueue,
1018 * BaseType_t *pxHigherPriorityTaskWoken
1022 * This is a macro that calls xQueueGenericSendFromISR().
1024 * Post an item to the back of a queue. It is safe to use this macro from
1025 * within an interrupt service routine.
1027 * Items are queued by copy not reference so it is preferable to only
1028 * queue small items, especially when called from an ISR. In most cases
1029 * it would be preferable to store a pointer to the item being queued.
1031 * @param xQueue The handle to the queue on which the item is to be posted.
1033 * @param pvItemToQueue A pointer to the item that is to be placed on the
1034 * queue. The size of the items the queue will hold was defined when the
1035 * queue was created, so this many bytes will be copied from pvItemToQueue
1036 * into the queue storage area.
1038 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
1039 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1040 * to unblock, and the unblocked task has a priority higher than the currently
1041 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
1042 * a context switch should be requested before the interrupt is exited.
1044 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1047 * Example usage for buffered IO (where the ISR can obtain more than one value
1050 * void vBufferISR( void )
1053 * BaseType_t xHigherPriorityTaskWoken;
1055 * // We have not woken a task at the start of the ISR.
1056 * xHigherPriorityTaskWoken = pdFALSE;
1058 * // Loop until the buffer is empty.
1061 * // Obtain a byte from the buffer.
1062 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1065 * xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1067 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1069 * // Now the buffer is empty we can switch context if necessary.
1070 * if( xHigherPriorityTaskWoken )
1077 * \defgroup xQueueSendFromISR xQueueSendFromISR
1078 * \ingroup QueueManagement
1080 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1081 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1086 * BaseType_t xQueueOverwriteFromISR(
1087 * QueueHandle_t xQueue,
1088 * const void * pvItemToQueue,
1089 * BaseType_t *pxHigherPriorityTaskWoken
1093 * A version of xQueueOverwrite() that can be used in an interrupt service
1096 * Only for use with queues that can hold a single item - so the queue is either
1099 * Post an item on a queue. If the queue is already full then overwrite the
1100 * value held in the queue. The item is queued by copy, not by reference.
1102 * @param xQueue The handle to the queue on which the item is to be posted.
1104 * @param pvItemToQueue A pointer to the item that is to be placed on the
1105 * queue. The size of the items the queue will hold was defined when the
1106 * queue was created, so this many bytes will be copied from pvItemToQueue
1107 * into the queue storage area.
1109 * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
1110 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1111 * to unblock, and the unblocked task has a priority higher than the currently
1112 * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
1113 * a context switch should be requested before the interrupt is exited.
1115 * @return xQueueOverwriteFromISR() is a macro that calls
1116 * xQueueGenericSendFromISR(), and therefore has the same return values as
1117 * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
1118 * returned because xQueueOverwriteFromISR() will write to the queue even when
1119 * the queue is already full.
1124 * QueueHandle_t xQueue;
1126 * void vFunction( void *pvParameters )
1128 * // Create a queue to hold one uint32_t value. It is strongly
1129 * // recommended *not* to use xQueueOverwriteFromISR() on queues that can
1130 * // contain more than one value, and doing so will trigger an assertion
1131 * // if configASSERT() is defined.
1132 * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
1135 * void vAnInterruptHandler( void )
1137 * // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
1138 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
1139 * uint32_t ulVarToSend, ulValReceived;
1141 * // Write the value 10 to the queue using xQueueOverwriteFromISR().
1143 * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1145 * // The queue is full, but calling xQueueOverwriteFromISR() again will still
1146 * // pass because the value held in the queue will be overwritten with the
1148 * ulVarToSend = 100;
1149 * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1151 * // Reading from the queue will now return 100.
1155 * if( xHigherPrioritytaskWoken == pdTRUE )
1157 * // Writing to the queue caused a task to unblock and the unblocked task
1158 * // has a priority higher than or equal to the priority of the currently
1159 * // executing task (the task this interrupt interrupted). Perform a context
1160 * // switch so this interrupt returns directly to the unblocked task.
1161 * portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
1165 * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
1166 * \ingroup QueueManagement
1168 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1169 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1174 * BaseType_t xQueueSendFromISR(
1175 * QueueHandle_t xQueue,
1176 * const void *pvItemToQueue,
1177 * BaseType_t *pxHigherPriorityTaskWoken
1181 * This is a macro that calls xQueueGenericSendFromISR(). It is included
1182 * for backward compatibility with versions of FreeRTOS.org that did not
1183 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
1186 * Post an item to the back of a queue. It is safe to use this function from
1187 * within an interrupt service routine.
1189 * Items are queued by copy not reference so it is preferable to only
1190 * queue small items, especially when called from an ISR. In most cases
1191 * it would be preferable to store a pointer to the item being queued.
1193 * @param xQueue The handle to the queue on which the item is to be posted.
1195 * @param pvItemToQueue A pointer to the item that is to be placed on the
1196 * queue. The size of the items the queue will hold was defined when the
1197 * queue was created, so this many bytes will be copied from pvItemToQueue
1198 * into the queue storage area.
1200 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
1201 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1202 * to unblock, and the unblocked task has a priority higher than the currently
1203 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
1204 * a context switch should be requested before the interrupt is exited.
1206 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1209 * Example usage for buffered IO (where the ISR can obtain more than one value
1212 * void vBufferISR( void )
1215 * BaseType_t xHigherPriorityTaskWoken;
1217 * // We have not woken a task at the start of the ISR.
1218 * xHigherPriorityTaskWoken = pdFALSE;
1220 * // Loop until the buffer is empty.
1223 * // Obtain a byte from the buffer.
1224 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1227 * xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1229 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1231 * // Now the buffer is empty we can switch context if necessary.
1232 * if( xHigherPriorityTaskWoken )
1234 * // Actual macro used here is port specific.
1235 * portYIELD_FROM_ISR ();
1240 * \defgroup xQueueSendFromISR xQueueSendFromISR
1241 * \ingroup QueueManagement
1243 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1244 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1249 * BaseType_t xQueueGenericSendFromISR(
1250 * QueueHandle_t xQueue,
1251 * const void *pvItemToQueue,
1252 * BaseType_t *pxHigherPriorityTaskWoken,
1253 * BaseType_t xCopyPosition
1257 * It is preferred that the macros xQueueSendFromISR(),
1258 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1259 * of calling this function directly. xQueueGiveFromISR() is an
1260 * equivalent for use by semaphores that don't actually copy any data.
1262 * Post an item on a queue. It is safe to use this function from within an
1263 * interrupt service routine.
1265 * Items are queued by copy not reference so it is preferable to only
1266 * queue small items, especially when called from an ISR. In most cases
1267 * it would be preferable to store a pointer to the item being queued.
1269 * @param xQueue The handle to the queue on which the item is to be posted.
1271 * @param pvItemToQueue A pointer to the item that is to be placed on the
1272 * queue. The size of the items the queue will hold was defined when the
1273 * queue was created, so this many bytes will be copied from pvItemToQueue
1274 * into the queue storage area.
1276 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1277 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1278 * to unblock, and the unblocked task has a priority higher than the currently
1279 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
1280 * a context switch should be requested before the interrupt is exited.
1282 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1283 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1284 * at the front of the queue (for high priority messages).
1286 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1289 * Example usage for buffered IO (where the ISR can obtain more than one value
1292 * void vBufferISR( void )
1295 * BaseType_t xHigherPriorityTaskWokenByPost;
1297 * // We have not woken a task at the start of the ISR.
1298 * xHigherPriorityTaskWokenByPost = pdFALSE;
1300 * // Loop until the buffer is empty.
1303 * // Obtain a byte from the buffer.
1304 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1306 * // Post each byte.
1307 * xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1309 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1311 * // Now the buffer is empty we can switch context if necessary. Note that the
1312 * // name of the yield function required is port specific.
1313 * if( xHigherPriorityTaskWokenByPost )
1315 * portYIELD_FROM_ISR();
1320 * \defgroup xQueueSendFromISR xQueueSendFromISR
1321 * \ingroup QueueManagement
1323 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
1324 const void * const pvItemToQueue,
1325 BaseType_t * const pxHigherPriorityTaskWoken,
1326 const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1327 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
1328 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1333 * BaseType_t xQueueReceiveFromISR(
1334 * QueueHandle_t xQueue,
1336 * BaseType_t *pxTaskWoken
1340 * Receive an item from a queue. It is safe to use this function from within an
1341 * interrupt service routine.
1343 * @param xQueue The handle to the queue from which the item is to be
1346 * @param pvBuffer Pointer to the buffer into which the received item will
1349 * @param pxTaskWoken A task may be blocked waiting for space to become
1350 * available on the queue. If xQueueReceiveFromISR causes such a task to
1351 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
1354 * @return pdTRUE if an item was successfully received from the queue,
1355 * otherwise pdFALSE.
1360 * QueueHandle_t xQueue;
1362 * // Function to create a queue and post some values.
1363 * void vAFunction( void *pvParameters )
1365 * char cValueToPost;
1366 * const TickType_t xTicksToWait = ( TickType_t )0xff;
1368 * // Create a queue capable of containing 10 characters.
1369 * xQueue = xQueueCreate( 10, sizeof( char ) );
1372 * // Failed to create the queue.
1377 * // Post some characters that will be used within an ISR. If the queue
1378 * // is full then this task will block for xTicksToWait ticks.
1379 * cValueToPost = 'a';
1380 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1381 * cValueToPost = 'b';
1382 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1384 * // ... keep posting characters ... this task may block when the queue
1387 * cValueToPost = 'c';
1388 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1391 * // ISR that outputs all the characters received on the queue.
1392 * void vISR_Routine( void )
1394 * BaseType_t xTaskWokenByReceive = pdFALSE;
1397 * while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1399 * // A character was received. Output the character now.
1400 * vOutputCharacter( cRxedChar );
1402 * // If removing the character from the queue woke the task that was
1403 * // posting onto the queue xTaskWokenByReceive will have been set to
1404 * // pdTRUE. No matter how many times this loop iterates only one
1405 * // task will be woken.
1408 * if( xTaskWokenByReceive != ( char ) pdFALSE;
1414 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
1415 * \ingroup QueueManagement
1417 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
1418 void * const pvBuffer,
1419 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1422 * Utilities to query queues that are safe to use from an ISR. These utilities
1423 * should be used only from within an ISR, or within a critical section.
1425 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1426 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1427 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1430 * The functions defined above are for passing data to and from tasks. The
1431 * functions below are the equivalents for passing data to and from
1434 * These functions are called from the co-routine macro implementation and
1435 * should not be called directly from application code. Instead use the macro
1436 * wrappers defined within croutine.h.
1438 BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue,
1439 const void * pvItemToQueue,
1440 BaseType_t xCoRoutinePreviouslyWoken );
1441 BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue,
1443 BaseType_t * pxTaskWoken );
1444 BaseType_t xQueueCRSend( QueueHandle_t xQueue,
1445 const void * pvItemToQueue,
1446 TickType_t xTicksToWait );
1447 BaseType_t xQueueCRReceive( QueueHandle_t xQueue,
1449 TickType_t xTicksToWait );
1452 * For internal use only. Use xSemaphoreCreateMutex(),
1453 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1454 * these functions directly.
1456 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1457 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
1458 StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1459 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
1460 const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1461 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
1462 const UBaseType_t uxInitialCount,
1463 StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1464 BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
1465 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1466 TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1467 TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1470 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1471 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1473 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
1474 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1475 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
1478 * Reset a queue back to its original empty state. The return value is now
1479 * obsolete and is always set to pdPASS.
1481 #define xQueueReset( xQueue ) xQueueGenericReset( ( xQueue ), pdFALSE )
1484 * The registry is provided as a means for kernel aware debuggers to
1485 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1486 * a queue, semaphore or mutex handle to the registry if you want the handle
1487 * to be available to a kernel aware debugger. If you are not using a kernel
1488 * aware debugger then this function can be ignored.
1490 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1491 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1492 * within FreeRTOSConfig.h for the registry to be available. Its value
1493 * does not affect the number of queues, semaphores and mutexes that can be
1494 * created - just the number that the registry can hold.
1496 * If vQueueAddToRegistry is called more than once with the same xQueue
1497 * parameter, the registry will store the pcQueueName parameter from the
1498 * most recent call to vQueueAddToRegistry.
1500 * @param xQueue The handle of the queue being added to the registry. This
1501 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1502 * handles can also be passed in here.
1504 * @param pcQueueName The name to be associated with the handle. This is the
1505 * name that the kernel aware debugger will display. The queue registry only
1506 * stores a pointer to the string - so the string must be persistent (global or
1507 * preferably in ROM/Flash), not on the stack.
1509 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1510 void vQueueAddToRegistry( QueueHandle_t xQueue,
1511 const char * pcQueueName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1515 * The registry is provided as a means for kernel aware debuggers to
1516 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1517 * a queue, semaphore or mutex handle to the registry if you want the handle
1518 * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1519 * remove the queue, semaphore or mutex from the register. If you are not using
1520 * a kernel aware debugger then this function can be ignored.
1522 * @param xQueue The handle of the queue being removed from the registry.
1524 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1525 void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1529 * The queue registry is provided as a means for kernel aware debuggers to
1530 * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
1531 * up and return the name of a queue in the queue registry from the queue's
1534 * @param xQueue The handle of the queue the name of which will be returned.
1535 * @return If the queue is in the registry then a pointer to the name of the
1536 * queue is returned. If the queue is not in the registry then NULL is
1539 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1540 const char * pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1544 * Generic version of the function used to create a queue using dynamic memory
1545 * allocation. This is called by other functions and macros that create other
1546 * RTOS objects that use the queue structure as their base.
1548 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1549 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
1550 const UBaseType_t uxItemSize,
1551 const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1555 * Generic version of the function used to create a queue using dynamic memory
1556 * allocation. This is called by other functions and macros that create other
1557 * RTOS objects that use the queue structure as their base.
1559 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1560 QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
1561 const UBaseType_t uxItemSize,
1562 uint8_t * pucQueueStorage,
1563 StaticQueue_t * pxStaticQueue,
1564 const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1568 * Queue sets provide a mechanism to allow a task to block (pend) on a read
1569 * operation from multiple queues or semaphores simultaneously.
1571 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1574 * A queue set must be explicitly created using a call to xQueueCreateSet()
1575 * before it can be used. Once created, standard FreeRTOS queues and semaphores
1576 * can be added to the set using calls to xQueueAddToSet().
1577 * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1578 * or semaphores contained in the set is in a state where a queue read or
1579 * semaphore take operation would be successful.
1581 * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
1582 * for reasons why queue sets are very rarely needed in practice as there are
1583 * simpler methods of blocking on multiple objects.
1585 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1586 * mutex holder to inherit the priority of the blocked task.
1588 * Note 3: An additional 4 bytes of RAM is required for each space in a every
1589 * queue added to a queue set. Therefore counting semaphores that have a high
1590 * maximum count value should not be added to a queue set.
1592 * Note 4: A receive (in the case of a queue) or take (in the case of a
1593 * semaphore) operation must not be performed on a member of a queue set unless
1594 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1596 * @param uxEventQueueLength Queue sets store events that occur on
1597 * the queues and semaphores contained in the set. uxEventQueueLength specifies
1598 * the maximum number of events that can be queued at once. To be absolutely
1599 * certain that events are not lost uxEventQueueLength should be set to the
1600 * total sum of the length of the queues added to the set, where binary
1601 * semaphores and mutexes have a length of 1, and counting semaphores have a
1602 * length set by their maximum count value. Examples:
1603 * + If a queue set is to hold a queue of length 5, another queue of length 12,
1604 * and a binary semaphore, then uxEventQueueLength should be set to
1605 * (5 + 12 + 1), or 18.
1606 * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1607 * should be set to (1 + 1 + 1 ), or 3.
1608 * + If a queue set is to hold a counting semaphore that has a maximum count of
1609 * 5, and a counting semaphore that has a maximum count of 3, then
1610 * uxEventQueueLength should be set to (5 + 3), or 8.
1612 * @return If the queue set is created successfully then a handle to the created
1613 * queue set is returned. Otherwise NULL is returned.
1615 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1618 * Adds a queue or semaphore to a queue set that was previously created by a
1619 * call to xQueueCreateSet().
1621 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1624 * Note 1: A receive (in the case of a queue) or take (in the case of a
1625 * semaphore) operation must not be performed on a member of a queue set unless
1626 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1628 * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1629 * the queue set (cast to an QueueSetMemberHandle_t type).
1631 * @param xQueueSet The handle of the queue set to which the queue or semaphore
1634 * @return If the queue or semaphore was successfully added to the queue set
1635 * then pdPASS is returned. If the queue could not be successfully added to the
1636 * queue set because it is already a member of a different queue set then pdFAIL
1639 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1640 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1643 * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1644 * be removed from a set if the queue or semaphore is empty.
1646 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1649 * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1650 * from the queue set (cast to an QueueSetMemberHandle_t type).
1652 * @param xQueueSet The handle of the queue set in which the queue or semaphore
1655 * @return If the queue or semaphore was successfully removed from the queue set
1656 * then pdPASS is returned. If the queue was not in the queue set, or the
1657 * queue (or semaphore) was not empty, then pdFAIL is returned.
1659 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1660 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1663 * xQueueSelectFromSet() selects from the members of a queue set a queue or
1664 * semaphore that either contains data (in the case of a queue) or is available
1665 * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1666 * allows a task to block (pend) on a read operation on all the queues and
1667 * semaphores in a queue set simultaneously.
1669 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1672 * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
1673 * for reasons why queue sets are very rarely needed in practice as there are
1674 * simpler methods of blocking on multiple objects.
1676 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1677 * mutex holder to inherit the priority of the blocked task.
1679 * Note 3: A receive (in the case of a queue) or take (in the case of a
1680 * semaphore) operation must not be performed on a member of a queue set unless
1681 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1683 * @param xQueueSet The queue set on which the task will (potentially) block.
1685 * @param xTicksToWait The maximum time, in ticks, that the calling task will
1686 * remain in the Blocked state (with other tasks executing) to wait for a member
1687 * of the queue set to be ready for a successful queue read or semaphore take
1690 * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1691 * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1692 * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1693 * in the queue set that is available, or NULL if no such queue or semaphore
1694 * exists before before the specified block time expires.
1696 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
1697 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1700 * A version of xQueueSelectFromSet() that can be used from an ISR.
1702 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1704 /* Not public API functions. */
1705 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
1706 TickType_t xTicksToWait,
1707 const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1708 BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
1709 BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1710 void vQueueSetQueueNumber( QueueHandle_t xQueue,
1711 UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1712 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1713 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1722 #endif /* QUEUE_H */