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_STATIC_ALLOCATION == 1 )
424 BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
425 uint8_t ** ppucQueueStorage,
426 StaticQueue_t ** ppxStaticQueue )
429 Queue_t * const pxQueue = xQueue;
431 configASSERT( pxQueue );
432 configASSERT( ppxStaticQueue );
434 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
436 /* Check if the queue was statically allocated. */
437 if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
439 if( ppucQueueStorage != NULL )
441 *ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
444 *ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
452 #else /* configSUPPORT_DYNAMIC_ALLOCATION */
454 /* Queue must have been statically allocated. */
455 if( ppucQueueStorage != NULL )
457 *ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
460 *ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
463 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
468 #endif /* configSUPPORT_STATIC_ALLOCATION */
469 /*-----------------------------------------------------------*/
471 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
473 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
474 const UBaseType_t uxItemSize,
475 const uint8_t ucQueueType )
477 Queue_t * pxNewQueue = NULL;
478 size_t xQueueSizeInBytes;
479 uint8_t * pucQueueStorage;
481 if( ( uxQueueLength > ( UBaseType_t ) 0 ) &&
482 /* Check for multiplication overflow. */
483 ( ( SIZE_MAX / uxQueueLength ) >= uxItemSize ) &&
484 /* Check for addition overflow. */
485 ( ( SIZE_MAX - sizeof( Queue_t ) ) >= ( uxQueueLength * uxItemSize ) ) )
487 /* Allocate enough space to hold the maximum number of items that
488 * can be in the queue at any time. It is valid for uxItemSize to be
489 * zero in the case the queue is used as a semaphore. */
490 xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
492 /* Allocate the queue and storage area. Justification for MISRA
493 * deviation as follows: pvPortMalloc() always ensures returned memory
494 * blocks are aligned per the requirements of the MCU stack. In this case
495 * pvPortMalloc() must return a pointer that is guaranteed to meet the
496 * alignment requirements of the Queue_t structure - which in this case
497 * is an int8_t *. Therefore, whenever the stack alignment requirements
498 * are greater than or equal to the pointer to char requirements the cast
499 * is safe. In other cases alignment requirements are not strict (one or
501 pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes ); /*lint !e9087 !e9079 see comment above. */
503 if( pxNewQueue != NULL )
505 /* Jump past the queue structure to find the location of the queue
507 pucQueueStorage = ( uint8_t * ) pxNewQueue;
508 pucQueueStorage += sizeof( Queue_t ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */
510 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
512 /* Queues can be created either statically or dynamically, so
513 * note this task was created dynamically in case it is later
515 pxNewQueue->ucStaticallyAllocated = pdFALSE;
517 #endif /* configSUPPORT_STATIC_ALLOCATION */
519 prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );
523 traceQUEUE_CREATE_FAILED( ucQueueType );
524 mtCOVERAGE_TEST_MARKER();
529 configASSERT( pxNewQueue );
530 mtCOVERAGE_TEST_MARKER();
536 #endif /* configSUPPORT_STATIC_ALLOCATION */
537 /*-----------------------------------------------------------*/
539 static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
540 const UBaseType_t uxItemSize,
541 uint8_t * pucQueueStorage,
542 const uint8_t ucQueueType,
543 Queue_t * pxNewQueue )
545 /* Remove compiler warnings about unused parameters should
546 * configUSE_TRACE_FACILITY not be set to 1. */
547 ( void ) ucQueueType;
549 if( uxItemSize == ( UBaseType_t ) 0 )
551 /* No RAM was allocated for the queue storage area, but PC head cannot
552 * be set to NULL because NULL is used as a key to say the queue is used as
553 * a mutex. Therefore just set pcHead to point to the queue as a benign
554 * value that is known to be within the memory map. */
555 pxNewQueue->pcHead = ( int8_t * ) pxNewQueue;
559 /* Set the head to the start of the queue storage area. */
560 pxNewQueue->pcHead = ( int8_t * ) pucQueueStorage;
563 /* Initialise the queue members as described where the queue type is
565 pxNewQueue->uxLength = uxQueueLength;
566 pxNewQueue->uxItemSize = uxItemSize;
567 ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );
569 #if ( configUSE_TRACE_FACILITY == 1 )
571 pxNewQueue->ucQueueType = ucQueueType;
573 #endif /* configUSE_TRACE_FACILITY */
575 #if ( configUSE_QUEUE_SETS == 1 )
577 pxNewQueue->pxQueueSetContainer = NULL;
579 #endif /* configUSE_QUEUE_SETS */
581 traceQUEUE_CREATE( pxNewQueue );
583 /*-----------------------------------------------------------*/
585 #if ( configUSE_MUTEXES == 1 )
587 static void prvInitialiseMutex( Queue_t * pxNewQueue )
589 if( pxNewQueue != NULL )
591 /* The queue create function will set all the queue structure members
592 * correctly for a generic queue, but this function is creating a
593 * mutex. Overwrite those members that need to be set differently -
594 * in particular the information required for priority inheritance. */
595 pxNewQueue->u.xSemaphore.xMutexHolder = NULL;
596 pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;
598 /* In case this is a recursive mutex. */
599 pxNewQueue->u.xSemaphore.uxRecursiveCallCount = 0;
601 traceCREATE_MUTEX( pxNewQueue );
603 /* Start with the semaphore in the expected state. */
604 ( void ) xQueueGenericSend( pxNewQueue, NULL, ( TickType_t ) 0U, queueSEND_TO_BACK );
608 traceCREATE_MUTEX_FAILED();
612 #endif /* configUSE_MUTEXES */
613 /*-----------------------------------------------------------*/
615 #if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
617 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType )
619 QueueHandle_t xNewQueue;
620 const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;
622 xNewQueue = xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType );
623 prvInitialiseMutex( ( Queue_t * ) xNewQueue );
628 #endif /* configUSE_MUTEXES */
629 /*-----------------------------------------------------------*/
631 #if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
633 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
634 StaticQueue_t * pxStaticQueue )
636 QueueHandle_t xNewQueue;
637 const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;
639 /* Prevent compiler warnings about unused parameters if
640 * configUSE_TRACE_FACILITY does not equal 1. */
641 ( void ) ucQueueType;
643 xNewQueue = xQueueGenericCreateStatic( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType );
644 prvInitialiseMutex( ( Queue_t * ) xNewQueue );
649 #endif /* configUSE_MUTEXES */
650 /*-----------------------------------------------------------*/
652 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
654 TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore )
656 TaskHandle_t pxReturn;
657 Queue_t * const pxSemaphore = ( Queue_t * ) xSemaphore;
659 configASSERT( xSemaphore );
661 /* This function is called by xSemaphoreGetMutexHolder(), and should not
662 * be called directly. Note: This is a good way of determining if the
663 * calling task is the mutex holder, but not a good way of determining the
664 * identity of the mutex holder, as the holder may change between the
665 * following critical section exiting and the function returning. */
666 taskENTER_CRITICAL();
668 if( pxSemaphore->uxQueueType == queueQUEUE_IS_MUTEX )
670 pxReturn = pxSemaphore->u.xSemaphore.xMutexHolder;
680 } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */
682 #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
683 /*-----------------------------------------------------------*/
685 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
687 TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore )
689 TaskHandle_t pxReturn;
691 configASSERT( xSemaphore );
693 /* Mutexes cannot be used in interrupt service routines, so the mutex
694 * holder should not change in an ISR, and therefore a critical section is
695 * not required here. */
696 if( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )
698 pxReturn = ( ( Queue_t * ) xSemaphore )->u.xSemaphore.xMutexHolder;
706 } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */
708 #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
709 /*-----------------------------------------------------------*/
711 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
713 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex )
716 Queue_t * const pxMutex = ( Queue_t * ) xMutex;
718 configASSERT( pxMutex );
720 /* If this is the task that holds the mutex then xMutexHolder will not
721 * change outside of this task. If this task does not hold the mutex then
722 * pxMutexHolder can never coincidentally equal the tasks handle, and as
723 * this is the only condition we are interested in it does not matter if
724 * pxMutexHolder is accessed simultaneously by another task. Therefore no
725 * mutual exclusion is required to test the pxMutexHolder variable. */
726 if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() )
728 traceGIVE_MUTEX_RECURSIVE( pxMutex );
730 /* uxRecursiveCallCount cannot be zero if xMutexHolder is equal to
731 * the task handle, therefore no underflow check is required. Also,
732 * uxRecursiveCallCount is only modified by the mutex holder, and as
733 * there can only be one, no mutual exclusion is required to modify the
734 * uxRecursiveCallCount member. */
735 ( pxMutex->u.xSemaphore.uxRecursiveCallCount )--;
737 /* Has the recursive call count unwound to 0? */
738 if( pxMutex->u.xSemaphore.uxRecursiveCallCount == ( UBaseType_t ) 0 )
740 /* Return the mutex. This will automatically unblock any other
741 * task that might be waiting to access the mutex. */
742 ( void ) xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );
746 mtCOVERAGE_TEST_MARKER();
753 /* The mutex cannot be given because the calling task is not the
757 traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex );
763 #endif /* configUSE_RECURSIVE_MUTEXES */
764 /*-----------------------------------------------------------*/
766 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
768 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
769 TickType_t xTicksToWait )
772 Queue_t * const pxMutex = ( Queue_t * ) xMutex;
774 configASSERT( pxMutex );
776 /* Comments regarding mutual exclusion as per those within
777 * xQueueGiveMutexRecursive(). */
779 traceTAKE_MUTEX_RECURSIVE( pxMutex );
781 if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() )
783 ( pxMutex->u.xSemaphore.uxRecursiveCallCount )++;
788 xReturn = xQueueSemaphoreTake( pxMutex, xTicksToWait );
790 /* pdPASS will only be returned if the mutex was successfully
791 * obtained. The calling task may have entered the Blocked state
792 * before reaching here. */
793 if( xReturn != pdFAIL )
795 ( pxMutex->u.xSemaphore.uxRecursiveCallCount )++;
799 traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex );
806 #endif /* configUSE_RECURSIVE_MUTEXES */
807 /*-----------------------------------------------------------*/
809 #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
811 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
812 const UBaseType_t uxInitialCount,
813 StaticQueue_t * pxStaticQueue )
815 QueueHandle_t xHandle = NULL;
817 if( ( uxMaxCount != 0 ) &&
818 ( uxInitialCount <= uxMaxCount ) )
820 xHandle = xQueueGenericCreateStatic( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
822 if( xHandle != NULL )
824 ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;
826 traceCREATE_COUNTING_SEMAPHORE();
830 traceCREATE_COUNTING_SEMAPHORE_FAILED();
835 configASSERT( xHandle );
836 mtCOVERAGE_TEST_MARKER();
842 #endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
843 /*-----------------------------------------------------------*/
845 #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
847 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
848 const UBaseType_t uxInitialCount )
850 QueueHandle_t xHandle = NULL;
852 if( ( uxMaxCount != 0 ) &&
853 ( uxInitialCount <= uxMaxCount ) )
855 xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
857 if( xHandle != NULL )
859 ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;
861 traceCREATE_COUNTING_SEMAPHORE();
865 traceCREATE_COUNTING_SEMAPHORE_FAILED();
870 configASSERT( xHandle );
871 mtCOVERAGE_TEST_MARKER();
877 #endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
878 /*-----------------------------------------------------------*/
880 BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
881 const void * const pvItemToQueue,
882 TickType_t xTicksToWait,
883 const BaseType_t xCopyPosition )
885 BaseType_t xEntryTimeSet = pdFALSE, xYieldRequired;
887 Queue_t * const pxQueue = xQueue;
889 configASSERT( pxQueue );
890 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
891 configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
892 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
894 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
898 /*lint -save -e904 This function relaxes the coding standard somewhat to
899 * allow return statements within the function itself. This is done in the
900 * interest of execution time efficiency. */
903 taskENTER_CRITICAL();
905 /* Is there room on the queue now? The running task must be the
906 * highest priority task wanting to access the queue. If the head item
907 * in the queue is to be overwritten then it does not matter if the
909 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
911 traceQUEUE_SEND( pxQueue );
913 #if ( configUSE_QUEUE_SETS == 1 )
915 const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;
917 xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
919 if( pxQueue->pxQueueSetContainer != NULL )
921 if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )
923 /* Do not notify the queue set as an existing item
924 * was overwritten in the queue so the number of items
925 * in the queue has not changed. */
926 mtCOVERAGE_TEST_MARKER();
928 else if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
930 /* The queue is a member of a queue set, and posting
931 * to the queue set caused a higher priority task to
932 * unblock. A context switch is required. */
933 queueYIELD_IF_USING_PREEMPTION();
937 mtCOVERAGE_TEST_MARKER();
942 /* If there was a task waiting for data to arrive on the
943 * queue then unblock it now. */
944 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
946 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
948 /* The unblocked task has a priority higher than
949 * our own so yield immediately. Yes it is ok to
950 * do this from within the critical section - the
951 * kernel takes care of that. */
952 queueYIELD_IF_USING_PREEMPTION();
956 mtCOVERAGE_TEST_MARKER();
959 else if( xYieldRequired != pdFALSE )
961 /* This path is a special case that will only get
962 * executed if the task was holding multiple mutexes
963 * and the mutexes were given back in an order that is
964 * different to that in which they were taken. */
965 queueYIELD_IF_USING_PREEMPTION();
969 mtCOVERAGE_TEST_MARKER();
973 #else /* configUSE_QUEUE_SETS */
975 xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
977 /* If there was a task waiting for data to arrive on the
978 * queue then unblock it now. */
979 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
981 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
983 /* The unblocked task has a priority higher than
984 * our own so yield immediately. Yes it is ok to do
985 * this from within the critical section - the kernel
986 * takes care of that. */
987 queueYIELD_IF_USING_PREEMPTION();
991 mtCOVERAGE_TEST_MARKER();
994 else if( xYieldRequired != pdFALSE )
996 /* This path is a special case that will only get
997 * executed if the task was holding multiple mutexes and
998 * the mutexes were given back in an order that is
999 * different to that in which they were taken. */
1000 queueYIELD_IF_USING_PREEMPTION();
1004 mtCOVERAGE_TEST_MARKER();
1007 #endif /* configUSE_QUEUE_SETS */
1009 taskEXIT_CRITICAL();
1014 if( xTicksToWait == ( TickType_t ) 0 )
1016 /* The queue was full and no block time is specified (or
1017 * the block time has expired) so leave now. */
1018 taskEXIT_CRITICAL();
1020 /* Return to the original privilege level before exiting
1022 traceQUEUE_SEND_FAILED( pxQueue );
1023 return errQUEUE_FULL;
1025 else if( xEntryTimeSet == pdFALSE )
1027 /* The queue was full and a block time was specified so
1028 * configure the timeout structure. */
1029 vTaskInternalSetTimeOutState( &xTimeOut );
1030 xEntryTimeSet = pdTRUE;
1034 /* Entry time was already set. */
1035 mtCOVERAGE_TEST_MARKER();
1039 taskEXIT_CRITICAL();
1041 /* Interrupts and other tasks can send to and receive from the queue
1042 * now the critical section has been exited. */
1045 prvLockQueue( pxQueue );
1047 /* Update the timeout state to see if it has expired yet. */
1048 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
1050 if( prvIsQueueFull( pxQueue ) != pdFALSE )
1052 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
1053 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
1055 /* Unlocking the queue means queue events can effect the
1056 * event list. It is possible that interrupts occurring now
1057 * remove this task from the event list again - but as the
1058 * scheduler is suspended the task will go onto the pending
1059 * ready list instead of the actual ready list. */
1060 prvUnlockQueue( pxQueue );
1062 /* Resuming the scheduler will move tasks from the pending
1063 * ready list into the ready list - so it is feasible that this
1064 * task is already in the ready list before it yields - in which
1065 * case the yield will not cause a context switch unless there
1066 * is also a higher priority task in the pending ready list. */
1067 if( xTaskResumeAll() == pdFALSE )
1069 portYIELD_WITHIN_API();
1075 prvUnlockQueue( pxQueue );
1076 ( void ) xTaskResumeAll();
1081 /* The timeout has expired. */
1082 prvUnlockQueue( pxQueue );
1083 ( void ) xTaskResumeAll();
1085 traceQUEUE_SEND_FAILED( pxQueue );
1086 return errQUEUE_FULL;
1088 } /*lint -restore */
1090 /*-----------------------------------------------------------*/
1092 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
1093 const void * const pvItemToQueue,
1094 BaseType_t * const pxHigherPriorityTaskWoken,
1095 const BaseType_t xCopyPosition )
1098 portBASE_TYPE xSavedInterruptStatus;
1099 Queue_t * const pxQueue = xQueue;
1101 configASSERT( pxQueue );
1102 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
1103 configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
1105 /* RTOS ports that support interrupt nesting have the concept of a maximum
1106 * system call (or maximum API call) interrupt priority. Interrupts that are
1107 * above the maximum system call priority are kept permanently enabled, even
1108 * when the RTOS kernel is in a critical section, but cannot make any calls to
1109 * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
1110 * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
1111 * failure if a FreeRTOS API function is called from an interrupt that has been
1112 * assigned a priority above the configured maximum system call priority.
1113 * Only FreeRTOS functions that end in FromISR can be called from interrupts
1114 * that have been assigned a priority at or (logically) below the maximum
1115 * system call interrupt priority. FreeRTOS maintains a separate interrupt
1116 * safe API to ensure interrupt entry is as fast and as simple as possible.
1117 * More information (albeit Cortex-M specific) is provided on the following
1118 * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
1119 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
1121 /* Similar to xQueueGenericSend, except without blocking if there is no room
1122 * in the queue. Also don't directly wake a task that was blocked on a queue
1123 * read, instead return a flag to say whether a context switch is required or
1124 * not (i.e. has a task with a higher priority than us been woken by this
1126 xSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
1128 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
1130 const int8_t cTxLock = pxQueue->cTxLock;
1131 const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;
1133 traceQUEUE_SEND_FROM_ISR( pxQueue );
1135 /* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a
1136 * semaphore or mutex. That means prvCopyDataToQueue() cannot result
1137 * in a task disinheriting a priority and prvCopyDataToQueue() can be
1138 * called here even though the disinherit function does not check if
1139 * the scheduler is suspended before accessing the ready lists. */
1140 ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
1142 /* The event list is not altered if the queue is locked. This will
1143 * be done when the queue is unlocked later. */
1144 if( cTxLock == queueUNLOCKED )
1146 #if ( configUSE_QUEUE_SETS == 1 )
1148 if( pxQueue->pxQueueSetContainer != NULL )
1150 if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )
1152 /* Do not notify the queue set as an existing item
1153 * was overwritten in the queue so the number of items
1154 * in the queue has not changed. */
1155 mtCOVERAGE_TEST_MARKER();
1157 else if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
1159 /* The queue is a member of a queue set, and posting
1160 * to the queue set caused a higher priority task to
1161 * unblock. A context switch is required. */
1162 if( pxHigherPriorityTaskWoken != NULL )
1164 *pxHigherPriorityTaskWoken = pdTRUE;
1168 mtCOVERAGE_TEST_MARKER();
1173 mtCOVERAGE_TEST_MARKER();
1178 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1180 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1182 /* The task waiting has a higher priority so
1183 * record that a context switch is required. */
1184 if( pxHigherPriorityTaskWoken != NULL )
1186 *pxHigherPriorityTaskWoken = pdTRUE;
1190 mtCOVERAGE_TEST_MARKER();
1195 mtCOVERAGE_TEST_MARKER();
1200 mtCOVERAGE_TEST_MARKER();
1204 #else /* configUSE_QUEUE_SETS */
1206 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1208 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1210 /* The task waiting has a higher priority so record that a
1211 * context switch is required. */
1212 if( pxHigherPriorityTaskWoken != NULL )
1214 *pxHigherPriorityTaskWoken = pdTRUE;
1218 mtCOVERAGE_TEST_MARKER();
1223 mtCOVERAGE_TEST_MARKER();
1228 mtCOVERAGE_TEST_MARKER();
1231 /* Not used in this path. */
1232 ( void ) uxPreviousMessagesWaiting;
1234 #endif /* configUSE_QUEUE_SETS */
1238 /* Increment the lock count so the task that unlocks the queue
1239 * knows that data was posted while it was locked. */
1240 prvIncrementQueueTxLock( pxQueue, cTxLock );
1247 traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
1248 xReturn = errQUEUE_FULL;
1251 portCLEAR_INTERRUPT_MASK_FROM_ISR( xSavedInterruptStatus );
1255 /*-----------------------------------------------------------*/
1257 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
1258 BaseType_t * const pxHigherPriorityTaskWoken )
1261 portBASE_TYPE xSavedInterruptStatus;
1262 Queue_t * const pxQueue = xQueue;
1264 /* Similar to xQueueGenericSendFromISR() but used with semaphores where the
1265 * item size is 0. Don't directly wake a task that was blocked on a queue
1266 * read, instead return a flag to say whether a context switch is required or
1267 * not (i.e. has a task with a higher priority than us been woken by this
1270 configASSERT( pxQueue );
1272 /* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR()
1273 * if the item size is not 0. */
1274 configASSERT( pxQueue->uxItemSize == 0 );
1276 /* Normally a mutex would not be given from an interrupt, especially if
1277 * there is a mutex holder, as priority inheritance makes no sense for an
1278 * interrupts, only tasks. */
1279 configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->u.xSemaphore.xMutexHolder != NULL ) ) );
1281 /* RTOS ports that support interrupt nesting have the concept of a maximum
1282 * system call (or maximum API call) interrupt priority. Interrupts that are
1283 * above the maximum system call priority are kept permanently enabled, even
1284 * when the RTOS kernel is in a critical section, but cannot make any calls to
1285 * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
1286 * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
1287 * failure if a FreeRTOS API function is called from an interrupt that has been
1288 * assigned a priority above the configured maximum system call priority.
1289 * Only FreeRTOS functions that end in FromISR can be called from interrupts
1290 * that have been assigned a priority at or (logically) below the maximum
1291 * system call interrupt priority. FreeRTOS maintains a separate interrupt
1292 * safe API to ensure interrupt entry is as fast and as simple as possible.
1293 * More information (albeit Cortex-M specific) is provided on the following
1294 * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
1295 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
1297 xSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
1299 const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
1301 /* When the queue is used to implement a semaphore no data is ever
1302 * moved through the queue but it is still valid to see if the queue 'has
1304 if( uxMessagesWaiting < pxQueue->uxLength )
1306 const int8_t cTxLock = pxQueue->cTxLock;
1308 traceQUEUE_SEND_FROM_ISR( pxQueue );
1310 /* A task can only have an inherited priority if it is a mutex
1311 * holder - and if there is a mutex holder then the mutex cannot be
1312 * given from an ISR. As this is the ISR version of the function it
1313 * can be assumed there is no mutex holder and no need to determine if
1314 * priority disinheritance is needed. Simply increase the count of
1315 * messages (semaphores) available. */
1316 pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1;
1318 /* The event list is not altered if the queue is locked. This will
1319 * be done when the queue is unlocked later. */
1320 if( cTxLock == queueUNLOCKED )
1322 #if ( configUSE_QUEUE_SETS == 1 )
1324 if( pxQueue->pxQueueSetContainer != NULL )
1326 if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
1328 /* The semaphore is a member of a queue set, and
1329 * posting to the queue set caused a higher priority
1330 * task to unblock. A context switch is required. */
1331 if( pxHigherPriorityTaskWoken != NULL )
1333 *pxHigherPriorityTaskWoken = pdTRUE;
1337 mtCOVERAGE_TEST_MARKER();
1342 mtCOVERAGE_TEST_MARKER();
1347 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1349 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1351 /* The task waiting has a higher priority so
1352 * record that a context switch is required. */
1353 if( pxHigherPriorityTaskWoken != NULL )
1355 *pxHigherPriorityTaskWoken = pdTRUE;
1359 mtCOVERAGE_TEST_MARKER();
1364 mtCOVERAGE_TEST_MARKER();
1369 mtCOVERAGE_TEST_MARKER();
1373 #else /* configUSE_QUEUE_SETS */
1375 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1377 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1379 /* The task waiting has a higher priority so record that a
1380 * context switch is required. */
1381 if( pxHigherPriorityTaskWoken != NULL )
1383 *pxHigherPriorityTaskWoken = pdTRUE;
1387 mtCOVERAGE_TEST_MARKER();
1392 mtCOVERAGE_TEST_MARKER();
1397 mtCOVERAGE_TEST_MARKER();
1400 #endif /* configUSE_QUEUE_SETS */
1404 /* Increment the lock count so the task that unlocks the queue
1405 * knows that data was posted while it was locked. */
1406 prvIncrementQueueTxLock( pxQueue, cTxLock );
1413 traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
1414 xReturn = errQUEUE_FULL;
1417 portCLEAR_INTERRUPT_MASK_FROM_ISR( xSavedInterruptStatus );
1421 /*-----------------------------------------------------------*/
1423 BaseType_t xQueueReceive( QueueHandle_t xQueue,
1424 void * const pvBuffer,
1425 TickType_t xTicksToWait )
1427 BaseType_t xEntryTimeSet = pdFALSE;
1429 Queue_t * const pxQueue = xQueue;
1431 /* Check the pointer is not NULL. */
1432 configASSERT( ( pxQueue ) );
1434 /* The buffer into which data is received can only be NULL if the data size
1435 * is zero (so no data is copied into the buffer). */
1436 configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
1438 /* Cannot block if the scheduler is suspended. */
1439 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
1441 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
1445 /*lint -save -e904 This function relaxes the coding standard somewhat to
1446 * allow return statements within the function itself. This is done in the
1447 * interest of execution time efficiency. */
1450 taskENTER_CRITICAL();
1452 const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
1454 /* Is there data in the queue now? To be running the calling task
1455 * must be the highest priority task wanting to access the queue. */
1456 if( uxMessagesWaiting > ( UBaseType_t ) 0 )
1458 /* Data available, remove one item. */
1459 prvCopyDataFromQueue( pxQueue, pvBuffer );
1460 traceQUEUE_RECEIVE( pxQueue );
1461 pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;
1463 /* There is now space in the queue, were any tasks waiting to
1464 * post to the queue? If so, unblock the highest priority waiting
1466 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
1468 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
1470 queueYIELD_IF_USING_PREEMPTION();
1474 mtCOVERAGE_TEST_MARKER();
1479 mtCOVERAGE_TEST_MARKER();
1482 taskEXIT_CRITICAL();
1487 if( xTicksToWait == ( TickType_t ) 0 )
1489 /* The queue was empty and no block time is specified (or
1490 * the block time has expired) so leave now. */
1491 taskEXIT_CRITICAL();
1492 traceQUEUE_RECEIVE_FAILED( pxQueue );
1493 return errQUEUE_EMPTY;
1495 else if( xEntryTimeSet == pdFALSE )
1497 /* The queue was empty and a block time was specified so
1498 * configure the timeout structure. */
1499 vTaskInternalSetTimeOutState( &xTimeOut );
1500 xEntryTimeSet = pdTRUE;
1504 /* Entry time was already set. */
1505 mtCOVERAGE_TEST_MARKER();
1509 taskEXIT_CRITICAL();
1511 /* Interrupts and other tasks can send to and receive from the queue
1512 * now the critical section has been exited. */
1515 prvLockQueue( pxQueue );
1517 /* Update the timeout state to see if it has expired yet. */
1518 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
1520 /* The timeout has not expired. If the queue is still empty place
1521 * the task on the list of tasks waiting to receive from the queue. */
1522 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1524 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
1525 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
1526 prvUnlockQueue( pxQueue );
1528 if( xTaskResumeAll() == pdFALSE )
1530 portYIELD_WITHIN_API();
1534 mtCOVERAGE_TEST_MARKER();
1539 /* The queue contains data again. Loop back to try and read the
1541 prvUnlockQueue( pxQueue );
1542 ( void ) xTaskResumeAll();
1547 /* Timed out. If there is no data in the queue exit, otherwise loop
1548 * back and attempt to read the data. */
1549 prvUnlockQueue( pxQueue );
1550 ( void ) xTaskResumeAll();
1552 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1554 traceQUEUE_RECEIVE_FAILED( pxQueue );
1555 return errQUEUE_EMPTY;
1559 mtCOVERAGE_TEST_MARKER();
1562 } /*lint -restore */
1564 /*-----------------------------------------------------------*/
1566 BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
1567 TickType_t xTicksToWait )
1569 BaseType_t xEntryTimeSet = pdFALSE;
1571 Queue_t * const pxQueue = xQueue;
1573 #if ( configUSE_MUTEXES == 1 )
1574 BaseType_t xInheritanceOccurred = pdFALSE;
1577 /* Check the queue pointer is not NULL. */
1578 configASSERT( ( pxQueue ) );
1580 /* Check this really is a semaphore, in which case the item size will be
1582 configASSERT( pxQueue->uxItemSize == 0 );
1584 /* Cannot block if the scheduler is suspended. */
1585 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
1587 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
1591 /*lint -save -e904 This function relaxes the coding standard somewhat to allow return
1592 * statements within the function itself. This is done in the interest
1593 * of execution time efficiency. */
1596 taskENTER_CRITICAL();
1598 /* Semaphores are queues with an item size of 0, and where the
1599 * number of messages in the queue is the semaphore's count value. */
1600 const UBaseType_t uxSemaphoreCount = pxQueue->uxMessagesWaiting;
1602 /* Is there data in the queue now? To be running the calling task
1603 * must be the highest priority task wanting to access the queue. */
1604 if( uxSemaphoreCount > ( UBaseType_t ) 0 )
1606 traceQUEUE_RECEIVE( pxQueue );
1608 /* Semaphores are queues with a data size of zero and where the
1609 * messages waiting is the semaphore's count. Reduce the count. */
1610 pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1;
1612 #if ( configUSE_MUTEXES == 1 )
1614 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
1616 /* Record the information required to implement
1617 * priority inheritance should it become necessary. */
1618 pxQueue->u.xSemaphore.xMutexHolder = pvTaskIncrementMutexHeldCount();
1622 mtCOVERAGE_TEST_MARKER();
1625 #endif /* configUSE_MUTEXES */
1627 /* Check to see if other tasks are blocked waiting to give the
1628 * semaphore, and if so, unblock the highest priority such task. */
1629 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
1631 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
1633 queueYIELD_IF_USING_PREEMPTION();
1637 mtCOVERAGE_TEST_MARKER();
1642 mtCOVERAGE_TEST_MARKER();
1645 taskEXIT_CRITICAL();
1650 if( xTicksToWait == ( TickType_t ) 0 )
1652 /* The semaphore count was 0 and no block time is specified
1653 * (or the block time has expired) so exit now. */
1654 taskEXIT_CRITICAL();
1655 traceQUEUE_RECEIVE_FAILED( pxQueue );
1656 return errQUEUE_EMPTY;
1658 else if( xEntryTimeSet == pdFALSE )
1660 /* The semaphore count was 0 and a block time was specified
1661 * so configure the timeout structure ready to block. */
1662 vTaskInternalSetTimeOutState( &xTimeOut );
1663 xEntryTimeSet = pdTRUE;
1667 /* Entry time was already set. */
1668 mtCOVERAGE_TEST_MARKER();
1672 taskEXIT_CRITICAL();
1674 /* Interrupts and other tasks can give to and take from the semaphore
1675 * now the critical section has been exited. */
1678 prvLockQueue( pxQueue );
1680 /* Update the timeout state to see if it has expired yet. */
1681 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
1683 /* A block time is specified and not expired. If the semaphore
1684 * count is 0 then enter the Blocked state to wait for a semaphore to
1685 * become available. As semaphores are implemented with queues the
1686 * queue being empty is equivalent to the semaphore count being 0. */
1687 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1689 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
1691 #if ( configUSE_MUTEXES == 1 )
1693 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
1695 taskENTER_CRITICAL();
1697 xInheritanceOccurred = xTaskPriorityInherit( pxQueue->u.xSemaphore.xMutexHolder );
1699 taskEXIT_CRITICAL();
1703 mtCOVERAGE_TEST_MARKER();
1706 #endif /* if ( configUSE_MUTEXES == 1 ) */
1708 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
1709 prvUnlockQueue( pxQueue );
1711 if( xTaskResumeAll() == pdFALSE )
1713 portYIELD_WITHIN_API();
1717 mtCOVERAGE_TEST_MARKER();
1722 /* There was no timeout and the semaphore count was not 0, so
1723 * attempt to take the semaphore again. */
1724 prvUnlockQueue( pxQueue );
1725 ( void ) xTaskResumeAll();
1731 prvUnlockQueue( pxQueue );
1732 ( void ) xTaskResumeAll();
1734 /* If the semaphore count is 0 exit now as the timeout has
1735 * expired. Otherwise return to attempt to take the semaphore that is
1736 * known to be available. As semaphores are implemented by queues the
1737 * queue being empty is equivalent to the semaphore count being 0. */
1738 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1740 #if ( configUSE_MUTEXES == 1 )
1742 /* xInheritanceOccurred could only have be set if
1743 * pxQueue->uxQueueType == queueQUEUE_IS_MUTEX so no need to
1744 * test the mutex type again to check it is actually a mutex. */
1745 if( xInheritanceOccurred != pdFALSE )
1747 taskENTER_CRITICAL();
1749 UBaseType_t uxHighestWaitingPriority;
1751 /* This task blocking on the mutex caused another
1752 * task to inherit this task's priority. Now this task
1753 * has timed out the priority should be disinherited
1754 * again, but only as low as the next highest priority
1755 * task that is waiting for the same mutex. */
1756 uxHighestWaitingPriority = prvGetDisinheritPriorityAfterTimeout( pxQueue );
1757 vTaskPriorityDisinheritAfterTimeout( pxQueue->u.xSemaphore.xMutexHolder, uxHighestWaitingPriority );
1759 taskEXIT_CRITICAL();
1762 #endif /* configUSE_MUTEXES */
1764 traceQUEUE_RECEIVE_FAILED( pxQueue );
1765 return errQUEUE_EMPTY;
1769 mtCOVERAGE_TEST_MARKER();
1772 } /*lint -restore */
1774 /*-----------------------------------------------------------*/
1776 BaseType_t xQueuePeek( QueueHandle_t xQueue,
1777 void * const pvBuffer,
1778 TickType_t xTicksToWait )
1780 BaseType_t xEntryTimeSet = pdFALSE;
1782 int8_t * pcOriginalReadPosition;
1783 Queue_t * const pxQueue = xQueue;
1785 /* Check the pointer is not NULL. */
1786 configASSERT( ( pxQueue ) );
1788 /* The buffer into which data is received can only be NULL if the data size
1789 * is zero (so no data is copied into the buffer. */
1790 configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
1792 /* Cannot block if the scheduler is suspended. */
1793 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
1795 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
1799 /*lint -save -e904 This function relaxes the coding standard somewhat to
1800 * allow return statements within the function itself. This is done in the
1801 * interest of execution time efficiency. */
1804 taskENTER_CRITICAL();
1806 const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
1808 /* Is there data in the queue now? To be running the calling task
1809 * must be the highest priority task wanting to access the queue. */
1810 if( uxMessagesWaiting > ( UBaseType_t ) 0 )
1812 /* Remember the read position so it can be reset after the data
1813 * is read from the queue as this function is only peeking the
1814 * data, not removing it. */
1815 pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom;
1817 prvCopyDataFromQueue( pxQueue, pvBuffer );
1818 traceQUEUE_PEEK( pxQueue );
1820 /* The data is not being removed, so reset the read pointer. */
1821 pxQueue->u.xQueue.pcReadFrom = pcOriginalReadPosition;
1823 /* The data is being left in the queue, so see if there are
1824 * any other tasks waiting for the data. */
1825 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
1827 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
1829 /* The task waiting has a higher priority than this task. */
1830 queueYIELD_IF_USING_PREEMPTION();
1834 mtCOVERAGE_TEST_MARKER();
1839 mtCOVERAGE_TEST_MARKER();
1842 taskEXIT_CRITICAL();
1847 if( xTicksToWait == ( TickType_t ) 0 )
1849 /* The queue was empty and no block time is specified (or
1850 * the block time has expired) so leave now. */
1851 taskEXIT_CRITICAL();
1852 traceQUEUE_PEEK_FAILED( pxQueue );
1853 return errQUEUE_EMPTY;
1855 else if( xEntryTimeSet == pdFALSE )
1857 /* The queue was empty and a block time was specified so
1858 * configure the timeout structure ready to enter the blocked
1860 vTaskInternalSetTimeOutState( &xTimeOut );
1861 xEntryTimeSet = pdTRUE;
1865 /* Entry time was already set. */
1866 mtCOVERAGE_TEST_MARKER();
1870 taskEXIT_CRITICAL();
1872 /* Interrupts and other tasks can send to and receive from the queue
1873 * now that the critical section has been exited. */
1876 prvLockQueue( pxQueue );
1878 /* Update the timeout state to see if it has expired yet. */
1879 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
1881 /* Timeout has not expired yet, check to see if there is data in the
1882 * queue now, and if not enter the Blocked state to wait for data. */
1883 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1885 traceBLOCKING_ON_QUEUE_PEEK( pxQueue );
1886 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
1887 prvUnlockQueue( pxQueue );
1889 if( xTaskResumeAll() == pdFALSE )
1891 portYIELD_WITHIN_API();
1895 mtCOVERAGE_TEST_MARKER();
1900 /* There is data in the queue now, so don't enter the blocked
1901 * state, instead return to try and obtain the data. */
1902 prvUnlockQueue( pxQueue );
1903 ( void ) xTaskResumeAll();
1908 /* The timeout has expired. If there is still no data in the queue
1909 * exit, otherwise go back and try to read the data again. */
1910 prvUnlockQueue( pxQueue );
1911 ( void ) xTaskResumeAll();
1913 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
1915 traceQUEUE_PEEK_FAILED( pxQueue );
1916 return errQUEUE_EMPTY;
1920 mtCOVERAGE_TEST_MARKER();
1923 } /*lint -restore */
1925 /*-----------------------------------------------------------*/
1927 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
1928 void * const pvBuffer,
1929 BaseType_t * const pxHigherPriorityTaskWoken )
1932 portBASE_TYPE xSavedInterruptStatus;
1933 Queue_t * const pxQueue = xQueue;
1935 configASSERT( pxQueue );
1936 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
1938 /* RTOS ports that support interrupt nesting have the concept of a maximum
1939 * system call (or maximum API call) interrupt priority. Interrupts that are
1940 * above the maximum system call priority are kept permanently enabled, even
1941 * when the RTOS kernel is in a critical section, but cannot make any calls to
1942 * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
1943 * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
1944 * failure if a FreeRTOS API function is called from an interrupt that has been
1945 * assigned a priority above the configured maximum system call priority.
1946 * Only FreeRTOS functions that end in FromISR can be called from interrupts
1947 * that have been assigned a priority at or (logically) below the maximum
1948 * system call interrupt priority. FreeRTOS maintains a separate interrupt
1949 * safe API to ensure interrupt entry is as fast and as simple as possible.
1950 * More information (albeit Cortex-M specific) is provided on the following
1951 * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
1952 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
1954 xSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
1956 const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
1958 /* Cannot block in an ISR, so check there is data available. */
1959 if( uxMessagesWaiting > ( UBaseType_t ) 0 )
1961 const int8_t cRxLock = pxQueue->cRxLock;
1963 traceQUEUE_RECEIVE_FROM_ISR( pxQueue );
1965 prvCopyDataFromQueue( pxQueue, pvBuffer );
1966 pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;
1968 /* If the queue is locked the event list will not be modified.
1969 * Instead update the lock count so the task that unlocks the queue
1970 * will know that an ISR has removed data while the queue was
1972 if( cRxLock == queueUNLOCKED )
1974 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
1976 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
1978 /* The task waiting has a higher priority than us so
1979 * force a context switch. */
1980 if( pxHigherPriorityTaskWoken != NULL )
1982 *pxHigherPriorityTaskWoken = pdTRUE;
1986 mtCOVERAGE_TEST_MARKER();
1991 mtCOVERAGE_TEST_MARKER();
1996 mtCOVERAGE_TEST_MARKER();
2001 /* Increment the lock count so the task that unlocks the queue
2002 * knows that data was removed while it was locked. */
2003 prvIncrementQueueRxLock( pxQueue, cRxLock );
2011 traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );
2014 portCLEAR_INTERRUPT_MASK_FROM_ISR( xSavedInterruptStatus );
2018 /*-----------------------------------------------------------*/
2020 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
2021 void * const pvBuffer )
2024 portBASE_TYPE xSavedInterruptStatus;
2025 int8_t * pcOriginalReadPosition;
2026 Queue_t * const pxQueue = xQueue;
2028 configASSERT( pxQueue );
2029 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
2030 configASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */
2032 /* RTOS ports that support interrupt nesting have the concept of a maximum
2033 * system call (or maximum API call) interrupt priority. Interrupts that are
2034 * above the maximum system call priority are kept permanently enabled, even
2035 * when the RTOS kernel is in a critical section, but cannot make any calls to
2036 * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
2037 * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
2038 * failure if a FreeRTOS API function is called from an interrupt that has been
2039 * assigned a priority above the configured maximum system call priority.
2040 * Only FreeRTOS functions that end in FromISR can be called from interrupts
2041 * that have been assigned a priority at or (logically) below the maximum
2042 * system call interrupt priority. FreeRTOS maintains a separate interrupt
2043 * safe API to ensure interrupt entry is as fast and as simple as possible.
2044 * More information (albeit Cortex-M specific) is provided on the following
2045 * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
2046 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
2048 xSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
2050 /* Cannot block in an ISR, so check there is data available. */
2051 if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )
2053 traceQUEUE_PEEK_FROM_ISR( pxQueue );
2055 /* Remember the read position so it can be reset as nothing is
2056 * actually being removed from the queue. */
2057 pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom;
2058 prvCopyDataFromQueue( pxQueue, pvBuffer );
2059 pxQueue->u.xQueue.pcReadFrom = pcOriginalReadPosition;
2066 traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );
2069 portCLEAR_INTERRUPT_MASK_FROM_ISR( xSavedInterruptStatus );
2073 /*-----------------------------------------------------------*/
2075 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue )
2077 UBaseType_t uxReturn;
2079 configASSERT( xQueue );
2081 taskENTER_CRITICAL();
2083 uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting;
2085 taskEXIT_CRITICAL();
2088 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
2089 /*-----------------------------------------------------------*/
2091 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
2093 UBaseType_t uxReturn;
2094 Queue_t * const pxQueue = xQueue;
2096 configASSERT( pxQueue );
2098 taskENTER_CRITICAL();
2100 uxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting;
2102 taskEXIT_CRITICAL();
2105 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
2106 /*-----------------------------------------------------------*/
2108 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue )
2110 UBaseType_t uxReturn;
2111 Queue_t * const pxQueue = xQueue;
2113 configASSERT( pxQueue );
2114 uxReturn = pxQueue->uxMessagesWaiting;
2117 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
2118 /*-----------------------------------------------------------*/
2120 void vQueueDelete( QueueHandle_t xQueue )
2122 Queue_t * const pxQueue = xQueue;
2124 configASSERT( pxQueue );
2125 traceQUEUE_DELETE( pxQueue );
2127 #if ( configQUEUE_REGISTRY_SIZE > 0 )
2129 vQueueUnregisterQueue( pxQueue );
2133 #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
2135 /* The queue can only have been allocated dynamically - free it
2137 vPortFree( pxQueue );
2139 #elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
2141 /* The queue could have been allocated statically or dynamically, so
2142 * check before attempting to free the memory. */
2143 if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
2145 vPortFree( pxQueue );
2149 mtCOVERAGE_TEST_MARKER();
2152 #else /* if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) */
2154 /* The queue must have been statically allocated, so is not going to be
2155 * deleted. Avoid compiler warnings about the unused parameter. */
2158 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
2160 /*-----------------------------------------------------------*/
2162 #if ( configUSE_TRACE_FACILITY == 1 )
2164 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue )
2166 return ( ( Queue_t * ) xQueue )->uxQueueNumber;
2169 #endif /* configUSE_TRACE_FACILITY */
2170 /*-----------------------------------------------------------*/
2172 #if ( configUSE_TRACE_FACILITY == 1 )
2174 void vQueueSetQueueNumber( QueueHandle_t xQueue,
2175 UBaseType_t uxQueueNumber )
2177 ( ( Queue_t * ) xQueue )->uxQueueNumber = uxQueueNumber;
2180 #endif /* configUSE_TRACE_FACILITY */
2181 /*-----------------------------------------------------------*/
2183 #if ( configUSE_TRACE_FACILITY == 1 )
2185 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue )
2187 return ( ( Queue_t * ) xQueue )->ucQueueType;
2190 #endif /* configUSE_TRACE_FACILITY */
2191 /*-----------------------------------------------------------*/
2193 #if ( configUSE_MUTEXES == 1 )
2195 static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue )
2197 UBaseType_t uxHighestPriorityOfWaitingTasks;
2199 /* If a task waiting for a mutex causes the mutex holder to inherit a
2200 * priority, but the waiting task times out, then the holder should
2201 * disinherit the priority - but only down to the highest priority of any
2202 * other tasks that are waiting for the same mutex. For this purpose,
2203 * return the priority of the highest priority task that is waiting for the
2205 if( listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) ) > 0U )
2207 uxHighestPriorityOfWaitingTasks = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) );
2211 uxHighestPriorityOfWaitingTasks = tskIDLE_PRIORITY;
2214 return uxHighestPriorityOfWaitingTasks;
2217 #endif /* configUSE_MUTEXES */
2218 /*-----------------------------------------------------------*/
2220 static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
2221 const void * pvItemToQueue,
2222 const BaseType_t xPosition )
2224 BaseType_t xReturn = pdFALSE;
2225 UBaseType_t uxMessagesWaiting;
2227 /* This function is called from a critical section. */
2229 uxMessagesWaiting = pxQueue->uxMessagesWaiting;
2231 if( pxQueue->uxItemSize == ( UBaseType_t ) 0 )
2233 #if ( configUSE_MUTEXES == 1 )
2235 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
2237 /* The mutex is no longer being held. */
2238 xReturn = xTaskPriorityDisinherit( pxQueue->u.xSemaphore.xMutexHolder );
2239 pxQueue->u.xSemaphore.xMutexHolder = NULL;
2243 mtCOVERAGE_TEST_MARKER();
2246 #endif /* configUSE_MUTEXES */
2248 else if( xPosition == queueSEND_TO_BACK )
2250 ( 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. */
2251 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. */
2253 if( pxQueue->pcWriteTo >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
2255 pxQueue->pcWriteTo = pxQueue->pcHead;
2259 mtCOVERAGE_TEST_MARKER();
2264 ( 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. */
2265 pxQueue->u.xQueue.pcReadFrom -= pxQueue->uxItemSize;
2267 if( pxQueue->u.xQueue.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
2269 pxQueue->u.xQueue.pcReadFrom = ( pxQueue->u.xQueue.pcTail - pxQueue->uxItemSize );
2273 mtCOVERAGE_TEST_MARKER();
2276 if( xPosition == queueOVERWRITE )
2278 if( uxMessagesWaiting > ( UBaseType_t ) 0 )
2280 /* An item is not being added but overwritten, so subtract
2281 * one from the recorded number of items in the queue so when
2282 * one is added again below the number of recorded items remains
2284 --uxMessagesWaiting;
2288 mtCOVERAGE_TEST_MARKER();
2293 mtCOVERAGE_TEST_MARKER();
2297 pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1;
2301 /*-----------------------------------------------------------*/
2303 static void prvCopyDataFromQueue( Queue_t * const pxQueue,
2304 void * const pvBuffer )
2306 if( pxQueue->uxItemSize != ( UBaseType_t ) 0 )
2308 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. */
2310 if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */
2312 pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead;
2316 mtCOVERAGE_TEST_MARKER();
2319 ( 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. */
2322 /*-----------------------------------------------------------*/
2324 static void prvUnlockQueue( Queue_t * const pxQueue )
2326 /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
2328 /* The lock counts contains the number of extra data items placed or
2329 * removed from the queue while the queue was locked. When a queue is
2330 * locked items can be added or removed, but the event lists cannot be
2332 taskENTER_CRITICAL();
2334 int8_t cTxLock = pxQueue->cTxLock;
2336 /* See if data was added to the queue while it was locked. */
2337 while( cTxLock > queueLOCKED_UNMODIFIED )
2339 /* Data was posted while the queue was locked. Are any tasks
2340 * blocked waiting for data to become available? */
2341 #if ( configUSE_QUEUE_SETS == 1 )
2343 if( pxQueue->pxQueueSetContainer != NULL )
2345 if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
2347 /* The queue is a member of a queue set, and posting to
2348 * the queue set caused a higher priority task to unblock.
2349 * A context switch is required. */
2354 mtCOVERAGE_TEST_MARKER();
2359 /* Tasks that are removed from the event list will get
2360 * added to the pending ready list as the scheduler is still
2362 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
2364 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
2366 /* The task waiting has a higher priority so record that a
2367 * context switch is required. */
2372 mtCOVERAGE_TEST_MARKER();
2381 #else /* configUSE_QUEUE_SETS */
2383 /* Tasks that are removed from the event list will get added to
2384 * the pending ready list as the scheduler is still suspended. */
2385 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
2387 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
2389 /* The task waiting has a higher priority so record that
2390 * a context switch is required. */
2395 mtCOVERAGE_TEST_MARKER();
2403 #endif /* configUSE_QUEUE_SETS */
2408 pxQueue->cTxLock = queueUNLOCKED;
2410 taskEXIT_CRITICAL();
2412 /* Do the same for the Rx lock. */
2413 taskENTER_CRITICAL();
2415 int8_t cRxLock = pxQueue->cRxLock;
2417 while( cRxLock > queueLOCKED_UNMODIFIED )
2419 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
2421 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
2427 mtCOVERAGE_TEST_MARKER();
2438 pxQueue->cRxLock = queueUNLOCKED;
2440 taskEXIT_CRITICAL();
2442 /*-----------------------------------------------------------*/
2444 static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue )
2448 taskENTER_CRITICAL();
2450 if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 )
2459 taskEXIT_CRITICAL();
2463 /*-----------------------------------------------------------*/
2465 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )
2468 Queue_t * const pxQueue = xQueue;
2470 configASSERT( pxQueue );
2472 if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 )
2482 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
2483 /*-----------------------------------------------------------*/
2485 static BaseType_t prvIsQueueFull( const Queue_t * pxQueue )
2489 taskENTER_CRITICAL();
2491 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
2500 taskEXIT_CRITICAL();
2504 /*-----------------------------------------------------------*/
2506 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
2509 Queue_t * const pxQueue = xQueue;
2511 configASSERT( pxQueue );
2513 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
2523 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
2524 /*-----------------------------------------------------------*/
2526 #if ( configQUEUE_REGISTRY_SIZE > 0 )
2528 void vQueueAddToRegistry( QueueHandle_t xQueue,
2529 const char * pcQueueName ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
2532 QueueRegistryItem_t * pxEntryToWrite = NULL;
2534 configASSERT( xQueue );
2536 if( pcQueueName != NULL )
2538 /* See if there is an empty space in the registry. A NULL name denotes
2540 for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ )
2542 /* Replace an existing entry if the queue is already in the registry. */
2543 if( xQueue == xQueueRegistry[ ux ].xHandle )
2545 pxEntryToWrite = &( xQueueRegistry[ ux ] );
2548 /* Otherwise, store in the next empty location */
2549 else if( ( pxEntryToWrite == NULL ) && ( xQueueRegistry[ ux ].pcQueueName == NULL ) )
2551 pxEntryToWrite = &( xQueueRegistry[ ux ] );
2555 mtCOVERAGE_TEST_MARKER();
2560 if( pxEntryToWrite != NULL )
2562 /* Store the information on this queue. */
2563 pxEntryToWrite->pcQueueName = pcQueueName;
2564 pxEntryToWrite->xHandle = xQueue;
2566 traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName );
2570 #endif /* configQUEUE_REGISTRY_SIZE */
2571 /*-----------------------------------------------------------*/
2573 #if ( configQUEUE_REGISTRY_SIZE > 0 )
2575 const char * pcQueueGetName( QueueHandle_t xQueue ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
2578 const char * pcReturn = NULL; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
2580 configASSERT( xQueue );
2582 /* Note there is nothing here to protect against another task adding or
2583 * removing entries from the registry while it is being searched. */
2585 for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ )
2587 if( xQueueRegistry[ ux ].xHandle == xQueue )
2589 pcReturn = xQueueRegistry[ ux ].pcQueueName;
2594 mtCOVERAGE_TEST_MARKER();
2599 } /*lint !e818 xQueue cannot be a pointer to const because it is a typedef. */
2601 #endif /* configQUEUE_REGISTRY_SIZE */
2602 /*-----------------------------------------------------------*/
2604 #if ( configQUEUE_REGISTRY_SIZE > 0 )
2606 void vQueueUnregisterQueue( QueueHandle_t xQueue )
2610 configASSERT( xQueue );
2612 /* See if the handle of the queue being unregistered in actually in the
2614 for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ )
2616 if( xQueueRegistry[ ux ].xHandle == xQueue )
2618 /* Set the name to NULL to show that this slot if free again. */
2619 xQueueRegistry[ ux ].pcQueueName = NULL;
2621 /* Set the handle to NULL to ensure the same queue handle cannot
2622 * appear in the registry twice if it is added, removed, then
2624 xQueueRegistry[ ux ].xHandle = ( QueueHandle_t ) 0;
2629 mtCOVERAGE_TEST_MARKER();
2632 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
2634 #endif /* configQUEUE_REGISTRY_SIZE */
2635 /*-----------------------------------------------------------*/
2637 #if ( configUSE_TIMERS == 1 )
2639 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
2640 TickType_t xTicksToWait,
2641 const BaseType_t xWaitIndefinitely )
2643 Queue_t * const pxQueue = xQueue;
2645 /* This function should not be called by application code hence the
2646 * 'Restricted' in its name. It is not part of the public API. It is
2647 * designed for use by kernel code, and has special calling requirements.
2648 * It can result in vListInsert() being called on a list that can only
2649 * possibly ever have one item in it, so the list will be fast, but even
2650 * so it should be called with the scheduler locked and not from a critical
2653 /* Only do anything if there are no messages in the queue. This function
2654 * will not actually cause the task to block, just place it on a blocked
2655 * list. It will not block until the scheduler is unlocked - at which
2656 * time a yield will be performed. If an item is added to the queue while
2657 * the queue is locked, and the calling task blocks on the queue, then the
2658 * calling task will be immediately unblocked when the queue is unlocked. */
2659 prvLockQueue( pxQueue );
2661 if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0U )
2663 /* There is nothing in the queue, block for the specified period. */
2664 vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait, xWaitIndefinitely );
2668 mtCOVERAGE_TEST_MARKER();
2671 prvUnlockQueue( pxQueue );
2674 #endif /* configUSE_TIMERS */
2675 /*-----------------------------------------------------------*/
2677 #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
2679 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength )
2681 QueueSetHandle_t pxQueue;
2683 pxQueue = xQueueGenericCreate( uxEventQueueLength, ( UBaseType_t ) sizeof( Queue_t * ), queueQUEUE_TYPE_SET );
2688 #endif /* configUSE_QUEUE_SETS */
2689 /*-----------------------------------------------------------*/
2691 #if ( configUSE_QUEUE_SETS == 1 )
2693 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
2694 QueueSetHandle_t xQueueSet )
2698 taskENTER_CRITICAL();
2700 if( ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )
2702 /* Cannot add a queue/semaphore to more than one queue set. */
2705 else if( ( ( Queue_t * ) xQueueOrSemaphore )->uxMessagesWaiting != ( UBaseType_t ) 0 )
2707 /* Cannot add a queue/semaphore to a queue set if there are already
2708 * items in the queue/semaphore. */
2713 ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;
2717 taskEXIT_CRITICAL();
2722 #endif /* configUSE_QUEUE_SETS */
2723 /*-----------------------------------------------------------*/
2725 #if ( configUSE_QUEUE_SETS == 1 )
2727 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
2728 QueueSetHandle_t xQueueSet )
2731 Queue_t * const pxQueueOrSemaphore = ( Queue_t * ) xQueueOrSemaphore;
2733 if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )
2735 /* The queue was not a member of the set. */
2738 else if( pxQueueOrSemaphore->uxMessagesWaiting != ( UBaseType_t ) 0 )
2740 /* It is dangerous to remove a queue from a set when the queue is
2741 * not empty because the queue set will still hold pending events for
2747 taskENTER_CRITICAL();
2749 /* The queue is no longer contained in the set. */
2750 pxQueueOrSemaphore->pxQueueSetContainer = NULL;
2752 taskEXIT_CRITICAL();
2757 } /*lint !e818 xQueueSet could not be declared as pointing to const as it is a typedef. */
2759 #endif /* configUSE_QUEUE_SETS */
2760 /*-----------------------------------------------------------*/
2762 #if ( configUSE_QUEUE_SETS == 1 )
2764 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
2765 TickType_t const xTicksToWait )
2767 QueueSetMemberHandle_t xReturn = NULL;
2769 ( void ) xQueueReceive( ( QueueHandle_t ) xQueueSet, &xReturn, xTicksToWait ); /*lint !e961 Casting from one typedef to another is not redundant. */
2773 #endif /* configUSE_QUEUE_SETS */
2774 /*-----------------------------------------------------------*/
2776 #if ( configUSE_QUEUE_SETS == 1 )
2778 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet )
2780 QueueSetMemberHandle_t xReturn = NULL;
2782 ( void ) xQueueReceiveFromISR( ( QueueHandle_t ) xQueueSet, &xReturn, NULL ); /*lint !e961 Casting from one typedef to another is not redundant. */
2786 #endif /* configUSE_QUEUE_SETS */
2787 /*-----------------------------------------------------------*/
2789 #if ( configUSE_QUEUE_SETS == 1 )
2791 static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
2793 Queue_t * pxQueueSetContainer = pxQueue->pxQueueSetContainer;
2794 BaseType_t xReturn = pdFALSE;
2796 /* This function must be called form a critical section. */
2798 /* The following line is not reachable in unit tests because every call
2799 * to prvNotifyQueueSetContainer is preceded by a check that
2800 * pxQueueSetContainer != NULL */
2801 configASSERT( pxQueueSetContainer ); /* LCOV_EXCL_BR_LINE */
2802 configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );
2804 if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )
2806 const int8_t cTxLock = pxQueueSetContainer->cTxLock;
2808 traceQUEUE_SET_SEND( pxQueueSetContainer );
2810 /* The data copied is the handle of the queue that contains data. */
2811 xReturn = prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, queueSEND_TO_BACK );
2813 if( cTxLock == queueUNLOCKED )
2815 if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )
2817 if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )
2819 /* The task waiting has a higher priority. */
2824 mtCOVERAGE_TEST_MARKER();
2829 mtCOVERAGE_TEST_MARKER();
2834 prvIncrementQueueTxLock( pxQueueSetContainer, cTxLock );
2839 mtCOVERAGE_TEST_MARKER();
2845 #endif /* configUSE_QUEUE_SETS */