2 * FreeRTOS Kernel V11.1.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
33 #ifndef INC_FREERTOS_H
34 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
46 * Type by which queues are referenced. For example, a call to xQueueCreate()
47 * returns an QueueHandle_t variable that can then be used as a parameter to
48 * xQueueSend(), xQueueReceive(), etc.
50 struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
51 typedef struct QueueDefinition * QueueHandle_t;
54 * Type by which queue sets are referenced. For example, a call to
55 * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
56 * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
58 typedef struct QueueDefinition * QueueSetHandle_t;
61 * Queue sets can contain both queues and semaphores, so the
62 * QueueSetMemberHandle_t is defined as a type to be used where a parameter or
63 * return value can be either an QueueHandle_t or an SemaphoreHandle_t.
65 typedef struct QueueDefinition * QueueSetMemberHandle_t;
67 /* For internal use only. */
68 #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
69 #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
70 #define queueOVERWRITE ( ( BaseType_t ) 2 )
72 /* For internal use only. These definitions *must* match those in queue.c. */
73 #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
74 #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
75 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
76 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
77 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
78 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
83 * QueueHandle_t xQueueCreate(
84 * UBaseType_t uxQueueLength,
85 * UBaseType_t uxItemSize
89 * Creates a new queue instance, and returns a handle by which the new queue
92 * Internally, within the FreeRTOS implementation, queues use two blocks of
93 * memory. The first block is used to hold the queue's data structures. The
94 * second block is used to hold items placed into the queue. If a queue is
95 * created using xQueueCreate() then both blocks of memory are automatically
96 * dynamically allocated inside the xQueueCreate() function. (see
97 * https://www.FreeRTOS.org/a00111.html). If a queue is created using
98 * xQueueCreateStatic() then the application writer must provide the memory that
99 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
100 * be created without using any dynamic memory allocation.
102 * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
104 * @param uxQueueLength The maximum number of items that the queue can contain.
106 * @param uxItemSize The number of bytes each item in the queue will require.
107 * Items are queued by copy, not by reference, so this is the number of bytes
108 * that will be copied for each posted item. Each item on the queue must be
111 * @return If the queue is successfully create then a handle to the newly
112 * created queue is returned. If the queue cannot be created then 0 is
123 * void vATask( void *pvParameters )
125 * QueueHandle_t xQueue1, xQueue2;
127 * // Create a queue capable of containing 10 uint32_t values.
128 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
131 * // Queue was not created and must not be used.
134 * // Create a queue capable of containing 10 pointers to AMessage structures.
135 * // These should be passed by pointer as they contain a lot of data.
136 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
139 * // Queue was not created and must not be used.
142 * // ... Rest of task code.
145 * \defgroup xQueueCreate xQueueCreate
146 * \ingroup QueueManagement
148 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
149 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
155 * QueueHandle_t xQueueCreateStatic(
156 * UBaseType_t uxQueueLength,
157 * UBaseType_t uxItemSize,
158 * uint8_t *pucQueueStorage,
159 * StaticQueue_t *pxQueueBuffer
163 * Creates a new queue instance, and returns a handle by which the new queue
166 * Internally, within the FreeRTOS implementation, queues use two blocks of
167 * memory. The first block is used to hold the queue's data structures. The
168 * second block is used to hold items placed into the queue. If a queue is
169 * created using xQueueCreate() then both blocks of memory are automatically
170 * dynamically allocated inside the xQueueCreate() function. (see
171 * https://www.FreeRTOS.org/a00111.html). If a queue is created using
172 * xQueueCreateStatic() then the application writer must provide the memory that
173 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
174 * be created without using any dynamic memory allocation.
176 * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
178 * @param uxQueueLength The maximum number of items that the queue can contain.
180 * @param uxItemSize The number of bytes each item in the queue will require.
181 * Items are queued by copy, not by reference, so this is the number of bytes
182 * that will be copied for each posted item. Each item on the queue must be
185 * @param pucQueueStorage If uxItemSize is not zero then
186 * pucQueueStorage must point to a uint8_t array that is at least large
187 * enough to hold the maximum number of items that can be in the queue at any
188 * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
189 * zero then pucQueueStorage can be NULL.
191 * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
192 * will be used to hold the queue's data structure.
194 * @return If the queue is created then a handle to the created queue is
195 * returned. If pxQueueBuffer is NULL then NULL is returned.
205 #define QUEUE_LENGTH 10
206 #define ITEM_SIZE sizeof( uint32_t )
208 * // xQueueBuffer will hold the queue structure.
209 * StaticQueue_t xQueueBuffer;
211 * // ucQueueStorage will hold the items posted to the queue. Must be at least
212 * // [(queue length) * ( queue item size)] bytes long.
213 * uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
215 * void vATask( void *pvParameters )
217 * QueueHandle_t xQueue1;
219 * // Create a queue capable of containing 10 uint32_t values.
220 * xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
221 * ITEM_SIZE // The size of each item in the queue
222 * &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
223 * &xQueueBuffer ); // The buffer that will hold the queue structure.
225 * // The queue is guaranteed to be created successfully as no dynamic memory
226 * // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
228 * // ... Rest of task code.
231 * \defgroup xQueueCreateStatic xQueueCreateStatic
232 * \ingroup QueueManagement
234 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
235 #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
236 #endif /* configSUPPORT_STATIC_ALLOCATION */
241 * BaseType_t xQueueGetStaticBuffers( QueueHandle_t xQueue,
242 * uint8_t ** ppucQueueStorage,
243 * StaticQueue_t ** ppxStaticQueue );
246 * Retrieve pointers to a statically created queue's data structure buffer
247 * and storage area buffer. These are the same buffers that are supplied
248 * at the time of creation.
250 * @param xQueue The queue for which to retrieve the buffers.
252 * @param ppucQueueStorage Used to return a pointer to the queue's storage
255 * @param ppxStaticQueue Used to return a pointer to the queue's data
258 * @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
260 * \defgroup xQueueGetStaticBuffers xQueueGetStaticBuffers
261 * \ingroup QueueManagement
263 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
264 #define xQueueGetStaticBuffers( xQueue, ppucQueueStorage, ppxStaticQueue ) xQueueGenericGetStaticBuffers( ( xQueue ), ( ppucQueueStorage ), ( ppxStaticQueue ) )
265 #endif /* configSUPPORT_STATIC_ALLOCATION */
270 * BaseType_t xQueueSendToFront(
271 * QueueHandle_t xQueue,
272 * const void *pvItemToQueue,
273 * TickType_t xTicksToWait
277 * Post an item to the front of a queue. The item is queued by copy, not by
278 * reference. This function must not be called from an interrupt service
279 * routine. See xQueueSendFromISR () for an alternative which may be used
282 * @param xQueue The handle to the queue on which the item is to be posted.
284 * @param pvItemToQueue A pointer to the item that is to be placed on the
285 * queue. The size of the items the queue will hold was defined when the
286 * queue was created, so this many bytes will be copied from pvItemToQueue
287 * into the queue storage area.
289 * @param xTicksToWait The maximum amount of time the task should block
290 * waiting for space to become available on the queue, should it already
291 * be full. The call will return immediately if this is set to 0 and the
292 * queue is full. The time is defined in tick periods so the constant
293 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
295 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
305 * uint32_t ulVar = 10U;
307 * void vATask( void *pvParameters )
309 * QueueHandle_t xQueue1, xQueue2;
310 * struct AMessage *pxMessage;
312 * // Create a queue capable of containing 10 uint32_t values.
313 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
315 * // Create a queue capable of containing 10 pointers to AMessage structures.
316 * // These should be passed by pointer as they contain a lot of data.
317 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
323 * // Send an uint32_t. Wait for 10 ticks for space to become
324 * // available if necessary.
325 * if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
327 * // Failed to post the message, even after 10 ticks.
333 * // Send a pointer to a struct AMessage object. Don't block if the
334 * // queue is already full.
335 * pxMessage = & xMessage;
336 * xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
339 * // ... Rest of task code.
342 * \defgroup xQueueSend xQueueSend
343 * \ingroup QueueManagement
345 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \
346 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
351 * BaseType_t xQueueSendToBack(
352 * QueueHandle_t xQueue,
353 * const void *pvItemToQueue,
354 * TickType_t xTicksToWait
358 * This is a macro that calls xQueueGenericSend().
360 * Post an item to the back of a queue. The item is queued by copy, not by
361 * reference. This function must not be called from an interrupt service
362 * routine. See xQueueSendFromISR () for an alternative which may be used
365 * @param xQueue The handle to the queue on which the item is to be posted.
367 * @param pvItemToQueue A pointer to the item that is to be placed on the
368 * queue. The size of the items the queue will hold was defined when the
369 * queue was created, so this many bytes will be copied from pvItemToQueue
370 * into the queue storage area.
372 * @param xTicksToWait The maximum amount of time the task should block
373 * waiting for space to become available on the queue, should it already
374 * be full. The call will return immediately if this is set to 0 and the queue
375 * is full. The time is defined in tick periods so the constant
376 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
378 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
388 * uint32_t ulVar = 10U;
390 * void vATask( void *pvParameters )
392 * QueueHandle_t xQueue1, xQueue2;
393 * struct AMessage *pxMessage;
395 * // Create a queue capable of containing 10 uint32_t values.
396 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
398 * // Create a queue capable of containing 10 pointers to AMessage structures.
399 * // These should be passed by pointer as they contain a lot of data.
400 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
406 * // Send an uint32_t. Wait for 10 ticks for space to become
407 * // available if necessary.
408 * if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
410 * // Failed to post the message, even after 10 ticks.
416 * // Send a pointer to a struct AMessage object. Don't block if the
417 * // queue is already full.
418 * pxMessage = & xMessage;
419 * xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
422 * // ... Rest of task code.
425 * \defgroup xQueueSend xQueueSend
426 * \ingroup QueueManagement
428 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
429 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
434 * BaseType_t xQueueSend(
435 * QueueHandle_t xQueue,
436 * const void * pvItemToQueue,
437 * TickType_t xTicksToWait
441 * This is a macro that calls xQueueGenericSend(). It is included for
442 * backward compatibility with versions of FreeRTOS.org that did not
443 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
444 * equivalent to xQueueSendToBack().
446 * Post an item on a queue. The item is queued by copy, not by reference.
447 * This function must not be called from an interrupt service routine.
448 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
450 * @param xQueue The handle to the queue on which the item is to be posted.
452 * @param pvItemToQueue A pointer to the item that is to be placed on the
453 * queue. The size of the items the queue will hold was defined when the
454 * queue was created, so this many bytes will be copied from pvItemToQueue
455 * into the queue storage area.
457 * @param xTicksToWait The maximum amount of time the task should block
458 * waiting for space to become available on the queue, should it already
459 * be full. The call will return immediately if this is set to 0 and the
460 * queue is full. The time is defined in tick periods so the constant
461 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
463 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
473 * uint32_t ulVar = 10U;
475 * void vATask( void *pvParameters )
477 * QueueHandle_t xQueue1, xQueue2;
478 * struct AMessage *pxMessage;
480 * // Create a queue capable of containing 10 uint32_t values.
481 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
483 * // Create a queue capable of containing 10 pointers to AMessage structures.
484 * // These should be passed by pointer as they contain a lot of data.
485 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
491 * // Send an uint32_t. Wait for 10 ticks for space to become
492 * // available if necessary.
493 * if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
495 * // Failed to post the message, even after 10 ticks.
501 * // Send a pointer to a struct AMessage object. Don't block if the
502 * // queue is already full.
503 * pxMessage = & xMessage;
504 * xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
507 * // ... Rest of task code.
510 * \defgroup xQueueSend xQueueSend
511 * \ingroup QueueManagement
513 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
514 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
519 * BaseType_t xQueueOverwrite(
520 * QueueHandle_t xQueue,
521 * const void * pvItemToQueue
525 * Only for use with queues that have a length of one - so the queue is either
528 * Post an item on a queue. If the queue is already full then overwrite the
529 * value held in the queue. The item is queued by copy, not by reference.
531 * This function must not be called from an interrupt service routine.
532 * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
534 * @param xQueue The handle of the queue to which the data is being sent.
536 * @param pvItemToQueue A pointer to the item that is to be placed on the
537 * queue. The size of the items the queue will hold was defined when the
538 * queue was created, so this many bytes will be copied from pvItemToQueue
539 * into the queue storage area.
541 * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
542 * therefore has the same return values as xQueueSendToFront(). However, pdPASS
543 * is the only value that can be returned because xQueueOverwrite() will write
544 * to the queue even when the queue is already full.
549 * void vFunction( void *pvParameters )
551 * QueueHandle_t xQueue;
552 * uint32_t ulVarToSend, ulValReceived;
554 * // Create a queue to hold one uint32_t value. It is strongly
555 * // recommended *not* to use xQueueOverwrite() on queues that can
556 * // contain more than one value, and doing so will trigger an assertion
557 * // if configASSERT() is defined.
558 * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
560 * // Write the value 10 to the queue using xQueueOverwrite().
562 * xQueueOverwrite( xQueue, &ulVarToSend );
564 * // Peeking the queue should now return 10, but leave the value 10 in
565 * // the queue. A block time of zero is used as it is known that the
566 * // queue holds a value.
568 * xQueuePeek( xQueue, &ulValReceived, 0 );
570 * if( ulValReceived != 10 )
572 * // Error unless the item was removed by a different task.
575 * // The queue is still full. Use xQueueOverwrite() to overwrite the
576 * // value held in the queue with 100.
578 * xQueueOverwrite( xQueue, &ulVarToSend );
580 * // This time read from the queue, leaving the queue empty once more.
581 * // A block time of 0 is used again.
582 * xQueueReceive( xQueue, &ulValReceived, 0 );
584 * // The value read should be the last value written, even though the
585 * // queue was already full when the value was written.
586 * if( ulValReceived != 100 )
594 * \defgroup xQueueOverwrite xQueueOverwrite
595 * \ingroup QueueManagement
597 #define xQueueOverwrite( xQueue, pvItemToQueue ) \
598 xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
604 * BaseType_t xQueueGenericSend(
605 * QueueHandle_t xQueue,
606 * const void * pvItemToQueue,
607 * TickType_t xTicksToWait
608 * BaseType_t xCopyPosition
612 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
613 * xQueueSendToBack() are used in place of calling this function directly.
615 * Post an item on a queue. The item is queued by copy, not by reference.
616 * This function must not be called from an interrupt service routine.
617 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
619 * @param xQueue The handle to the queue on which the item is to be posted.
621 * @param pvItemToQueue A pointer to the item that is to be placed on the
622 * queue. The size of the items the queue will hold was defined when the
623 * queue was created, so this many bytes will be copied from pvItemToQueue
624 * into the queue storage area.
626 * @param xTicksToWait The maximum amount of time the task should block
627 * waiting for space to become available on the queue, should it already
628 * be full. The call will return immediately if this is set to 0 and the
629 * queue is full. The time is defined in tick periods so the constant
630 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
632 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
633 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
634 * at the front of the queue (for high priority messages).
636 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
646 * uint32_t ulVar = 10U;
648 * void vATask( void *pvParameters )
650 * QueueHandle_t xQueue1, xQueue2;
651 * struct AMessage *pxMessage;
653 * // Create a queue capable of containing 10 uint32_t values.
654 * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
656 * // Create a queue capable of containing 10 pointers to AMessage structures.
657 * // These should be passed by pointer as they contain a lot of data.
658 * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
664 * // Send an uint32_t. Wait for 10 ticks for space to become
665 * // available if necessary.
666 * if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
668 * // Failed to post the message, even after 10 ticks.
674 * // Send a pointer to a struct AMessage object. Don't block if the
675 * // queue is already full.
676 * pxMessage = & xMessage;
677 * xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
680 * // ... Rest of task code.
683 * \defgroup xQueueSend xQueueSend
684 * \ingroup QueueManagement
686 BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
687 const void * const pvItemToQueue,
688 TickType_t xTicksToWait,
689 const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
694 * BaseType_t xQueuePeek(
695 * QueueHandle_t xQueue,
696 * void * const pvBuffer,
697 * TickType_t xTicksToWait
701 * Receive an item from a queue without removing the item from the queue.
702 * The item is received by copy so a buffer of adequate size must be
703 * provided. The number of bytes copied into the buffer was defined when
704 * the queue was created.
706 * Successfully received items remain on the queue so will be returned again
707 * by the next call, or a call to xQueueReceive().
709 * This macro must not be used in an interrupt service routine. See
710 * xQueuePeekFromISR() for an alternative that can be called from an interrupt
713 * @param xQueue The handle to the queue from which the item is to be
716 * @param pvBuffer Pointer to the buffer into which the received item will
719 * @param xTicksToWait The maximum amount of time the task should block
720 * waiting for an item to receive should the queue be empty at the time
721 * of the call. The time is defined in tick periods so the constant
722 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
723 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
726 * @return pdTRUE if an item was successfully received from the queue,
737 * QueueHandle_t xQueue;
739 * // Task to create a queue and post a value.
740 * void vATask( void *pvParameters )
742 * struct AMessage *pxMessage;
744 * // Create a queue capable of containing 10 pointers to AMessage structures.
745 * // These should be passed by pointer as they contain a lot of data.
746 * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
749 * // Failed to create the queue.
754 * // Send a pointer to a struct AMessage object. Don't block if the
755 * // queue is already full.
756 * pxMessage = & xMessage;
757 * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
759 * // ... Rest of task code.
762 * // Task to peek the data from the queue.
763 * void vADifferentTask( void *pvParameters )
765 * struct AMessage *pxRxedMessage;
769 * // Peek a message on the created queue. Block for 10 ticks if a
770 * // message is not immediately available.
771 * if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
773 * // pcRxedMessage now points to the struct AMessage variable posted
774 * // by vATask, but the item still remains on the queue.
778 * // ... Rest of task code.
781 * \defgroup xQueuePeek xQueuePeek
782 * \ingroup QueueManagement
784 BaseType_t xQueuePeek( QueueHandle_t xQueue,
785 void * const pvBuffer,
786 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
791 * BaseType_t xQueuePeekFromISR(
792 * QueueHandle_t xQueue,
797 * A version of xQueuePeek() that can be called from an interrupt service
800 * Receive an item from a queue without removing the item from the queue.
801 * The item is received by copy so a buffer of adequate size must be
802 * provided. The number of bytes copied into the buffer was defined when
803 * the queue was created.
805 * Successfully received items remain on the queue so will be returned again
806 * by the next call, or a call to xQueueReceive().
808 * @param xQueue The handle to the queue from which the item is to be
811 * @param pvBuffer Pointer to the buffer into which the received item will
814 * @return pdTRUE if an item was successfully received from the queue,
817 * \defgroup xQueuePeekFromISR xQueuePeekFromISR
818 * \ingroup QueueManagement
820 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
821 void * const pvBuffer ) PRIVILEGED_FUNCTION;
826 * BaseType_t xQueueReceive(
827 * QueueHandle_t xQueue,
829 * TickType_t xTicksToWait
833 * Receive an item from a queue. The item is received by copy so a buffer of
834 * adequate size must be provided. The number of bytes copied into the buffer
835 * was defined when the queue was created.
837 * Successfully received items are removed from the queue.
839 * This function must not be used in an interrupt service routine. See
840 * xQueueReceiveFromISR for an alternative that can.
842 * @param xQueue The handle to the queue from which the item is to be
845 * @param pvBuffer Pointer to the buffer into which the received item will
848 * @param xTicksToWait The maximum amount of time the task should block
849 * waiting for an item to receive should the queue be empty at the time
850 * of the call. xQueueReceive() will return immediately if xTicksToWait
851 * is zero and the queue is empty. The time is defined in tick periods so the
852 * constant portTICK_PERIOD_MS should be used to convert to real time if this is
855 * @return pdTRUE if an item was successfully received from the queue,
866 * QueueHandle_t xQueue;
868 * // Task to create a queue and post a value.
869 * void vATask( void *pvParameters )
871 * struct AMessage *pxMessage;
873 * // Create a queue capable of containing 10 pointers to AMessage structures.
874 * // These should be passed by pointer as they contain a lot of data.
875 * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
878 * // Failed to create the queue.
883 * // Send a pointer to a struct AMessage object. Don't block if the
884 * // queue is already full.
885 * pxMessage = & xMessage;
886 * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
888 * // ... Rest of task code.
891 * // Task to receive from the queue.
892 * void vADifferentTask( void *pvParameters )
894 * struct AMessage *pxRxedMessage;
898 * // Receive a message on the created queue. Block for 10 ticks if a
899 * // message is not immediately available.
900 * if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
902 * // pcRxedMessage now points to the struct AMessage variable posted
907 * // ... Rest of task code.
910 * \defgroup xQueueReceive xQueueReceive
911 * \ingroup QueueManagement
913 BaseType_t xQueueReceive( QueueHandle_t xQueue,
914 void * const pvBuffer,
915 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
920 * UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
923 * Return the number of messages stored in a queue.
925 * @param xQueue A handle to the queue being queried.
927 * @return The number of messages available in the queue.
929 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
930 * \ingroup QueueManagement
932 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
937 * UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
940 * Return the number of free spaces available in a queue. This is equal to the
941 * number of items that can be sent to the queue before the queue becomes full
942 * if no items are removed.
944 * @param xQueue A handle to the queue being queried.
946 * @return The number of spaces available in the queue.
948 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
949 * \ingroup QueueManagement
951 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
956 * void vQueueDelete( QueueHandle_t xQueue );
959 * Delete a queue - freeing all the memory allocated for storing of items
960 * placed on the queue.
962 * @param xQueue A handle to the queue to be deleted.
964 * \defgroup vQueueDelete vQueueDelete
965 * \ingroup QueueManagement
967 void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
972 * BaseType_t xQueueSendToFrontFromISR(
973 * QueueHandle_t xQueue,
974 * const void *pvItemToQueue,
975 * BaseType_t *pxHigherPriorityTaskWoken
979 * This is a macro that calls xQueueGenericSendFromISR().
981 * Post an item to the front of a queue. It is safe to use this macro from
982 * within an interrupt service routine.
984 * Items are queued by copy not reference so it is preferable to only
985 * queue small items, especially when called from an ISR. In most cases
986 * it would be preferable to store a pointer to the item being queued.
988 * @param xQueue The handle to the queue on which the item is to be posted.
990 * @param pvItemToQueue A pointer to the item that is to be placed on the
991 * queue. The size of the items the queue will hold was defined when the
992 * queue was created, so this many bytes will be copied from pvItemToQueue
993 * into the queue storage area.
995 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
996 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
997 * to unblock, and the unblocked task has a priority higher than the currently
998 * running task. If xQueueSendToFrontFromISR() sets this value to pdTRUE then
999 * a context switch should be requested before the interrupt is exited.
1001 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1004 * Example usage for buffered IO (where the ISR can obtain more than one value
1007 * void vBufferISR( void )
1010 * BaseType_t xHigherPriorityTaskWoken;
1012 * // We have not woken a task at the start of the ISR.
1013 * xHigherPriorityTaskWoken = pdFALSE;
1015 * // Loop until the buffer is empty.
1018 * // Obtain a byte from the buffer.
1019 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1022 * xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1024 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1026 * // Now the buffer is empty we can switch context if necessary.
1027 * if( xHigherPriorityTaskWoken )
1034 * \defgroup xQueueSendFromISR xQueueSendFromISR
1035 * \ingroup QueueManagement
1037 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1038 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
1044 * BaseType_t xQueueSendToBackFromISR(
1045 * QueueHandle_t xQueue,
1046 * const void *pvItemToQueue,
1047 * BaseType_t *pxHigherPriorityTaskWoken
1051 * This is a macro that calls xQueueGenericSendFromISR().
1053 * Post an item to the back of a queue. It is safe to use this macro from
1054 * within an interrupt service routine.
1056 * Items are queued by copy not reference so it is preferable to only
1057 * queue small items, especially when called from an ISR. In most cases
1058 * it would be preferable to store a pointer to the item being queued.
1060 * @param xQueue The handle to the queue on which the item is to be posted.
1062 * @param pvItemToQueue A pointer to the item that is to be placed on the
1063 * queue. The size of the items the queue will hold was defined when the
1064 * queue was created, so this many bytes will be copied from pvItemToQueue
1065 * into the queue storage area.
1067 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
1068 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1069 * to unblock, and the unblocked task has a priority higher than the currently
1070 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
1071 * a context switch should be requested before the interrupt is exited.
1073 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1076 * Example usage for buffered IO (where the ISR can obtain more than one value
1079 * void vBufferISR( void )
1082 * BaseType_t xHigherPriorityTaskWoken;
1084 * // We have not woken a task at the start of the ISR.
1085 * xHigherPriorityTaskWoken = pdFALSE;
1087 * // Loop until the buffer is empty.
1090 * // Obtain a byte from the buffer.
1091 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1094 * xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1096 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1098 * // Now the buffer is empty we can switch context if necessary.
1099 * if( xHigherPriorityTaskWoken )
1106 * \defgroup xQueueSendFromISR xQueueSendFromISR
1107 * \ingroup QueueManagement
1109 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1110 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1115 * BaseType_t xQueueOverwriteFromISR(
1116 * QueueHandle_t xQueue,
1117 * const void * pvItemToQueue,
1118 * BaseType_t *pxHigherPriorityTaskWoken
1122 * A version of xQueueOverwrite() that can be used in an interrupt service
1125 * Only for use with queues that can hold a single item - so the queue is either
1128 * Post an item on a queue. If the queue is already full then overwrite the
1129 * value held in the queue. The item is queued by copy, not by reference.
1131 * @param xQueue The handle to the queue on which the item is to be posted.
1133 * @param pvItemToQueue A pointer to the item that is to be placed on the
1134 * queue. The size of the items the queue will hold was defined when the
1135 * queue was created, so this many bytes will be copied from pvItemToQueue
1136 * into the queue storage area.
1138 * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
1139 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1140 * to unblock, and the unblocked task has a priority higher than the currently
1141 * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
1142 * a context switch should be requested before the interrupt is exited.
1144 * @return xQueueOverwriteFromISR() is a macro that calls
1145 * xQueueGenericSendFromISR(), and therefore has the same return values as
1146 * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
1147 * returned because xQueueOverwriteFromISR() will write to the queue even when
1148 * the queue is already full.
1153 * QueueHandle_t xQueue;
1155 * void vFunction( void *pvParameters )
1157 * // Create a queue to hold one uint32_t value. It is strongly
1158 * // recommended *not* to use xQueueOverwriteFromISR() on queues that can
1159 * // contain more than one value, and doing so will trigger an assertion
1160 * // if configASSERT() is defined.
1161 * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
1164 * void vAnInterruptHandler( void )
1166 * // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
1167 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
1168 * uint32_t ulVarToSend, ulValReceived;
1170 * // Write the value 10 to the queue using xQueueOverwriteFromISR().
1172 * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1174 * // The queue is full, but calling xQueueOverwriteFromISR() again will still
1175 * // pass because the value held in the queue will be overwritten with the
1177 * ulVarToSend = 100;
1178 * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1180 * // Reading from the queue will now return 100.
1184 * if( xHigherPrioritytaskWoken == pdTRUE )
1186 * // Writing to the queue caused a task to unblock and the unblocked task
1187 * // has a priority higher than or equal to the priority of the currently
1188 * // executing task (the task this interrupt interrupted). Perform a context
1189 * // switch so this interrupt returns directly to the unblocked task.
1190 * // The macro used is port specific and will be either
1191 * // portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to the documentation
1192 * // page for the port being used.
1193 * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
1197 * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
1198 * \ingroup QueueManagement
1200 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1201 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1206 * BaseType_t xQueueSendFromISR(
1207 * QueueHandle_t xQueue,
1208 * const void *pvItemToQueue,
1209 * BaseType_t *pxHigherPriorityTaskWoken
1213 * This is a macro that calls xQueueGenericSendFromISR(). It is included
1214 * for backward compatibility with versions of FreeRTOS.org that did not
1215 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
1218 * Post an item to the back of a queue. It is safe to use this function from
1219 * within an interrupt service routine.
1221 * Items are queued by copy not reference so it is preferable to only
1222 * queue small items, especially when called from an ISR. In most cases
1223 * it would be preferable to store a pointer to the item being queued.
1225 * @param xQueue The handle to the queue on which the item is to be posted.
1227 * @param pvItemToQueue A pointer to the item that is to be placed on the
1228 * queue. The size of the items the queue will hold was defined when the
1229 * queue was created, so this many bytes will be copied from pvItemToQueue
1230 * into the queue storage area.
1232 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
1233 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1234 * to unblock, and the unblocked task has a priority higher than the currently
1235 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
1236 * a context switch should be requested before the interrupt is exited.
1238 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1241 * Example usage for buffered IO (where the ISR can obtain more than one value
1244 * void vBufferISR( void )
1247 * BaseType_t xHigherPriorityTaskWoken;
1249 * // We have not woken a task at the start of the ISR.
1250 * xHigherPriorityTaskWoken = pdFALSE;
1252 * // Loop until the buffer is empty.
1255 * // Obtain a byte from the buffer.
1256 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1259 * xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1261 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1263 * // Now the buffer is empty we can switch context if necessary.
1264 * if( xHigherPriorityTaskWoken )
1266 * // As xHigherPriorityTaskWoken is now set to pdTRUE then a context
1267 * // switch should be requested. The macro used is port specific and
1268 * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
1269 * // refer to the documentation page for the port being used.
1270 * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
1275 * \defgroup xQueueSendFromISR xQueueSendFromISR
1276 * \ingroup QueueManagement
1278 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
1279 xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1284 * BaseType_t xQueueGenericSendFromISR(
1285 * QueueHandle_t xQueue,
1286 * const void *pvItemToQueue,
1287 * BaseType_t *pxHigherPriorityTaskWoken,
1288 * BaseType_t xCopyPosition
1292 * It is preferred that the macros xQueueSendFromISR(),
1293 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1294 * of calling this function directly. xQueueGiveFromISR() is an
1295 * equivalent for use by semaphores that don't actually copy any data.
1297 * Post an item on a queue. It is safe to use this function from within an
1298 * interrupt service routine.
1300 * Items are queued by copy not reference so it is preferable to only
1301 * queue small items, especially when called from an ISR. In most cases
1302 * it would be preferable to store a pointer to the item being queued.
1304 * @param xQueue The handle to the queue on which the item is to be posted.
1306 * @param pvItemToQueue A pointer to the item that is to be placed on the
1307 * queue. The size of the items the queue will hold was defined when the
1308 * queue was created, so this many bytes will be copied from pvItemToQueue
1309 * into the queue storage area.
1311 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1312 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1313 * to unblock, and the unblocked task has a priority higher than the currently
1314 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
1315 * a context switch should be requested before the interrupt is exited.
1317 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1318 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1319 * at the front of the queue (for high priority messages).
1321 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1324 * Example usage for buffered IO (where the ISR can obtain more than one value
1327 * void vBufferISR( void )
1330 * BaseType_t xHigherPriorityTaskWokenByPost;
1332 * // We have not woken a task at the start of the ISR.
1333 * xHigherPriorityTaskWokenByPost = pdFALSE;
1335 * // Loop until the buffer is empty.
1338 * // Obtain a byte from the buffer.
1339 * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1341 * // Post each byte.
1342 * xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1344 * } while( portINPUT_BYTE( BUFFER_COUNT ) );
1346 * // Now the buffer is empty we can switch context if necessary.
1347 * if( xHigherPriorityTaskWokenByPost )
1349 * // As xHigherPriorityTaskWokenByPost is now set to pdTRUE then a context
1350 * // switch should be requested. The macro used is port specific and
1351 * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
1352 * // refer to the documentation page for the port being used.
1353 * portYIELD_FROM_ISR( xHigherPriorityTaskWokenByPost );
1358 * \defgroup xQueueSendFromISR xQueueSendFromISR
1359 * \ingroup QueueManagement
1361 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
1362 const void * const pvItemToQueue,
1363 BaseType_t * const pxHigherPriorityTaskWoken,
1364 const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1365 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
1366 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1371 * BaseType_t xQueueReceiveFromISR(
1372 * QueueHandle_t xQueue,
1374 * BaseType_t *pxTaskWoken
1378 * Receive an item from a queue. It is safe to use this function from within an
1379 * interrupt service routine.
1381 * @param xQueue The handle to the queue from which the item is to be
1384 * @param pvBuffer Pointer to the buffer into which the received item will
1387 * @param pxHigherPriorityTaskWoken A task may be blocked waiting for space to
1388 * become available on the queue. If xQueueReceiveFromISR causes such a task
1389 * to unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
1392 * @return pdTRUE if an item was successfully received from the queue,
1393 * otherwise pdFALSE.
1398 * QueueHandle_t xQueue;
1400 * // Function to create a queue and post some values.
1401 * void vAFunction( void *pvParameters )
1403 * char cValueToPost;
1404 * const TickType_t xTicksToWait = ( TickType_t )0xff;
1406 * // Create a queue capable of containing 10 characters.
1407 * xQueue = xQueueCreate( 10, sizeof( char ) );
1410 * // Failed to create the queue.
1415 * // Post some characters that will be used within an ISR. If the queue
1416 * // is full then this task will block for xTicksToWait ticks.
1417 * cValueToPost = 'a';
1418 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1419 * cValueToPost = 'b';
1420 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1422 * // ... keep posting characters ... this task may block when the queue
1425 * cValueToPost = 'c';
1426 * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1429 * // ISR that outputs all the characters received on the queue.
1430 * void vISR_Routine( void )
1432 * BaseType_t xTaskWokenByReceive = pdFALSE;
1435 * while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1437 * // A character was received. Output the character now.
1438 * vOutputCharacter( cRxedChar );
1440 * // If removing the character from the queue woke the task that was
1441 * // posting onto the queue xTaskWokenByReceive will have been set to
1442 * // pdTRUE. No matter how many times this loop iterates only one
1443 * // task will be woken.
1446 * if( xTaskWokenByReceive != ( char ) pdFALSE;
1452 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
1453 * \ingroup QueueManagement
1455 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
1456 void * const pvBuffer,
1457 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1460 * Utilities to query queues that are safe to use from an ISR. These utilities
1461 * should be used only from within an ISR, or within a critical section.
1463 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1464 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1465 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1467 #if ( configUSE_CO_ROUTINES == 1 )
1470 * The functions defined above are for passing data to and from tasks. The
1471 * functions below are the equivalents for passing data to and from
1474 * These functions are called from the co-routine macro implementation and
1475 * should not be called directly from application code. Instead use the macro
1476 * wrappers defined within croutine.h.
1478 BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue,
1479 const void * pvItemToQueue,
1480 BaseType_t xCoRoutinePreviouslyWoken );
1481 BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue,
1483 BaseType_t * pxTaskWoken );
1484 BaseType_t xQueueCRSend( QueueHandle_t xQueue,
1485 const void * pvItemToQueue,
1486 TickType_t xTicksToWait );
1487 BaseType_t xQueueCRReceive( QueueHandle_t xQueue,
1489 TickType_t xTicksToWait );
1491 #endif /* if ( configUSE_CO_ROUTINES == 1 ) */
1494 * For internal use only. Use xSemaphoreCreateMutex(),
1495 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1496 * these functions directly.
1498 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1500 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1501 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
1502 StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1505 #if ( configUSE_COUNTING_SEMAPHORES == 1 )
1506 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
1507 const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1510 #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
1511 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
1512 const UBaseType_t uxInitialCount,
1513 StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1516 BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
1517 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1519 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
1520 TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1521 TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1525 * For internal use only. Use xSemaphoreTakeRecursive() or
1526 * xSemaphoreGiveRecursive() instead of calling these functions directly.
1528 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
1529 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1530 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
1533 * Reset a queue back to its original empty state. The return value is now
1534 * obsolete and is always set to pdPASS.
1536 #define xQueueReset( xQueue ) xQueueGenericReset( ( xQueue ), pdFALSE )
1539 * The registry is provided as a means for kernel aware debuggers to
1540 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1541 * a queue, semaphore or mutex handle to the registry if you want the handle
1542 * to be available to a kernel aware debugger. If you are not using a kernel
1543 * aware debugger then this function can be ignored.
1545 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1546 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1547 * within FreeRTOSConfig.h for the registry to be available. Its value
1548 * does not affect the number of queues, semaphores and mutexes that can be
1549 * created - just the number that the registry can hold.
1551 * If vQueueAddToRegistry is called more than once with the same xQueue
1552 * parameter, the registry will store the pcQueueName parameter from the
1553 * most recent call to vQueueAddToRegistry.
1555 * @param xQueue The handle of the queue being added to the registry. This
1556 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1557 * handles can also be passed in here.
1559 * @param pcQueueName The name to be associated with the handle. This is the
1560 * name that the kernel aware debugger will display. The queue registry only
1561 * stores a pointer to the string - so the string must be persistent (global or
1562 * preferably in ROM/Flash), not on the stack.
1564 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1565 void vQueueAddToRegistry( QueueHandle_t xQueue,
1566 const char * pcQueueName ) PRIVILEGED_FUNCTION;
1570 * The registry is provided as a means for kernel aware debuggers to
1571 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1572 * a queue, semaphore or mutex handle to the registry if you want the handle
1573 * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1574 * remove the queue, semaphore or mutex from the register. If you are not using
1575 * a kernel aware debugger then this function can be ignored.
1577 * @param xQueue The handle of the queue being removed from the registry.
1579 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1580 void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1584 * The queue registry is provided as a means for kernel aware debuggers to
1585 * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
1586 * up and return the name of a queue in the queue registry from the queue's
1589 * @param xQueue The handle of the queue the name of which will be returned.
1590 * @return If the queue is in the registry then a pointer to the name of the
1591 * queue is returned. If the queue is not in the registry then NULL is
1594 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1595 const char * pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1599 * Generic version of the function used to create a queue using dynamic memory
1600 * allocation. This is called by other functions and macros that create other
1601 * RTOS objects that use the queue structure as their base.
1603 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1604 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
1605 const UBaseType_t uxItemSize,
1606 const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1610 * Generic version of the function used to create a queue using dynamic memory
1611 * allocation. This is called by other functions and macros that create other
1612 * RTOS objects that use the queue structure as their base.
1614 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1615 QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
1616 const UBaseType_t uxItemSize,
1617 uint8_t * pucQueueStorage,
1618 StaticQueue_t * pxStaticQueue,
1619 const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1623 * Generic version of the function used to retrieve the buffers of statically
1624 * created queues. This is called by other functions and macros that retrieve
1625 * the buffers of other statically created RTOS objects that use the queue
1626 * structure as their base.
1628 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1629 BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
1630 uint8_t ** ppucQueueStorage,
1631 StaticQueue_t ** ppxStaticQueue ) PRIVILEGED_FUNCTION;
1635 * Queue sets provide a mechanism to allow a task to block (pend) on a read
1636 * operation from multiple queues or semaphores simultaneously.
1638 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1641 * A queue set must be explicitly created using a call to xQueueCreateSet()
1642 * before it can be used. Once created, standard FreeRTOS queues and semaphores
1643 * can be added to the set using calls to xQueueAddToSet().
1644 * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1645 * or semaphores contained in the set is in a state where a queue read or
1646 * semaphore take operation would be successful.
1648 * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
1649 * for reasons why queue sets are very rarely needed in practice as there are
1650 * simpler methods of blocking on multiple objects.
1652 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1653 * mutex holder to inherit the priority of the blocked task.
1655 * Note 3: An additional 4 bytes of RAM is required for each space in a every
1656 * queue added to a queue set. Therefore counting semaphores that have a high
1657 * maximum count value should not be added to a queue set.
1659 * Note 4: A receive (in the case of a queue) or take (in the case of a
1660 * semaphore) operation must not be performed on a member of a queue set unless
1661 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1663 * @param uxEventQueueLength Queue sets store events that occur on
1664 * the queues and semaphores contained in the set. uxEventQueueLength specifies
1665 * the maximum number of events that can be queued at once. To be absolutely
1666 * certain that events are not lost uxEventQueueLength should be set to the
1667 * total sum of the length of the queues added to the set, where binary
1668 * semaphores and mutexes have a length of 1, and counting semaphores have a
1669 * length set by their maximum count value. Examples:
1670 * + If a queue set is to hold a queue of length 5, another queue of length 12,
1671 * and a binary semaphore, then uxEventQueueLength should be set to
1672 * (5 + 12 + 1), or 18.
1673 * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1674 * should be set to (1 + 1 + 1 ), or 3.
1675 * + If a queue set is to hold a counting semaphore that has a maximum count of
1676 * 5, and a counting semaphore that has a maximum count of 3, then
1677 * uxEventQueueLength should be set to (5 + 3), or 8.
1679 * @return If the queue set is created successfully then a handle to the created
1680 * queue set is returned. Otherwise NULL is returned.
1682 #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
1683 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1687 * Adds a queue or semaphore to a queue set that was previously created by a
1688 * call to xQueueCreateSet().
1690 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1693 * Note 1: A receive (in the case of a queue) or take (in the case of a
1694 * semaphore) operation must not be performed on a member of a queue set unless
1695 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1697 * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1698 * the queue set (cast to an QueueSetMemberHandle_t type).
1700 * @param xQueueSet The handle of the queue set to which the queue or semaphore
1703 * @return If the queue or semaphore was successfully added to the queue set
1704 * then pdPASS is returned. If the queue could not be successfully added to the
1705 * queue set because it is already a member of a different queue set then pdFAIL
1708 #if ( configUSE_QUEUE_SETS == 1 )
1709 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1710 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1714 * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1715 * be removed from a set if the queue or semaphore is empty.
1717 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1720 * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1721 * from the queue set (cast to an QueueSetMemberHandle_t type).
1723 * @param xQueueSet The handle of the queue set in which the queue or semaphore
1726 * @return If the queue or semaphore was successfully removed from the queue set
1727 * then pdPASS is returned. If the queue was not in the queue set, or the
1728 * queue (or semaphore) was not empty, then pdFAIL is returned.
1730 #if ( configUSE_QUEUE_SETS == 1 )
1731 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1732 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1736 * xQueueSelectFromSet() selects from the members of a queue set a queue or
1737 * semaphore that either contains data (in the case of a queue) or is available
1738 * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1739 * allows a task to block (pend) on a read operation on all the queues and
1740 * semaphores in a queue set simultaneously.
1742 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1745 * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
1746 * for reasons why queue sets are very rarely needed in practice as there are
1747 * simpler methods of blocking on multiple objects.
1749 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1750 * mutex holder to inherit the priority of the blocked task.
1752 * Note 3: A receive (in the case of a queue) or take (in the case of a
1753 * semaphore) operation must not be performed on a member of a queue set unless
1754 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1756 * @param xQueueSet The queue set on which the task will (potentially) block.
1758 * @param xTicksToWait The maximum time, in ticks, that the calling task will
1759 * remain in the Blocked state (with other tasks executing) to wait for a member
1760 * of the queue set to be ready for a successful queue read or semaphore take
1763 * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1764 * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1765 * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1766 * in the queue set that is available, or NULL if no such queue or semaphore
1767 * exists before before the specified block time expires.
1769 #if ( configUSE_QUEUE_SETS == 1 )
1770 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
1771 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1775 * A version of xQueueSelectFromSet() that can be used from an ISR.
1777 #if ( configUSE_QUEUE_SETS == 1 )
1778 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1781 /* Not public API functions. */
1782 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
1783 TickType_t xTicksToWait,
1784 const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1785 BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
1786 BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1788 #if ( configUSE_TRACE_FACILITY == 1 )
1789 void vQueueSetQueueNumber( QueueHandle_t xQueue,
1790 UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1793 #if ( configUSE_TRACE_FACILITY == 1 )
1794 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1797 #if ( configUSE_TRACE_FACILITY == 1 )
1798 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1801 UBaseType_t uxQueueGetQueueItemSize( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1802 UBaseType_t uxQueueGetQueueLength( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1810 #endif /* QUEUE_H */