]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
If tickless idle mode is in use then ensure prvResetNextTaskUnblockTime() is called...
[freertos] / FreeRTOS / Source / tasks.c
index 7e4d9c52080f2678df04dae016556a9c0050ef25..e62b388602fcaec3178b6791d746295fb22f4be7 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * FreeRTOS Kernel V10.0.1\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ * FreeRTOS Kernel V10.2.1\r
+ * Copyright (C) 2019 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
@@ -40,11 +40,11 @@ task.h is included from an application file. */
 #include "timers.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
@@ -75,24 +75,7 @@ functions but without including stdio.h here. */
  */\r
 #define tskSTACK_FILL_BYTE     ( 0xa5U )\r
 \r
-/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using\r
-dynamically allocated RAM, in which case when any task is deleted it is known\r
-that both the task's stack and TCB need to be freed.  Sometimes the\r
-FreeRTOSConfig.h settings only allow a task to be created using statically\r
-allocated RAM, in which case when any task is deleted it is known that neither\r
-the task's stack or TCB should be freed.  Sometimes the FreeRTOSConfig.h\r
-settings allow a task to be created using either statically or dynamically\r
-allocated RAM, in which case a member of the TCB is used to record whether the\r
-stack and/or TCB were allocated statically or dynamically, so when a task is\r
-deleted the RAM that was allocated dynamically is freed again and no attempt is\r
-made to free the RAM that was allocated statically.\r
-tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a\r
-task to be created using either statically or dynamically allocated RAM.  Note\r
-that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with\r
-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
+/* Bits used to recored how a task's stack and TCB were allocated. */\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
@@ -100,7 +83,7 @@ changed then the definition of StaticTask_t must also be updated. */
 /* If any of the following are set then task stacks are filled with a known\r
 value so the high water mark can be determined.  If none of the following are\r
 set then don't fill the stack so there is no unnecessary dependency on memset. */\r
-#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) )\r
        #define tskSET_NEW_STACKS_TO_KNOWN_VALUE        1\r
 #else\r
        #define tskSET_NEW_STACKS_TO_KNOWN_VALUE        0\r
