OSTimeTick() basically consist of decrementing the OSTCBDly field for each OS_TCB (if it‘s nonzero).
OSTimeTick() follows the chain of OS_TCB starting at OSTCBList L3.20(2) until it reaches the idle task L3.20(3).
When the OSTCBDly field of a task’s OS_TCB is decremented to zero, the task is made ready to run L3.20(4).
The task is not readied, however, if it was explicitly suspended by OSTaskSuspend() L3.20(5).
The execution time of OSTimeTick() is directly proportional to the number of tasks created in an application.
void OSTimeTick (void) { OS_TCB *ptcb; OSTimeTickHook(); (1) ptcb = OSTCBList; (2) while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { (3) OS_ENTER_CRITICAL(); if (ptcb->OSTCBDly != 0) { if (--ptcb->OSTCBDly == 0) { if (!(ptcb->OSTCBStat & OS_STAT_SUSPEND)) { (5) OSRdyGrp |= ptcb->OSTCBBitY; (4) OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX; } else { ptcb->OSTCBDly = 1; } } } ptcb = ptcb->OSTCBNext; OS_EXIT_CRITICAL(); } OS_ENTER_CRITICAL(); (7) OSTime++; (6) OS_EXIT_CRITICAL(); }
OSTimeTick() also accumulates the number of clock ticks since power up in an unsigned 32-bit variable called OSTime L3.20(6).
Note that I disable interrupts L3.20(7) before incrementing OSTime because on some processors, a 32-bit increment will most likely be done using multiple instructions.