]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/queue.c
Update version number in preparation for maintenance release.
[freertos] / FreeRTOS / Source / queue.c
index 3a6aea92a155fb7d211d48690a8770898fda50a8..9fbe6ba983fe05456d6ae70a71d4f88a0244e2a0 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.\r
+    FreeRTOS V9.0.1 - Copyright (C) 2017 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
@@ -90,9 +90,9 @@ privileged Vs unprivileged linkage and placement. */
 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
 \r
 \r
-/* Constants used with the xRxLock and xTxLock structure members. */\r
-#define queueUNLOCKED                                  ( ( BaseType_t ) -1 )\r
-#define queueLOCKED_UNMODIFIED                 ( ( BaseType_t ) 0 )\r
+/* Constants used with the cRxLock and cTxLock structure members. */\r
+#define queueUNLOCKED                                  ( ( int8_t ) -1 )\r
+#define queueLOCKED_UNMODIFIED                 ( ( int8_t ) 0 )\r
 \r
 /* When the Queue_t structure is used to represent a base queue its pcHead and\r
 pcTail members are used as pointers into the queue storage area.  When the\r
@@ -114,13 +114,6 @@ zero. */
 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( UBaseType_t ) 0 )\r
 #define queueMUTEX_GIVE_BLOCK_TIME              ( ( TickType_t ) 0U )\r
 \r
-/* Bits that can be set in xQUEUE->ucStaticAllocationFlags to indicate that the\r
-queue storage area and queue structure were statically allocated respectively.\r
-When these are statically allocated they won't be freed if the queue gets\r
-deleted. */\r
-#define queueSTATICALLY_ALLOCATED_STORAGE              ( ( uint8_t ) 0x01 )\r
-#define queueSTATICALLY_ALLOCATED_QUEUE_STRUCT ( ( uint8_t ) 0x02 )\r
-\r
 #if( configUSE_PREEMPTION == 0 )\r
        /* If the cooperative scheduler is being used then a yield should not be\r
        performed just because a higher priority task has been woken. */\r
@@ -153,8 +146,12 @@ typedef struct QueueDefinition
        UBaseType_t uxLength;                   /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */\r
        UBaseType_t uxItemSize;                 /*< The size of each items that the queue will hold. */\r
 \r
-       volatile BaseType_t xRxLock;    /*< 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. */\r
-       volatile BaseType_t xTxLock;    /*< 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. */\r
+       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. */\r
+       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. */\r
+\r
+       #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
+               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. */\r
+       #endif\r
 \r
        #if ( configUSE_QUEUE_SETS == 1 )\r
                struct QueueDefinition *pxQueueSetContainer;\r
@@ -165,10 +162,6 @@ typedef struct QueueDefinition
                uint8_t ucQueueType;\r
        #endif\r
 \r
-       #if ( configSUPPORT_STATIC_ALLOCATION == 1 )\r
-               uint8_t ucStaticAllocationFlags;\r
-       #endif\r
-\r
 } xQUEUE;\r
 \r
 /* The old xQUEUE name is maintained above then typedefed to the new Queue_t\r
@@ -239,17 +232,6 @@ static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvIte
  */\r
 static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;\r
 \r
-/*\r
- * A queue requires two blocks of memory; a structure to hold the queue state\r
- * and a storage area to hold the items in the queue.  The memory is assigned\r
- * by prvAllocateQueueMemory().  If ppucQueueStorage is NULL then the queue\r
- * storage will allocated dynamically, otherwise the buffer passed in\r
- * ppucQueueStorage will be used.  If pxStaticQueue is NULL then the queue\r
- * structure will be allocated dynamically, otherwise the buffer pointed to by\r
- * pxStaticQueue will be used.\r
- */\r
-static Queue_t *prvAllocateQueueMemory( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t **ppucQueueStorage, StaticQueue_t *pxStaticQueue );\r
-\r
 #if ( configUSE_QUEUE_SETS == 1 )\r
        /*\r
         * Checks to see if a queue is a member of a queue set, and if so, notifies\r
@@ -258,6 +240,31 @@ static Queue_t *prvAllocateQueueMemory( const UBaseType_t uxQueueLength, const U
        static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;\r
 #endif\r
 \r
+/*\r
+ * Called after a Queue_t structure has been allocated either statically or\r
+ * dynamically to fill in the structure's members.\r
+ */\r
+static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, const uint8_t ucQueueType, Queue_t *pxNewQueue ) PRIVILEGED_FUNCTION;\r
+\r
+/*\r
+ * Mutexes are a special type of queue.  When a mutex is created, first the\r
+ * queue is created, then prvInitialiseMutex() is called to configure the queue\r
+ * as a mutex.\r
+ */\r
+#if( configUSE_MUTEXES == 1 )\r
+       static void prvInitialiseMutex( Queue_t *pxNewQueue ) PRIVILEGED_FUNCTION;\r
+#endif\r
+\r
+#if( configUSE_MUTEXES == 1 )\r
+       /*\r
+        * If a task waiting for a mutex causes the mutex holder to inherit a\r
+        * priority, but the waiting task times out, then the holder should\r
+        * disinherit the priority - but only down to the highest priority of any\r
+        * other tasks that are waiting for the same mutex.  This function returns\r
+        * that priority.\r
+        */\r
+       static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;\r
+#endif\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -267,13 +274,13 @@ static Queue_t *prvAllocateQueueMemory( const UBaseType_t uxQueueLength, const U
 #define prvLockQueue( pxQueue )                                                                \\r
        taskENTER_CRITICAL();                                                                   \\r
        {                                                                                                               \\r
-               if( ( pxQueue )->xRxLock == queueUNLOCKED )                     \\r
+               if( ( pxQueue )->cRxLock == queueUNLOCKED )                     \\r
                {                                                                                                       \\r
-                       ( pxQueue )->xRxLock = queueLOCKED_UNMODIFIED;  \\r
+                       ( pxQueue )->cRxLock = queueLOCKED_UNMODIFIED;  \\r
                }                                                                                                       \\r
-               if( ( pxQueue )->xTxLock == queueUNLOCKED )                     \\r
+               if( ( pxQueue )->cTxLock == queueUNLOCKED )                     \\r
                {                                                                                                       \\r
-                       ( pxQueue )->xTxLock = queueLOCKED_UNMODIFIED;  \\r
+                       ( pxQueue )->cTxLock = queueLOCKED_UNMODIFIED;  \\r
                }                                                                                                       \\r
        }                                                                                                               \\r
        taskEXIT_CRITICAL()\r
@@ -291,8 +298,8 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                pxQueue->uxMessagesWaiting = ( UBaseType_t ) 0U;\r
                pxQueue->pcWriteTo = pxQueue->pcHead;\r
                pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( UBaseType_t ) 1U ) * pxQueue->uxItemSize );\r