@@ -245,7 +228,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
@@ -266,7 +249,7 @@ to its original value when it is released. */
  * and stores task state information, including a pointer to the task's context\r
  * (the task's run time environment, including register values)\r
  */\r
-typedef struct tskTaskControlBlock\r
+typedef struct tskTaskControlBlock                     /* The old naming convention is used to prevent breaking kernel aware debuggers. */\r
 {\r
        volatile StackType_t    *pxTopOfStack;  /*< Points to the location of the last item placed on the tasks stack.  THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */\r
 \r
@@ -317,7 +300,10 @@ typedef struct tskTaskControlBlock
                responsible for resulting newlib operation.  User must be familiar with\r
                newlib and must provide system-wide implementations of the necessary\r
                stubs. Be warned that (at the time of writing) the current newlib design\r
-               implements a system-wide malloc() that must be provided with locks. */\r
+               implements a system-wide malloc() that must be provided with locks.\r
+\r
+               See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html\r
+               for additional information. */\r
                struct  _reent xNewLib_reent;\r
        #endif\r
 \r
@@ -326,9 +312,9 @@ typedef struct tskTaskControlBlock
                volatile uint8_t ucNotifyState;\r
        #endif\r
 \r
-       /* See the comments above the definition of\r
+       /* See the comments in FreeRTOS.h with 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
@@ -336,6 +322,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
@@ -344,10 +334,12 @@ 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
+/* Lists for ready and blocked tasks. --------------------\r
+xDelayedTaskList1 and xDelayedTaskList2 could be move to function scople but\r
+doing so breaks some kernel aware debuggers and debuggers that rely on removing\r
+the static qualifier. */\r
 PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */\r
 PRIVILEGED_DATA static List_t xDelayedTaskList1;                                               /*< Delayed tasks. */\r
 PRIVILEGED_DATA static List_t xDelayedTaskList2;                                               /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\r
@@ -368,12 +360,18 @@ 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 ) 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
+PRIVILEGED_DATA static volatile TickType_t xPendedTicks                        = ( TickType_t ) 0U;\r
 PRIVILEGED_DATA static volatile BaseType_t xYieldPending                       = pdFALSE;\r
 PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows                     = ( BaseType_t ) 0;\r
 PRIVILEGED_DATA static UBaseType_t uxTaskNumber                                        = ( UBaseType_t ) 0U;\r
@@ -392,6 +390,8 @@ PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended    = ( UBaseType_t
 \r
 #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
 \r
+       /* Do not move these variables to function scope as doing so prevents the\r
+       code working with debuggers that need to remove the static qualifier. */\r
        PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL;     /*< Holds the value of a timer/counter the last time a task was switched in. */\r
        PRIVILEGED_DATA static uint32_t ulTotalRunTime = 0UL;           /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
 \r
@@ -410,13 +410,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
@@ -507,9 +507,9 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, const BaseT
  * This function determines the 'high water mark' of the task stack by\r
  * determining how much of the stack remains at the original preset value.\r
  */\r
-#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 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
@@ -599,6 +599,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
@@ -607,16 +608,16 @@ 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
                                pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
-                       #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
+                       #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */\r
 \r
                        prvInitialiseNewTask( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &xReturn, pxNewTCB, NULL );\r
                        prvAddNewTaskToReadyList( pxNewTCB );\r
@@ -658,7 +659,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                task was created statically in case the task is later deleted. */\r
                                pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
-                       #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
+                       #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */\r
 \r
                        prvInitialiseNewTask(   pxTaskDefinition->pvTaskCode,\r
                                                                        pxTaskDefinition->pcName,\r
@@ -699,14 +700,14 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                /* Store the stack location in the TCB. */\r
                                pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;\r
 \r
-                               #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+                               #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )\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
+                               #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */\r
 \r
                                prvInitialiseNewTask(   pxTaskDefinition->pvTaskCode,\r
                                                                                pxTaskDefinition->pcName,\r
@@ -769,12 +770,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
@@ -797,13 +798,13 @@ 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
                                pxNewTCB->ucStaticallyAllocated = tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
-                       #endif /* configSUPPORT_STATIC_ALLOCATION */\r
+                       #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */\r
 \r
                        prvInitialiseNewTask( pxTaskCode, pcName, ( uint32_t ) usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB, NULL );\r
                        prvAddNewTaskToReadyList( pxNewTCB );\r
@@ -860,8 +861,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
@@ -888,26 +889,35 @@ UBaseType_t x;
        #endif /* portSTACK_GROWTH */\r
 \r
        /* Store the task name in the TCB. */\r
-       for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )\r
+       if( pcName != NULL )\r
        {\r
-               pxNewTCB->pcTaskName[ x ] = pcName[ x ];\r
-\r
-               /* 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
-               {\r
-                       break;\r
-               }\r
-               else\r
+               for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )\r
                {\r
-                       mtCOVERAGE_TEST_MARKER();\r
+                       pxNewTCB->pcTaskName[ x ] = pcName[ x ];\r
+\r
+                       /* 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 ] == ( char ) 0x00 )\r
+                       {\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
                }\r
-       }\r
 \r
-       /* Ensure the name string is terminated in the case that the string length\r
-       was greater or equal to configMAX_TASK_NAME_LEN. */\r
-       pxNewTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0';\r
+               /* Ensure the name string is terminated in the case that the string length\r
+               was greater or equal to configMAX_TASK_NAME_LEN. */\r
+               pxNewTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0';\r
+       }\r
+       else\r
+       {\r
+               /* The task has not been given a name, so just ensure there is a NULL\r
+               terminator when it is read out. */\r
+               pxNewTCB->pcTaskName[ 0 ] = 0x00;\r
+       }\r
 \r
        /* This is used as an array index so must ensure it's not too large.  First\r
        remove the privilege bit if one is present. */\r
@@ -986,7 +996,9 @@ UBaseType_t x;
 \r
        #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
        {\r
-               /* Initialise this task's Newlib reent structure. */\r
+               /* Initialise this task's Newlib reent structure.\r
+               See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html\r
+               for additional information. */\r
                _REENT_INIT_PTR( ( &( pxNewTCB->xNewLib_reent ) ) );\r
        }\r
        #endif\r
@@ -1003,15 +1015,53 @@ UBaseType_t x;
        the top of stack variable is updated. */\r
        #if( portUSING_MPU_WRAPPERS == 1 )\r
        {\r
-               pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters, xRunPrivileged );\r
+               /* If the port has capability to detect stack overflow,\r
+               pass the stack end address to the stack initialization\r
+               function as well. */\r
+               #if( portHAS_STACK_OVERFLOW_CHECKING == 1 )\r
+               {\r
+                       #if( portSTACK_GROWTH < 0 )\r
+                       {\r
+                               pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxNewTCB->pxStack, pxTaskCode, pvParameters, xRunPrivileged );\r
+                       }\r
+                       #else /* portSTACK_GROWTH */\r
+                       {\r
+                               pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxNewTCB->pxEndOfStack, pxTaskCode, pvParameters, xRunPrivileged );\r
+                       }\r
+                       #endif /* portSTACK_GROWTH */\r
+               }\r
+               #else /* portHAS_STACK_OVERFLOW_CHECKING */\r
+               {\r
+                       pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters, xRunPrivileged );\r
+               }\r
+               #endif /* portHAS_STACK_OVERFLOW_CHECKING */\r
        }\r
        #else /* portUSING_MPU_WRAPPERS */\r
        {\r
-               pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters );\r
+               /* If the port has capability to detect stack overflow,\r
+               pass the stack end address to the stack initialization\r
+               function as well. */\r
+               #if( portHAS_STACK_OVERFLOW_CHECKING == 1 )\r
+               {\r
+                       #if( portSTACK_GROWTH < 0 )\r
+                       {\r
+                               pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxNewTCB->pxStack, pxTaskCode, pvParameters );\r
+                       }\r
+                       #else /* portSTACK_GROWTH */\r
+                       {\r
+                               pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxNewTCB->pxEndOfStack, pxTaskCode, pvParameters );\r
+                       }\r
+                       #endif /* portSTACK_GROWTH */\r
+               }\r
+               #else /* portHAS_STACK_OVERFLOW_CHECKING */\r
+               {\r
+                       pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters );\r
+               }\r
+               #endif /* portHAS_STACK_OVERFLOW_CHECKING */\r
        }\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
