]> git.sur5r.net Git - freertos/blobdiff - Source/tasks.c
Add in the pcTaskGetTaskName(), xTaskGetIdleTaskHandle() and xTimerGetTimerTaskHandle...
[freertos] / Source / tasks.c
index 6f305f725fc7a183eec5dd723d6543cd624d12fe..16914978cb84b29ce511f37efcae967a26d7e8b9 100644 (file)
@@ -1,38 +1,44 @@
 /*\r
-    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+    FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+       \r
+\r
+       FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:\r
+       Atollic AB - Atollic provides professional embedded systems development \r
+       tools for C/C++ development, code analysis and test automation.  \r
+       See http://www.atollic.com\r
+       \r
 \r
     ***************************************************************************\r
-    *                                                                         *\r
-    * If you are:                                                             *\r
-    *                                                                         *\r
-    *    + New to FreeRTOS,                                                   *\r
-    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
-    *    + Looking for basic training,                                        *\r
-    *    + Wanting to improve your FreeRTOS skills and productivity           *\r
-    *                                                                         *\r
-    * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
-    *                                                                         *\r
-    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
-    *                  http://www.FreeRTOS.org/Documentation                  *\r
-    *                                                                         *\r
-    * A pdf reference manual is also available.  Both are usually delivered   *\r
-    * to your inbox within 20 minutes to two hours when purchased between 8am *\r
-    * and 8pm GMT (although please allow up to 24 hours in case of            *\r
-    * exceptional circumstances).  Thank you for your support!                *\r
-    *                                                                         *\r
+     *                                                                       *\r
+     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
+     *    Complete, revised, and edited pdf reference manuals are also       *\r
+     *    available.                                                         *\r
+     *                                                                       *\r
+     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
+     *    ensuring you get running as quickly as possible and with an        *\r
+     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
+     *    the FreeRTOS project to continue with its mission of providing     *\r
+     *    professional grade, cross platform, de facto standard solutions    *\r
+     *    for microcontrollers - completely free of charge!                  *\r
+     *                                                                       *\r
+     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
+     *                                                                       *\r
+     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
+     *                                                                       *\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
-    ***NOTE*** The exception to the GPL is included to allow you to distribute\r
-    a combined work that includes FreeRTOS without being obliged to provide the\r
-    source code for proprietary components outside of the FreeRTOS kernel.\r
-    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
-    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
-    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+    >>>NOTE<<< The modification to the GPL is included to allow you to\r
+    distribute a combined work that includes FreeRTOS without being obliged to\r
+    provide the source code for proprietary components outside of the FreeRTOS\r
+    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
     more details. You should have received a copy of the GNU General Public\r
     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
@@ -151,6 +157,12 @@ PRIVILEGED_DATA static xList xPendingReadyList;                                                    /*< Tasks that have been r
 \r
 #endif\r
 \r
+#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
+       \r
+       PRIVILEGED_DATA static xTaskHandle xIdleTaskHandle = NULL;\r
+       \r
+#endif\r
+\r
 /* File private variables. --------------------------------*/\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks  = ( unsigned portBASE_TYPE ) 0;\r
 PRIVILEGED_DATA static volatile portTickType xTickCount                                                = ( portTickType ) 0;\r
@@ -267,7 +279,6 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime                                            = ( portTickType )
  */\r
 #define prvCheckDelayedTasks()                                                                                                                 \\r
 {                                                                                                                                                                              \\r
-register tskTCB *pxTCB;                                                                                                                                        \\r
 portTickType xItemValue;                                                                                                                               \\r
                                                                                                                                                                                \\r
        /* Is the tick count greater than or equal to the wake time of the first                        \\r
@@ -329,6 +340,7 @@ portTickType xItemValue;                                                                                                                            \
 \r
 /* Callback function prototypes. --------------------------*/\r
 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );\r
+extern void vApplicationTickHook( void );\r
                \r
 /* File private functions. --------------------------------*/\r
 \r
@@ -429,6 +441,9 @@ signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed ch
 signed portBASE_TYPE xReturn;\r
 tskTCB * pxNewTCB;\r
 \r
