]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
Update trace recorder code to the latest.
[freertos] / FreeRTOS / Source / tasks.c
index 1cdb016db6c83724e02104ab354666592624afaf..d8b75bee528983bd65d3ad7c2b4036ad8d91f3e0 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.0\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
 /* Standard includes. */\r
 #include <stdlib.h>\r
@@ -80,13 +38,13 @@ task.h is included from an application file. */
 #include "FreeRTOS.h"\r
 #include "task.h"\r
 #include "timers.h"\r
-#include "StackMacros.h"\r
+#include "stack_macros.h"\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
 /* Set configUSE_STATS_FORMATTING_FUNCTIONS to 2 to include the stats formatting\r
 functions but without including stdio.h here. */\r
@@ -134,7 +92,7 @@ that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with
 a statically allocated stack and a dynamically allocated TCB.\r
 !!!NOTE!!! If the definition of tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is\r
 changed then the definition of StaticTask_t must also be updated. */\r
-#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE   ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
+#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE      ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
 #define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB                 ( ( uint8_t ) 0 )\r
 #define tskSTATICALLY_ALLOCATED_STACK_ONLY                     ( ( uint8_t ) 1 )\r
 #define tskSTATICALLY_ALLOCATED_STACK_AND_TCB          ( ( uint8_t ) 2 )\r
@@ -151,6 +109,7 @@ set then don't fill the stack so there is no unnecessary dependency on memset. *
 /*\r
  * Macros used by vListTask to indicate which state a task is in.\r
  */\r
+#define tskRUNNING_CHAR                ( 'X' )\r
 #define tskBLOCKED_CHAR                ( 'B' )\r
 #define tskREADY_CHAR          ( 'R' )\r
 #define tskDELETED_CHAR                ( 'D' )\r
@@ -164,6 +123,12 @@ set then don't fill the stack so there is no unnecessary dependency on memset. *
        #define static\r
 #endif\r
 \r
+/* The name allocated to the Idle task.  This can be overridden by defining\r
+configIDLE_TASK_NAME in FreeRTOSConfig.h. */\r
+#ifndef configIDLE_TASK_NAME\r
+       #define configIDLE_TASK_NAME "IDLE"\r
+#endif\r
+\r
 #if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )\r
 \r
        /* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is\r
@@ -280,7 +245,7 @@ count overflows. */
  * task should be used in place of the parameter.  This macro simply checks to\r
  * see if the parameter is NULL and returns a pointer to the appropriate TCB.\r
  */\r
-#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( TCB_t * ) pxCurrentTCB : ( TCB_t * ) ( pxHandle ) )\r
+#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? pxCurrentTCB : ( pxHandle ) )\r
 \r
 /* The item value of the event list item is normally used to hold the priority\r
 of the task to which it belongs (coded to allow it to be held in reverse\r
@@ -363,7 +328,7 @@ typedef struct tskTaskControlBlock
 \r
        /* See the comments above the definition of\r
        tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */\r
-       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\r
+       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */\r
                uint8_t ucStaticallyAllocated;          /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */\r
        #endif\r
 \r
@@ -371,6 +336,10 @@ typedef struct tskTaskControlBlock
                uint8_t ucDelayAborted;\r
        #endif\r
 \r
+       #if( configUSE_POSIX_ERRNO == 1 )\r
+               int iTaskErrno;\r
+       #endif\r
+\r
 } tskTCB;\r
 \r
 /* The old tskTCB name is maintained above then typedefed to the new TCB_t name\r
@@ -379,7 +348,6 @@ typedef tskTCB TCB_t;
 \r
 /*lint -save -e956 A manual analysis and inspection has been used to determine\r
 which static variables must be declared volatile. */\r
-\r
 PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;\r
 \r
 /* Lists for ready and blocked tasks. --------------------*/\r
@@ -403,9 +371,15 @@ PRIVILEGED_DATA static List_t xPendingReadyList;                                           /*< Tasks that have been r
 \r
 #endif\r
 \r
+/* Global POSIX errno. Its value is changed upon context switching to match\r
+the errno of the currently running task. */\r
+#if ( configUSE_POSIX_ERRNO == 1 )\r
+       int FreeRTOS_errno = 0;\r
+#endif\r
+\r
 /* Other file private variables. --------------------------------*/\r
 PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks     = ( UBaseType_t ) 0U;\r
-PRIVILEGED_DATA static volatile TickType_t xTickCount                          = ( TickType_t ) 0U;\r
+PRIVILEGED_DATA static volatile TickType_t xTickCount                          = ( TickType_t ) configINITIAL_TICK_COUNT;\r
 PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority                 = tskIDLE_PRIORITY;\r
 PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning           = pdFALSE;\r
 PRIVILEGED_DATA static volatile UBaseType_t uxPendedTicks                      = ( UBaseType_t ) 0U;\r
@@ -445,13 +419,13 @@ PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended  = ( UBaseType_t
 \r
 #if( configUSE_TICK_HOOK > 0 )\r
 \r
-       extern void vApplicationTickHook( void );\r
+       extern void vApplicationTickHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */\r
 \r
 #endif\r
 \r
 #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
 \r
-       extern void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );\r
+       extern void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */\r
 \r
 #endif\r
 \r
@@ -544,7 +518,7 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, const BaseT
  */\r
 #if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
 \r
-       static uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte ) PRIVILEGED_FUNCTION;\r
+       static configSTACK_DEPTH_TYPE prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte ) PRIVILEGED_FUNCTION;\r
 \r
 #endif\r
 \r
@@ -634,6 +608,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                        structure. */\r
                        volatile size_t xSize = sizeof( StaticTask_t );\r
                        configASSERT( xSize == sizeof( TCB_t ) );\r
+                       ( void ) xSize; /* Prevent lint warning when configASSERT() is not used. */\r
                }\r
                #endif /* configASSERT_DEFINED */\r
 \r
