2 * FreeRTOS Kernel V10.3.1
3 * Copyright (C) 2020 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
31 #ifndef INC_FREERTOS_H
32 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
44 * Type by which queues are referenced. For example, a call to xQueueCreate()
45 * returns an QueueHandle_t variable that can then be used as a parameter to
46 * xQueueSend(), xQueueReceive(), etc.
48 struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
49 typedef struct QueueDefinition * QueueHandle_t;
52 * Type by which queue sets are referenced. For example, a call to
53 * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
54 * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
56 typedef struct QueueDefinition * QueueSetHandle_t;
59 * Queue sets can contain both queues and semaphores, so the
60 * QueueSetMemberHandle_t is defined as a type to be used where a parameter or
61 * return value can be either an QueueHandle_t or an SemaphoreHandle_t.
63 typedef struct QueueDefinition * QueueSetMemberHandle_t;
65 /* For internal use only. */
66 #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
67 #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
68 #define queueOVERWRITE ( ( BaseType_t ) 2 )
70 /* For internal use only. These definitions *must* match those in queue.c. */
71 #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
72 #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
73 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
74 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
75 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
76 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
81 * QueueHandle_t xQueueCreate(
82 * UBaseType_t uxQueueLength,
83 * UBaseType_t uxItemSize
87 * Creates a new queue instance, and returns a handle by which the new queue
90 * Internally, within the FreeRTOS implementation, queues use two blocks of
91 * memory. The first block is used to hold the queue's data structures. The
92 * second block is used to hold items placed into the queue. If a queue is
93 * created using xQueueCreate() then both blocks of memory are automatically
94 * dynamically allocated inside the xQueueCreate() function. (see
95 * http://www.freertos.org/a00111.html). If a queue is created using
96 * xQueueCreateStatic() then the application writer must provide the memory that
97 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
98 * be created without using any dynamic memory allocation.
100 * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html
102 * @param uxQueueLength The maximum number of items that the queue can contain.
104 * @param uxItemSize The number of bytes each item in the queue will require.
105 * Items are queued by copy, not by reference, so this is the number of bytes
106 * that will be copied for each posted item. Each item on the queue must be
109 * @return If the queue is successfully create then a handle to the newly
110 * created queue is returned. If the queue cannot be created then 0 is
121 * void vATask( void *pvParameters )
123 * QueueHandle_t xQueue1, xQueue2;
125 * // Create a queue capable of containing 10 uint32_t values.
126 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
129 * // Queue was not created and must not be used.
132 * // Create a queue capable of containing 10 pointers to AMessage structures.
133 * // These should be passed by pointer as they contain a lot of data.
134 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
137 * // Queue was not created and must not be used.
140 * // ... Rest of task code.
143 * \defgroup xQueueCreate xQueueCreate
144 * \ingroup QueueManagement
146 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
147 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
153 * QueueHandle_t xQueueCreateStatic(
154 * UBaseType_t uxQueueLength,
155 * UBaseType_t uxItemSize,
156 * uint8_t *pucQueueStorageBuffer,
157 * StaticQueue_t *pxQueueBuffer
161 * Creates a new queue instance, and returns a handle by which the new queue
164 * Internally, within the FreeRTOS implementation, queues use two blocks of
165 * memory. The first block is used to hold the queue's data structures. The
166 * second block is used to hold items placed into the queue. If a queue is
167 * created using xQueueCreate() then both blocks of memory are automatically
168 * dynamically allocated inside the xQueueCreate() function. (see
169 * http://www.freertos.org/a00111.html). If a queue is created using
170 * xQueueCreateStatic() then the application writer must provide the memory that
171 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
172 * be created without using any dynamic memory allocation.
174 * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html
176 * @param uxQueueLength The maximum number of items that the queue can contain.
178 * @param uxItemSize The number of bytes each item in the queue will require.
179 * Items are queued by copy, not by reference, so this is the number of bytes
180 * that will be copied for each posted item. Each item on the queue must be
183 * @param pucQueueStorageBuffer If uxItemSize is not zero then
184 * pucQueueStorageBuffer must point to a uint8_t array that is at least large
185 * enough to hold the maximum number of items that can be in the queue at any
186 * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
187 * zero then pucQueueStorageBuffer can be NULL.
189 * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
190 * will be used to hold the queue's data structure.
192 * @return If the queue is created then a handle to the created queue is
193 * returned. If pxQueueBuffer is NULL then NULL is returned.
203 #define QUEUE_LENGTH 10
204 #define ITEM_SIZE sizeof( uint32_t )
206 * // xQueueBuffer will hold the queue structure.
207 * StaticQueue_t xQueueBuffer;
209 * // ucQueueStorage will hold the items posted to the queue. Must be at least
210 * // [(queue length) * ( queue item size)] bytes long.
211 * uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
213 * void vATask( void *pvParameters )
215 * QueueHandle_t xQueue1;
217 * // Create a queue capable of containing 10 uint32_t values.
218 * xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
219 * ITEM_SIZE // The size of each item in the queue
220 * &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
221 * &xQueueBuffer ); // The buffer that will hold the queue structure.
223 * // The queue is guaranteed to be created successfully as no dynamic memory
224 * // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
226 * // ... Rest of task code.
229 * \defgroup xQueueCreateStatic xQueueCreateStatic
230 * \ingroup QueueManagement
232 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
233 #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
234 #endif /* configSUPPORT_STATIC_ALLOCATION */
239 * BaseType_t xQueueSendToToFront(
240 * QueueHandle_t xQueue,
241 * const void *pvItemToQueue,
242 * TickType_t xTicksToWait
246 * Post an item to the front of a queue. The item is queued by copy, not by
247 * reference. This function must not be called from an interrupt service
248 * routine. See xQueueSendFromISR () for an alternative which may be used
251 * @param xQueue The handle to the queue on which the item is to be posted.
253 * @param pvItemToQueue A pointer to the item that is to be placed on the
254 * queue. The size of the items the queue will hold was defined when the
255 * queue was created, so this many bytes will be copied from pvItemToQueue
256 * into the queue storage area.
258 * @param xTicksToWait The maximum amount of time the task should block
259 * waiting for space to become available on the queue, should it already
260 * be full. The call will return immediately if this is set to 0 and the
261 * queue is full. The time is defined in tick periods so the constant
262 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
264 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
274 * uint32_t ulVar = 10UL;
276 * void vATask( void *pvParameters )
278 * QueueHandle_t xQueue1, xQueue2;
279 * struct AMessage *pxMessage;
281 * // Create a queue capable of containing 10 uint32_t values.
282 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
284 * // Create a queue capable of containing 10 pointers to AMessage structures.
285 * // These should be passed by pointer as they contain a lot of data.
286 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
292 * // Send an uint32_t. Wait for 10 ticks for space to become
293 * // available if necessary.
294 * if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
296 * // Failed to post the message, even after 10 ticks.
302 * // Send a pointer to a struct AMessage object. Don't block if the
303 * // queue is already full.
304 * pxMessage = & xMessage;
305 * xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
308 * // ... Rest of task code.
311 * \defgroup xQueueSend xQueueSend
312 * \ingroup QueueManagement
314 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \
315 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
320 * BaseType_t xQueueSendToBack(
321 * QueueHandle_t xQueue,
322 * const void *pvItemToQueue,
323 * TickType_t xTicksToWait
327 * This is a macro that calls xQueueGenericSend().
329 * Post an item to the back of a queue. The item is queued by copy, not by
330 * reference. This function must not be called from an interrupt service
331 * routine. See xQueueSendFromISR () for an alternative which may be used
334 * @param xQueue The handle to the queue on which the item is to be posted.
336 * @param pvItemToQueue A pointer to the item that is to be placed on the
337 * queue. The size of the items the queue will hold was defined when the
338 * queue was created, so this many bytes will be copied from pvItemToQueue
339 * into the queue storage area.
341 * @param xTicksToWait The maximum amount of time the task should block
342 * waiting for space to become available on the queue, should it already
343 * be full. The call will return immediately if this is set to 0 and the queue
344 * is full. The time is defined in tick periods so the constant
345 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
347 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
357 * uint32_t ulVar = 10UL;
359 * void vATask( void *pvParameters )
361 * QueueHandle_t xQueue1, xQueue2;
362 * struct AMessage *pxMessage;
364 * // Create a queue capable of containing 10 uint32_t values.
365 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
367 * // Create a queue capable of containing 10 pointers to AMessage structures.
368 * // These should be passed by pointer as they contain a lot of data.
369 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
375 * // Send an uint32_t. Wait for 10 ticks for space to become
376 * // available if necessary.
377 * if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
379 * // Failed to post the message, even after 10 ticks.
385 * // Send a pointer to a struct AMessage object. Don't block if the
386 * // queue is already full.
387 * pxMessage = & xMessage;
388 * xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
391 * // ... Rest of task code.
394 * \defgroup xQueueSend xQueueSend
395 * \ingroup QueueManagement
397 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
398 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
403 * BaseType_t xQueueSend(
404 * QueueHandle_t xQueue,
405 * const void * pvItemToQueue,
406 * TickType_t xTicksToWait
410 * This is a macro that calls xQueueGenericSend(). It is included for
411 * backward compatibility with versions of FreeRTOS.org that did not
412 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
413 * equivalent to xQueueSendToBack().
415 * Post an item on a queue. The item is queued by copy, not by reference.
416 * This function must not be called from an interrupt service routine.
417 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
419 * @param xQueue The handle to the queue on which the item is to be posted.
421 * @param pvItemToQueue A pointer to the item that is to be placed on the
422 * queue. The size of the items the queue will hold was defined when the
423 * queue was created, so this many bytes will be copied from pvItemToQueue
424 * into the queue storage area.
426 * @param xTicksToWait The maximum amount of time the task should block
427 * waiting for space to become available on the queue, should it already
428 * be full. The call will return immediately if this is set to 0 and the
429 * queue is full. The time is defined in tick periods so the constant
430 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
432 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
442 * uint32_t ulVar = 10UL;
444 * void vATask( void *pvParameters )
446 * QueueHandle_t xQueue1, xQueue2;
447 * struct AMessage *pxMessage;
449 * // Create a queue capable of containing 10 uint32_t values.
450 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
452 * // Create a queue capable of containing 10 pointers to AMessage structures.
453 * // These should be passed by pointer as they contain a lot of data.
454 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
460 * // Send an uint32_t. Wait for 10 ticks for space to become
461 * // available if necessary.
462 * if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
464 * // Failed to post the message, even after 10 ticks.
470 * // Send a pointer to a struct AMessage object. Don't block if the
471 * // queue is already full.
472 * pxMessage = & xMessage;
473 * xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
476 * // ... Rest of task code.
479 * \defgroup xQueueSend xQueueSend
480 * \ingroup QueueManagement
482 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
483 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
488 * BaseType_t xQueueOverwrite(
489 * QueueHandle_t xQueue,
490 * const void * pvItemToQueue
494 * Only for use with queues that have a length of one - so the queue is either
497 * Post an item on a queue. If the queue is already full then overwrite the
498 * value held in the queue. The item is queued by copy, not by reference.
500 * This function must not be called from an interrupt service routine.
501 * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
503 * @param xQueue The handle of the queue to which the data is being sent.
505 * @param pvItemToQueue A pointer to the item that is to be placed on the
506 * queue. The size of the items the queue will hold was defined when the
507 * queue was created, so this many bytes will be copied from pvItemToQueue
508 * into the queue storage area.
510 * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
511 * therefore has the same return values as xQueueSendToFront(). However, pdPASS
512 * is the only value that can be returned because xQueueOverwrite() will write
513 * to the queue even when the queue is already full.
518 * void vFunction( void *pvParameters )
520 * QueueHandle_t xQueue;
521 * uint32_t ulVarToSend, ulValReceived;
523 * // Create a queue to hold one uint32_t value. It is strongly
524 * // recommended *not* to use xQueueOverwrite() on queues that can
525 * // contain more than one value, and doing so will trigger an assertion
526 * // if configASSERT() is defined.
527 * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
529 * // Write the value 10 to the queue using xQueueOverwrite().
531 * xQueueOverwrite( xQueue, &ulVarToSend );
533 * // Peeking the queue should now return 10, but leave the value 10 in
534 * // the queue. A block time of zero is used as it is known that the
535 * // queue holds a value.
537 * xQueuePeek( xQueue, &ulValReceived, 0 );
539 * if( ulValReceived != 10 )
541 * // Error unless the item was removed by a different task.
544 * // The queue is still full. Use xQueueOverwrite() to overwrite the
545 * // value held in the queue with 100.
547 * xQueueOverwrite( xQueue, &ulVarToSend );
549 * // This time read from the queue, leaving the queue empty once more.
550 * // A block time of 0 is used again.
551 * xQueueReceive( xQueue, &ulValReceived, 0 );
553 * // The value read should be the last value written, even though the
554 * // queue was already full when the value was written.
555 * if( ulValReceived != 100 )
563 * \defgroup xQueueOverwrite xQueueOverwrite
564 * \ingroup QueueManagement
566 #define xQueueOverwrite( xQueue, pvItemToQueue ) \
567 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
573 * BaseType_t xQueueGenericSend(
574 * QueueHandle_t xQueue,
575 * const void * pvItemToQueue,
576 * TickType_t xTicksToWait
577 * BaseType_t xCopyPosition
581 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
582 * xQueueSendToBack() are used in place of calling this function directly.
584 * Post an item on a queue. The item is queued by copy, not by reference.
585 * This function must not be called from an interrupt service routine.
586 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
588 * @param xQueue The handle to the queue on which the item is to be posted.
590 * @param pvItemToQueue A pointer to the item that is to be placed on the
591 * queue. The size of the items the queue will hold was defined when the
592 * queue was created, so this many bytes will be copied from pvItemToQueue
593 * into the queue storage area.
595 * @param xTicksToWait The maximum amount of time the task should block
596 * waiting for space to become available on the queue, should it already
597 * be full. The call will return immediately if this is set to 0 and the
598 * queue is full. The time is defined in tick periods so the constant
599 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
601 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
602 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
603 * at the front of the queue (for high priority messages).
605 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
615 * uint32_t ulVar = 10UL;
617 * void vATask( void *pvParameters )
619 * QueueHandle_t xQueue1, xQueue2;
620 * struct AMessage *pxMessage;
622 * // Create a queue capable of containing 10 uint32_t values.
623 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
625 * // Create a queue capable of containing 10 pointers to AMessage structures.
626 * // These should be passed by pointer as they contain a lot of data.
627 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
633 * // Send an uint32_t. Wait for 10 ticks for space to become
634 * // available if necessary.
635 * if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
637 * // Failed to post the message, even after 10 ticks.
643 * // Send a pointer to a struct AMessage object. Don't block if the
644 * // queue is already full.
645 * pxMessage = & xMessage;
646 * xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
649 * // ... Rest of task code.
652 * \defgroup xQueueSend xQueueSend
653 * \ingroup QueueManagement
655 BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
656 const void * const pvItemToQueue,
657 TickType_t xTicksToWait,
658 const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
663 * BaseType_t xQueuePeek(
664 * QueueHandle_t xQueue,
665 * void * const pvBuffer,
666 * TickType_t xTicksToWait
670 * Receive an item from a queue without removing the item from the queue.
671 * The item is received by copy so a buffer of adequate size must be
672 * provided. The number of bytes copied into the buffer was defined when
673 * the queue was created.
675 * Successfully received items remain on the queue so will be returned again
676 * by the next call, or a call to xQueueReceive().
678 * This macro must not be used in an interrupt service routine. See
679 * xQueuePeekFromISR() for an alternative that can be called from an interrupt
682 * @param xQueue The handle to the queue from which the item is to be
685 * @param pvBuffer Pointer to the buffer into which the received item will
688 * @param xTicksToWait The maximum amount of time the task should block
689 * waiting for an item to receive should the queue be empty at the time
690 * of the call. The time is defined in tick periods so the constant
691 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
692 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
695 * @return pdTRUE if an item was successfully received from the queue,
706 * QueueHandle_t xQueue;
708 * // Task to create a queue and post a value.
709 * void vATask( void *pvParameters )
711 * struct AMessage *pxMessage;
713 * // Create a queue capable of containing 10 pointers to AMessage structures.
714 * // These should be passed by pointer as they contain a lot of data.
715 * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
718 * // Failed to create the queue.
723 * // Send a pointer to a struct AMessage object. Don't block if the
724 * // queue is already full.
725 * pxMessage = & xMessage;
726 * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
728 * // ... Rest of task code.
731 * // Task to peek the data from the queue.
732 * void vADifferentTask( void *pvParameters )
734 * struct AMessage *pxRxedMessage;
738 * // Peek a message on the created queue. Block for 10 ticks if a
739 * // message is not immediately available.
740 * if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
742 * // pcRxedMessage now points to the struct AMessage variable posted
743 * // by vATask, but the item still remains on the queue.
747 * // ... Rest of task code.
750 * \defgroup xQueuePeek xQueuePeek
751 * \ingroup QueueManagement
753 BaseType_t xQueuePeek( QueueHandle_t xQueue,
754 void * const pvBuffer,
755 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
760 * BaseType_t xQueuePeekFromISR(
761 * QueueHandle_t xQueue,
766 * A version of xQueuePeek() that can be called from an interrupt service
769 * Receive an item from a queue without removing the item from the queue.
770 * The item is received by copy so a buffer of adequate size must be
771 * provided. The number of bytes copied into the buffer was defined when
772 * the queue was created.
774 * Successfully received items remain on the queue so will be returned again
775 * by the next call, or a call to xQueueReceive().
777 * @param xQueue The handle to the queue from which the item is to be
780 * @param pvBuffer Pointer to the buffer into which the received item will
783 * @return pdTRUE if an item was successfully received from the queue,
786 * \defgroup xQueuePeekFromISR xQueuePeekFromISR
787 * \ingroup QueueManagement
789 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
790 void * const pvBuffer ) PRIVILEGED_FUNCTION;
795 * BaseType_t xQueueReceive(
796 * QueueHandle_t xQueue,
798 * TickType_t xTicksToWait
802 * Receive an item from a queue. The item is received by copy so a buffer of
803 * adequate size must be provided. The number of bytes copied into the buffer
804 * was defined when the queue was created.
806 * Successfully received items are removed from the queue.
808 * This function must not be used in an interrupt service routine. See
809 * xQueueReceiveFromISR for an alternative that can.
811 * @param xQueue The handle to the queue from which the item is to be
814 * @param pvBuffer Pointer to the buffer into which the received item will
817 * @param xTicksToWait The maximum amount of time the task should block
818 * waiting for an item to receive should the queue be empty at the time
819 * of the call. xQueueReceive() will return immediately if xTicksToWait
820 * is zero and the queue is empty. The time is defined in tick periods so the
821 * constant portTICK_PERIOD_MS should be used to convert to real time if this is
824 * @return pdTRUE if an item was successfully received from the queue,
835 * QueueHandle_t xQueue;
837 * // Task to create a queue and post a value.
838 * void vATask( void *pvParameters )
840 * struct AMessage *pxMessage;
842 * // Create a queue capable of containing 10 pointers to AMessage structures.
843 * // These should be passed by pointer as they contain a lot of data.
844 * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
847 * // Failed to create the queue.
852 * // Send a pointer to a struct AMessage object. Don't block if the
853 * // queue is already full.
854 * pxMessage = & xMessage;
855 * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
857 * // ... Rest of task code.
860 * // Task to receive from the queue.
861 * void vADifferentTask( void *pvParameters )
863 * struct AMessage *pxRxedMessage;
867 * // Receive a message on the created queue. Block for 10 ticks if a
868 * // message is not immediately available.
869 * if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
871 * // pcRxedMessage now points to the struct AMessage variable posted
876 * // ... Rest of task code.
879 * \defgroup xQueueReceive xQueueReceive
880 * \ingroup QueueManagement
882 BaseType_t xQueueReceive( QueueHandle_t xQueue,
883 void * const pvBuffer,
884 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
889 * UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
892 * Return the number of messages stored in a queue.
894 * @param xQueue A handle to the queue being queried.
896 * @return The number of messages available in the queue.
898 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
899 * \ingroup QueueManagement
901 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
906 * UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
909 * Return the number of free spaces available in a queue. This is equal to the
910 * number of items that can be sent to the queue before the queue becomes full
911 * if no items are removed.
913 * @param xQueue A handle to the queue being queried.
915 * @return The number of spaces available in the queue.
917 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
918 * \ingroup QueueManagement
920 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
925 * void vQueueDelete( QueueHandle_t xQueue );
928 * Delete a queue - freeing all the memory allocated for storing of items
929 * placed on the queue.
931 * @param xQueue A handle to the queue to be deleted.
933 * \defgroup vQueueDelete vQueueDelete
934 * \ingroup QueueManagement
936 void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
941 * BaseType_t xQueueSendToFrontFromISR(
942 * QueueHandle_t xQueue,
943 * const void *pvItemToQueue,
944 * BaseType_t *pxHigherPriorityTaskWoken
948 * This is a macro that calls xQueueGenericSendFromISR().
950 * Post an item to the front of a queue. It is safe to use this macro from
951 * within an interrupt service routine.
953 * Items are queued by copy not reference so it is preferable to only
954 * queue small items, especially when called from an ISR. In most cases
955 * it would be preferable to store a pointer to the item being queued.
957 * @param xQueue The handle to the queue on which the item is to be posted.
959 * @param pvItemToQueue A pointer to the item that is to be placed on the
960 * queue. The size of the items the queue will hold was defined when the
961 * queue was created, so this many bytes will be copied from pvItemToQueue
962 * into the queue storage area.
964 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
965 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
966 * to unblock, and the unblocked task has a priority higher than the currently
967 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
968 * a context switch should be requested before the interrupt is exited.
970 * @return pdTRUE if the data was successfully sent to the queue, otherwise
973 * Example usage for buffered IO (where the ISR can obtain more than one value
976 * void vBufferISR( void )
979 * BaseType_t xHigherPrioritTaskWoken;
981 * // We have not woken a task at the start of the ISR.
982 * xHigherPriorityTaskWoken = pdFALSE;
984 * // Loop until the buffer is empty.
987 * // Obtain a byte from the buffer.
988 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
991 * xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
993 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
995 * // Now the buffer is empty we can switch context if necessary.
996 * if( xHigherPriorityTaskWoken )
1003 * \defgroup xQueueSendFromISR xQueueSendFromISR
1004 * \ingroup QueueManagement
1006 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1007 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
1013 * BaseType_t xQueueSendToBackFromISR(
1014 * QueueHandle_t xQueue,
1015 * const void *pvItemToQueue,
1016 * BaseType_t *pxHigherPriorityTaskWoken
1020 * This is a macro that calls xQueueGenericSendFromISR().
1022 * Post an item to the back of a queue. It is safe to use this macro from
1023 * within an interrupt service routine.
1025 * Items are queued by copy not reference so it is preferable to only
1026 * queue small items, especially when called from an ISR. In most cases
1027 * it would be preferable to store a pointer to the item being queued.
1029 * @param xQueue The handle to the queue on which the item is to be posted.
1031 * @param pvItemToQueue A pointer to the item that is to be placed on the
1032 * queue. The size of the items the queue will hold was defined when the
1033 * queue was created, so this many bytes will be copied from pvItemToQueue
1034 * into the queue storage area.
1036 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
1037 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1038 * to unblock, and the unblocked task has a priority higher than the currently
1039 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
1040 * a context switch should be requested before the interrupt is exited.
1042 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1045 * Example usage for buffered IO (where the ISR can obtain more than one value
1048 * void vBufferISR( void )
1051 * BaseType_t xHigherPriorityTaskWoken;
1053 * // We have not woken a task at the start of the ISR.
1054 * xHigherPriorityTaskWoken = pdFALSE;
1056 * // Loop until the buffer is empty.
1059 * // Obtain a byte from the buffer.
1060 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1063 * xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1065 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1067 * // Now the buffer is empty we can switch context if necessary.
1068 * if( xHigherPriorityTaskWoken )
1075 * \defgroup xQueueSendFromISR xQueueSendFromISR
1076 * \ingroup QueueManagement
1078 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1079 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1084 * BaseType_t xQueueOverwriteFromISR(
1085 * QueueHandle_t xQueue,
1086 * const void * pvItemToQueue,
1087 * BaseType_t *pxHigherPriorityTaskWoken
1091 * A version of xQueueOverwrite() that can be used in an interrupt service
1094 * Only for use with queues that can hold a single item - so the queue is either
1097 * Post an item on a queue. If the queue is already full then overwrite the
1098 * value held in the queue. The item is queued by copy, not by reference.
1100 * @param xQueue The handle to the queue on which the item is to be posted.
1102 * @param pvItemToQueue A pointer to the item that is to be placed on the
1103 * queue. The size of the items the queue will hold was defined when the
1104 * queue was created, so this many bytes will be copied from pvItemToQueue
1105 * into the queue storage area.
1107 * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
1108 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1109 * to unblock, and the unblocked task has a priority higher than the currently
1110 * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
1111 * a context switch should be requested before the interrupt is exited.
1113 * @return xQueueOverwriteFromISR() is a macro that calls
1114 * xQueueGenericSendFromISR(), and therefore has the same return values as
1115 * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
1116 * returned because xQueueOverwriteFromISR() will write to the queue even when
1117 * the queue is already full.
1122 * QueueHandle_t xQueue;
1124 * void vFunction( void *pvParameters )
1126 * // Create a queue to hold one uint32_t value. It is strongly
1127 * // recommended *not* to use xQueueOverwriteFromISR() on queues that can
1128 * // contain more than one value, and doing so will trigger an assertion
1129 * // if configASSERT() is defined.
1130 * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
1133 * void vAnInterruptHandler( void )
1135 * // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
1136 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
1137 * uint32_t ulVarToSend, ulValReceived;
1139 * // Write the value 10 to the queue using xQueueOverwriteFromISR().
1141 * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1143 * // The queue is full, but calling xQueueOverwriteFromISR() again will still
1144 * // pass because the value held in the queue will be overwritten with the
1146 * ulVarToSend = 100;
1147 * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1149 * // Reading from the queue will now return 100.
1153 * if( xHigherPrioritytaskWoken == pdTRUE )
1155 * // Writing to the queue caused a task to unblock and the unblocked task
1156 * // has a priority higher than or equal to the priority of the currently
1157 * // executing task (the task this interrupt interrupted). Perform a context
1158 * // switch so this interrupt returns directly to the unblocked task.
1159 * portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
1163 * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
1164 * \ingroup QueueManagement
1166 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1167 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1172 * BaseType_t xQueueSendFromISR(
1173 * QueueHandle_t xQueue,
1174 * const void *pvItemToQueue,
1175 * BaseType_t *pxHigherPriorityTaskWoken
1179 * This is a macro that calls xQueueGenericSendFromISR(). It is included
1180 * for backward compatibility with versions of FreeRTOS.org that did not
1181 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
1184 * Post an item to the back of a queue. It is safe to use this function from
1185 * within an interrupt service routine.
1187 * Items are queued by copy not reference so it is preferable to only
1188 * queue small items, especially when called from an ISR. In most cases
1189 * it would be preferable to store a pointer to the item being queued.
1191 * @param xQueue The handle to the queue on which the item is to be posted.
1193 * @param pvItemToQueue A pointer to the item that is to be placed on the
1194 * queue. The size of the items the queue will hold was defined when the
1195 * queue was created, so this many bytes will be copied from pvItemToQueue
1196 * into the queue storage area.
1198 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
1199 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1200 * to unblock, and the unblocked task has a priority higher than the currently
1201 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
1202 * a context switch should be requested before the interrupt is exited.
1204 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1207 * Example usage for buffered IO (where the ISR can obtain more than one value
1210 * void vBufferISR( void )
1213 * BaseType_t xHigherPriorityTaskWoken;
1215 * // We have not woken a task at the start of the ISR.
1216 * xHigherPriorityTaskWoken = pdFALSE;
1218 * // Loop until the buffer is empty.
1221 * // Obtain a byte from the buffer.
1222 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1225 * xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1227 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1229 * // Now the buffer is empty we can switch context if necessary.
1230 * if( xHigherPriorityTaskWoken )
1232 * // Actual macro used here is port specific.
1233 * portYIELD_FROM_ISR ();
1238 * \defgroup xQueueSendFromISR xQueueSendFromISR
1239 * \ingroup QueueManagement
1241 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1242 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1247 * BaseType_t xQueueGenericSendFromISR(
1248 * QueueHandle_t xQueue,
1249 * const void *pvItemToQueue,
1250 * BaseType_t *pxHigherPriorityTaskWoken,
1251 * BaseType_t xCopyPosition
1255 * It is preferred that the macros xQueueSendFromISR(),
1256 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1257 * of calling this function directly. xQueueGiveFromISR() is an
1258 * equivalent for use by semaphores that don't actually copy any data.
1260 * Post an item on a queue. It is safe to use this function from within an
1261 * interrupt service routine.
1263 * Items are queued by copy not reference so it is preferable to only
1264 * queue small items, especially when called from an ISR. In most cases
1265 * it would be preferable to store a pointer to the item being queued.
1267 * @param xQueue The handle to the queue on which the item is to be posted.
1269 * @param pvItemToQueue A pointer to the item that is to be placed on the
1270 * queue. The size of the items the queue will hold was defined when the
1271 * queue was created, so this many bytes will be copied from pvItemToQueue
1272 * into the queue storage area.
1274 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1275 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1276 * to unblock, and the unblocked task has a priority higher than the currently
1277 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
1278 * a context switch should be requested before the interrupt is exited.
1280 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1281 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1282 * at the front of the queue (for high priority messages).
1284 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1287 * Example usage for buffered IO (where the ISR can obtain more than one value
1290 * void vBufferISR( void )
1293 * BaseType_t xHigherPriorityTaskWokenByPost;
1295 * // We have not woken a task at the start of the ISR.
1296 * xHigherPriorityTaskWokenByPost = pdFALSE;
1298 * // Loop until the buffer is empty.
1301 * // Obtain a byte from the buffer.
1302 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1304 * // Post each byte.
1305 * xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1307 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1309 * // Now the buffer is empty we can switch context if necessary. Note that the
1310 * // name of the yield function required is port specific.
1311 * if( xHigherPriorityTaskWokenByPost )
1313 * portYIELD_FROM_ISR();
1318 * \defgroup xQueueSendFromISR xQueueSendFromISR
1319 * \ingroup QueueManagement
1321 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
1322 const void * const pvItemToQueue,
1323 BaseType_t * const pxHigherPriorityTaskWoken,
1324 const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1325 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
1326 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1331 * BaseType_t xQueueReceiveFromISR(
1332 * QueueHandle_t xQueue,
1334 * BaseType_t *pxTaskWoken
1338 * Receive an item from a queue. It is safe to use this function from within an
1339 * interrupt service routine.
1341 * @param xQueue The handle to the queue from which the item is to be
1344 * @param pvBuffer Pointer to the buffer into which the received item will
1347 * @param pxTaskWoken A task may be blocked waiting for space to become
1348 * available on the queue. If xQueueReceiveFromISR causes such a task to
1349 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
1352 * @return pdTRUE if an item was successfully received from the queue,
1353 * otherwise pdFALSE.
1358 * QueueHandle_t xQueue;
1360 * // Function to create a queue and post some values.
1361 * void vAFunction( void *pvParameters )
1363 * char cValueToPost;
1364 * const TickType_t xTicksToWait = ( TickType_t )0xff;
1366 * // Create a queue capable of containing 10 characters.
1367 * xQueue = xQueueCreate( 10, sizeof( char ) );
1370 * // Failed to create the queue.
1375 * // Post some characters that will be used within an ISR. If the queue
1376 * // is full then this task will block for xTicksToWait ticks.
1377 * cValueToPost = 'a';
1378 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1379 * cValueToPost = 'b';
1380 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1382 * // ... keep posting characters ... this task may block when the queue
1385 * cValueToPost = 'c';
1386 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1389 * // ISR that outputs all the characters received on the queue.
1390 * void vISR_Routine( void )
1392 * BaseType_t xTaskWokenByReceive = pdFALSE;
1395 * while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1397 * // A character was received. Output the character now.
1398 * vOutputCharacter( cRxedChar );
1400 * // If removing the character from the queue woke the task that was
1401 * // posting onto the queue cTaskWokenByReceive will have been set to
1402 * // pdTRUE. No matter how many times this loop iterates only one
1403 * // task will be woken.
1406 * if( cTaskWokenByPost != ( char ) pdFALSE;
1412 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
1413 * \ingroup QueueManagement
1415 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
1416 void * const pvBuffer,
1417 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1420 * Utilities to query queues that are safe to use from an ISR. These utilities
1421 * should be used only from witin an ISR, or within a critical section.
1423 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1424 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1425 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1428 * The functions defined above are for passing data to and from tasks. The
1429 * functions below are the equivalents for passing data to and from
1432 * These functions are called from the co-routine macro implementation and
1433 * should not be called directly from application code. Instead use the macro
1434 * wrappers defined within croutine.h.
1436 BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue,
1437 const void * pvItemToQueue,
1438 BaseType_t xCoRoutinePreviouslyWoken );
1439 BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue,
1441 BaseType_t * pxTaskWoken );
1442 BaseType_t xQueueCRSend( QueueHandle_t xQueue,
1443 const void * pvItemToQueue,
1444 TickType_t xTicksToWait );
1445 BaseType_t xQueueCRReceive( QueueHandle_t xQueue,
1447 TickType_t xTicksToWait );
1450 * For internal use only. Use xSemaphoreCreateMutex(),
1451 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1452 * these functions directly.
1454 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1455 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
1456 StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1457 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
1458 const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1459 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
1460 const UBaseType_t uxInitialCount,
1461 StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1462 BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
1463 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1464 TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1465 TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1468 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1469 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1471 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
1472 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1473 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
1476 * Reset a queue back to its original empty state. The return value is now
1477 * obsolete and is always set to pdPASS.
1479 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
1482 * The registry is provided as a means for kernel aware debuggers to
1483 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1484 * a queue, semaphore or mutex handle to the registry if you want the handle
1485 * to be available to a kernel aware debugger. If you are not using a kernel
1486 * aware debugger then this function can be ignored.
1488 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1489 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1490 * within FreeRTOSConfig.h for the registry to be available. Its value
1491 * does not effect the number of queues, semaphores and mutexes that can be
1492 * created - just the number that the registry can hold.
1494 * @param xQueue The handle of the queue being added to the registry. This
1495 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1496 * handles can also be passed in here.
1498 * @param pcName The name to be associated with the handle. This is the
1499 * name that the kernel aware debugger will display. The queue registry only
1500 * stores a pointer to the string - so the string must be persistent (global or
1501 * preferably in ROM/Flash), not on the stack.
1503 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1504 void vQueueAddToRegistry( QueueHandle_t xQueue,
1505 const char * pcQueueName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1509 * The registry is provided as a means for kernel aware debuggers to
1510 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1511 * a queue, semaphore or mutex handle to the registry if you want the handle
1512 * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1513 * remove the queue, semaphore or mutex from the register. If you are not using
1514 * a kernel aware debugger then this function can be ignored.
1516 * @param xQueue The handle of the queue being removed from the registry.
1518 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1519 void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1523 * The queue registry is provided as a means for kernel aware debuggers to
1524 * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
1525 * up and return the name of a queue in the queue registry from the queue's
1528 * @param xQueue The handle of the queue the name of which will be returned.
1529 * @return If the queue is in the registry then a pointer to the name of the
1530 * queue is returned. If the queue is not in the registry then NULL is
1533 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1534 const char * pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1538 * Generic version of the function used to creaet a queue using dynamic memory
1539 * allocation. This is called by other functions and macros that create other
1540 * RTOS objects that use the queue structure as their base.
1542 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1543 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
1544 const UBaseType_t uxItemSize,
1545 const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1549 * Generic version of the function used to creaet a queue using dynamic memory
1550 * allocation. This is called by other functions and macros that create other
1551 * RTOS objects that use the queue structure as their base.
1553 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1554 QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
1555 const UBaseType_t uxItemSize,
1556 uint8_t * pucQueueStorage,
1557 StaticQueue_t * pxStaticQueue,
1558 const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1562 * Queue sets provide a mechanism to allow a task to block (pend) on a read
1563 * operation from multiple queues or semaphores simultaneously.
1565 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1568 * A queue set must be explicitly created using a call to xQueueCreateSet()
1569 * before it can be used. Once created, standard FreeRTOS queues and semaphores
1570 * can be added to the set using calls to xQueueAddToSet().
1571 * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1572 * or semaphores contained in the set is in a state where a queue read or
1573 * semaphore take operation would be successful.
1575 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1576 * for reasons why queue sets are very rarely needed in practice as there are
1577 * simpler methods of blocking on multiple objects.
1579 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1580 * mutex holder to inherit the priority of the blocked task.
1582 * Note 3: An additional 4 bytes of RAM is required for each space in a every
1583 * queue added to a queue set. Therefore counting semaphores that have a high
1584 * maximum count value should not be added to a queue set.
1586 * Note 4: A receive (in the case of a queue) or take (in the case of a
1587 * semaphore) operation must not be performed on a member of a queue set unless
1588 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1590 * @param uxEventQueueLength Queue sets store events that occur on
1591 * the queues and semaphores contained in the set. uxEventQueueLength specifies
1592 * the maximum number of events that can be queued at once. To be absolutely
1593 * certain that events are not lost uxEventQueueLength should be set to the
1594 * total sum of the length of the queues added to the set, where binary
1595 * semaphores and mutexes have a length of 1, and counting semaphores have a
1596 * length set by their maximum count value. Examples:
1597 * + If a queue set is to hold a queue of length 5, another queue of length 12,
1598 * and a binary semaphore, then uxEventQueueLength should be set to
1599 * (5 + 12 + 1), or 18.
1600 * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1601 * should be set to (1 + 1 + 1 ), or 3.
1602 * + If a queue set is to hold a counting semaphore that has a maximum count of
1603 * 5, and a counting semaphore that has a maximum count of 3, then
1604 * uxEventQueueLength should be set to (5 + 3), or 8.
1606 * @return If the queue set is created successfully then a handle to the created
1607 * queue set is returned. Otherwise NULL is returned.
1609 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1612 * Adds a queue or semaphore to a queue set that was previously created by a
1613 * call to xQueueCreateSet().
1615 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1618 * Note 1: 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 xQueueOrSemaphore The handle of the queue or semaphore being added to
1623 * the queue set (cast to an QueueSetMemberHandle_t type).
1625 * @param xQueueSet The handle of the queue set to which the queue or semaphore
1628 * @return If the queue or semaphore was successfully added to the queue set
1629 * then pdPASS is returned. If the queue could not be successfully added to the
1630 * queue set because it is already a member of a different queue set then pdFAIL
1633 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1634 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1637 * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1638 * be removed from a set if the queue or semaphore is empty.
1640 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1643 * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1644 * from the queue set (cast to an QueueSetMemberHandle_t type).
1646 * @param xQueueSet The handle of the queue set in which the queue or semaphore
1649 * @return If the queue or semaphore was successfully removed from the queue set
1650 * then pdPASS is returned. If the queue was not in the queue set, or the
1651 * queue (or semaphore) was not empty, then pdFAIL is returned.
1653 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1654 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1657 * xQueueSelectFromSet() selects from the members of a queue set a queue or
1658 * semaphore that either contains data (in the case of a queue) or is available
1659 * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1660 * allows a task to block (pend) on a read operation on all the queues and
1661 * semaphores in a queue set simultaneously.
1663 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1666 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1667 * for reasons why queue sets are very rarely needed in practice as there are
1668 * simpler methods of blocking on multiple objects.
1670 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1671 * mutex holder to inherit the priority of the blocked task.
1673 * Note 3: A receive (in the case of a queue) or take (in the case of a
1674 * semaphore) operation must not be performed on a member of a queue set unless
1675 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1677 * @param xQueueSet The queue set on which the task will (potentially) block.
1679 * @param xTicksToWait The maximum time, in ticks, that the calling task will
1680 * remain in the Blocked state (with other tasks executing) to wait for a member
1681 * of the queue set to be ready for a successful queue read or semaphore take
1684 * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1685 * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1686 * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1687 * in the queue set that is available, or NULL if no such queue or semaphore
1688 * exists before before the specified block time expires.
1690 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
1691 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1694 * A version of xQueueSelectFromSet() that can be used from an ISR.
1696 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1698 /* Not public API functions. */
1699 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
1700 TickType_t xTicksToWait,
1701 const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1702 BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
1703 BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1704 void vQueueSetQueueNumber( QueueHandle_t xQueue,
1705 UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1706 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1707 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1716 #endif /* QUEUE_H */