+       configASSERT( pxTaskCode );\r
+       configASSERT( ( uxPriority < 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
        pxNewTCB = prvAllocateTCBAndStack( usStackDepth, puxStackBuffer );\r
@@ -459,10 +474,16 @@ tskTCB * pxNewTCB;
                {\r
                        pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - ( unsigned short ) 1 );\r
                        pxTopOfStack = ( portSTACK_TYPE * ) ( ( ( unsigned long ) pxTopOfStack ) & ( ( unsigned long ) ~portBYTE_ALIGNMENT_MASK  ) );\r
+\r
+                       /* Check the alignment of the calculated top of stack is correct. */\r
+                       configASSERT( ( ( ( unsigned long ) pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
                }\r
                #else\r
                {\r
                        pxTopOfStack = pxNewTCB->pxStack;\r
+                       \r
+                       /* Check the alignment of the stack buffer is correct. */\r
+                       configASSERT( ( ( ( unsigned long ) pxNewTCB->pxStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
 \r
                        /* If we want to use stack checking on architectures that use\r
                        a positive stack growth direction then we also need to store the\r
@@ -488,6 +509,9 @@ tskTCB * pxNewTCB;
                }\r
                #endif\r
 \r
+               /* Check the alignment of the initialised stack. */\r
+               configASSERT( ( ( ( unsigned long ) pxNewTCB->pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
+\r
                if( ( void * ) pxCreatedTask != NULL )\r
                {\r
                        /* Pass the TCB out - in an anonymous way.  The calling function/\r
@@ -647,6 +671,9 @@ tskTCB * pxNewTCB;
        portTickType xTimeToWake;\r
        portBASE_TYPE xAlreadyYielded, xShouldDelay = pdFALSE;\r
 \r
+               configASSERT( pxPreviousWakeTime );\r
+               configASSERT( ( xTimeIncrement > 0 ) );\r
+\r
                vTaskSuspendAll();\r
                {\r
                        /* Generate the tick time at which the task wants to wake. */\r
@@ -748,19 +775,6 @@ tskTCB * pxNewTCB;
 #endif\r
 /*-----------------------------------------------------------*/\r
 \r
-void vTaskUnblockTask( xTaskHandle pxTask )\r
-{\r
-tskTCB *pxTCB = ( tskTCB * ) pxTask;\r
-\r
-       /* This function is not intended to be a public API function and definitely\r
-       is not for generic use as it assumes pxTask is not the running task and not\r
-       suspended, does not remove the task from any event lists it might be \r
-       blocked on, and does not take care of mutual exclusion. */\r
-       vListRemove( &( pxTCB->xGenericListItem ) );\r
-       prvAddTaskToReadyQueue( pxTCB );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
 #if ( INCLUDE_uxTaskPriorityGet == 1 )\r
 \r
        unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask )\r
@@ -791,6 +805,8 @@ tskTCB *pxTCB = ( tskTCB * ) pxTask;
        unsigned portBASE_TYPE uxCurrentPriority;\r
        portBASE_TYPE xYieldRequired = pdFALSE;\r
 \r
+               configASSERT( ( uxNewPriority < configMAX_PRIORITIES ) );\r
+\r
                /* Ensure the new priority is valid. */\r
                if( uxNewPriority >= configMAX_PRIORITIES )\r
                {\r
@@ -934,9 +950,9 @@ tskTCB *pxTCB = ( tskTCB * ) pxTask;
                                /* The scheduler is not running, but the task that was pointed\r
                                to by pxCurrentTCB has just been suspended and pxCurrentTCB\r
                                must be adjusted to point to a different task. */\r
-                               if( uxCurrentNumberOfTasks == ( unsigned portBASE_TYPE ) 1U )\r
+                               if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks ) \r
                                {\r
-                                       /* No other tasks are defined, so set pxCurrentTCB back to\r
+                                       /* No other tasks are ready, so set pxCurrentTCB back to\r
                                        NULL so when the next task is created pxCurrentTCB will\r
                                        be set to point to it no matter what its relative priority\r
                                        is. */\r
@@ -960,6 +976,9 @@ tskTCB *pxTCB = ( tskTCB * ) pxTask;
        portBASE_TYPE xReturn = pdFALSE;\r
        const tskTCB * const pxTCB = ( tskTCB * ) xTask;\r
 \r
+               /* It does not make sense to check if the calling task is suspended. */\r
+               configASSERT( xTask );\r
+\r
                /* Is the task we are attempting to resume actually in the\r
                suspended list? */\r
                if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
@@ -990,6 +1009,9 @@ tskTCB *pxTCB = ( tskTCB * ) pxTask;
        {\r
        tskTCB *pxTCB;\r
 \r
+               /* It does not make sense to resume the calling task. */\r
+               configASSERT( pxTaskToResume );\r
+\r
                /* Remove the task from whichever list it is currently in, and place\r
                it in the ready list. */\r
                pxTCB = ( tskTCB * ) pxTaskToResume;\r
@@ -1033,6 +1055,8 @@ tskTCB *pxTCB = ( tskTCB * ) pxTask;
        portBASE_TYPE xYieldRequired = pdFALSE;\r
        tskTCB *pxTCB;\r
 \r
+               configASSERT( pxTaskToResume );\r
+\r
                pxTCB = ( tskTCB * ) pxTaskToResume;\r
 \r
                if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
@@ -1072,7 +1096,18 @@ void vTaskStartScheduler( void )
 portBASE_TYPE xReturn;\r
 \r
        /* Add the idle task at the lowest priority. */\r
-       xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), ( xTaskHandle * ) NULL );\r
+       #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
+       {\r
+               /* Create the idle task, storing its handle in xIdleTaskHandle so it can\r
+               be returned by the xTaskGetIdleTaskHandle() function. */\r
+               xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle );\r
+       }\r
+       #else\r
+       {\r
+               /* Create the idle task without storing its handle. */\r
+               xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL );\r
+       }\r
+       #endif\r
 \r
        #if ( configUSE_TIMERS == 1 )\r
        {\r
@@ -1115,6 +1150,9 @@ portBASE_TYPE xReturn;
                        /* Should only reach here if a task calls xTaskEndScheduler(). */\r
                }\r
        }\r
+\r
+       /* This line will only be reached if the kernel could not be started. */\r
+       configASSERT( xReturn );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1142,6 +1180,10 @@ signed portBASE_TYPE xTaskResumeAll( void )
 register tskTCB *pxTCB;\r
 signed portBASE_TYPE xAlreadyYielded = pdFALSE;\r
 \r
+       /* If uxSchedulerSuspended is zero then this function does not match a\r
+       previous call to vTaskSuspendAll(). */\r
+       configASSERT( uxSchedulerSuspended );\r
+\r
        /* It is possible that an ISR caused a task to be removed from an event\r
        list while the scheduler was suspended.  If this was the case then the\r
        removed task will have been added to the xPendingReadyList.  Once the\r
@@ -1237,7 +1279,14 @@ portTickType xTicks;
 \r
 portTickType xTaskGetTickCountFromISR( void )\r
 {\r
-       return xTickCount;\r
+portTickType xReturn;\r
+unsigned portBASE_TYPE uxSavedInterruptStatus;\r
+\r
+       uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+       xReturn = xTickCount;\r
+       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+       return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1249,6 +1298,17 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery )\r
+{\r
+tskTCB *pxTCB;\r
+\r
+       /* If null is passed in here then the name of the calling task is being queried. */\r
+       pxTCB = prvGetTCBFromHandle( xTaskToQuery );\r
+       configASSERT( pxTCB );\r
+       return &( pxTCB->pcTaskName[ 0 ] );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 #if ( configUSE_TRACE_FACILITY == 1 )\r
 \r
        void vTaskList( signed char *pcWriteBuffer )\r
@@ -1272,25 +1332,25 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
                        {\r
                                uxQueue--;\r
 \r
-                               if( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) )\r
+                               if( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) == pdFALSE )\r
                                {\r
                                        prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), tskREADY_CHAR );\r
                                }\r
                        }while( uxQueue > ( unsigned short ) tskIDLE_PRIORITY );\r
 \r
-                       if( !listLIST_IS_EMPTY( pxDelayedTaskList ) )\r
+                       if( listLIST_IS_EMPTY( pxDelayedTaskList ) == pdFALSE )\r
                        {\r
                                prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) pxDelayedTaskList, tskBLOCKED_CHAR );\r
                        }\r
 \r
-                       if( !listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) )\r
+                       if( listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) == pdFALSE )\r
                        {\r
                                prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) pxOverflowDelayedTaskList, tskBLOCKED_CHAR );\r
                        }\r
 \r
                        #if( INCLUDE_vTaskDelete == 1 )\r
                        {\r
-                               if( !listLIST_IS_EMPTY( &xTasksWaitingTermination ) )\r
+                               if( listLIST_IS_EMPTY( &xTasksWaitingTermination ) == pdFALSE )\r
                                {\r
                                        prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &xTasksWaitingTermination, tskDELETED_CHAR );\r
                                }\r