@@ -642,10 +617,10 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                {\r
                        /* The memory used for the task's TCB and stack are passed into this\r
                        function - use them. */\r
-                       pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*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
+                       pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*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
                        pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;\r
 \r
-                       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\r
+                       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */\r
                        {\r
                                /* Tasks can be created statically or dynamically, so note this\r
                                task was created statically in case the task is later deleted. */\r
@@ -694,7 +669,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
                        #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
-                       \r
+\r
                        prvInitialiseNewTask(   pxTaskDefinition->pvTaskCode,\r
                                                                        pxTaskDefinition->pcName,\r
                                                                        ( uint32_t ) pxTaskDefinition->usStackDepth,\r
@@ -734,10 +709,14 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                /* Store the stack location in the TCB. */\r
                                pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;\r
 \r
-                               /* Tasks can be created statically or dynamically, so note\r
-                               this task had a statically allocated stack in case it is\r
-                               later deleted.  The TCB was allocated dynamically. */\r
-                               pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_ONLY;\r
+                               #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+                               {\r
+                                       /* Tasks can be created statically or dynamically, so note\r
+                                       this task had a statically allocated stack in case it is\r
+                                       later deleted.  The TCB was allocated dynamically. */\r
+                                       pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_ONLY;\r
+                               }\r
+                               #endif\r
 \r
                                prvInitialiseNewTask(   pxTaskDefinition->pvTaskCode,\r
                                                                                pxTaskDefinition->pcName,\r
@@ -762,7 +741,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
 \r
        BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,\r
                                                        const char * const pcName,              /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
-                                                       const uint16_t usStackDepth,\r
+                                                       const configSTACK_DEPTH_TYPE usStackDepth,\r
                                                        void * const pvParameters,\r
                                                        UBaseType_t uxPriority,\r
                                                        TaskHandle_t * const pxCreatedTask )\r
@@ -800,12 +779,12 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                StackType_t *pxStack;\r
 \r
                        /* Allocate space for the stack used by the task being created. */\r
-                       pxStack = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+                       pxStack = pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation is the stack. */\r
 \r
                        if( pxStack != NULL )\r
                        {\r
                                /* Allocate space for the TCB. */\r
-                               pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); /*lint !e961 MISRA exception as the casts are only redundant for some paths. */\r
+                               pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of TCB_t is always a pointer to the task's stack. */\r
 \r
                                if( pxNewTCB != NULL )\r
                                {\r
@@ -828,7 +807,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
 \r
                if( pxNewTCB != NULL )\r
                {\r
-                       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\r
+                       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e9029 !e731 Macro has been consolidated for readability reasons. */\r
                        {\r
                                /* Tasks can be created statically or dynamically, so note this\r
                                task was created dynamically in case it is later deleted. */\r
@@ -877,6 +856,8 @@ UBaseType_t x;
                uxPriority &= ~portPRIVILEGE_BIT;\r
        #endif /* portUSING_MPU_WRAPPERS == 1 */\r
 \r
+       configASSERT( pcName );\r
+\r
        /* Avoid dependency on memset() if it is not required. */\r
        #if( tskSET_NEW_STACKS_TO_KNOWN_VALUE == 1 )\r
        {\r
@@ -891,8 +872,8 @@ UBaseType_t x;
        by the port. */\r
        #if( portSTACK_GROWTH < 0 )\r
        {\r
-               pxTopOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 );\r
-               pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); /*lint !e923 MISRA exception.  Avoiding casts between pointers and integers is not practical.  Size differences accounted for using portPOINTER_SIZE_TYPE type. */\r
+               pxTopOfStack = &( pxNewTCB->pxStack[ ulStackDepth - ( uint32_t ) 1 ] );\r
+               pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); /*lint !e923 !e9033 !e9078 MISRA exception.  Avoiding casts between pointers and integers is not practical.  Size differences accounted for using portPOINTER_SIZE_TYPE type.  Checked by assert(). */\r
 \r
                /* Check the alignment of the calculated top of stack is correct. */\r
                configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
@@ -926,7 +907,7 @@ UBaseType_t x;
                /* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than\r
                configMAX_TASK_NAME_LEN characters just in case the memory after the\r
                string is not accessible (extremely unlikely). */\r
-               if( pcName[ x ] == 0x00 )\r
+               if( pcName[ x ] == ( char ) 0x00 )\r
                {\r
                        break;\r
                }\r
@@ -1042,7 +1023,7 @@ UBaseType_t x;
        }\r
        #endif /* portUSING_MPU_WRAPPERS */\r
 \r
-       if( ( void * ) pxCreatedTask != NULL )\r
+       if( pxCreatedTask != NULL )\r
        {\r
                /* Pass the handle out in an anonymous way.  The handle can be used to\r
                change the created task's priority, delete the created task, etc.*/\r
@@ -1364,8 +1345,8 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
        eTaskState eTaskGetState( TaskHandle_t xTask )\r
        {\r
        eTaskState eReturn;\r
-       List_t *pxStateList;\r
-       const TCB_t * const pxTCB = ( TCB_t * ) xTask;\r
+       List_t const * pxStateList, *pxDelayedList, *pxOverflowedDelayedList;\r
+       const TCB_t * const pxTCB = xTask;\r
 \r
                configASSERT( pxTCB );\r
 \r
@@ -1378,11 +1359,13 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                {\r
                        taskENTER_CRITICAL();\r
                        {\r
-                               pxStateList = ( List_t * ) listLIST_ITEM_CONTAINER( &( pxTCB->xStateListItem ) );\r
+                               pxStateList = listLIST_ITEM_CONTAINER( &( pxTCB->xStateListItem ) );\r
+                               pxDelayedList = pxDelayedTaskList;\r
+                               pxOverflowedDelayedList = pxOverflowDelayedTaskList;\r
                        }\r
                        taskEXIT_CRITICAL();\r
 \r
-                       if( ( pxStateList == pxDelayedTaskList ) || ( pxStateList == pxOverflowDelayedTaskList ) )\r
+                       if( ( pxStateList == pxDelayedList ) || ( pxStateList == pxOverflowedDelayedList ) )\r
                        {\r
                                /* The task being queried is referenced from one of the Blocked\r
                                lists. */\r
@@ -1393,11 +1376,30 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                                else if( pxStateList == &xSuspendedTaskList )\r
                                {\r
                                        /* The task being queried is referenced from the suspended\r
-                                       list.  Is it genuinely suspended or is it block\r
+                                       list.  Is it genuinely suspended or is it blocked\r
                                        indefinitely? */\r
                                        if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL )\r
                                        {\r
-                                               eReturn = eSuspended;\r
+                                               #if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+                                               {\r
+                                                       /* The task does not appear on the event list item of\r
+                                                       and of the RTOS objects, but could still be in the\r
+                                                       blocked state if it is waiting on its notification\r
+                                                       rather than waiting on an object. */\r
+                                                       if( pxTCB->ucNotifyState == taskWAITING_NOTIFICATION )\r
+                                                       {\r
+                                                               eReturn = eBlocked;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               eReturn = eSuspended;\r
+                                                       }\r
+                                               }\r
+                                               #else\r
+                                               {\r
+                                                       eReturn = eSuspended;\r
+                                               }\r
+                                               #endif\r
                                        }\r
                                        else\r
                                        {\r
@@ -1432,15 +1434,15 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
 \r
 #if ( INCLUDE_uxTaskPriorityGet == 1 )\r
 \r
-       UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask )\r
+       UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask )\r
        {\r
-       TCB_t *pxTCB;\r
+       TCB_t const *pxTCB;\r
        UBaseType_t uxReturn;\r
 \r
                taskENTER_CRITICAL();\r
                {\r
-                       /* If null is passed in here then it is the priority of the that\r
-                       called uxTaskPriorityGet() that is being queried. */\r
+                       /* If null is passed in here then it is the priority of the task\r
+                       that called uxTaskPriorityGet() that is being queried. */\r
                        pxTCB = prvGetTCBFromHandle( xTask );\r
                        uxReturn = pxTCB->uxPriority;\r
                }\r
@@ -1454,9 +1456,9 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
 \r
 #if ( INCLUDE_uxTaskPriorityGet == 1 )\r
 \r
-       UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask )\r
+       UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask )\r
        {\r
-       TCB_t *pxTCB;\r
+       TCB_t const *pxTCB;\r
        UBaseType_t uxReturn, uxSavedInterruptState;\r
 \r
                /* RTOS ports that support interrupt nesting have the concept of a\r
@@ -1474,7 +1476,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                separate interrupt safe API to ensure interrupt entry is as fast and as\r
                simple as possible.  More information (albeit Cortex-M specific) is\r
                provided on the following link:\r
-               http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+               https://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
                portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
                uxSavedInterruptState = portSET_INTERRUPT_MASK_FROM_ISR();\r
@@ -1610,14 +1612,14 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                                }\r
 \r
                                /* If the task is in the blocked or suspended list we need do\r
-                               nothing more than change it's priority variable. However, if\r
+                               nothing more than change its priority variable. However, if\r
                                the task is in a ready list it needs to be removed and placed\r
                                in the list appropriate to its new priority. */\r
                                if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE )\r
                                {\r
-                                       /* The task is currently in its ready list - remove before adding\r
-                                       it to it's new ready list.  As we are in a critical section we\r
-                                       can do this even if the scheduler is suspended. */\r
+                                       /* The task is currently in its ready list - remove before\r
+                                       adding it to it's new ready list.  As we are in a critical\r
+                                       section we can do this even if the scheduler is suspended. */\r
                                        if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
                                        {\r
                                                /* It is known that the task is in its ready list so\r
@@ -1692,6 +1694,17 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                        }\r
 \r
                        vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) );\r
+\r
+                       #if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+                       {\r
+                               if( pxTCB->ucNotifyState == taskWAITING_NOTIFICATION )\r
+                               {\r
+                                       /* The task was blocked to wait for a notification, but is\r
+                                       now suspended, so no notification was received. */\r
+                                       pxTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\r
+                               }\r
+                       }\r
+                       #endif\r
                }\r
                taskEXIT_CRITICAL();\r
 \r
@@ -1723,7 +1736,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                                /* The scheduler is not running, but the task that was pointed\r
                                to by pxCurrentTCB has just been suspended and pxCurrentTCB\r
                                must be adjusted to point to a different task. */\r
-                               if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks )\r
+                               if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks ) /*lint !e931 Right has no side effect, just volatile. */\r
                                {\r
                                        /* No other tasks are ready, so set pxCurrentTCB back to\r
                                        NULL so when the next task is created pxCurrentTCB will\r
@@ -1751,7 +1764,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
        static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask )\r
        {\r
        BaseType_t xReturn = pdFALSE;\r
-       const TCB_t * const pxTCB = ( TCB_t * ) xTask;\r
+       const TCB_t * const pxTCB = xTask;\r
 \r
                /* Accesses xPendingReadyList so must be called from a critical\r
                section. */\r
@@ -1796,14 +1809,14 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
 \r
        void vTaskResume( TaskHandle_t xTaskToResume )\r
        {\r
-       TCB_t * const pxTCB = ( TCB_t * ) xTaskToResume;\r
+       TCB_t * const pxTCB = xTaskToResume;\r
 \r
                /* It does not make sense to resume the calling task. */\r
                configASSERT( xTaskToResume );\r
 \r
                /* The parameter cannot be NULL as it is impossible to resume the\r
                currently executing task. */\r
-               if( ( pxTCB != NULL ) && ( pxTCB != pxCurrentTCB ) )\r
+               if( ( pxTCB != pxCurrentTCB ) && ( pxTCB != NULL ) )\r
                {\r
                        taskENTER_CRITICAL();\r
                        {\r
@@ -1811,12 +1824,12 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                                {\r
                                        traceTASK_RESUME( pxTCB );\r
 \r
-                                       /* As we are in a critical section we can access the ready\r
-                                       lists even if the scheduler is suspended. */\r
+                                       /* The ready list can be accessed even if the scheduler is\r
+                                       suspended because this is inside a critical section. */\r
                                        ( void ) uxListRemove(  &( pxTCB->xStateListItem ) );\r
                                        prvAddTaskToReadyList( pxTCB );\r
 \r
-                                       /* We may have just resumed a higher priority task. */\r
+                                       /* A higher priority task may have just been resumed. */\r
                                        if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
                                        {\r
                                                /* This yield may not cause the task just resumed to run,\r
@@ -1851,7 +1864,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
        BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume )\r
        {\r
        BaseType_t xYieldRequired = pdFALSE;\r
-       TCB_t * const pxTCB = ( TCB_t * ) xTaskToResume;\r
+       TCB_t * const pxTCB = xTaskToResume;\r
        UBaseType_t uxSavedInterruptStatus;\r
 \r
                configASSERT( xTaskToResume );\r
@@ -1871,7 +1884,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                separate interrupt safe API to ensure interrupt entry is as fast and as\r
                simple as possible.  More information (albeit Cortex-M specific) is\r
                provided on the following link:\r
-               http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+               https://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
                portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
                uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
@@ -1933,10 +1946,10 @@ BaseType_t xReturn;
                address of the RAM then create the idle task. */\r
                vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize );\r
                xIdleTaskHandle = xTaskCreateStatic(    prvIdleTask,\r
-                                                                                               "IDLE",\r
+                                                                                               configIDLE_TASK_NAME,\r
                                                                                                ulIdleTaskStackSize,\r
                                                                                                ( void * ) NULL, /*lint !e961.  The cast is not redundant for all compilers. */\r
-                                                                                               ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),\r
+                                                                                               portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */\r
                                                                                                pxIdleTaskStackBuffer,\r
                                                                                                pxIdleTaskTCBBuffer ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
 \r
@@ -1953,9 +1966,10 @@ BaseType_t xReturn;
        {\r
                /* The Idle task is being created using dynamically allocated RAM. */\r
                xReturn = xTaskCreate(  prvIdleTask,\r
-                                                               "IDLE", configMINIMAL_STACK_SIZE,\r
+                                                               configIDLE_TASK_NAME,\r
+                                                               configMINIMAL_STACK_SIZE,\r
                                                                ( void * ) NULL,\r
-                                                               ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),\r
+                                                               portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */\r
                                                                &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
        }\r
        #endif /* configSUPPORT_STATIC_ALLOCATION */\r
@@ -2001,7 +2015,7 @@ BaseType_t xReturn;
 \r
                xNextTaskUnblockTime = portMAX_DELAY;\r
                xSchedulerRunning = pdTRUE;\r
-               xTickCount = ( TickType_t ) 0U;\r
+               xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;\r
 \r
                /* If configGENERATE_RUN_TIME_STATS is defined then the following\r
                macro must be defined to configure the timer/counter used to generate\r
@@ -2011,6 +2025,8 @@ BaseType_t xReturn;
                FreeRTOSConfig.h file. */\r
                portCONFIGURE_TIMER_FOR_RUN_TIME_STATS();\r
 \r
+               traceTASK_SWITCHED_IN();\r
+\r
                /* Setting up the timer tick is hardware specific and thus in the\r
                portable interface. */\r
                if( xPortStartScheduler() != pdFALSE )\r
@@ -2147,7 +2163,7 @@ BaseType_t xAlreadyYielded = pdFALSE;
                                appropriate ready list. */\r
                                while( listLIST_IS_EMPTY( &xPendingReadyList ) == pdFALSE )\r
                                {\r
-                                       pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) );\r
+                                       pxTCB = listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
                                        ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
                                        ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
                                        prvAddTaskToReadyList( pxTCB );\r
@@ -2264,7 +2280,7 @@ UBaseType_t uxSavedInterruptStatus;
        system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
        safe API to ensure interrupt entry is as fast and as simple as possible.\r
        More information (albeit Cortex-M specific) is provided on the following\r
-       link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+       link: https://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
        portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
        uxSavedInterruptStatus = portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR();\r
@@ -2304,19 +2320,21 @@ TCB_t *pxTCB;
        TCB_t *pxNextTCB, *pxFirstTCB, *pxReturn = NULL;\r
        UBaseType_t x;\r
        char cNextChar;\r
+       BaseType_t xBreakLoop;\r
 \r
                /* This function is called with the scheduler suspended. */\r
 \r
                if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )\r
                {\r
-                       listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
+                       listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );  /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
 \r
                        do\r
                        {\r
-                               listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\r
+                               listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
 \r
                                /* Check each character in the name looking for a match or\r
                                mismatch. */\r
+                               xBreakLoop = pdFALSE;\r
                                for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )\r
                                {\r
                                        cNextChar = pxNextTCB->pcTaskName[ x ];\r
@@ -2324,19 +2342,24 @@ TCB_t *pxTCB;
                                        if( cNextChar != pcNameToQuery[ x ] )\r
                                        {\r
                                                /* Characters didn't match. */\r
-                                               break;\r
+                                               xBreakLoop = pdTRUE;\r
                                        }\r
-                                       else if( cNextChar == 0x00 )\r
+                                       else if( cNextChar == ( char ) 0x00 )\r
                                        {\r
                                                /* Both strings terminated, a match must have been\r
                                                found. */\r
                                                pxReturn = pxNextTCB;\r
-                                               break;\r
+                                               xBreakLoop = pdTRUE;\r
                                        }\r
                                        else\r
                                        {\r
                                                mtCOVERAGE_TEST_MARKER();\r
                                        }\r
+\r
+                                       if( xBreakLoop != pdFALSE )\r
+                                       {\r
+                                               break;\r
+                                       }\r
                                }\r
 \r
                                if( pxReturn != NULL )\r
@@ -2417,7 +2440,7 @@ TCB_t *pxTCB;
                }\r
                ( void ) xTaskResumeAll();\r
 \r
-               return ( TaskHandle_t ) pxTCB;\r
+               return pxTCB;\r
        }\r
 \r
 #endif /* INCLUDE_xTaskGetHandle */\r
@@ -2533,8 +2556,8 @@ implementations require configUSE_TICKLESS_IDLE to be set to a value other than
 \r
        BaseType_t xTaskAbortDelay( TaskHandle_t xTask )\r
        {\r
-       TCB_t *pxTCB = ( TCB_t * ) xTask;\r
-       BaseType_t xReturn = pdFALSE;\r
+       TCB_t *pxTCB = xTask;\r
+       BaseType_t xReturn;\r
 \r
                configASSERT( pxTCB );\r
 \r
@@ -2544,6 +2567,8 @@ implementations require configUSE_TICKLESS_IDLE to be set to a value other than
                        it is actually in the Blocked state. */\r
                        if( eTaskGetState( xTask ) == eBlocked )\r
                        {\r
+                               xReturn = pdPASS;\r
+\r
                                /* Remove the reference to the task from the blocked list.  An\r
                                interrupt won't touch the xStateListItem because the\r
                                scheduler is suspended. */\r
@@ -2592,7 +2617,7 @@ implementations require configUSE_TICKLESS_IDLE to be set to a value other than
                        }\r
                        else\r
                        {\r
-                               mtCOVERAGE_TEST_MARKER();\r
+                               xReturn = pdFAIL;\r
                        }\r
                }\r
                ( void ) xTaskResumeAll();\r
@@ -2656,7 +2681,7 @@ BaseType_t xSwitchRequired = pdFALSE;
                                        item at the head of the delayed list.  This is the time\r
                                        at which the task at the head of the delayed list must\r
                                        be removed from the Blocked state. */\r
-                                       pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
+                                       pxTCB = listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
                                        xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ) );\r
 \r
                                        if( xConstTickCount < xItemValue )\r
