前言.这篇文章可能稍长,需要你花点时间去理解.
这也是freertos核心.理解了它,其他的就不在话下了.
一.任务的启动
void vTaskStartScheduler( void )
{
BaseType_t xReturn;
xReturn = xTaskCreate( prvIdleTask,
configIDLE_TASK_NAME,
configMINIMAL_STACK_SIZE,
( void * ) NULL,
portPRIVILEGE_BIT,
&xIdleTaskHandle );
}
if( xReturn == pdPASS )
{
portDISABLE_INTERRUPTS();
xNextTaskUnblockTime = portMAX_DELAY;
xSchedulerRunning = pdTRUE;
xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;
portCONFIGURE_TIMER_FOR_RUN_TIME_STATS();
if( xPortStartScheduler() != pdFALSE )
{
/* 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(). */
}
}
/* Prevent compiler warnings if INCLUDE_xTaskGetIdleTaskHandle is set to 0,
meaning xIdleTaskHandle is not used anywhere else. */
( void ) xIdleTaskHandle;
}
1.首先创建IDLE任务.IDLE任务优先级最低.
2.初始化变量
xNextTaskUnblockTime = portMAX_DELAY;/*下一次任务启动的时间*/
xSchedulerRunning = pdTRUE;/*调度器标志开启*/
xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;/*时间戳置位*/
3.运行xPortStartScheduler函数,正常函数不会返回.
二.开启调度
xPortStartScheduler需要由移植层提供,这里