]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Source / tasks.c
index 28d1c96326c9c765fbbc6679faed28a2768350ee..426ee2d591f9460d0b848d04ad1493128306ebb4 100644 (file)
@@ -1,60 +1,64 @@
 /*\r
-    FreeRTOS V8.1.0 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+    FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS provides completely free yet professionally developed,    *\r
-     *    robust, strictly quality controlled, supported, and cross          *\r
-     *    platform software that has become a de facto standard.             *\r
-     *                                                                       *\r
-     *    Help yourself get started quickly and support the FreeRTOS         *\r
-     *    project by purchasing a FreeRTOS tutorial book, reference          *\r
-     *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
-     *                                                                       *\r
-     *    Thank you!                                                         *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
     This file is part of the FreeRTOS distribution.\r
 \r
     FreeRTOS is free software; you can redistribute it and/or modify it under\r
     the terms of the GNU General Public License (version 2) as published by the\r
     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
 \r
+    ***************************************************************************\r
     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
     >>!   obliged to provide the source code for proprietary components     !<<\r
     >>!   outside of the FreeRTOS kernel.                                   !<<\r
+    ***************************************************************************\r
 \r
     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
-    FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
+    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
     link: http://www.freertos.org/a00114.html\r
 \r
-    1 tab == 4 spaces!\r
-\r
     ***************************************************************************\r
      *                                                                       *\r
-     *    Having a problem?  Start by reading the FAQ "My application does   *\r
-     *    not run, what could be wrong?"                                     *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
      *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
      *                                                                       *\r
     ***************************************************************************\r
 \r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
 \r
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
 \r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
-    Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
-    licenses offer ticketed support, indemnification and middleware.\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\r
 \r
     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
     engineered and independently SIL3 certified version for use in safety and\r
@@ -84,6 +88,8 @@ header files above, but not in this file, in order to generate the correct
 privileged Vs unprivileged linkage and placement. */\r
 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
 \r
+/* Set configUSE_STATS_FORMATTING_FUNCTIONS to 2 to include the stats formatting\r
+functions but without including stdio.h here. */\r
 #if ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 )\r
        /* At the bottom of this file are two optional functions that can be used\r
        to generate human readable text from the raw data generated by the\r
@@ -112,6 +118,14 @@ privileged Vs unprivileged linkage and placement. */
        #define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()\r
 #endif\r
 \r
+/* Value that can be assigned to the eNotifyState member of the TCB. */\r
+typedef enum\r
+{\r
+       eNotWaitingNotification = 0,\r
+       eWaitingNotification,\r
+       eNotified\r
+} eNotifyValue;\r
+\r
 /*\r
  * Task control block.  A task control block (TCB) is allocated for each task,\r
  * and stores task state information, including a pointer to the task's context\r
@@ -123,6 +137,7 @@ typedef struct tskTaskControlBlock
 \r
        #if ( portUSING_MPU_WRAPPERS == 1 )\r
                xMPU_SETTINGS   xMPUSettings;           /*< The MPU settings are defined as part of the port layer.  THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */\r
+               BaseType_t              xUsingStaticallyAllocatedStack; /* Set to pdTRUE if the stack is a statically allocated array, and pdFALSE if the stack is dynamically allocated. */\r
        #endif\r
 \r
        ListItem_t                      xGenericListItem;       /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */\r
@@ -153,6 +168,10 @@ typedef struct tskTaskControlBlock
                TaskHookFunction_t pxTaskTag;\r
        #endif\r
 \r
+       #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )\r
+               void *pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];\r
+       #endif\r
+\r
        #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
                uint32_t                ulRunTimeCounter;       /*< Stores the amount of time the task has spent in the Running state. */\r
        #endif\r
@@ -168,6 +187,11 @@ typedef struct tskTaskControlBlock
                struct  _reent xNewLib_reent;\r
        #endif\r
 \r
+       #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
+               volatile uint32_t ulNotifiedValue;\r
+               volatile eNotifyValue eNotifyState;\r
+       #endif\r
+\r
 } tskTCB;\r
 \r
 /* The old tskTCB name is maintained above then typedefed to the new TCB_t name\r
@@ -226,8 +250,8 @@ PRIVILEGED_DATA static UBaseType_t uxTaskNumber                                     = ( UBaseType_t ) 0U;
 PRIVILEGED_DATA static volatile TickType_t xNextTaskUnblockTime                = portMAX_DELAY;\r
 \r
 /* Context switches are held pending while the scheduler is suspended.  Also,\r
-interrupts must not manipulate the xStateListItem of a TCB, or any of the\r
-lists the xStateListItem can be referenced from, if the scheduler is suspended.\r
+interrupts must not manipulate the xGenericListItem of a TCB, or any of the\r
+lists the xGenericListItem can be referenced from, if the scheduler is suspended.\r
 If an interrupt needs to unblock a task while the scheduler is suspended then it\r
 moves the task's event list item into the xPendingReadyList, ready for the\r
 kernel to move the task from the pending ready list into the real ready list\r
@@ -328,12 +352,12 @@ PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended  = ( UBaseType_t
        /* A port optimised version is provided, call it only if the TCB being reset\r
        is being referenced from a ready list.  If it is referenced from a delayed\r
        or suspended list then it won't be in a ready list. */\r
-       #define taskRESET_READY_PRIORITY( uxPriority )                                                                                                  \\r
-       {                                                                                                                                                                                               \\r
-               if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == 0 )                          \\r
-               {                                                                                                                                                                                       \\r
-                       portRESET_READY_PRIORITY( ( uxPriority ), ( uxTopReadyPriority ) );                                             \\r
-               }                                                                                                                                                                                       \\r
+       #define taskRESET_READY_PRIORITY( uxPriority )                                                                                                          \\r
+       {                                                                                                                                                                                                       \\r
+               if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == ( UBaseType_t ) 0 )  \\r
+               {                                                                                                                                                                                               \\r
+                       portRESET_READY_PRIORITY( ( uxPriority ), ( uxTopReadyPriority ) );                                                     \\r
+               }                                                                                                                                                                                               \\r
        }\r
 \r
 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
