voidOS_Sched(void){#ifOS_CRITICAL_METHOD ==3u/* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr =0u;#endifOS_ENTER_CRITICAL();if(OSIntNesting ==0u)/* Schedule only if all ISRs done and ... */{if(OSLockNesting ==0u)/* ... scheduler is not locked */{OS_SchedNew();
OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];if(OSPrioHighRdy != OSPrioCur)/* No Ctx Sw if current task is highest rdy */{#ifOS_TASK_PROFILE_EN >0u
OSTCBHighRdy->OSTCBCtxSwCtr++;/* Inc. # of context switches to this task */#endif
OSCtxSwCtr++;/* Increment context switch counter */OS_TASK_SW();/* Perform a context switch */}}}OS_EXIT_CRITICAL();}
发生中断,强制当前任务让渡CPU
voidOSIntExit(void){#ifOS_CRITICAL_METHOD ==3u/* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr =0u;#endifif(OSRunning == OS_TRUE){OS_ENTER_CRITICAL();if(OSIntNesting >0u)/* Prevent OSIntNesting from wrapping */{
OSIntNesting--;}if(OSIntNesting ==0u)/* Reschedule only if all ISRs complete ... */{if(OSLockNesting ==0u)/* ... and not locked. */{OS_SchedNew();
OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];if(OSPrioHighRdy != OSPrioCur)/* No Ctx Sw if current task is highest rdy */{#ifOS_TASK_PROFILE_EN >0u
OSTCBHighRdy->OSTCBCtxSwCtr++;/* Inc. # of context switches to this task */#endif
OSCtxSwCtr++;/* Keep track of the number of ctx switches */OSIntCtxSw();/* Perform interrupt level ctx switch */}}}OS_EXIT_CRITICAL();}}
就绪表(ucos_ii.h文件的函数)
OS_EXT OS_PRIO OSRdyTbl[OS_RDY_TBL_SIZE];/* Table of tasks which are ready to run */