]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
Linting and MISRA checking
[freertos] / FreeRTOS / Source / tasks.c
index 83d9f09a36b72f61c56372817557928e48423214..a851af055bf05e99fa28b2eea1e83d90ded53270 100644 (file)
@@ -73,7 +73,6 @@
 */\r
 \r
 /* Standard includes. */\r
-#include <stdio.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
 \r
@@ -88,7 +87,19 @@ task.h is included from an application file. */
 #include "timers.h"\r
 #include "StackMacros.h"\r
 \r
-#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
+/* Lint e961 and e750 are suppressed as a MISRA exception justified because the\r
+MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\r
+header files above, but not in this file, in order to generate the correct\r
+privileged Vs unprivileged linkage and placement. */\r
+#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
+\r
+#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configINCLUDE_STATS_FORMATTING_FUNCTIONS == 1 ) )\r
+       /* At the bottom of this file are two optional functions that can be used\r
+       to generate human readable text from the raw data generated by the\r
+       xTaskGetSystemState() function.  Note the formatting functions are provided\r
+       for convenience only, and are NOT considered part of the kernel. */\r
+       #include <stdio.h>\r
+#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configINCLUDE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */\r
 \r
 /* Sanity check the configuration. */\r
 #if configUSE_TICKLESS_IDLE != 0\r
@@ -168,14 +179,16 @@ typedef struct tskTaskControlBlock
        #define static\r
 #endif\r
 \r
-/*lint -e956 */\r
+/*lint -e956 A manual analysis and inspection has been used to determine which\r
+static variables must be declared volatile. */\r
+\r
 PRIVILEGED_DATA tskTCB * volatile pxCurrentTCB = NULL;\r
 \r
 /* Lists for ready and blocked tasks. --------------------*/\r
 PRIVILEGED_DATA static xList pxReadyTasksLists[ configMAX_PRIORITIES ];        /*< Prioritised ready tasks. */\r
 PRIVILEGED_DATA static xList xDelayedTaskList1;                                                        /*< Delayed tasks. */\r
 PRIVILEGED_DATA static xList xDelayedTaskList2;                                                        /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\r
-PRIVILEGED_DATA static xList * volatile pxDelayedTaskList ;                            /*< Points to the delayed task list currently being used. */\r
+PRIVILEGED_DATA static xList * volatile pxDelayedTaskList                            /*< Points to the delayed task list currently being used. */\r
 PRIVILEGED_DATA static xList * volatile pxOverflowDelayedTaskList;             /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */\r
 PRIVILEGED_DATA static xList xPendingReadyList;                                                        /*< Tasks that have been readied while the scheduler was suspended.  They will be moved to the ready list when the scheduler is resumed. */\r
 \r
@@ -198,26 +211,27 @@ PRIVILEGED_DATA static xList xPendingReadyList;                                                   /*< Tasks that have been r
 \r
 #endif\r
 \r
-/* File private variables. --------------------------------*/\r
+/* Other file private variables. --------------------------------*/\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks  = ( unsigned portBASE_TYPE ) 0U;\r
 PRIVILEGED_DATA static volatile portTickType xTickCount                                                = ( portTickType ) 0U;\r
-PRIVILEGED_DATA static unsigned portBASE_TYPE uxTopUsedPriority                                        = tskIDLE_PRIORITY;\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxTopReadyPriority              = tskIDLE_PRIORITY;\r
 PRIVILEGED_DATA static volatile signed portBASE_TYPE xSchedulerRunning                         = pdFALSE;\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxSchedulerSuspended            = ( unsigned portBASE_TYPE ) pdFALSE;\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxPendedTicks                   = ( unsigned portBASE_TYPE ) 0U;\r
-PRIVILEGED_DATA static volatile portBASE_TYPE xYieldPending                                            = ( portBASE_TYPE ) pdFALSE;\r
+PRIVILEGED_DATA static volatile portBASE_TYPE xYieldPending                                    = pdFALSE;\r
 PRIVILEGED_DATA static volatile portBASE_TYPE xNumOfOverflows                                  = ( portBASE_TYPE ) 0;\r
 PRIVILEGED_DATA static unsigned portBASE_TYPE uxTaskNumber                                             = ( unsigned portBASE_TYPE ) 0U;\r
-PRIVILEGED_DATA static volatile portTickType xNextTaskUnblockTime                              = ( portTickType ) portMAX_DELAY;\r
+PRIVILEGED_DATA static volatile portTickType xNextTaskUnblockTime                              = portMAX_DELAY;\r
 \r
 #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
 \r
        PRIVILEGED_DATA static unsigned long ulTaskSwitchedInTime = 0UL;        /*< Holds the value of a timer/counter the last time a task was switched in. */\r
-       PRIVILEGED_DATA static unsigned long ulTotalRunTime = 0UL;                              /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
+       PRIVILEGED_DATA static unsigned long ulTotalRunTime = 0UL;                      /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
 \r
 #endif\r
 \r
+/*lint +e956 */\r
+\r
 /* Debugging and trace facilities private variables and macros. ------------*/\r
 \r
 /*\r
@@ -357,7 +371,7 @@ count overflows. */
 #define prvAddTaskToReadyList( pxTCB )                                                                                                                                                         \\r
        traceMOVED_TASK_TO_READY_STATE( pxTCB )                                                                                                                                                 \\r
        taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority );                                                                                                                             \\r