@@ -1119,7 +1169,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                        being deleted. */\r
                        pxTCB = prvGetTCBFromHandle( xTaskToDelete );\r
 \r
-                       /* Remove task from the ready list. */\r
+                       /* Remove task from the ready/delayed list. */\r
                        if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
                        {\r
                                taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
@@ -1159,6 +1209,10 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                                check the xTasksWaitingTermination list. */\r
                                ++uxDeletedTasksWaitingCleanUp;\r
 \r
+                               /* Call the delete hook before portPRE_TASK_DELETE_HOOK() as\r
+                               portPRE_TASK_DELETE_HOOK() does not return in the Win32 port. */\r
+                               traceTASK_DELETE( pxTCB );\r
+\r
                                /* The pre-delete hook is primarily for the Windows simulator,\r
                                in which Windows specific clean up operations are performed,\r
                                after which it is not possible to yield away from this task -\r
@@ -1169,14 +1223,13 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                        else\r
                        {\r
                                --uxCurrentNumberOfTasks;\r
+                               traceTASK_DELETE( pxTCB );\r
                                prvDeleteTCB( pxTCB );\r
 \r
                                /* Reset the next expected unblock time in case it referred to\r
                                the task that has just been deleted. */\r
                                prvResetNextTaskUnblockTime();\r
                        }\r
-\r
-                       traceTASK_DELETE( pxTCB );\r
                }\r
                taskEXIT_CRITICAL();\r
 \r
@@ -1328,13 +1381,13 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
 #endif /* INCLUDE_vTaskDelay */\r
 /*-----------------------------------------------------------*/\r
 \r
-#if( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) )\r
+#if( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_xTaskAbortDelay == 1 ) )\r
 \r
        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
@@ -1347,11 +1400,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
@@ -1362,11 +1417,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
@@ -1401,15 +1475,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
@@ -1423,9 +1497,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
@@ -1443,7 +1517,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
@@ -1703,7 +1777,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
@@ -1731,7 +1805,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
@@ -1776,14 +1850,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
@@ -1831,7 +1905,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
@@ -1851,7 +1925,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
@@ -1916,7 +1990,7 @@ BaseType_t xReturn;
                                                                                                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
@@ -1936,7 +2010,7 @@ BaseType_t xReturn;
                                                                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
@@ -1975,14 +2049,16 @@ BaseType_t xReturn;
                #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
                {\r
                        /* Switch Newlib's _impure_ptr variable to point to the _reent\r
-                       structure specific to the task that will run first. */\r
+                       structure specific to the task that will run first.\r
+                       See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html\r
+                       for additional information. */\r
                        _impure_ptr = &( pxCurrentTCB->xNewLib_reent );\r
                }\r
                #endif /* configUSE_NEWLIB_REENTRANT */\r
 \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
@@ -1992,6 +2068,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
@@ -2036,6 +2114,7 @@ void vTaskSuspendAll( void )
        post in the FreeRTOS support forum before reporting this as a bug! -\r
        http://goo.gl/wu4acr */\r
        ++uxSchedulerSuspended;\r
+       portMEMORY_BARRIER();\r
 }\r
 /*----------------------------------------------------------*/\r
 \r
