]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/queue.c
Update version numbers ready for release.
[freertos] / FreeRTOS / Source / queue.c
index 6706629e9cbc31950b491b122ebdafd225db5376..bd0648b722b9c5f1d2fff9dfd0a728a29dd1ad08 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * FreeRTOS Kernel V10.0.1\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\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
@@ -41,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
@@ -56,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
@@ -83,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
@@ -246,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
@@ -321,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
@@ -345,6 +354,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                else\r
                {\r
                        traceQUEUE_CREATE_FAILED( ucQueueType );\r
+                       mtCOVERAGE_TEST_MARKER();\r
                }\r
 \r
                return pxNewQueue;\r
@@ -375,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
@@ -397,6 +417,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                else\r
                {\r
                        traceQUEUE_CREATE_FAILED( ucQueueType );\r
+                       mtCOVERAGE_TEST_MARKER();\r
                }\r
 \r
                return pxNewQueue;\r
@@ -457,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
@@ -481,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
@@ -497,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
@@ -515,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
@@ -526,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
@@ -545,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
@@ -556,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
@@ -578,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
@@ -638,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
@@ -652,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
@@ -726,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
@@ -738,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
@@ -752,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
@@ -805,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
@@ -916,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
@@ -924,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
@@ -1075,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
@@ -1092,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
@@ -1240,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
@@ -1257,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
@@ -1374,7 +1407,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
-       }\r
+       } /*lint -restore */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1382,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
@@ -1403,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
@@ -1431,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
@@ -1519,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
@@ -1578,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
@@ -1593,7 +1625,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
-       }\r
+       } /*lint -restore */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1602,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
@@ -1619,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
@@ -1636,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
@@ -1743,7 +1774,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
-       }\r
+       } /*lint -restore */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1751,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
@@ -1843,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
@@ -1874,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
@@ -1911,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
@@ -1929,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
@@ -1940,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
@@ -2022,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
@@ -2053,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
@@ -2065,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
@@ -2078,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
@@ -2120,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
@@ -2278,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
@@ -2317,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
@@ -2337,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
@@ -2414,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
@@ -2451,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
@@ -2503,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
@@ -2552,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
@@ -2700,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