@@ -2667,7 +2692,7 @@ BaseType_t xSwitchRequired = pdFALSE;
                                                state - so record the item value in\r
                                                xNextTaskUnblockTime. */\r
                                                xNextTaskUnblockTime = xItemValue;\r
-                                               break;\r
+                                               break; /*lint !e9011 Code structure here is deedmed easier to understand with multiple breaks. */\r
                                        }\r
                                        else\r
                                        {\r
@@ -2789,13 +2814,15 @@ BaseType_t xSwitchRequired = pdFALSE;
                }\r
                else\r
                {\r
-                       xTCB = ( TCB_t * ) xTask;\r
+                       xTCB = xTask;\r
                }\r
 \r
                /* Save the hook function in the TCB.  A critical section is required as\r
                the value can be accessed from an interrupt. */\r
                taskENTER_CRITICAL();\r
+               {\r
                        xTCB->pxTaskTag = pxHookFunction;\r
+               }\r
                taskEXIT_CRITICAL();\r
        }\r
 \r
@@ -2816,7 +2843,7 @@ BaseType_t xSwitchRequired = pdFALSE;
                }\r
                else\r
                {\r
-                       xTCB = ( TCB_t * ) xTask;\r
+                       xTCB = xTask;\r
                }\r
 \r
                /* Save the hook function in the TCB.  A critical section is required as\r
@@ -2843,11 +2870,11 @@ BaseType_t xSwitchRequired = pdFALSE;
                /* If xTask is NULL then we are calling our own task hook. */\r
                if( xTask == NULL )\r
                {\r
-                       xTCB = ( TCB_t * ) pxCurrentTCB;\r
+                       xTCB = pxCurrentTCB;\r
                }\r
                else\r
                {\r
-                       xTCB = ( TCB_t * ) xTask;\r
+                       xTCB = xTask;\r
                }\r
 \r
                if( xTCB->pxTaskTag != NULL )\r