@@ -1299,7 +1359,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
                        #if ( INCLUDE_vTaskSuspend == 1 )\r
                        {\r
-                               if( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )\r
+                               if( listLIST_IS_EMPTY( &xSuspendedTaskList ) == pdFALSE )\r
                                {\r
                                        prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &xSuspendedTaskList, tskSUSPENDED_CHAR );\r
                                }\r
@@ -1347,25 +1407,25 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
                        {\r
                                uxQueue--;\r
 \r
-                               if( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) )\r
+                               if( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) == pdFALSE )\r
                                {\r
                                        prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), ulTotalRunTime );\r
                                }\r
                        }while( uxQueue > ( unsigned short ) tskIDLE_PRIORITY );\r
 \r
-                       if( !listLIST_IS_EMPTY( pxDelayedTaskList ) )\r
+                       if( listLIST_IS_EMPTY( pxDelayedTaskList ) == pdFALSE )\r
                        {\r
                                prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxDelayedTaskList, ulTotalRunTime );\r
                        }\r
 \r
-                       if( !listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) )\r
+                       if( listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) == pdFALSE )\r
                        {\r
                                prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxOverflowDelayedTaskList, ulTotalRunTime );\r
                        }\r
 \r
                        #if ( INCLUDE_vTaskDelete == 1 )\r
                        {\r
-                               if( !listLIST_IS_EMPTY( &xTasksWaitingTermination ) )\r
+                               if( listLIST_IS_EMPTY( &xTasksWaitingTermination ) == pdFALSE )\r
                                {\r
                                        prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &xTasksWaitingTermination, ulTotalRunTime );\r
                                }\r
