34. 启动任务调度器

发布时间 2023-08-28 22:20:27作者: 一代枭雄

1. 开启任务调度器

vTaskStartScheduler()

void vTaskStartScheduler( void )
    if ( configSUPPORT_STATIC_ALLOCATION == 1 )
    {
            /* The Idle task is being created using dynamically allocated RAM. */
            //创建空闲任务
            xReturn = xTaskCreate( prvIdleTask,
                      configIDLE_TASK_NAME, //"IDLE"
                      configMINIMAL_STACK_SIZE, //128 word
                      ( void * ) NULL,
                        /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */
                       portPRIVILEGE_BIT, //#define portPRIVILEGE_BIT    ( ( UBaseType_t ) 0x00 )
                       &xIdleTaskHandle ); // static TaskHandle_t xIdleTaskHandle = NULL;
        
            #if ( configUSE_TIMERS == 1 )
            {
                if( xReturn == pdPASS )
                {
                    //创建软件定时器任务
                    xReturn = xTimerCreateTimerTask();
                }
            }
            #endif /* configUSE_TIMERS */
            
             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. */
                portDISABLE_INTERRUPTS();
                 
                xNextTaskUnblockTime = portMAX_DELAY;// #define portMAX_DELAY   ( TickType_t ) 0xffffffffUL
                xSchedulerRunning = pdTRUE;
                xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT; // #define configINITIAL_TICK_COUNT    0
                 
                if( xPortStartScheduler() != pdFALSE )
                {
                    /* Should not reach here as if the scheduler is running the
                     * function will not return. */
                }
             }
    }
 BaseType_t xTimerCreateTimerTask( void )
{
    BaseType_t xReturn = pdFAIL;