@@ -2908,11 +2935,25 @@ void vTaskSwitchContext( void )
                /* Check for stack overflow, if configured. */\r
                taskCHECK_FOR_STACK_OVERFLOW();\r
 \r
+               /* Before the currently running task is switched out, save its errno. */\r
+               #if( configUSE_POSIX_ERRNO == 1 )\r
+               {\r
+                       pxCurrentTCB->iTaskErrno = FreeRTOS_errno;\r
+               }\r
+               #endif\r
+\r
                /* Select a new task to run using either the generic C or port\r
                optimised asm code. */\r
-               taskSELECT_HIGHEST_PRIORITY_TASK();\r
+               taskSELECT_HIGHEST_PRIORITY_TASK(); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
                traceTASK_SWITCHED_IN();\r
 \r
+               /* After the new task is switched in, update the global errno. */\r
+               #if( configUSE_POSIX_ERRNO == 1 )\r
+               {\r
+                       FreeRTOS_errno = pxCurrentTCB->iTaskErrno;\r
+               }\r
+               #endif\r
+\r
                #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
                {\r
                        /* Switch Newlib's _impure_ptr variable to point to the _reent\r
@@ -3016,7 +3057,7 @@ BaseType_t xReturn;
 \r
        This function assumes that a check has already been made to ensure that\r
        pxEventList is not empty. */\r
-       pxUnblockedTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
+       pxUnblockedTCB = listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
        configASSERT( pxUnblockedTCB );\r
        ( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
 \r
@@ -3079,7 +3120,7 @@ TCB_t *pxUnblockedTCB;
 \r
        /* Remove the event list form the event flag.  Interrupts do not access\r
        event flags. */\r
-       pxUnblockedTCB = ( TCB_t * ) listGET_LIST_ITEM_OWNER( pxEventListItem );\r
+       pxUnblockedTCB = listGET_LIST_ITEM_OWNER( pxEventListItem ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
        configASSERT( pxUnblockedTCB );\r
        ( void ) uxListRemove( pxEventListItem );\r
 \r
@@ -3103,6 +3144,18 @@ TCB_t *pxUnblockedTCB;
 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut )\r
 {\r
        configASSERT( pxTimeOut );\r
+       taskENTER_CRITICAL();\r
+       {\r
+               pxTimeOut->xOverflowCount = xNumOfOverflows;\r
+               pxTimeOut->xTimeOnEntering = xTickCount;\r
+       }\r
+       taskEXIT_CRITICAL();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut )\r
+{\r
+       /* For internal use only as it does not use a critical section. */\r
        pxTimeOut->xOverflowCount = xNumOfOverflows;\r
        pxTimeOut->xTimeOnEntering = xTickCount;\r
 }\r
@@ -3119,9 +3172,10 @@ BaseType_t xReturn;
        {\r
                /* Minor optimisation.  The tick count cannot change in this block. */\r
                const TickType_t xConstTickCount = xTickCount;\r
+               const TickType_t xElapsedTime = xConstTickCount - pxTimeOut->xTimeOnEntering;\r
 \r
                #if( INCLUDE_xTaskAbortDelay == 1 )\r
-                       if( pxCurrentTCB->ucDelayAborted != pdFALSE )\r
+                       if( pxCurrentTCB->ucDelayAborted != ( uint8_t ) pdFALSE )\r
                        {\r
                                /* The delay was aborted, which is not the same as a time out,\r
                                but has the same result. */\r
@@ -3151,15 +3205,16 @@ BaseType_t xReturn;
                        was called. */\r
                        xReturn = pdTRUE;\r
                }\r
-               else if( ( ( TickType_t ) ( xConstTickCount - pxTimeOut->xTimeOnEntering ) ) < *pxTicksToWait ) /*lint !e961 Explicit casting is only redundant with some compilers, whereas others require it to prevent integer conversion errors. */\r
+               else if( xElapsedTime < *pxTicksToWait ) /*lint !e961 Explicit casting is only redundant with some compilers, whereas others require it to prevent integer conversion errors. */\r
                {\r
                        /* Not a genuine timeout. Adjust parameters for time remaining. */\r
-                       *pxTicksToWait -= ( xConstTickCount - pxTimeOut->xTimeOnEntering );\r
-                       vTaskSetTimeOutState( pxTimeOut );\r
+                       *pxTicksToWait -= xElapsedTime;\r
+                       vTaskInternalSetTimeOutState( pxTimeOut );\r
                        xReturn = pdFALSE;\r
                }\r
                else\r
                {\r
+                       *pxTicksToWait = 0;\r
                        xReturn = pdTRUE;\r
                }\r
        }\r
@@ -3180,11 +3235,11 @@ void vTaskMissedYield( void )
        UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask )\r
        {\r
        UBaseType_t uxReturn;\r
-       TCB_t *pxTCB;\r
+       TCB_t const *pxTCB;\r
 \r
                if( xTask != NULL )\r
                {\r
-                       pxTCB = ( TCB_t * ) xTask;\r
+                       pxTCB = xTask;\r
                        uxReturn = pxTCB->uxTaskNumber;\r
                }\r
                else\r
@@ -3202,11 +3257,11 @@ void vTaskMissedYield( void )
 \r
        void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle )\r
        {\r
-       TCB_t *pxTCB;\r
+       TCB_t * pxTCB;\r
 \r
                if( xTask != NULL )\r
                {\r
-                       pxTCB = ( TCB_t * ) xTask;\r
+                       pxTCB = xTask;\r
                        pxTCB->uxTaskNumber = uxHandle;\r
                }\r
        }\r
@@ -3232,6 +3287,11 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
        /** THIS IS THE RTOS IDLE TASK - WHICH IS CREATED AUTOMATICALLY WHEN THE\r
        SCHEDULER IS STARTED. **/\r
 \r
+       /* In case a task that has a secure context deletes itself, in which case\r
+       the idle task is responsible for deleting the task's secure context, if\r
+       any. */\r
+       portTASK_CALLS_SECURE_FUNCTIONS();\r
+\r
        for( ;; )\r
        {\r
                /* See if any tasks have deleted themselves - if so then the idle task\r
@@ -3308,6 +3368,11 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
                                        configASSERT( xNextTaskUnblockTime >= xTickCount );\r
                                        xExpectedIdleTime = prvGetExpectedIdleTime();\r
 \r
+                                       /* Define the following macro to set xExpectedIdleTime to 0\r
+                                       if the application does not want\r
+                                       portSUPPRESS_TICKS_AND_SLEEP() to be called. */\r
+                                       configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( xExpectedIdleTime );\r
+\r
                                        if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )\r
                                        {\r
                                                traceLOW_POWER_IDLE_BEGIN();\r
@@ -3465,37 +3530,22 @@ static void prvCheckTasksWaitingTermination( void )
 \r
        #if ( INCLUDE_vTaskDelete == 1 )\r
        {\r
-               BaseType_t xListIsEmpty;\r
+               TCB_t *pxTCB;\r
 \r
-               /* ucTasksDeleted is used to prevent vTaskSuspendAll() being called\r
-               too often in the idle task. */\r
+               /* uxDeletedTasksWaitingCleanUp is used to prevent taskENTER_CRITICAL()\r
+               being called too often in the idle task. */\r
                while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U )\r
                {\r
-                       vTaskSuspendAll();\r
+                       taskENTER_CRITICAL();\r
                        {\r
-                               xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );\r
+                               pxTCB = listGET_OWNER_OF_HEAD_ENTRY( ( &xTasksWaitingTermination ) ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
+                               ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+                               --uxCurrentNumberOfTasks;\r
+                               --uxDeletedTasksWaitingCleanUp;\r
                        }\r
-                       ( void ) xTaskResumeAll();\r
-\r
-                       if( xListIsEmpty == pdFALSE )\r
-                       {\r
-                               TCB_t *pxTCB;\r
-\r
-                               taskENTER_CRITICAL();\r
-                               {\r
-                                       pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xTasksWaitingTermination ) );\r
-                                       ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
-                                       --uxCurrentNumberOfTasks;\r
-                                       --uxDeletedTasksWaitingCleanUp;\r
-                               }\r
-                               taskEXIT_CRITICAL();\r
+                       taskEXIT_CRITICAL();\r
 \r
-                               prvDeleteTCB( pxTCB );\r
-                       }\r
-                       else\r
-                       {\r
-                               mtCOVERAGE_TEST_MARKER();\r
-                       }\r
+                       prvDeleteTCB( pxTCB );\r
                }\r
        }\r
        #endif /* INCLUDE_vTaskDelete */\r