-               pxQueue->xRxLock = queueUNLOCKED;\r
-               pxQueue->xTxLock = queueUNLOCKED;\r
+               pxQueue->cRxLock = queueUNLOCKED;\r
+               pxQueue->cTxLock = queueUNLOCKED;\r
 \r
                if( xNewQueue == pdFALSE )\r
                {\r
@@ -332,189 +339,155 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static Queue_t *prvAllocateQueueMemory( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t **ppucQueueStorage, StaticQueue_t *pxStaticQueue )\r
-{\r
-Queue_t *pxNewQueue;\r
-size_t xQueueSizeInBytes;\r
-\r
-       configASSERT( uxQueueLength > ( UBaseType_t ) 0 );\r
+#if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
 \r
-       #if( ( configASSERT_DEFINED == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\r
+       QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType )\r
        {\r
-               /* Sanity check that the size of the structure used to declare a\r
-               variable of type StaticQueue_t or StaticSemaphore_t equals the size of\r
-               the real queue and semaphore structures. */\r
-               volatile size_t xSize = sizeof( StaticQueue_t );\r
-               configASSERT( xSize == sizeof( Queue_t ) );\r
-       }\r
-       #endif /* configASSERT_DEFINED */\r
+       Queue_t *pxNewQueue;\r
 \r
-       if( uxItemSize == ( UBaseType_t ) 0 )\r
-       {\r
-               /* There is not going to be a queue storage area. */\r
-               xQueueSizeInBytes = ( size_t ) 0;\r
-       }\r
-       else\r
-       {\r
-               /* Allocate enough space to hold the maximum number of items that can be\r
-               in the queue at any time. */\r
-               xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
-       }\r
+               configASSERT( uxQueueLength > ( UBaseType_t ) 0 );\r
 \r
-       #if( configSUPPORT_STATIC_ALLOCATION == 0 )\r
-       {\r
-               /* Allocate the new queue structure and storage area. */\r
-               pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes );\r
+               /* The StaticQueue_t structure and the queue storage area must be\r
+               supplied. */\r
+               configASSERT( pxStaticQueue != NULL );\r
 \r
-               if( pxNewQueue != NULL )\r
-               {\r
-                       /* Jump past the queue structure to find the location of the queue\r
-                       storage area. */\r
-                       *ppucQueueStorage = ( ( uint8_t * ) pxNewQueue ) + sizeof( Queue_t );\r
-               }\r
+               /* A queue storage area should be provided if the item size is not 0, and\r
+               should not be provided if the item size is 0. */\r
+               configASSERT( !( ( pucQueueStorage != NULL ) && ( uxItemSize == 0 ) ) );\r
+               configASSERT( !( ( pucQueueStorage == NULL ) && ( uxItemSize != 0 ) ) );\r
 \r
-               /* The pxStaticQueue parameter is not used.  Remove compiler warnings. */\r
-               ( void ) pxStaticQueue;\r
-       }\r
-       #else\r
-       {\r
-               if( pxStaticQueue == NULL )\r
-               {\r
-                       /* A statically allocated queue was not passed in, so create one\r
-                       dynamically. */\r
-                       pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) );\r
-                       pxNewQueue->ucStaticAllocationFlags = 0;\r
-               }\r
-               else\r
+               #if( configASSERT_DEFINED == 1 )\r
                {\r
-                       /* The address of a statically allocated queue was passed in, use\r
-                       it and note that the queue was not dynamically allocated so there is\r
-                       no attempt to free it again should the queue be deleted. */\r
-                       pxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\r
-                       pxNewQueue->ucStaticAllocationFlags = queueSTATICALLY_ALLOCATED_QUEUE_STRUCT;\r
+                       /* Sanity check that the size of the structure used to declare a\r
+                       variable of type StaticQueue_t or StaticSemaphore_t equals the size of\r
+                       the real queue and semaphore structures. */\r
+                       volatile size_t xSize = sizeof( StaticQueue_t );\r
+                       configASSERT( xSize == sizeof( Queue_t ) );\r
                }\r
+               #endif /* configASSERT_DEFINED */\r
+\r
+               /* The address of a statically allocated queue was passed in, use it.\r
+               The address of a statically allocated storage area was also passed in\r
+               but is already set. */\r
+               pxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\r
 \r
                if( pxNewQueue != NULL )\r
                {\r
-                       if( ( *ppucQueueStorage == NULL ) && ( xQueueSizeInBytes > ( size_t ) 0 ) )\r
-                       {\r
-                               /* A statically allocated queue storage area was not passed in,\r
-                               so allocate the queue storage area dynamically. */\r
-                               *ppucQueueStorage = ( uint8_t * ) pvPortMalloc( xQueueSizeInBytes );\r
-\r
-                               if( *ppucQueueStorage == NULL )\r
-                               {\r
-                                       /* The queue storage area could not be created, so free the\r
-                                       queue structure also. */\r
-                                       if( ( pxNewQueue->ucStaticAllocationFlags & queueSTATICALLY_ALLOCATED_QUEUE_STRUCT ) == 0 )\r
-                                       {\r
-                                               vPortFree( ( void * ) pxNewQueue );\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               mtCOVERAGE_TEST_MARKER();\r
-                                       }\r
-\r
-                                       pxNewQueue = NULL;\r
-                               }\r
-                               else\r
-                               {\r
-                                       mtCOVERAGE_TEST_MARKER();\r
-                               }\r
-                       }\r
-                       else\r
+                       #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\r
                        {\r
-                               /* Note the fact that either the queue storage area was passed\r
-                               into this function, or the size requirement for the queue\r
-                               storage area was zero - either way no attempt should be made to\r
-                               free the queue storage area if the queue is deleted. */\r
-                               pxNewQueue->ucStaticAllocationFlags |= queueSTATICALLY_ALLOCATED_STORAGE;\r
+                               /* Queues can be allocated wither statically or dynamically, so\r
+                               note this queue was allocated statically in case the queue is\r
+                               later deleted. */\r
+                               pxNewQueue->ucStaticallyAllocated = pdTRUE;\r
                        }\r
+                       #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
+\r
+                       prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );\r
                }\r
+\r
+               return pxNewQueue;\r
        }\r
-       #endif\r
 \r
-       return pxNewQueue;\r
-}\r
+#endif /* configSUPPORT_STATIC_ALLOCATION */\r
 /*-----------------------------------------------------------*/\r
 \r
-QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType )\r
-{\r
-Queue_t *pxNewQueue;\r
+#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\r
 \r
-       /* Remove compiler warnings about unused parameters should\r
-       configUSE_TRACE_FACILITY not be set to 1. */\r
-       ( void ) ucQueueType;\r
+       QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType )\r
+       {\r
+       Queue_t *pxNewQueue;\r
+       size_t xQueueSizeInBytes;\r
+       uint8_t *pucQueueStorage;\r
 \r
-       /* A queue requires a queue structure and a queue storage area.  These may\r
-       be allocated statically or dynamically, depending on the parameter\r
-       values. */\r
-       pxNewQueue = prvAllocateQueueMemory( uxQueueLength, uxItemSize, &pucQueueStorage, pxStaticQueue );\r
+               configASSERT( uxQueueLength > ( UBaseType_t ) 0 );\r
 \r
-       if( pxNewQueue != NULL )\r
-       {\r
                if( uxItemSize == ( UBaseType_t ) 0 )\r
                {\r
-                       /* No RAM was allocated for the queue storage area, but PC head\r
-                       cannot be set to NULL because NULL is used as a key to say the queue\r
-                       is used as a mutex.  Therefore just set pcHead to point to the queue\r
-                       as a benign value that is known to be within the memory map. */\r
-                       pxNewQueue->pcHead = ( int8_t * ) pxNewQueue;\r
+                       /* There is not going to be a queue storage area. */\r
+                       xQueueSizeInBytes = ( size_t ) 0;\r
                }\r
                else\r
                {\r
-                       /* Set the head to the start of the queue storage area. */\r
-                       pxNewQueue->pcHead = ( int8_t * ) pucQueueStorage;\r
+                       /* Allocate enough space to hold the maximum number of items that\r
+                       can be in the queue at any time. */\r
+                       xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
                }\r
 \r
-               /* Initialise the queue members as described where the queue type is\r
-               defined. */\r
-               pxNewQueue->uxLength = uxQueueLength;\r
-               pxNewQueue->uxItemSize = uxItemSize;\r
-               ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );\r
+               pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes );\r
 \r
-               #if ( configUSE_TRACE_FACILITY == 1 )\r
+               if( pxNewQueue != NULL )\r
                {\r
-                       pxNewQueue->ucQueueType = ucQueueType;\r
-               }\r
-               #endif /* configUSE_TRACE_FACILITY */\r
+                       /* Jump past the queue structure to find the location of the queue\r
+                       storage area. */\r
+                       pucQueueStorage = ( ( uint8_t * ) pxNewQueue ) + sizeof( Queue_t );\r
 \r
-               #if( configUSE_QUEUE_SETS == 1 )\r
-               {\r
-                       pxNewQueue->pxQueueSetContainer = NULL;\r
+                       #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+                       {\r
+                               /* Queues can be created either statically or dynamically, so\r
+                               note this task was created dynamically in case it is later\r
+                               deleted. */\r
+                               pxNewQueue->ucStaticallyAllocated = pdFALSE;\r
+                       }\r
+                       #endif /* configSUPPORT_STATIC_ALLOCATION */\r
+\r
+                       prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );\r
                }\r
-               #endif /* configUSE_QUEUE_SETS */\r
 \r
-               traceQUEUE_CREATE( pxNewQueue );\r
+               return pxNewQueue;\r
+       }\r
+\r
+#endif /* configSUPPORT_STATIC_ALLOCATION */\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, const uint8_t ucQueueType, Queue_t *pxNewQueue )\r
+{\r
+       /* Remove compiler warnings about unused parameters should\r
+       configUSE_TRACE_FACILITY not be set to 1. */\r
+       ( void ) ucQueueType;\r
+\r
+       if( uxItemSize == ( UBaseType_t ) 0 )\r
+       {\r
+               /* No RAM was allocated for the queue storage area, but PC head cannot\r
+               be set to NULL because NULL is used as a key to say the queue is used as\r
+               a mutex.  Therefore just set pcHead to point to the queue as a benign\r
+               value that is known to be within the memory map. */\r
+               pxNewQueue->pcHead = ( int8_t * ) pxNewQueue;\r
        }\r
        else\r
        {\r
-               mtCOVERAGE_TEST_MARKER();\r
+               /* Set the head to the start of the queue storage area. */\r
+               pxNewQueue->pcHead = ( int8_t * ) pucQueueStorage;\r
        }\r
 \r
-       configASSERT( pxNewQueue );\r
+       /* Initialise the queue members as described where the queue type is\r
+       defined. */\r
+       pxNewQueue->uxLength = uxQueueLength;\r
+       pxNewQueue->uxItemSize = uxItemSize;\r
+       ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );\r
 \r