@@ -363,7 +387,7 @@ count overflows. */
  * the task.  It is inserted at the end of the list.\r
  */\r
 #define prvAddTaskToReadyList( pxTCB )                                                                                                                         \\r
-       traceMOVED_TASK_TO_READY_STATE( pxTCB )                                                                                                                 \\r
+       traceMOVED_TASK_TO_READY_STATE( pxTCB );                                                                                                                \\r
        taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority );                                                                                             \\r
        vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) )\r
 /*-----------------------------------------------------------*/\r
@@ -412,7 +436,9 @@ static void prvInitialiseTCBVariables( TCB_t * const pxTCB, const char * const p
  * currently in the Suspended state, or pdFALSE if the task referenced by xTask\r
  * is in any other state.\r
  */\r
-static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;\r
+#if ( INCLUDE_vTaskSuspend == 1 )\r
+       static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;\r
+#endif /* INCLUDE_vTaskSuspend */\r
 \r
 /*\r
  * Utility to ready all the lists used by the scheduler.  This is called\r
@@ -511,15 +537,25 @@ static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t *
  */\r
 static void prvResetNextTaskUnblockTime( void );\r
 \r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
+\r
+       /*\r
+        * Helper function used to pad task names with spaces when printing out\r
+        * human readable tables of task information.\r
+        */\r
+       static char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName );\r
+\r
+#endif\r
 /*-----------------------------------------------------------*/\r
 \r
 BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, const MemoryRegion_t * const xRegions ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
 {\r
 BaseType_t xReturn;\r
 TCB_t * pxNewTCB;\r
+StackType_t *pxTopOfStack;\r
 \r
        configASSERT( pxTaskCode );\r
-       configASSERT( ( ( uxPriority & ( ~portPRIVILEGE_BIT ) ) < configMAX_PRIORITIES ) );\r
+       configASSERT( ( ( uxPriority & ( UBaseType_t ) ( ~portPRIVILEGE_BIT ) ) < ( UBaseType_t ) configMAX_PRIORITIES ) );\r
 \r
        /* Allocate the memory required by the TCB and stack for the new task,\r
        checking that the allocation was successful. */\r
@@ -527,8 +563,6 @@ TCB_t * pxNewTCB;
 \r
        if( pxNewTCB != NULL )\r
        {\r
-               StackType_t *pxTopOfStack;\r
-\r
                #if( portUSING_MPU_WRAPPERS == 1 )\r
                        /* Should the task be created in privileged mode? */\r
                        BaseType_t xRunPrivileged;\r
@@ -541,6 +575,20 @@ TCB_t * pxNewTCB;
                                xRunPrivileged = pdFALSE;\r
                        }\r
                        uxPriority &= ~portPRIVILEGE_BIT;\r
+\r
+                       if( puxStackBuffer != NULL )\r
+                       {\r
+                               /* The application provided its own stack.  Note this so no\r
+                               attempt is made to delete the stack should that task be\r
+                               deleted. */\r
+                               pxNewTCB->xUsingStaticallyAllocatedStack = pdTRUE;\r
+                       }\r
+                       else\r
+                       {\r
+                               /* The stack was allocated dynamically.  Note this so it can be\r
+                               deleted again if the task is deleted. */\r
+                               pxNewTCB->xUsingStaticallyAllocatedStack = pdFALSE;\r
+                       }\r
                #endif /* portUSING_MPU_WRAPPERS == 1 */\r
 \r
                /* Calculate the top of stack address.  This depends on whether the\r
@@ -550,7 +598,7 @@ TCB_t * pxNewTCB;
                #if( portSTACK_GROWTH < 0 )\r
                {\r
                        pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - ( uint16_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 = ( 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
 \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
@@ -991,7 +1039,7 @@ TCB_t * pxNewTCB;
                                }\r
                        #endif\r
 \r
-                       else\r
+                       else /*lint !e525 Negative indentation is intended to make use of pre-processor clearer. */\r
                        {\r
                                /* If the task is not in any other state, it must be in the\r
                                Ready (including pending ready) state. */\r
@@ -1000,7 +1048,7 @@ TCB_t * pxNewTCB;
                }\r
 \r
                return eReturn;\r
-       }\r
+       } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */\r
 \r
 #endif /* INCLUDE_eTaskGetState */\r
 /*-----------------------------------------------------------*/\r
@@ -1027,6 +1075,46 @@ TCB_t * pxNewTCB;
 #endif /* INCLUDE_uxTaskPriorityGet */\r
 /*-----------------------------------------------------------*/\r
 \r
+#if ( INCLUDE_uxTaskPriorityGet == 1 )\r
+\r
+       UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask )\r
+       {\r
+       TCB_t *pxTCB;\r
+       UBaseType_t uxReturn, uxSavedInterruptState;\r
+\r
+               /* RTOS ports that support interrupt nesting have the concept of a\r
+               maximum system call (or maximum API call) interrupt priority.\r
+               Interrupts that are     above the maximum system call priority are keep\r
+               permanently enabled, even when the RTOS kernel is in a critical section,\r
+               but cannot make any calls to FreeRTOS API functions.  If configASSERT()\r
+               is defined in FreeRTOSConfig.h then\r
+               portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+               failure if a FreeRTOS API function is called from an interrupt that has\r
+               been assigned a priority above the configured maximum system call\r
+               priority.  Only FreeRTOS functions that end in FromISR can be called\r
+               from interrupts that have been assigned a priority at or (logically)\r
+               below the maximum system call interrupt priority.  FreeRTOS maintains a\r
+               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
+               portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+               uxSavedInterruptState = portSET_INTERRUPT_MASK_FROM_ISR();\r
+               {\r
+                       /* If null is passed in here then it is the priority of the calling\r
+                       task that is being queried. */\r
+                       pxTCB = prvGetTCBFromHandle( xTask );\r
+                       uxReturn = pxTCB->uxPriority;\r
+               }\r
+               portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptState );\r
+\r
+               return uxReturn;\r
+       }\r
+\r
+#endif /* INCLUDE_uxTaskPriorityGet */\r
+/*-----------------------------------------------------------*/\r
+\r
 #if ( INCLUDE_vTaskPrioritySet == 1 )\r
 \r
        void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority )\r
