FreeRTOS源码解析 -> vTaskStartScheduler()

来源:互联网 发布:ubuntu如何搜索文件 编辑:程序博客网 时间:2024/05/16 07:32

       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 occurbefore or during the call to xPortStartScheduler().  The stacks ofthe created tasks contain a status word with interrupts switched onso interrupts will automatically get re-enabled when the first taskstarts to run.STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THEDEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. */portDISABLE_INTERRUPTS();        //调度器flag,用于判断调度器是否在运行xSchedulerRunning = pdTRUE;//计数器清零xTickCount = ( portTickType ) 0;/* If configGENERATE_RUN_TIME_STATS is defined then the followingmacro must be defined to configure the timer/counter used to generatethe run time counter time base. */portCONFIGURE_TIMER_FOR_RUN_TIME_STATS();        /* Setting up the timer tick is hardware specific and thus in theportable interface. *//*启动任务调度*/if( xPortStartScheduler() ){/* Should not reach here as if the scheduler is running thefunction 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 );}


0 0
原创粉丝点击