@@ -3517,25 +3567,6 @@ static void prvCheckTasksWaitingTermination( void )
                pxTaskStatus->pxStackBase = pxTCB->pxStack;\r
                pxTaskStatus->xTaskNumber = pxTCB->uxTCBNumber;\r
 \r
-               #if ( INCLUDE_vTaskSuspend == 1 )\r
-               {\r
-                       /* If the task is in the suspended list then there is a chance it is\r
-                       actually just blocked indefinitely - so really it should be reported as\r
-                       being in the Blocked state. */\r
-                       if( pxTaskStatus->eCurrentState == eSuspended )\r
-                       {\r
-                               vTaskSuspendAll();\r
-                               {\r
-                                       if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
-                                       {\r
-                                               pxTaskStatus->eCurrentState = eBlocked;\r
-                                       }\r
-                               }\r
-                               ( void ) xTaskResumeAll();\r
-                       }\r
-               }\r
-               #endif /* INCLUDE_vTaskSuspend */\r
-\r
                #if ( configUSE_MUTEXES == 1 )\r
                {\r
                        pxTaskStatus->uxBasePriority = pxTCB->uxBasePriority;\r
@@ -3556,16 +3587,42 @@ static void prvCheckTasksWaitingTermination( void )
                }\r
                #endif\r
 \r