-       vListInsertEnd( ( xList * ) &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) )\r
+       vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) )\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -471,8 +485,6 @@ static tskTCB *prvAllocateTCBAndStack( unsigned short usStackDepth, portSTACK_TY
 \r
 #endif\r
 \r
-/*lint +e956 */\r
-\r
 signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions )\r
 {\r
 signed portBASE_TYPE xReturn;\r
@@ -510,7 +522,7 @@ tskTCB * pxNewTCB;
                #if( portSTACK_GROWTH < 0 )\r
                {\r
                        pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - ( unsigned short ) 1 );\r
-                       pxTopOfStack = ( portSTACK_TYPE * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK  ) );\r
+                       pxTopOfStack = ( portSTACK_TYPE * ) ( ( ( 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( ( ( ( unsigned long ) pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
@@ -587,13 +599,6 @@ tskTCB * pxNewTCB;
                                }\r
                        }\r
 \r
-                       /* Remember the top priority to make context switching faster.  Use\r
-                       the priority in pxNewTCB as this has been capped to a valid value. */\r
-                       if( pxNewTCB->uxPriority > uxTopUsedPriority )\r
-                       {\r
-                               uxTopUsedPriority = pxNewTCB->uxPriority;\r
-                       }\r
-\r
                        uxTaskNumber++;\r
 \r
                        #if ( configUSE_TRACE_FACILITY == 1 )\r
@@ -656,18 +661,18 @@ tskTCB * pxNewTCB;
                        This will stop the task from be scheduled.  The idle task will check\r
                        the termination list and free up any memory allocated by the\r
                        scheduler for the TCB and stack. */\r
-                       if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                       if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                        {\r
                                taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
                        }\r
 \r
                        /* Is the task waiting on an event also? */\r
-                       if( pxTCB->xEventListItem.pvContainer != NULL )\r
+                       if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
                        {\r
-                               uxListRemove( &( pxTCB->xEventListItem ) );\r
+                               ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
                        }\r
 \r
-                       vListInsertEnd( ( xList * ) &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) );\r
+                       vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) );\r
 \r
                        /* Increment the ucTasksDeleted variable so the idle task knows\r
                        there is a task that has been deleted and that it should therefore\r
@@ -685,7 +690,7 @@ tskTCB * pxNewTCB;
                /* Force a reschedule if we have just deleted the current task. */\r
                if( xSchedulerRunning != pdFALSE )\r
                {\r
-                       if( ( void * ) xTaskToDelete == NULL )\r
+                       if( ( void * ) xTaskToDelete ==  NULL ) /*lint !e961 MISRA exception as this is not a redundant cast when used with some supported compilers. */\r
                        {\r
                                portYIELD_WITHIN_API();\r
                        }\r
@@ -707,17 +712,21 @@ tskTCB * pxNewTCB;
 \r
                vTaskSuspendAll();\r
                {\r
+                       /* Minor optimisation.  The tick count cannot change in this\r
+                       block. */\r
+                       const portTickType xConstTickCount = xTickCount;\r
+\r
                        /* Generate the tick time at which the task wants to wake. */\r
                        xTimeToWake = *pxPreviousWakeTime + xTimeIncrement;\r
 \r
-                       if( xTickCount < *pxPreviousWakeTime )\r
+                       if( xConstTickCount < *pxPreviousWakeTime )\r
                        {\r
                                /* The tick count has overflowed since this function was\r
                                lasted called.  In this case the only time we should ever\r
                                actually delay is if the wake time has also     overflowed,\r
                                and the wake time is greater than the tick time.  When this\r
                                is the case it is as if neither time had overflowed. */\r
-                               if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xTickCount ) )\r
+                               if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xConstTickCount ) )\r
                                {\r
                                        xShouldDelay = pdTRUE;\r
                                }\r
@@ -727,7 +736,7 @@ tskTCB * pxNewTCB;
                                /* The tick time has not overflowed.  In this case we will\r
                                delay if either the wake time has overflowed, and/or the\r
                                tick time is less than the wake time. */\r
-                               if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xTickCount ) )\r
+                               if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xConstTickCount ) )\r
                                {\r
                                        xShouldDelay = pdTRUE;\r
                                }\r
@@ -743,7 +752,7 @@ tskTCB * pxNewTCB;
                                /* We must remove ourselves from the ready list before adding\r
                                ourselves to the blocked list as the same list item is used for\r
                                both lists. */\r
-                               if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )\r
+                               if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                                {\r
                                        /* The current task must be in a ready list, so there is\r
                                        no need to check, and the port reset macro can be called\r
@@ -796,7 +805,7 @@ tskTCB * pxNewTCB;
                                /* We must remove ourselves from the ready list before adding\r
                                ourselves to the blocked list as the same list item is used for\r
                                both lists. */\r
-                               if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )\r
+                               if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                                {\r
                                        /* The current task must be in a ready list, so there is\r
                                        no need to check, and the port reset macro can be called\r
@@ -825,9 +834,7 @@ tskTCB * pxNewTCB;
        {\r
        eTaskState eReturn;\r
        xList *pxStateList;\r
-       tskTCB *pxTCB;\r
-\r
-               pxTCB = ( tskTCB * ) xTask;\r
+       const tskTCB * const pxTCB = ( tskTCB * ) xTask;\r
 \r
                if( pxTCB == pxCurrentTCB )\r
                {\r
@@ -914,9 +921,9 @@ tskTCB * pxNewTCB;
                configASSERT( ( uxNewPriority < configMAX_PRIORITIES ) );\r
 \r
                /* Ensure the new priority is valid. */\r
-               if( uxNewPriority >= configMAX_PRIORITIES )\r
+               if( uxNewPriority >= ( unsigned portBASE_TYPE ) configMAX_PRIORITIES )\r
                {\r
-                       uxNewPriority = configMAX_PRIORITIES - ( unsigned portBASE_TYPE ) 1U;\r
+                       uxNewPriority = ( unsigned portBASE_TYPE ) configMAX_PRIORITIES - ( unsigned portBASE_TYPE ) 1U;\r
                }\r
 \r
                taskENTER_CRITICAL();\r
@@ -963,6 +970,10 @@ tskTCB * pxNewTCB;
                                        task of higher priority that is ready to execute. */\r
                                        xYieldRequired = pdTRUE;\r
                                }\r