-       return ( QueueHandle_t ) pxNewQueue;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-#if ( configUSE_MUTEXES == 1 )\r
+       #if ( configUSE_TRACE_FACILITY == 1 )\r
+       {\r
+               pxNewQueue->ucQueueType = ucQueueType;\r
+       }\r
+       #endif /* configUSE_TRACE_FACILITY */\r
 \r
-       QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue )\r
+       #if( configUSE_QUEUE_SETS == 1 )\r
        {\r
-       Queue_t *pxNewQueue;\r
-       const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;\r
+               pxNewQueue->pxQueueSetContainer = NULL;\r
+       }\r
+       #endif /* configUSE_QUEUE_SETS */\r
 \r
-               /* Prevent compiler warnings about unused parameters if\r
-               configUSE_TRACE_FACILITY does not equal 1. */\r
-               ( void ) ucQueueType;\r
+       traceQUEUE_CREATE( pxNewQueue );\r
+}\r
+/*-----------------------------------------------------------*/\r
 \r
-               pxNewQueue = ( Queue_t * ) xQueueGenericCreate( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType );\r
+#if( configUSE_MUTEXES == 1 )\r
 \r
-               /* Allocate the new queue structure. */\r
+       static void prvInitialiseMutex( Queue_t *pxNewQueue )\r
+       {\r
                if( pxNewQueue != NULL )\r
                {\r
-                       /* xQueueGenericCreate() will set all the queue structure members\r
+                       /* The queue create function will set all the queue structure members\r
                        correctly for a generic queue, but this function is creating a\r
                        mutex.  Overwrite those members that need to be set differently -\r
                        in particular the information required for priority inheritance. */\r
@@ -533,6 +506,40 @@ Queue_t *pxNewQueue;
                {\r
                        traceCREATE_MUTEX_FAILED();\r
                }\r
+       }\r
+\r
+#endif /* configUSE_MUTEXES */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
+\r
+       QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType )\r
+       {\r
+       Queue_t *pxNewQueue;\r
+       const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;\r
+\r
+               pxNewQueue = ( Queue_t * ) xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType );\r
+               prvInitialiseMutex( pxNewQueue );\r
+\r
+               return pxNewQueue;\r
+       }\r
+\r
+#endif /* configUSE_MUTEXES */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\r
+\r
+       QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue )\r
+       {\r
+       Queue_t *pxNewQueue;\r
+       const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;\r
+\r
+               /* Prevent compiler warnings about unused parameters if\r
+               configUSE_TRACE_FACILITY does not equal 1. */\r
+               ( void ) ucQueueType;\r
+\r
+               pxNewQueue = ( Queue_t * ) xQueueGenericCreateStatic( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType );\r
+               prvInitialiseMutex( pxNewQueue );\r
 \r
                return pxNewQueue;\r
        }\r
@@ -570,6 +577,32 @@ Queue_t *pxNewQueue;
 #endif\r
 /*-----------------------------------------------------------*/\r
 \r
+#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )\r
+\r
+       void* xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore )\r
+       {\r
+       void *pxReturn;\r
+\r
+               configASSERT( xSemaphore );\r
+\r
+               /* Mutexes cannot be used in interrupt service routines, so the mutex\r
+               holder should not change in an ISR, and therefore a critical section is\r
+               not required here. */\r
+               if( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )\r
+               {\r
+                       pxReturn = ( void * ) ( ( Queue_t * ) xSemaphore )->pxMutexHolder;\r
+               }\r
+               else\r
+               {\r
+                       pxReturn = NULL;\r
+               }\r
+\r
+               return pxReturn;\r
+       } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
 #if ( configUSE_RECURSIVE_MUTEXES == 1 )\r
 \r
        BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex )\r
@@ -646,7 +679,7 @@ Queue_t *pxNewQueue;
                }\r
                else\r
                {\r
-                       xReturn = xQueueGenericReceive( pxMutex, NULL, xTicksToWait, pdFALSE );\r
+                       xReturn = xQueueSemaphoreTake( pxMutex, xTicksToWait );\r
 \r
                        /* pdPASS will only be returned if the mutex was successfully\r
                        obtained.  The calling task may have entered the Blocked state\r
@@ -667,16 +700,44 @@ Queue_t *pxNewQueue;
 #endif /* configUSE_RECURSIVE_MUTEXES */\r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( configUSE_COUNTING_SEMAPHORES == 1 )\r
+#if( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\r
+\r
+       QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue )\r
+       {\r
+       QueueHandle_t xHandle;\r
+\r
+               configASSERT( uxMaxCount != 0 );\r
+               configASSERT( uxInitialCount <= uxMaxCount );\r
+\r
+               xHandle = xQueueGenericCreateStatic( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
+\r
+               if( xHandle != NULL )\r
+               {\r
+                       ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;\r
+\r
+                       traceCREATE_COUNTING_SEMAPHORE();\r
+               }\r
+               else\r
+               {\r
+                       traceCREATE_COUNTING_SEMAPHORE_FAILED();\r
+               }\r
+\r
+               return xHandle;\r
+       }\r
+\r
+#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
 \r
-       QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue )\r
+       QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount )\r
        {\r
        QueueHandle_t xHandle;\r
 \r
                configASSERT( uxMaxCount != 0 );\r
                configASSERT( uxInitialCount <= uxMaxCount );\r
 \r
-               xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
+               xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
 \r
                if( xHandle != NULL )\r
                {\r
@@ -689,11 +750,10 @@ Queue_t *pxNewQueue;
                        traceCREATE_COUNTING_SEMAPHORE_FAILED();\r
                }\r
 \r
-               configASSERT( xHandle );\r
                return xHandle;\r
        }\r
 \r
-#endif /* configUSE_COUNTING_SEMAPHORES */\r
+#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */\r
 /*-----------------------------------------------------------*/\r
 \r
 BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition )\r