-               /* Obtaining the task state is a little fiddly, so is only done if the value\r
-               of eState passed into this function is eInvalid - otherwise the state is\r
-               just set to whatever is passed in. */\r
+               /* Obtaining the task state is a little fiddly, so is only done if the\r
+               value of eState passed into this function is eInvalid - otherwise the\r
+               state is just set to whatever is passed in. */\r
                if( eState != eInvalid )\r
                {\r
-                       pxTaskStatus->eCurrentState = eState;\r
+                       if( pxTCB == pxCurrentTCB )\r
+                       {\r
+                               pxTaskStatus->eCurrentState = eRunning;\r
+                       }\r
+                       else\r
+                       {\r
+                               pxTaskStatus->eCurrentState = eState;\r
+\r
+                               #if ( INCLUDE_vTaskSuspend == 1 )\r
+                               {\r
+                                       /* If the task is in the suspended list then there is a\r
+                                       chance it is actually just blocked indefinitely - so really\r
+                                       it should be reported as being in the Blocked state. */\r
+                                       if( eState == eSuspended )\r
+                                       {\r
+                                               vTaskSuspendAll();\r
+                                               {\r
+                                                       if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
+                                                       {\r
+                                                               pxTaskStatus->eCurrentState = eBlocked;\r
+                                                       }\r
+                                               }\r
+                                               ( void ) xTaskResumeAll();\r
+                                       }\r
+                               }\r
+                               #endif /* INCLUDE_vTaskSuspend */\r
+                       }\r
                }\r
                else\r
                {\r
-                       pxTaskStatus->eCurrentState = eTaskGetState( xTask );\r
+                       pxTaskStatus->eCurrentState = eTaskGetState( pxTCB );\r
                }\r
 \r
                /* Obtaining the stack space takes some time, so the xGetFreeStackSpace\r
@@ -3600,7 +3657,7 @@ static void prvCheckTasksWaitingTermination( void )
 \r
                if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )\r
                {\r
-                       listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
+                       listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
 \r
                        /* Populate an TaskStatus_t structure within the\r
                        pxTaskStatusArray array for each task that is referenced from\r
@@ -3608,7 +3665,7 @@ static void prvCheckTasksWaitingTermination( void )
                        meaning of each TaskStatus_t structure member. */\r
                        do\r
                        {\r
-                               listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\r
+                               listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
                                vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState );\r
                                uxTask++;\r
                        } while( pxNextTCB != pxFirstTCB );\r
@@ -3626,7 +3683,7 @@ static void prvCheckTasksWaitingTermination( void )
 \r
 #if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
 \r
-       static uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte )\r
+       static configSTACK_DEPTH_TYPE prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte )\r
        {\r
        uint32_t ulCount = 0U;\r
 \r
@@ -3638,7 +3695,7 @@ static void prvCheckTasksWaitingTermination( void )
 \r
                ulCount /= ( uint32_t ) sizeof( StackType_t ); /*lint !e961 Casting is not redundant on smaller architectures. */\r
 \r
-               return ( uint16_t ) ulCount;\r
+               return ( configSTACK_DEPTH_TYPE ) ulCount;\r
        }\r
 \r
 #endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */\r
@@ -3696,7 +3753,7 @@ static void prvCheckTasksWaitingTermination( void )
                        vPortFree( pxTCB->pxStack );\r
                        vPortFree( pxTCB );\r
                }\r
-               #elif( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\r
+               #elif( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */\r
                {\r
                        /* The task could have been allocated statically or dynamically, so\r
                        check what was statically allocated before trying to free the\r
@@ -3718,7 +3775,7 @@ static void prvCheckTasksWaitingTermination( void )
                        {\r
                                /* Neither the stack nor the TCB were allocated dynamically, so\r
                                nothing needs to be freed. */\r
-                               configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB     )\r
+                               configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB     );\r
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
@@ -3746,7 +3803,7 @@ TCB_t *pxTCB;
                the item at the head of the delayed list.  This is the time at\r
                which the task at the head of the delayed list should be removed\r
                from the Blocked state. */\r
-               ( pxTCB ) = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
+               ( pxTCB ) = listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
                xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( ( pxTCB )->xStateListItem ) );\r
        }\r
 }\r
@@ -3799,25 +3856,27 @@ TCB_t *pxTCB;
 \r
 #if ( configUSE_MUTEXES == 1 )\r
 \r
-       void vTaskPriorityInherit( TaskHandle_t const pxMutexHolder )\r
+       BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder )\r
        {\r
-       TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
+       TCB_t * const pxMutexHolderTCB = pxMutexHolder;\r
+       BaseType_t xReturn = pdFALSE;\r
 \r
                /* If the mutex was given back by an interrupt while the queue was\r
-               locked then the mutex holder might now be NULL. */\r
+               locked then the mutex holder might now be NULL.  _RB_ Is this still\r
+               needed as interrupts can no longer use mutexes? */\r
                if( pxMutexHolder != NULL )\r
                {\r
                        /* If the holder of the mutex has a priority below the priority of\r
                        the task attempting to obtain the mutex then it will temporarily\r
                        inherit the priority of the task attempting to obtain the mutex. */\r
-                       if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )\r
+                       if( pxMutexHolderTCB->uxPriority < pxCurrentTCB->uxPriority )\r
                        {\r
                                /* Adjust the mutex holder state to account for its new\r
                                priority.  Only reset the event list item value if the value is\r
-                               not     being used for anything else. */\r
-                               if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
+                               not being used for anything else. */\r
+                               if( ( listGET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
                                {\r
-                                       listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+                                       listSET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
                                }\r
                                else\r
                                {\r
@@ -3826,11 +3885,11 @@ TCB_t *pxTCB;
 \r
                                /* If the task being modified is in the ready state it will need\r
                                to be moved into a new list. */\r
-                               if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xStateListItem ) ) != pdFALSE )\r
+                               if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxMutexHolderTCB->uxPriority ] ), &( pxMutexHolderTCB->xStateListItem ) ) != pdFALSE )\r
                                {\r
-                                       if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
+                                       if( uxListRemove( &( pxMutexHolderTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
                                        {\r
-                                               taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+                                               taskRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority );\r
                                        }\r
                                        else\r
                                        {\r
@@ -3838,26 +3897,45 @@ TCB_t *pxTCB;
                                        }\r
 \r
                                        /* Inherit the priority before being moved into the new list. */\r
-                                       pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
-                                       prvAddTaskToReadyList( pxTCB );\r
+                                       pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;\r
+                                       prvAddTaskToReadyList( pxMutexHolderTCB );\r
                                }\r
                                else\r
                                {\r
                                        /* Just inherit the priority. */\r
-                                       pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
+                                       pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;\r
                                }\r
 \r
-                               traceTASK_PRIORITY_INHERIT( pxTCB, pxCurrentTCB->uxPriority );\r
+                               traceTASK_PRIORITY_INHERIT( pxMutexHolderTCB, pxCurrentTCB->uxPriority );\r
+\r
+                               /* Inheritance occurred. */\r
+                               xReturn = pdTRUE;\r
                        }\r
                        else\r
                        {\r
-                               mtCOVERAGE_TEST_MARKER();\r
+                               if( pxMutexHolderTCB->uxBasePriority < pxCurrentTCB->uxPriority )\r
+                               {\r
+                                       /* The base priority of the mutex holder is lower than the\r
+                                       priority of the task attempting to take the mutex, but the\r
+                                       current priority of the mutex holder is not lower than the\r
+                                       priority of the task attempting to take the mutex.\r
+                                       Therefore the mutex holder must have already inherited a\r
+                                       priority, but inheritance would have occurred if that had\r
+                                       not been the case. */\r
+                                       xReturn = pdTRUE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
                        }\r
                }\r
                else\r
                {\r
                        mtCOVERAGE_TEST_MARKER();\r
                }\r
+\r
+               return xReturn;\r
        }\r
 \r
 #endif /* configUSE_MUTEXES */\r