+                               else\r
+                               {\r
+                                       /* Yield not required. */\r
+                               }\r
 \r
                                /* Remember the ready list the task might be referenced from\r
                                before its uxPriority member is changed so the\r
@@ -987,18 +998,18 @@ tskTCB * pxNewTCB;
                                }\r
                                #endif\r
 \r
-                               listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( configMAX_PRIORITIES - ( portTickType ) uxNewPriority ) );\r
+                               listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( portTickType ) configMAX_PRIORITIES - ( portTickType ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
 \r
                                /* If the task is in the blocked or suspended list we need do\r
                                nothing more than change it's priority variable. However, if\r
                                the task is in a ready list it needs to be removed and placed\r
                                in the queue appropriate to its new priority. */\r
-                               if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxCurrentPriority ] ), &( pxTCB->xGenericListItem ) ) )\r
+                               if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxCurrentPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
                                {\r
                                        /* The task is currently in its ready list - remove before adding\r
                                        it to it's new ready list.  As we are in a critical section we\r
                                        can do this even if the scheduler is suspended. */\r
-                                       if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                                       if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                                        {\r
                                                taskRESET_READY_PRIORITY( uxPriorityUsedOnEntry );\r
                                        }\r
@@ -1042,22 +1053,22 @@ tskTCB * pxNewTCB;
                        traceTASK_SUSPEND( pxTCB );\r
 \r
                        /* Remove task from the ready/delayed list and place in the     suspended list. */\r
-                       if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                       if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                        {\r
                                taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
                        }\r
 \r
                        /* Is the task waiting on an event also? */\r
-                       if( pxTCB->xEventListItem.pvContainer != NULL )\r
+                       if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
                        {\r
-                               uxListRemove( &( pxTCB->xEventListItem ) );\r
+                               ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
                        }\r
 \r
-                       vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );\r
+                       vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );\r
                }\r
                taskEXIT_CRITICAL();\r
 \r
-               if( ( void * ) xTaskToSuspend == NULL )\r
+               if( ( void * ) xTaskToSuspend == NULL ) /*lint !e961 MISRA exception justified because it is not a redundant cast for some supported compilers. */\r
                {\r
                        if( xSchedulerRunning != pdFALSE )\r
                        {\r
@@ -1103,13 +1114,13 @@ tskTCB * pxNewTCB;
                if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
                {\r
                        /* Has the task already been resumed from within an ISR? */\r
-                       if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) != pdTRUE )\r
+                       if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) == pdFALSE )\r
                        {\r
                                /* Is it in the suspended list because it is in the\r
                                Suspended state?  It is possible to be in the suspended\r
                                list because it is blocked on a task with no timeout\r
                                specified. */\r
-                               if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) == pdTRUE )\r
+                               if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) != pdFALSE )\r
                                {\r
                                        xReturn = pdTRUE;\r
                                }\r
@@ -1117,7 +1128,7 @@ tskTCB * pxNewTCB;
                }\r
 \r
                return xReturn;\r
-       }\r
+       } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */\r
 \r
 #endif /* INCLUDE_vTaskSuspend */\r
 /*-----------------------------------------------------------*/\r
@@ -1126,15 +1137,11 @@ tskTCB * pxNewTCB;
 \r
        void vTaskResume( xTaskHandle xTaskToResume )\r
        {\r
-       tskTCB *pxTCB;\r
+       tskTCB * const pxTCB = ( tskTCB * ) xTaskToResume;\r
 \r
                /* It does not make sense to resume the calling task. */\r
                configASSERT( xTaskToResume );\r
 \r
-               /* Remove the task from whichever list it is currently in, and place\r
-               it in the ready list. */\r
-               pxTCB = ( tskTCB * ) xTaskToResume;\r
-\r
                /* The parameter cannot be NULL as it is impossible to resume the\r
                currently executing task. */\r
                if( ( pxTCB != NULL ) && ( pxTCB != pxCurrentTCB ) )\r
@@ -1147,7 +1154,7 @@ tskTCB * pxNewTCB;
 \r
                                        /* As we are in a critical section we can access the ready\r
                                        lists even if the scheduler is suspended. */\r
-                                       uxListRemove(  &( pxTCB->xGenericListItem ) );\r
+                                       ( void ) uxListRemove(  &( pxTCB->xGenericListItem ) );\r
                                        prvAddTaskToReadyList( pxTCB );\r
 \r
                                        /* We may have just resumed a higher priority task. */\r
@@ -1172,12 +1179,28 @@ tskTCB * pxNewTCB;
        portBASE_TYPE xTaskResumeFromISR( xTaskHandle xTaskToResume )\r
        {\r
        portBASE_TYPE xYieldRequired = pdFALSE;\r
-       tskTCB *pxTCB;\r
+       tskTCB * const pxTCB = ( tskTCB * ) xTaskToResume;\r
        unsigned portBASE_TYPE uxSavedInterruptStatus;\r
 \r
                configASSERT( xTaskToResume );\r
 \r
-               pxTCB = ( tskTCB * ) xTaskToResume;\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
                uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
                {\r
@@ -1188,7 +1211,7 @@ tskTCB * pxNewTCB;
                                if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
                                {\r
                                        xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority );\r
-                                       uxListRemove(  &( pxTCB->xGenericListItem ) );\r
+                                       ( void ) uxListRemove(  &( pxTCB->xGenericListItem ) );\r
                                        prvAddTaskToReadyList( pxTCB );\r
                                }\r
                                else\r
@@ -1196,7 +1219,7 @@ tskTCB * pxNewTCB;
                                        /* We cannot access the delayed or ready lists, so will hold this\r
                                        task pending until the scheduler is resumed, at which point a\r
                                        yield will be performed if necessary. */\r
-                                       vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+                                       vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
                                }\r
                        }\r
                }\r
