]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/queue.c
Update version numbers ready for release.
[freertos] / FreeRTOS / Source / queue.c
index 7b2df093b6a116266cb5af6f939f77d362c6a4a0..bd0648b722b9c5f1d2fff9dfd0a728a29dd1ad08 100644 (file)
@@ -1,71 +1,29 @@
 /*\r
-    FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.\r
-    All rights reserved\r
-\r
-    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
-\r
-    This file is part of the FreeRTOS distribution.\r
-\r
-    FreeRTOS is free software; you can redistribute it and/or modify it under\r
-    the terms of the GNU General Public License (version 2) as published by the\r
-    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
-\r
-    ***************************************************************************\r
-    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
-    >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
-    >>!   obliged to provide the source code for proprietary components     !<<\r
-    >>!   outside of the FreeRTOS kernel.                                   !<<\r
-    ***************************************************************************\r
-\r
-    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
-    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
-    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
-    link: http://www.freertos.org/a00114.html\r
-\r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS provides completely free yet professionally developed,    *\r
-     *    robust, strictly quality controlled, supported, and cross          *\r
-     *    platform software that is more than just the market leader, it     *\r
-     *    is the industry's de facto standard.                               *\r
-     *                                                                       *\r
-     *    Help yourself get started quickly while simultaneously helping     *\r
-     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
-     *    tutorial book, reference manual, or both:                          *\r
-     *    http://www.FreeRTOS.org/Documentation                              *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
-    the FAQ page "My application does not run, what could be wrong?".  Have you\r
-    defined configASSERT()?\r
-\r
-    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
-    embedded software for free we request you assist our global community by\r
-    participating in the support forum.\r
-\r
-    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
-    be as productive as possible as early as possible.  Now you can receive\r
-    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
-    Ltd, and the world's leading authority on the world's leading RTOS.\r
-\r
-    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
-    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
-    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
-\r
-    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
-    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
-\r
-    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
-    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
-    licenses offer ticketed support, indemnification and commercial middleware.\r
-\r
-    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
-    engineered and independently SIL3 certified version for use in safety and\r
-    mission critical applications that require provable dependability.\r
-\r
-    1 tab == 4 spaces!\r
-*/\r
+ * FreeRTOS Kernel V10.1.1\r
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
 \r
 #include <stdlib.h>\r
 #include <string.h>\r
@@ -83,11 +41,11 @@ task.h is included from an application file. */
        #include "croutine.h"\r
 #endif\r
 \r
-/* Lint e961 and e750 are suppressed as a MISRA exception justified because the\r
-MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\r
-header files above, but not in this file, in order to generate the correct\r
-privileged Vs unprivileged linkage and placement. */\r
-#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
+/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified\r
+because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined\r
+for the header files above, but not in this file, in order to generate the\r
+correct privileged Vs unprivileged linkage and placement. */\r
+#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */\r
 \r
 \r
 /* Constants used with the cRxLock and cTxLock structure members. */\r
@@ -98,17 +56,26 @@ privileged Vs unprivileged linkage and placement. */
 pcTail members are used as pointers into the queue storage area.  When the\r
 Queue_t structure is used to represent a mutex pcHead and pcTail pointers are\r
 not necessary, and the pcHead pointer is set to NULL to indicate that the\r
-pcTail pointer actually points to the mutex holder (if any).  Map alternative\r
-names to the pcHead and pcTail structure members to ensure the readability of\r
-the code is maintained despite this dual use of two structure members.  An\r
-alternative implementation would be to use a union, but use of a union is\r
-against the coding standard (although an exception to the standard has been\r
-permitted where the dual use also significantly changes the type of the\r
-structure member). */\r
-#define pxMutexHolder                                  pcTail\r
+structure instead holds a pointer to the mutex holder (if any).  Map alternative\r
+names to the pcHead and structure member to ensure the readability of the code\r
+is maintained.  The QueuePointers_t and SemaphoreData_t types are used to form\r
+a union as their usage is mutually exclusive dependent on what the queue is\r
+being used for. */\r
 #define uxQueueType                                            pcHead\r
 #define queueQUEUE_IS_MUTEX                            NULL\r
 \r
