1.任务级调度器 OSSched()
系统初始化后会自动创建几个任务,可以看到所调用的创建任务函数OSTaskCreate的最后都会调用OSSched()函数(任务级调度器)。
Description: This function is called by other uC/OS-III services to determine whether a new, high priority task has been made ready to run. This function is invoked by TASK level code and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
该函数定义在os_core.c中,可以看到 该函数体中依次执行
CPU_INT_DIS();
OSPrioHighRdy = OS_PrioGetHighest();
CPU_INT_DIS(); // cpu_sr = CPU_SR_Save(); 关闭中断
OSPrioHighRdy = OS_PrioGetHighest(); //获取就绪任务的最高优先级
if (OS_CFG_TASK_IDLE_EN == DEF_ENABLED)
OSTCBHighRdyPtr = OSRdyList[OSPrioHighRdy].HeadPtr; //获取优先级最高的就绪任务
if (OSTCBHighRdyPtr == OSTCBCurPtr) //优先级最高的就绪任务为当前任务
{