]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
Changes to core code and port layer:
[freertos] / FreeRTOS / Source / tasks.c
index 47f38bea92840c45cc3efbecd462dd9cc4a20952..f101e258eb422d23e5f9bfa0dbb3782e3b7b3cd2 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
+    FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
@@ -117,6 +117,26 @@ functions but without including stdio.h here. */
  */\r
 #define tskSTACK_FILL_BYTE     ( 0xa5U )\r
 \r
+/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using\r
+dynamically allocated RAM, in which case when any task is deleted it is known\r
+that both the task's stack and TCB need to be freed.  Sometimes the\r
+FreeRTOSConfig.h settings only allow a task to be created using statically\r
+allocated RAM, in which case when any task is deleted it is known that neither\r
+the task's stack or TCB should be freed.  Sometimes the FreeRTOSConfig.h\r
+settings allow a task to be created using either statically or dynamically\r
+allocated RAM, in which case a member of the TCB is used to record whether the\r
+stack and/or TCB were allocated statically or dynamically, so when a task is\r
+deleted the RAM that was allocated dynamically is freed again and no attempt is\r
+made to free the RAM that was allocated statically.\r
+tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a\r
+task to be created using either statically or dynamically allocated RAM.  Note\r
+that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with\r
+a statically allocated stack and a dynamically allocated TCB. */\r
+#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE ( ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) || ( portUSING_MPU_WRAPPERS == 1 ) )\r
+#define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB                 ( ( uint8_t ) 0 )\r
+#define tskSTATICALLY_ALLOCATED_STACK_ONLY                     ( ( uint8_t ) 1 )\r
+#define tskSTATICALLY_ALLOCATED_STACK_AND_TCB          ( ( uint8_t ) 2 )\r
+\r
 /*\r
  * Macros used by vListTask to indicate which state a task is in.\r
  */\r
@@ -330,8 +350,10 @@ typedef struct tskTaskControlBlock
                volatile uint8_t ucNotifyState;\r
        #endif\r
 \r
-       #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
-               uint8_t ucStaticallyAllocated; /* Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */\r
+       /* See the comments above the definition of\r
+       tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */\r
+       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )\r
+               uint8_t ucStaticallyAllocated;          /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */\r
        #endif\r
 \r
        #if( INCLUDE_xTaskAbortDelay == 1 )\r
@@ -413,7 +435,7 @@ PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended    = ( UBaseType_t
 #endif\r
 \r
 #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
-       extern void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint16_t *pusIdleTaskStackSize );\r
+       extern void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );\r
 #endif\r
 \r
 /* File private functions. --------------------------------*/\r
@@ -490,7 +512,7 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, const BaseT
  * Searches pxList for a task with name pcNameToQuery - returning a handle to\r
  * the task if it is found, or NULL if the task is not found.\r
  */\r
-#if ( INCLUDE_xTaskGetTaskHandle == 1 )\r
+#if ( INCLUDE_xTaskGetHandle == 1 )\r
 \r
        static TCB_t *prvSearchForNameWithinSingleList( List_t *pxList, const char pcNameToQuery[] ) PRIVILEGED_FUNCTION;\r
 \r
@@ -542,7 +564,14 @@ static void prvResetNextTaskUnblockTime( void );
  * Called after a Task_t structure has been allocated either statically or\r
  * dynamically to fill in the structure's members.\r
  */\r
-static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+static void prvInitialiseNewTask(      TaskFunction_t pxTaskCode,\r
+                                                                       const char * const pcName,\r
+                                                                       const uint32_t ulStackDepth,\r
+                                                                       void * const pvParameters,\r
+                                                                       UBaseType_t uxPriority,\r
+                                                                       TaskHandle_t * const pxCreatedTask,\r
+                                                                       TCB_t *pxNewTCB,\r
+                                                                       const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
 \r
 /*\r
  * Called after a new task has been created and initialised to place the task\r
@@ -554,10 +583,16 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
 \r
 #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
 \r
-       BaseType_t xTaskCreateStatic( 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, StaticTask_t * const pxTaskBuffer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+       TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,\r
+                                                                       const char * const pcName,\r
+                                                                       const uint32_t ulStackDepth,\r
+                                                                       void * const pvParameters,\r
+                                                                       UBaseType_t uxPriority,\r
+                                                                       StackType_t * const puxStackBuffer,\r
+                                                                       StaticTask_t * const pxTaskBuffer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
        {\r
        TCB_t *pxNewTCB;\r
-       BaseType_t xReturn;\r
+       TaskHandle_t xReturn;\r
 \r
                configASSERT( puxStackBuffer != NULL );\r
                configASSERT( pxTaskBuffer != NULL );\r
@@ -569,21 +604,20 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                        pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\r
                        pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;\r
 \r
-                       #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\r
+                       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )\r
                        {\r
                                /* Tasks can be created statically or dynamically, so note this\r
                                task was created statically in case the task is later deleted. */\r
-                               pxNewTCB->ucStaticallyAllocated = pdTRUE;\r
+                               pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
                        #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
 \r
-                       prvInitialiseNewTask( pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB );\r
+                       prvInitialiseNewTask( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &xReturn, pxNewTCB, NULL );\r
                        prvAddNewTaskToReadyList( pxNewTCB );\r
-                       xReturn = pdPASS;\r
                }\r
                else\r
                {\r
-                       xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;\r
+                       xReturn = NULL;\r
                }\r
 \r
                return xReturn;\r
