{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_TCB *ptcb;
OSTimeTickHook(); /* Call user definable hook */
#if OS_TIME_GET_SET_EN > 0
OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
OSTime++; //(1)
OS_EXIT_CRITICAL();
#endif
if (OSRunning == TRUE) { //(2)
ptcb = OSTCBList; /* Point at first TCB in TCB list */
while (ptcb->OSTCBPrio != OS_IDLE_PRIO)
{ /* Go through all TCBs in TCB list */ //(3)
OS_ENTER_CRITICAL(); //(4)
if (ptcb->OSTCBDly != 0)
{ /* Delayed or waiting for event with TO */ //(5)
if (--ptcb->OSTCBDly == 0)
{ /* Decrement nbr of ticks to end of delay */ //(6)
if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY)
{ /* Is task suspended? */ //(7)
/* No, Make task R-to-R (timed out)*/
OSRdyGrp |= ptcb->OSTCBBitY;
OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX; //(8)
} else { /* Yes, Leave 1 tick to prevent loosing the task when the suspension is removed.*/
ptcb->OSTCBDly = 1; //(9)
}
}
}
ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */ //(10)
OS_EXIT_CRITICAL(); //(11)
}
}
}