+typedef struct QueuePointers\r
+{\r
+       int8_t *pcTail;                                 /*< Points to the byte at the end of the queue storage area.  Once more byte is allocated than necessary to store the queue items, this is used as a marker. */\r
+       int8_t *pcReadFrom;                             /*< Points to the last place that a queued item was read from when the structure is used as a queue. */\r
+} QueuePointers_t;\r
+\r
+typedef struct SemaphoreData\r
+{\r
+       TaskHandle_t xMutexHolder;               /*< The handle of the task that holds the mutex. */\r
+       UBaseType_t uxRecursiveCallCount;/*< Maintains a count of the number of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */\r
+} SemaphoreData_t;\r
+\r
 /* Semaphores do not actually store or copy data, so have an item size of\r
 zero. */\r
 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( UBaseType_t ) 0 )\r
@@ -125,18 +92,17 @@ zero. */
 /*\r
  * Definition of the queue used by the scheduler.\r
  * Items are queued by copy, not reference.  See the following link for the\r
- * rationale: http://www.freertos.org/Embedded-RTOS-Queues.html\r
+ * rationale: https://www.freertos.org/Embedded-RTOS-Queues.html\r
  */\r
-typedef struct QueueDefinition\r
+typedef struct QueueDefinition /* Using old naming convention so as not to break kernel aware debuggers. */\r
 {\r
        int8_t *pcHead;                                 /*< Points to the beginning of the queue storage area. */\r
-       int8_t *pcTail;                                 /*< Points to the byte at the end of the queue storage area.  Once more byte is allocated than necessary to store the queue items, this is used as a marker. */\r
        int8_t *pcWriteTo;                              /*< Points to the free next place in the storage area. */\r
 \r
-       union                                                   /* Use of a union is an exception to the coding standard to ensure two mutually exclusive structure members don't appear simultaneously (wasting RAM). */\r
+       union\r
        {\r
-               int8_t *pcReadFrom;                     /*< Points to the last place that a queued item was read from when the structure is used as a queue. */\r
-               UBaseType_t uxRecursiveCallCount;/*< Maintains a count of the number of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */\r
+               QueuePointers_t xQueue;         /*< Data required exclusively when this structure is used as a queue. */\r
+               SemaphoreData_t xSemaphore; /*< Data required exclusively when this structure is used as a semaphore. */\r
        } u;\r
 \r
        List_t xTasksWaitingToSend;             /*< List of tasks that are blocked waiting to post onto this queue.  Stored in priority order. */\r
@@ -288,16 +254,16 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
 \r
 BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue )\r
 {\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
        configASSERT( pxQueue );\r
 \r
        taskENTER_CRITICAL();\r
        {\r
-               pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );\r
+               pxQueue->u.xQueue.pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */\r
                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->u.xQueue.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - 1U ) * pxQueue->uxItemSize ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */\r
                pxQueue->cRxLock = queueUNLOCKED;\r
                pxQueue->cTxLock = queueUNLOCKED;\r
 \r
@@ -363,13 +329,14 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        the real queue and semaphore structures. */\r
                        volatile size_t xSize = sizeof( StaticQueue_t );\r
                        configASSERT( xSize == sizeof( Queue_t ) );\r
+                       ( void ) xSize; /* Keeps lint quiet when configASSERT() is not defined. */\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
+               pxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\r
 \r
                if( pxNewQueue != NULL )\r
                {\r
@@ -384,6 +351,11 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 \r
                        prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );\r
                }\r
+               else\r
+               {\r
+                       traceQUEUE_CREATE_FAILED( ucQueueType );\r
+                       mtCOVERAGE_TEST_MARKER();\r
+               }\r
 \r
                return pxNewQueue;\r
        }\r
@@ -413,13 +385,23 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
                }\r
 \r
