您的位置:首页 > 其它

FreeRTOS源码解析 -> vTaskStartScheduler()

2014-12-31 18:19 381 查看
       xPortStartScheduler()会在后面介绍port.c的时候详细说明。

void vTaskStartScheduler( void )
{
portBASE_TYPE xReturn;

/* Add the idle task at the lowest priority. */
/*空闲任务的责任是要将分配给已删除任务的内存释放掉。
在vTaskDelete()删除任务后,在prvIdleTask释放内存*/
xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), ( xTaskHandle * ) NULL );

#if ( configUSE_TIMERS == 1 )
{
if( xReturn == pdPASS )
{
xReturn = xTimerCreateTimerTask();
}
}
#endif

//上面的idle任务创建成功
if( xReturn == pdPASS )
{
/* Interrupts are turned off here, to ensure a tick does not occur
before or during the call to xPortStartScheduler().  The stacks of
the created tasks contain a status word with interrupts switched on
so interrupts will automatically get re-enabled when the first task
starts to run.

STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE
DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. */
portDISABLE_INTERRUPTS();

//调度器flag,用于判断调度器是否在运行
xSchedulerRunning = pdTRUE;
//计数器清零
xTickCount = ( portTickType ) 0;

/* If configGENERATE_RUN_TIME_STATS is defined then the following
macro must be defined to configure the timer/counter used to generate
the run time counter time base. */
portCONFIGURE_TIMER_FOR_RUN_TIME_STATS();

/* Setting up the timer tick is hardware specific and thus in the
portable interface. */
/*启动任务调度*/
if( xPortStartScheduler() )
{
/* Should not reach here as if the scheduler is running the
function will not return. */
}
else
{
/* Should only reach here if a task calls xTaskEndScheduler(). */
}
}

/* This line will only be reached if the kernel could not be started. */
configASSERT( xReturn );
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息