]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Source / tasks.c
index 74edf06e1f6598dd08fbe006488707dd4daac153..426ee2d591f9460d0b848d04ad1493128306ebb4 100644 (file)
@@ -1,60 +1,64 @@
 /*\r
-    FreeRTOS V8.1.2 - 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
@@ -117,7 +121,7 @@ functions but without including stdio.h here. */
 /* Value that can be assigned to the eNotifyState member of the TCB. */\r
 typedef enum\r
 {\r
-       eNotWaitingNotification,\r
+       eNotWaitingNotification = 0,\r
        eWaitingNotification,\r
        eNotified\r
 } eNotifyValue;\r
@@ -133,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
@@ -163,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
@@ -179,8 +188,8 @@ typedef struct tskTaskControlBlock
        #endif\r
 \r
        #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
-               uint32_t ulNotifiedValue;\r
-               eNotifyValue eNotifyState;\r
+               volatile uint32_t ulNotifiedValue;\r
+               volatile eNotifyValue eNotifyState;\r
        #endif\r
 \r
 } tskTCB;\r
@@ -378,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
@@ -543,9 +552,10 @@ BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcN
 {\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
@@ -553,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
@@ -567,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
@@ -576,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
@@ -1080,8 +1102,8 @@ TCB_t * pxNewTCB;
 \r
                uxSavedInterruptState = portSET_INTERRUPT_MASK_FROM_ISR();\r
                {\r
-                       /* If null is passed in here then we are changing the\r
-                       priority of the calling function. */\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
@@ -1743,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
@@ -1774,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
@@ -2373,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
@@ -2384,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
@@ -2864,6 +2887,15 @@ 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
@@ -2880,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
@@ -3222,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
@@ -3235,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
@@ -3309,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
@@ -3323,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
@@ -3371,15 +3459,23 @@ 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 == ( UBaseType_t ) 0 )\r
                                {\r
-                                       /* A task can only have an inhertied priority if it holds\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
@@ -3510,7 +3606,7 @@ TCB_t *pxTCB;
 \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; x++ )\r
+               for( x = strlen( pcBuffer ); x < ( configMAX_TASK_NAME_LEN - 1 ); x++ )\r
                {\r
                        pcBuffer[ x ] = ' ';\r
                }\r
@@ -3578,22 +3674,22 @@ 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
                                /* Write the task name to the string, padding with spaces so it\r
@@ -3601,7 +3697,7 @@ TCB_t *pxTCB;
                                pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );\r
 \r
                                /* Write the rest of the string. */\r
-                               sprintf( pcWriteBuffer, "\t\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
+                               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
@@ -3685,22 +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
-                                               /* 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
                                                #ifdef portLU_PRINTF_SPECIFIER_REQUIRED\r
                                                {\r
-                                                       sprintf( pcWriteBuffer, "\t\t%lu\t\t%lu%%\r\n", 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, "\t\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 );\r
                                                }\r
                                                #endif\r
                                        }\r
@@ -3710,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
@@ -3787,7 +3883,7 @@ TickType_t uxReturn;
                                /* Mark this task as waiting for a notification. */\r
                                pxCurrentTCB->eNotifyState = eWaitingNotification;\r
 \r
-                               if( xTicksToWait > 0 )\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
@@ -3856,7 +3952,7 @@ TickType_t uxReturn;
                {\r
                        ulReturn = pxCurrentTCB->ulNotifiedValue;\r
 \r
-                       if( ulReturn != 0 )\r
+                       if( ulReturn != 0UL )\r
                        {\r
                                if( xClearCountOnExit != pdFALSE )\r
                                {\r
@@ -3884,7 +3980,7 @@ TickType_t uxReturn;
 \r
 #if( configUSE_TASK_NOTIFICATIONS == 1 )\r
 \r
-       BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, BaseType_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait )\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
@@ -3902,7 +3998,7 @@ TickType_t uxReturn;
                                /* Mark this task as waiting for a notification. */\r
                                pxCurrentTCB->eNotifyState = eWaitingNotification;\r
 \r
-                               if( xTicksToWait > 0 )\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
@@ -4005,7 +4101,7 @@ TickType_t uxReturn;
 \r
 #if( configUSE_TASK_NOTIFICATIONS == 1 )\r
 \r
-       BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction )\r
+       BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue )\r
        {\r
        TCB_t * pxTCB;\r
        eNotifyValue eOriginalNotifyState;\r
@@ -4016,6 +4112,11 @@ TickType_t uxReturn;
 \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
@@ -4046,7 +4147,7 @@ TickType_t uxReturn;
                                        }\r
                                        break;\r
 \r
-                               default :\r
+                               case eNoAction:\r
                                        /* The task is being notified without its notify value being\r
                                        updated. */\r
                                        break;\r
@@ -4067,7 +4168,7 @@ TickType_t uxReturn;
                                {\r
                                        /* The notified task has a priority above the currently\r
                                        executing task so a yield is required. */\r
-                                       portYIELD_WITHIN_API();\r
+                                       taskYIELD_IF_USING_PREEMPTION();\r
                                }\r
                                else\r
                                {\r
@@ -4150,7 +4251,7 @@ TickType_t uxReturn;
                                        }\r
                                        break;\r
 \r
-                               default :\r
+                               case eNoAction :\r
                                        /* The task is being notified without its notify value being\r
                                        updated. */\r
                                        break;\r
@@ -4199,6 +4300,87 @@ TickType_t uxReturn;
 #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