ucos-ii 之 OSTimeTick


 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值