static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
uxCurrentNumberOfTasks++; 当前的任务数量加一(PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;)初始值为0
if( pxCurrentTCB == NULL )//没有任务在执行
if( uxCurrentNumberOfTasks == ( UBaseType_t ) 1 )
/* This is the first task to be created so do the preliminary initialisation required. We will not recover if this call fails, but we will report the failure. */
这个任务是第一个任务,所以要进行任务初始化,内部是初始化就绪、延时、挂起、等任务列表
prvInitialiseTaskLists();
static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
{
/* Ensure interrupts don't access the task lists while the lists are being
updated. */
taskENTER_CRITICAL();//进入临界区,仅关闭中断优先级小于5(可设置)的中断
{
uxCurrentNumberOfTasks++;//除去挂起的当前所有的任务数量加一(下面还有一个)
if( pxCurrentTCB == NULL )//判断有任务在执行吗变量TCB_t * volatile pxCurrentTCB //=NULL;指向当前任务(是一个任务控制块)
{
/* There are no other tasks, or all the other tasks are in
the suspended state - make this the current task. */
pxCurrentTCB = pxNewTCB;//指向当前任务
if( uxCurrentNumberOfTasks == ( UBaseType_t ) 1 )
{
/* This is the first task to be created so do the preliminary
initialisation required. We will not recover if this call
fails, but we will report the failure. */
prvInitialiseTaskLists();//这个任务是第一个任务,所以要进行任务初始化,内部是初始化 // 就绪、延时、挂起、等任务列表,
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else
{
/* If the scheduler is not already running, make this task the
current task if it is the highest priority task to be created
so far. */
if( xSchedulerRunning == pdFALSE )
{
if( pxCurrentTCB->uxPriority <= pxNewTCB->uxPriority )//判断新加入的任务的优先级
{
pxCurrentTCB = pxNewTCB;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
uxTaskNumber++;//总的任务数量,包括挂起的任务(上面的不包括)
prvAddTaskToReadyList( pxNewTCB );//放在下面
}
taskEXIT_CRITICAL();//退出,可以进行任务切换了,任务切换需要中断,上面把中断关了
}
prvAddTaskToReadyList( pxNewTCB );
vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) );
&( pxReadyTasksLists[ ( pxTCB )->uxPriority ] )//新增任务的优先级(就绪列表又根据优先级分类)例如pxReadyTasksLists[3]
&( ( pxTCB )->xStateListItem )//根据状态列表插入到列表的最后
void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
{
ListItem_t * const pxIndex = pxList->pxIndex;\
pxNewListItem->pxNext = pxIndex;
pxNewListItem->pxPrevious = pxIndex->pxPrevious;
pxIndex->pxPrevious->pxNext = pxNewListItem;
pxIndex->pxPrevious = pxNewListItem;
/* Remember which list the item is in. */
pxNewListItem->pvContainer = ( void * ) pxList;
( pxList->uxNumberOfItems )++;
}
/*-----------------------------------------------------------*/