@@ -2106,6 +2185,7 @@ BaseType_t xTaskResumeAll( void )
 {\r
 TCB_t *pxTCB = NULL;\r
 BaseType_t xAlreadyYielded = pdFALSE;\r
+TickType_t xTicksToNextUnblockTime;\r
 \r
        /* If uxSchedulerSuspended is zero then this function does not match a\r
        previous call to vTaskSuspendAll(). */\r
@@ -2128,7 +2208,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
@@ -2160,30 +2240,51 @@ BaseType_t xAlreadyYielded = pdFALSE;
                                they should be processed now.  This ensures the tick count does\r
                                not     slip, and that any delayed tasks are resumed at the correct\r
                                time. */\r
+                               while( xPendedTicks > ( TickType_t ) 0 )\r
                                {\r
-                                       UBaseType_t uxPendedCounts = uxPendedTicks; /* Non-volatile copy. */\r
+                                       /* Calculate how far into the future the next task will\r
+                                       leave the Blocked state because its timeout expired.  If\r
+                                       there are no tasks due to leave the blocked state between\r
+                                       the time now and the time at which the tick count overflows\r
+                                       then xNextTaskUnblockTime will the tick overflow time.\r
+                                       This means xNextTaskUnblockTime can never be less than\r
+                                       xTickCount, and the following can therefore not\r
+                                       underflow. */\r
+                                       configASSERT( xNextTaskUnblockTime >= xTickCount );\r
+                                       xTicksToNextUnblockTime = xNextTaskUnblockTime - xTickCount;\r
 \r
-                                       if( uxPendedCounts > ( UBaseType_t ) 0U )\r
+                                       /* Don't want to move the tick count more than the number\r
+                                       of ticks that are pending, so cap if necessary. */\r
+                                       if( xTicksToNextUnblockTime > xPendedTicks )\r
                                        {\r
-                                               do\r
-                                               {\r
-                                                       if( xTaskIncrementTick() != pdFALSE )\r
-                                                       {\r
-                                                               xYieldPending = pdTRUE;\r
-                                                       }\r
-                                                       else\r
-                                                       {\r
-                                                               mtCOVERAGE_TEST_MARKER();\r
-                                                       }\r
-                                                       --uxPendedCounts;\r
-                                               } while( uxPendedCounts > ( UBaseType_t ) 0U );\r
+                                               xTicksToNextUnblockTime = xPendedTicks;\r
+                                       }\r
 \r
-                                               uxPendedTicks = 0;\r
+                                       if( xTicksToNextUnblockTime == 0 )\r
+                                       {\r
+                                               /* xTicksToNextUnblockTime could be zero if the tick\r
+                                               count is about to overflow and xTicksToNetUnblockTime\r
+                                               holds the time at which the tick count will overflow\r
+                                               (rather than the time at which the next task will\r
+                                               unblock).  Set to 1 otherwise xPendedTicks won't be\r
+                                               decremented below. */\r
+                                               xTicksToNextUnblockTime = ( TickType_t ) 1;\r
                                        }\r
-                                       else\r
+                                       else if( xTicksToNextUnblockTime > ( TickType_t ) 1 )\r
                                        {\r
-                                               mtCOVERAGE_TEST_MARKER();\r
+                                               /* Move the tick count one short of the next unblock\r
+                                               time, then call xTaskIncrementTick() to move the tick\r
+                                               count up to the next unblock time to unblock the task,\r
+                                               if any.  This will also swap the blocked task and\r
+                                               overflow blocked task lists if necessary. */\r
+                                               xTickCount += ( xTicksToNextUnblockTime - ( TickType_t ) 1 );\r
                                        }\r
+                                       xYieldPending |= xTaskIncrementTick();\r
+\r
+                                       /* Adjust for the number of ticks just added to\r
+                                       xTickCount and go around the loop again if\r
+                                       xTicksToCatchUp is still greater than 0. */\r
+                                       xPendedTicks -= xTicksToNextUnblockTime;\r
                                }\r
 \r
                                if( xYieldPending != pdFALSE )\r
@@ -2245,7 +2346,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
@@ -2285,19 +2386,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
@@ -2305,19 +2408,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
@@ -2398,7 +2506,7 @@ TCB_t *pxTCB;
                }\r
                ( void ) xTaskResumeAll();\r
 \r
-               return ( TaskHandle_t ) pxTCB;\r
+               return pxTCB;\r
        }\r
 \r
 #endif /* INCLUDE_xTaskGetHandle */\r
@@ -2510,11 +2618,114 @@ implementations require configUSE_TICKLESS_IDLE to be set to a value other than
 #endif /* configUSE_TICKLESS_IDLE */\r
 /*----------------------------------------------------------*/\r
 \r
+BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp )\r
+{\r
+BaseType_t xYieldRequired = pdFALSE;\r
+\r
+       /* Must not be called with the scheduler suspended as the implementation\r
+       relies on xPendedTicks being wound down to 0 in xTaskResumeAll(). */\r
+       configASSERT( uxSchedulerSuspended == 0 );\r
+\r
+       /* Use xPendedTicks to mimic xTicksToCatchUp number of ticks occurring when\r
+       the scheduler is suspended so the ticks are executed in xTaskResumeAll(). */\r
+       vTaskSuspendAll();\r
+       xPendedTicks += xTicksToCatchUp;\r
+       xYieldRequired = xTaskResumeAll();\r
+\r
+       return xYieldRequired;\r
+}\r
+/*----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_xTaskAbortDelay == 1 )\r
+\r
+       BaseType_t xTaskAbortDelayFromISR( TaskHandle_t xTask, BaseType_t * const pxHigherPriorityTaskWoken )\r
+       {\r
+       TCB_t *pxTCB = xTask;\r
+       BaseType_t xReturn;\r
+       UBaseType_t uxSavedInterruptStatus;\r
+\r
+               configASSERT( pxTCB );\r
+\r
+               /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+               system call (or maximum API call) interrupt priority.  Interrupts that are\r
+               above the maximum system call priority are kept permanently enabled, even\r
+               when the RTOS kernel is in a critical section, but cannot make any calls to\r
+               FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
+               then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+               failure if a FreeRTOS API function is called from an interrupt that has been\r
+               assigned a priority above the configured maximum system call priority.\r
+               Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+               that have been assigned a priority at or (logically) below the maximum\r
+               system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
+               safe API to ensure interrupt entry is as fast and as simple as possible.\r
+               More information (albeit Cortex-M specific) is provided on the following\r
+               link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+               portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+               uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+               {\r
+                       /* A task can only be prematurely removed from the Blocked state if\r
+                       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.  A higher\r
+                               priority interrupt won't touch the xStateListItem because of the\r
+                               critical section. */\r
+                               ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+\r
+                               /* Is the task waiting on an event also?  If so remove it from\r
+                               the event list too. */\r
+                               if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
+                               {\r
+                                       ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
+\r
+                                       /* This lets the task know it was forcibly removed from the\r
+                                       blocked state so it should not re-evaluate its block time and\r
+                                       then block again. */\r
+                                       pxTCB->ucDelayAborted = pdTRUE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+\r
+                               /* Place the unblocked task into the appropriate ready list. */\r
+                               prvAddTaskToReadyList( pxTCB );\r
+\r
+                               if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+                               {\r
+                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                       {\r
+                                               /* Pend the yield to be performed when the scheduler\r
+                                               is unsuspended. */\r
+                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               xReturn = pdFAIL;\r
+                       }\r
+               }\r
+               portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif\r
+/*----------------------------------------------------------*/\r
+\r
 #if ( INCLUDE_xTaskAbortDelay == 1 )\r
 \r
        BaseType_t xTaskAbortDelay( TaskHandle_t xTask )\r
        {\r
-       TCB_t *pxTCB = ( TCB_t * ) xTask;\r
+       TCB_t *pxTCB = xTask;\r
        BaseType_t xReturn;\r
 \r
                configASSERT( pxTCB );\r
@@ -2541,6 +2752,10 @@ implementations require configUSE_TICKLESS_IDLE to be set to a value other than
                                        if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
                                        {\r
                                                ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
+\r
+                                               /* This lets the task know it was forcibly removed from the\r
+                                               blocked state so it should not re-evaluate its block time and\r
+                                               then block again. */\r
                                                pxTCB->ucDelayAborted = pdTRUE;\r
                                        }\r
                                        else\r
@@ -2639,7 +2854,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
@@ -2650,7 +2865,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
@@ -2717,7 +2932,7 @@ BaseType_t xSwitchRequired = pdFALSE;
                {\r
                        /* Guard against the tick hook being called when the pended tick\r
                        count is being unwound (when the scheduler is being unlocked). */\r
-                       if( uxPendedTicks == ( UBaseType_t ) 0U )\r
+                       if( xPendedTicks == ( TickType_t ) 0 )\r
                        {\r
                                vApplicationTickHook();\r
                        }\r
@@ -2727,10 +2942,23 @@ BaseType_t xSwitchRequired = pdFALSE;
                        }\r
                }\r
                #endif /* configUSE_TICK_HOOK */\r
+\r
+               #if ( configUSE_PREEMPTION == 1 )\r
+               {\r
+                       if( xYieldPending != pdFALSE )\r
+                       {\r
+                               xSwitchRequired = pdTRUE;\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+               #endif /* configUSE_PREEMPTION */\r
        }\r
        else\r
        {\r
-               ++uxPendedTicks;\r
+               ++xPendedTicks;\r
 \r
                /* The tick hook gets called at regular intervals, even if the\r
                scheduler is locked. */\r
@@ -2741,19 +2969,6 @@ BaseType_t xSwitchRequired = pdFALSE;
                #endif\r
        }\r
 \r
-       #if ( configUSE_PREEMPTION == 1 )\r
-       {\r
-               if( xYieldPending != pdFALSE )\r
-               {\r
-                       xSwitchRequired = pdTRUE;\r
-               }\r
-               else\r
-               {\r
-                       mtCOVERAGE_TEST_MARKER();\r
-               }\r
-       }\r
-       #endif /* configUSE_PREEMPTION */\r
-\r
        return xSwitchRequired;\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -2772,13 +2987,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
@@ -2789,24 +3006,17 @@ BaseType_t xSwitchRequired = pdFALSE;
 \r
        TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask )\r
        {\r
-       TCB_t *xTCB;\r
+       TCB_t *pxTCB;\r
        TaskHookFunction_t xReturn;\r
 \r
-               /* If xTask is NULL then we are setting our own task hook. */\r
-               if( xTask == NULL )\r
-               {\r
-                       xTCB = ( TCB_t * ) pxCurrentTCB;\r
-               }\r
-               else\r
-               {\r
-                       xTCB = ( TCB_t * ) xTask;\r
-               }\r
+               /* If xTask is NULL then set the calling task's hook. */\r
+               pxTCB = prvGetTCBFromHandle( xTask );\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
-                       xReturn = xTCB->pxTaskTag;\r
+                       xReturn = pxTCB->pxTaskTag;\r
                }\r
                taskEXIT_CRITICAL();\r
 \r
@@ -2816,6 +3026,31 @@ BaseType_t xSwitchRequired = pdFALSE;
 #endif /* configUSE_APPLICATION_TASK_TAG */\r
 /*-----------------------------------------------------------*/\r
 \r
+#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+\r
+       TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask )\r
+       {\r
+       TCB_t *pxTCB;\r
+       TaskHookFunction_t xReturn;\r
+       UBaseType_t uxSavedInterruptStatus;\r
+\r
+               /* If xTask is NULL then set the calling task's hook. */\r
+               pxTCB = prvGetTCBFromHandle( xTask );\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
+               uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+               {\r
+                       xReturn = pxTCB->pxTaskTag;\r
+               }\r
+               portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif /* configUSE_APPLICATION_TASK_TAG */\r
+/*-----------------------------------------------------------*/\r
+\r
 #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
 \r
        BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter )\r