-               pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes );\r
+               /* Allocate the queue and storage area.  Justification for MISRA\r
+               deviation as follows:  pvPortMalloc() always ensures returned memory\r
+               blocks are aligned per the requirements of the MCU stack.  In this case\r
+               pvPortMalloc() must return a pointer that is guaranteed to meet the\r
+               alignment requirements of the Queue_t structure - which in this case\r
+               is an int8_t *.  Therefore, whenever the stack alignment requirements\r
+               are greater than or equal to the pointer to char requirements the cast\r
+               is safe.  In other cases alignment requirements are not strict (one or\r
+               two bytes). */\r
+               pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes ); /*lint !e9087 !e9079 see comment above. */\r
 \r
                if( pxNewQueue != NULL )\r
                {\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
+                       pucQueueStorage = ( uint8_t * ) pxNewQueue;\r
+                       pucQueueStorage += sizeof( Queue_t ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */\r
 \r
                        #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
                        {\r
@@ -432,6 +414,11 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 \r
                        prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );\r
                }\r
+               else\r
+               {\r
+                       traceQUEUE_CREATE_FAILED( ucQueueType );\r
+                       mtCOVERAGE_TEST_MARKER();\r
+               }\r
 \r
                return pxNewQueue;\r
        }\r
@@ -491,11 +478,11 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
                        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
-                       pxNewQueue->pxMutexHolder = NULL;\r
+                       pxNewQueue->u.xSemaphore.xMutexHolder = NULL;\r
                        pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;\r
 \r
                        /* In case this is a recursive mutex. */\r
-                       pxNewQueue->u.uxRecursiveCallCount = 0;\r
+                       pxNewQueue->u.xSemaphore.uxRecursiveCallCount = 0;\r
 \r
                        traceCREATE_MUTEX( pxNewQueue );\r
 \r
@@ -515,13 +502,13 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
 \r
        QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType )\r
        {\r
-       Queue_t *pxNewQueue;\r
+       QueueHandle_t xNewQueue;\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
+               xNewQueue = xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType );\r
+               prvInitialiseMutex( ( Queue_t * ) xNewQueue );\r
 \r
-               return pxNewQueue;\r
+               return xNewQueue;\r
        }\r
 \r
 #endif /* configUSE_MUTEXES */\r
@@ -531,17 +518,17 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
 \r
        QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue )\r
        {\r
-       Queue_t *pxNewQueue;\r
+       QueueHandle_t xNewQueue;\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
+               xNewQueue = xQueueGenericCreateStatic( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType );\r
+               prvInitialiseMutex( ( Queue_t * ) xNewQueue );\r
 \r
-               return pxNewQueue;\r
+               return xNewQueue;\r
        }\r
 \r
 #endif /* configUSE_MUTEXES */\r
@@ -549,9 +536,10 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
 \r
 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )\r
 \r