@@ -592,9 +626,59 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
 #endif /* SUPPORT_STATIC_ALLOCATION */\r
 /*-----------------------------------------------------------*/\r
 \r
+#if( portUSING_MPU_WRAPPERS == 1 )\r
+\r
+       BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask )\r
+       {\r
+       TCB_t *pxNewTCB;\r
+       BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;\r
+\r
+               configASSERT( pxTaskDefinition->puxStackBuffer );\r
+\r
+               if( pxTaskDefinition->puxStackBuffer != NULL )\r
+               {\r
+                       /* Allocate space for the TCB.  Where the memory comes from depends\r
+                       on the implementation of the port malloc function and whether or\r
+                       not static allocation is being used. */\r
+                       pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
+\r
+                       if( pxNewTCB != NULL )\r
+                       {\r
+                               /* Store the stack location in the TCB. */\r
+                               pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;\r
+\r
+                               /* Tasks can be created statically or dynamically, so note\r
+                               this task had a statically allocated stack in case it is\r
+                               later deleted.  The TCB was allocated dynamically. */\r
+                               pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_ONLY;\r
+\r
+                               prvInitialiseNewTask(   pxTaskDefinition->pvTaskCode,\r
+                                                                               pxTaskDefinition->pcName,\r
+                                                                               ( uint32_t ) pxTaskDefinition->usStackDepth,\r
+                                                                               pxTaskDefinition->pvParameters,\r
+                                                                               pxTaskDefinition->uxPriority,\r
+                                                                               pxCreatedTask, pxNewTCB,\r
+                                                                               pxTaskDefinition->xRegions );\r
+\r
+                               prvAddNewTaskToReadyList( pxNewTCB );\r
+                               xReturn = pdPASS;\r
+                       }\r
+               }\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif /* portUSING_MPU_WRAPPERS */\r
+/*-----------------------------------------------------------*/\r
+\r
 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\r
 \r
-       BaseType_t xTaskCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+       BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,\r
+                                                       const char * const pcName,\r
+                                                       const uint16_t usStackDepth,\r
+                                                       void * const pvParameters,\r
+                                                       UBaseType_t uxPriority,\r
+                                                       TaskHandle_t * const pxCreatedTask ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
        {\r
        TCB_t *pxNewTCB;\r
        BaseType_t xReturn;\r
@@ -657,15 +741,15 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
 \r
                if( pxNewTCB != NULL )\r
                {\r
-                       #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+                       #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )\r
                        {\r
                                /* Tasks can be created statically or dynamically, so note this\r
                                task was created dynamically in case it is later deleted. */\r
-                               pxNewTCB->ucStaticallyAllocated = pdFALSE;\r
+                               pxNewTCB->ucStaticallyAllocated = tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
                        #endif /* configSUPPORT_STATIC_ALLOCATION */\r
 \r
-                       prvInitialiseNewTask( pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB );\r
+                       prvInitialiseNewTask( pxTaskCode, pcName, ( uint32_t ) usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB, NULL );\r
                        prvAddNewTaskToReadyList( pxNewTCB );\r
                        xReturn = pdPASS;\r
                }\r
@@ -680,7 +764,14 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, TCB_t *pxNewTCB ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+static void prvInitialiseNewTask(      TaskFunction_t pxTaskCode,\r
+                                                                       const char * const pcName,\r
+                                                                       const uint32_t ulStackDepth,\r
+                                                                       void * const pvParameters,\r
+                                                                       UBaseType_t uxPriority,\r
+                                                                       TaskHandle_t * const pxCreatedTask,\r
+                                                                       TCB_t *pxNewTCB,\r
+                                                                       const MemoryRegion_t * const xRegions ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
 {\r
 StackType_t *pxTopOfStack;\r
 UBaseType_t x;\r
@@ -703,7 +794,7 @@ UBaseType_t x;
        #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
        {\r
                /* Fill the stack with a known value to assist debugging. */\r
-               ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( StackType_t ) );\r
+               ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) ulStackDepth * sizeof( StackType_t ) );\r
        }\r
        #endif /* ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) ) */\r
 \r
@@ -713,7 +804,7 @@ UBaseType_t x;
        by the port. */\r
        #if( portSTACK_GROWTH < 0 )\r
        {\r
-               pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - ( uint16_t ) 1 );\r
+               pxTopOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 );\r
                pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); /*lint !e923 MISRA exception.  Avoiding casts between pointers and integers is not practical.  Size differences accounted for using portPOINTER_SIZE_TYPE type. */\r
 \r
                /* Check the alignment of the calculated top of stack is correct. */\r