@@ -1374,7 +1434,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
                        #if ( INCLUDE_vTaskSuspend == 1 )\r
                        {\r
-                               if( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )\r
+                               if( listLIST_IS_EMPTY( &xSuspendedTaskList ) == pdFALSE )\r
                                {\r
                                        prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &xSuspendedTaskList, ulTotalRunTime );\r
                                }\r
@@ -1391,6 +1451,9 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
        void vTaskStartTrace( signed char * pcBuffer, unsigned long ulBufferSize )\r
        {\r
+               configASSERT( pcBuffer );\r
+               configASSERT( ulBufferSize );\r
+\r
                taskENTER_CRITICAL();\r
                {\r
                        pcTraceBuffer = ( signed char * )pcBuffer;\r
@@ -1420,8 +1483,19 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
        }\r
 \r
 #endif\r
+/*----------------------------------------------------------*/\r
 \r
+#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
 \r
+       xTaskHandle xTaskGetIdleTaskHandle( void )\r
+       {\r
+               /* If xTaskGetIdleTaskHandle() is called before the scheduler has been\r
+               started, then xIdleTaskHandle will be NULL. */\r
+               configASSERT( ( xIdleTaskHandle != NULL ) );\r
+               return xIdleTaskHandle;\r
+       }\r
+       \r
+#endif\r
 \r
 /*-----------------------------------------------------------\r
  * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES\r
@@ -1431,6 +1505,8 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
 void vTaskIncrementTick( void )\r
 {\r
+tskTCB * pxTCB;\r
+\r
        /* Called by the portable layer each time a tick interrupt occurs.\r
        Increments the tick then checks to see if the new tick value will cause any\r
        tasks to be unblocked. */\r
@@ -1444,26 +1520,28 @@ void vTaskIncrementTick( void )
                        /* Tick count has overflowed so we need to swap the delay lists.\r
                        If there are any items in pxDelayedTaskList here then there is\r
                        an error! */\r
+                       configASSERT( ( listLIST_IS_EMPTY( pxDelayedTaskList ) ) );\r
+                       \r
                        pxTemp = pxDelayedTaskList;\r
                        pxDelayedTaskList = pxOverflowDelayedTaskList;\r
                        pxOverflowDelayedTaskList = pxTemp;\r
                        xNumOfOverflows++;\r
+       \r
                        if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
                        {\r
-                               /* The delayed list is empty.  Set xNextTaskUnblockTime to the\r
-                               maximum possible value so it is extremely unlikely that the\r
-                               if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
-                               until there is an item in the delayed list. */\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
+                               if( xTickCount >= xNextTaskUnblockTime ) test will pass until \r
+                               there is an item in the delayed list. */\r
                                xNextTaskUnblockTime = portMAX_DELAY;\r
                        }\r
                        else\r
                        {\r
-                               tskTCB * pxTCB;\r
-\r
-                               /* The delayed list is not empty, get the value of the item at\r
-                               the head of the delayed list.  This is the time at which the\r
-                               task at the head of the delayed list should be removed from\r
-                               the Blocked state. */\r
+                               /* The new current delayed list is not empty, get the value of \r
+                               the item at the head of the delayed list.  This is the time at \r
+                               which the task at the head of the delayed list should be removed \r
+                               from the Blocked state. */\r
                                pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
                                xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
                        }\r
@@ -1480,8 +1558,6 @@ void vTaskIncrementTick( void )
                scheduler is locked. */\r
                #if ( configUSE_TICK_HOOK == 1 )\r
                {\r
-                       extern void vApplicationTickHook( void );\r
-\r
                        vApplicationTickHook();\r
                }\r
                #endif\r
@@ -1489,11 +1565,9 @@ void vTaskIncrementTick( void )
 \r
        #if ( configUSE_TICK_HOOK == 1 )\r
        {\r
-               extern void vApplicationTickHook( void );\r
-\r
                /* Guard against the tick hook being called when the missed tick\r
                count is being unwound (when the scheduler is being unlocked. */\r
-               if( uxMissedTicks == 0 )\r
+               if( uxMissedTicks == ( unsigned portBASE_TYPE ) 0U )\r
                {\r
                        vApplicationTickHook();\r
                }\r
@@ -1518,7 +1592,7 @@ void vTaskIncrementTick( void )
                {\r
                        usQueue--;\r
 \r
-                       while( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ usQueue ] ) ) )\r
+                       while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ usQueue ] ) ) == pdFALSE )\r
                        {\r
                                listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &( pxReadyTasksLists[ usQueue ] ) );\r
                                vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