@@ -1217,12 +1240,12 @@ portBASE_TYPE xReturn;
        {\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
+               xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( 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
        }\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
+               xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL );  /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
        }\r
        #endif /* INCLUDE_xTaskGetIdleTaskHandle */\r
 \r
@@ -1326,8 +1349,8 @@ void vTaskSuspendAll( void )
 \r
 signed portBASE_TYPE xTaskResumeAll( void )\r
 {\r
-register tskTCB *pxTCB;\r
-signed portBASE_TYPE xAlreadyYielded = pdFALSE;\r
+tskTCB *pxTCB;\r
+portBASE_TYPE xAlreadyYielded = pdFALSE;\r
 portBASE_TYPE xYieldRequired = pdFALSE;\r
 \r
        /* If uxSchedulerSuspended is zero then this function does not match a\r
@@ -1349,11 +1372,11 @@ portBASE_TYPE xYieldRequired = pdFALSE;
                        {\r
                                /* Move any readied tasks from the pending list into the\r
                                appropriate ready list. */\r
-                               while( listLIST_IS_EMPTY( ( xList * ) &xPendingReadyList ) == pdFALSE )\r
+                               while( listLIST_IS_EMPTY( &xPendingReadyList ) == pdFALSE )\r
                                {\r
-                                       pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY(  ( ( xList * ) &xPendingReadyList ) );\r
-                                       uxListRemove( &( pxTCB->xEventListItem ) );\r
-                                       uxListRemove( &( pxTCB->xGenericListItem ) );\r
+                                       pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) );\r
+                                       ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
+                                       ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
                                        prvAddTaskToReadyList( pxTCB );\r
 \r
                                        /* If we have moved a task that has a priority higher than\r
@@ -1414,6 +1437,22 @@ portTickType xTaskGetTickCountFromISR( void )
 portTickType xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
 \r
+       /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+       system call (or maximum API call) interrupt priority.  Interrupts that are\r
+       above the maximum system call priority are keep permanently enabled, even\r
+       when the RTOS kernel is in a critical section, but cannot make any calls to\r
+       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
+       then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+       failure if a FreeRTOS API function is called from an interrupt that has been\r
+       assigned a priority above the configured maximum system call priority.\r
+       Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+       that have been assigned a priority at or (logically) below the maximum\r
+       system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
+       safe API to ensure interrupt entry is as fast and as simple as possible.\r
+       More information (albeit Cortex-M specific) is provided on the following\r
+       link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+       portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
        uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
        xReturn = xTickCount;\r
        portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
@@ -1461,9 +1500,9 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
                                do\r
                                {\r
                                        uxQueue--;\r
-                                       uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), eReady );\r
+                                       uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady );\r
 \r
-                               }while( uxQueue > ( unsigned short ) tskIDLE_PRIORITY );\r
+                               } while( uxQueue > ( unsigned portBASE_TYPE ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
 \r
                                /* Fill in an xTaskStatusType structure with information on each\r
                                task in the Blocked state. */\r
@@ -1472,7 +1511,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
                                #if( INCLUDE_vTaskDelete == 1 )\r
                                {\r
-                                       /* Fill in an xTaskStatusType structure with information on \r
+                                       /* Fill in an xTaskStatusType structure with information on\r
                                        each task that has been deleted but not yet cleaned up. */\r
                                        uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted );\r
                                }\r
@@ -1480,7 +1519,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
                                #if ( INCLUDE_vTaskSuspend == 1 )\r
                                {\r
-                                       /* Fill in an xTaskStatusType structure with information on \r
+                                       /* Fill in an xTaskStatusType structure with information on\r
                                        each task in the Suspended state. */\r
                                        uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended );\r
                                }\r
@@ -1488,16 +1527,22 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
                                #if ( configGENERATE_RUN_TIME_STATS == 1)\r
                                {\r
-                                       *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+                                       if( pulTotalRunTime != NULL )\r
+                                       {\r
+                                               *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+                                       }\r
                                }\r
                                #else\r
                                {\r
-                                       *pulTotalRunTime = 0;\r
+                                       if( pulTotalRunTime != NULL )\r
+                                       {\r
+                                               *pulTotalRunTime = 0;\r
+                                       }\r
                                }\r
                                #endif\r
                        }\r
                }\r
-               xTaskResumeAll();\r
+               ( void ) xTaskResumeAll();\r
 \r
                return uxTask;\r
        }\r
@@ -1551,75 +1596,82 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
                /* Increment the RTOS tick, switching the delayed and overflowed\r
                delayed lists if it wraps to 0. */\r
                ++xTickCount;\r