@@ -728,7 +819,7 @@ UBaseType_t x;
 \r
                /* The other extreme of the stack space is required if stack checking is\r
                performed. */\r
-               pxNewTCB->pxEndOfStack = pxNewTCB->pxStack + ( usStackDepth - ( uint16_t ) 1 );\r
+               pxNewTCB->pxEndOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 );\r
        }\r
        #endif /* portSTACK_GROWTH */\r
 \r
@@ -804,7 +895,12 @@ UBaseType_t x;
 \r
        #if ( portUSING_MPU_WRAPPERS == 1 )\r
        {\r
-               vPortStoreTaskMPUSettings( &( pxNewTCB->xMPUSettings ), xRegions, pxNewTCB->pxStack, usStackDepth );\r
+               vPortStoreTaskMPUSettings( &( pxNewTCB->xMPUSettings ), xRegions, pxNewTCB->pxStack, ulStackDepth );\r
+       }\r
+       #else\r
+       {\r
+               /* Avoid compiler warning about unreferenced parameter. */\r
+               ( void ) xRegions;\r
        }\r
        #endif\r
 \r
@@ -979,6 +1075,12 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
 \r
+                       /* Increment the uxTaskNumber also so kernel aware debuggers can\r
+                       detect that the task lists need re-generating.  This is done before\r
+                       portPRE_TASK_DELETE_HOOK() as in the Windows port that macro will\r
+                       not return. */\r
+                       uxTaskNumber++;\r
+\r
                        if( pxTCB == pxCurrentTCB )\r
                        {\r
                                /* A task is deleting itself.  This cannot complete within the\r
@@ -992,16 +1094,23 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                                there is a task that has been deleted and that it should therefore\r
                                check the xTasksWaitingTermination list. */\r
                                ++uxDeletedTasksWaitingCleanUp;\r
+\r
+                               /* The pre-delete hook is primarily for the Windows simulator,\r
+                               in which Windows specific clean up operations are performed,\r
+                               after which it is not possible to yield away from this task -\r
+                               hence xYieldPending is used to latch that a context switch is\r
+                               required. */\r
+                               portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending );\r
                        }\r
                        else\r
                        {\r
                                --uxCurrentNumberOfTasks;\r
                                prvDeleteTCB( pxTCB );\r
-                       }\r
 \r
-                       /* Increment the uxTaskNumber also so kernel aware debuggers can\r
-                       detect that the task lists need re-generating. */\r
-                       uxTaskNumber++;\r
+                               /* Reset the next expected unblock time in case it referred to\r
+                               the task that has just been deleted. */\r
+                               prvResetNextTaskUnblockTime();\r
+                       }\r
 \r
                        traceTASK_DELETE( pxTCB );\r
                }\r
@@ -1014,24 +1123,11 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                        if( pxTCB == pxCurrentTCB )\r
                        {\r
                                configASSERT( uxSchedulerSuspended == 0 );\r
-\r
-                               /* The pre-delete hook is primarily for the Windows simulator,\r
-                               in which Windows specific clean up operations are performed,\r
-                               after which it is not possible to yield away from this task -\r
-                               hence xYieldPending is used to latch that a context switch is\r
-                               required. */\r
-                               portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending );\r
                                portYIELD_WITHIN_API();\r
                        }\r
                        else\r
                        {\r
-                               /* Reset the next expected unblock time in case it referred to\r
-                               the task that has just been deleted. */\r
-                               taskENTER_CRITICAL();\r
-                               {\r
-                                       prvResetNextTaskUnblockTime();\r
-                               }\r
-                               taskEXIT_CRITICAL();\r
+                               mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
        }\r
