2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
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
32 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
33 * all the API functions to use the MPU wrappers. That should only be done when
34 * task.h is included from an application file. */
35 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
41 /* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
42 * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
43 * for the header files above, but not in this file, in order to generate the
44 * correct privileged Vs unprivileged linkage and placement. */
45 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */
48 /* Constants used with the cRxLock and cTxLock structure members. */
49 #define queueUNLOCKED ( ( int8_t ) -1 )
50 #define queueLOCKED_UNMODIFIED ( ( int8_t ) 0 )
51 #define queueINT8_MAX ( ( int8_t ) 127 )
53 /* When the Queue_t structure is used to represent a base queue its pcHead and
54 * pcTail members are used as pointers into the queue storage area. When the
55 * Queue_t structure is used to represent a mutex pcHead and pcTail pointers are
56 * not necessary, and the pcHead pointer is set to NULL to indicate that the
57 * structure instead holds a pointer to the mutex holder (if any). Map alternative
58 * names to the pcHead and structure member to ensure the readability of the code
59 * is maintained. The QueuePointers_t and SemaphoreData_t types are used to form
60 * a union as their usage is mutually exclusive dependent on what the queue is
62 #define uxQueueType pcHead
63 #define queueQUEUE_IS_MUTEX NULL
65 typedef struct QueuePointers
67 int8_t * pcTail; /*< Points to the byte at the end of the queue storage area. Once more byte is allocated than necessary to store the queue items, this is used as a marker. */
68 int8_t * pcReadFrom; /*< Points to the last place that a queued item was read from when the structure is used as a queue. */
71 typedef struct SemaphoreData
73 TaskHandle_t xMutexHolder; /*< The handle of the task that holds the mutex. */
74 UBaseType_t uxRecursiveCallCount; /*< Maintains a count of the number of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */
77 /* Semaphores do not actually store or copy data, so have an item size of
79 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( UBaseType_t ) 0 )
80 #define queueMUTEX_GIVE_BLOCK_TIME ( ( TickType_t ) 0U )
82 #if ( configUSE_PREEMPTION == 0 )
84 /* If the cooperative scheduler is being used then a yield should not be
85 * performed just because a higher priority task has been woken. */
86 #define queueYIELD_IF_USING_PREEMPTION()
88 #define queueYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()
92 * Definition of the queue used by the scheduler.
93 * Items are queued by copy, not reference. See the following link for the
94 * rationale: https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
96 typedef struct QueueDefinition /* The old naming convention is used to prevent breaking kernel aware debuggers. */
98 int8_t * pcHead; /*< Points to the beginning of the queue storage area. */
99 int8_t * pcWriteTo; /*< Points to the free next place in the storage area. */
103 QueuePointers_t xQueue; /*< Data required exclusively when this structure is used as a queue. */
104 SemaphoreData_t xSemaphore; /*< Data required exclusively when this structure is used as a semaphore. */
107 List_t xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */
108 List_t xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */
110 volatile UBaseType_t uxMessagesWaiting; /*< The number of items currently in the queue. */
111 UBaseType_t uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */
112 UBaseType_t uxItemSize; /*< The size of each items that the queue will hold. */
114 volatile int8_t cRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
115 volatile int8_t cTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
117 #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
118 uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the memory used by the queue was statically allocated to ensure no attempt is made to free the memory. */
121 #if ( configUSE_QUEUE_SETS == 1 )
122 struct QueueDefinition * pxQueueSetContainer;
125 #if ( configUSE_TRACE_FACILITY == 1 )
126 UBaseType_t uxQueueNumber;
131 /* The old xQUEUE name is maintained above then typedefed to the new Queue_t
132 * name below to enable the use of older kernel aware debuggers. */
133 typedef xQUEUE Queue_t;
135 /*-----------------------------------------------------------*/
138 * The queue registry is just a means for kernel aware debuggers to locate
139 * queue structures. It has no other purpose so is an optional component.
141 #if ( configQUEUE_REGISTRY_SIZE > 0 )
143 /* The type stored within the queue registry array. This allows a name
144 * to be assigned to each queue making kernel aware debugging a little
145 * more user friendly. */
146 typedef struct QUEUE_REGISTRY_ITEM
148 const char * pcQueueName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
149 QueueHandle_t xHandle;
150 } xQueueRegistryItem;
152 /* The old xQueueRegistryItem name is maintained above then typedefed to the
153 * new xQueueRegistryItem name below to enable the use of older kernel aware
155 typedef xQueueRegistryItem QueueRegistryItem_t;
157 /* The queue registry is simply an array of QueueRegistryItem_t structures.
158 * The pcQueueName member of a structure being NULL is indicative of the
159 * array position being vacant. */
160 PRIVILEGED_DATA QueueRegistryItem_t xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];
162 #endif /* configQUEUE_REGISTRY_SIZE */
165 * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not
166 * prevent an ISR from adding or removing items to the queue, but does prevent
167 * an ISR from removing tasks from the queue event lists. If an ISR finds a
168 * queue is locked it will instead increment the appropriate queue lock count
169 * to indicate that a task may require unblocking. When the queue in unlocked
170 * these lock counts are inspected, and the appropriate action taken.
172 static void prvUnlockQueue( Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
175 * Uses a critical section to determine if there is any data in a queue.
177 * @return pdTRUE if the queue contains no items, otherwise pdFALSE.
179 static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue ) PRIVILEGED_FUNCTION;
182 * Uses a critical section to determine if there is any space in a queue.
184 * @return pdTRUE if there is no space, otherwise pdFALSE;
186 static BaseType_t prvIsQueueFull( const Queue_t * pxQueue ) PRIVILEGED_FUNCTION;
189 * Copies an item into the queue, either at the front of the queue or the
192 static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
193 const void * pvItemToQueue,
194 const BaseType_t xPosition ) PRIVILEGED_FUNCTION;
197 * Copies an item out of a queue.
199 static void prvCopyDataFromQueue( Queue_t * const pxQueue,
200 void * const pvBuffer ) PRIVILEGED_FUNCTION;
202 #if ( configUSE_QUEUE_SETS == 1 )
205 * Checks to see if a queue is a member of a queue set, and if so, notifies
206 * the queue set that the queue contains data.
208 static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
212 * Called after a Queue_t structure has been allocated either statically or
213 * dynamically to fill in the structure's members.
215 static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
216 const UBaseType_t uxItemSize,
217 uint8_t * pucQueueStorage,
218 const uint8_t ucQueueType,
219 Queue_t * pxNewQueue ) PRIVILEGED_FUNCTION;
222 * Mutexes are a special type of queue. When a mutex is created, first the
223 * queue is created, then prvInitialiseMutex() is called to configure the queue
226 #if ( configUSE_MUTEXES == 1 )
227 static void prvInitialiseMutex( Queue_t * pxNewQueue ) PRIVILEGED_FUNCTION;
230 #if ( configUSE_MUTEXES == 1 )
233 * If a task waiting for a mutex causes the mutex holder to inherit a
234 * priority, but the waiting task times out, then the holder should
235 * disinherit the priority - but only down to the highest priority of any
236 * other tasks that are waiting for the same mutex. This function returns
239 static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
241 /*-----------------------------------------------------------*/
244 * Macro to mark a queue as locked. Locking a queue prevents an ISR from
245 * accessing the queue event lists.
247 #define prvLockQueue( pxQueue ) \
248 taskENTER_CRITICAL(); \
250 if( ( pxQueue )->cRxLock == queueUNLOCKED ) \
252 ( pxQueue )->cRxLock = queueLOCKED_UNMODIFIED; \
254 if( ( pxQueue )->cTxLock == queueUNLOCKED ) \
256 ( pxQueue )->cTxLock = queueLOCKED_UNMODIFIED; \
262 * Macro to increment cTxLock member of the queue data structure. It is
263 * capped at the number of tasks in the system as we cannot unblock more
264 * tasks than the number of tasks in the system.
266 #define prvIncrementQueueTxLock( pxQueue, cTxLock ) \
268 const UBaseType_t uxNumberOfTasks = uxTaskGetNumberOfTasks(); \
269 if( ( UBaseType_t ) ( cTxLock ) < uxNumberOfTasks ) \
271 configASSERT( ( cTxLock ) != queueINT8_MAX ); \
272 ( pxQueue )->cTxLock = ( int8_t ) ( ( cTxLock ) + ( int8_t ) 1 ); \
277 * Macro to increment cRxLock member of the queue data structure. It is
278 * capped at the number of tasks in the system as we cannot unblock more
279 * tasks than the number of tasks in the system.
281 #define prvIncrementQueueRxLock( pxQueue, cRxLock ) \
283 const UBaseType_t uxNumberOfTasks = uxTaskGetNumberOfTasks(); \
284 if( ( UBaseType_t ) ( cRxLock ) < uxNumberOfTasks ) \
286 configASSERT( ( cRxLock ) != queueINT8_MAX ); \
287 ( pxQueue )->cRxLock = ( int8_t ) ( ( cRxLock ) + ( int8_t ) 1 ); \
290 /*-----------------------------------------------------------*/
292 BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
293 BaseType_t xNewQueue )
295 BaseType_t xReturn = pdPASS;
296 Queue_t * const pxQueue = xQueue;
298 configASSERT( pxQueue );
300 if( ( pxQueue != NULL ) &&
301 ( pxQueue->uxLength >= 1U ) &&
302 /* Check for multiplication overflow. */
303 ( ( SIZE_MAX / pxQueue->uxLength ) >= pxQueue->uxItemSize ) )
305 taskENTER_CRITICAL();
307 pxQueue->u.xQueue.pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */
308 pxQueue->uxMessagesWaiting = ( UBaseType_t ) 0U;
309 pxQueue->pcWriteTo = pxQueue->pcHead;
310 pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - 1U ) * pxQueue->uxItemSize ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */
311 pxQueue->cRxLock = queueUNLOCKED;
312 pxQueue->cTxLock = queueUNLOCKED;
314 if( xNewQueue == pdFALSE )
316 /* If there are tasks blocked waiting to read from the queue, then
317 * the tasks will remain blocked as after this function exits the queue
318 * will still be empty. If there are tasks blocked waiting to write to
319 * the queue, then one should be unblocked as after this function exits
320 * it will be possible to write to it. */
321 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
323 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
325 queueYIELD_IF_USING_PREEMPTION();
329 mtCOVERAGE_TEST_MARKER();
334 mtCOVERAGE_TEST_MARKER();
339 /* Ensure the event queues start in the correct state. */
340 vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
341 vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
351 configASSERT( xReturn != pdFAIL );
353 /* A value is returned for calling semantic consistency with previous
357 /*-----------------------------------------------------------*/
359 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
361 QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
362 const UBaseType_t uxItemSize,
363 uint8_t * pucQueueStorage,
364 StaticQueue_t * pxStaticQueue,
365 const uint8_t ucQueueType )
367 Queue_t * pxNewQueue = NULL;
369 /* The StaticQueue_t structure and the queue storage area must be
371 configASSERT( pxStaticQueue );
373 if( ( uxQueueLength > ( UBaseType_t ) 0 ) &&
374 ( pxStaticQueue != NULL ) &&
376 /* A queue storage area should be provided if the item size is not 0, and
377 * should not be provided if the item size is 0. */
378 ( !( ( pucQueueStorage != NULL ) && ( uxItemSize == 0 ) ) ) &&
379 ( !( ( pucQueueStorage == NULL ) && ( uxItemSize != 0 ) ) ) )
381 #if ( configASSERT_DEFINED == 1 )
383 /* Sanity check that the size of the structure used to declare a
384 * variable of type StaticQueue_t or StaticSemaphore_t equals the size of
385 * the real queue and semaphore structures. */
386 volatile size_t xSize = sizeof( StaticQueue_t );
388 /* This assertion cannot be branch covered in unit tests */
389 configASSERT( xSize == sizeof( Queue_t ) ); /* LCOV_EXCL_BR_LINE */
390 ( void ) xSize; /* Keeps lint quiet when configASSERT() is not defined. */
392 #endif /* configASSERT_DEFINED */
394 /* The address of a statically allocated queue was passed in, use it.
395 * The address of a statically allocated storage area was also passed in
396 * but is already set. */
397 pxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
399 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
401 /* Queues can be allocated wither statically or dynamically, so
402 * note this queue was allocated statically in case the queue is
404 pxNewQueue->ucStaticallyAllocated = pdTRUE;
406 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
408 prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );
412 configASSERT( pxNewQueue );
413 mtCOVERAGE_TEST_MARKER();
419 #endif /* configSUPPORT_STATIC_ALLOCATION */
420 /*-----------------------------------------------------------*/
422 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
424 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
425 const UBaseType_t uxItemSize,
426 const uint8_t ucQueueType )
428 Queue_t * pxNewQueue = NULL;
429 size_t xQueueSizeInBytes;
430 uint8_t * pucQueueStorage;
432 if( ( uxQueueLength > ( UBaseType_t ) 0 ) &&
433 /* Check for multiplication overflow. */
434 ( ( SIZE_MAX / uxQueueLength ) >= uxItemSize ) &&
435 /* Check for addition overflow. */
436 ( ( SIZE_MAX - sizeof( Queue_t ) ) >= ( uxQueueLength * uxItemSize ) ) )
438 /* Allocate enough space to hold the maximum number of items that
439 * can be in the queue at any time. It is valid for uxItemSize to be
440 * zero in the case the queue is used as a semaphore. */
441 xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
443 /* Allocate the queue and storage area. Justification for MISRA
444 * deviation as follows: pvPortMalloc() always ensures returned memory
445 * blocks are aligned per the requirements of the MCU stack. In this case
446 * pvPortMalloc() must return a pointer that is guaranteed to meet the
447 * alignment requirements of the Queue_t structure - which in this case
448 * is an int8_t *. Therefore, whenever the stack alignment requirements
449 * are greater than or equal to the pointer to char requirements the cast
450 * is safe. In other cases alignment requirements are not strict (one or
452 pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes ); /*lint !e9087 !e9079 see comment above. */
454 if( pxNewQueue != NULL )
456 /* Jump past the queue structure to find the location of the queue
458 pucQueueStorage = ( uint8_t * ) pxNewQueue;
459 pucQueueStorage += sizeof( Queue_t ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */
461 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
463 /* Queues can be created either statically or dynamically, so
464 * note this task was created dynamically in case it is later
466 pxNewQueue->ucStaticallyAllocated = pdFALSE;
468 #endif /* configSUPPORT_STATIC_ALLOCATION */
470 prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );
474 traceQUEUE_CREATE_FAILED( ucQueueType );
475 mtCOVERAGE_TEST_MARKER();
480 configASSERT( pxNewQueue );
481 mtCOVERAGE_TEST_MARKER();
487 #endif /* configSUPPORT_STATIC_ALLOCATION */
488 /*-----------------------------------------------------------*/
490 static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
491 const UBaseType_t uxItemSize,
492 uint8_t * pucQueueStorage,
493 const uint8_t ucQueueType,
494 Queue_t * pxNewQueue )
496 /* Remove compiler warnings about unused parameters should
497 * configUSE_TRACE_FACILITY not be set to 1. */
498 ( void ) ucQueueType;
500 if( uxItemSize == ( UBaseType_t ) 0 )
502 /* No RAM was allocated for the queue storage area, but PC head cannot
503 * be set to NULL because NULL is used as a key to say the queue is used as
504 * a mutex. Therefore just set pcHead to point to the queue as a benign
505 * value that is known to be within the memory map. */
506 pxNewQueue->pcHead = ( int8_t * ) pxNewQueue;
510 /* Set the head to the start of the queue storage area. */
511 pxNewQueue->pcHead = ( int8_t * ) pucQueueStorage;
514 /* Initialise the queue members as described where the queue type is
516 pxNewQueue->uxLength = uxQueueLength;
517 pxNewQueue->uxItemSize = uxItemSize;
518 ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );
520 #if ( configUSE_TRACE_FACILITY == 1 )
522 pxNewQueue->ucQueueType = ucQueueType;
524 #endif /* configUSE_TRACE_FACILITY */
526 #if ( configUSE_QUEUE_SETS == 1 )
528 pxNewQueue->pxQueueSetContainer = NULL;
530 #endif /* configUSE_QUEUE_SETS */
532 traceQUEUE_CREATE( pxNewQueue );
534 /*-----------------------------------------------------------*/
536 #if ( configUSE_MUTEXES == 1 )
538 static void prvInitialiseMutex( Queue_t * pxNewQueue )
540 if( pxNewQueue != NULL )
542 /* The queue create function will set all the queue structure members
543 * correctly for a generic queue, but this function is creating a
544 * mutex. Overwrite those members that need to be set differently -
545 * in particular the information required for priority inheritance. */
546 pxNewQueue->u.xSemaphore.xMutexHolder = NULL;
547 pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;
549 /* In case this is a recursive mutex. */
550 pxNewQueue->u.xSemaphore.uxRecursiveCallCount = 0;
552 traceCREATE_MUTEX( pxNewQueue );
554 /* Start with the semaphore in the expected state. */
555 ( void ) xQueueGenericSend( pxNewQueue, NULL, ( TickType_t ) 0U, queueSEND_TO_BACK );
559 traceCREATE_MUTEX_FAILED();
563 #endif /* configUSE_MUTEXES */
564 /*-----------------------------------------------------------*/
566 #if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
568 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType )
570 QueueHandle_t xNewQueue;
571 const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;
573 xNewQueue = xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType );
574 prvInitialiseMutex( ( Queue_t * ) xNewQueue );
579 #endif /* configUSE_MUTEXES */
580 /*-----------------------------------------------------------*/
582 #if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
584 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
585 StaticQueue_t * pxStaticQueue )
587 QueueHandle_t xNewQueue;
588 const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;
590 /* Prevent compiler warnings about unused parameters if
591 * configUSE_TRACE_FACILITY does not equal 1. */
592 ( void ) ucQueueType;
594 xNewQueue = xQueueGenericCreateStatic( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType );
595 prvInitialiseMutex( ( Queue_t * ) xNewQueue );
600 #endif /* configUSE_MUTEXES */
601 /*-----------------------------------------------------------*/
603 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
605 TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore )
607 TaskHandle_t pxReturn;
608 Queue_t * const pxSemaphore = ( Queue_t * ) xSemaphore;
610 configASSERT( xSemaphore );
612 /* This function is called by xSemaphoreGetMutexHolder(), and should not
613 * be called directly. Note: This is a good way of determining if the
614 * calling task is the mutex holder, but not a good way of determining the
615 * identity of the mutex holder, as the holder may change between the
616 * following critical section exiting and the function returning. */
617 taskENTER_CRITICAL();
619 if( pxSemaphore->uxQueueType == queueQUEUE_IS_MUTEX )
621 pxReturn = pxSemaphore->u.xSemaphore.xMutexHolder;
631 } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */
633 #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
634 /*-----------------------------------------------------------*/
636 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
638 TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore )
640 TaskHandle_t pxReturn;
642 configASSERT( xSemaphore );
644 /* Mutexes cannot be used in interrupt service routines, so the mutex
645 * holder should not change in an ISR, and therefore a critical section is
646 * not required here. */
647 if( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )
649 pxReturn = ( ( Queue_t * ) xSemaphore )->u.xSemaphore.xMutexHolder;
657 } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */
659 #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
660 /*-----------------------------------------------------------*/
662 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
664 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex )
667 Queue_t * const pxMutex = ( Queue_t * ) xMutex;
669 configASSERT( pxMutex );
671 /* If this is the task that holds the mutex then xMutexHolder will not
672 * change outside of this task. If this task does not hold the mutex then
673 * pxMutexHolder can never coincidentally equal the tasks handle, and as
674 * this is the only condition we are interested in it does not matter if
675 * pxMutexHolder is accessed simultaneously by another task. Therefore no
676 * mutual exclusion is required to test the pxMutexHolder variable. */
677 if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() )
679 traceGIVE_MUTEX_RECURSIVE( pxMutex );
681 /* uxRecursiveCallCount cannot be zero if xMutexHolder is equal to
682 * the task handle, therefore no underflow check is required. Also,
683 * uxRecursiveCallCount is only modified by the mutex holder, and as
684 * there can only be one, no mutual exclusion is required to modify the
685 * uxRecursiveCallCount member. */
686 ( pxMutex->u.xSemaphore.uxRecursiveCallCount )--;
688 /* Has the recursive call count unwound to 0? */
689 if( pxMutex->u.xSemaphore.uxRecursiveCallCount == ( UBaseType_t ) 0 )
691 /* Return the mutex. This will automatically unblock any other
692 * task that might be waiting to access the mutex. */
693 ( void ) xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );
697 mtCOVERAGE_TEST_MARKER();
704 /* The mutex cannot be given because the calling task is not the
708 traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex );
714 #endif /* configUSE_RECURSIVE_MUTEXES */
715 /*-----------------------------------------------------------*/
717 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
719 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
720 TickType_t xTicksToWait )
723 Queue_t * const pxMutex = ( Queue_t * ) xMutex;
725 configASSERT( pxMutex );
727 /* Comments regarding mutual exclusion as per those within
728 * xQueueGiveMutexRecursive(). */
730 traceTAKE_MUTEX_RECURSIVE( pxMutex );
732 if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() )
734 ( pxMutex->u.xSemaphore.uxRecursiveCallCount )++;
739 xReturn = xQueueSemaphoreTake( pxMutex, xTicksToWait );
741 /* pdPASS will only be returned if the mutex was successfully
742 * obtained. The calling task may have entered the Blocked state
743 * before reaching here. */
744 if( xReturn != pdFAIL )
746 ( pxMutex->u.xSemaphore.uxRecursiveCallCount )++;
750 traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex );
757 #endif /* configUSE_RECURSIVE_MUTEXES */
758 /*-----------------------------------------------------------*/
760 #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
762 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
763 const UBaseType_t uxInitialCount,
764 StaticQueue_t * pxStaticQueue )
766 QueueHandle_t xHandle = NULL;
768 if( ( uxMaxCount != 0 ) &&
769 ( uxInitialCount <= uxMaxCount ) )
771 xHandle = xQueueGenericCreateStatic( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
773 if( xHandle != NULL )
775 ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;
777 traceCREATE_COUNTING_SEMAPHORE();
781 traceCREATE_COUNTING_SEMAPHORE_FAILED();
786 configASSERT( xHandle );
787 mtCOVERAGE_TEST_MARKER();
793 #endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
794 /*-----------------------------------------------------------*/
796 #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
798 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
799 const UBaseType_t uxInitialCount )
801 QueueHandle_t xHandle = NULL;
803 if( ( uxMaxCount != 0 ) &&
804 ( uxInitialCount <= uxMaxCount ) )
806 xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
808 if( xHandle != NULL )
810 ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;
812 traceCREATE_COUNTING_SEMAPHORE();
816 traceCREATE_COUNTING_SEMAPHORE_FAILED();
821 configASSERT( xHandle );
822 mtCOVERAGE_TEST_MARKER();
828 #endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
829 /*-----------------------------------------------------------*/
831 BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
832 const void * const pvItemToQueue,
833 TickType_t xTicksToWait,
834 const BaseType_t xCopyPosition )
836 BaseType_t xEntryTimeSet = pdFALSE, xYieldRequired;
838 Queue_t * const pxQueue = xQueue;
840 configASSERT( pxQueue );
841 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
842 configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
843 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
845 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
849 /*lint -save -e904 This function relaxes the coding standard somewhat to
850 * allow return statements within the function itself. This is done in the
851 * interest of execution time efficiency. */
854 taskENTER_CRITICAL();
856 /* Is there room on the queue now? The running task must be the
857 * highest priority task wanting to access the queue. If the head item
858 * in the queue is to be overwritten then it does not matter if the
860 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
862 traceQUEUE_SEND( pxQueue );
864 #if ( configUSE_QUEUE_SETS == 1 )
866 const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;
868 xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
870 if( pxQueue->pxQueueSetContainer != NULL )
872 if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )
874 /* Do not notify the queue set as an existing item
875 * was overwritten in the queue so the number of items
876 * in the queue has not changed. */
877 mtCOVERAGE_TEST_MARKER();
879 else if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
881 /* The queue is a member of a queue set, and posting
882 * to the queue set caused a higher priority task to
883 * unblock. A context switch is required. */
884 queueYIELD_IF_USING_PREEMPTION();
888 mtCOVERAGE_TEST_MARKER();
893 /* If there was a task waiting for data to arrive on the
894 * queue then unblock it now. */
895 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
897 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
899 /* The unblocked task has a priority higher than
900 * our own so yield immediately. Yes it is ok to
901 * do this from within the critical section - the
902 * kernel takes care of that. */
903 queueYIELD_IF_USING_PREEMPTION();
907 mtCOVERAGE_TEST_MARKER();
910 else if( xYieldRequired != pdFALSE )
912 /* This path is a special case that will only get
913 * executed if the task was holding multiple mutexes
914 * and the mutexes were given back in an order that is
915 * different to that in which they were taken. */
916 queueYIELD_IF_USING_PREEMPTION();
920 mtCOVERAGE_TEST_MARKER();
924 #else /* configUSE_QUEUE_SETS */
926 xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
928 /* If there was a task waiting for data to arrive on the
929 * queue then unblock it now. */
930 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
932 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
934 /* The unblocked task has a priority higher than
935 * our own so yield immediately. Yes it is ok to do
936 * this from within the critical section - the kernel
937 * takes care of that. */
938 queueYIELD_IF_USING_PREEMPTION();
942 mtCOVERAGE_TEST_MARKER();
945 else if( xYieldRequired != pdFALSE )
947 /* This path is a special case that will only get
948 * executed if the task was holding multiple mutexes and
949 * the mutexes were given back in an order that is
950 * different to that in which they were taken. */
951 queueYIELD_IF_USING_PREEMPTION();
955 mtCOVERAGE_TEST_MARKER();
958 #endif /* configUSE_QUEUE_SETS */
965 if( xTicksToWait == ( TickType_t ) 0 )
967 /* The queue was full and no block time is specified (or
968 * the block time has expired) so leave now. */
971 /* Return to the original privilege level before exiting
973 traceQUEUE_SEND_FAILED( pxQueue );
974 return errQUEUE_FULL;
976 else if( xEntryTimeSet == pdFALSE )
978 /* The queue was full and a block time was specified so
979 * configure the timeout structure. */
980 vTaskInternalSetTimeOutState( &xTimeOut );
981 xEntryTimeSet = pdTRUE;
985 /* Entry time was already set. */
986 mtCOVERAGE_TEST_MARKER();
992 /* Interrupts and other tasks can send to and receive from the queue
993 * now the critical section has been exited. */
996 prvLockQueue( pxQueue );
998 /* Update the timeout state to see if it has expired yet. */
999 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
1001 if( prvIsQueueFull( pxQueue ) != pdFALSE )
1003 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
1004 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
1006 /* Unlocking the queue means queue events can effect the
1007 * event list. It is possible that interrupts occurring now
1008 * remove this task from the event list again - but as the
1009 * scheduler is suspended the task will go onto the pending
1010 * ready list instead of the actual ready list. */
1011 prvUnlockQueue( pxQueue );
1013 /* Resuming the scheduler will move tasks from the pending
1014 * ready list into the ready list - so it is feasible that this
1015 * task is already in the ready list before it yields - in which
1016 * case the yield will not cause a context switch unless there
1017 * is also a higher priority task in the pending ready list. */
1018 if( xTaskResumeAll() == pdFALSE )
1020 portYIELD_WITHIN_API();
1026 prvUnlockQueue( pxQueue );
1027 ( void ) xTaskResumeAll();
1032 /* The timeout has expired. */
1033 prvUnlockQueue( pxQueue );
1034 ( void ) xTaskResumeAll();
1036 traceQUEUE_SEND_FAILED( pxQueue );
1037 return errQUEUE_FULL;
1039 } /*lint -restore */
1041 /*-----------------------------------------------------------*/
1043 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
1044 const void * const pvItemToQueue,
1045 BaseType_t * const pxHigherPriorityTaskWoken,
1046 const BaseType_t xCopyPosition )
1049 UBaseType_t uxSavedInterruptStatus;
1050 Queue_t * const pxQueue = xQueue;
1052 configASSERT( pxQueue );
1053 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
1054 configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
1056 /* RTOS ports that support interrupt nesting have the concept of a maximum
1057 * system call (or maximum API call) interrupt priority. Interrupts that are
1058 * above the maximum system call priority are kept permanently enabled, even
1059 * when the RTOS kernel is in a critical section, but cannot make any calls to
1060 * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
1061 * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
1062 * failure if a FreeRTOS API function is called from an interrupt that has been
1063 * assigned a priority above the configured maximum system call priority.
1064 * Only FreeRTOS functions that end in FromISR can be called from interrupts
1065 * that have been assigned a priority at or (logically) below the maximum
1066 * system call interrupt priority. FreeRTOS maintains a separate interrupt
1067 * safe API to ensure interrupt entry is as fast and as simple as possible.
1068 * More information (albeit Cortex-M specific) is provided on the following
1069 * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
1070 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
1072 /* Similar to xQueueGenericSend, except without blocking if there is no room
1073 * in the queue. Also don't directly wake a task that was blocked on a queue
1074 * read, instead return a flag to say whether a context switch is required or
1075 * not (i.e. has a task with a higher priority than us been woken by this
1077 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
1079 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
1081 const int8_t cTxLock = pxQueue->cTxLock;
1082 const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;
1084 traceQUEUE_SEND_FROM_ISR( pxQueue );
1086 /* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a
1087 * semaphore or mutex. That means prvCopyDataToQueue() cannot result
1088 * in a task disinheriting a priority and prvCopyDataToQueue() can be
1089 * called here even though the disinherit function does not check if
1090 * the scheduler is suspended before accessing the ready lists. */
1091 ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
1093 /* The event list is not altered if the queue is locked. This will
1094 * be done when the queue is unlocked later. */
1095 if( cTxLock == queueUNLOCKED )
1097 #if ( configUSE_QUEUE_SETS == 1 )
1099 if( pxQueue->pxQueueSetContainer != NULL )
1101 if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )
1103 /* Do not notify the queue set as an existing item
1104 * was overwritten in the queue so the number of items
1105 * in the queue has not changed. */
1106 mtCOVERAGE_TEST_MARKER();
1108 else if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
1110 /* The queue is a member of a queue set, and posting
1111 * to the queue set caused a higher priority task to
1112 * unblock. A context switch is required. */
1113 if( pxHigherPriorityTaskWoken != NULL )
1115 *pxHigherPriorityTaskWoken = pdTRUE;
1119 mtCOVERAGE_TEST_MARKER();
1124 mtCOVERAGE_TEST_MARKER();
1129 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1131 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1133 /* The task waiting has a higher priority so
1134 * record that a context switch is required. */
1135 if( pxHigherPriorityTaskWoken != NULL )
1137 *pxHigherPriorityTaskWoken = pdTRUE;
1141 mtCOVERAGE_TEST_MARKER();
1146 mtCOVERAGE_TEST_MARKER();
1151 mtCOVERAGE_TEST_MARKER();
1155 #else /* configUSE_QUEUE_SETS */
1157 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1159 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1161 /* The task waiting has a higher priority so record that a
1162 * context switch is required. */
1163 if( pxHigherPriorityTaskWoken != NULL )
1165 *pxHigherPriorityTaskWoken = pdTRUE;
1169 mtCOVERAGE_TEST_MARKER();
1174 mtCOVERAGE_TEST_MARKER();
1179 mtCOVERAGE_TEST_MARKER();
1182 /* Not used in this path. */
1183 ( void ) uxPreviousMessagesWaiting;
1185 #endif /* configUSE_QUEUE_SETS */
1189 /* Increment the lock count so the task that unlocks the queue
1190 * knows that data was posted while it was locked. */
1191 prvIncrementQueueTxLock( pxQueue, cTxLock );
1198 traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
1199 xReturn = errQUEUE_FULL;
1202 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
1206 /*-----------------------------------------------------------*/
1208 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
1209 BaseType_t * const pxHigherPriorityTaskWoken )
1212 UBaseType_t uxSavedInterruptStatus;
1213 Queue_t * const pxQueue = xQueue;
1215 /* Similar to xQueueGenericSendFromISR() but used with semaphores where the
1216 * item size is 0. Don't directly wake a task that was blocked on a queue
1217 * read, instead return a flag to say whether a context switch is required or
1218 * not (i.e. has a task with a higher priority than us been woken by this
1221 configASSERT( pxQueue );
1223 /* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR()
1224 * if the item size is not 0. */
1225 configASSERT( pxQueue->uxItemSize == 0 );
1227 /* Normally a mutex would not be given from an interrupt, especially if
1228 * there is a mutex holder, as priority inheritance makes no sense for an
1229 * interrupts, only tasks. */
1230 configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->u.xSemaphore.xMutexHolder != NULL ) ) );
1232 /* RTOS ports that support interrupt nesting have the concept of a maximum
1233 * system call (or maximum API call) interrupt priority. Interrupts that are
1234 * above the maximum system call priority are kept permanently enabled, even
1235 * when the RTOS kernel is in a critical section, but cannot make any calls to
1236 * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
1237 * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
1238 * failure if a FreeRTOS API function is called from an interrupt that has been
1239 * assigned a priority above the configured maximum system call priority.
1240 * Only FreeRTOS functions that end in FromISR can be called from interrupts
1241 * that have been assigned a priority at or (logically) below the maximum
1242 * system call interrupt priority. FreeRTOS maintains a separate interrupt
1243 * safe API to ensure interrupt entry is as fast and as simple as possible.
1244 * More information (albeit Cortex-M specific) is provided on the following
1245 * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
1246 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
1248 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
1250 const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
1252 /* When the queue is used to implement a semaphore no data is ever
1253 * moved through the queue but it is still valid to see if the queue 'has
1255 if( uxMessagesWaiting < pxQueue->uxLength )
1257 const int8_t cTxLock = pxQueue->cTxLock;
1259 traceQUEUE_SEND_FROM_ISR( pxQueue );
1261 /* A task can only have an inherited priority if it is a mutex
1262 * holder - and if there is a mutex holder then the mutex cannot be
1263 * given from an ISR. As this is the ISR version of the function it
1264 * can be assumed there is no mutex holder and no need to determine if
1265 * priority disinheritance is needed. Simply increase the count of
1266 * messages (semaphores) available. */
1267 pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1;
1269 /* The event list is not altered if the queue is locked. This will
1270 * be done when the queue is unlocked later. */
1271 if( cTxLock == queueUNLOCKED )
1273 #if ( configUSE_QUEUE_SETS == 1 )
1275 if( pxQueue->pxQueueSetContainer != NULL )
1277 if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
1279 /* The semaphore is a member of a queue set, and
1280 * posting to the queue set caused a higher priority
1281 * task to unblock. A context switch is required. */
1282 if( pxHigherPriorityTaskWoken != NULL )
1284 *pxHigherPriorityTaskWoken = pdTRUE;
1288 mtCOVERAGE_TEST_MARKER();
1293 mtCOVERAGE_TEST_MARKER();
1298 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1300 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1302 /* The task waiting has a higher priority so
1303 * record that a context switch is required. */
1304 if( pxHigherPriorityTaskWoken != NULL )
1306 *pxHigherPriorityTaskWoken = pdTRUE;
1310 mtCOVERAGE_TEST_MARKER();
1315 mtCOVERAGE_TEST_MARKER();
1320 mtCOVERAGE_TEST_MARKER();
1324 #else /* configUSE_QUEUE_SETS */
1326 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1328 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1330 /* The task waiting has a higher priority so record that a
1331 * context switch is required. */
1332 if( pxHigherPriorityTaskWoken != NULL )
1334 *pxHigherPriorityTaskWoken = pdTRUE;
1338 mtCOVERAGE_TEST_MARKER();
1343 mtCOVERAGE_TEST_MARKER();
1348 mtCOVERAGE_TEST_MARKER();
1351 #endif /* configUSE_QUEUE_SETS */
1355 /* Increment the lock count so the task that unlocks the queue
1356 * knows that data was posted while it was locked. */
1357 prvIncrementQueueTxLock( pxQueue, cTxLock );
1364 traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
1365 xReturn = errQUEUE_FULL;
1368 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
1372 /*-----------------------------------------------------------*/
1374 BaseType_t xQueueReceive( QueueHandle_t xQueue,
1375 void * const pvBuffer,
1376 TickType_t xTicksToWait )
1378 BaseType_t xEntryTimeSet = pdFALSE;
1380 Queue_t * const pxQueue = xQueue;
1382 /* Check the pointer is not NULL. */
1383 configASSERT( ( pxQueue ) );
1385 /* The buffer into which data is received can only be NULL if the data size
1386 * is zero (so no data is copied into the buffer). */
1387 configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
1389 /* Cannot block if the scheduler is suspended. */
1390 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
1392 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
1396 /*lint -save -e904 This function relaxes the coding standard somewhat to
1397 * allow return statements within the function itself. This is done in the
1398 * interest of execution time efficiency. */
1401 taskENTER_CRITICAL();
1403 const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
1405 /* Is there data in the queue now? To be running the calling task
1406 * must be the highest priority task wanting to access the queue. */
1407 if( uxMessagesWaiting > ( UBaseType_t ) 0 )
1409 /* Data available, remove one item. */
1410 prvCopyDataFromQueue( pxQueue, pvBuffer );
1411 traceQUEUE_RECEIVE( pxQueue );
1412 pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;
1414 /* There is now space in the queue, were any tasks waiting to
1415 * post to the queue? If so, unblock the highest priority waiting
1417 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
1419 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
1421 queueYIELD_IF_USING_PREEMPTION();
1425 mtCOVERAGE_TEST_MARKER();
1430 mtCOVERAGE_TEST_MARKER();
1433 taskEXIT_CRITICAL();
1438 if( xTicksToWait == ( TickType_t ) 0 )
1440 /* The queue was empty and no block time is specified (or
1441 * the block time has expired) so leave now. */
1442 taskEXIT_CRITICAL();
1443 traceQUEUE_RECEIVE_FAILED( pxQueue );
1444 return errQUEUE_EMPTY;
1446 else if( xEntryTimeSet == pdFALSE )
1448 /* The queue was empty and a block time was specified so
1449 * configure the timeout structure. */
1450 vTaskInternalSetTimeOutState( &xTimeOut );
1451 xEntryTimeSet = pdTRUE;
1455 /* Entry time was already set. */
1456 mtCOVERAGE_TEST_MARKER();
1460 taskEXIT_CRITICAL();
1462 /* Interrupts and other tasks can send to and receive from the queue
1463 * now the critical section has been exited. */
1466 prvLockQueue( pxQueue );
1468 /* Update the timeout state to see if it has expired yet. */
1469 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
1471 /* The timeout has not expired. If the queue is still empty place
1472 * the task on the list of tasks waiting to receive from the queue. */
1473 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1475 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
1476 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
1477 prvUnlockQueue( pxQueue );
1479 if( xTaskResumeAll() == pdFALSE )
1481 portYIELD_WITHIN_API();
1485 mtCOVERAGE_TEST_MARKER();
1490 /* The queue contains data again. Loop back to try and read the
1492 prvUnlockQueue( pxQueue );
1493 ( void ) xTaskResumeAll();
1498 /* Timed out. If there is no data in the queue exit, otherwise loop
1499 * back and attempt to read the data. */
1500 prvUnlockQueue( pxQueue );
1501 ( void ) xTaskResumeAll();
1503 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1505 traceQUEUE_RECEIVE_FAILED( pxQueue );
1506 return errQUEUE_EMPTY;
1510 mtCOVERAGE_TEST_MARKER();
1513 } /*lint -restore */
1515 /*-----------------------------------------------------------*/
1517 BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
1518 TickType_t xTicksToWait )
1520 BaseType_t xEntryTimeSet = pdFALSE;
1522 Queue_t * const pxQueue = xQueue;
1524 #if ( configUSE_MUTEXES == 1 )
1525 BaseType_t xInheritanceOccurred = pdFALSE;
1528 /* Check the queue pointer is not NULL. */
1529 configASSERT( ( pxQueue ) );
1531 /* Check this really is a semaphore, in which case the item size will be
1533 configASSERT( pxQueue->uxItemSize == 0 );
1535 /* Cannot block if the scheduler is suspended. */
1536 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
1538 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
1542 /*lint -save -e904 This function relaxes the coding standard somewhat to allow return
1543 * statements within the function itself. This is done in the interest
1544 * of execution time efficiency. */
1547 taskENTER_CRITICAL();
1549 /* Semaphores are queues with an item size of 0, and where the
1550 * number of messages in the queue is the semaphore's count value. */
1551 const UBaseType_t uxSemaphoreCount = pxQueue->uxMessagesWaiting;
1553 /* Is there data in the queue now? To be running the calling task
1554 * must be the highest priority task wanting to access the queue. */
1555 if( uxSemaphoreCount > ( UBaseType_t ) 0 )
1557 traceQUEUE_RECEIVE( pxQueue );
1559 /* Semaphores are queues with a data size of zero and where the
1560 * messages waiting is the semaphore's count. Reduce the count. */
1561 pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1;
1563 #if ( configUSE_MUTEXES == 1 )
1565 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
1567 /* Record the information required to implement
1568 * priority inheritance should it become necessary. */
1569 pxQueue->u.xSemaphore.xMutexHolder = pvTaskIncrementMutexHeldCount();
1573 mtCOVERAGE_TEST_MARKER();
1576 #endif /* configUSE_MUTEXES */
1578 /* Check to see if other tasks are blocked waiting to give the
1579 * semaphore, and if so, unblock the highest priority such task. */
1580 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
1582 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
1584 queueYIELD_IF_USING_PREEMPTION();
1588 mtCOVERAGE_TEST_MARKER();
1593 mtCOVERAGE_TEST_MARKER();
1596 taskEXIT_CRITICAL();
1601 if( xTicksToWait == ( TickType_t ) 0 )
1603 /* The semaphore count was 0 and no block time is specified
1604 * (or the block time has expired) so exit now. */
1605 taskEXIT_CRITICAL();
1606 traceQUEUE_RECEIVE_FAILED( pxQueue );
1607 return errQUEUE_EMPTY;
1609 else if( xEntryTimeSet == pdFALSE )
1611 /* The semaphore count was 0 and a block time was specified
1612 * so configure the timeout structure ready to block. */
1613 vTaskInternalSetTimeOutState( &xTimeOut );
1614 xEntryTimeSet = pdTRUE;
1618 /* Entry time was already set. */
1619 mtCOVERAGE_TEST_MARKER();
1623 taskEXIT_CRITICAL();
1625 /* Interrupts and other tasks can give to and take from the semaphore
1626 * now the critical section has been exited. */
1629 prvLockQueue( pxQueue );
1631 /* Update the timeout state to see if it has expired yet. */
1632 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
1634 /* A block time is specified and not expired. If the semaphore
1635 * count is 0 then enter the Blocked state to wait for a semaphore to
1636 * become available. As semaphores are implemented with queues the
1637 * queue being empty is equivalent to the semaphore count being 0. */
1638 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1640 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
1642 #if ( configUSE_MUTEXES == 1 )
1644 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
1646 taskENTER_CRITICAL();
1648 xInheritanceOccurred = xTaskPriorityInherit( pxQueue->u.xSemaphore.xMutexHolder );
1650 taskEXIT_CRITICAL();
1654 mtCOVERAGE_TEST_MARKER();
1657 #endif /* if ( configUSE_MUTEXES == 1 ) */
1659 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
1660 prvUnlockQueue( pxQueue );
1662 if( xTaskResumeAll() == pdFALSE )
1664 portYIELD_WITHIN_API();
1668 mtCOVERAGE_TEST_MARKER();
1673 /* There was no timeout and the semaphore count was not 0, so
1674 * attempt to take the semaphore again. */
1675 prvUnlockQueue( pxQueue );
1676 ( void ) xTaskResumeAll();
1682 prvUnlockQueue( pxQueue );
1683 ( void ) xTaskResumeAll();
1685 /* If the semaphore count is 0 exit now as the timeout has
1686 * expired. Otherwise return to attempt to take the semaphore that is
1687 * known to be available. As semaphores are implemented by queues the
1688 * queue being empty is equivalent to the semaphore count being 0. */
1689 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1691 #if ( configUSE_MUTEXES == 1 )
1693 /* xInheritanceOccurred could only have be set if
1694 * pxQueue->uxQueueType == queueQUEUE_IS_MUTEX so no need to
1695 * test the mutex type again to check it is actually a mutex. */
1696 if( xInheritanceOccurred != pdFALSE )
1698 taskENTER_CRITICAL();
1700 UBaseType_t uxHighestWaitingPriority;
1702 /* This task blocking on the mutex caused another
1703 * task to inherit this task's priority. Now this task
1704 * has timed out the priority should be disinherited
1705 * again, but only as low as the next highest priority
1706 * task that is waiting for the same mutex. */
1707 uxHighestWaitingPriority = prvGetDisinheritPriorityAfterTimeout( pxQueue );
1708 vTaskPriorityDisinheritAfterTimeout( pxQueue->u.xSemaphore.xMutexHolder, uxHighestWaitingPriority );
1710 taskEXIT_CRITICAL();
1713 #endif /* configUSE_MUTEXES */
1715 traceQUEUE_RECEIVE_FAILED( pxQueue );
1716 return errQUEUE_EMPTY;
1720 mtCOVERAGE_TEST_MARKER();
1723 } /*lint -restore */
1725 /*-----------------------------------------------------------*/
1727 BaseType_t xQueuePeek( QueueHandle_t xQueue,
1728 void * const pvBuffer,
1729 TickType_t xTicksToWait )
1731 BaseType_t xEntryTimeSet = pdFALSE;
1733 int8_t * pcOriginalReadPosition;
1734 Queue_t * const pxQueue = xQueue;
1736 /* Check the pointer is not NULL. */
1737 configASSERT( ( pxQueue ) );
1739 /* The buffer into which data is received can only be NULL if the data size
1740 * is zero (so no data is copied into the buffer. */
1741 configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
1743 /* Cannot block if the scheduler is suspended. */
1744 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
1746 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
1750 /*lint -save -e904 This function relaxes the coding standard somewhat to
1751 * allow return statements within the function itself. This is done in the
1752 * interest of execution time efficiency. */
1755 taskENTER_CRITICAL();
1757 const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
1759 /* Is there data in the queue now? To be running the calling task
1760 * must be the highest priority task wanting to access the queue. */
1761 if( uxMessagesWaiting > ( UBaseType_t ) 0 )
1763 /* Remember the read position so it can be reset after the data
1764 * is read from the queue as this function is only peeking the
1765 * data, not removing it. */
1766 pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom;
1768 prvCopyDataFromQueue( pxQueue, pvBuffer );
1769 traceQUEUE_PEEK( pxQueue );
1771 /* The data is not being removed, so reset the read pointer. */
1772 pxQueue->u.xQueue.pcReadFrom = pcOriginalReadPosition;
1774 /* The data is being left in the queue, so see if there are
1775 * any other tasks waiting for the data. */
1776 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1778 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1780 /* The task waiting has a higher priority than this task. */
1781 queueYIELD_IF_USING_PREEMPTION();
1785 mtCOVERAGE_TEST_MARKER();
1790 mtCOVERAGE_TEST_MARKER();
1793 taskEXIT_CRITICAL();
1798 if( xTicksToWait == ( TickType_t ) 0 )
1800 /* The queue was empty and no block time is specified (or
1801 * the block time has expired) so leave now. */
1802 taskEXIT_CRITICAL();
1803 traceQUEUE_PEEK_FAILED( pxQueue );
1804 return errQUEUE_EMPTY;
1806 else if( xEntryTimeSet == pdFALSE )
1808 /* The queue was empty and a block time was specified so
1809 * configure the timeout structure ready to enter the blocked
1811 vTaskInternalSetTimeOutState( &xTimeOut );
1812 xEntryTimeSet = pdTRUE;
1816 /* Entry time was already set. */
1817 mtCOVERAGE_TEST_MARKER();
1821 taskEXIT_CRITICAL();
1823 /* Interrupts and other tasks can send to and receive from the queue
1824 * now that the critical section has been exited. */
1827 prvLockQueue( pxQueue );
1829 /* Update the timeout state to see if it has expired yet. */
1830 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
1832 /* Timeout has not expired yet, check to see if there is data in the
1833 * queue now, and if not enter the Blocked state to wait for data. */
1834 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1836 traceBLOCKING_ON_QUEUE_PEEK( pxQueue );
1837 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
1838 prvUnlockQueue( pxQueue );
1840 if( xTaskResumeAll() == pdFALSE )
1842 portYIELD_WITHIN_API();
1846 mtCOVERAGE_TEST_MARKER();
1851 /* There is data in the queue now, so don't enter the blocked
1852 * state, instead return to try and obtain the data. */
1853 prvUnlockQueue( pxQueue );
1854 ( void ) xTaskResumeAll();
1859 /* The timeout has expired. If there is still no data in the queue
1860 * exit, otherwise go back and try to read the data again. */
1861 prvUnlockQueue( pxQueue );
1862 ( void ) xTaskResumeAll();
1864 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1866 traceQUEUE_PEEK_FAILED( pxQueue );
1867 return errQUEUE_EMPTY;
1871 mtCOVERAGE_TEST_MARKER();
1874 } /*lint -restore */
1876 /*-----------------------------------------------------------*/
1878 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
1879 void * const pvBuffer,
1880 BaseType_t * const pxHigherPriorityTaskWoken )
1883 UBaseType_t uxSavedInterruptStatus;
1884 Queue_t * const pxQueue = xQueue;
1886 configASSERT( pxQueue );
1887 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
1889 /* RTOS ports that support interrupt nesting have the concept of a maximum
1890 * system call (or maximum API call) interrupt priority. Interrupts that are
1891 * above the maximum system call priority are kept permanently enabled, even
1892 * when the RTOS kernel is in a critical section, but cannot make any calls to
1893 * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
1894 * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
1895 * failure if a FreeRTOS API function is called from an interrupt that has been
1896 * assigned a priority above the configured maximum system call priority.
1897 * Only FreeRTOS functions that end in FromISR can be called from interrupts
1898 * that have been assigned a priority at or (logically) below the maximum
1899 * system call interrupt priority. FreeRTOS maintains a separate interrupt
1900 * safe API to ensure interrupt entry is as fast and as simple as possible.
1901 * More information (albeit Cortex-M specific) is provided on the following
1902 * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
1903 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
1905 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
1907 const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
1909 /* Cannot block in an ISR, so check there is data available. */
1910 if( uxMessagesWaiting > ( UBaseType_t ) 0 )
1912 const int8_t cRxLock = pxQueue->cRxLock;
1914 traceQUEUE_RECEIVE_FROM_ISR( pxQueue );
1916 prvCopyDataFromQueue( pxQueue, pvBuffer );
1917 pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;
1919 /* If the queue is locked the event list will not be modified.
1920 * Instead update the lock count so the task that unlocks the queue
1921 * will know that an ISR has removed data while the queue was
1923 if( cRxLock == queueUNLOCKED )
1925 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
1927 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
1929 /* The task waiting has a higher priority than us so
1930 * force a context switch. */
1931 if( pxHigherPriorityTaskWoken != NULL )
1933 *pxHigherPriorityTaskWoken = pdTRUE;
1937 mtCOVERAGE_TEST_MARKER();
1942 mtCOVERAGE_TEST_MARKER();
1947 mtCOVERAGE_TEST_MARKER();
1952 /* Increment the lock count so the task that unlocks the queue
1953 * knows that data was removed while it was locked. */
1954 prvIncrementQueueRxLock( pxQueue, cRxLock );
1962 traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );
1965 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
1969 /*-----------------------------------------------------------*/
1971 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
1972 void * const pvBuffer )
1975 UBaseType_t uxSavedInterruptStatus;
1976 int8_t * pcOriginalReadPosition;
1977 Queue_t * const pxQueue = xQueue;
1979 configASSERT( pxQueue );
1980 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
1981 configASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */
1983 /* RTOS ports that support interrupt nesting have the concept of a maximum
1984 * system call (or maximum API call) interrupt priority. Interrupts that are
1985 * above the maximum system call priority are kept permanently enabled, even
1986 * when the RTOS kernel is in a critical section, but cannot make any calls to
1987 * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
1988 * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
1989 * failure if a FreeRTOS API function is called from an interrupt that has been
1990 * assigned a priority above the configured maximum system call priority.
1991 * Only FreeRTOS functions that end in FromISR can be called from interrupts
1992 * that have been assigned a priority at or (logically) below the maximum
1993 * system call interrupt priority. FreeRTOS maintains a separate interrupt
1994 * safe API to ensure interrupt entry is as fast and as simple as possible.
1995 * More information (albeit Cortex-M specific) is provided on the following
1996 * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
1997 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
1999 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
2001 /* Cannot block in an ISR, so check there is data available. */
2002 if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )
2004 traceQUEUE_PEEK_FROM_ISR( pxQueue );
2006 /* Remember the read position so it can be reset as nothing is
2007 * actually being removed from the queue. */
2008 pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom;
2009 prvCopyDataFromQueue( pxQueue, pvBuffer );
2010 pxQueue->u.xQueue.pcReadFrom = pcOriginalReadPosition;
2017 traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );
2020 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
2024 /*-----------------------------------------------------------*/
2026 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue )
2028 UBaseType_t uxReturn;
2030 configASSERT( xQueue );
2032 taskENTER_CRITICAL();
2034 uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting;
2036 taskEXIT_CRITICAL();
2039 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
2040 /*-----------------------------------------------------------*/
2042 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
2044 UBaseType_t uxReturn;
2045 Queue_t * const pxQueue = xQueue;
2047 configASSERT( pxQueue );
2049 taskENTER_CRITICAL();
2051 uxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting;
2053 taskEXIT_CRITICAL();
2056 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
2057 /*-----------------------------------------------------------*/
2059 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue )
2061 UBaseType_t uxReturn;
2062 Queue_t * const pxQueue = xQueue;
2064 configASSERT( pxQueue );
2065 uxReturn = pxQueue->uxMessagesWaiting;
2068 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
2069 /*-----------------------------------------------------------*/
2071 void vQueueDelete( QueueHandle_t xQueue )
2073 Queue_t * const pxQueue = xQueue;
2075 configASSERT( pxQueue );
2076 traceQUEUE_DELETE( pxQueue );
2078 #if ( configQUEUE_REGISTRY_SIZE > 0 )
2080 vQueueUnregisterQueue( pxQueue );
2084 #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
2086 /* The queue can only have been allocated dynamically - free it
2088 vPortFree( pxQueue );
2090 #elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
2092 /* The queue could have been allocated statically or dynamically, so
2093 * check before attempting to free the memory. */
2094 if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
2096 vPortFree( pxQueue );
2100 mtCOVERAGE_TEST_MARKER();
2103 #else /* if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) */
2105 /* The queue must have been statically allocated, so is not going to be
2106 * deleted. Avoid compiler warnings about the unused parameter. */
2109 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
2111 /*-----------------------------------------------------------*/
2113 #if ( configUSE_TRACE_FACILITY == 1 )
2115 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue )
2117 return ( ( Queue_t * ) xQueue )->uxQueueNumber;
2120 #endif /* configUSE_TRACE_FACILITY */
2121 /*-----------------------------------------------------------*/
2123 #if ( configUSE_TRACE_FACILITY == 1 )
2125 void vQueueSetQueueNumber( QueueHandle_t xQueue,
2126 UBaseType_t uxQueueNumber )
2128 ( ( Queue_t * ) xQueue )->uxQueueNumber = uxQueueNumber;
2131 #endif /* configUSE_TRACE_FACILITY */
2132 /*-----------------------------------------------------------*/
2134 #if ( configUSE_TRACE_FACILITY == 1 )
2136 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue )
2138 return ( ( Queue_t * ) xQueue )->ucQueueType;
2141 #endif /* configUSE_TRACE_FACILITY */
2142 /*-----------------------------------------------------------*/
2144 #if ( configUSE_MUTEXES == 1 )
2146 static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue )
2148 UBaseType_t uxHighestPriorityOfWaitingTasks;
2150 /* If a task waiting for a mutex causes the mutex holder to inherit a
2151 * priority, but the waiting task times out, then the holder should
2152 * disinherit the priority - but only down to the highest priority of any
2153 * other tasks that are waiting for the same mutex. For this purpose,
2154 * return the priority of the highest priority task that is waiting for the
2156 if( listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) ) > 0U )
2158 uxHighestPriorityOfWaitingTasks = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) );
2162 uxHighestPriorityOfWaitingTasks = tskIDLE_PRIORITY;
2165 return uxHighestPriorityOfWaitingTasks;
2168 #endif /* configUSE_MUTEXES */
2169 /*-----------------------------------------------------------*/
2171 static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
2172 const void * pvItemToQueue,
2173 const BaseType_t xPosition )
2175 BaseType_t xReturn = pdFALSE;
2176 UBaseType_t uxMessagesWaiting;
2178 /* This function is called from a critical section. */
2180 uxMessagesWaiting = pxQueue->uxMessagesWaiting;
2182 if( pxQueue->uxItemSize == ( UBaseType_t ) 0 )
2184 #if ( configUSE_MUTEXES == 1 )
2186 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
2188 /* The mutex is no longer being held. */
2189 xReturn = xTaskPriorityDisinherit( pxQueue->u.xSemaphore.xMutexHolder );
2190 pxQueue->u.xSemaphore.xMutexHolder = NULL;
2194 mtCOVERAGE_TEST_MARKER();
2197 #endif /* configUSE_MUTEXES */
2199 else if( xPosition == queueSEND_TO_BACK )
2201 ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */
2202 pxQueue->pcWriteTo += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */
2204 if( pxQueue->pcWriteTo >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
2206 pxQueue->pcWriteTo = pxQueue->pcHead;
2210 mtCOVERAGE_TEST_MARKER();
2215 ( void ) memcpy( ( void * ) pxQueue->u.xQueue.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e9087 !e418 MISRA exception as the casts are only redundant for some ports. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. Assert checks null pointer only used when length is 0. */
2216 pxQueue->u.xQueue.pcReadFrom -= pxQueue->uxItemSize;
2218 if( pxQueue->u.xQueue.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
2220 pxQueue->u.xQueue.pcReadFrom = ( pxQueue->u.xQueue.pcTail - pxQueue->uxItemSize );
2224 mtCOVERAGE_TEST_MARKER();
2227 if( xPosition == queueOVERWRITE )
2229 if( uxMessagesWaiting > ( UBaseType_t ) 0 )
2231 /* An item is not being added but overwritten, so subtract
2232 * one from the recorded number of items in the queue so when
2233 * one is added again below the number of recorded items remains
2235 --uxMessagesWaiting;
2239 mtCOVERAGE_TEST_MARKER();
2244 mtCOVERAGE_TEST_MARKER();
2248 pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1;
2252 /*-----------------------------------------------------------*/
2254 static void prvCopyDataFromQueue( Queue_t * const pxQueue,
2255 void * const pvBuffer )
2257 if( pxQueue->uxItemSize != ( UBaseType_t ) 0 )
2259 pxQueue->u.xQueue.pcReadFrom += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */
2261 if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */
2263 pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead;
2267 mtCOVERAGE_TEST_MARKER();
2270 ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports. Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */
2273 /*-----------------------------------------------------------*/
2275 static void prvUnlockQueue( Queue_t * const pxQueue )
2277 /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
2279 /* The lock counts contains the number of extra data items placed or
2280 * removed from the queue while the queue was locked. When a queue is
2281 * locked items can be added or removed, but the event lists cannot be
2283 taskENTER_CRITICAL();
2285 int8_t cTxLock = pxQueue->cTxLock;
2287 /* See if data was added to the queue while it was locked. */
2288 while( cTxLock > queueLOCKED_UNMODIFIED )
2290 /* Data was posted while the queue was locked. Are any tasks
2291 * blocked waiting for data to become available? */
2292 #if ( configUSE_QUEUE_SETS == 1 )
2294 if( pxQueue->pxQueueSetContainer != NULL )
2296 if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
2298 /* The queue is a member of a queue set, and posting to
2299 * the queue set caused a higher priority task to unblock.
2300 * A context switch is required. */
2305 mtCOVERAGE_TEST_MARKER();
2310 /* Tasks that are removed from the event list will get
2311 * added to the pending ready list as the scheduler is still
2313 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
2315 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
2317 /* The task waiting has a higher priority so record that a
2318 * context switch is required. */
2323 mtCOVERAGE_TEST_MARKER();
2332 #else /* configUSE_QUEUE_SETS */
2334 /* Tasks that are removed from the event list will get added to
2335 * the pending ready list as the scheduler is still suspended. */
2336 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
2338 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
2340 /* The task waiting has a higher priority so record that
2341 * a context switch is required. */
2346 mtCOVERAGE_TEST_MARKER();
2354 #endif /* configUSE_QUEUE_SETS */
2359 pxQueue->cTxLock = queueUNLOCKED;
2361 taskEXIT_CRITICAL();
2363 /* Do the same for the Rx lock. */
2364 taskENTER_CRITICAL();
2366 int8_t cRxLock = pxQueue->cRxLock;
2368 while( cRxLock > queueLOCKED_UNMODIFIED )
2370 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
2372 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
2378 mtCOVERAGE_TEST_MARKER();
2389 pxQueue->cRxLock = queueUNLOCKED;
2391 taskEXIT_CRITICAL();
2393 /*-----------------------------------------------------------*/
2395 static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue )
2399 taskENTER_CRITICAL();
2401 if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 )
2410 taskEXIT_CRITICAL();
2414 /*-----------------------------------------------------------*/
2416 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )
2419 Queue_t * const pxQueue = xQueue;
2421 configASSERT( pxQueue );
2423 if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 )
2433 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
2434 /*-----------------------------------------------------------*/
2436 static BaseType_t prvIsQueueFull( const Queue_t * pxQueue )
2440 taskENTER_CRITICAL();
2442 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
2451 taskEXIT_CRITICAL();
2455 /*-----------------------------------------------------------*/
2457 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
2460 Queue_t * const pxQueue = xQueue;
2462 configASSERT( pxQueue );
2464 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
2474 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
2475 /*-----------------------------------------------------------*/
2477 #if ( configQUEUE_REGISTRY_SIZE > 0 )
2479 void vQueueAddToRegistry( QueueHandle_t xQueue,
2480 const char * pcQueueName ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
2483 QueueRegistryItem_t * pxEntryToWrite = NULL;
2485 configASSERT( xQueue );
2487 if( pcQueueName != NULL )
2489 /* See if there is an empty space in the registry. A NULL name denotes
2491 for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ )
2493 /* Replace an existing entry if the queue is already in the registry. */
2494 if( xQueue == xQueueRegistry[ ux ].xHandle )
2496 pxEntryToWrite = &( xQueueRegistry[ ux ] );
2499 /* Otherwise, store in the next empty location */
2500 else if( ( pxEntryToWrite == NULL ) && ( xQueueRegistry[ ux ].pcQueueName == NULL ) )
2502 pxEntryToWrite = &( xQueueRegistry[ ux ] );
2506 mtCOVERAGE_TEST_MARKER();
2511 if( pxEntryToWrite != NULL )
2513 /* Store the information on this queue. */
2514 pxEntryToWrite->pcQueueName = pcQueueName;
2515 pxEntryToWrite->xHandle = xQueue;
2517 traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName );
2521 #endif /* configQUEUE_REGISTRY_SIZE */
2522 /*-----------------------------------------------------------*/
2524 #if ( configQUEUE_REGISTRY_SIZE > 0 )
2526 const char * pcQueueGetName( QueueHandle_t xQueue ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
2529 const char * pcReturn = NULL; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
2531 configASSERT( xQueue );
2533 /* Note there is nothing here to protect against another task adding or
2534 * removing entries from the registry while it is being searched. */
2536 for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ )
2538 if( xQueueRegistry[ ux ].xHandle == xQueue )
2540 pcReturn = xQueueRegistry[ ux ].pcQueueName;
2545 mtCOVERAGE_TEST_MARKER();
2550 } /*lint !e818 xQueue cannot be a pointer to const because it is a typedef. */
2552 #endif /* configQUEUE_REGISTRY_SIZE */
2553 /*-----------------------------------------------------------*/
2555 #if ( configQUEUE_REGISTRY_SIZE > 0 )
2557 void vQueueUnregisterQueue( QueueHandle_t xQueue )
2561 configASSERT( xQueue );
2563 /* See if the handle of the queue being unregistered in actually in the
2565 for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ )
2567 if( xQueueRegistry[ ux ].xHandle == xQueue )
2569 /* Set the name to NULL to show that this slot if free again. */
2570 xQueueRegistry[ ux ].pcQueueName = NULL;
2572 /* Set the handle to NULL to ensure the same queue handle cannot
2573 * appear in the registry twice if it is added, removed, then
2575 xQueueRegistry[ ux ].xHandle = ( QueueHandle_t ) 0;
2580 mtCOVERAGE_TEST_MARKER();
2583 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
2585 #endif /* configQUEUE_REGISTRY_SIZE */
2586 /*-----------------------------------------------------------*/
2588 #if ( configUSE_TIMERS == 1 )
2590 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
2591 TickType_t xTicksToWait,
2592 const BaseType_t xWaitIndefinitely )
2594 Queue_t * const pxQueue = xQueue;
2596 /* This function should not be called by application code hence the
2597 * 'Restricted' in its name. It is not part of the public API. It is
2598 * designed for use by kernel code, and has special calling requirements.
2599 * It can result in vListInsert() being called on a list that can only
2600 * possibly ever have one item in it, so the list will be fast, but even
2601 * so it should be called with the scheduler locked and not from a critical
2604 /* Only do anything if there are no messages in the queue. This function
2605 * will not actually cause the task to block, just place it on a blocked
2606 * list. It will not block until the scheduler is unlocked - at which
2607 * time a yield will be performed. If an item is added to the queue while
2608 * the queue is locked, and the calling task blocks on the queue, then the
2609 * calling task will be immediately unblocked when the queue is unlocked. */
2610 prvLockQueue( pxQueue );
2612 if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0U )
2614 /* There is nothing in the queue, block for the specified period. */
2615 vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait, xWaitIndefinitely );
2619 mtCOVERAGE_TEST_MARKER();
2622 prvUnlockQueue( pxQueue );
2625 #endif /* configUSE_TIMERS */
2626 /*-----------------------------------------------------------*/
2628 #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
2630 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength )
2632 QueueSetHandle_t pxQueue;
2634 pxQueue = xQueueGenericCreate( uxEventQueueLength, ( UBaseType_t ) sizeof( Queue_t * ), queueQUEUE_TYPE_SET );
2639 #endif /* configUSE_QUEUE_SETS */
2640 /*-----------------------------------------------------------*/
2642 #if ( configUSE_QUEUE_SETS == 1 )
2644 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
2645 QueueSetHandle_t xQueueSet )
2649 taskENTER_CRITICAL();
2651 if( ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )
2653 /* Cannot add a queue/semaphore to more than one queue set. */
2656 else if( ( ( Queue_t * ) xQueueOrSemaphore )->uxMessagesWaiting != ( UBaseType_t ) 0 )
2658 /* Cannot add a queue/semaphore to a queue set if there are already
2659 * items in the queue/semaphore. */
2664 ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;
2668 taskEXIT_CRITICAL();
2673 #endif /* configUSE_QUEUE_SETS */
2674 /*-----------------------------------------------------------*/
2676 #if ( configUSE_QUEUE_SETS == 1 )
2678 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
2679 QueueSetHandle_t xQueueSet )
2682 Queue_t * const pxQueueOrSemaphore = ( Queue_t * ) xQueueOrSemaphore;
2684 if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )
2686 /* The queue was not a member of the set. */
2689 else if( pxQueueOrSemaphore->uxMessagesWaiting != ( UBaseType_t ) 0 )
2691 /* It is dangerous to remove a queue from a set when the queue is
2692 * not empty because the queue set will still hold pending events for
2698 taskENTER_CRITICAL();
2700 /* The queue is no longer contained in the set. */
2701 pxQueueOrSemaphore->pxQueueSetContainer = NULL;
2703 taskEXIT_CRITICAL();
2708 } /*lint !e818 xQueueSet could not be declared as pointing to const as it is a typedef. */
2710 #endif /* configUSE_QUEUE_SETS */
2711 /*-----------------------------------------------------------*/
2713 #if ( configUSE_QUEUE_SETS == 1 )
2715 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
2716 TickType_t const xTicksToWait )
2718 QueueSetMemberHandle_t xReturn = NULL;
2720 ( void ) xQueueReceive( ( QueueHandle_t ) xQueueSet, &xReturn, xTicksToWait ); /*lint !e961 Casting from one typedef to another is not redundant. */
2724 #endif /* configUSE_QUEUE_SETS */
2725 /*-----------------------------------------------------------*/
2727 #if ( configUSE_QUEUE_SETS == 1 )
2729 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet )
2731 QueueSetMemberHandle_t xReturn = NULL;
2733 ( void ) xQueueReceiveFromISR( ( QueueHandle_t ) xQueueSet, &xReturn, NULL ); /*lint !e961 Casting from one typedef to another is not redundant. */
2737 #endif /* configUSE_QUEUE_SETS */
2738 /*-----------------------------------------------------------*/
2740 #if ( configUSE_QUEUE_SETS == 1 )
2742 static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
2744 Queue_t * pxQueueSetContainer = pxQueue->pxQueueSetContainer;
2745 BaseType_t xReturn = pdFALSE;
2747 /* This function must be called form a critical section. */
2749 /* The following line is not reachable in unit tests because every call
2750 * to prvNotifyQueueSetContainer is preceded by a check that
2751 * pxQueueSetContainer != NULL */
2752 configASSERT( pxQueueSetContainer ); /* LCOV_EXCL_BR_LINE */
2753 configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );
2755 if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )
2757 const int8_t cTxLock = pxQueueSetContainer->cTxLock;
2759 traceQUEUE_SET_SEND( pxQueueSetContainer );
2761 /* The data copied is the handle of the queue that contains data. */
2762 xReturn = prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, queueSEND_TO_BACK );
2764 if( cTxLock == queueUNLOCKED )
2766 if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )
2768 if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )
2770 /* The task waiting has a higher priority. */
2775 mtCOVERAGE_TEST_MARKER();
2780 mtCOVERAGE_TEST_MARKER();
2785 prvIncrementQueueTxLock( pxQueueSetContainer, cTxLock );
2790 mtCOVERAGE_TEST_MARKER();
2796 #endif /* configUSE_QUEUE_SETS */