-       void* xQueueGetMutexHolder( QueueHandle_t xSemaphore )\r
+       TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore )\r
        {\r
-       void *pxReturn;\r
+       TaskHandle_t pxReturn;\r
+       Queue_t * const pxSemaphore = ( Queue_t * ) xSemaphore;\r
 \r
                /* This function is called by xSemaphoreGetMutexHolder(), and should not\r
                be called directly.  Note:  This is a good way of determining if the\r
@@ -560,9 +548,9 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
                following critical section exiting and the function returning. */\r
                taskENTER_CRITICAL();\r
                {\r
-                       if( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )\r
+                       if( pxSemaphore->uxQueueType == queueQUEUE_IS_MUTEX )\r
                        {\r
-                               pxReturn = ( void * ) ( ( Queue_t * ) xSemaphore )->pxMutexHolder;\r
+                               pxReturn = pxSemaphore->u.xSemaphore.xMutexHolder;\r
                        }\r
                        else\r
                        {\r
@@ -579,9 +567,9 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
 \r
 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )\r
 \r
-       void* xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore )\r
+       TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore )\r
        {\r
-       void *pxReturn;\r
+       TaskHandle_t pxReturn;\r
 \r
                configASSERT( xSemaphore );\r
 \r
@@ -590,7 +578,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
                not required here. */\r
                if( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )\r
                {\r
-                       pxReturn = ( void * ) ( ( Queue_t * ) xSemaphore )->pxMutexHolder;\r
+                       pxReturn = ( ( Queue_t * ) xSemaphore )->u.xSemaphore.xMutexHolder;\r
                }\r
                else\r
                {\r
@@ -612,25 +600,25 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
 \r
                configASSERT( pxMutex );\r
 \r
-               /* If this is the task that holds the mutex then pxMutexHolder will not\r
+               /* If this is the task that holds the mutex then xMutexHolder will not\r
                change outside of this task.  If this task does not hold the mutex then\r
                pxMutexHolder can never coincidentally equal the tasks handle, and as\r
                this is the only condition we are interested in it does not matter if\r
                pxMutexHolder is accessed simultaneously by another task.  Therefore no\r
                mutual exclusion is required to test the pxMutexHolder variable. */\r
-               if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Not a redundant cast as TaskHandle_t is a typedef. */\r
+               if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() )\r
                {\r
                        traceGIVE_MUTEX_RECURSIVE( pxMutex );\r
 \r
-                       /* uxRecursiveCallCount cannot be zero if pxMutexHolder is equal to\r
+                       /* uxRecursiveCallCount cannot be zero if xMutexHolder is equal to\r
                        the task handle, therefore no underflow check is required.  Also,\r
                        uxRecursiveCallCount is only modified by the mutex holder, and as\r
                        there can only be one, no mutual exclusion is required to modify the\r
                        uxRecursiveCallCount member. */\r
-                       ( pxMutex->u.uxRecursiveCallCount )--;\r
+                       ( pxMutex->u.xSemaphore.uxRecursiveCallCount )--;\r
 \r
                        /* Has the recursive call count unwound to 0? */\r
-                       if( pxMutex->u.uxRecursiveCallCount == ( UBaseType_t ) 0 )\r
+                       if( pxMutex->u.xSemaphore.uxRecursiveCallCount == ( UBaseType_t ) 0 )\r
                        {\r
                                /* Return the mutex.  This will automatically unblock any other\r
                                task that might be waiting to access the mutex. */\r
@@ -672,9 +660,9 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
 \r
                traceTAKE_MUTEX_RECURSIVE( pxMutex );\r
 \r
-               if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as TaskHandle_t is a typedef. */\r
+               if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() )\r
                {\r
-                       ( pxMutex->u.uxRecursiveCallCount )++;\r
+                       ( pxMutex->u.xSemaphore.uxRecursiveCallCount )++;\r
                        xReturn = pdPASS;\r
                }\r
                else\r
@@ -686,7 +674,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
                        before reaching here. */\r
                        if( xReturn != pdFAIL )\r
                        {\r
-                               ( pxMutex->u.uxRecursiveCallCount )++;\r
+                               ( pxMutex->u.xSemaphore.uxRecursiveCallCount )++;\r
                        }\r
                        else\r
                        {\r
@@ -760,7 +748,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQ
 {\r
 BaseType_t xEntryTimeSet = pdFALSE, xYieldRequired;\r
 TimeOut_t xTimeOut;\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
@@ -772,9 +760,9 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        #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
+       /*lint -save -e904 This function relaxes the coding standard somewhat to\r
+       allow return statements within the function itself.  This is done in the\r
+       interest of execution time efficiency. */\r
        for( ;; )\r
        {\r
                taskENTER_CRITICAL();\r
@@ -786,13 +774,23 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
                        {\r
                                traceQUEUE_SEND( pxQueue );\r
-                               xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
 \r
                                #if ( configUSE_QUEUE_SETS == 1 )\r
                                {\r
+                               UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;\r
+\r
+                                       xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
+\r
                                        if( pxQueue->pxQueueSetContainer != NULL )\r
                                        {\r
-                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE )\r
+                                               if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )\r
+                                               {\r
+                                                       /* Do not notify the queue set as an existing item\r
+                                                       was overwritten in the queue so the number of items\r
+                                                       in the queue has not changed. */\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
+                                               else if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != 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
@@ -839,6 +837,8 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                }\r
                                #else /* configUSE_QUEUE_SETS */\r
                                {\r
+                                       xYieldRequired = 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
@@ -891,7 +891,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                {\r
                                        /* The queue was full and a block time was specified so\r
                                        configure the timeout structure. */\r
-                                       vTaskSetTimeOutState( &xTimeOut );\r
+                                       vTaskInternalSetTimeOutState( &xTimeOut );\r
                                        xEntryTimeSet = pdTRUE;\r
                                }\r
                                else\r
@@ -918,8 +918,8 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );\r
 \r
                                /* Unlocking the queue means queue events can effect the\r
-                               event list.  It is possible     that interrupts occurring now\r
-                               remove this task from the event list again - but as the\r
+                               event list.  It is possible that interrupts occurring now\r
+                               remove this task from the event list again - but as the\r
                                scheduler is suspended the task will go onto the pending\r
                                ready last instead of the actual ready list. */\r
                                prvUnlockQueue( pxQueue );\r
@@ -950,7 +950,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        traceQUEUE_SEND_FAILED( pxQueue );\r
                        return errQUEUE_FULL;\r
                }\r
-       }\r
+       } /*lint -restore */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -958,7 +958,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pv
 {\r
 BaseType_t xReturn;\r
 UBaseType_t uxSavedInterruptStatus;\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
@@ -1109,7 +1109,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherP
 {\r
 BaseType_t xReturn;\r
 UBaseType_t uxSavedInterruptStatus;\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = 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
@@ -1126,7 +1126,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        /* 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
+       configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->u.xSemaphore.xMutexHolder != 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
@@ -1274,7 +1274,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_
 {\r
 BaseType_t xEntryTimeSet = pdFALSE;\r
 TimeOut_t xTimeOut;\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
        /* Check the pointer is not NULL. */\r
        configASSERT( ( pxQueue ) );\r
@@ -1291,10 +1291,9 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        #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
+       /*lint -save -e904  This function relaxes the coding standard somewhat to\r
+       allow return statements within the function itself.  This is done in the\r
+       interest of execution time efficiency. */\r
        for( ;; )\r
        {\r
                taskENTER_CRITICAL();\r
@@ -1346,7 +1345,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                {\r
                                        /* The queue was empty and a block time was specified so\r
                                        configure the timeout structure. */\r
-                                       vTaskSetTimeOutState( &xTimeOut );\r
+                                       vTaskInternalSetTimeOutState( &xTimeOut );\r
                                        xEntryTimeSet = pdTRUE;\r
                                }\r
                                else\r
@@ -1408,7 +1407,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
-       }\r
+       } /*lint -restore */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1416,7 +1415,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait )
 {\r
 BaseType_t xEntryTimeSet = pdFALSE;\r
 TimeOut_t xTimeOut;\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
 #if( configUSE_MUTEXES == 1 )\r
        BaseType_t xInheritanceOccurred = pdFALSE;\r
@@ -1437,10 +1436,9 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        #endif\r
 \r
 \r
-       /* This function relaxes the coding standard somewhat to allow return\r
+       /*lint -save -e904 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
@@ -1465,7 +1463,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        {\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
+                                               pxQueue->u.xSemaphore.xMutexHolder = pvTaskIncrementMutexHeldCount();\r
                                        }\r
                                        else\r
                                        {\r
@@ -1502,7 +1500,11 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        /* 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
+                                       #if( configUSE_MUTEXES == 1 )\r
+                                       {\r
+                                               configASSERT( xInheritanceOccurred == pdFALSE );\r
+                                       }\r
+                                       #endif /* configUSE_MUTEXES */\r
 \r
                                        /* The semaphore count was 0 and no block time is specified\r
                                        (or the block time has expired) so exit now. */\r
@@ -1514,7 +1516,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                {\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
+                                       vTaskInternalSetTimeOutState( &xTimeOut );\r
                                        xEntryTimeSet = pdTRUE;\r
                                }\r
                                else\r
@@ -1549,7 +1551,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        {\r
                                                taskENTER_CRITICAL();\r
                                                {\r
-                                                       xInheritanceOccurred = xTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
+                                                       xInheritanceOccurred = xTaskPriorityInherit( pxQueue->u.xSemaphore.xMutexHolder );\r
                                                }\r
                                                taskEXIT_CRITICAL();\r
                                        }\r
@@ -1608,7 +1610,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                                        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
+                                                       vTaskPriorityDisinheritAfterTimeout( pxQueue->u.xSemaphore.xMutexHolder, uxHighestWaitingPriority );\r
                                                }\r
                                                taskEXIT_CRITICAL();\r
                                        }\r
@@ -1623,7 +1625,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
-       }\r
+       } /*lint -restore */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1632,7 +1634,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t x
 BaseType_t xEntryTimeSet = pdFALSE;\r
 TimeOut_t xTimeOut;\r
 int8_t *pcOriginalReadPosition;\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
        /* Check the pointer is not NULL. */\r
        configASSERT( ( pxQueue ) );\r
