2 * FreeRTOS Kernel V10.2.1
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
32 #ifndef INC_FREERTOS_H
33 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
43 * Type by which queues are referenced. For example, a call to xQueueCreate()
44 * returns an QueueHandle_t variable that can then be used as a parameter to
45 * xQueueSend(), xQueueReceive(), etc.
47 struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
48 typedef struct QueueDefinition * QueueHandle_t;
51 * Type by which queue sets are referenced. For example, a call to
52 * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
53 * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
55 typedef struct QueueDefinition * QueueSetHandle_t;
58 * Queue sets can contain both queues and semaphores, so the
59 * QueueSetMemberHandle_t is defined as a type to be used where a parameter or
60 * return value can be either an QueueHandle_t or an SemaphoreHandle_t.
62 typedef struct QueueDefinition * QueueSetMemberHandle_t;
64 /* For internal use only. */
65 #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
66 #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
67 #define queueOVERWRITE ( ( BaseType_t ) 2 )
69 /* For internal use only. These definitions *must* match those in queue.c. */
70 #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
71 #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
72 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
73 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
74 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
75 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
80 QueueHandle_t xQueueCreate(
81 UBaseType_t uxQueueLength,
82 UBaseType_t uxItemSize
86 * Creates a new queue instance, and returns a handle by which the new queue
89 * Internally, within the FreeRTOS implementation, queues use two blocks of
90 * memory. The first block is used to hold the queue's data structures. The
91 * second block is used to hold items placed into the queue. If a queue is
92 * created using xQueueCreate() then both blocks of memory are automatically
93 * dynamically allocated inside the xQueueCreate() function. (see
94 * http://www.freertos.org/a00111.html). If a queue is created using
95 * xQueueCreateStatic() then the application writer must provide the memory that
96 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
97 * be created without using any dynamic memory allocation.
99 * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html
101 * @param uxQueueLength The maximum number of items that the queue can contain.
103 * @param uxItemSize The number of bytes each item in the queue will require.
104 * Items are queued by copy, not by reference, so this is the number of bytes
105 * that will be copied for each posted item. Each item on the queue must be
108 * @return If the queue is successfully create then a handle to the newly
109 * created queue is returned. If the queue cannot be created then 0 is
120 void vATask( void *pvParameters )
122 QueueHandle_t xQueue1, xQueue2;
124 // Create a queue capable of containing 10 uint32_t values.
125 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
128 // Queue was not created and must not be used.
131 // Create a queue capable of containing 10 pointers to AMessage structures.
132 // These should be passed by pointer as they contain a lot of data.
133 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
136 // Queue was not created and must not be used.
139 // ... Rest of task code.
142 * \defgroup xQueueCreate xQueueCreate
143 * \ingroup QueueManagement
145 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
146 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
152 QueueHandle_t xQueueCreateStatic(
153 UBaseType_t uxQueueLength,
154 UBaseType_t uxItemSize,
155 uint8_t *pucQueueStorageBuffer,
156 StaticQueue_t *pxQueueBuffer
160 * Creates a new queue instance, and returns a handle by which the new queue
163 * Internally, within the FreeRTOS implementation, queues use two blocks of
164 * memory. The first block is used to hold the queue's data structures. The
165 * second block is used to hold items placed into the queue. If a queue is
166 * created using xQueueCreate() then both blocks of memory are automatically
167 * dynamically allocated inside the xQueueCreate() function. (see
168 * http://www.freertos.org/a00111.html). If a queue is created using
169 * xQueueCreateStatic() then the application writer must provide the memory that
170 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
171 * be created without using any dynamic memory allocation.
173 * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html
175 * @param uxQueueLength The maximum number of items that the queue can contain.
177 * @param uxItemSize The number of bytes each item in the queue will require.
178 * Items are queued by copy, not by reference, so this is the number of bytes
179 * that will be copied for each posted item. Each item on the queue must be
182 * @param pucQueueStorageBuffer If uxItemSize is not zero then
183 * pucQueueStorageBuffer must point to a uint8_t array that is at least large
184 * enough to hold the maximum number of items that can be in the queue at any
185 * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
186 * zero then pucQueueStorageBuffer can be NULL.
188 * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
189 * will be used to hold the queue's data structure.
191 * @return If the queue is created then a handle to the created queue is
192 * returned. If pxQueueBuffer is NULL then NULL is returned.
202 #define QUEUE_LENGTH 10
203 #define ITEM_SIZE sizeof( uint32_t )
205 // xQueueBuffer will hold the queue structure.
206 StaticQueue_t xQueueBuffer;
208 // ucQueueStorage will hold the items posted to the queue. Must be at least
209 // [(queue length) * ( queue item size)] bytes long.
210 uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
212 void vATask( void *pvParameters )
214 QueueHandle_t xQueue1;
216 // Create a queue capable of containing 10 uint32_t values.
217 xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
218 ITEM_SIZE // The size of each item in the queue
219 &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
220 &xQueueBuffer ); // The buffer that will hold the queue structure.
222 // The queue is guaranteed to be created successfully as no dynamic memory
223 // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
225 // ... Rest of task code.
228 * \defgroup xQueueCreateStatic xQueueCreateStatic
229 * \ingroup QueueManagement
231 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
232 #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
233 #endif /* configSUPPORT_STATIC_ALLOCATION */
238 BaseType_t xQueueSendToToFront(
239 QueueHandle_t xQueue,
240 const void *pvItemToQueue,
241 TickType_t xTicksToWait
245 * Post an item to the front of a queue. The item is queued by copy, not by
246 * reference. This function must not be called from an interrupt service
247 * routine. See xQueueSendFromISR () for an alternative which may be used
250 * @param xQueue The handle to the queue on which the item is to be posted.
252 * @param pvItemToQueue A pointer to the item that is to be placed on the
253 * queue. The size of the items the queue will hold was defined when the
254 * queue was created, so this many bytes will be copied from pvItemToQueue
255 * into the queue storage area.
257 * @param xTicksToWait The maximum amount of time the task should block
258 * waiting for space to become available on the queue, should it already
259 * be full. The call will return immediately if this is set to 0 and the
260 * queue is full. The time is defined in tick periods so the constant
261 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
263 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
273 uint32_t ulVar = 10UL;
275 void vATask( void *pvParameters )
277 QueueHandle_t xQueue1, xQueue2;
278 struct AMessage *pxMessage;
280 // Create a queue capable of containing 10 uint32_t values.
281 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
283 // Create a queue capable of containing 10 pointers to AMessage structures.
284 // These should be passed by pointer as they contain a lot of data.
285 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
291 // Send an uint32_t. Wait for 10 ticks for space to become
292 // available if necessary.
293 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
295 // Failed to post the message, even after 10 ticks.
301 // Send a pointer to a struct AMessage object. Don't block if the
302 // queue is already full.
303 pxMessage = & xMessage;
304 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
307 // ... Rest of task code.
310 * \defgroup xQueueSend xQueueSend
311 * \ingroup QueueManagement
313 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
318 BaseType_t xQueueSendToBack(
319 QueueHandle_t xQueue,
320 const void *pvItemToQueue,
321 TickType_t xTicksToWait
325 * This is a macro that calls xQueueGenericSend().
327 * Post an item to the back of a queue. The item is queued by copy, not by
328 * reference. This function must not be called from an interrupt service
329 * routine. See xQueueSendFromISR () for an alternative which may be used
332 * @param xQueue The handle to the queue on which the item is to be posted.
334 * @param pvItemToQueue A pointer to the item that is to be placed on the
335 * queue. The size of the items the queue will hold was defined when the
336 * queue was created, so this many bytes will be copied from pvItemToQueue
337 * into the queue storage area.
339 * @param xTicksToWait The maximum amount of time the task should block
340 * waiting for space to become available on the queue, should it already
341 * be full. The call will return immediately if this is set to 0 and the queue
342 * is full. The time is defined in tick periods so the constant
343 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
345 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
355 uint32_t ulVar = 10UL;
357 void vATask( void *pvParameters )
359 QueueHandle_t xQueue1, xQueue2;
360 struct AMessage *pxMessage;
362 // Create a queue capable of containing 10 uint32_t values.
363 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
365 // Create a queue capable of containing 10 pointers to AMessage structures.
366 // These should be passed by pointer as they contain a lot of data.
367 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
373 // Send an uint32_t. Wait for 10 ticks for space to become
374 // available if necessary.
375 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
377 // Failed to post the message, even after 10 ticks.
383 // Send a pointer to a struct AMessage object. Don't block if the
384 // queue is already full.
385 pxMessage = & xMessage;
386 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
389 // ... Rest of task code.
392 * \defgroup xQueueSend xQueueSend
393 * \ingroup QueueManagement
395 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
400 BaseType_t xQueueSend(
401 QueueHandle_t xQueue,
402 const void * pvItemToQueue,
403 TickType_t xTicksToWait
407 * This is a macro that calls xQueueGenericSend(). It is included for
408 * backward compatibility with versions of FreeRTOS.org that did not
409 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
410 * equivalent to xQueueSendToBack().
412 * Post an item on a queue. The item is queued by copy, not by reference.
413 * This function must not be called from an interrupt service routine.
414 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
416 * @param xQueue The handle to the queue on which the item is to be posted.
418 * @param pvItemToQueue A pointer to the item that is to be placed on the
419 * queue. The size of the items the queue will hold was defined when the
420 * queue was created, so this many bytes will be copied from pvItemToQueue
421 * into the queue storage area.
423 * @param xTicksToWait The maximum amount of time the task should block
424 * waiting for space to become available on the queue, should it already
425 * be full. The call will return immediately if this is set to 0 and the
426 * queue is full. The time is defined in tick periods so the constant
427 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
429 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
439 uint32_t ulVar = 10UL;
441 void vATask( void *pvParameters )
443 QueueHandle_t xQueue1, xQueue2;
444 struct AMessage *pxMessage;
446 // Create a queue capable of containing 10 uint32_t values.
447 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
449 // Create a queue capable of containing 10 pointers to AMessage structures.
450 // These should be passed by pointer as they contain a lot of data.
451 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
457 // Send an uint32_t. Wait for 10 ticks for space to become
458 // available if necessary.
459 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
461 // Failed to post the message, even after 10 ticks.
467 // Send a pointer to a struct AMessage object. Don't block if the
468 // queue is already full.
469 pxMessage = & xMessage;
470 xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
473 // ... Rest of task code.
476 * \defgroup xQueueSend xQueueSend
477 * \ingroup QueueManagement
479 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
484 BaseType_t xQueueOverwrite(
485 QueueHandle_t xQueue,
486 const void * pvItemToQueue
490 * Only for use with queues that have a length of one - so the queue is either
493 * Post an item on a queue. If the queue is already full then overwrite the
494 * value held in the queue. The item is queued by copy, not by reference.
496 * This function must not be called from an interrupt service routine.
497 * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
499 * @param xQueue The handle of the queue to which the data is being sent.
501 * @param pvItemToQueue A pointer to the item that is to be placed on the
502 * queue. The size of the items the queue will hold was defined when the
503 * queue was created, so this many bytes will be copied from pvItemToQueue
504 * into the queue storage area.
506 * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
507 * therefore has the same return values as xQueueSendToFront(). However, pdPASS
508 * is the only value that can be returned because xQueueOverwrite() will write
509 * to the queue even when the queue is already full.
514 void vFunction( void *pvParameters )
516 QueueHandle_t xQueue;
517 uint32_t ulVarToSend, ulValReceived;
519 // Create a queue to hold one uint32_t value. It is strongly
520 // recommended *not* to use xQueueOverwrite() on queues that can
521 // contain more than one value, and doing so will trigger an assertion
522 // if configASSERT() is defined.
523 xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
525 // Write the value 10 to the queue using xQueueOverwrite().
527 xQueueOverwrite( xQueue, &ulVarToSend );
529 // Peeking the queue should now return 10, but leave the value 10 in
530 // the queue. A block time of zero is used as it is known that the
531 // queue holds a value.
533 xQueuePeek( xQueue, &ulValReceived, 0 );
535 if( ulValReceived != 10 )
537 // Error unless the item was removed by a different task.
540 // The queue is still full. Use xQueueOverwrite() to overwrite the
541 // value held in the queue with 100.
543 xQueueOverwrite( xQueue, &ulVarToSend );
545 // This time read from the queue, leaving the queue empty once more.
546 // A block time of 0 is used again.
547 xQueueReceive( xQueue, &ulValReceived, 0 );
549 // The value read should be the last value written, even though the
550 // queue was already full when the value was written.
551 if( ulValReceived != 100 )
559 * \defgroup xQueueOverwrite xQueueOverwrite
560 * \ingroup QueueManagement
562 #define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
568 BaseType_t xQueueGenericSend(
569 QueueHandle_t xQueue,
570 const void * pvItemToQueue,
571 TickType_t xTicksToWait
572 BaseType_t xCopyPosition
576 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
577 * xQueueSendToBack() are used in place of calling this function directly.
579 * Post an item on a queue. The item is queued by copy, not by reference.
580 * This function must not be called from an interrupt service routine.
581 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
583 * @param xQueue The handle to the queue on which the item is to be posted.
585 * @param pvItemToQueue A pointer to the item that is to be placed on the
586 * queue. The size of the items the queue will hold was defined when the
587 * queue was created, so this many bytes will be copied from pvItemToQueue
588 * into the queue storage area.
590 * @param xTicksToWait The maximum amount of time the task should block
591 * waiting for space to become available on the queue, should it already
592 * be full. The call will return immediately if this is set to 0 and the
593 * queue is full. The time is defined in tick periods so the constant
594 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
596 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
597 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
598 * at the front of the queue (for high priority messages).
600 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
610 uint32_t ulVar = 10UL;
612 void vATask( void *pvParameters )
614 QueueHandle_t xQueue1, xQueue2;
615 struct AMessage *pxMessage;
617 // Create a queue capable of containing 10 uint32_t values.
618 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
620 // Create a queue capable of containing 10 pointers to AMessage structures.
621 // These should be passed by pointer as they contain a lot of data.
622 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
628 // Send an uint32_t. Wait for 10 ticks for space to become
629 // available if necessary.
630 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
632 // Failed to post the message, even after 10 ticks.
638 // Send a pointer to a struct AMessage object. Don't block if the
639 // queue is already full.
640 pxMessage = & xMessage;
641 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
644 // ... Rest of task code.
647 * \defgroup xQueueSend xQueueSend
648 * \ingroup QueueManagement
650 BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
655 BaseType_t xQueuePeek(
656 QueueHandle_t xQueue,
657 void * const pvBuffer,
658 TickType_t xTicksToWait
661 * Receive an item from a queue without removing the item from the queue.
662 * The item is received by copy so a buffer of adequate size must be
663 * provided. The number of bytes copied into the buffer was defined when
664 * the queue was created.
666 * Successfully received items remain on the queue so will be returned again
667 * by the next call, or a call to xQueueReceive().
669 * This macro must not be used in an interrupt service routine. See
670 * xQueuePeekFromISR() for an alternative that can be called from an interrupt
673 * @param xQueue The handle to the queue from which the item is to be
676 * @param pvBuffer Pointer to the buffer into which the received item will
679 * @param xTicksToWait The maximum amount of time the task should block
680 * waiting for an item to receive should the queue be empty at the time
681 * of the call. The time is defined in tick periods so the constant
682 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
683 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
686 * @return pdTRUE if an item was successfully received from the queue,
697 QueueHandle_t xQueue;
699 // Task to create a queue and post a value.
700 void vATask( void *pvParameters )
702 struct AMessage *pxMessage;
704 // Create a queue capable of containing 10 pointers to AMessage structures.
705 // These should be passed by pointer as they contain a lot of data.
706 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
709 // Failed to create the queue.
714 // Send a pointer to a struct AMessage object. Don't block if the
715 // queue is already full.
716 pxMessage = & xMessage;
717 xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
719 // ... Rest of task code.
722 // Task to peek the data from the queue.
723 void vADifferentTask( void *pvParameters )
725 struct AMessage *pxRxedMessage;
729 // Peek a message on the created queue. Block for 10 ticks if a
730 // message is not immediately available.
731 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
733 // pcRxedMessage now points to the struct AMessage variable posted
734 // by vATask, but the item still remains on the queue.
738 // ... Rest of task code.
741 * \defgroup xQueuePeek xQueuePeek
742 * \ingroup QueueManagement
744 BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
749 BaseType_t xQueuePeekFromISR(
750 QueueHandle_t xQueue,
754 * A version of xQueuePeek() that can be called from an interrupt service
757 * Receive an item from a queue without removing the item from the queue.
758 * The item is received by copy so a buffer of adequate size must be
759 * provided. The number of bytes copied into the buffer was defined when
760 * the queue was created.
762 * Successfully received items remain on the queue so will be returned again
763 * by the next call, or a call to xQueueReceive().
765 * @param xQueue The handle to the queue from which the item is to be
768 * @param pvBuffer Pointer to the buffer into which the received item will
771 * @return pdTRUE if an item was successfully received from the queue,
774 * \defgroup xQueuePeekFromISR xQueuePeekFromISR
775 * \ingroup QueueManagement
777 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;
782 BaseType_t xQueueReceive(
783 QueueHandle_t xQueue,
785 TickType_t xTicksToWait
788 * Receive an item from a queue. The item is received by copy so a buffer of
789 * adequate size must be provided. The number of bytes copied into the buffer
790 * was defined when the queue was created.
792 * Successfully received items are removed from the queue.
794 * This function must not be used in an interrupt service routine. See
795 * xQueueReceiveFromISR for an alternative that can.
797 * @param xQueue The handle to the queue from which the item is to be
800 * @param pvBuffer Pointer to the buffer into which the received item will
803 * @param xTicksToWait The maximum amount of time the task should block
804 * waiting for an item to receive should the queue be empty at the time
805 * of the call. xQueueReceive() will return immediately if xTicksToWait
806 * is zero and the queue is empty. The time is defined in tick periods so the
807 * constant portTICK_PERIOD_MS should be used to convert to real time if this is
810 * @return pdTRUE if an item was successfully received from the queue,
821 QueueHandle_t xQueue;
823 // Task to create a queue and post a value.
824 void vATask( void *pvParameters )
826 struct AMessage *pxMessage;
828 // Create a queue capable of containing 10 pointers to AMessage structures.
829 // These should be passed by pointer as they contain a lot of data.
830 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
833 // Failed to create the queue.
838 // Send a pointer to a struct AMessage object. Don't block if the
839 // queue is already full.
840 pxMessage = & xMessage;
841 xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
843 // ... Rest of task code.
846 // Task to receive from the queue.
847 void vADifferentTask( void *pvParameters )
849 struct AMessage *pxRxedMessage;
853 // Receive a message on the created queue. Block for 10 ticks if a
854 // message is not immediately available.
855 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
857 // pcRxedMessage now points to the struct AMessage variable posted
862 // ... Rest of task code.
865 * \defgroup xQueueReceive xQueueReceive
866 * \ingroup QueueManagement
868 BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
872 * <pre>UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );</pre>
874 * Return the number of messages stored in a queue.
876 * @param xQueue A handle to the queue being queried.
878 * @return The number of messages available in the queue.
880 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
881 * \ingroup QueueManagement
883 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
887 * <pre>UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );</pre>
889 * Return the number of free spaces available in a queue. This is equal to the
890 * number of items that can be sent to the queue before the queue becomes full
891 * if no items are removed.
893 * @param xQueue A handle to the queue being queried.
895 * @return The number of spaces available in the queue.
897 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
898 * \ingroup QueueManagement
900 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
904 * <pre>void vQueueDelete( QueueHandle_t xQueue );</pre>
906 * Delete a queue - freeing all the memory allocated for storing of items
907 * placed on the queue.
909 * @param xQueue A handle to the queue to be deleted.
911 * \defgroup vQueueDelete vQueueDelete
912 * \ingroup QueueManagement
914 void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
919 BaseType_t xQueueSendToFrontFromISR(
920 QueueHandle_t xQueue,
921 const void *pvItemToQueue,
922 BaseType_t *pxHigherPriorityTaskWoken
926 * This is a macro that calls xQueueGenericSendFromISR().
928 * Post an item to the front of a queue. It is safe to use this macro from
929 * within an interrupt service routine.
931 * Items are queued by copy not reference so it is preferable to only
932 * queue small items, especially when called from an ISR. In most cases
933 * it would be preferable to store a pointer to the item being queued.
935 * @param xQueue The handle to the queue on which the item is to be posted.
937 * @param pvItemToQueue A pointer to the item that is to be placed on the
938 * queue. The size of the items the queue will hold was defined when the
939 * queue was created, so this many bytes will be copied from pvItemToQueue
940 * into the queue storage area.
942 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
943 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
944 * to unblock, and the unblocked task has a priority higher than the currently
945 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
946 * a context switch should be requested before the interrupt is exited.
948 * @return pdTRUE if the data was successfully sent to the queue, otherwise
951 * Example usage for buffered IO (where the ISR can obtain more than one value
954 void vBufferISR( void )
957 BaseType_t xHigherPrioritTaskWoken;
959 // We have not woken a task at the start of the ISR.
960 xHigherPriorityTaskWoken = pdFALSE;
962 // Loop until the buffer is empty.
965 // Obtain a byte from the buffer.
966 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
969 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
971 } while( portINPUT_BYTE( BUFFER_COUNT ) );
973 // Now the buffer is empty we can switch context if necessary.
974 if( xHigherPriorityTaskWoken )
981 * \defgroup xQueueSendFromISR xQueueSendFromISR
982 * \ingroup QueueManagement
984 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
990 BaseType_t xQueueSendToBackFromISR(
991 QueueHandle_t xQueue,
992 const void *pvItemToQueue,
993 BaseType_t *pxHigherPriorityTaskWoken
997 * This is a macro that calls xQueueGenericSendFromISR().
999 * Post an item to the back of a queue. It is safe to use this macro from
1000 * within an interrupt service routine.
1002 * Items are queued by copy not reference so it is preferable to only
1003 * queue small items, especially when called from an ISR. In most cases
1004 * it would be preferable to store a pointer to the item being queued.
1006 * @param xQueue The handle to the queue on which the item is to be posted.
1008 * @param pvItemToQueue A pointer to the item that is to be placed on the
1009 * queue. The size of the items the queue will hold was defined when the
1010 * queue was created, so this many bytes will be copied from pvItemToQueue
1011 * into the queue storage area.
1013 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
1014 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1015 * to unblock, and the unblocked task has a priority higher than the currently
1016 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
1017 * a context switch should be requested before the interrupt is exited.
1019 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1022 * Example usage for buffered IO (where the ISR can obtain more than one value
1025 void vBufferISR( void )
1028 BaseType_t xHigherPriorityTaskWoken;
1030 // We have not woken a task at the start of the ISR.
1031 xHigherPriorityTaskWoken = pdFALSE;
1033 // Loop until the buffer is empty.
1036 // Obtain a byte from the buffer.
1037 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1040 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1042 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1044 // Now the buffer is empty we can switch context if necessary.
1045 if( xHigherPriorityTaskWoken )
1052 * \defgroup xQueueSendFromISR xQueueSendFromISR
1053 * \ingroup QueueManagement
1055 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1060 BaseType_t xQueueOverwriteFromISR(
1061 QueueHandle_t xQueue,
1062 const void * pvItemToQueue,
1063 BaseType_t *pxHigherPriorityTaskWoken
1067 * A version of xQueueOverwrite() that can be used in an interrupt service
1070 * Only for use with queues that can hold a single item - so the queue is either
1073 * Post an item on a queue. If the queue is already full then overwrite the
1074 * value held in the queue. The item is queued by copy, not by reference.
1076 * @param xQueue The handle to the queue on which the item is to be posted.
1078 * @param pvItemToQueue A pointer to the item that is to be placed on the
1079 * queue. The size of the items the queue will hold was defined when the
1080 * queue was created, so this many bytes will be copied from pvItemToQueue
1081 * into the queue storage area.
1083 * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
1084 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1085 * to unblock, and the unblocked task has a priority higher than the currently
1086 * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
1087 * a context switch should be requested before the interrupt is exited.
1089 * @return xQueueOverwriteFromISR() is a macro that calls
1090 * xQueueGenericSendFromISR(), and therefore has the same return values as
1091 * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
1092 * returned because xQueueOverwriteFromISR() will write to the queue even when
1093 * the queue is already full.
1098 QueueHandle_t xQueue;
1100 void vFunction( void *pvParameters )
1102 // Create a queue to hold one uint32_t value. It is strongly
1103 // recommended *not* to use xQueueOverwriteFromISR() on queues that can
1104 // contain more than one value, and doing so will trigger an assertion
1105 // if configASSERT() is defined.
1106 xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
1109 void vAnInterruptHandler( void )
1111 // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
1112 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
1113 uint32_t ulVarToSend, ulValReceived;
1115 // Write the value 10 to the queue using xQueueOverwriteFromISR().
1117 xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1119 // The queue is full, but calling xQueueOverwriteFromISR() again will still
1120 // pass because the value held in the queue will be overwritten with the
1123 xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1125 // Reading from the queue will now return 100.
1129 if( xHigherPrioritytaskWoken == pdTRUE )
1131 // Writing to the queue caused a task to unblock and the unblocked task
1132 // has a priority higher than or equal to the priority of the currently
1133 // executing task (the task this interrupt interrupted). Perform a context
1134 // switch so this interrupt returns directly to the unblocked task.
1135 portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
1139 * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
1140 * \ingroup QueueManagement
1142 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1147 BaseType_t xQueueSendFromISR(
1148 QueueHandle_t xQueue,
1149 const void *pvItemToQueue,
1150 BaseType_t *pxHigherPriorityTaskWoken
1154 * This is a macro that calls xQueueGenericSendFromISR(). It is included
1155 * for backward compatibility with versions of FreeRTOS.org that did not
1156 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
1159 * Post an item to the back of a queue. It is safe to use this function from
1160 * within an interrupt service routine.
1162 * Items are queued by copy not reference so it is preferable to only
1163 * queue small items, especially when called from an ISR. In most cases
1164 * it would be preferable to store a pointer to the item being queued.
1166 * @param xQueue The handle to the queue on which the item is to be posted.
1168 * @param pvItemToQueue A pointer to the item that is to be placed on the
1169 * queue. The size of the items the queue will hold was defined when the
1170 * queue was created, so this many bytes will be copied from pvItemToQueue
1171 * into the queue storage area.
1173 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
1174 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1175 * to unblock, and the unblocked task has a priority higher than the currently
1176 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
1177 * a context switch should be requested before the interrupt is exited.
1179 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1182 * Example usage for buffered IO (where the ISR can obtain more than one value
1185 void vBufferISR( void )
1188 BaseType_t xHigherPriorityTaskWoken;
1190 // We have not woken a task at the start of the ISR.
1191 xHigherPriorityTaskWoken = pdFALSE;
1193 // Loop until the buffer is empty.
1196 // Obtain a byte from the buffer.
1197 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1200 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1202 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1204 // Now the buffer is empty we can switch context if necessary.
1205 if( xHigherPriorityTaskWoken )
1207 // Actual macro used here is port specific.
1208 portYIELD_FROM_ISR ();
1213 * \defgroup xQueueSendFromISR xQueueSendFromISR
1214 * \ingroup QueueManagement
1216 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1221 BaseType_t xQueueGenericSendFromISR(
1222 QueueHandle_t xQueue,
1223 const void *pvItemToQueue,
1224 BaseType_t *pxHigherPriorityTaskWoken,
1225 BaseType_t xCopyPosition
1229 * It is preferred that the macros xQueueSendFromISR(),
1230 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1231 * of calling this function directly. xQueueGiveFromISR() is an
1232 * equivalent for use by semaphores that don't actually copy any data.
1234 * Post an item on a queue. It is safe to use this function from within an
1235 * interrupt service routine.
1237 * Items are queued by copy not reference so it is preferable to only
1238 * queue small items, especially when called from an ISR. In most cases
1239 * it would be preferable to store a pointer to the item being queued.
1241 * @param xQueue The handle to the queue on which the item is to be posted.
1243 * @param pvItemToQueue A pointer to the item that is to be placed on the
1244 * queue. The size of the items the queue will hold was defined when the
1245 * queue was created, so this many bytes will be copied from pvItemToQueue
1246 * into the queue storage area.
1248 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1249 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1250 * to unblock, and the unblocked task has a priority higher than the currently
1251 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
1252 * a context switch should be requested before the interrupt is exited.
1254 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1255 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1256 * at the front of the queue (for high priority messages).
1258 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1261 * Example usage for buffered IO (where the ISR can obtain more than one value
1264 void vBufferISR( void )
1267 BaseType_t xHigherPriorityTaskWokenByPost;
1269 // We have not woken a task at the start of the ISR.
1270 xHigherPriorityTaskWokenByPost = pdFALSE;
1272 // Loop until the buffer is empty.
1275 // Obtain a byte from the buffer.
1276 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1279 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1281 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1283 // Now the buffer is empty we can switch context if necessary. Note that the
1284 // name of the yield function required is port specific.
1285 if( xHigherPriorityTaskWokenByPost )
1287 taskYIELD_YIELD_FROM_ISR();
1292 * \defgroup xQueueSendFromISR xQueueSendFromISR
1293 * \ingroup QueueManagement
1295 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1296 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1301 BaseType_t xQueueReceiveFromISR(
1302 QueueHandle_t xQueue,
1304 BaseType_t *pxTaskWoken
1308 * Receive an item from a queue. It is safe to use this function from within an
1309 * interrupt service routine.
1311 * @param xQueue The handle to the queue from which the item is to be
1314 * @param pvBuffer Pointer to the buffer into which the received item will
1317 * @param pxTaskWoken A task may be blocked waiting for space to become
1318 * available on the queue. If xQueueReceiveFromISR causes such a task to
1319 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
1322 * @return pdTRUE if an item was successfully received from the queue,
1323 * otherwise pdFALSE.
1328 QueueHandle_t xQueue;
1330 // Function to create a queue and post some values.
1331 void vAFunction( void *pvParameters )
1334 const TickType_t xTicksToWait = ( TickType_t )0xff;
1336 // Create a queue capable of containing 10 characters.
1337 xQueue = xQueueCreate( 10, sizeof( char ) );
1340 // Failed to create the queue.
1345 // Post some characters that will be used within an ISR. If the queue
1346 // is full then this task will block for xTicksToWait ticks.
1348 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1350 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1352 // ... keep posting characters ... this task may block when the queue
1356 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1359 // ISR that outputs all the characters received on the queue.
1360 void vISR_Routine( void )
1362 BaseType_t xTaskWokenByReceive = pdFALSE;
1365 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1367 // A character was received. Output the character now.
1368 vOutputCharacter( cRxedChar );
1370 // If removing the character from the queue woke the task that was
1371 // posting onto the queue cTaskWokenByReceive will have been set to
1372 // pdTRUE. No matter how many times this loop iterates only one
1373 // task will be woken.
1376 if( cTaskWokenByPost != ( char ) pdFALSE;
1382 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
1383 * \ingroup QueueManagement
1385 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1388 * Utilities to query queues that are safe to use from an ISR. These utilities
1389 * should be used only from witin an ISR, or within a critical section.
1391 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1392 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1393 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1396 * The functions defined above are for passing data to and from tasks. The
1397 * functions below are the equivalents for passing data to and from
1400 * These functions are called from the co-routine macro implementation and
1401 * should not be called directly from application code. Instead use the macro
1402 * wrappers defined within croutine.h.
1404 BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken );
1405 BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxTaskWoken );
1406 BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait );
1407 BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait );
1410 * For internal use only. Use xSemaphoreCreateMutex(),
1411 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1412 * these functions directly.
1414 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1415 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
1416 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1417 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
1418 BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1419 TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1420 TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1423 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1424 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1426 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1427 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
1430 * Reset a queue back to its original empty state. The return value is now
1431 * obsolete and is always set to pdPASS.
1433 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
1436 * The registry is provided as a means for kernel aware debuggers to
1437 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1438 * a queue, semaphore or mutex handle to the registry if you want the handle
1439 * to be available to a kernel aware debugger. If you are not using a kernel
1440 * aware debugger then this function can be ignored.
1442 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1443 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1444 * within FreeRTOSConfig.h for the registry to be available. Its value
1445 * does not effect the number of queues, semaphores and mutexes that can be
1446 * created - just the number that the registry can hold.
1448 * @param xQueue The handle of the queue being added to the registry. This
1449 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1450 * handles can also be passed in here.
1452 * @param pcName The name to be associated with the handle. This is the
1453 * name that the kernel aware debugger will display. The queue registry only
1454 * stores a pointer to the string - so the string must be persistent (global or
1455 * preferably in ROM/Flash), not on the stack.
1457 #if( configQUEUE_REGISTRY_SIZE > 0 )
1458 void vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcQueueName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1462 * The registry is provided as a means for kernel aware debuggers to
1463 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1464 * a queue, semaphore or mutex handle to the registry if you want the handle
1465 * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1466 * remove the queue, semaphore or mutex from the register. If you are not using
1467 * a kernel aware debugger then this function can be ignored.
1469 * @param xQueue The handle of the queue being removed from the registry.
1471 #if( configQUEUE_REGISTRY_SIZE > 0 )
1472 void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1476 * The queue registry is provided as a means for kernel aware debuggers to
1477 * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
1478 * up and return the name of a queue in the queue registry from the queue's
1481 * @param xQueue The handle of the queue the name of which will be returned.
1482 * @return If the queue is in the registry then a pointer to the name of the
1483 * queue is returned. If the queue is not in the registry then NULL is
1486 #if( configQUEUE_REGISTRY_SIZE > 0 )
1487 const char *pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1491 * Generic version of the function used to creaet a queue using dynamic memory
1492 * allocation. This is called by other functions and macros that create other
1493 * RTOS objects that use the queue structure as their base.
1495 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1496 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1500 * Generic version of the function used to creaet a queue using dynamic memory
1501 * allocation. This is called by other functions and macros that create other
1502 * RTOS objects that use the queue structure as their base.
1504 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
1505 QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1509 * Queue sets provide a mechanism to allow a task to block (pend) on a read
1510 * operation from multiple queues or semaphores simultaneously.
1512 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1515 * A queue set must be explicitly created using a call to xQueueCreateSet()
1516 * before it can be used. Once created, standard FreeRTOS queues and semaphores
1517 * can be added to the set using calls to xQueueAddToSet().
1518 * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1519 * or semaphores contained in the set is in a state where a queue read or
1520 * semaphore take operation would be successful.
1522 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1523 * for reasons why queue sets are very rarely needed in practice as there are
1524 * simpler methods of blocking on multiple objects.
1526 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1527 * mutex holder to inherit the priority of the blocked task.
1529 * Note 3: An additional 4 bytes of RAM is required for each space in a every
1530 * queue added to a queue set. Therefore counting semaphores that have a high
1531 * maximum count value should not be added to a queue set.
1533 * Note 4: A receive (in the case of a queue) or take (in the case of a
1534 * semaphore) operation must not be performed on a member of a queue set unless
1535 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1537 * @param uxEventQueueLength Queue sets store events that occur on
1538 * the queues and semaphores contained in the set. uxEventQueueLength specifies
1539 * the maximum number of events that can be queued at once. To be absolutely
1540 * certain that events are not lost uxEventQueueLength should be set to the
1541 * total sum of the length of the queues added to the set, where binary
1542 * semaphores and mutexes have a length of 1, and counting semaphores have a
1543 * length set by their maximum count value. Examples:
1544 * + If a queue set is to hold a queue of length 5, another queue of length 12,
1545 * and a binary semaphore, then uxEventQueueLength should be set to
1546 * (5 + 12 + 1), or 18.
1547 * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1548 * should be set to (1 + 1 + 1 ), or 3.
1549 * + If a queue set is to hold a counting semaphore that has a maximum count of
1550 * 5, and a counting semaphore that has a maximum count of 3, then
1551 * uxEventQueueLength should be set to (5 + 3), or 8.
1553 * @return If the queue set is created successfully then a handle to the created
1554 * queue set is returned. Otherwise NULL is returned.
1556 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1559 * Adds a queue or semaphore to a queue set that was previously created by a
1560 * call to xQueueCreateSet().
1562 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1565 * Note 1: A receive (in the case of a queue) or take (in the case of a
1566 * semaphore) operation must not be performed on a member of a queue set unless
1567 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1569 * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1570 * the queue set (cast to an QueueSetMemberHandle_t type).
1572 * @param xQueueSet The handle of the queue set to which the queue or semaphore
1575 * @return If the queue or semaphore was successfully added to the queue set
1576 * then pdPASS is returned. If the queue could not be successfully added to the
1577 * queue set because it is already a member of a different queue set then pdFAIL
1580 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1583 * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1584 * be removed from a set if the queue or semaphore is empty.
1586 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1589 * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1590 * from the queue set (cast to an QueueSetMemberHandle_t type).
1592 * @param xQueueSet The handle of the queue set in which the queue or semaphore
1595 * @return If the queue or semaphore was successfully removed from the queue set
1596 * then pdPASS is returned. If the queue was not in the queue set, or the
1597 * queue (or semaphore) was not empty, then pdFAIL is returned.
1599 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1602 * xQueueSelectFromSet() selects from the members of a queue set a queue or
1603 * semaphore that either contains data (in the case of a queue) or is available
1604 * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1605 * allows a task to block (pend) on a read operation on all the queues and
1606 * semaphores in a queue set simultaneously.
1608 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1611 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1612 * for reasons why queue sets are very rarely needed in practice as there are
1613 * simpler methods of blocking on multiple objects.
1615 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1616 * mutex holder to inherit the priority of the blocked task.
1618 * Note 3: A receive (in the case of a queue) or take (in the case of a
1619 * semaphore) operation must not be performed on a member of a queue set unless
1620 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1622 * @param xQueueSet The queue set on which the task will (potentially) block.
1624 * @param xTicksToWait The maximum time, in ticks, that the calling task will
1625 * remain in the Blocked state (with other tasks executing) to wait for a member
1626 * of the queue set to be ready for a successful queue read or semaphore take
1629 * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1630 * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1631 * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1632 * in the queue set that is available, or NULL if no such queue or semaphore
1633 * exists before before the specified block time expires.
1635 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1638 * A version of xQueueSelectFromSet() that can be used from an ISR.
1640 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1642 /* Not public API functions. */
1643 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1644 BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1645 void vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1646 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1647 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1654 #endif /* QUEUE_H */