一种高效定时器模块的设计与实现
可见,启动某个软件定时器便是设置由timer_id枚举的TIMER数组成员的各个成员变量,下面详细介绍软件定时器的运行。
本文引用地址:https://www.eepw.com.cn/article/118088.htm作为所有软件定时器的基准源,硬件定时器设定为2ms的周期定时,在时钟中断服务程序中全局时钟嘀嗒Jiffs累加,TimerTicked置1,软件定时器运行函数如下:
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;
}
评论