@@ -1649,10 +1651,9 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        #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
+       /*lint -save -e904  This function relaxes the coding standard somewhat to\r
+       allow return statements within the function itself.  This is done in the\r
+       interest of execution time efficiency. */\r
        for( ;; )\r
        {\r
                taskENTER_CRITICAL();\r
@@ -1666,13 +1667,13 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                /* 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
+                               pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom;\r
 \r
                                prvCopyDataFromQueue( pxQueue, pvBuffer );\r
                                traceQUEUE_PEEK( pxQueue );\r
 \r
                                /* The data is not being removed, so reset the read pointer. */\r
-                               pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
+                               pxQueue->u.xQueue.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
@@ -1703,7 +1704,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        /* 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
+                                       traceQUEUE_PEEK_FAILED( pxQueue );\r
                                        return errQUEUE_EMPTY;\r
                                }\r
                                else if( xEntryTimeSet == pdFALSE )\r
@@ -1711,7 +1712,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        /* The queue was empty and a block time was specified so\r
                                        configure the timeout structure ready to enter the blocked\r
                                        state. */\r
-                                       vTaskSetTimeOutState( &xTimeOut );\r
+                                       vTaskInternalSetTimeOutState( &xTimeOut );\r
                                        xEntryTimeSet = pdTRUE;\r
                                }\r
                                else\r