@@ -1610,8 +1698,8 @@ BaseType_t xAlreadyYielded = pdFALSE;
                                        ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
                                        prvAddTaskToReadyList( pxTCB );\r
 \r
-                                       /* If we have moved a task that has a priority higher than\r
-                                       the current task then we should yield. */\r
+                                       /* If the moved task has a priority higher than the current\r
+                                       task then a yield must be performed. */\r
                                        if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
                                        {\r
                                                xYieldPending = pdTRUE;\r
@@ -1677,11 +1765,11 @@ TickType_t xTaskGetTickCount( void )
 TickType_t xTicks;\r
 \r
        /* Critical section required if running on a 16 bit processor. */\r
-       taskENTER_CRITICAL();\r
+       portTICK_TYPE_ENTER_CRITICAL();\r
        {\r
                xTicks = xTickCount;\r
        }\r
-       taskEXIT_CRITICAL();\r
+       portTICK_TYPE_EXIT_CRITICAL();\r
 \r
        return xTicks;\r
 }\r
@@ -1708,11 +1796,11 @@ UBaseType_t uxSavedInterruptStatus;
        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
+       uxSavedInterruptStatus = portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR();\r
        {\r
                xReturn = xTickCount;\r
        }\r
-       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+       portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
 \r
        return xReturn;\r
 }\r
@@ -1728,7 +1816,7 @@ UBaseType_t uxTaskGetNumberOfTasks( void )
 \r
 #if ( INCLUDE_pcTaskGetTaskName == 1 )\r
 \r
-       char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery )\r
+       char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
        {\r
        TCB_t *pxTCB;\r
 \r
@@ -1880,7 +1968,7 @@ BaseType_t xSwitchRequired = pdFALSE;
                        /* See if this tick has made a timeout expire.  Tasks are stored in\r
                        the     queue in the order of their wake time - meaning once one task\r
                        has been found whose block time has not expired there is no need to\r
-                       look any further        down the list. */\r
+                       look any further down the list. */\r
                        if( xConstTickCount >= xNextTaskUnblockTime )\r
                        {\r
                                for( ;; )\r
@@ -2307,7 +2395,7 @@ TickType_t xTimeToWake;
                /* This function should not be called by application code hence the\r
                'Restricted' in its name.  It is not part of the public API.  It is\r
                designed for use by kernel code, and has special calling requirements -\r
-               it should be called from a critical section. */\r
+               it should be called with the scheduler suspended. */\r
 \r
 \r
                /* Place the event list item of the TCB in the appropriate event list.\r
@@ -2318,7 +2406,8 @@ TickType_t xTimeToWake;
 \r
                /* We must remove this task from the ready list before adding it to the\r
                blocked list as the same list item is used for both lists.  This\r
-               function is called form a critical section. */\r
+               function is called with the scheduler locked so interrupts will not\r
+               access the lists at the same time. */\r
                if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
                {\r
                        /* The current task must be in a ready list, so there is no need to\r
@@ -2391,6 +2480,20 @@ BaseType_t xReturn;
                xReturn = pdFALSE;\r
        }\r
 \r
+       #if( configUSE_TICKLESS_IDLE == 1 )\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 get 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
@@ -2784,6 +2887,22 @@ UBaseType_t x;
        }\r
        #endif /* portUSING_MPU_WRAPPERS */\r
 \r
+       #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\r
+       {\r
+               for( x = 0; x < ( UBaseType_t ) configNUM_THREAD_LOCAL_STORAGE_POINTERS; x++ )\r
+               {\r
+                       pxTCB->pvThreadLocalStoragePointers[ x ] = NULL;\r
+               }\r
+       }\r
+       #endif\r
+\r
+       #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
+       {\r
+               pxTCB->ulNotifiedValue = 0;\r
+               pxTCB->eNotifyState = eNotWaitingNotification;\r
+       }\r
+       #endif\r
+\r
        #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
        {\r
                /* Initialise this task's Newlib reent structure. */\r
@@ -2793,6 +2912,45 @@ UBaseType_t x;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\r
+\r
+       void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue )\r
+       {\r
+       TCB_t *pxTCB;\r
+\r
+               if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )\r
+               {\r
+                       pxTCB = prvGetTCBFromHandle( xTaskToSet );\r
+                       pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue;\r
+               }\r
+       }\r
+\r
+#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\r
+\r
+       void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex )\r
+       {\r
+       void *pvReturn = NULL;\r
+       TCB_t *pxTCB;\r
+\r
+               if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )\r
+               {\r
+                       pxTCB = prvGetTCBFromHandle( xTaskToQuery );\r
+                       pvReturn = pxTCB->pvThreadLocalStoragePointers[ xIndex ];\r
+               }\r
+               else\r
+               {\r
+                       pvReturn = NULL;\r
+               }\r
+\r
+               return pvReturn;\r
+       }\r
+\r
+#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */\r
+/*-----------------------------------------------------------*/\r
+\r
 #if ( portUSING_MPU_WRAPPERS == 1 )\r
 \r
        void vTaskAllocateMPURegions( TaskHandle_t xTaskToModify, const MemoryRegion_t * const xRegions )\r
