新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 一種高效定時(shí)器模塊的設(shè)計(jì)與實(shí)現(xiàn)

一種高效定時(shí)器模塊的設(shè)計(jì)與實(shí)現(xiàn)

作者: 時(shí)間:2011-03-25 來(lái)源:電子產(chǎn)品世界 收藏

  可見(jiàn),啟動(dòng)某個(gè)軟件定時(shí)器便是設(shè)置由timer_id枚舉的TIMER數(shù)組成員的各個(gè)成員變量,下面詳細(xì)介紹軟件定時(shí)器的運(yùn)行。

本文引用地址:http://butianyuan.cn/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)論


相關(guān)推薦

技術(shù)專(zhuān)區(qū)

關(guān)閉