@@ -1730,23 +1826,42 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
 void vTaskStartScheduler( void )\r
 {\r
 BaseType_t xReturn;\r
-uint16_t usIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
 \r
        /* Add the idle task at the lowest priority. */\r
        #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
        {\r
                StaticTask_t *pxIdleTaskTCBBuffer = NULL;\r
                StackType_t *pxIdleTaskStackBuffer = NULL;\r
+               uint32_t ulIdleTaskStackSize;\r
 \r
                /* The Idle task is created using user provided RAM - obtain the\r
                address of the RAM then create the idle task. */\r
-               vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &usIdleTaskStackSize );\r
-               xReturn = xTaskCreateStatic( prvIdleTask, "IDLE", usIdleTaskStackSize, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle, pxIdleTaskStackBuffer, pxIdleTaskTCBBuffer ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
+               vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize );\r
+               xIdleTaskHandle = xTaskCreateStatic(    prvIdleTask,\r
+                                                                                               "IDLE",\r
+                                                                                               ulIdleTaskStackSize,\r
+                                                                                               ( void * ) NULL,\r
+                                                                                               ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),\r
+                                                                                               pxIdleTaskStackBuffer,\r
+                                                                                               pxIdleTaskTCBBuffer ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
+\r
+               if( xIdleTaskHandle != NULL )\r
+               {\r
+                       xReturn = pdPASS;\r
+               }\r
+               else\r
+               {\r
+                       xReturn = pdFAIL;\r
+               }\r
        }\r
        #else\r
        {\r
                /* The Idle task is being created using dynamically allocated RAM. */\r
-               xReturn = xTaskCreate( prvIdleTask, "IDLE", usIdleTaskStackSize, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
+               xReturn = xTaskCreate(  prvIdleTask,\r
+                                                               "IDLE", configMINIMAL_STACK_SIZE,\r
+                                                               ( void * ) NULL,\r
+                                                               ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),\r
+                                                               &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
        }\r
        #endif /* configSUPPORT_STATIC_ALLOCATION */\r
 \r
@@ -1786,7 +1901,10 @@ uint16_t usIdleTaskStackSize = configMINIMAL_STACK_SIZE;
 \r
                /* If configGENERATE_RUN_TIME_STATS is defined then the following\r
                macro must be defined to configure the timer/counter used to generate\r
-               the run time counter time base. */\r
+               the run time counter time base.   NOTE:  If configGENERATE_RUN_TIME_STATS\r
+               is set to 0 and the following line fails to build then ensure you do not\r
+               have portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() defined in your\r
+               FreeRTOSConfig.h file. */\r
                portCONFIGURE_TIMER_FOR_RUN_TIME_STATS();\r
 \r
                /* Setting up the timer tick is hardware specific and thus in the\r
@@ -1806,7 +1924,7 @@ uint16_t usIdleTaskStackSize = configMINIMAL_STACK_SIZE;
                /* This line will only be reached if the kernel could not be started,\r
                because there was not enough FreeRTOS heap to create the idle task\r
                or the timer task. */\r
-               configASSERT( xReturn );\r
+               configASSERT( xReturn != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY );\r
        }\r
 \r
        /* Prevent compiler warnings if INCLUDE_xTaskGetIdleTaskHandle is set to 0,\r
@@ -2075,7 +2193,7 @@ TCB_t *pxTCB;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( INCLUDE_xTaskGetTaskHandle == 1 )\r
+#if ( INCLUDE_xTaskGetHandle == 1 )\r
 \r
        static TCB_t *prvSearchForNameWithinSingleList( List_t *pxList, const char pcNameToQuery[] )\r
        {\r
@@ -2133,12 +2251,12 @@ TCB_t *pxTCB;
                return pxReturn;\r
        }\r
 \r
-#endif /* INCLUDE_xTaskGetTaskHandle */\r
+#endif /* INCLUDE_xTaskGetHandle */\r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( INCLUDE_xTaskGetTaskHandle == 1 )\r
+#if ( INCLUDE_xTaskGetHandle == 1 )\r
 \r
-       TaskHandle_t xTaskGetTaskHandle( const char *pcNameToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+       TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
        {\r
        UBaseType_t uxQueue = configMAX_PRIORITIES;\r
        TCB_t* pxTCB;\r
@@ -2198,7 +2316,7 @@ TCB_t *pxTCB;
                return ( TaskHandle_t ) pxTCB;\r
        }\r
 \r
-#endif /* INCLUDE_xTaskGetTaskHandle */\r
+#endif /* INCLUDE_xTaskGetHandle */\r
 /*-----------------------------------------------------------*/\r
 \r
 #if ( configUSE_TRACE_FACILITY == 1 )\r
@@ -2373,7 +2491,7 @@ implementations require configUSE_TICKLESS_IDLE to be set to a value other than
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r
-               xTaskResumeAll();\r
+               ( void ) xTaskResumeAll();\r
 \r
                return xReturn;\r
        }\r