@@ -894,37 +954,73 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( configUSE_ALTERNATIVE_API == 1 )\r
+BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition )\r
+{\r
+BaseType_t xReturn;\r
+UBaseType_t uxSavedInterruptStatus;\r
+Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
 \r
-       BaseType_t xQueueAltGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, BaseType_t xCopyPosition )\r
-       {\r
-       BaseType_t xEntryTimeSet = pdFALSE;\r
-       TimeOut_t xTimeOut;\r
-       Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+       configASSERT( pxQueue );\r
+       configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+       configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
 \r
-               configASSERT( pxQueue );\r
-               configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+       /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+       system call (or maximum API call) interrupt priority.  Interrupts that are\r
+       above the maximum system call priority are kept permanently enabled, even\r
+       when the RTOS kernel is in a critical section, but cannot make any calls to\r
+       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
+       then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+       failure if a FreeRTOS API function is called from an interrupt that has been\r
+       assigned a priority above the configured maximum system call priority.\r
+       Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+       that have been assigned a priority at or (logically) below the maximum\r
+       system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
+       safe API to ensure interrupt entry is as fast and as simple as possible.\r
+       More information (albeit Cortex-M specific) is provided on the following\r
+       link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+       portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
-               for( ;; )\r
+       /* Similar to xQueueGenericSend, except without blocking if there is no room\r
+       in the queue.  Also don't directly wake a task that was blocked on a queue\r
+       read, instead return a flag to say whether a context switch is required or\r
+       not (i.e. has a task with a higher priority than us been woken by this\r
+       post). */\r
+       uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+       {\r
+               if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
                {\r
-                       taskENTER_CRITICAL();\r
+                       const int8_t cTxLock = pxQueue->cTxLock;\r
+\r
+                       traceQUEUE_SEND_FROM_ISR( pxQueue );\r
+\r
+                       /* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a\r
+                       semaphore or mutex.  That means prvCopyDataToQueue() cannot result\r
+                       in a task disinheriting a priority and prvCopyDataToQueue() can be\r
+                       called here even though the disinherit function does not check if\r
+                       the scheduler is suspended before accessing the ready lists. */\r
+                       ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
+\r
+                       /* The event list is not altered if the queue is locked.  This will\r
+                       be done when the queue is unlocked later. */\r
+                       if( cTxLock == queueUNLOCKED )\r
                        {\r
-                               /* Is there room on the queue now?  To be running we must be\r
-                               the highest priority task wanting to access the queue. */\r
-                               if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+                               #if ( configUSE_QUEUE_SETS == 1 )\r
                                {\r
-                                       traceQUEUE_SEND( pxQueue );\r
-                                       prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
-\r
-                                       /* If there was a task waiting for data to arrive on the\r
-                                       queue then unblock it now. */\r
-                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                                       if( pxQueue->pxQueueSetContainer != NULL )\r
                                        {\r
-                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE )\r
                                                {\r
-                                                       /* The unblocked task has a priority higher than\r
-                                                       our own so yield immediately. */\r
-                                                       portYIELD_WITHIN_API();\r
+                                                       /* The queue is a member of a queue set, and posting\r
+                                                       to the queue set caused a higher priority task to\r
+                                                       unblock.  A context switch is required. */\r
+                                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                                       {\r
+                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               mtCOVERAGE_TEST_MARKER();\r
+                                                       }\r
                                                }\r
                                                else\r
                                                {\r
@@ -933,132 +1029,20 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        }\r
                                        else\r
                                        {\r
-                                               mtCOVERAGE_TEST_MARKER();\r
-                                       }\r
-\r
-                                       taskEXIT_CRITICAL();\r
-                                       return pdPASS;\r
-                               }\r
-                               else\r
-                               {\r
-                                       if( xTicksToWait == ( TickType_t ) 0 )\r
-                                       {\r
-                                               taskEXIT_CRITICAL();\r
-                                               return errQUEUE_FULL;\r
-                                       }\r
-                                       else if( xEntryTimeSet == pdFALSE )\r
-                                       {\r
-                                               vTaskSetTimeOutState( &xTimeOut );\r
-                                               xEntryTimeSet = pdTRUE;\r
-                                       }\r
-                               }\r
-                       }\r
-                       taskEXIT_CRITICAL();\r
-\r
-                       taskENTER_CRITICAL();\r
-                       {\r
-                               if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
-                               {\r
-                                       if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
-                                       {\r
-                                               traceBLOCKING_ON_QUEUE_SEND( pxQueue );\r
-                                               vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );\r
-                                               portYIELD_WITHIN_API();\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               mtCOVERAGE_TEST_MARKER();\r
-                                       }\r
-                               }\r
-                               else\r
-                               {\r
-                                       taskEXIT_CRITICAL();\r
-                                       traceQUEUE_SEND_FAILED( pxQueue );\r
-                                       return errQUEUE_FULL;\r
-                               }\r
-                       }\r
-                       taskEXIT_CRITICAL();\r
-               }\r
-       }\r
-\r
-#endif /* configUSE_ALTERNATIVE_API */\r
-/*-----------------------------------------------------------*/\r
-\r
-#if ( configUSE_ALTERNATIVE_API == 1 )\r
-\r
-       BaseType_t xQueueAltGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, BaseType_t xJustPeeking )\r
-       {\r
-       BaseType_t xEntryTimeSet = pdFALSE;\r
-       TimeOut_t xTimeOut;\r
-       int8_t *pcOriginalReadPosition;\r
-       Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
-\r
-               configASSERT( pxQueue );\r
-               configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
-\r
-               for( ;; )\r
-               {\r
-                       taskENTER_CRITICAL();\r
-                       {\r
-                               if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )\r
-                               {\r
-                                       /* Remember our read position in case we are just peeking. */\r
-                                       pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
-\r
-                                       prvCopyDataFromQueue( pxQueue, pvBuffer );\r
-\r
-                                       if( xJustPeeking == pdFALSE )\r
-                                       {\r
-                                               traceQUEUE_RECEIVE( pxQueue );\r
-\r
-                                               /* Data is actually being removed (not just peeked). */\r
-                                               --( pxQueue->uxMessagesWaiting );\r
-\r
-                                               #if ( configUSE_MUTEXES == 1 )\r
-                                               {\r
-                                                       if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
-                                                       {\r
-                                                               /* Record the information required to implement\r
-                                                               priority inheritance should it become necessary. */\r
-                                                               pxQueue->pxMutexHolder = ( int8_t * ) xTaskGetCurrentTaskHandle();\r
-                                                       }\r
-                                                       else\r
-                                                       {\r
-                                                               mtCOVERAGE_TEST_MARKER();\r
-                                                       }\r
-                                               }\r
-                                               #endif\r
-\r
-                                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
-                                               {\r
-                                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
-                                                       {\r
-                                                               portYIELD_WITHIN_API();\r
-                                                       }\r
-                                                       else\r
-                                                       {\r
-                                                               mtCOVERAGE_TEST_MARKER();\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               traceQUEUE_PEEK( pxQueue );\r
-\r
-                                               /* The data is not being removed, so reset our read\r
-                                               pointer. */\r
-                                               pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
-\r
-                                               /* The data is being left in the queue, so see if there are\r
-                                               any other tasks waiting for the data. */\r
                                                if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                                {\r
-                                                       /* Tasks that are removed from the event list will get added to\r
-                                                       the pending ready list as the scheduler is still suspended. */\r
                                                        if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                                        {\r
-                                                               /* The task waiting has a higher priority than this task. */\r
-                                                               portYIELD_WITHIN_API();\r
+                                                               /* The task waiting has a higher priority so\r
+                                                               record that a context switch is required. */\r
+                                                               if( pxHigherPriorityTaskWoken != NULL )\r
+                                                               {\r
+                                                                       *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       mtCOVERAGE_TEST_MARKER();\r
+                                                               }\r
                                                        }\r
                                                        else\r
                                                        {\r
@@ -1070,84 +1054,79 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                                        mtCOVERAGE_TEST_MARKER();\r
                                                }\r
                                        }\r
-\r
-                                       taskEXIT_CRITICAL();\r
-                                       return pdPASS;\r
                                }\r
-                               else\r
-                               {\r
-                                       if( xTicksToWait == ( TickType_t ) 0 )\r
-                                       {\r
-                                               taskEXIT_CRITICAL();\r
-                                               traceQUEUE_RECEIVE_FAILED( pxQueue );\r
-                                               return errQUEUE_EMPTY;\r
-                                       }\r
-                                       else if( xEntryTimeSet == pdFALSE )\r
-                                       {\r
-                                               vTaskSetTimeOutState( &xTimeOut );\r
-                                               xEntryTimeSet = pdTRUE;\r
-                                       }\r
-                               }\r
-                       }\r
-                       taskEXIT_CRITICAL();\r
-\r
-                       taskENTER_CRITICAL();\r
-                       {\r
-                               if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
+                               #else /* configUSE_QUEUE_SETS */\r
                                {\r
-                                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                        {\r
-                                               traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
-\r
-                                               #if ( configUSE_MUTEXES == 1 )\r
+                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                                {\r
-                                                       if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
+                                                       /* The task waiting has a higher priority so record that a\r
+                                                       context switch is required. */\r
+                                                       if( pxHigherPriorityTaskWoken != NULL )\r
                                                        {\r
-                                                               taskENTER_CRITICAL();\r
-                                                               {\r
-                                                                       vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
-                                                               }\r
-                                                               taskEXIT_CRITICAL();\r
+                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
                                                        }\r
                                                        else\r
                                                        {\r
                                                                mtCOVERAGE_TEST_MARKER();\r
                                                        }\r
                                                }\r
-                                               #endif\r
-\r
-                                               vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
-                                               portYIELD_WITHIN_API();\r
+                                               else\r
+                                               {\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
                                        }\r
                                        else\r
                                        {\r
                                                mtCOVERAGE_TEST_MARKER();\r
                                        }\r
                                }\r
-                               else\r
-                               {\r
-                                       taskEXIT_CRITICAL();\r
-                                       traceQUEUE_RECEIVE_FAILED( pxQueue );\r
-                                       return errQUEUE_EMPTY;\r
-                               }\r
+                               #endif /* configUSE_QUEUE_SETS */\r
                        }\r
-                       taskEXIT_CRITICAL();\r
+                       else\r
+                       {\r
+                               /* Increment the lock count so the task that unlocks the queue\r
+                               knows that data was posted while it was locked. */\r
+                               pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );\r
+                       }\r
+\r
+                       xReturn = pdPASS;\r
+               }\r
+               else\r
+               {\r
+                       traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\r
+                       xReturn = errQUEUE_FULL;\r
                }\r
        }\r
+       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
 \r
-\r
-#endif /* configUSE_ALTERNATIVE_API */\r
+       return xReturn;\r
+}\r
 /*-----------------------------------------------------------*/\r
 \r
-BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition )\r
+BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken )\r
 {\r
 BaseType_t xReturn;\r
 UBaseType_t uxSavedInterruptStatus;\r
 Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
 \r
+       /* Similar to xQueueGenericSendFromISR() but used with semaphores where the\r
+       item size is 0.  Don't directly wake a task that was blocked on a queue\r
+       read, instead return a flag to say whether a context switch is required or\r
+       not (i.e. has a task with a higher priority than us been woken by this\r
+       post). */\r
+\r
        configASSERT( pxQueue );\r
-       configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
-       configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
+\r
+       /* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR()\r
+       if the item size is not 0. */\r
+       configASSERT( pxQueue->uxItemSize == 0 );\r
+\r
+       /* Normally a mutex would not be given from an interrupt, especially if\r
+       there is a mutex holder, as priority inheritance makes no sense for an\r
+       interrupts, only tasks. */\r
+       configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->pxMutexHolder != NULL ) ) );\r
 \r
        /* RTOS ports that support interrupt nesting have the concept of a maximum\r
        system call (or maximum API call) interrupt priority.  Interrupts that are\r
@@ -1165,37 +1144,40 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
        portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
-       /* Similar to xQueueGenericSend, except without blocking if there is no room\r
-       in the queue.  Also don't directly wake a task that was blocked on a queue\r
-       read, instead return a flag to say whether a context switch is required or\r
-       not (i.e. has a task with a higher priority than us been woken by this\r
-       post). */\r
        uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
        {\r
-               if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
+               const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\r
+\r
+               /* When the queue is used to implement a semaphore no data is ever\r
+               moved through the queue but it is still valid to see if the queue 'has\r
+               space'. */\r
+               if( uxMessagesWaiting < pxQueue->uxLength )\r
                {\r
+                       const int8_t cTxLock = pxQueue->cTxLock;\r
+\r
                        traceQUEUE_SEND_FROM_ISR( pxQueue );\r
 \r
-                       /* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a\r
-                       semaphore or mutex.  That means prvCopyDataToQueue() cannot result\r
-                       in a task disinheriting a priority and prvCopyDataToQueue() can be\r
-                       called here even though the disinherit function does not check if\r
-                       the scheduler is suspended before accessing the ready lists. */\r
-                       ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
+                       /* A task can only have an inherited priority if it is a mutex\r
+                       holder - and if there is a mutex holder then the mutex cannot be\r
+                       given from an ISR.  As this is the ISR version of the function it\r
+                       can be assumed there is no mutex holder and no need to determine if\r
+                       priority disinheritance is needed.  Simply increase the count of\r
+                       messages (semaphores) available. */\r
+                       pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1;\r
 \r
                        /* The event list is not altered if the queue is locked.  This will\r
                        be done when the queue is unlocked later. */\r
-                       if( pxQueue->xTxLock == queueUNLOCKED )\r
+                       if( cTxLock == queueUNLOCKED )\r
                        {\r
                                #if ( configUSE_QUEUE_SETS == 1 )\r
                                {\r
                                        if( pxQueue->pxQueueSetContainer != NULL )\r
                                        {\r
-                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE )\r
+                                               if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) != pdFALSE )\r
                                                {\r
-                                                       /* The queue is a member of a queue set, and posting\r
-                                                       to the queue set caused a higher priority task to\r
-                                                       unblock.  A context switch is required. */\r
+                                                       /* The semaphore is a member of a queue set, and\r
+                                                       posting to the queue set caused a higher priority\r
+                                                       task to unblock.  A context switch is required. */\r
                                                        if( pxHigherPriorityTaskWoken != NULL )\r
                                                        {\r
                                                                *pxHigherPriorityTaskWoken = pdTRUE;\r
@@ -1271,7 +1253,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        {\r
                                /* Increment the lock count so the task that unlocks the queue\r
                                knows that data was posted while it was locked. */\r
-                               ++( pxQueue->xTxLock );\r
+                               pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );\r
                        }\r
 \r
                        xReturn = pdPASS;\r
@@ -1288,182 +1270,385 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken )\r
+BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )\r
 {\r
-BaseType_t xReturn;\r
-UBaseType_t uxSavedInterruptStatus;\r
+BaseType_t xEntryTimeSet = pdFALSE;\r
+TimeOut_t xTimeOut;\r
 Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
 \r
-       /* Similar to xQueueGenericSendFromISR() but used with semaphores where the\r
-       item size is 0.  Don't directly wake a task that was blocked on a queue\r
-       read, instead return a flag to say whether a context switch is required or\r
-       not (i.e. has a task with a higher priority than us been woken by this\r
-       post). */\r
+       /* Check the pointer is not NULL. */\r
+       configASSERT( ( pxQueue ) );\r
 \r
-       configASSERT( pxQueue );\r
+       /* The buffer into which data is received can only be NULL if the data size\r
+       is zero (so no data is copied into the buffer. */\r
+       configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
 \r
-       /* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR()\r
-       if the item size is not 0. */\r
+       /* Cannot block if the scheduler is suspended. */\r
+       #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+       {\r
+               configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
+       }\r
+       #endif\r
+\r
+\r
+       /* This function relaxes the coding standard somewhat to allow return\r
+       statements within the function itself.  This is done in the interest\r
+       of execution time efficiency. */\r
+\r
+       for( ;; )\r
+       {\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\r
+\r
+                       /* Is there data in the queue now?  To be running the calling task\r
+                       must be the highest priority task wanting to access the queue. */\r
+                       if( uxMessagesWaiting > ( UBaseType_t ) 0 )\r
+                       {\r
+                               /* Data available, remove one item. */\r
+                               prvCopyDataFromQueue( pxQueue, pvBuffer );\r
+                               traceQUEUE_RECEIVE( pxQueue );\r
+                               pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;\r
+\r
+                               /* There is now space in the queue, were any tasks waiting to\r
+                               post to the queue?  If so, unblock the highest priority waiting\r
+                               task. */\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
+                               {\r
+                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
+                                       {\r
+                                               queueYIELD_IF_USING_PREEMPTION();\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+\r
+                               taskEXIT_CRITICAL();\r
+                               return pdPASS;\r
+                       }\r
+                       else\r
+                       {\r
+                               if( xTicksToWait == ( TickType_t ) 0 )\r
+                               {\r
+                                       /* The queue was empty and no block time is specified (or\r
+                                       the block time has expired) so leave now. */\r
+                                       taskEXIT_CRITICAL();\r
+                                       traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                                       return errQUEUE_EMPTY;\r
+                               }\r
+                               else if( xEntryTimeSet == pdFALSE )\r
+                               {\r
+                                       /* The queue was empty and a block time was specified so\r
+                                       configure the timeout structure. */\r
+                                       vTaskSetTimeOutState( &xTimeOut );\r
+                                       xEntryTimeSet = pdTRUE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       /* Entry time was already set. */\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               /* Interrupts and other tasks can send to and receive from the queue\r
+               now the critical section has been exited. */\r
+\r
+               vTaskSuspendAll();\r
+               prvLockQueue( pxQueue );\r
+\r
+               /* Update the timeout state to see if it has expired yet. */\r
+               if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
+               {\r
+                       /* The timeout has not expired.  If the queue is still empty place\r
+                       the task on the list of tasks waiting to receive from the queue. */\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+                       {\r
+                               traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
+                               vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
+                               prvUnlockQueue( pxQueue );\r
+                               if( xTaskResumeAll() == pdFALSE )\r
+                               {\r
+                                       portYIELD_WITHIN_API();\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               /* The queue contains data again.  Loop back to try and read the\r
+                               data. */\r
+                               prvUnlockQueue( pxQueue );\r
+                               ( void ) xTaskResumeAll();\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       /* Timed out.  If there is no data in the queue exit, otherwise loop\r
+                       back and attempt to read the data. */\r
+                       prvUnlockQueue( pxQueue );\r
+                       ( void ) xTaskResumeAll();\r
+\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+                       {\r
+                               traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                               return errQUEUE_EMPTY;\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait )\r
+{\r
+BaseType_t xEntryTimeSet = pdFALSE;\r
+TimeOut_t xTimeOut;\r
+Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+\r
+#if( configUSE_MUTEXES == 1 )\r
+       BaseType_t xInheritanceOccurred = pdFALSE;\r
+#endif\r
+\r
+       /* Check the queue pointer is not NULL. */\r
+       configASSERT( ( pxQueue ) );\r
+\r
+       /* Check this really is a semaphore, in which case the item size will be\r
+       0. */\r
        configASSERT( pxQueue->uxItemSize == 0 );\r
 \r
-       /* Normally a mutex would not be given from an interrupt, especially if\r
-       there is a mutex holder, as priority inheritance makes no sense for an\r
-       interrupts, only tasks. */\r
-       configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->pxMutexHolder != NULL ) ) );\r
+       /* Cannot block if the scheduler is suspended. */\r
+       #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+       {\r
+               configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
+       }\r
+       #endif\r
 \r
-       /* RTOS ports that support interrupt nesting have the concept of a maximum\r
-       system call (or maximum API call) interrupt priority.  Interrupts that are\r
-       above the maximum system call priority are kept permanently enabled, even\r
-       when the RTOS kernel is in a critical section, but cannot make any calls to\r
-       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
-       then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
-       failure if a FreeRTOS API function is called from an interrupt that has been\r
-       assigned a priority above the configured maximum system call priority.\r
-       Only FreeRTOS functions that end in FromISR can be called from interrupts\r
-       that have been assigned a priority at or (logically) below the maximum\r
-       system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
-       safe API to ensure interrupt entry is as fast and as simple as possible.\r
-       More information (albeit Cortex-M specific) is provided on the following\r
-       link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
-       portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
-       uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
-       {\r
-               /* When the queue is used to implement a semaphore no data is ever\r
-               moved through the queue but it is still valid to see if the queue 'has\r
-               space'. */\r
-               if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
-               {\r
-                       traceQUEUE_SEND_FROM_ISR( pxQueue );\r
+       /* This function relaxes the coding standard somewhat to allow return\r
+       statements within the function itself.  This is done in the interest\r
+       of execution time efficiency. */\r
+\r
+       for( ;; )\r
+       {\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       /* Semaphores are queues with an item size of 0, and where the\r
+                       number of messages in the queue is the semaphore's count value. */\r
+                       const UBaseType_t uxSemaphoreCount = pxQueue->uxMessagesWaiting;\r
+\r
+                       /* Is there data in the queue now?  To be running the calling task\r
+                       must be the highest priority task wanting to access the queue. */\r
+                       if( uxSemaphoreCount > ( UBaseType_t ) 0 )\r
+                       {\r
+                               traceQUEUE_RECEIVE( pxQueue );\r
+\r
+                               /* Semaphores are queues with a data size of zero and where the\r
+                               messages waiting is the semaphore's count.  Reduce the count. */\r
+                               pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1;\r
+\r
+                               #if ( configUSE_MUTEXES == 1 )\r
+                               {\r
+                                       if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
+                                       {\r
+                                               /* Record the information required to implement\r
+                                               priority inheritance should it become necessary. */\r
+                                               pxQueue->pxMutexHolder = ( int8_t * ) pvTaskIncrementMutexHeldCount(); /*lint !e961 Cast is not redundant as TaskHandle_t is a typedef. */\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+                               }\r
+                               #endif /* configUSE_MUTEXES */\r
+\r
+                               /* Check to see if other tasks are blocked waiting to give the\r
+                               semaphore, and if so, unblock the highest priority such task. */\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
+                               {\r
+                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
+                                       {\r
+                                               queueYIELD_IF_USING_PREEMPTION();\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+\r
+                               taskEXIT_CRITICAL();\r
+                               return pdPASS;\r
+                       }\r
+                       else\r
+                       {\r
+                               if( xTicksToWait == ( TickType_t ) 0 )\r
+                               {\r
+                                       /* For inheritance to have occurred there must have been an\r
+                                       initial timeout, and an adjusted timeout cannot become 0, as\r
+                                       if it were 0 the function would have exited. */\r
+                                       configASSERT( xInheritanceOccurred == pdFALSE );\r
+\r
+                                       /* The semaphore count was 0 and no block time is specified\r
+                                       (or the block time has expired) so exit now. */\r
+                                       taskEXIT_CRITICAL();\r
+                                       traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                                       return errQUEUE_EMPTY;\r
+                               }\r
+                               else if( xEntryTimeSet == pdFALSE )\r
+                               {\r
+                                       /* The semaphore count was 0 and a block time was specified\r
+                                       so configure the timeout structure ready to block. */\r
+                                       vTaskSetTimeOutState( &xTimeOut );\r
+                                       xEntryTimeSet = pdTRUE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       /* Entry time was already set. */\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               /* Interrupts and other tasks can give to and take from the semaphore\r
+               now the critical section has been exited. */\r
 \r
-                       /* A task can only have an inherited priority if it is a mutex\r
-                       holder - and if there is a mutex holder then the mutex cannot be\r
-                       given from an ISR.  As this is the ISR version of the function it\r
-                       can be assumed there is no mutex holder and no need to determine if\r
-                       priority disinheritance is needed.  Simply increase the count of\r
-                       messages (semaphores) available. */\r
-                       ++( pxQueue->uxMessagesWaiting );\r
+               vTaskSuspendAll();\r
+               prvLockQueue( pxQueue );\r
 \r
-                       /* The event list is not altered if the queue is locked.  This will\r
-                       be done when the queue is unlocked later. */\r
-                       if( pxQueue->xTxLock == queueUNLOCKED )\r
+               /* Update the timeout state to see if it has expired yet. */\r
+               if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
+               {\r
+                       /* A block time is specified and not expired.  If the semaphore\r
+                       count is 0 then enter the Blocked state to wait for a semaphore to\r
+                       become available.  As semaphores are implemented with queues the\r
+                       queue being empty is equivalent to the semaphore count being 0. */\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
                        {\r
-                               #if ( configUSE_QUEUE_SETS == 1 )\r
+                               traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
+\r
+                               #if ( configUSE_MUTEXES == 1 )\r
                                {\r
-                                       if( pxQueue->pxQueueSetContainer != NULL )\r
+                                       if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
                                        {\r
-                                               if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) != pdFALSE )\r
-                                               {\r
-                                                       /* The semaphore is a member of a queue set, and\r
-                                                       posting to the queue set caused a higher priority\r
-                                                       task to unblock.  A context switch is required. */\r
-                                                       if( pxHigherPriorityTaskWoken != NULL )\r
-                                                       {\r
-                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
-                                                       }\r
-                                                       else\r
-                                                       {\r
-                                                               mtCOVERAGE_TEST_MARKER();\r
-                                                       }\r
-                                               }\r
-                                               else\r
+                                               taskENTER_CRITICAL();\r
                                                {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
+                                                       xInheritanceOccurred = xTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
                                                }\r
+                                               taskEXIT_CRITICAL();\r
                                        }\r
                                        else\r
                                        {\r
-                                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
-                                               {\r
-                                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
-                                                       {\r
-                                                               /* The task waiting has a higher priority so\r
-                                                               record that a context switch is required. */\r
-                                                               if( pxHigherPriorityTaskWoken != NULL )\r
-                                                               {\r
-                                                                       *pxHigherPriorityTaskWoken = pdTRUE;\r
-                                                               }\r
-                                                               else\r
-                                                               {\r
-                                                                       mtCOVERAGE_TEST_MARKER();\r
-                                                               }\r
-                                                       }\r
-                                                       else\r
-                                                       {\r
-                                                               mtCOVERAGE_TEST_MARKER();\r
-                                                       }\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
-                                               }\r
+                                               mtCOVERAGE_TEST_MARKER();\r
                                        }\r
                                }\r
-                               #else /* configUSE_QUEUE_SETS */\r
+                               #endif\r
+\r
+                               vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
+                               prvUnlockQueue( pxQueue );\r
+                               if( xTaskResumeAll() == pdFALSE )\r
                                {\r
-                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                                       portYIELD_WITHIN_API();\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               /* There was no timeout and the semaphore count was not 0, so\r
+                               attempt to take the semaphore again. */\r
+                               prvUnlockQueue( pxQueue );\r
+                               ( void ) xTaskResumeAll();\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       /* Timed out. */\r
+                       prvUnlockQueue( pxQueue );\r
+                       ( void ) xTaskResumeAll();\r
+\r
+                       /* If the semaphore count is 0 exit now as the timeout has\r
+                       expired.  Otherwise return to attempt to take the semaphore that is\r
+                       known to be available.  As semaphores are implemented by queues the\r
+                       queue being empty is equivalent to the semaphore count being 0. */\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+                       {\r
+                               #if ( configUSE_MUTEXES == 1 )\r
+                               {\r
+                                       /* xInheritanceOccurred could only have be set if\r
+                                       pxQueue->uxQueueType == queueQUEUE_IS_MUTEX so no need to\r
+                                       test the mutex type again to check it is actually a mutex. */\r
+                                       if( xInheritanceOccurred != pdFALSE )\r
                                        {\r
-                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
-                                               {\r
-                                                       /* The task waiting has a higher priority so record that a\r
-                                                       context switch is required. */\r
-                                                       if( pxHigherPriorityTaskWoken != NULL )\r
-                                                       {\r
-                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
-                                                       }\r
-                                                       else\r
-                                                       {\r
-                                                               mtCOVERAGE_TEST_MARKER();\r
-                                                       }\r
-                                               }\r
-                                               else\r
+                                               taskENTER_CRITICAL();\r
                                                {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
+                                                       UBaseType_t uxHighestWaitingPriority;\r
+\r
+                                                       /* This task blocking on the mutex caused another\r
+                                                       task to inherit this task's priority.  Now this task\r
+                                                       has timed out the priority should be disinherited\r
+                                                       again, but only as low as the next highest priority\r
+                                                       task that is waiting for the same mutex. */\r
+                                                       uxHighestWaitingPriority = prvGetDisinheritPriorityAfterTimeout( pxQueue );\r
+                                                       vTaskPriorityDisinheritAfterTimeout( ( void * ) pxQueue->pxMutexHolder, uxHighestWaitingPriority );\r
                                                }\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               mtCOVERAGE_TEST_MARKER();\r
+                                               taskEXIT_CRITICAL();\r
                                        }\r
                                }\r
-                               #endif /* configUSE_QUEUE_SETS */\r
+                               #endif /* configUSE_MUTEXES */\r
+\r
+                               traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                               return errQUEUE_EMPTY;\r
                        }\r
                        else\r
                        {\r
-                               /* Increment the lock count so the task that unlocks the queue\r
-                               knows that data was posted while it was locked. */\r
-                               ++( pxQueue->xTxLock );\r
+                               mtCOVERAGE_TEST_MARKER();\r
                        }\r
-\r
-                       xReturn = pdPASS;\r
-               }\r
-               else\r
-               {\r
-                       traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\r
-                       xReturn = errQUEUE_FULL;\r
                }\r
        }\r
-       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
-\r
-       return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xJustPeeking )\r
+BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )\r
 {\r
 BaseType_t xEntryTimeSet = pdFALSE;\r
 TimeOut_t xTimeOut;\r
 int8_t *pcOriginalReadPosition;\r
 Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
 \r
-       configASSERT( pxQueue );\r
-       configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+       /* Check the pointer is not NULL. */\r
+       configASSERT( ( pxQueue ) );\r
+\r
+       /* The buffer into which data is received can only be NULL if the data size\r
+       is zero (so no data is copied into the buffer. */\r
+       configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+\r
+       /* Cannot block if the scheduler is suspended. */\r
        #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
        {\r
                configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
        }\r
        #endif\r
 \r
+\r
        /* This function relaxes the coding standard somewhat to allow return\r
        statements within the function itself.  This is done in the interest\r
        of execution time efficiency. */\r
@@ -1472,48 +1657,31 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        {\r
                taskENTER_CRITICAL();\r
                {\r
+                       const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\r
+\r
                        /* Is there data in the queue now?  To be running the calling task\r
                        must be the highest priority task wanting to access the queue. */\r
-                       if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )\r
+                       if( uxMessagesWaiting > ( UBaseType_t ) 0 )\r
                        {\r
-                               /* Remember the read position in case the queue is only being\r
-                               peeked. */\r
+                               /* Remember the read position so it can be reset after the data\r
+                               is read from the queue as this function is only peeking the\r
+                               data, not removing it. */\r
                                pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
 \r
                                prvCopyDataFromQueue( pxQueue, pvBuffer );\r
+                               traceQUEUE_PEEK( pxQueue );\r
 \r
-                               if( xJustPeeking == pdFALSE )\r
-                               {\r
-                                       traceQUEUE_RECEIVE( pxQueue );\r
-\r
-                                       /* Actually removing data, not just peeking. */\r
-                                       --( pxQueue->uxMessagesWaiting );\r
-\r
-                                       #if ( configUSE_MUTEXES == 1 )\r
-                                       {\r
-                                               if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
-                                               {\r
-                                                       /* Record the information required to implement\r
-                                                       priority inheritance should it become necessary. */\r
-                                                       pxQueue->pxMutexHolder = ( int8_t * ) pvTaskIncrementMutexHeldCount(); /*lint !e961 Cast is not redundant as TaskHandle_t is a typedef. */\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
-                                               }\r
-                                       }\r
-                                       #endif /* configUSE_MUTEXES */\r
+                               /* The data is not being removed, so reset the read pointer. */\r
+                               pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
 \r
-                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
+                               /* The data is being left in the queue, so see if there are\r
+                               any other tasks waiting for the data. */\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                               {\r
+                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                        {\r
-                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
-                                               {\r
-                                                       queueYIELD_IF_USING_PREEMPTION();\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
-                                               }\r
+                                               /* The task waiting has a higher priority than this task. */\r
+                                               queueYIELD_IF_USING_PREEMPTION();\r
                                        }\r
                                        else\r
                                        {\r
@@ -1522,30 +1690,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                }\r
                                else\r
                                {\r
-                                       traceQUEUE_PEEK( pxQueue );\r
-\r
-                                       /* The data is not being removed, so reset the read\r
-                                       pointer. */\r
-                                       pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
-\r
-                                       /* The data is being left in the queue, so see if there are\r
-                                       any other tasks waiting for the data. */\r
-                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
-                                       {\r
-                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
-                                               {\r
-                                                       /* The task waiting has a higher priority than this task. */\r
-                                                       queueYIELD_IF_USING_PREEMPTION();\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
-                                               }\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               mtCOVERAGE_TEST_MARKER();\r
-                                       }\r
+                                       mtCOVERAGE_TEST_MARKER();\r
                                }\r
 \r
                                taskEXIT_CRITICAL();\r
@@ -1564,7 +1709,8 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                else if( xEntryTimeSet == pdFALSE )\r
                                {\r
                                        /* The queue was empty and a block time was specified so\r
-                                       configure the timeout structure. */\r
+                                       configure the timeout structure ready to enter the blocked\r
+                                       state. */\r
                                        vTaskSetTimeOutState( &xTimeOut );\r
                                        xEntryTimeSet = pdTRUE;\r
                                }\r
@@ -1586,27 +1732,11 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                /* Update the timeout state to see if it has expired yet. */\r
                if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
                {\r
+                       /* Timeout has not expired yet, check to see if there is data in the\r
+                       queue now, and if not enter the Blocked state to wait for data. */\r
                        if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
                        {\r
                                traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
-\r
-                               #if ( configUSE_MUTEXES == 1 )\r
-                               {\r
-                                       if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
-                                       {\r
-                                               taskENTER_CRITICAL();\r
-                                               {\r
-                                                       vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
-                                               }\r
-                                               taskEXIT_CRITICAL();\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               mtCOVERAGE_TEST_MARKER();\r
-                                       }\r
-                               }\r
-                               #endif\r
-\r
                                vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
                                prvUnlockQueue( pxQueue );\r
                                if( xTaskResumeAll() == pdFALSE )\r
@@ -1620,13 +1750,16 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        }\r
                        else\r
                        {\r
-                               /* Try again. */\r
+                               /* There is data in the queue now, so don't enter the blocked\r
+                               state, instead return to try and obtain the data. */\r
                                prvUnlockQueue( pxQueue );\r
                                ( void ) xTaskResumeAll();\r
                        }\r
                }\r
                else\r
                {\r
+                       /* The timeout has expired.  If there is still no data in the queue\r
+                       exit, otherwise go back and try to read the data again. */\r
                        prvUnlockQueue( pxQueue );\r
                        ( void ) xTaskResumeAll();\r
 \r
@@ -1671,19 +1804,23 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 \r
        uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
        {\r
+               const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\r
+\r
                /* Cannot block in an ISR, so check there is data available. */\r
-               if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )\r
+               if( uxMessagesWaiting > ( UBaseType_t ) 0 )\r
                {\r
+                       const int8_t cRxLock = pxQueue->cRxLock;\r
+\r
                        traceQUEUE_RECEIVE_FROM_ISR( pxQueue );\r
 \r
                        prvCopyDataFromQueue( pxQueue, pvBuffer );\r
-                       --( pxQueue->uxMessagesWaiting );\r
+                       pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;\r
 \r
                        /* If the queue is locked the event list will not be modified.\r
                        Instead update the lock count so the task that unlocks the queue\r
                        will know that an ISR has removed data while the queue was\r
                        locked. */\r
-                       if( pxQueue->xRxLock == queueUNLOCKED )\r
+                       if( cRxLock == queueUNLOCKED )\r
                        {\r
                                if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
                                {\r
@@ -1714,7 +1851,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        {\r
                                /* Increment the lock count so the task that unlocks the queue\r
                                knows that data was removed while it was locked. */\r
-                               ++( pxQueue->xRxLock );\r
+                               pxQueue->cRxLock = ( int8_t ) ( cRxLock + 1 );\r
                        }\r
 \r
                        xReturn = pdPASS;\r
@@ -1836,37 +1973,26 @@ void vQueueDelete( QueueHandle_t xQueue )
 Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
 \r
        configASSERT( pxQueue );\r
-\r
        traceQUEUE_DELETE( pxQueue );\r
+\r
        #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
        {\r
                vQueueUnregisterQueue( pxQueue );\r
        }\r
        #endif\r
 \r
-       #if( configSUPPORT_STATIC_ALLOCATION == 0 )\r
+       #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )\r
        {\r
-               /* The queue and the queue storage area will have been dynamically\r
-               allocated in one go. */\r
+               /* The queue can only have been allocated dynamically - free it\r
+               again. */\r
                vPortFree( pxQueue );\r
        }\r
-       #else\r
+       #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\r
        {\r
-               if( ( pxQueue->ucStaticAllocationFlags & queueSTATICALLY_ALLOCATED_STORAGE ) == 0 )\r
-               {\r
-                       /* The queue storage area was dynamically allocated, so must be\r
-                       freed. */\r
-                       vPortFree( pxQueue->pcHead );\r
-               }\r
-               else\r
-               {\r
-                       mtCOVERAGE_TEST_MARKER();\r
-               }\r
-\r
-               if( ( pxQueue->ucStaticAllocationFlags & queueSTATICALLY_ALLOCATED_QUEUE_STRUCT ) == 0 )\r
+               /* The queue could have been allocated statically or dynamically, so\r
+               check before attempting to free the memory. */\r
+               if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdFALSE )\r
                {\r
-                       /* The queue structure was dynamically allocated, so must be\r
-                       free. */\r
                        vPortFree( pxQueue );\r
                }\r
                else\r
@@ -1874,7 +2000,13 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        mtCOVERAGE_TEST_MARKER();\r
                }\r
        }\r
-       #endif\r
+       #else\r
+       {\r
+               /* The queue must have been statically allocated, so is not going to be\r
+               deleted.  Avoid compiler warnings about the unused parameter. */\r
+               ( void ) pxQueue;\r
+       }\r
+       #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1908,9 +2040,41 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 #endif /* configUSE_TRACE_FACILITY */\r
 /*-----------------------------------------------------------*/\r
 \r
+#if( configUSE_MUTEXES == 1 )\r
+\r
+       static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue )\r
+       {\r
+       UBaseType_t uxHighestPriorityOfWaitingTasks;\r
+\r
+               /* If a task waiting for a mutex causes the mutex holder to inherit a\r
+               priority, but the waiting task times out, then the holder should\r
+               disinherit the priority - but only down to the highest priority of any\r
+               other tasks that are waiting for the same mutex.  For this purpose,\r
+               return the priority of the highest priority task that is waiting for the\r
+               mutex. */\r
+               if( listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) ) > 0 )\r
+               {\r
+                       uxHighestPriorityOfWaitingTasks = configMAX_PRIORITIES - listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) );\r
+               }\r
+               else\r
+               {\r
+                       uxHighestPriorityOfWaitingTasks = tskIDLE_PRIORITY;\r
+               }\r
+\r
+               return uxHighestPriorityOfWaitingTasks;\r
+       }\r
+\r
+#endif /* configUSE_MUTEXES */\r
+/*-----------------------------------------------------------*/\r
+\r
 static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )\r
 {\r
 BaseType_t xReturn = pdFALSE;\r
+UBaseType_t uxMessagesWaiting;\r
+\r
+       /* This function is called from a critical section. */\r
+\r
+       uxMessagesWaiting = pxQueue->uxMessagesWaiting;\r
 \r
        if( pxQueue->uxItemSize == ( UBaseType_t ) 0 )\r
        {\r
@@ -1957,13 +2121,13 @@ BaseType_t xReturn = pdFALSE;
 \r
                if( xPosition == queueOVERWRITE )\r
                {\r
-                       if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )\r
+                       if( uxMessagesWaiting > ( UBaseType_t ) 0 )\r
                        {\r
                                /* An item is not being added but overwritten, so subtract\r
                                one from the recorded number of items in the queue so when\r
                                one is added again below the number of recorded items remains\r
                                correct. */\r
-                               --( pxQueue->uxMessagesWaiting );\r
+                               --uxMessagesWaiting;\r
                        }\r
                        else\r
                        {\r
@@ -1976,7 +2140,7 @@ BaseType_t xReturn = pdFALSE;
                }\r
        }\r
 \r
-       ++( pxQueue->uxMessagesWaiting );\r
+       pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1;\r
 \r
        return xReturn;\r
 }\r
@@ -2010,8 +2174,10 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
        updated. */\r
        taskENTER_CRITICAL();\r
        {\r
+               int8_t cTxLock = pxQueue->cTxLock;\r
+\r
                /* See if data was added to the queue while it was locked. */\r
-               while( pxQueue->xTxLock > queueLOCKED_UNMODIFIED )\r
+               while( cTxLock > queueLOCKED_UNMODIFIED )\r
                {\r
                        /* Data was posted while the queue was locked.  Are any tasks\r
                        blocked waiting for data to become available? */\r
@@ -2079,17 +2245,19 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
                        }\r
                        #endif /* configUSE_QUEUE_SETS */\r
 \r
-                       --( pxQueue->xTxLock );\r
+                       --cTxLock;\r
                }\r
 \r
-               pxQueue->xTxLock = queueUNLOCKED;\r
+               pxQueue->cTxLock = queueUNLOCKED;\r
        }\r
        taskEXIT_CRITICAL();\r
 \r
        /* Do the same for the Rx lock. */\r
        taskENTER_CRITICAL();\r
        {\r
-               while( pxQueue->xRxLock > queueLOCKED_UNMODIFIED )\r
+               int8_t cRxLock = pxQueue->cRxLock;\r
+\r
+               while( cRxLock > queueLOCKED_UNMODIFIED )\r
                {\r
                        if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
                        {\r
@@ -2102,7 +2270,7 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
                                        mtCOVERAGE_TEST_MARKER();\r
                                }\r
 \r
-                               --( pxQueue->xRxLock );\r
+                               --cRxLock;\r
                        }\r
                        else\r
                        {\r
@@ -2110,7 +2278,7 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
                        }\r
                }\r
 \r
-               pxQueue->xRxLock = queueUNLOCKED;\r
+               pxQueue->cRxLock = queueUNLOCKED;\r
        }\r
        taskEXIT_CRITICAL();\r
 }\r
@@ -2500,7 +2668,7 @@ BaseType_t xReturn;
 \r
 #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
 \r
-       const char *pcQueueGetQueueName( QueueHandle_t xQueue ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+       const char *pcQueueGetName( QueueHandle_t xQueue ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
        {\r
        UBaseType_t ux;\r
        const char *pcReturn = NULL; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
@@ -2521,7 +2689,7 @@ BaseType_t xReturn;
                }\r
 \r
                return pcReturn;\r
-       }\r
+       } /*lint !e818 xQueue cannot be a pointer to const because it is a typedef. */\r
 \r
 #endif /* configQUEUE_REGISTRY_SIZE */\r
 /*-----------------------------------------------------------*/\r
@@ -2594,13 +2762,13 @@ BaseType_t xReturn;
 #endif /* configUSE_TIMERS */\r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( configUSE_QUEUE_SETS == 1 )\r
+#if( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
 \r
        QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength )\r
        {\r
        QueueSetHandle_t pxQueue;\r
 \r
-               pxQueue = xQueueGenericCreate( uxEventQueueLength, sizeof( Queue_t * ), NULL, NULL, queueQUEUE_TYPE_SET );\r
+               pxQueue = xQueueGenericCreate( uxEventQueueLength, ( UBaseType_t ) sizeof( Queue_t * ), queueQUEUE_TYPE_SET );\r
 \r
                return pxQueue;\r
        }\r
@@ -2683,7 +2851,7 @@ BaseType_t xReturn;
        {\r
        QueueSetMemberHandle_t xReturn = NULL;\r
 \r
-               ( void ) xQueueGenericReceive( ( QueueHandle_t ) xQueueSet, &xReturn, xTicksToWait, pdFALSE ); /*lint !e961 Casting from one typedef to another is not redundant. */\r
+               ( void ) xQueueReceive( ( QueueHandle_t ) xQueueSet, &xReturn, xTicksToWait ); /*lint !e961 Casting from one typedef to another is not redundant. */\r
                return xReturn;\r
        }\r
 \r
@@ -2717,12 +2885,14 @@ BaseType_t xReturn;
 \r
                if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )\r
                {\r
+                       const int8_t cTxLock = pxQueueSetContainer->cTxLock;\r
+\r
                        traceQUEUE_SEND( pxQueueSetContainer );\r
 \r
                        /* The data copied is the handle of the queue that contains data. */\r
                        xReturn = prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );\r
 \r
-                       if( pxQueueSetContainer->xTxLock == queueUNLOCKED )\r
+                       if( cTxLock == queueUNLOCKED )\r
                        {\r
                                if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                {\r
@@ -2743,7 +2913,7 @@ BaseType_t xReturn;
                        }\r
                        else\r
                        {\r
-                               ( pxQueueSetContainer->xTxLock )++;\r
+                               pxQueueSetContainer->cTxLock = ( int8_t ) ( cTxLock + 1 );\r
                        }\r
                }\r
                else\r