@@ -3867,7 +3945,7 @@ TCB_t *pxTCB;
 \r
        BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder )\r
        {\r
-       TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
+       TCB_t * const pxTCB = pxMutexHolder;\r
        BaseType_t xReturn = pdFALSE;\r
 \r
                if( pxMutexHolder != NULL )\r
@@ -3877,7 +3955,6 @@ TCB_t *pxTCB;
                        interrupt, and if a mutex is given by the holding task then it must\r
                        be the running state task. */\r
                        configASSERT( pxTCB == pxCurrentTCB );\r
-\r
                        configASSERT( pxTCB->uxMutexesHeld );\r
                        ( pxTCB->uxMutexesHeld )--;\r
 \r
@@ -3891,8 +3968,8 @@ TCB_t *pxTCB;
                                        /* A task can only have an inherited priority if it holds\r
                                        the mutex.  If the mutex is held by a task then it cannot be\r
                                        given from an interrupt, and if a mutex is given by the\r
-                                       holding task then it must be the running state task.  Remove\r
-                                       the     holding task from the ready     list. */\r
+                                       holding task then it must be the running state task.  Remove\r
+                                       the holding task from the ready list. */\r
                                        if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
                                        {\r
                                                taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
@@ -3944,6 +4021,108 @@ TCB_t *pxTCB;
 #endif /* configUSE_MUTEXES */\r
 /*-----------------------------------------------------------*/\r
 \r
+#if ( configUSE_MUTEXES == 1 )\r
+\r
+       void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask )\r
+       {\r
+       TCB_t * const pxTCB = pxMutexHolder;\r
+       UBaseType_t uxPriorityUsedOnEntry, uxPriorityToUse;\r
+       const UBaseType_t uxOnlyOneMutexHeld = ( UBaseType_t ) 1;\r
+\r
+               if( pxMutexHolder != NULL )\r
+               {\r
+                       /* If pxMutexHolder is not NULL then the holder must hold at least\r
+                       one mutex. */\r
+                       configASSERT( pxTCB->uxMutexesHeld );\r
+\r
+                       /* Determine the priority to which the priority of the task that\r
+                       holds the mutex should be set.  This will be the greater of the\r
+                       holding task's base priority and the priority of the highest\r
+                       priority task that is waiting to obtain the mutex. */\r
+                       if( pxTCB->uxBasePriority < uxHighestPriorityWaitingTask )\r
+                       {\r
+                               uxPriorityToUse = uxHighestPriorityWaitingTask;\r
+                       }\r
+                       else\r
+                       {\r
+                               uxPriorityToUse = pxTCB->uxBasePriority;\r
+                       }\r
+\r
+                       /* Does the priority need to change? */\r
+                       if( pxTCB->uxPriority != uxPriorityToUse )\r
+                       {\r
+                               /* Only disinherit if no other mutexes are held.  This is a\r
+                               simplification in the priority inheritance implementation.  If\r
+                               the task that holds the mutex is also holding other mutexes then\r
+                               the other mutexes may have caused the priority inheritance. */\r
+                               if( pxTCB->uxMutexesHeld == uxOnlyOneMutexHeld )\r
+                               {\r
+                                       /* If a task has timed out because it already holds the\r
+                                       mutex it was trying to obtain then it cannot of inherited\r
+                                       its own priority. */\r
+                                       configASSERT( pxTCB != pxCurrentTCB );\r
+\r
+                                       /* Disinherit the priority, remembering the previous\r
+                                       priority to facilitate determining the subject task's\r
+                                       state. */\r
+                                       traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
+                                       uxPriorityUsedOnEntry = pxTCB->uxPriority;\r
+                                       pxTCB->uxPriority = uxPriorityToUse;\r
+\r
+                                       /* Only reset the event list item value if the value is not\r
+                                       being used for anything else. */\r
+                                       if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
+                                       {\r
+                                               listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriorityToUse ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+\r
+                                       /* If the running task is not the task that holds the mutex\r
+                                       then the task that holds the mutex could be in either the\r
+                                       Ready, Blocked or Suspended states.  Only remove the task\r
+                                       from its current state list if it is in the Ready state as\r
+                                       the task's priority is going to change and there is one\r
+                                       Ready list per priority. */\r
+                                       if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE )\r
+                                       {\r
+                                               if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
+                                               {\r
+                                                       taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
+\r
+                                               prvAddTaskToReadyList( pxTCB );\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       mtCOVERAGE_TEST_MARKER();\r
+               }\r
+       }\r
+\r
+#endif /* configUSE_MUTEXES */\r
+/*-----------------------------------------------------------*/\r
+\r
 #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
 \r
        void vTaskEnterCritical( void )\r
@@ -4024,7 +4203,7 @@ TCB_t *pxTCB;
                }\r
 \r
                /* Terminate. */\r
-               pcBuffer[ x ] = 0x00;\r
+               pcBuffer[ x ] = ( char ) 0x00;\r
 \r
                /* Return the new end of string. */\r
                return &( pcBuffer[ x ] );\r
@@ -4038,7 +4217,7 @@ TCB_t *pxTCB;
        void vTaskList( char * pcWriteBuffer )\r
        {\r
        TaskStatus_t *pxTaskStatusArray;\r
-       volatile UBaseType_t uxArraySize, x;\r
+       UBaseType_t uxArraySize, x;\r
        char cStatus;\r
 \r
                /*\r
@@ -4067,7 +4246,7 @@ TCB_t *pxTCB;
 \r
 \r
                /* Make sure the write buffer does not contain a string. */\r
-               *pcWriteBuffer = 0x00;\r
+               *pcWriteBuffer = ( char ) 0x00;\r
 \r
                /* Take a snapshot of the number of tasks in case it changes while this\r
                function is executing. */\r
@@ -4076,7 +4255,7 @@ TCB_t *pxTCB;
                /* Allocate an array index for each task.  NOTE!  if\r
                configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will\r
                equate to NULL. */\r
-               pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );\r
+               pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation allocates a struct that has the alignment requirements of a pointer. */\r
 \r
                if( pxTaskStatusArray != NULL )\r
                {\r
@@ -4088,6 +4267,9 @@ TCB_t *pxTCB;
                        {\r
                                switch( pxTaskStatusArray[ x ].eCurrentState )\r
                                {\r
+                                       case eRunning:          cStatus = tskRUNNING_CHAR;\r
+                                                                               break;\r
+\r
                                        case eReady:            cStatus = tskREADY_CHAR;\r
                                                                                break;\r
 \r
@@ -4100,9 +4282,10 @@ TCB_t *pxTCB;
                                        case eDeleted:          cStatus = tskDELETED_CHAR;\r
                                                                                break;\r
 \r
+                                       case eInvalid:          /* Fall through. */\r
                                        default:                        /* Should not get here, but it is included\r
                                                                                to prevent static checking errors. */\r
-                                                                               cStatus = 0x00;\r
+                                                                               cStatus = ( char ) 0x00;\r
                                                                                break;\r
                                }\r
 \r
@@ -4111,8 +4294,8 @@ TCB_t *pxTCB;
                                pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );\r
 \r
                                /* Write the rest of the string. */\r
-                               sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );\r
-                               pcWriteBuffer += strlen( pcWriteBuffer );\r
+                               sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */\r
+                               pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers especially as in this case where it best denotes the intent of the code. */\r
                        }\r
 \r
                        /* Free the array again.  NOTE!  If configSUPPORT_DYNAMIC_ALLOCATION\r
@@ -4133,7 +4316,7 @@ TCB_t *pxTCB;
        void vTaskGetRunTimeStats( char *pcWriteBuffer )\r
        {\r
        TaskStatus_t *pxTaskStatusArray;\r
-       volatile UBaseType_t uxArraySize, x;\r
+       UBaseType_t uxArraySize, x;\r
        uint32_t ulTotalTime, ulStatsAsPercentage;\r
 \r
                #if( configUSE_TRACE_FACILITY != 1 )\r
@@ -4168,7 +4351,7 @@ TCB_t *pxTCB;
                 */\r
 \r
                /* Make sure the write buffer does not contain a string. */\r
-               *pcWriteBuffer = 0x00;\r
+               *pcWriteBuffer = ( char ) 0x00;\r
 \r
                /* Take a snapshot of the number of tasks in case it changes while this\r
                function is executing. */\r
@@ -4177,7 +4360,7 @@ TCB_t *pxTCB;
                /* Allocate an array index for each task.  NOTE!  If\r
                configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will\r
                equate to NULL. */\r
-               pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );\r
+               pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation allocates a struct that has the alignment requirements of a pointer. */\r
 \r
                if( pxTaskStatusArray != NULL )\r
                {\r
@@ -4188,7 +4371,7 @@ TCB_t *pxTCB;
                        ulTotalTime /= 100UL;\r
 \r
                        /* Avoid divide by zero errors. */\r
-                       if( ulTotalTime > 0 )\r
+                       if( ulTotalTime > 0UL )\r
                        {\r
                                /* Create a human readable table from the binary data. */\r
                                for( x = 0; x < uxArraySize; x++ )\r
@@ -4213,7 +4396,7 @@ TCB_t *pxTCB;
                                                {\r
                                                        /* sizeof( int ) == sizeof( long ) so a smaller\r
                                                        printf() library can be used. */\r
-                                                       sprintf( pcWriteBuffer, "\t%u\t\t%u%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage );\r
+                                                       sprintf( pcWriteBuffer, "\t%u\t\t%u%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */\r
                                                }\r
                                                #endif\r
                                        }\r
@@ -4229,12 +4412,12 @@ TCB_t *pxTCB;
                                                {\r
                                                        /* sizeof( int ) == sizeof( long ) so a smaller\r
                                                        printf() library can be used. */\r
-                                                       sprintf( pcWriteBuffer, "\t%u\t\t<1%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );\r
+                                                       sprintf( pcWriteBuffer, "\t%u\t\t<1%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */\r
                                                }\r
                                                #endif\r
                                        }\r
 \r
-                                       pcWriteBuffer += strlen( pcWriteBuffer );\r
+                                       pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers especially as in this case where it best denotes the intent of the code. */\r
                                }\r
                        }\r
                        else\r
@@ -4271,7 +4454,7 @@ TickType_t uxReturn;
 \r
 #if ( configUSE_MUTEXES == 1 )\r
 \r
-       void *pvTaskIncrementMutexHeldCount( void )\r
+       TaskHandle_t pvTaskIncrementMutexHeldCount( void )\r
        {\r
                /* If xSemaphoreCreateMutex() is called before any tasks have been created\r
                then pxCurrentTCB will be NULL. */\r
@@ -4411,7 +4594,7 @@ TickType_t uxReturn;
                        blocked state (because a notification was already pending) or the\r
                        task unblocked because of a notification.  Otherwise the task\r
                        unblocked because of a timeout. */\r
-                       if( pxCurrentTCB->ucNotifyState == taskWAITING_NOTIFICATION )\r
+                       if( pxCurrentTCB->ucNotifyState != taskNOTIFICATION_RECEIVED )\r
                        {\r
                                /* A notification was not received. */\r
                                xReturn = pdFALSE;\r
@@ -4443,7 +4626,7 @@ TickType_t uxReturn;
        uint8_t ucOriginalNotifyState;\r
 \r
                configASSERT( xTaskToNotify );\r
-               pxTCB = ( TCB_t * ) xTaskToNotify;\r
+               pxTCB = xTaskToNotify;\r
 \r
                taskENTER_CRITICAL();\r
                {\r
@@ -4486,6 +4669,14 @@ TickType_t uxReturn;
                                        /* The task is being notified without its notify value being\r
                                        updated. */\r
                                        break;\r
+\r
+                               default:\r
+                                       /* Should not get here if all enums are handled.\r
+                                       Artificially force an assert by testing a value the\r
+                                       compiler can't assume is const. */\r
+                                       configASSERT( pxTCB->ulNotifiedValue == ~0UL );\r
+\r
+                                       break;\r
                        }\r
 \r
                        traceTASK_NOTIFY();\r
@@ -4569,7 +4760,7 @@ TickType_t uxReturn;
                http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
                portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
-               pxTCB = ( TCB_t * ) xTaskToNotify;\r
+               pxTCB = xTaskToNotify;\r
 \r
                uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
                {\r
@@ -4611,6 +4802,13 @@ TickType_t uxReturn;
                                        /* The task is being notified without its notify value being\r
                                        updated. */\r
                                        break;\r
+\r
+                               default:\r
+                                       /* Should not get here if all enums are handled.\r
+                                       Artificially force an assert by testing a value the\r
+                                       compiler can't assume is const. */\r
+                                       configASSERT( pxTCB->ulNotifiedValue == ~0UL );\r
+                                       break;\r
                        }\r
 \r
                        traceTASK_NOTIFY_FROM_ISR();\r
@@ -4642,13 +4840,11 @@ TickType_t uxReturn;
                                        {\r
                                                *pxHigherPriorityTaskWoken = pdTRUE;\r
                                        }\r
-                                       else\r
-                                       {\r
-                                               /* Mark that a yield is pending in case the user is not\r
-                                               using the "xHigherPriorityTaskWoken" parameter to an ISR\r
-                                               safe FreeRTOS function. */\r
-                                               xYieldPending = pdTRUE;\r
-                                       }\r
+\r
+                                       /* Mark that a yield is pending in case the user is not\r
+                                       using the "xHigherPriorityTaskWoken" parameter to an ISR\r
+                                       safe FreeRTOS function. */\r
+                                       xYieldPending = pdTRUE;\r
                                }\r
                                else\r
                                {\r
@@ -4692,7 +4888,7 @@ TickType_t uxReturn;
                http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
                portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
-               pxTCB = ( TCB_t * ) xTaskToNotify;\r
+               pxTCB = xTaskToNotify;\r
 \r
                uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
                {\r
@@ -4732,13 +4928,11 @@ TickType_t uxReturn;
                                        {\r
                                                *pxHigherPriorityTaskWoken = pdTRUE;\r
                                        }\r
-                                       else\r
-                                       {\r
-                                               /* Mark that a yield is pending in case the user is not\r
-                                               using the "xHigherPriorityTaskWoken" parameter in an ISR\r
-                                               safe FreeRTOS function. */\r
-                                               xYieldPending = pdTRUE;\r
-                                       }\r
+\r
+                                       /* Mark that a yield is pending in case the user is not\r
+                                       using the "xHigherPriorityTaskWoken" parameter in an ISR\r
+                                       safe FreeRTOS function. */\r
+                                       xYieldPending = pdTRUE;\r
                                }\r
                                else\r
                                {\r
@@ -4805,7 +4999,7 @@ const TickType_t xConstTickCount = xTickCount;
        {\r
                /* The current task must be in a ready list, so there is no need to\r
                check, and the port reset macro can be called directly. */\r
-               portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+               portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); /*lint !e931 pxCurrentTCB cannot change as it is the calling task.  pxCurrentTCB->uxPriority and uxTopReadyPriority cannot change as called with scheduler suspended or in a critical section. */\r
        }\r
        else\r
        {\r
@@ -4909,12 +5103,12 @@ when performing module tests). */
 \r
        #include "freertos_tasks_c_additions.h"\r
 \r
-       static void freertos_tasks_c_additions_init( void )\r
-       {\r
-               #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\r
+       #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\r
+               static void freertos_tasks_c_additions_init( void )\r
+               {\r
                        FREERTOS_TASKS_C_ADDITIONS_INIT();\r
-               #endif\r
-       }\r
+               }\r
+       #endif\r
 \r
 #endif\r
 \r