@@ -2844,10 +2962,9 @@ BaseType_t xReturn;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-BaseType_t xTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue )\r
+void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue )\r
 {\r
 TCB_t *pxUnblockedTCB;\r
-BaseType_t xReturn;\r
 \r
        /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED.  It is used by\r
        the event flags implementation. */\r
@@ -2870,22 +2987,12 @@ BaseType_t xReturn;
 \r
        if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority )\r
        {\r
-               /* Return true if the task removed from the event list has\r
-               a higher priority than the calling task.  This allows\r
-               the calling task to know if it should force a context\r
-               switch now. */\r
-               xReturn = pdTRUE;\r
-\r
-               /* Mark that a yield is pending in case the user is not using the\r
-               "xHigherPriorityTaskWoken" parameter to an ISR safe FreeRTOS function. */\r
+               /* The unblocked task has a priority above that of the calling task, so\r
+               a context switch is required.  This function is called with the\r
+               scheduler suspended so xYieldPending is set so the context switch\r
+               occurs immediately that the scheduler is resumed (unsuspended). */\r
                xYieldPending = pdTRUE;\r
        }\r
-       else\r
-       {\r
-               xReturn = pdFALSE;\r
-       }\r
-\r
-       return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -3293,7 +3400,7 @@ static void prvCheckTasksWaitingTermination( void )
 \r
 #if( configUSE_TRACE_FACILITY == 1 )\r
 \r
-       void vTaskGetTaskInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState )\r
+       void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState )\r
        {\r
        TCB_t *pxTCB;\r
 \r
@@ -3320,7 +3427,7 @@ static void prvCheckTasksWaitingTermination( void )
                                                pxTaskStatus->eCurrentState = eBlocked;\r
                                        }\r
                                }\r
-                               xTaskResumeAll();\r
+                               ( void ) xTaskResumeAll();\r
                        }\r
                }\r
                #endif /* INCLUDE_vTaskSuspend */\r
@@ -3384,7 +3491,7 @@ static void prvCheckTasksWaitingTermination( void )
 \r
        static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState )\r
        {\r
-       volatile TCB_t *pxNextTCB, *pxFirstTCB;\r
+       configLIST_VOLATILE TCB_t *pxNextTCB, *pxFirstTCB;\r
        UBaseType_t uxTask = 0;\r
 \r
                if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )\r
@@ -3398,7 +3505,7 @@ static void prvCheckTasksWaitingTermination( void )
                        do\r
                        {\r
                                listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\r
-                               vTaskGetTaskInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState );\r
+                               vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState );\r
                                uxTask++;\r
                        } while( pxNextTCB != pxFirstTCB );\r
                }\r
@@ -3478,24 +3585,36 @@ static void prvCheckTasksWaitingTermination( void )
                }\r
                #endif /* configUSE_NEWLIB_REENTRANT */\r
 \r
-               #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )\r
+               #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) && ( portUSING_MPU_WRAPPERS == 0 ) )\r
                {\r
-                       /* The task can only have been allocated dynamically - free it\r
-                       again. */\r
+                       /* The task can only have been allocated dynamically - free both\r
+                       the stack and TCB. */\r
                        vPortFree( pxTCB->pxStack );\r
                        vPortFree( pxTCB );\r
                }\r
-               #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\r
+               #elif( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 )\r
                {\r
                        /* The task could have been allocated statically or dynamically, so\r
-                       check before attempting to free the memory. */\r
-                       if( pxTCB->ucStaticallyAllocated == ( uint8_t ) pdFALSE )\r
+                       check what was statically allocated before trying to free the\r
+                       memory. */\r
+                       if( pxTCB->ucStaticallyAllocated == tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB )\r
                        {\r
+                               /* Both the stack and TCB were allocated dynamically, so both\r
+                               must be freed. */\r
                                vPortFree( pxTCB->pxStack );\r
                                vPortFree( pxTCB );\r
                        }\r
+                       else if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_ONLY )\r
+                       {\r
+                               /* Only the stack was statically allocated, so the TCB is the\r
+                               only memory that must be freed. */\r
+                               vPortFree( pxTCB );\r
+                       }\r
                        else\r
                        {\r
+                               /* Neither the stack nor the TCB were allocated dynamically, so\r
+                               nothing needs to be freed. */\r
+                               configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB     )\r
                                mtCOVERAGE_TEST_MARKER();\r
                        }\r
                }\r