-               if( xTickCount == ( portTickType ) 0U )\r
-               {\r
-                       taskSWITCH_DELAYED_LISTS();\r
-               }\r
 \r
-               /* See if this tick has made a timeout expire.  Tasks are stored in the\r
-               queue in the order of their wake time - meaning once one tasks has been\r
-               found whose block time has not expired there is no need not look any\r
-               further down the list. */\r
-               if( xTickCount >= xNextTaskUnblockTime )\r
                {\r
-                       for( ;; )\r
+                       /* Minor optimisation.  The tick count cannot change in this\r
+                       block. */\r
+                       const portTickType xConstTickCount = xTickCount;\r
+\r
+                       if( xConstTickCount == ( portTickType ) 0U )\r
                        {\r
-                               if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
-                               {\r
-                                       /* The delayed list is empty.  Set xNextTaskUnblockTime to\r
-                                       the     maximum possible value so it is extremely unlikely that\r
-                                       the if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
-                                       next time through. */\r
-                                       xNextTaskUnblockTime = portMAX_DELAY;\r
-                                       break;\r
-                               }\r
-                               else\r
+                               taskSWITCH_DELAYED_LISTS();\r
+                       }\r
+\r
+                       /* See if this tick has made a timeout expire.  Tasks are stored in the\r
+                       queue in the order of their wake time - meaning once one tasks has been\r
+                       found whose block time has not expired there is no need not look any\r
+                       further down the list. */\r
+                       if( xConstTickCount >= xNextTaskUnblockTime )\r
+                       {\r
+                               for( ;; )\r
                                {\r
-                                       /* The delayed list is not empty, get the value of the item\r
-                                       at the head of the delayed list.  This is the time at which\r
-                                       the task at the head of the delayed list must be removed\r
-                                       from the Blocked state. */\r
-                                       pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
-                                       xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
-\r
-                                       if( xTickCount < xItemValue )\r
+                                       if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
                                        {\r
-                                               /* It is not time to unblock this item yet, but the item\r
-                                               value is the time at which the task at the head of the\r
-                                               blocked list must be removed from the Blocked state -\r
-                                               so record the item value in xNextTaskUnblockTime. */\r
-                                               xNextTaskUnblockTime = xItemValue;\r
+                                               /* The delayed list is empty.  Set xNextTaskUnblockTime to\r
+                                               the     maximum possible value so it is extremely unlikely that\r
+                                               the if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
+                                               next time through. */\r
+                                               xNextTaskUnblockTime = portMAX_DELAY;\r
                                                break;\r
                                        }\r
+                                       else\r
+                                       {\r
+                                               /* The delayed list is not empty, get the value of the item\r
+                                               at the head of the delayed list.  This is the time at which\r
+                                               the task at the head of the delayed list must be removed\r
+                                               from the Blocked state. */\r
+                                               pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
+                                               xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
+\r
+                                               if( xConstTickCount < xItemValue )\r
+                                               {\r
+                                                       /* It is not time to unblock this item yet, but the item\r
+                                                       value is the time at which the task at the head of the\r
+                                                       blocked list must be removed from the Blocked state -\r
+                                                       so record the item value in xNextTaskUnblockTime. */\r
+                                                       xNextTaskUnblockTime = xItemValue;\r
+                                                       break;\r
+                                               }\r
 \r
-                                       /* It is time to remove the item from the Blocked state. */\r
-                                       uxListRemove( &( pxTCB->xGenericListItem ) );\r
+                                               /* It is time to remove the item from the Blocked state. */\r
+                                               ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
 \r
-                                       /* Is the task waiting on an event also?  If so remove it\r
-                                       from the event list. */\r
-                                       if( pxTCB->xEventListItem.pvContainer != NULL )\r
-                                       {\r
-                                               uxListRemove( &( pxTCB->xEventListItem ) );\r
-                                       }\r
+                                               /* Is the task waiting on an event also?  If so remove it\r
+                                               from the event list. */\r
+                                               if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
+                                               {\r
+                                                       ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
+                                               }\r
 \r
-                                       /* Place the unblocked task into the appropriate ready\r
-                                       list. */\r
-                                       prvAddTaskToReadyList( pxTCB );\r
+                                               /* Place the unblocked task into the appropriate ready\r
+                                               list. */\r
+                                               prvAddTaskToReadyList( pxTCB );\r
 \r
-                                       /* A task being unblocked cannot cause an immediate context\r
-                                       switch if preemption is turned off. */\r
-                                       #if (  configUSE_PREEMPTION == 1 )\r
-                                       {\r
-                                               /* Preemption is on, but a context switch should only\r
-                                               be performed if the unblocked task has a priority that\r
-                                               is equal to or higher than the currently executing\r
-                                               task. */\r
-                                               if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+                                               /* A task being unblocked cannot cause an immediate context\r
+                                               switch if preemption is turned off. */\r
+                                               #if (  configUSE_PREEMPTION == 1 )\r
                                                {\r
-                                                       xSwitchRequired = pdTRUE;\r
+                                                       /* Preemption is on, but a context switch should only\r
+                                                       be performed if the unblocked task has a priority that\r
+                                                       is equal to or higher than the currently executing\r
+                                                       task. */\r
+                                                       if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+                                                       {\r
+                                                               xSwitchRequired = pdTRUE;\r
+                                                       }\r
                                                }\r
+                                               #endif /* configUSE_PREEMPTION */\r
                                        }\r
-                                       #endif /* configUSE_PREEMPTION */\r
                                }\r
                        }\r
                }\r
@@ -1629,7 +1681,7 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
                writer has not explicitly turned time slicing off. */\r
                #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) )\r
                {\r
-                       if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB->uxPriority ] ) ) > 1 )\r
+                       if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB->uxPriority ] ) ) > ( unsigned portBASE_TYPE ) 1 )\r
                        {\r
                                xSwitchRequired = pdTRUE;\r
                        }\r