@@ -2915,34 +3073,72 @@ static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t *
 {\r
 TCB_t *pxNewTCB;\r
 \r
-       /* Allocate space for the TCB.  Where the memory comes from depends on\r
-       the implementation of the port malloc function. */\r
-       pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
-\r
-       if( pxNewTCB != NULL )\r
+       /* If the stack grows down then allocate the stack then the TCB so the stack\r
+       does not grow into the TCB.  Likewise if the stack grows up then allocate\r
+       the TCB then the stack. */\r
+       #if( portSTACK_GROWTH > 0 )\r
        {\r
-               /* Allocate space for the stack used by the task being created.\r
-               The base of the stack memory stored in the TCB so the task can\r
-               be deleted later if required. */\r
-               pxNewTCB->pxStack = ( StackType_t * ) pvPortMallocAligned( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ), puxStackBuffer ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+               /* Allocate space for the TCB.  Where the memory comes from depends on\r
+               the implementation of the port malloc function. */\r
+               pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
 \r
-               if( pxNewTCB->pxStack == NULL )\r
+               if( pxNewTCB != NULL )\r
                {\r
-                       /* Could not allocate the stack.  Delete the allocated TCB. */\r
-                       vPortFree( pxNewTCB );\r
-                       pxNewTCB = NULL;\r
+                       /* Allocate space for the stack used by the task being created.\r
+                       The base of the stack memory stored in the TCB so the task can\r
+                       be deleted later if required. */\r
+                       pxNewTCB->pxStack = ( StackType_t * ) pvPortMallocAligned( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ), puxStackBuffer ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+\r
+                       if( pxNewTCB->pxStack == NULL )\r
+                       {\r
+                               /* Could not allocate the stack.  Delete the allocated TCB. */\r
+                               vPortFree( pxNewTCB );\r
+                               pxNewTCB = NULL;\r
+                       }\r
                }\r
-               else\r
+       }\r
+       #else /* portSTACK_GROWTH */\r
+       {\r
+       StackType_t *pxStack;\r
+\r
+               /* Allocate space for the stack used by the task being created. */\r
+               pxStack = ( StackType_t * ) pvPortMallocAligned( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ), puxStackBuffer ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+\r
+               if( pxStack != NULL )\r
                {\r
-                       /* Avoid dependency on memset() if it is not required. */\r
-                       #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+                       /* Allocate space for the TCB.  Where the memory comes from depends\r
+                       on the implementation of the port malloc function. */\r
+                       pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
+\r
+                       if( pxNewTCB != NULL )\r
                        {\r
-                               /* Just to help debugging. */\r
-                               ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( StackType_t ) );\r
+                               /* Store the stack location in the TCB. */\r
+                               pxNewTCB->pxStack = pxStack;\r
                        }\r
-                       #endif /* ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) ) */\r
+                       else\r
+                       {\r
+                               /* The stack cannot be used as the TCB was not created.  Free it\r
+                               again. */\r
+                               vPortFree( pxStack );\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       pxNewTCB = NULL;\r
                }\r
        }\r
+       #endif /* portSTACK_GROWTH */\r
+\r
+       if( pxNewTCB != NULL )\r
+       {\r
+               /* Avoid dependency on memset() if it is not required. */\r
+               #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+               {\r
+                       /* Just to help debugging. */\r
+                       ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( StackType_t ) );\r
+               }\r
+               #endif /* ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) ) */\r
+       }\r
 \r
        return pxNewTCB;\r
 }\r
@@ -3039,13 +3235,13 @@ TCB_t *pxNewTCB;
        {\r
        uint32_t ulCount = 0U;\r
 \r
-               while( *pucStackByte == tskSTACK_FILL_BYTE )\r
+               while( *pucStackByte == ( uint8_t ) tskSTACK_FILL_BYTE )\r
                {\r
                        pucStackByte -= portSTACK_GROWTH;\r
                        ulCount++;\r
                }\r
 \r
-               ulCount /= ( uint32_t ) sizeof( StackType_t );\r
+               ulCount /= ( uint32_t ) sizeof( StackType_t ); /*lint !e961 Casting is not redundant on smaller architectures. */\r
 \r
                return ( uint16_t ) ulCount;\r
        }\r
@@ -3097,7 +3293,22 @@ TCB_t *pxNewTCB;
                        _reclaim_reent( &( pxTCB->xNewLib_reent ) );\r
                }\r
                #endif /* configUSE_NEWLIB_REENTRANT */\r
-               vPortFreeAligned( pxTCB->pxStack );\r
+\r
+               #if( portUSING_MPU_WRAPPERS == 1 )\r
+               {\r
+                       /* Only free the stack if it was allocated dynamically in the first\r
+                       place. */\r
+                       if( pxTCB->xUsingStaticallyAllocatedStack == pdFALSE )\r
+                       {\r
+                               vPortFreeAligned( pxTCB->pxStack );\r
+                       }\r
+               }\r
+               #else\r
+               {\r
+                       vPortFreeAligned( pxTCB->pxStack );\r
+               }\r
+               #endif\r
+\r
                vPortFree( pxTCB );\r
        }\r
 \r
