@ -201,7 +201,6 @@ PRIVILEGED_DATA static xList xPendingReadyList; /*< Tasks that have been r
/* File private variables. --------------------------------*/
/* File private variables. --------------------------------*/
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0U ;
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0U ;
PRIVILEGED_DATA static volatile portTickType xTickCount = ( portTickType ) 0U ;
PRIVILEGED_DATA static volatile portTickType xTickCount = ( portTickType ) 0U ;
PRIVILEGED_DATA static unsigned portBASE_TYPE uxTopUsedPriority = tskIDLE_PRIORITY ;
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxTopReadyPriority = tskIDLE_PRIORITY ;
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxTopReadyPriority = tskIDLE_PRIORITY ;
PRIVILEGED_DATA static volatile signed portBASE_TYPE xSchedulerRunning = pdFALSE ;
PRIVILEGED_DATA static volatile signed portBASE_TYPE xSchedulerRunning = pdFALSE ;
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxSchedulerSuspended = ( unsigned portBASE_TYPE ) pdFALSE ;
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxSchedulerSuspended = ( unsigned portBASE_TYPE ) pdFALSE ;
@ -587,13 +586,6 @@ tskTCB * pxNewTCB;
}
}
}
}
/* Remember the top priority to make context switching faster. Use
the priority in pxNewTCB as this has been capped to a valid value . */
if ( pxNewTCB - > uxPriority > uxTopUsedPriority )
{
uxTopUsedPriority = pxNewTCB - > uxPriority ;
}
uxTaskNumber + + ;
uxTaskNumber + + ;
# if ( configUSE_TRACE_FACILITY == 1 )
# if ( configUSE_TRACE_FACILITY == 1 )
@ -662,7 +654,7 @@ tskTCB * pxNewTCB;
}
}
/* Is the task waiting on an event also? */
/* Is the task waiting on an event also? */
if ( pxTCB - > xEventListItem . pvContainer ! = NULL )
if ( listLIST_ITEM_CONTAINER ( & ( pxTCB - > xEventListItem ) ) ! = NULL )
{
{
uxListRemove ( & ( pxTCB - > xEventListItem ) ) ;
uxListRemove ( & ( pxTCB - > xEventListItem ) ) ;
}
}
@ -707,17 +699,21 @@ tskTCB * pxNewTCB;
vTaskSuspendAll ( ) ;
vTaskSuspendAll ( ) ;
{
{
/* Minor optimisation. The tick count cannot change in this
block . */
const portTickType xConstTickCount = xTickCount ;
/* Generate the tick time at which the task wants to wake. */
/* Generate the tick time at which the task wants to wake. */
xTimeToWake = * pxPreviousWakeTime + xTimeIncrement ;
xTimeToWake = * pxPreviousWakeTime + xTimeIncrement ;
if ( xTickCount < * pxPreviousWakeTime )
if ( x Const TickCount < * pxPreviousWakeTime )
{
{
/* The tick count has overflowed since this function was
/* The tick count has overflowed since this function was
lasted called . In this case the only time we should ever
lasted called . In this case the only time we should ever
actually delay is if the wake time has also overflowed ,
actually delay is if the wake time has also overflowed ,
and the wake time is greater than the tick time . When this
and the wake time is greater than the tick time . When this
is the case it is as if neither time had overflowed . */
is the case it is as if neither time had overflowed . */
if ( ( xTimeToWake < * pxPreviousWakeTime ) & & ( xTimeToWake > x TickCount ) )
if ( ( xTimeToWake < * pxPreviousWakeTime ) & & ( xTimeToWake > x Const TickCount ) )
{
{
xShouldDelay = pdTRUE ;
xShouldDelay = pdTRUE ;
}
}
@ -727,7 +723,7 @@ tskTCB * pxNewTCB;
/* The tick time has not overflowed. In this case we will
/* The tick time has not overflowed. In this case we will
delay if either the wake time has overflowed , and / or the
delay if either the wake time has overflowed , and / or the
tick time is less than the wake time . */
tick time is less than the wake time . */
if ( ( xTimeToWake < * pxPreviousWakeTime ) | | ( xTimeToWake > x TickCount ) )
if ( ( xTimeToWake < * pxPreviousWakeTime ) | | ( xTimeToWake > x Const TickCount ) )
{
{
xShouldDelay = pdTRUE ;
xShouldDelay = pdTRUE ;
}
}
@ -825,9 +821,7 @@ tskTCB * pxNewTCB;
{
{
eTaskState eReturn ;
eTaskState eReturn ;
xList * pxStateList ;
xList * pxStateList ;
tskTCB * pxTCB ;
const tskTCB * const pxTCB = ( tskTCB * ) xTask ;
pxTCB = ( tskTCB * ) xTask ;
if ( pxTCB = = pxCurrentTCB )
if ( pxTCB = = pxCurrentTCB )
{
{
@ -1048,7 +1042,7 @@ tskTCB * pxNewTCB;
}
}
/* Is the task waiting on an event also? */
/* Is the task waiting on an event also? */
if ( pxTCB - > xEventListItem . pvContainer ! = NULL )
if ( listLIST_ITEM_CONTAINER ( & ( pxTCB - > xEventListItem ) ) ! = NULL )
{
{
uxListRemove ( & ( pxTCB - > xEventListItem ) ) ;
uxListRemove ( & ( pxTCB - > xEventListItem ) ) ;
}
}
@ -1126,15 +1120,11 @@ tskTCB * pxNewTCB;
void vTaskResume ( xTaskHandle xTaskToResume )
void vTaskResume ( xTaskHandle xTaskToResume )
{
{
tskTCB * pxTCB ;
tskTCB * const pxTCB = ( tskTCB * ) xTaskToResume ;
/* It does not make sense to resume the calling task. */
/* It does not make sense to resume the calling task. */
configASSERT ( xTaskToResume ) ;
configASSERT ( xTaskToResume ) ;
/* Remove the task from whichever list it is currently in, and place
it in the ready list . */
pxTCB = ( tskTCB * ) xTaskToResume ;
/* The parameter cannot be NULL as it is impossible to resume the
/* The parameter cannot be NULL as it is impossible to resume the
currently executing task . */
currently executing task . */
if ( ( pxTCB ! = NULL ) & & ( pxTCB ! = pxCurrentTCB ) )
if ( ( pxTCB ! = NULL ) & & ( pxTCB ! = pxCurrentTCB ) )
@ -1172,7 +1162,7 @@ tskTCB * pxNewTCB;
portBASE_TYPE xTaskResumeFromISR ( xTaskHandle xTaskToResume )
portBASE_TYPE xTaskResumeFromISR ( xTaskHandle xTaskToResume )
{
{
portBASE_TYPE xYieldRequired = pdFALSE ;
portBASE_TYPE xYieldRequired = pdFALSE ;
tskTCB * pxTCB ;
tskTCB * const pxTCB = ( tskTCB * ) xTaskToResume ;
unsigned portBASE_TYPE uxSavedInterruptStatus ;
unsigned portBASE_TYPE uxSavedInterruptStatus ;
configASSERT ( xTaskToResume ) ;
configASSERT ( xTaskToResume ) ;
@ -1195,8 +1185,6 @@ tskTCB * pxNewTCB;
http : //www.freertos.org/RTOS-Cortex-M3-M4.html */
http : //www.freertos.org/RTOS-Cortex-M3-M4.html */
portASSERT_IF_INTERRUPT_PRIORITY_INVALID ( ) ;
portASSERT_IF_INTERRUPT_PRIORITY_INVALID ( ) ;
pxTCB = ( tskTCB * ) xTaskToResume ;
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR ( ) ;
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR ( ) ;
{
{
if ( xTaskIsTaskSuspended ( pxTCB ) = = pdTRUE )
if ( xTaskIsTaskSuspended ( pxTCB ) = = pdTRUE )
@ -1521,13 +1509,19 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
# endif
# endif
# if ( configGENERATE_RUN_TIME_STATS == 1)
# if ( configGENERATE_RUN_TIME_STATS == 1)
{
if ( pulTotalRunTime ! = NULL )
{
{
* pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE ( ) ;
* pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE ( ) ;
}
}
}
# else
# else
{
if ( pulTotalRunTime ! = NULL )
{
{
* pulTotalRunTime = 0 ;
* pulTotalRunTime = 0 ;
}
}
}
# endif
# endif
}
}
}
}
@ -1585,7 +1579,13 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
/* Increment the RTOS tick, switching the delayed and overflowed
/* Increment the RTOS tick, switching the delayed and overflowed
delayed lists if it wraps to 0. */
delayed lists if it wraps to 0. */
+ + xTickCount ;
+ + xTickCount ;
if ( xTickCount = = ( portTickType ) 0U )
{
/* Minor optimisation. The tick count cannot change in this
block . */
const portTickType xConstTickCount = xTickCount ;
if ( xConstTickCount = = ( portTickType ) 0U )
{
{
taskSWITCH_DELAYED_LISTS ( ) ;
taskSWITCH_DELAYED_LISTS ( ) ;
}
}
@ -1594,7 +1594,7 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
queue in the order of their wake time - meaning once one tasks has been
queue in the order of their wake time - meaning once one tasks has been
found whose block time has not expired there is no need not look any
found whose block time has not expired there is no need not look any
further down the list . */
further down the list . */
if ( x TickCount > = xNextTaskUnblockTime )
if ( x Const TickCount > = xNextTaskUnblockTime )
{
{
for ( ; ; )
for ( ; ; )
{
{
@ -1616,7 +1616,7 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY ( pxDelayedTaskList ) ;
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY ( pxDelayedTaskList ) ;
xItemValue = listGET_LIST_ITEM_VALUE ( & ( pxTCB - > xGenericListItem ) ) ;
xItemValue = listGET_LIST_ITEM_VALUE ( & ( pxTCB - > xGenericListItem ) ) ;
if ( x TickCount < xItemValue )
if ( x Const TickCount < xItemValue )
{
{
/* It is not time to unblock this item yet, but the item
/* It is not time to unblock this item yet, but the item
value is the time at which the task at the head of the
value is the time at which the task at the head of the
@ -1631,7 +1631,7 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
/* Is the task waiting on an event also? If so remove it
/* Is the task waiting on an event also? If so remove it
from the event list . */
from the event list . */
if ( pxTCB - > xEventListItem . pvContainer ! = NULL )
if ( listLIST_ITEM_CONTAINER ( & ( pxTCB - > xEventListItem ) ) ! = NULL )
{
{
uxListRemove ( & ( pxTCB - > xEventListItem ) ) ;
uxListRemove ( & ( pxTCB - > xEventListItem ) ) ;
}
}
@ -1657,6 +1657,7 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
}
}
}
}
}
}
}
/* Tasks of equal priority to the currently running task will share
/* Tasks of equal priority to the currently running task will share
processing time ( time slice ) if preemption is on , and the application
processing time ( time slice ) if preemption is on , and the application
@ -1999,6 +2000,9 @@ portBASE_TYPE xReturn;
taskENTER_CRITICAL ( ) ;
taskENTER_CRITICAL ( ) ;
{
{
/* Minor optimisation. The tick count cannot change in this block. */
const portTickType xConstTickCount = xTickCount ;
# if ( INCLUDE_vTaskSuspend == 1 )
# if ( INCLUDE_vTaskSuspend == 1 )
/* If INCLUDE_vTaskSuspend is set to 1 and the block time specified is
/* If INCLUDE_vTaskSuspend is set to 1 and the block time specified is
the maximum block time then the task should block indefinitely , and
the maximum block time then the task should block indefinitely , and
@ -2010,7 +2014,7 @@ portBASE_TYPE xReturn;
else /* We are not blocking indefinitely, perform the checks below. */
else /* We are not blocking indefinitely, perform the checks below. */
# endif
# endif
if ( ( xNumOfOverflows ! = pxTimeOut - > xOverflowCount ) & & ( ( portTickType ) x TickCount > = ( portTickType ) pxTimeOut - > xTimeOnEntering ) )
if ( ( xNumOfOverflows ! = pxTimeOut - > xOverflowCount ) & & ( ( portTickType ) x Const TickCount > = ( portTickType ) pxTimeOut - > xTimeOnEntering ) )
{
{
/* The tick count is greater than the time at which vTaskSetTimeout()
/* The tick count is greater than the time at which vTaskSetTimeout()
was called , but has also overflowed since vTaskSetTimeOut ( ) was called .
was called , but has also overflowed since vTaskSetTimeOut ( ) was called .
@ -2018,10 +2022,10 @@ portBASE_TYPE xReturn;
passed since vTaskSetTimeout ( ) was called . */
passed since vTaskSetTimeout ( ) was called . */
xReturn = pdTRUE ;
xReturn = pdTRUE ;
}
}
else if ( ( ( portTickType ) ( ( portTickType ) x TickCount - ( portTickType ) pxTimeOut - > xTimeOnEntering ) ) < ( portTickType ) * pxTicksToWait )
else if ( ( ( portTickType ) ( ( portTickType ) x Const TickCount - ( portTickType ) pxTimeOut - > xTimeOnEntering ) ) < ( portTickType ) * pxTicksToWait )
{
{
/* Not a genuine timeout. Adjust parameters for time remaining. */
/* Not a genuine timeout. Adjust parameters for time remaining. */
* pxTicksToWait - = ( ( portTickType ) x TickCount - ( portTickType ) pxTimeOut - > xTimeOnEntering ) ;
* pxTicksToWait - = ( ( portTickType ) x Const TickCount - ( portTickType ) pxTimeOut - > xTimeOnEntering ) ;
vTaskSetTimeOutState ( pxTimeOut ) ;
vTaskSetTimeOutState ( pxTimeOut ) ;
xReturn = pdFALSE ;
xReturn = pdFALSE ;
}
}
@ -2741,7 +2745,6 @@ tskTCB *pxNewTCB;
{
{
xTaskStatusType * pxTaskStatusArray ;
xTaskStatusType * pxTaskStatusArray ;
volatile unsigned portBASE_TYPE uxArraySize , x ;
volatile unsigned portBASE_TYPE uxArraySize , x ;
unsigned long ulTotalRunTime ;
char cStatus ;
char cStatus ;
/*
/*
@ -2782,7 +2785,7 @@ tskTCB *pxNewTCB;
if ( pxTaskStatusArray ! = NULL )
if ( pxTaskStatusArray ! = NULL )
{
{
/* Generate the (binary) data. */
/* Generate the (binary) data. */
uxArraySize = xTaskGetSystemState ( pxTaskStatusArray , uxArraySize , & ulTotalRunTime ) ;
uxArraySize = xTaskGetSystemState ( pxTaskStatusArray , uxArraySize , NULL ) ;
/* Create a human readable table from the binary data. */
/* Create a human readable table from the binary data. */
for ( x = 0 ; x < uxArraySize ; x + + )
for ( x = 0 ; x < uxArraySize ; x + + )
@ -2825,7 +2828,7 @@ tskTCB *pxNewTCB;
{
{
xTaskStatusType * pxTaskStatusArray ;
xTaskStatusType * pxTaskStatusArray ;
volatile unsigned portBASE_TYPE uxArraySize , x ;
volatile unsigned portBASE_TYPE uxArraySize , x ;
unsigned long ulTotal Run Time, ulStatsAsPercentage ;
unsigned long ulTotal Time, ulStatsAsPercentage ;
/*
/*
* PLEASE NOTE :
* PLEASE NOTE :
@ -2865,13 +2868,13 @@ tskTCB *pxNewTCB;
if ( pxTaskStatusArray ! = NULL )
if ( pxTaskStatusArray ! = NULL )
{
{
/* Generate the (binary) data. */
/* Generate the (binary) data. */
uxArraySize = xTaskGetSystemState ( pxTaskStatusArray , uxArraySize , & ulTotal Run Time ) ;
uxArraySize = xTaskGetSystemState ( pxTaskStatusArray , uxArraySize , & ulTotal Time ) ;
/* For percentage calculations. */
/* For percentage calculations. */
ulTotal Run Time / = 100UL ;
ulTotal Time / = 100UL ;
/* Avoid divide by zero errors. */
/* Avoid divide by zero errors. */
if ( ulTotal Run Time > 0 )
if ( ulTotal Time > 0 )
{
{
/* Create a human readable table from the binary data. */
/* Create a human readable table from the binary data. */
for ( x = 0 ; x < uxArraySize ; x + + )
for ( x = 0 ; x < uxArraySize ; x + + )
@ -2879,7 +2882,7 @@ tskTCB *pxNewTCB;
/* What percentage of the total run time has the task used?
/* What percentage of the total run time has the task used?
This will always be rounded down to the nearest integer .
This will always be rounded down to the nearest integer .
ulTotalRunTimeDiv100 has already been divided by 100. */
ulTotalRunTimeDiv100 has already been divided by 100. */
ulStatsAsPercentage = pxTaskStatusArray [ x ] . ulRunTimeCounter / ulTotal Run Time;
ulStatsAsPercentage = pxTaskStatusArray [ x ] . ulRunTimeCounter / ulTotal Time;
if ( ulStatsAsPercentage > 0UL )
if ( ulStatsAsPercentage > 0UL )
{
{