@@ -1804,7 +1856,7 @@ void vTaskSwitchContext( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait )\r
+void vTaskPlaceOnEventList( xList * const pxEventList, portTickType xTicksToWait )\r
 {\r
 portTickType xTimeToWake;\r
 \r
@@ -1816,12 +1868,12 @@ portTickType xTimeToWake;
        /* Place the event list item of the TCB in the appropriate event list.\r
        This is placed in the list in priority order so the highest priority task\r
        is the first to be woken by the event. */\r
-       vListInsert( ( xList * ) pxEventList, ( xListItem * ) &( pxCurrentTCB->xEventListItem ) );\r
+       vListInsert( pxEventList, &( pxCurrentTCB->xEventListItem ) );\r
 \r
        /* We must remove ourselves from the ready list before adding ourselves\r
        to the blocked list as the same list item is used for both lists.  We have\r
        exclusive access to the ready lists as the scheduler is locked. */\r
-       if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )\r
+       if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
        {\r
                /* The current task must be in a ready list, so there is no need to\r
                check, and the port reset macro can be called directly. */\r
@@ -1835,7 +1887,7 @@ portTickType xTimeToWake;
                        /* Add ourselves to the suspended task list instead of a delayed task\r
                        list to ensure we are not woken by a timing event.  We will block\r
                        indefinitely. */\r
-                       vListInsertEnd( ( xList * ) &xSuspendedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+                       vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
                }\r
                else\r
                {\r
@@ -1858,7 +1910,7 @@ portTickType xTimeToWake;
 \r
 #if configUSE_TIMERS == 1\r
 \r
-       void vTaskPlaceOnEventListRestricted( const xList * const pxEventList, portTickType xTicksToWait )\r
+       void vTaskPlaceOnEventListRestricted( xList * const pxEventList, portTickType xTicksToWait )\r
        {\r
        portTickType xTimeToWake;\r
 \r
@@ -1874,12 +1926,12 @@ portTickType xTimeToWake;
                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
+               vListInsertEnd( pxEventList, &( 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
-               if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )\r
+               if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                {\r
                        /* The current task must be in a ready list, so there is no need to\r
                        check, and the port reset macro can be called directly. */\r
@@ -1917,18 +1969,18 @@ portBASE_TYPE xReturn;
        pxEventList is not empty. */\r
        pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
        configASSERT( pxUnblockedTCB );\r
-       uxListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
+       ( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
 \r
        if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
        {\r
-               uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );\r
+               ( void ) uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );\r
                prvAddTaskToReadyList( pxUnblockedTCB );\r
        }\r
        else\r
        {\r
                /* We cannot access the delayed or ready lists, so will hold this\r
                task pending until the scheduler is resumed. */\r
-               vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxUnblockedTCB->xEventListItem ) );\r
+               vListInsertEnd( &( xPendingReadyList ), &( pxUnblockedTCB->xEventListItem ) );\r
        }\r
 \r
        if( pxUnblockedTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
@@ -1965,6 +2017,9 @@ portBASE_TYPE xReturn;
 \r
        taskENTER_CRITICAL();\r
        {\r
+               /* Minor optimisation.  The tick count cannot change in this block. */\r
+               const portTickType xConstTickCount = xTickCount;\r
+\r
                #if ( INCLUDE_vTaskSuspend == 1 )\r
                        /* If INCLUDE_vTaskSuspend is set to 1 and the block time specified is\r
                        the maximum block time then the task should block indefinitely, and\r
@@ -1976,7 +2031,7 @@ portBASE_TYPE xReturn;
                        else /* We are not blocking indefinitely, perform the checks below. */\r
                #endif\r
 \r
-               if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( ( portTickType ) xTickCount >= ( portTickType ) pxTimeOut->xTimeOnEntering ) )\r
+               if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xConstTickCount >= pxTimeOut->xTimeOnEntering ) ) /*lint !e525 Indentation preferred as is to make code within pre-processor directives clearer. */\r
                {\r
                        /* The tick count is greater than the time at which vTaskSetTimeout()\r
                        was called, but has also overflowed since vTaskSetTimeOut() was called.\r
@@ -1984,10 +2039,10 @@ portBASE_TYPE xReturn;
                        passed since vTaskSetTimeout() was called. */\r
                        xReturn = pdTRUE;\r
                }\r
-               else if( ( ( portTickType ) ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering ) ) < ( portTickType ) *pxTicksToWait )\r
+               else if( ( xConstTickCount - pxTimeOut->xTimeOnEntering ) < *pxTicksToWait )\r
                {\r
                        /* Not a genuine timeout. Adjust parameters for time remaining. */\r
-                       *pxTicksToWait -= ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering );\r
+                       *pxTicksToWait -= ( xConstTickCount -  pxTimeOut->xTimeOnEntering );\r
                        vTaskSetTimeOutState( pxTimeOut );\r
                        xReturn = pdFALSE;\r
                }\r
@@ -2143,7 +2198,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
                }\r
                #endif /* configUSE_TICKLESS_IDLE */\r
        }\r
-} /*lint !e715 pvParameters is not accessed but all task functions require the same prototype. */\r
+}\r
 /*-----------------------------------------------------------*/\r
 \r
 #if configUSE_TICKLESS_IDLE != 0\r