@@ -3110,9 +3321,8 @@ TCB_t *pxTCB;
 \r
        if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
        {\r
-               /* The new current delayed list is empty.  Set\r
-               xNextTaskUnblockTime to the maximum possible value so it is\r
-               extremely unlikely that the\r
+               /* The new current delayed list is empty.  Set xNextTaskUnblockTime to\r
+               the maximum possible value so it is     extremely unlikely that the\r
                if( xTickCount >= xNextTaskUnblockTime ) test will pass until\r
                there is an item in the delayed list. */\r
                xNextTaskUnblockTime = portMAX_DELAY;\r
@@ -3184,6 +3394,9 @@ TCB_t *pxTCB;
                locked then the mutex holder might now be NULL. */\r
                if( pxMutexHolder != NULL )\r
                {\r
+                       /* If the holder of the mutex has a priority below the priority of\r
+                       the task attempting to obtain the mutex then it will temporarily\r
+                       inherit the priority of the task attempting to obtain the mutex. */\r
                        if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )\r
                        {\r
                                /* Adjust the mutex holder state to account for its new\r
@@ -3198,8 +3411,8 @@ TCB_t *pxTCB;
                                        mtCOVERAGE_TEST_MARKER();\r
                                }\r
 \r
-                               /* If the task being modified is in the ready state it will need to\r
-                               be moved into a new list. */\r
+                               /* If the task being modified is in the ready state it will need\r
+                               to be moved into a new list. */\r
                                if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
                                {\r
                                        if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
@@ -3246,16 +3459,27 @@ TCB_t *pxTCB;
 \r
                if( pxMutexHolder != NULL )\r
                {\r
+                       /* A task can only have an inherited priority if it holds the mutex.\r
+                       If the mutex is held by a task then it cannot be given from an\r
+                       interrupt, and if a mutex is given by the holding task then it must\r
+                       be the running state task. */\r
+                       configASSERT( pxTCB == pxCurrentTCB );\r
+\r
                        configASSERT( pxTCB->uxMutexesHeld );\r
                        ( pxTCB->uxMutexesHeld )--;\r
 \r
+                       /* Has the holder of the mutex inherited the priority of another\r
+                       task? */\r
                        if( pxTCB->uxPriority != pxTCB->uxBasePriority )\r
                        {\r
                                /* Only disinherit if no other mutexes are held. */\r
-                               if( pxTCB->uxMutexesHeld == 0 )\r
+                               if( pxTCB->uxMutexesHeld == ( UBaseType_t ) 0 )\r
                                {\r
-                                       /* The holding task must be the running task to be able to give\r
-                                       the mutex back.  Remove the holding task from the ready list. */\r
+                                       /* A task can only have an inherited priority if it holds\r
+                                       the mutex.  If the mutex is held by a task then it cannot be\r
+                                       given from an interrupt, and if a mutex is given by the\r
+                                       holding task then it must be the running state task.  Remove\r
+                                       the     holding task from the ready     list. */\r
                                        if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
                                        {\r
                                                taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
@@ -3265,8 +3489,8 @@ TCB_t *pxTCB;
                                                mtCOVERAGE_TEST_MARKER();\r
                                        }\r
 \r
-                                       /* Disinherit the priority before adding the task into the new\r
-                                       ready list. */\r
+                                       /* Disinherit the priority before adding the task into the\r
+                                       new     ready list. */\r
                                        traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
                                        pxTCB->uxPriority = pxTCB->uxBasePriority;\r
 \r
@@ -3279,7 +3503,11 @@ TCB_t *pxTCB;
                                        /* Return true to indicate that a context switch is required.\r
                                        This is only actually required in the corner case whereby\r
                                        multiple mutexes were held and the mutexes were given back\r
-                                       in an order different to that in which they were taken. */\r
+                                       in an order different to that in which they were taken.\r
+                                       If a context switch did not occur when the first mutex was\r
+                                       returned, even if a task was waiting on it, then a context\r
+                                       switch should occur when the last mutex is returned whether\r
+                                       a task is waiting on it or not. */\r
                                        xReturn = pdTRUE;\r
                                }\r
                                else\r
@@ -3367,7 +3595,33 @@ TCB_t *pxTCB;
 #endif /* portCRITICAL_NESTING_IN_TCB */\r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
+\r
+       static char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName )\r
+       {\r
+       BaseType_t x;\r
+\r
+               /* Start by copying the entire string. */\r
+               strcpy( pcBuffer, pcTaskName );\r
+\r
+               /* Pad the end of the string with spaces to ensure columns line up when\r
+               printed out. */\r
+               for( x = strlen( pcBuffer ); x < ( configMAX_TASK_NAME_LEN - 1 ); x++ )\r
+               {\r
+                       pcBuffer[ x ] = ' ';\r
+               }\r
+\r
+               /* Terminate. */\r
+               pcBuffer[ x ] = 0x00;\r
+\r
+               /* Return the new end of string. */\r
+               return &( pcBuffer[ x ] );\r
+       }\r
+\r
+#endif /* ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
 \r
        void vTaskList( char * pcWriteBuffer )\r
        {\r
@@ -3420,25 +3674,30 @@ TCB_t *pxTCB;
                        {\r
                                switch( pxTaskStatusArray[ x ].eCurrentState )\r
                                {\r
-                               case eReady:            cStatus = tskREADY_CHAR;\r
-                                                                       break;\r
+                                       case eReady:            cStatus = tskREADY_CHAR;\r
+                                                                               break;\r
 \r
-                               case eBlocked:          cStatus = tskBLOCKED_CHAR;\r
-                                                                       break;\r
+                                       case eBlocked:          cStatus = tskBLOCKED_CHAR;\r
+                                                                               break;\r
 \r
-                               case eSuspended:        cStatus = tskSUSPENDED_CHAR;\r
-                                                                       break;\r
+                                       case eSuspended:        cStatus = tskSUSPENDED_CHAR;\r
+                                                                               break;\r
 \r
-                               case eDeleted:          cStatus = tskDELETED_CHAR;\r
-                                                                       break;\r
+                                       case eDeleted:          cStatus = tskDELETED_CHAR;\r
+                                                                               break;\r
 \r
-                               default:                        /* Should not get here, but it is included\r
-                                                                       to prevent static checking errors. */\r
-                                                                       cStatus = 0x00;\r
-                                                                       break;\r
+                                       default:                        /* Should not get here, but it is included\r
+                                                                               to prevent static checking errors. */\r
+                                                                               cStatus = 0x00;\r
+                                                                               break;\r
                                }\r
 \r
-                               sprintf( pcWriteBuffer, "%s\t\t%c\t%u\t%u\t%u\r\n", pxTaskStatusArray[ x ].pcTaskName, cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );\r
+                               /* Write the task name to the string, padding with spaces so it\r
+                               can be printed in tabular form more easily. */\r
+                               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
                        }\r
 \r
@@ -3451,10 +3710,10 @@ TCB_t *pxTCB;
                }\r
        }\r
 \r
-#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */\r
+#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */\r
 /*----------------------------------------------------------*/\r
 \r
-#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )\r
+#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
 \r
        void vTaskGetRunTimeStats( char *pcWriteBuffer )\r
        {\r
@@ -3522,17 +3781,22 @@ TCB_t *pxTCB;
                                        ulTotalRunTimeDiv100 has already been divided by 100. */\r
                                        ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;\r
 \r
+                                       /* Write the task name to the string, padding with\r
+                                       spaces so it can be printed in tabular form more\r
+                                       easily. */\r
+                                       pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );\r
+\r
                                        if( ulStatsAsPercentage > 0UL )\r
                                        {\r
                                                #ifdef portLU_PRINTF_SPECIFIER_REQUIRED\r
                                                {\r
-                                                       sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );\r
+                                                       sprintf( pcWriteBuffer, "\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );\r
                                                }\r
                                                #else\r
                                                {\r
                                                        /* sizeof( int ) == sizeof( long ) so a smaller\r
                                                        printf() library can be used. */\r
-                                                       sprintf( pcWriteBuffer, "%s\t\t%u\t\t%u%%\r\n", pxTaskStatusArray[ x ].pcTaskName, ( 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 );\r
                                                }\r
                                                #endif\r
                                        }\r
@@ -3542,13 +3806,13 @@ TCB_t *pxTCB;
                                                consumed less than 1% of the total run time. */\r
                                                #ifdef portLU_PRINTF_SPECIFIER_REQUIRED\r
                                                {\r
-                                                       sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );\r
+                                                       sprintf( pcWriteBuffer, "\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter );\r
                                                }\r
                                                #else\r
                                                {\r
                                                        /* sizeof( int ) == sizeof( long ) so a smaller\r
                                                        printf() library can be used. */\r
-                                                       sprintf( pcWriteBuffer, "%s\t\t%u\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );\r
+                                                       sprintf( pcWriteBuffer, "\t%u\t\t<1%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );\r
                                                }\r
                                                #endif\r
                                        }\r
@@ -3570,7 +3834,7 @@ TCB_t *pxTCB;
                }\r
        }\r
 \r
-#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */\r
+#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */\r
 /*-----------------------------------------------------------*/\r
 \r
 TickType_t uxTaskResetEventItemValue( void )\r
@@ -3587,9 +3851,9 @@ TickType_t uxReturn;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void *pvTaskIncrementMutexHeldCount( void )\r
-{\r
-       #if ( configUSE_MUTEXES == 1 )\r
+#if ( configUSE_MUTEXES == 1 )\r
+\r
+       void *pvTaskIncrementMutexHeldCount( void )\r
        {\r
                /* If xSemaphoreCreateMutex() is called before any tasks have been created\r
                then pxCurrentTCB will be NULL. */\r
@@ -3600,10 +3864,523 @@ void *pvTaskIncrementMutexHeldCount( void )
 \r
                return pxCurrentTCB;\r
        }\r
-       #endif\r
-}\r
+\r
+#endif /* configUSE_MUTEXES */\r
 /*-----------------------------------------------------------*/\r
 \r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+       uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait )\r
+       {\r
+       TickType_t xTimeToWake;\r
+       uint32_t ulReturn;\r
+\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       /* Only block if the notification count is not already non-zero. */\r
+                       if( pxCurrentTCB->ulNotifiedValue == 0UL )\r
+                       {\r
+                               /* Mark this task as waiting for a notification. */\r
+                               pxCurrentTCB->eNotifyState = eWaitingNotification;\r
+\r
+                               if( xTicksToWait > ( TickType_t ) 0 )\r
+                               {\r
+                                       /* The task is going to block.  First it must be removed\r
+                                       from the ready list. */\r
+                                       if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+                                       {\r
+                                               /* The current task must be in a ready list, so there is\r
+                                               no need to check, and the port reset macro can be called\r
+                                               directly. */\r
+                                               portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+\r
+                                       #if ( INCLUDE_vTaskSuspend == 1 )\r
+                                       {\r
+                                               if( xTicksToWait == portMAX_DELAY )\r
+                                               {\r
+                                                       /* Add the task to the suspended task list instead\r
+                                                       of a delayed task list to ensure the task is not\r
+                                                       woken by a timing event.  It will block\r
+                                                       indefinitely. */\r
+                                                       vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       /* Calculate the time at which the task should be\r
+                                                       woken if no notification events occur.  This may\r
+                                                       overflow but this doesn't matter, the scheduler will\r
+                                                       handle it. */\r
+                                                       xTimeToWake = xTickCount + xTicksToWait;\r
+                                                       prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+                                               }\r
+                                       }\r
+                                       #else /* INCLUDE_vTaskSuspend */\r
+                                       {\r
+                                                       /* Calculate the time at which the task should be\r
+                                                       woken if the event does not occur.  This may\r
+                                                       overflow but this doesn't matter, the scheduler will\r
+                                                       handle it. */\r
+                                                       xTimeToWake = xTickCount + xTicksToWait;\r
+                                                       prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+                                       }\r
+                                       #endif /* INCLUDE_vTaskSuspend */\r
+\r
+                                       /* All ports are written to allow a yield in a critical\r
+                                       section (some will yield immediately, others wait until the\r
+                                       critical section exits) - but it is not something that\r
+                                       application code should ever do. */\r
+                                       portYIELD_WITHIN_API();\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       ulReturn = pxCurrentTCB->ulNotifiedValue;\r
+\r
+                       if( ulReturn != 0UL )\r
+                       {\r
+                               if( xClearCountOnExit != pdFALSE )\r
+                               {\r
+                                       pxCurrentTCB->ulNotifiedValue = 0UL;\r
+                               }\r
+                               else\r
+                               {\r
+                                       ( pxCurrentTCB->ulNotifiedValue )--;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+\r
+                       pxCurrentTCB->eNotifyState = eNotWaitingNotification;\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               return ulReturn;\r
+       }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+       BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait )\r
+       {\r
+       TickType_t xTimeToWake;\r
+       BaseType_t xReturn;\r
+\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       /* Only block if a notification is not already pending. */\r
+                       if( pxCurrentTCB->eNotifyState != eNotified )\r
+                       {\r
+                               /* Clear bits in the task's notification value as bits may get\r
+                               set     by the notifying task or interrupt.  This can be used to\r
+                               clear the value to zero. */\r
+                               pxCurrentTCB->ulNotifiedValue &= ~ulBitsToClearOnEntry;\r
+\r
+                               /* Mark this task as waiting for a notification. */\r
+                               pxCurrentTCB->eNotifyState = eWaitingNotification;\r
+\r
+                               if( xTicksToWait > ( TickType_t ) 0 )\r
+                               {\r
+                                       /* The task is going to block.  First it must be removed\r
+                                       from the        ready list. */\r
+                                       if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+                                       {\r
+                                               /* The current task must be in a ready list, so there is\r
+                                               no need to check, and the port reset macro can be called\r
+                                               directly. */\r
+                                               portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+\r
+                                       #if ( INCLUDE_vTaskSuspend == 1 )\r
+                                       {\r
+                                               if( xTicksToWait == portMAX_DELAY )\r
+                                               {\r
+                                                       /* Add the task to the suspended task list instead\r
+                                                       of a delayed task list to ensure the task is not\r
+                                                       woken by a timing event.  It will block\r
+                                                       indefinitely. */\r
+                                                       vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       /* Calculate the time at which the task should be\r
+                                                       woken if no notification events occur.  This may\r
+                                                       overflow but this doesn't matter, the scheduler will\r
+                                                       handle it. */\r
+                                                       xTimeToWake = xTickCount + xTicksToWait;\r
+                                                       prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+                                               }\r
+                                       }\r
+                                       #else /* INCLUDE_vTaskSuspend */\r
+                                       {\r
+                                                       /* Calculate the time at which the task should be\r
+                                                       woken if the event does not occur.  This may\r
+                                                       overflow but this doesn't matter, the scheduler will\r
+                                                       handle it. */\r
+                                                       xTimeToWake = xTickCount + xTicksToWait;\r
+                                                       prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+                                       }\r
+                                       #endif /* INCLUDE_vTaskSuspend */\r
+\r
+                                       /* All ports are written to allow a yield in a critical\r
+                                       section (some will yield immediately, others wait until the\r
+                                       critical section exits) - but it is not something that\r
+                                       application code should ever do. */\r
+                                       portYIELD_WITHIN_API();\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       if( pulNotificationValue != NULL )\r
+                       {\r
+                               /* Output the current notification value, which may or may not\r
+                               have changed. */\r
+                               *pulNotificationValue = pxCurrentTCB->ulNotifiedValue;\r
+                       }\r
+\r
+                       /* If eNotifyValue is set then either the task never entered the\r
+                       blocked state (because a notification was already pending) or the\r
+                       task unblocked because of a notification.  Otherwise the task\r
+                       unblocked because of a timeout. */\r
+                       if( pxCurrentTCB->eNotifyState == eWaitingNotification )\r
+                       {\r
+                               /* A notification was not received. */\r
+                               xReturn = pdFALSE;\r
+                       }\r
+                       else\r
+                       {\r
+                               /* A notification was already pending or a notification was\r
+                               received while the task was waiting. */\r
+                               pxCurrentTCB->ulNotifiedValue &= ~ulBitsToClearOnExit;\r
+                               xReturn = pdTRUE;\r
+                       }\r
+\r
+                       pxCurrentTCB->eNotifyState = eNotWaitingNotification;\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+       BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue )\r
+       {\r
+       TCB_t * pxTCB;\r
+       eNotifyValue eOriginalNotifyState;\r
+       BaseType_t xReturn = pdPASS;\r
+\r
+               configASSERT( xTaskToNotify );\r
+               pxTCB = ( TCB_t * ) xTaskToNotify;\r
+\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       if( pulPreviousNotificationValue != NULL )\r
+                       {\r
+                               *pulPreviousNotificationValue = pxTCB->ulNotifiedValue;\r
+                       }\r
+\r
+                       eOriginalNotifyState = pxTCB->eNotifyState;\r
+\r
+                       pxTCB->eNotifyState = eNotified;\r
+\r
+                       switch( eAction )\r
+                       {\r
+                               case eSetBits   :\r
+                                       pxTCB->ulNotifiedValue |= ulValue;\r
+                                       break;\r
+\r
+                               case eIncrement :\r
+                                       ( pxTCB->ulNotifiedValue )++;\r
+                                       break;\r
+\r
+                               case eSetValueWithOverwrite     :\r
+                                       pxTCB->ulNotifiedValue = ulValue;\r
+                                       break;\r
+\r
+                               case eSetValueWithoutOverwrite :\r
+                                       if( eOriginalNotifyState != eNotified )\r
+                                       {\r
+                                               pxTCB->ulNotifiedValue = ulValue;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               /* The value could not be written to the task. */\r
+                                               xReturn = pdFAIL;\r
+                                       }\r
+                                       break;\r
+\r
+                               case eNoAction:\r
+                                       /* The task is being notified without its notify value being\r
+                                       updated. */\r
+                                       break;\r
+                       }\r
+\r
+\r
+                       /* If the task is in the blocked state specifically to wait for a\r
+                       notification then unblock it now. */\r
+                       if( eOriginalNotifyState == eWaitingNotification )\r
+                       {\r
+                               ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
+                               prvAddTaskToReadyList( pxTCB );\r
+\r
+                               /* The task should not have been on an event list. */\r
+                               configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\r
+\r
+                               if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+                               {\r
+                                       /* The notified task has a priority above the currently\r
+                                       executing task so a yield is required. */\r
+                                       taskYIELD_IF_USING_PREEMPTION();\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+       BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken )\r
+       {\r
+       TCB_t * pxTCB;\r
+       eNotifyValue eOriginalNotifyState;\r
+       BaseType_t xReturn = pdPASS;\r
+       UBaseType_t uxSavedInterruptStatus;\r
+\r
+               configASSERT( xTaskToNotify );\r
+\r
+               /* RTOS ports that support interrupt nesting have the concept of a\r
+               maximum system call (or maximum API call) interrupt priority.\r
+               Interrupts that are     above the maximum system call priority are keep\r
+               permanently enabled, even when the RTOS kernel is in a critical section,\r
+               but cannot make any calls to FreeRTOS API functions.  If configASSERT()\r
+               is defined in FreeRTOSConfig.h then\r
+               portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+               failure if a FreeRTOS API function is called from an interrupt that has\r
+               been assigned a priority above the configured maximum system call\r
+               priority.  Only FreeRTOS functions that end in FromISR can be called\r
+               from interrupts that have been assigned a priority at or (logically)\r
+               below the maximum system call interrupt priority.  FreeRTOS maintains a\r
+               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
+               portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+               pxTCB = ( TCB_t * ) xTaskToNotify;\r
+\r
+               uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+               {\r
+                       eOriginalNotifyState = pxTCB->eNotifyState;\r
+\r
+                       pxTCB->eNotifyState = eNotified;\r
+\r
+                       switch( eAction )\r
+                       {\r
+                               case eSetBits   :\r
+                                       pxTCB->ulNotifiedValue |= ulValue;\r
+                                       break;\r
+\r
+                               case eIncrement :\r
+                                       ( pxTCB->ulNotifiedValue )++;\r
+                                       break;\r
+\r
+                               case eSetValueWithOverwrite     :\r
+                                       pxTCB->ulNotifiedValue = ulValue;\r
+                                       break;\r
+\r
+                               case eSetValueWithoutOverwrite :\r
+                                       if( eOriginalNotifyState != eNotified )\r
+                                       {\r
+                                               pxTCB->ulNotifiedValue = ulValue;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               /* The value could not be written to the task. */\r
+                                               xReturn = pdFAIL;\r
+                                       }\r
+                                       break;\r
+\r
+                               case eNoAction :\r
+                                       /* The task is being notified without its notify value being\r
+                                       updated. */\r
+                                       break;\r
+                       }\r
+\r
+\r
+                       /* If the task is in the blocked state specifically to wait for a\r
+                       notification then unblock it now. */\r
+                       if( eOriginalNotifyState == eWaitingNotification )\r
+                       {\r
+                               /* The task should not have been on an event list. */\r
+                               configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\r
+\r
+                               if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+                               {\r
+                                       ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
+                                       prvAddTaskToReadyList( pxTCB );\r
+                               }\r
+                               else\r
+                               {\r
+                                       /* The delayed and ready lists cannot be accessed, so hold\r
+                                       this task pending until the scheduler is resumed. */\r
+                                       vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+                               }\r
+\r
+                               if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+                               {\r
+                                       /* The notified task has a priority above the currently\r
+                                       executing task so a yield is required. */\r
+                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                       {\r
+                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+               }\r
+               portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+       void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken )\r
+       {\r
+       TCB_t * pxTCB;\r
+       eNotifyValue eOriginalNotifyState;\r
+       UBaseType_t uxSavedInterruptStatus;\r
+\r
+               configASSERT( xTaskToNotify );\r
+\r
+               /* RTOS ports that support interrupt nesting have the concept of a\r
+               maximum system call (or maximum API call) interrupt priority.\r
+               Interrupts that are     above the maximum system call priority are keep\r
+               permanently enabled, even when the RTOS kernel is in a critical section,\r
+               but cannot make any calls to FreeRTOS API functions.  If configASSERT()\r
+               is defined in FreeRTOSConfig.h then\r
+               portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+               failure if a FreeRTOS API function is called from an interrupt that has\r
+               been assigned a priority above the configured maximum system call\r
+               priority.  Only FreeRTOS functions that end in FromISR can be called\r
+               from interrupts that have been assigned a priority at or (logically)\r
+               below the maximum system call interrupt priority.  FreeRTOS maintains a\r
+               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
+               portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+               pxTCB = ( TCB_t * ) xTaskToNotify;\r
+\r
+               uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+               {\r
+                       eOriginalNotifyState = pxTCB->eNotifyState;\r
+                       pxTCB->eNotifyState = eNotified;\r
+\r
+                       /* 'Giving' is equivalent to incrementing a count in a counting\r
+                       semaphore. */\r
+                       ( pxTCB->ulNotifiedValue )++;\r
+\r
+                       /* If the task is in the blocked state specifically to wait for a\r
+                       notification then unblock it now. */\r
+                       if( eOriginalNotifyState == eWaitingNotification )\r
+                       {\r
+                               /* The task should not have been on an event list. */\r
+                               configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\r
+\r
+                               if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+                               {\r
+                                       ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
+                                       prvAddTaskToReadyList( pxTCB );\r
+                               }\r
+                               else\r
+                               {\r
+                                       /* The delayed and ready lists cannot be accessed, so hold\r
+                                       this task pending until the scheduler is resumed. */\r
+                                       vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+                               }\r
+\r
+                               if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+                               {\r
+                                       /* The notified task has a priority above the currently\r
+                                       executing task so a yield is required. */\r
+                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                       {\r
+                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+               }\r
+               portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+       }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+\r
 #ifdef FREERTOS_MODULE_TEST\r
        #include "tasks_test_access_functions.h"\r
 #endif\r