@@ -1736,7 +1737,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        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
+                               traceBLOCKING_ON_QUEUE_PEEK( pxQueue );\r
                                vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
                                prvUnlockQueue( pxQueue );\r
                                if( xTaskResumeAll() == pdFALSE )\r
@@ -1765,7 +1766,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 \r
                        if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
                        {\r
-                               traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                               traceQUEUE_PEEK_FAILED( pxQueue );\r
                                return errQUEUE_EMPTY;\r
                        }\r
                        else\r
@@ -1773,7 +1774,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
-       }\r
+       } /*lint -restore */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1781,7 +1782,7 @@ BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, Ba
 {\r
 BaseType_t xReturn;\r
 UBaseType_t uxSavedInterruptStatus;\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
@@ -1873,7 +1874,7 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,  void * const pvBuffer )
 BaseType_t xReturn;\r
 UBaseType_t uxSavedInterruptStatus;\r
 int8_t *pcOriginalReadPosition;\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
@@ -1904,9 +1905,9 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 \r
                        /* Remember the read position so it can be reset as nothing is\r
                        actually being removed from the queue. */\r
-                       pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
+                       pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom;\r
                        prvCopyDataFromQueue( pxQueue, pvBuffer );\r
-                       pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
+                       pxQueue->u.xQueue.pcReadFrom = pcOriginalReadPosition;\r
 \r
                        xReturn = pdPASS;\r
                }\r