@@ -2826,11 +3061,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
@@ -2863,43 +3098,59 @@ void vTaskSwitchContext( void )
 \r
                #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
                {\r
-                               #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\r
-                                       portALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime );\r
-                               #else\r
-                                       ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
-                               #endif\r
+                       #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\r
+                               portALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime );\r
+                       #else\r
+                               ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+                       #endif\r
 \r
-                               /* Add the amount of time the task has been running to the\r
-                               accumulated time so far.  The time the task started running was\r
-                               stored in ulTaskSwitchedInTime.  Note that there is no overflow\r
-                               protection here so count values are only valid until the timer\r
-                               overflows.  The guard against negative values is to protect\r
-                               against suspect run time stat counter implementations - which\r
-                               are provided by the application, not the kernel. */\r
-                               if( ulTotalRunTime > ulTaskSwitchedInTime )\r
-                               {\r
-                                       pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\r
-                               }\r
-                               else\r
-                               {\r
-                                       mtCOVERAGE_TEST_MARKER();\r
-                               }\r
-                               ulTaskSwitchedInTime = ulTotalRunTime;\r
+                       /* Add the amount of time the task has been running to the\r
+                       accumulated time so far.  The time the task started running was\r
+                       stored in ulTaskSwitchedInTime.  Note that there is no overflow\r
+                       protection here so count values are only valid until the timer\r
+                       overflows.  The guard against negative values is to protect\r
+                       against suspect run time stat counter implementations - which\r
+                       are provided by the application, not the kernel. */\r
+                       if( ulTotalRunTime > ulTaskSwitchedInTime )\r
+                       {\r
+                               pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+                       ulTaskSwitchedInTime = ulTotalRunTime;\r
                }\r
                #endif /* configGENERATE_RUN_TIME_STATS */\r
 \r
                /* 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
-                       structure specific to this task. */\r
+                       structure specific to this task.\r
+                       See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html\r
+                       for additional information. */\r
                        _impure_ptr = &( pxCurrentTCB->xNewLib_reent );\r
                }\r
                #endif /* configUSE_NEWLIB_REENTRANT */\r
@@ -2999,7 +3250,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
@@ -3007,6 +3258,20 @@ BaseType_t xReturn;
        {\r
                ( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) );\r
                prvAddTaskToReadyList( pxUnblockedTCB );\r