@@ -2188,10 +2243,10 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
 \r
 static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const pcName, unsigned portBASE_TYPE uxPriority, const xMemoryRegion * const xRegions, unsigned short usStackDepth )\r
 {\r
-portBASE_TYPE x;\r
+unsigned portBASE_TYPE x;\r
 \r
        /* Store the task name in the TCB. */\r
-       for( x = 0; x < configMAX_TASK_NAME_LEN; x++ )\r
+       for( x = ( unsigned portBASE_TYPE ) 0; x < ( unsigned portBASE_TYPE ) configMAX_TASK_NAME_LEN; x++ )\r
        {\r
                pxTCB->pcTaskName[ x ] = pcName[ x ];\r
 \r
@@ -2210,9 +2265,9 @@ portBASE_TYPE x;
 \r
        /* This is used as an array index so must ensure it's not too large.  First\r
        remove the privilege bit if one is present. */\r
-       if( uxPriority >= configMAX_PRIORITIES )\r
+       if( uxPriority >= ( unsigned portBASE_TYPE ) configMAX_PRIORITIES )\r
        {\r
-               uxPriority = configMAX_PRIORITIES - ( unsigned portBASE_TYPE ) 1U;\r
+               uxPriority = ( unsigned portBASE_TYPE ) configMAX_PRIORITIES - ( unsigned portBASE_TYPE ) 1U;\r
        }\r
 \r
        pxTCB->uxPriority = uxPriority;\r
@@ -2230,7 +2285,7 @@ portBASE_TYPE x;
        listSET_LIST_ITEM_OWNER( &( pxTCB->xGenericListItem ), pxTCB );\r
 \r
        /* Event lists are always in priority order. */\r
-       listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );\r
+       listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( portTickType ) configMAX_PRIORITIES - ( portTickType ) uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
        listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );\r
 \r
        #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
@@ -2295,24 +2350,24 @@ static void prvInitialiseTaskLists( void )
 {\r
 unsigned portBASE_TYPE uxPriority;\r
 \r
-       for( uxPriority = ( unsigned portBASE_TYPE ) 0U; uxPriority < configMAX_PRIORITIES; uxPriority++ )\r
+       for( uxPriority = ( unsigned portBASE_TYPE ) 0U; uxPriority < ( unsigned portBASE_TYPE ) configMAX_PRIORITIES; uxPriority++ )\r
        {\r
-               vListInitialise( ( xList * ) &( pxReadyTasksLists[ uxPriority ] ) );\r
+               vListInitialise( &( pxReadyTasksLists[ uxPriority ] ) );\r
        }\r
 \r
-       vListInitialise( ( xList * ) &xDelayedTaskList1 );\r
-       vListInitialise( ( xList * ) &xDelayedTaskList2 );\r
-       vListInitialise( ( xList * ) &xPendingReadyList );\r
+       vListInitialise( &xDelayedTaskList1 );\r
+       vListInitialise( &xDelayedTaskList2 );\r
+       vListInitialise( &xPendingReadyList );\r
 \r
        #if ( INCLUDE_vTaskDelete == 1 )\r
        {\r
-               vListInitialise( ( xList * ) &xTasksWaitingTermination );\r
+               vListInitialise( &xTasksWaitingTermination );\r
        }\r
        #endif /* INCLUDE_vTaskDelete */\r
 \r
        #if ( INCLUDE_vTaskSuspend == 1 )\r
        {\r
-               vListInitialise( ( xList * ) &xSuspendedTaskList );\r
+               vListInitialise( &xSuspendedTaskList );\r
        }\r
        #endif /* INCLUDE_vTaskSuspend */\r
 \r
@@ -2335,7 +2390,7 @@ static void prvCheckTasksWaitingTermination( void )
                {\r
                        vTaskSuspendAll();\r
                                xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );\r
-                       xTaskResumeAll();\r
+                       ( void ) xTaskResumeAll();\r
 \r
                        if( xListIsEmpty == pdFALSE )\r
                        {\r
@@ -2343,8 +2398,8 @@ static void prvCheckTasksWaitingTermination( void )
 \r
                                taskENTER_CRITICAL();\r
                                {\r
-                                       pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) );\r
-                                       uxListRemove( &( pxTCB->xGenericListItem ) );\r
+                                       pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xTasksWaitingTermination ) );\r
+                                       ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
                                        --uxCurrentNumberOfTasks;\r
                                        --uxTasksDeleted;\r
                                }\r
@@ -2366,12 +2421,12 @@ static void prvAddCurrentTaskToDelayedList( portTickType xTimeToWake )
        if( xTimeToWake < xTickCount )\r
        {\r
                /* Wake time has overflowed.  Place this item in the overflow list. */\r
-               vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+               vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
        }\r
        else\r
        {\r
                /* The wake time has not overflowed, so we can use the current block list. */\r
-               vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+               vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
 \r
                /* If the task entering the blocked state was placed at the head of the\r
                list of blocked tasks then xNextTaskUnblockTime needs to be updated\r
@@ -2397,7 +2452,7 @@ tskTCB *pxNewTCB;
                /* Allocate space for the stack used by the task being created.\r
                The base of the stack memory stored in the TCB so the task can\r
                be deleted later if required. */\r
-               pxNewTCB->pxStack = ( portSTACK_TYPE * ) pvPortMallocAligned( ( ( ( size_t )usStackDepth ) * sizeof( portSTACK_TYPE ) ), puxStackBuffer );\r
+               pxNewTCB->pxStack = ( portSTACK_TYPE * ) pvPortMallocAligned( ( ( ( size_t ) usStackDepth ) * sizeof( portSTACK_TYPE ) ), puxStackBuffer ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
 \r
                if( pxNewTCB->pxStack == NULL )\r
                {\r
@@ -2408,7 +2463,7 @@ tskTCB *pxNewTCB;
                else\r
                {\r
                        /* Just to help debugging. */\r
-                       memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( portSTACK_TYPE ) );\r
+                       ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( portSTACK_TYPE ) );\r
                }\r
        }\r
 \r
