2 * FreeRTOS Kernel V10.0.1
3 * Copyright (C) 2017 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"
42 * Type by which queues are referenced. For example, a call to xQueueCreate()
43 * returns an QueueHandle_t variable that can then be used as a parameter to
44 * xQueueSend(), xQueueReceive(), etc.
46 typedef void * QueueHandle_t;
49 * Type by which queue sets are referenced. For example, a call to
50 * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
51 * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
53 typedef void * QueueSetHandle_t;
56 * Queue sets can contain both queues and semaphores, so the
57 * QueueSetMemberHandle_t is defined as a type to be used where a parameter or
58 * return value can be either an QueueHandle_t or an SemaphoreHandle_t.
60 typedef void * QueueSetMemberHandle_t;
62 /* For internal use only. */
63 #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
64 #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
65 #define queueOVERWRITE ( ( BaseType_t ) 2 )
67 /* For internal use only. These definitions *must* match those in queue.c. */
68 #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
69 #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
70 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
71 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
72 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
73 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
78 QueueHandle_t xQueueCreate(
79 UBaseType_t uxQueueLength,
80 UBaseType_t uxItemSize
84 * Creates a new queue instance, and returns a handle by which the new queue
87 * Internally, within the FreeRTOS implementation, queues use two blocks of
88 * memory. The first block is used to hold the queue's data structures. The
89 * second block is used to hold items placed into the queue. If a queue is
90 * created using xQueueCreate() then both blocks of memory are automatically
91 * dynamically allocated inside the xQueueCreate() function. (see
92 * http://www.freertos.org/a00111.html). If a queue is created using
93 * xQueueCreateStatic() then the application writer must provide the memory that
94 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
95 * be created without using any dynamic memory allocation.
97 * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html
99 * @param uxQueueLength The maximum number of items that the queue can contain.
101 * @param uxItemSize The number of bytes each item in the queue will require.
102 * Items are queued by copy, not by reference, so this is the number of bytes
103 * that will be copied for each posted item. Each item on the queue must be
106 * @return If the queue is successfully create then a handle to the newly
107 * created queue is returned. If the queue cannot be created then 0 is
118 void vATask( void *pvParameters )
120 QueueHandle_t xQueue1, xQueue2;
122 // Create a queue capable of containing 10 uint32_t values.
123 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
126 // Queue was not created and must not be used.
129 // Create a queue capable of containing 10 pointers to AMessage structures.
130 // These should be passed by pointer as they contain a lot of data.
131 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
134 // Queue was not created and must not be used.
137 // ... Rest of task code.
140 * \defgroup xQueueCreate xQueueCreate
141 * \ingroup QueueManagement
143 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
144 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
150 QueueHandle_t xQueueCreateStatic(
151 UBaseType_t uxQueueLength,
152 UBaseType_t uxItemSize,
153 uint8_t *pucQueueStorageBuffer,
154 StaticQueue_t *pxQueueBuffer
158 * Creates a new queue instance, and returns a handle by which the new queue
161 * Internally, within the FreeRTOS implementation, queues use two blocks of
162 * memory. The first block is used to hold the queue's data structures. The
163 * second block is used to hold items placed into the queue. If a queue is
164 * created using xQueueCreate() then both blocks of memory are automatically
165 * dynamically allocated inside the xQueueCreate() function. (see
166 * http://www.freertos.org/a00111.html). If a queue is created using
167 * xQueueCreateStatic() then the application writer must provide the memory that
168 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
169 * be created without using any dynamic memory allocation.
171 * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html
173 * @param uxQueueLength The maximum number of items that the queue can contain.
175 * @param uxItemSize The number of bytes each item in the queue will require.
176 * Items are queued by copy, not by reference, so this is the number of bytes
177 * that will be copied for each posted item. Each item on the queue must be
180 * @param pucQueueStorageBuffer If uxItemSize is not zero then
181 * pucQueueStorageBuffer must point to a uint8_t array that is at least large
182 * enough to hold the maximum number of items that can be in the queue at any
183 * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
184 * zero then pucQueueStorageBuffer can be NULL.
186 * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
187 * will be used to hold the queue's data structure.
189 * @return If the queue is created then a handle to the created queue is
190 * returned. If pxQueueBuffer is NULL then NULL is returned.
200 #define QUEUE_LENGTH 10
201 #define ITEM_SIZE sizeof( uint32_t )
203 // xQueueBuffer will hold the queue structure.
204 StaticQueue_t xQueueBuffer;
206 // ucQueueStorage will hold the items posted to the queue. Must be at least
207 // [(queue length) * ( queue item size)] bytes long.
208 uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
210 void vATask( void *pvParameters )
212 QueueHandle_t xQueue1;
214 // Create a queue capable of containing 10 uint32_t values.
215 xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
216 ITEM_SIZE // The size of each item in the queue
217 &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
218 &xQueueBuffer ); // The buffer that will hold the queue structure.
220 // The queue is guaranteed to be created successfully as no dynamic memory
221 // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
223 // ... Rest of task code.
226 * \defgroup xQueueCreateStatic xQueueCreateStatic
227 * \ingroup QueueManagement
229 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
230 #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
231 #endif /* configSUPPORT_STATIC_ALLOCATION */
236 BaseType_t xQueueSendToFront(
237 QueueHandle_t xQueue,
238 const void *pvItemToQueue,
239 TickType_t xTicksToWait
243 * Post an item to the front of a queue. The item is queued by copy, not by
244 * reference. This function must not be called from an interrupt service
245 * routine. See xQueueSendFromISR () for an alternative which may be used
248 * @param xQueue The handle to the queue on which the item is to be posted.
250 * @param pvItemToQueue A pointer to the item that is to be placed on the
251 * queue. The size of the items the queue will hold was defined when the
252 * queue was created, so this many bytes will be copied from pvItemToQueue
253 * into the queue storage area.
255 * @param xTicksToWait The maximum amount of time the task should block
256 * waiting for space to become available on the queue, should it already
257 * be full. The call will return immediately if this is set to 0 and the
258 * queue is full. The time is defined in tick periods so the constant
259 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
261 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
271 uint32_t ulVar = 10UL;
273 void vATask( void *pvParameters )
275 QueueHandle_t xQueue1, xQueue2;
276 struct AMessage *pxMessage;
278 // Create a queue capable of containing 10 uint32_t values.
279 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
281 // Create a queue capable of containing 10 pointers to AMessage structures.
282 // These should be passed by pointer as they contain a lot of data.
283 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
289 // Send an uint32_t. Wait for 10 ticks for space to become
290 // available if necessary.
291 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
293 // Failed to post the message, even after 10 ticks.
299 // Send a pointer to a struct AMessage object. Don't block if the
300 // queue is already full.
301 pxMessage = & xMessage;
302 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
305 // ... Rest of task code.
308 * \defgroup xQueueSend xQueueSend
309 * \ingroup QueueManagement
311 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
316 BaseType_t xQueueSendToBack(
317 QueueHandle_t xQueue,
318 const void *pvItemToQueue,
319 TickType_t xTicksToWait
323 * This is a macro that calls xQueueGenericSend().
325 * Post an item to the back of a queue. The item is queued by copy, not by
326 * reference. This function must not be called from an interrupt service
327 * routine. See xQueueSendFromISR () for an alternative which may be used
330 * @param xQueue The handle to the queue on which the item is to be posted.
332 * @param pvItemToQueue A pointer to the item that is to be placed on the
333 * queue. The size of the items the queue will hold was defined when the
334 * queue was created, so this many bytes will be copied from pvItemToQueue
335 * into the queue storage area.
337 * @param xTicksToWait The maximum amount of time the task should block
338 * waiting for space to become available on the queue, should it already
339 * be full. The call will return immediately if this is set to 0 and the queue
340 * is full. The time is defined in tick periods so the constant
341 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
343 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
353 uint32_t ulVar = 10UL;
355 void vATask( void *pvParameters )
357 QueueHandle_t xQueue1, xQueue2;
358 struct AMessage *pxMessage;
360 // Create a queue capable of containing 10 uint32_t values.
361 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
363 // Create a queue capable of containing 10 pointers to AMessage structures.
364 // These should be passed by pointer as they contain a lot of data.
365 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
371 // Send an uint32_t. Wait for 10 ticks for space to become
372 // available if necessary.
373 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
375 // Failed to post the message, even after 10 ticks.
381 // Send a pointer to a struct AMessage object. Don't block if the
382 // queue is already full.
383 pxMessage = & xMessage;
384 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
387 // ... Rest of task code.
390 * \defgroup xQueueSend xQueueSend
391 * \ingroup QueueManagement
393 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
398 BaseType_t xQueueSend(
399 QueueHandle_t xQueue,
400 const void * pvItemToQueue,
401 TickType_t xTicksToWait
405 * This is a macro that calls xQueueGenericSend(). It is included for
406 * backward compatibility with versions of FreeRTOS.org that did not
407 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
408 * equivalent to xQueueSendToBack().
410 * Post an item on a queue. The item is queued by copy, not by reference.
411 * This function must not be called from an interrupt service routine.
412 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
414 * @param xQueue The handle to the queue on which the item is to be posted.
416 * @param pvItemToQueue A pointer to the item that is to be placed on the
417 * queue. The size of the items the queue will hold was defined when the
418 * queue was created, so this many bytes will be copied from pvItemToQueue
419 * into the queue storage area.
421 * @param xTicksToWait The maximum amount of time the task should block
422 * waiting for space to become available on the queue, should it already
423 * be full. The call will return immediately if this is set to 0 and the
424 * queue is full. The time is defined in tick periods so the constant
425 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
427 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
437 uint32_t ulVar = 10UL;
439 void vATask( void *pvParameters )
441 QueueHandle_t xQueue1, xQueue2;
442 struct AMessage *pxMessage;
444 // Create a queue capable of containing 10 uint32_t values.
445 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
447 // Create a queue capable of containing 10 pointers to AMessage structures.
448 // These should be passed by pointer as they contain a lot of data.
449 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
455 // Send an uint32_t. Wait for 10 ticks for space to become
456 // available if necessary.
457 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
459 // Failed to post the message, even after 10 ticks.
465 // Send a pointer to a struct AMessage object. Don't block if the
466 // queue is already full.
467 pxMessage = & xMessage;
468 xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
471 // ... Rest of task code.
474 * \defgroup xQueueSend xQueueSend
475 * \ingroup QueueManagement
477 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
482 BaseType_t xQueueOverwrite(
483 QueueHandle_t xQueue,
484 const void * pvItemToQueue
488 * Only for use with queues that have a length of one - so the queue is either
491 * Post an item on a queue. If the queue is already full then overwrite the
492 * value held in the queue. The item is queued by copy, not by reference.
494 * This function must not be called from an interrupt service routine.
495 * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
497 * @param xQueue The handle of the queue to which the data is being sent.
499 * @param pvItemToQueue A pointer to the item that is to be placed on the
500 * queue. The size of the items the queue will hold was defined when the
501 * queue was created, so this many bytes will be copied from pvItemToQueue
502 * into the queue storage area.
504 * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
505 * therefore has the same return values as xQueueSendToFront(). However, pdPASS
506 * is the only value that can be returned because xQueueOverwrite() will write
507 * to the queue even when the queue is already full.
512 void vFunction( void *pvParameters )
514 QueueHandle_t xQueue;
515 uint32_t ulVarToSend, ulValReceived;
517 // Create a queue to hold one uint32_t value. It is strongly
518 // recommended *not* to use xQueueOverwrite() on queues that can
519 // contain more than one value, and doing so will trigger an assertion
520 // if configASSERT() is defined.
521 xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
523 // Write the value 10 to the queue using xQueueOverwrite().
525 xQueueOverwrite( xQueue, &ulVarToSend );
527 // Peeking the queue should now return 10, but leave the value 10 in
528 // the queue. A block time of zero is used as it is known that the
529 // queue holds a value.
531 xQueuePeek( xQueue, &ulValReceived, 0 );
533 if( ulValReceived != 10 )
535 // Error unless the item was removed by a different task.
538 // The queue is still full. Use xQueueOverwrite() to overwrite the
539 // value held in the queue with 100.
541 xQueueOverwrite( xQueue, &ulVarToSend );
543 // This time read from the queue, leaving the queue empty once more.
544 // A block time of 0 is used again.
545 xQueueReceive( xQueue, &ulValReceived, 0 );
547 // The value read should be the last value written, even though the
548 // queue was already full when the value was written.
549 if( ulValReceived != 100 )
557 * \defgroup xQueueOverwrite xQueueOverwrite
558 * \ingroup QueueManagement
560 #define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
566 BaseType_t xQueueGenericSend(
567 QueueHandle_t xQueue,
568 const void * pvItemToQueue,
569 TickType_t xTicksToWait
570 BaseType_t xCopyPosition
574 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
575 * xQueueSendToBack() are used in place of calling this function directly.
577 * Post an item on a queue. The item is queued by copy, not by reference.
578 * This function must not be called from an interrupt service routine.
579 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
581 * @param xQueue The handle to the queue on which the item is to be posted.
583 * @param pvItemToQueue A pointer to the item that is to be placed on the
584 * queue. The size of the items the queue will hold was defined when the
585 * queue was created, so this many bytes will be copied from pvItemToQueue
586 * into the queue storage area.
588 * @param xTicksToWait The maximum amount of time the task should block
589 * waiting for space to become available on the queue, should it already
590 * be full. The call will return immediately if this is set to 0 and the
591 * queue is full. The time is defined in tick periods so the constant
592 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
594 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
595 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
596 * at the front of the queue (for high priority messages).
598 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
608 uint32_t ulVar = 10UL;
610 void vATask( void *pvParameters )
612 QueueHandle_t xQueue1, xQueue2;
613 struct AMessage *pxMessage;
615 // Create a queue capable of containing 10 uint32_t values.
616 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
618 // Create a queue capable of containing 10 pointers to AMessage structures.
619 // These should be passed by pointer as they contain a lot of data.
620 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
626 // Send an uint32_t. Wait for 10 ticks for space to become
627 // available if necessary.
628 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
630 // Failed to post the message, even after 10 ticks.
636 // Send a pointer to a struct AMessage object. Don't block if the
637 // queue is already full.
638 pxMessage = & xMessage;
639 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
642 // ... Rest of task code.
645 * \defgroup xQueueSend xQueueSend
646 * \ingroup QueueManagement
648 BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
653 BaseType_t xQueuePeek(
654 QueueHandle_t xQueue,
655 void * const pvBuffer,
656 TickType_t xTicksToWait
659 * Receive an item from a queue without removing the item from the queue.
660 * The item is received by copy so a buffer of adequate size must be
661 * provided. The number of bytes copied into the buffer was defined when
662 * the queue was created.
664 * Successfully received items remain on the queue so will be returned again
665 * by the next call, or a call to xQueueReceive().
667 * This macro must not be used in an interrupt service routine. See
668 * xQueuePeekFromISR() for an alternative that can be called from an interrupt
671 * @param xQueue The handle to the queue from which the item is to be
674 * @param pvBuffer Pointer to the buffer into which the received item will
677 * @param xTicksToWait The maximum amount of time the task should block
678 * waiting for an item to receive should the queue be empty at the time
679 * of the call. The time is defined in tick periods so the constant
680 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
681 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
684 * @return pdTRUE if an item was successfully received from the queue,
695 QueueHandle_t xQueue;
697 // Task to create a queue and post a value.
698 void vATask( void *pvParameters )
700 struct AMessage *pxMessage;
702 // Create a queue capable of containing 10 pointers to AMessage structures.
703 // These should be passed by pointer as they contain a lot of data.
704 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
707 // Failed to create the queue.
712 // Send a pointer to a struct AMessage object. Don't block if the
713 // queue is already full.
714 pxMessage = & xMessage;
715 xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
717 // ... Rest of task code.
720 // Task to peek the data from the queue.
721 void vADifferentTask( void *pvParameters )
723 struct AMessage *pxRxedMessage;
727 // Peek a message on the created queue. Block for 10 ticks if a
728 // message is not immediately available.
729 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
731 // pcRxedMessage now points to the struct AMessage variable posted
732 // by vATask, but the item still remains on the queue.
736 // ... Rest of task code.
739 * \defgroup xQueuePeek xQueuePeek
740 * \ingroup QueueManagement
742 BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
747 BaseType_t xQueuePeekFromISR(
748 QueueHandle_t xQueue,
752 * A version of xQueuePeek() that can be called from an interrupt service
755 * Receive an item from a queue without removing the item from the queue.
756 * The item is received by copy so a buffer of adequate size must be
757 * provided. The number of bytes copied into the buffer was defined when
758 * the queue was created.
760 * Successfully received items remain on the queue so will be returned again
761 * by the next call, or a call to xQueueReceive().
763 * @param xQueue The handle to the queue from which the item is to be
766 * @param pvBuffer Pointer to the buffer into which the received item will
769 * @return pdTRUE if an item was successfully received from the queue,
772 * \defgroup xQueuePeekFromISR xQueuePeekFromISR
773 * \ingroup QueueManagement
775 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;
780 BaseType_t xQueueReceive(
781 QueueHandle_t xQueue,
783 TickType_t xTicksToWait
786 * Receive an item from a queue. The item is received by copy so a buffer of
787 * adequate size must be provided. The number of bytes copied into the buffer
788 * was defined when the queue was created.
790 * Successfully received items are removed from the queue.
792 * This function must not be used in an interrupt service routine. See
793 * xQueueReceiveFromISR for an alternative that can.
795 * @param xQueue The handle to the queue from which the item is to be
798 * @param pvBuffer Pointer to the buffer into which the received item will
801 * @param xTicksToWait The maximum amount of time the task should block
802 * waiting for an item to receive should the queue be empty at the time
803 * of the call. xQueueReceive() will return immediately if xTicksToWait
804 * is zero and the queue is empty. The time is defined in tick periods so the
805 * constant portTICK_PERIOD_MS should be used to convert to real time if this is
808 * @return pdTRUE if an item was successfully received from the queue,
819 QueueHandle_t xQueue;
821 // Task to create a queue and post a value.
822 void vATask( void *pvParameters )
824 struct AMessage *pxMessage;
826 // Create a queue capable of containing 10 pointers to AMessage structures.
827 // These should be passed by pointer as they contain a lot of data.
828 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
831 // Failed to create the queue.
836 // Send a pointer to a struct AMessage object. Don't block if the
837 // queue is already full.
838 pxMessage = & xMessage;
839 xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
841 // ... Rest of task code.
844 // Task to receive from the queue.
845 void vADifferentTask( void *pvParameters )
847 struct AMessage *pxRxedMessage;
851 // Receive a message on the created queue. Block for 10 ticks if a
852 // message is not immediately available.
853 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
855 // pcRxedMessage now points to the struct AMessage variable posted
860 // ... Rest of task code.
863 * \defgroup xQueueReceive xQueueReceive
864 * \ingroup QueueManagement
866 BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
870 * <pre>UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );</pre>
872 * Return the number of messages stored in a queue.
874 * @param xQueue A handle to the queue being queried.
876 * @return The number of messages available in the queue.
878 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
879 * \ingroup QueueManagement
881 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
885 * <pre>UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );</pre>
887 * Return the number of free spaces available in a queue. This is equal to the
888 * number of items that can be sent to the queue before the queue becomes full
889 * if no items are removed.
891 * @param xQueue A handle to the queue being queried.
893 * @return The number of spaces available in the queue.
895 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
896 * \ingroup QueueManagement
898 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
902 * <pre>void vQueueDelete( QueueHandle_t xQueue );</pre>
904 * Delete a queue - freeing all the memory allocated for storing of items
905 * placed on the queue.
907 * @param xQueue A handle to the queue to be deleted.
909 * \defgroup vQueueDelete vQueueDelete
910 * \ingroup QueueManagement
912 void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
917 BaseType_t xQueueSendToFrontFromISR(
918 QueueHandle_t xQueue,
919 const void *pvItemToQueue,
920 BaseType_t *pxHigherPriorityTaskWoken
924 * This is a macro that calls xQueueGenericSendFromISR().
926 * Post an item to the front of a queue. It is safe to use this macro from
927 * within an interrupt service routine.
929 * Items are queued by copy not reference so it is preferable to only
930 * queue small items, especially when called from an ISR. In most cases
931 * it would be preferable to store a pointer to the item being queued.
933 * @param xQueue The handle to the queue on which the item is to be posted.
935 * @param pvItemToQueue A pointer to the item that is to be placed on the
936 * queue. The size of the items the queue will hold was defined when the
937 * queue was created, so this many bytes will be copied from pvItemToQueue
938 * into the queue storage area.
940 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
941 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
942 * to unblock, and the unblocked task has a priority higher than the currently
943 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
944 * a context switch should be requested before the interrupt is exited.
946 * @return pdTRUE if the data was successfully sent to the queue, otherwise
949 * Example usage for buffered IO (where the ISR can obtain more than one value
952 void vBufferISR( void )
955 BaseType_t xHigherPrioritTaskWoken;
957 // We have not woken a task at the start of the ISR.
958 xHigherPriorityTaskWoken = pdFALSE;
960 // Loop until the buffer is empty.
963 // Obtain a byte from the buffer.
964 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
967 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
969 } while( portINPUT_BYTE( BUFFER_COUNT ) );
971 // Now the buffer is empty we can switch context if necessary.
972 if( xHigherPriorityTaskWoken )
979 * \defgroup xQueueSendFromISR xQueueSendFromISR
980 * \ingroup QueueManagement
982 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
988 BaseType_t xQueueSendToBackFromISR(
989 QueueHandle_t xQueue,
990 const void *pvItemToQueue,
991 BaseType_t *pxHigherPriorityTaskWoken
995 * This is a macro that calls xQueueGenericSendFromISR().
997 * Post an item to the back of a queue. It is safe to use this macro from
998 * within an interrupt service routine.
1000 * Items are queued by copy not reference so it is preferable to only
1001 * queue small items, especially when called from an ISR. In most cases
1002 * it would be preferable to store a pointer to the item being queued.
1004 * @param xQueue The handle to the queue on which the item is to be posted.
1006 * @param pvItemToQueue A pointer to the item that is to be placed on the
1007 * queue. The size of the items the queue will hold was defined when the
1008 * queue was created, so this many bytes will be copied from pvItemToQueue
1009 * into the queue storage area.
1011 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
1012 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1013 * to unblock, and the unblocked task has a priority higher than the currently
1014 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
1015 * a context switch should be requested before the interrupt is exited.
1017 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1020 * Example usage for buffered IO (where the ISR can obtain more than one value
1023 void vBufferISR( void )
1026 BaseType_t xHigherPriorityTaskWoken;
1028 // We have not woken a task at the start of the ISR.
1029 xHigherPriorityTaskWoken = pdFALSE;
1031 // Loop until the buffer is empty.
1034 // Obtain a byte from the buffer.
1035 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1038 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1040 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1042 // Now the buffer is empty we can switch context if necessary.
1043 if( xHigherPriorityTaskWoken )
1050 * \defgroup xQueueSendFromISR xQueueSendFromISR
1051 * \ingroup QueueManagement
1053 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1058 BaseType_t xQueueOverwriteFromISR(
1059 QueueHandle_t xQueue,
1060 const void * pvItemToQueue,
1061 BaseType_t *pxHigherPriorityTaskWoken
1065 * A version of xQueueOverwrite() that can be used in an interrupt service
1068 * Only for use with queues that can hold a single item - so the queue is either
1071 * Post an item on a queue. If the queue is already full then overwrite the
1072 * value held in the queue. The item is queued by copy, not by reference.
1074 * @param xQueue The handle to the queue on which the item is to be posted.
1076 * @param pvItemToQueue A pointer to the item that is to be placed on the
1077 * queue. The size of the items the queue will hold was defined when the
1078 * queue was created, so this many bytes will be copied from pvItemToQueue
1079 * into the queue storage area.
1081 * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
1082 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1083 * to unblock, and the unblocked task has a priority higher than the currently
1084 * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
1085 * a context switch should be requested before the interrupt is exited.
1087 * @return xQueueOverwriteFromISR() is a macro that calls
1088 * xQueueGenericSendFromISR(), and therefore has the same return values as
1089 * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
1090 * returned because xQueueOverwriteFromISR() will write to the queue even when
1091 * the queue is already full.
1096 QueueHandle_t xQueue;
1098 void vFunction( void *pvParameters )
1100 // Create a queue to hold one uint32_t value. It is strongly
1101 // recommended *not* to use xQueueOverwriteFromISR() on queues that can
1102 // contain more than one value, and doing so will trigger an assertion
1103 // if configASSERT() is defined.
1104 xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
1107 void vAnInterruptHandler( void )
1109 // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
1110 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
1111 uint32_t ulVarToSend, ulValReceived;
1113 // Write the value 10 to the queue using xQueueOverwriteFromISR().
1115 xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1117 // The queue is full, but calling xQueueOverwriteFromISR() again will still
1118 // pass because the value held in the queue will be overwritten with the
1121 xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1123 // Reading from the queue will now return 100.
1127 if( xHigherPrioritytaskWoken == pdTRUE )
1129 // Writing to the queue caused a task to unblock and the unblocked task
1130 // has a priority higher than or equal to the priority of the currently
1131 // executing task (the task this interrupt interrupted). Perform a context
1132 // switch so this interrupt returns directly to the unblocked task.
1133 portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
1137 * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
1138 * \ingroup QueueManagement
1140 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1145 BaseType_t xQueueSendFromISR(
1146 QueueHandle_t xQueue,
1147 const void *pvItemToQueue,
1148 BaseType_t *pxHigherPriorityTaskWoken
1152 * This is a macro that calls xQueueGenericSendFromISR(). It is included
1153 * for backward compatibility with versions of FreeRTOS.org that did not
1154 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
1157 * Post an item to the back of a queue. It is safe to use this function from
1158 * within an interrupt service routine.
1160 * Items are queued by copy not reference so it is preferable to only
1161 * queue small items, especially when called from an ISR. In most cases
1162 * it would be preferable to store a pointer to the item being queued.
1164 * @param xQueue The handle to the queue on which the item is to be posted.
1166 * @param pvItemToQueue A pointer to the item that is to be placed on the
1167 * queue. The size of the items the queue will hold was defined when the
1168 * queue was created, so this many bytes will be copied from pvItemToQueue
1169 * into the queue storage area.
1171 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
1172 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1173 * to unblock, and the unblocked task has a priority higher than the currently
1174 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
1175 * a context switch should be requested before the interrupt is exited.
1177 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1180 * Example usage for buffered IO (where the ISR can obtain more than one value
1183 void vBufferISR( void )
1186 BaseType_t xHigherPriorityTaskWoken;
1188 // We have not woken a task at the start of the ISR.
1189 xHigherPriorityTaskWoken = pdFALSE;
1191 // Loop until the buffer is empty.
1194 // Obtain a byte from the buffer.
1195 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1198 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1200 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1202 // Now the buffer is empty we can switch context if necessary.
1203 if( xHigherPriorityTaskWoken )
1205 // Actual macro used here is port specific.
1206 portYIELD_FROM_ISR ();
1211 * \defgroup xQueueSendFromISR xQueueSendFromISR
1212 * \ingroup QueueManagement
1214 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1219 BaseType_t xQueueGenericSendFromISR(
1220 QueueHandle_t xQueue,
1221 const void *pvItemToQueue,
1222 BaseType_t *pxHigherPriorityTaskWoken,
1223 BaseType_t xCopyPosition
1227 * It is preferred that the macros xQueueSendFromISR(),
1228 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1229 * of calling this function directly. xQueueGiveFromISR() is an
1230 * equivalent for use by semaphores that don't actually copy any data.
1232 * Post an item on a queue. It is safe to use this function from within an
1233 * interrupt service routine.
1235 * Items are queued by copy not reference so it is preferable to only
1236 * queue small items, especially when called from an ISR. In most cases
1237 * it would be preferable to store a pointer to the item being queued.
1239 * @param xQueue The handle to the queue on which the item is to be posted.
1241 * @param pvItemToQueue A pointer to the item that is to be placed on the
1242 * queue. The size of the items the queue will hold was defined when the
1243 * queue was created, so this many bytes will be copied from pvItemToQueue
1244 * into the queue storage area.
1246 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1247 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1248 * to unblock, and the unblocked task has a priority higher than the currently
1249 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
1250 * a context switch should be requested before the interrupt is exited.
1252 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1253 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1254 * at the front of the queue (for high priority messages).
1256 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1259 * Example usage for buffered IO (where the ISR can obtain more than one value
1262 void vBufferISR( void )
1265 BaseType_t xHigherPriorityTaskWokenByPost;
1267 // We have not woken a task at the start of the ISR.
1268 xHigherPriorityTaskWokenByPost = pdFALSE;
1270 // Loop until the buffer is empty.
1273 // Obtain a byte from the buffer.
1274 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1277 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1279 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1281 // Now the buffer is empty we can switch context if necessary. Note that the
1282 // name of the yield function required is port specific.
1283 if( xHigherPriorityTaskWokenByPost )
1285 taskYIELD_YIELD_FROM_ISR();
1290 * \defgroup xQueueSendFromISR xQueueSendFromISR
1291 * \ingroup QueueManagement
1293 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1294 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1299 BaseType_t xQueueReceiveFromISR(
1300 QueueHandle_t xQueue,
1302 BaseType_t *pxTaskWoken
1306 * Receive an item from a queue. It is safe to use this function from within an
1307 * interrupt service routine.
1309 * @param xQueue The handle to the queue from which the item is to be
1312 * @param pvBuffer Pointer to the buffer into which the received item will
1315 * @param pxTaskWoken A task may be blocked waiting for space to become
1316 * available on the queue. If xQueueReceiveFromISR causes such a task to
1317 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
1320 * @return pdTRUE if an item was successfully received from the queue,
1321 * otherwise pdFALSE.
1326 QueueHandle_t xQueue;
1328 // Function to create a queue and post some values.
1329 void vAFunction( void *pvParameters )
1332 const TickType_t xTicksToWait = ( TickType_t )0xff;
1334 // Create a queue capable of containing 10 characters.
1335 xQueue = xQueueCreate( 10, sizeof( char ) );
1338 // Failed to create the queue.
1343 // Post some characters that will be used within an ISR. If the queue
1344 // is full then this task will block for xTicksToWait ticks.
1346 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1348 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1350 // ... keep posting characters ... this task may block when the queue
1354 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1357 // ISR that outputs all the characters received on the queue.
1358 void vISR_Routine( void )
1360 BaseType_t xTaskWokenByReceive = pdFALSE;
1363 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1365 // A character was received. Output the character now.
1366 vOutputCharacter( cRxedChar );
1368 // If removing the character from the queue woke the task that was
1369 // posting onto the queue cTaskWokenByReceive will have been set to
1370 // pdTRUE. No matter how many times this loop iterates only one
1371 // task will be woken.
1374 if( cTaskWokenByPost != ( char ) pdFALSE;
1380 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
1381 * \ingroup QueueManagement
1383 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1386 * Utilities to query queues that are safe to use from an ISR. These utilities
1387 * should be used only from witin an ISR, or within a critical section.
1389 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1390 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1391 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1394 * The functions defined above are for passing data to and from tasks. The
1395 * functions below are the equivalents for passing data to and from
1398 * These functions are called from the co-routine macro implementation and
1399 * should not be called directly from application code. Instead use the macro
1400 * wrappers defined within croutine.h.
1402 BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken );
1403 BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxTaskWoken );
1404 BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait );
1405 BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait );
1408 * For internal use only. Use xSemaphoreCreateMutex(),
1409 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1410 * these functions directly.
1412 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1413 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
1414 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1415 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
1416 BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1417 void* xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1418 void* xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1421 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1422 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1424 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1425 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t pxMutex ) PRIVILEGED_FUNCTION;
1428 * Reset a queue back to its original empty state. The return value is now
1429 * obsolete and is always set to pdPASS.
1431 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
1434 * The registry is provided as a means for kernel aware debuggers to
1435 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1436 * a queue, semaphore or mutex handle to the registry if you want the handle
1437 * to be available to a kernel aware debugger. If you are not using a kernel
1438 * aware debugger then this function can be ignored.
1440 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1441 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1442 * within FreeRTOSConfig.h for the registry to be available. Its value
1443 * does not effect the number of queues, semaphores and mutexes that can be
1444 * created - just the number that the registry can hold.
1446 * @param xQueue The handle of the queue being added to the registry. This
1447 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1448 * handles can also be passed in here.
1450 * @param pcName The name to be associated with the handle. This is the
1451 * name that the kernel aware debugger will display. The queue registry only
1452 * stores a pointer to the string - so the string must be persistent (global or
1453 * preferably in ROM/Flash), not on the stack.
1455 #if( configQUEUE_REGISTRY_SIZE > 0 )
1456 void vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1460 * The registry is provided as a means for kernel aware debuggers to
1461 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1462 * a queue, semaphore or mutex handle to the registry if you want the handle
1463 * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1464 * remove the queue, semaphore or mutex from the register. If you are not using
1465 * a kernel aware debugger then this function can be ignored.
1467 * @param xQueue The handle of the queue being removed from the registry.
1469 #if( configQUEUE_REGISTRY_SIZE > 0 )
1470 void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1474 * The queue registry is provided as a means for kernel aware debuggers to
1475 * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
1476 * up and return the name of a queue in the queue registry from the queue's
1479 * @param xQueue The handle of the queue the name of which will be returned.
1480 * @return If the queue is in the registry then a pointer to the name of the
1481 * queue is returned. If the queue is not in the registry then NULL is
1484 #if( configQUEUE_REGISTRY_SIZE > 0 )
1485 const char *pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1489 * Generic version of the function used to creaet a queue using dynamic memory
1490 * allocation. This is called by other functions and macros that create other
1491 * RTOS objects that use the queue structure as their base.
1493 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1494 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1498 * Generic version of the function used to creaet a queue using dynamic memory
1499 * allocation. This is called by other functions and macros that create other
1500 * RTOS objects that use the queue structure as their base.
1502 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
1503 QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1507 * Queue sets provide a mechanism to allow a task to block (pend) on a read
1508 * operation from multiple queues or semaphores simultaneously.
1510 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1513 * A queue set must be explicitly created using a call to xQueueCreateSet()
1514 * before it can be used. Once created, standard FreeRTOS queues and semaphores
1515 * can be added to the set using calls to xQueueAddToSet().
1516 * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1517 * or semaphores contained in the set is in a state where a queue read or
1518 * semaphore take operation would be successful.
1520 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1521 * for reasons why queue sets are very rarely needed in practice as there are
1522 * simpler methods of blocking on multiple objects.
1524 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1525 * mutex holder to inherit the priority of the blocked task.
1527 * Note 3: An additional 4 bytes of RAM is required for each space in a every
1528 * queue added to a queue set. Therefore counting semaphores that have a high
1529 * maximum count value should not be added to a queue set.
1531 * Note 4: A receive (in the case of a queue) or take (in the case of a
1532 * semaphore) operation must not be performed on a member of a queue set unless
1533 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1535 * @param uxEventQueueLength Queue sets store events that occur on
1536 * the queues and semaphores contained in the set. uxEventQueueLength specifies
1537 * the maximum number of events that can be queued at once. To be absolutely
1538 * certain that events are not lost uxEventQueueLength should be set to the
1539 * total sum of the length of the queues added to the set, where binary
1540 * semaphores and mutexes have a length of 1, and counting semaphores have a
1541 * length set by their maximum count value. Examples:
1542 * + If a queue set is to hold a queue of length 5, another queue of length 12,
1543 * and a binary semaphore, then uxEventQueueLength should be set to
1544 * (5 + 12 + 1), or 18.
1545 * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1546 * should be set to (1 + 1 + 1 ), or 3.
1547 * + If a queue set is to hold a counting semaphore that has a maximum count of
1548 * 5, and a counting semaphore that has a maximum count of 3, then
1549 * uxEventQueueLength should be set to (5 + 3), or 8.
1551 * @return If the queue set is created successfully then a handle to the created
1552 * queue set is returned. Otherwise NULL is returned.
1554 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1557 * Adds a queue or semaphore to a queue set that was previously created by a
1558 * call to xQueueCreateSet().
1560 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1563 * Note 1: A receive (in the case of a queue) or take (in the case of a
1564 * semaphore) operation must not be performed on a member of a queue set unless
1565 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1567 * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1568 * the queue set (cast to an QueueSetMemberHandle_t type).
1570 * @param xQueueSet The handle of the queue set to which the queue or semaphore
1573 * @return If the queue or semaphore was successfully added to the queue set
1574 * then pdPASS is returned. If the queue could not be successfully added to the
1575 * queue set because it is already a member of a different queue set then pdFAIL
1578 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1581 * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1582 * be removed from a set if the queue or semaphore is empty.
1584 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1587 * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1588 * from the queue set (cast to an QueueSetMemberHandle_t type).
1590 * @param xQueueSet The handle of the queue set in which the queue or semaphore
1593 * @return If the queue or semaphore was successfully removed from the queue set
1594 * then pdPASS is returned. If the queue was not in the queue set, or the
1595 * queue (or semaphore) was not empty, then pdFAIL is returned.
1597 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1600 * xQueueSelectFromSet() selects from the members of a queue set a queue or
1601 * semaphore that either contains data (in the case of a queue) or is available
1602 * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1603 * allows a task to block (pend) on a read operation on all the queues and
1604 * semaphores in a queue set simultaneously.
1606 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1609 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1610 * for reasons why queue sets are very rarely needed in practice as there are
1611 * simpler methods of blocking on multiple objects.
1613 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1614 * mutex holder to inherit the priority of the blocked task.
1616 * Note 3: A receive (in the case of a queue) or take (in the case of a
1617 * semaphore) operation must not be performed on a member of a queue set unless
1618 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1620 * @param xQueueSet The queue set on which the task will (potentially) block.
1622 * @param xTicksToWait The maximum time, in ticks, that the calling task will
1623 * remain in the Blocked state (with other tasks executing) to wait for a member
1624 * of the queue set to be ready for a successful queue read or semaphore take
1627 * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1628 * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1629 * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1630 * in the queue set that is available, or NULL if no such queue or semaphore
1631 * exists before before the specified block time expires.
1633 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1636 * A version of xQueueSelectFromSet() that can be used from an ISR.
1638 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1640 /* Not public API functions. */
1641 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1642 BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1643 void vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1644 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1645 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1652 #endif /* QUEUE_H */