@@ -1528,7 +1602,7 @@ void vTaskIncrementTick( void )
                }while( usQueue > ( unsigned short ) tskIDLE_PRIORITY );\r
 \r
                /* Remove any TCB's from the delayed queue. */\r
-               while( !listLIST_IS_EMPTY( &xDelayedTaskList1 ) )\r
+               while( listLIST_IS_EMPTY( &xDelayedTaskList1 ) == pdFALSE )\r
                {\r
                        listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xDelayedTaskList1 );\r
                        vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
@@ -1537,7 +1611,7 @@ void vTaskIncrementTick( void )
                }\r
 \r
                /* Remove any TCB's from the overflow delayed queue. */\r
-               while( !listLIST_IS_EMPTY( &xDelayedTaskList2 ) )\r
+               while( listLIST_IS_EMPTY( &xDelayedTaskList2 ) == pdFALSE )\r
                {\r
                        listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xDelayedTaskList2 );\r
                        vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
@@ -1545,7 +1619,7 @@ void vTaskIncrementTick( void )
                        prvDeleteTCB( ( tskTCB * ) pxTCB );\r
                }\r
 \r
-               while( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )\r
+               while( listLIST_IS_EMPTY( &xSuspendedTaskList ) == pdFALSE )\r
                {\r
                        listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xSuspendedTaskList );\r
                        vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
@@ -1559,7 +1633,7 @@ void vTaskIncrementTick( void )
 \r
 #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
 \r
-       void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxTagValue )\r
+       void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction )\r
        {\r
        tskTCB *xTCB;\r
 \r
@@ -1576,7 +1650,7 @@ void vTaskIncrementTick( void )
                /* Save the hook function in the TCB.  A critical section is required as\r
                the value can be accessed from an interrupt. */\r
                taskENTER_CRITICAL();\r
-                       xTCB->pxTaskTag = pxTagValue;\r
+                       xTCB->pxTaskTag = pxHookFunction;\r
                taskEXIT_CRITICAL();\r
        }\r
 \r
