一種高效定時(shí)器模塊的設計與實(shí)現
可見(jiàn),啟動(dòng)某個(gè)軟件定時(shí)器便是設置由timer_id枚舉的TIMER數組成員的各個(gè)成員變量,下面詳細介紹軟件定時(shí)器的運行。
本文引用地址:http://dyxdggzs.com/article/118088.htm作為所有軟件定時(shí)器的基準源,硬件定時(shí)器設定為2ms的周期定時(shí),在時(shí)鐘中斷服務(wù)程序中全局時(shí)鐘嘀嗒Jiffs累加,TimerTicked置1,軟件定時(shí)器運行函數如下:
void TimerTick(void)
{
uint timer_index;
if(0==TimerTicked)
{
return ;
}
for(timer_index=0;timer_index
{
if(RUNNING==TIMER[timer_index].timer_state)
{
TIMER[timer_index].duration++;
if(TIMER[timer_index].duration>=TIMER[timer_index].timeout)
{
TIMER[timer_index].overflow_ag=1;
if(TIMER[timer_index].cycle)
{
TimerReStart(timer_index);
}
else
{
TIMER[timer_index].cnt_times--;
if(0==TIMER[timer_index].cnt_times)
{
TimerStall(timer_index);
}
else
{
TimerReStart(timer_index);
}}}}}
TimerTicked=0;
}
評論