+\r
+               #if( configUSE_TICKLESS_IDLE != 0 )\r
+               {\r
+                       /* If a task is blocked on a kernel object then xNextTaskUnblockTime\r
+                       might be set to the blocked task's time out time.  If the task is\r
+                       unblocked for a reason other than a timeout xNextTaskUnblockTime is\r
+                       normally left unchanged, because it is automatically reset to a new\r
+                       value when the tick count equals xNextTaskUnblockTime.  However if\r
+                       tickless idling is used it might be more important to enter sleep mode\r
+                       at the earliest possible time - so reset xNextTaskUnblockTime here to\r
+                       ensure it is updated at the earliest possible time. */\r
+                       prvResetNextTaskUnblockTime();\r
+               }\r
+               #endif\r
        }\r
        else\r
        {\r
@@ -3031,20 +3296,6 @@ BaseType_t xReturn;
                xReturn = pdFALSE;\r
        }\r
 \r
-       #if( configUSE_TICKLESS_IDLE != 0 )\r
-       {\r
-               /* If a task is blocked on a kernel object then xNextTaskUnblockTime\r
-               might be set to the blocked task's time out time.  If the task is\r
-               unblocked for a reason other than a timeout xNextTaskUnblockTime is\r
-               normally left unchanged, because it is automatically reset to a new\r
-               value when the tick count equals xNextTaskUnblockTime.  However if\r
-               tickless idling is used it might be more important to enter sleep mode\r
-               at the earliest possible time - so reset xNextTaskUnblockTime here to\r
-               ensure it is updated at the earliest possible time. */\r
-               prvResetNextTaskUnblockTime();\r
-       }\r
-       #endif\r
-\r
        return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -3062,10 +3313,24 @@ 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
+       #if( configUSE_TICKLESS_IDLE != 0 )\r
+       {\r
+               /* If a task is blocked on a kernel object then xNextTaskUnblockTime\r
+               might be set to the blocked task's time out time.  If the task is\r
+               unblocked for a reason other than a timeout xNextTaskUnblockTime is\r
+               normally left unchanged, because it is automatically reset to a new\r
+               value when the tick count equals xNextTaskUnblockTime.  However if\r
+               tickless idling is used it might be more important to enter sleep mode\r
+               at the earliest possible time - so reset xNextTaskUnblockTime here to\r
+               ensure it is updated at the earliest possible time. */\r
+               prvResetNextTaskUnblockTime();\r
+       }\r
+       #endif\r
+\r
        /* Remove the task from the delayed list and add it to the ready list.  The\r
        scheduler is suspended so interrupts will not be accessing the ready\r
        lists. */\r
@@ -3117,7 +3382,7 @@ BaseType_t xReturn;
                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
@@ -3177,11 +3442,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
@@ -3199,11 +3464,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,7 +3497,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
        /* 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
+       portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );\r
 \r
        for( ;; )\r
        {\r
@@ -3346,6 +3611,8 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
        const UBaseType_t uxNonApplicationTasks = 1;\r
        eSleepModeStatus eReturn = eStandardSleep;\r
 \r
+               /* This function must be called from a critical section. */\r
+\r
                if( listCURRENT_LIST_LENGTH( &xPendingReadyList ) != 0 )\r
                {\r
                        /* A task was made ready while the scheduler was suspended. */\r
@@ -3480,7 +3747,7 @@ static void prvCheckTasksWaitingTermination( void )
                {\r
                        taskENTER_CRITICAL();\r
                        {\r
-                               pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &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
@@ -3599,7 +3866,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
@@ -3607,7 +3874,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
@@ -3623,9 +3890,9 @@ static void prvCheckTasksWaitingTermination( void )
 #endif /* configUSE_TRACE_FACILITY */\r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 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
@@ -3637,10 +3904,50 @@ 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 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) ) */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )\r
+\r
+       /* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the\r
+       same except for their return type.  Using configSTACK_DEPTH_TYPE allows the\r
+       user to determine the return type.  It gets around the problem of the value\r
+       overflowing on 8-bit types without breaking backward compatibility for\r
+       applications that expect an 8-bit return type. */\r
+       configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask )\r
+       {\r
+       TCB_t *pxTCB;\r
+       uint8_t *pucEndOfStack;\r
+       configSTACK_DEPTH_TYPE uxReturn;\r
+\r
+               /* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are\r
+               the same except for their return type.  Using configSTACK_DEPTH_TYPE\r
+               allows the user to determine the return type.  It gets around the\r
+               problem of the value overflowing on 8-bit types without breaking\r
+               backward compatibility for applications that expect an 8-bit return\r
+               type. */\r
+\r
+               pxTCB = prvGetTCBFromHandle( xTask );\r
+\r
+               #if portSTACK_GROWTH < 0\r
+               {\r
+                       pucEndOfStack = ( uint8_t * ) pxTCB->pxStack;\r
+               }\r
+               #else\r
+               {\r
+                       pucEndOfStack = ( uint8_t * ) pxTCB->pxEndOfStack;\r
+               }\r
+               #endif\r
+\r
+               uxReturn = prvTaskCheckFreeStackSpace( pucEndOfStack );\r
+\r
+               return uxReturn;\r
        }\r
 \r