@@ -1941,9 +1942,8 @@ UBaseType_t uxReturn;
 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )\r
 {\r
 UBaseType_t uxReturn;\r
-Queue_t *pxQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
-       pxQueue = ( Queue_t * ) xQueue;\r
        configASSERT( pxQueue );\r
 \r
        taskENTER_CRITICAL();\r
@@ -1959,10 +1959,10 @@ Queue_t *pxQueue;
 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue )\r
 {\r
 UBaseType_t uxReturn;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
-       configASSERT( xQueue );\r
-\r
-       uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting;\r
+       configASSERT( pxQueue );\r
+       uxReturn = pxQueue->uxMessagesWaiting;\r
 \r
        return uxReturn;\r
 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\r
@@ -1970,7 +1970,7 @@ UBaseType_t uxReturn;
 \r
 void vQueueDelete( QueueHandle_t xQueue )\r
 {\r
-Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
        configASSERT( pxQueue );\r
        traceQUEUE_DELETE( pxQueue );\r
@@ -2052,9 +2052,9 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                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
+               if( listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) ) > 0U )\r
                {\r
-                       uxHighestPriorityOfWaitingTasks = configMAX_PRIORITIES - listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) );\r
+                       uxHighestPriorityOfWaitingTasks = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) );\r
                }\r
                else\r
                {\r
@@ -2083,8 +2083,8 @@ UBaseType_t uxMessagesWaiting;
                        if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
                        {\r
                                /* The mutex is no longer being held. */\r
-                               xReturn = xTaskPriorityDisinherit( ( void * ) pxQueue->pxMutexHolder );\r
-                               pxQueue->pxMutexHolder = NULL;\r
+                               xReturn = xTaskPriorityDisinherit( pxQueue->u.xSemaphore.xMutexHolder );\r
+                               pxQueue->u.xSemaphore.xMutexHolder = NULL;\r
                        }\r
                        else\r
                        {\r
@@ -2095,9 +2095,9 @@ UBaseType_t uxMessagesWaiting;
        }\r
        else if( xPosition == queueSEND_TO_BACK )\r
        {\r
-               ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. */\r
-               pxQueue->pcWriteTo += pxQueue->uxItemSize;\r
-               if( pxQueue->pcWriteTo >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\r
+               ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0.  Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */\r
+               pxQueue->pcWriteTo += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */\r
+               if( pxQueue->pcWriteTo >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\r
                {\r
                        pxQueue->pcWriteTo = pxQueue->pcHead;\r
                }\r
@@ -2108,11 +2108,11 @@ UBaseType_t uxMessagesWaiting;
        }\r
        else\r
        {\r
-               ( void ) memcpy( ( void * ) pxQueue->u.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
-               pxQueue->u.pcReadFrom -= pxQueue->uxItemSize;\r
-               if( pxQueue->u.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\r
+               ( void ) memcpy( ( void * ) pxQueue->u.xQueue.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e9087 !e418 MISRA exception as the casts are only redundant for some ports.  Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes.  Assert checks null pointer only used when length is 0. */\r
+               pxQueue->u.xQueue.pcReadFrom -= pxQueue->uxItemSize;\r
+               if( pxQueue->u.xQueue.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\r
                {\r
-                       pxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
+                       pxQueue->u.xQueue.pcReadFrom = ( pxQueue->u.xQueue.pcTail - pxQueue->uxItemSize );\r
                }\r
                else\r
                {\r
@@ -2150,16 +2150,16 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer
 {\r
        if( pxQueue->uxItemSize != ( UBaseType_t ) 0 )\r
        {\r
-               pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
-               if( pxQueue->u.pcReadFrom >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */\r
+               pxQueue->u.xQueue.pcReadFrom += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */\r
+               if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */\r
                {\r
-                       pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
+                       pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead;\r
                }\r
                else\r
                {\r
                        mtCOVERAGE_TEST_MARKER();\r
                }\r
-               ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports.  Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. */\r
+               ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports.  Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0.  Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -2308,9 +2308,10 @@ BaseType_t xReturn;
 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )\r
 {\r
 BaseType_t xReturn;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
-       configASSERT( xQueue );\r
-       if( ( ( Queue_t * ) xQueue )->uxMessagesWaiting == ( UBaseType_t ) 0 )\r
+       configASSERT( pxQueue );\r
+       if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 )\r
        {\r
                xReturn = pdTRUE;\r
        }\r
@@ -2347,9 +2348,10 @@ BaseType_t xReturn;
 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )\r
 {\r
 BaseType_t xReturn;\r
+Queue_t * const pxQueue = xQueue;\r
 \r
-       configASSERT( xQueue );\r
-       if( ( ( Queue_t * ) xQueue )->uxMessagesWaiting == ( ( Queue_t * ) xQueue )->uxLength )\r
+       configASSERT( pxQueue );\r
+       if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )\r
        {\r
                xReturn = pdTRUE;\r
        }\r
@@ -2367,7 +2369,7 @@ BaseType_t xReturn;
        BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait )\r
        {\r
        BaseType_t xReturn;\r
-       Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+       Queue_t * const pxQueue = xQueue;\r
 \r
                /* If the queue is already full we may have to block.  A critical section\r
                is required to prevent an interrupt removing something from the queue\r
@@ -2444,7 +2446,7 @@ BaseType_t xReturn;
        BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait )\r
        {\r
        BaseType_t xReturn;\r
-       Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+       Queue_t * const pxQueue = xQueue;\r
 \r
                /* If the queue is already empty we may have to block.  A critical section\r
                is required to prevent an interrupt adding something to the queue\r
@@ -2481,17 +2483,17 @@ BaseType_t xReturn;
                        if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )\r
                        {\r
                                /* Data is available from the queue. */\r
-                               pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
-                               if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
+                               pxQueue->u.xQueue.pcReadFrom += pxQueue->uxItemSize;\r
+                               if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail )\r
                                {\r
-                                       pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
+                                       pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead;\r
                                }\r
                                else\r
                                {\r
                                        mtCOVERAGE_TEST_MARKER();\r
                                }\r
                                --( pxQueue->uxMessagesWaiting );\r
-                               ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+                               ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
 \r
                                xReturn = pdPASS;\r
 \r
@@ -2533,7 +2535,7 @@ BaseType_t xReturn;
 \r
        BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken )\r
        {\r
-       Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+       Queue_t * const pxQueue = xQueue;\r
 \r
                /* Cannot block within an ISR so if there is no space on the queue then\r
                exit without doing anything. */\r
@@ -2582,24 +2584,24 @@ BaseType_t xReturn;
        BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxCoRoutineWoken )\r
        {\r
        BaseType_t xReturn;\r
-       Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+       Queue_t * const pxQueue = xQueue;\r
 \r
                /* We cannot block from an ISR, so check there is data available. If\r
                not then just leave without doing anything. */\r
                if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )\r
                {\r
                        /* Copy the data from the queue. */\r
-                       pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
-                       if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
+                       pxQueue->u.xQueue.pcReadFrom += pxQueue->uxItemSize;\r
+                       if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail )\r
                        {\r
-                               pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
+                               pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead;\r
                        }\r
                        else\r
                        {\r
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                        --( pxQueue->uxMessagesWaiting );\r
-                       ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+                       ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
 \r
                        if( ( *pxCoRoutineWoken ) == pdFALSE )\r
                        {\r
@@ -2730,7 +2732,7 @@ BaseType_t xReturn;
 \r
        void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely )\r
        {\r
-       Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+       Queue_t * const pxQueue = xQueue;\r
 \r
                /* This function should not be called by application code hence the\r
                'Restricted' in its name.  It is not part of the public API.  It is\r