@@ -2423,11 +2478,11 @@ tskTCB *pxNewTCB;
        volatile tskTCB *pxNextTCB, *pxFirstTCB;\r
        unsigned portBASE_TYPE uxTask = 0;\r
 \r
-               if( listCURRENT_LIST_LENGTH( pxList ) > 0 )\r
-               {                       \r
+               if( listCURRENT_LIST_LENGTH( pxList ) > ( unsigned portBASE_TYPE ) 0 )\r
+               {\r
                        listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
-                       \r
-                       /* Populate an xTaskStatusType structure within the \r
+\r
+                       /* Populate an xTaskStatusType structure within the\r
                        pxTaskStatusArray array for each task that is referenced from\r
                        pxList.  See the definition of xTaskStatusType in task.h for the\r
                        meaning of each xTaskStatusType structure member. */\r
@@ -2595,7 +2650,7 @@ tskTCB *pxNewTCB;
 \r
 #if ( configUSE_MUTEXES == 1 )\r
 \r
-       void vTaskPriorityInherit( xTaskHandle const pxMutexHolder )\r
+       void vTaskPriorityInherit( xTaskHandle const pxMutexHolder )\r
        {\r
        tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder;\r
 \r
@@ -2606,13 +2661,13 @@ tskTCB *pxNewTCB;
                        if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )\r
                        {\r
                                /* Adjust the mutex holder state to account for its new priority. */\r
-                               listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority );\r
+                               listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( portTickType ) configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\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( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
                                {\r
-                                       if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                                       if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                                        {\r
                                                taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
                                        }\r
@@ -2637,7 +2692,7 @@ tskTCB *pxNewTCB;
 \r
 #if ( configUSE_MUTEXES == 1 )\r
 \r
-       void vTaskPriorityDisinherit( xTaskHandle const pxMutexHolder )\r
+       void vTaskPriorityDisinherit( xTaskHandle const pxMutexHolder )\r
        {\r
        tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder;\r
 \r
@@ -2647,7 +2702,7 @@ tskTCB *pxNewTCB;
                        {\r
                                /* We must be the running task to be able to give the mutex back.\r
                                Remove ourselves from the ready list we currently appear in. */\r
-                               if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                               if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                                {\r
                                        taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
                                }\r
@@ -2656,7 +2711,7 @@ tskTCB *pxNewTCB;
                                ready list. */\r
                                traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
                                pxTCB->uxPriority = pxTCB->uxBasePriority;\r
-                               listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxTCB->uxPriority );\r
+                               listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( portTickType ) configMAX_PRIORITIES - ( portTickType ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
                                prvAddTaskToReadyList( pxTCB );\r
                        }\r
                }\r
@@ -2707,7 +2762,6 @@ tskTCB *pxNewTCB;
        {\r
        xTaskStatusType *pxTaskStatusArray;\r
        volatile unsigned portBASE_TYPE uxArraySize, x;\r
-       unsigned long ulTotalRunTime;\r
        char cStatus;\r
 \r
                /*\r
@@ -2748,7 +2802,7 @@ tskTCB *pxNewTCB;
                if( pxTaskStatusArray != NULL )\r
                {\r
                        /* Generate the (binary) data. */\r
-                       uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );\r
+                       uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );\r
 \r
                        /* Create a human readable table from the binary data. */\r
                        for( x = 0; x < uxArraySize; x++ )\r
@@ -2791,7 +2845,7 @@ tskTCB *pxNewTCB;
        {\r
        xTaskStatusType *pxTaskStatusArray;\r
        volatile unsigned portBASE_TYPE uxArraySize, x;\r
-       unsigned long ulTotalRunTime, ulStatsAsPercentage;\r
+       unsigned long ulTotalTime, ulStatsAsPercentage;\r
 \r
                /*\r
                 * PLEASE NOTE:\r
@@ -2831,13 +2885,13 @@ tskTCB *pxNewTCB;
                if( pxTaskStatusArray != NULL )\r
                {\r
                        /* Generate the (binary) data. */\r
-                       uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );\r
+                       uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime );\r
 \r
                        /* For percentage calculations. */\r
-                       ulTotalRunTime /= 100UL;\r
+                       ulTotalTime /= 100UL;\r
 \r
                        /* Avoid divide by zero errors. */\r
-                       if( ulTotalRunTime > 0 )\r
+                       if( ulTotalTime > 0 )\r
                        {\r
                                /* Create a human readable table from the binary data. */\r
                                for( x = 0; x < uxArraySize; x++ )\r
@@ -2845,7 +2899,7 @@ tskTCB *pxNewTCB;
                                        /* What percentage of the total run time has the task used?\r
                                        This will always be rounded down to the nearest integer.\r
                                        ulTotalRunTimeDiv100 has already been divided by 100. */\r
-                                       ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;\r
+                                       ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;\r
 \r
                                        if( ulStatsAsPercentage > 0UL )\r
                                        {\r