-#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */\r
+#endif /* INCLUDE_uxTaskGetStackHighWaterMark2 */\r
 /*-----------------------------------------------------------*/\r
 \r
 #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )\r
@@ -3681,7 +3988,9 @@ static void prvCheckTasksWaitingTermination( void )
                portCLEAN_UP_TCB( pxTCB );\r
 \r
                /* Free up the memory allocated by the scheduler for the task.  It is up\r
-               to the task to free any memory allocated at the application level. */\r
+               to the task to free any memory allocated at the application level.\r
+               See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html\r
+               for additional information. */\r
                #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
                {\r
                        _reclaim_reent( &( pxTCB->xNewLib_reent ) );\r
@@ -3695,7 +4004,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
@@ -3745,7 +4054,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
@@ -3800,7 +4109,7 @@ TCB_t *pxTCB;
 \r
        BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder )\r
        {\r
-       TCB_t * const pxMutexHolderTCB = ( 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
@@ -3831,7 +4140,10 @@ TCB_t *pxTCB;
                                {\r
                                        if( uxListRemove( &( pxMutexHolderTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
                                        {\r
-                                               taskRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority );\r
+                                               /* It is known that the task is in its ready list so\r
+                                               there is no need to check again and the port level\r
+                                               reset macro can be called directly. */\r
+                                               portRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority, uxTopReadyPriority );\r
                                        }\r
                                        else\r
                                        {\r
@@ -3887,7 +4199,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
@@ -3911,7 +4223,7 @@ TCB_t *pxTCB;
                                        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
+                                       the holding task from the ready/delayed list. */\r
                                        if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
                                        {\r
                                                taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
@@ -3967,7 +4279,7 @@ TCB_t *pxTCB;
 \r
        void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask )\r
        {\r
-       TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
+       TCB_t * const pxTCB = pxMutexHolder;\r
        UBaseType_t uxPriorityUsedOnEntry, uxPriorityToUse;\r
        const UBaseType_t uxOnlyOneMutexHeld = ( UBaseType_t ) 1;\r
 \r
@@ -4032,7 +4344,10 @@ TCB_t *pxTCB;
                                        {\r
                                                if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
                                                {\r
-                                                       taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+                                                       /* It is known that the task is in its ready list so\r
+                                                       there is no need to check again and the port level\r
+                                                       reset macro can be called directly. */\r
+                                                       portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );\r
                                                }\r
                                                else\r
                                                {\r
@@ -4145,7 +4460,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
@@ -4159,7 +4474,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
@@ -4188,7 +4503,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
@@ -4197,7 +4512,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
@@ -4224,9 +4539,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
@@ -4235,8 +4551,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
@@ -4257,7 +4573,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
@@ -4292,7 +4608,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
@@ -4301,7 +4617,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
@@ -4312,7 +4628,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
@@ -4337,7 +4653,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
@@ -4353,12 +4669,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
@@ -4395,7 +4711,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
@@ -4567,7 +4883,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
@@ -4610,6 +4926,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
@@ -4693,7 +5017,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
@@ -4735,6 +5059,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
@@ -4766,13 +5097,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
@@ -4816,7 +5145,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
@@ -4856,13 +5185,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
@@ -4874,7 +5201,6 @@ TickType_t uxReturn;
        }\r
 \r
 #endif /* configUSE_TASK_NOTIFICATIONS */\r
-\r
 /*-----------------------------------------------------------*/\r
 \r
 #if( configUSE_TASK_NOTIFICATIONS == 1 )\r
@@ -4908,6 +5234,41 @@ TickType_t uxReturn;
 #endif /* configUSE_TASK_NOTIFICATIONS */\r
 /*-----------------------------------------------------------*/\r
 \r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+       uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear )\r
+       {\r
+       TCB_t *pxTCB;\r
+       uint32_t ulReturn;\r
+\r
+               /* If null is passed in here then it is the calling task that is having\r
+               its notification state cleared. */\r
+               pxTCB = prvGetTCBFromHandle( xTask );\r
+\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       /* Return the notification as it was before the bits were cleared,\r
+                       then clear the bit mask. */\r
+                       ulReturn = pxCurrentTCB->ulNotifiedValue;\r
+                       pxTCB->ulNotifiedValue &= ~ulBitsToClear;\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               return ulReturn;\r
+       }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )\r
+\r
+       uint32_t ulTaskGetIdleRunTimeCounter( void )\r
+       {\r
+               return xIdleTaskHandle->ulRunTimeCounter;\r
+       }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
 \r
 static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, const BaseType_t xCanBlockIndefinitely )\r
 {\r
@@ -4929,7 +5290,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
@@ -5033,12 +5394,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