@@ -1682,6 +1756,7 @@ void vTaskSwitchContext( void )
                /* Find the highest priority queue that contains ready tasks. */\r
                while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) )\r
                {\r
+                       configASSERT( uxTopReadyPriority );\r
                        --uxTopReadyPriority;\r
                }\r
        \r
@@ -1699,6 +1774,8 @@ void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicks
 {\r
 portTickType xTimeToWake;\r
 \r
+       configASSERT( pxEventList );\r
+\r
        /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE\r
        SCHEDULER SUSPENDED. */\r
 \r
@@ -1741,6 +1818,40 @@ portTickType xTimeToWake;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+#if configUSE_TIMERS == 1\r
+\r
+       void vTaskPlaceOnEventListRestricted( const xList * const pxEventList, portTickType xTicksToWait )\r
+       {\r
+       portTickType xTimeToWake;\r
+\r
+               configASSERT( pxEventList );\r
+\r
+               /* 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
+\r
+       \r
+               /* Place the event list item of the TCB in the appropriate event list.\r
+               In this case it is assume that this is the only task that is going to\r
+               be waiting on this event list, so the faster vListInsertEnd() function\r
+               can be used in place of vListInsert. */\r
+               vListInsertEnd( ( xList * ) pxEventList, ( xListItem * ) &( pxCurrentTCB->xEventListItem ) );\r
+\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
+               vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+\r
+               /* Calculate the time at which the task should be woken if the event does\r
+               not occur.  This may overflow but this doesn't matter. */\r
+               xTimeToWake = xTickCount + xTicksToWait;\r
+               prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+       }\r
+       \r
+#endif /* configUSE_TIMERS */\r
+/*-----------------------------------------------------------*/\r
+\r
 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList )\r
 {\r
 tskTCB *pxUnblockedTCB;\r
@@ -1760,6 +1871,7 @@ portBASE_TYPE xReturn;
        This function assumes that a check has already been made to ensure that\r
        pxEventList is not empty. */\r
        pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
+       configASSERT( pxUnblockedTCB );\r
        vListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
 \r
        if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
@@ -1793,6 +1905,7 @@ portBASE_TYPE xReturn;
 \r
 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut )\r
 {\r
+       configASSERT( pxTimeOut );\r
        pxTimeOut->xOverflowCount = xNumOfOverflows;\r
        pxTimeOut->xTimeOnEntering = xTickCount;\r
 }\r
@@ -1802,6 +1915,9 @@ portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType
 {\r
 portBASE_TYPE xReturn;\r
 \r
+       configASSERT( pxTimeOut );\r
+       configASSERT( pxTicksToWait );\r
+\r
        taskENTER_CRITICAL();\r
        {\r
                #if ( INCLUDE_vTaskSuspend == 1 )\r
@@ -2091,7 +2207,7 @@ static void prvAddCurrentTaskToDelayedList( portTickType xTimeToWake )
                vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
 \r
                /* If the task entering the blocked state was placed at the head of the\r
-               list of blocked tasks then xNextTaskUnmblockTime needs to be updated\r
+               list of blocked tasks then xNextTaskUnblockTime needs to be updated\r
                too. */\r
                if( xTimeToWake < xNextTaskUnblockTime )\r
                {\r
@@ -2298,7 +2414,7 @@ tskTCB *pxNewTCB;
 \r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( INCLUDE_xTaskGetCurrentTaskHandle == 1 )\r
+#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )\r
 \r
        xTaskHandle xTaskGetCurrentTaskHandle( void )\r
        {\r
@@ -2316,7 +2432,7 @@ tskTCB *pxNewTCB;
 \r
 /*-----------------------------------------------------------*/\r
 \r
-#if ( INCLUDE_xTaskGetSchedulerState == 1 )\r
+#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
 \r
        portBASE_TYPE xTaskGetSchedulerState( void )\r
        {\r
@@ -2350,6 +2466,8 @@ tskTCB *pxNewTCB;
        {\r
        tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder;\r
 \r
+               configASSERT( pxMutexHolder );\r
+\r
                if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )\r
                {\r
                        /* Adjust the mutex holder state to account for its new priority. */\r