一種高效定時(shí)器模塊的設(shè)計(jì)與實(shí)現(xiàn)
可見,啟動(dòng)某個(gè)軟件定時(shí)器便是設(shè)置由timer_id枚舉的TIMER數(shù)組成員的各個(gè)成員變量,下面詳細(xì)介紹軟件定時(shí)器的運(yùn)行。
本文引用地址:http://cafeforensic.com/article/118088.htm作為所有軟件定時(shí)器的基準(zhǔn)源,硬件定時(shí)器設(shè)定為2ms的周期定時(shí),在時(shí)鐘中斷服務(wù)程序中全局時(shí)鐘嘀嗒Jiffs累加,TimerTicked置1,軟件定時(shí)器運(yùn)行函數(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;
}
評(píng)論