图 1
我设定在1MS的软定时器中 TimeCnt++;同时调用TimeDispatch()// 执行回调函数。
因为在 SetAlarm() 这个注册函数中
value值是根据timerscfg.h中的宏
// The timer is incrementing every 8 us.
//#define MS_TO_TIMEVAL(ms) ((ms) * 125)
//#define US_TO_TIMEVAL(us) ((us)>>3)
来确定分辨率的,我的Time_CNT 1ms ++ ,所以需改成
// The timer is incrementing every 1MS
#define MS_TO_TIMEVAL(ms) ((ms))
#define US_TO_TIMEVAL(us) ((us / 1000))
改完发现还是不正确
原函数
其中 getElapsedTime(void); 会在SetAlarm() 中被调用, 导致last_time_set 不正确,应将
last_time_set = TimeCNT; 放入中断函数中,如图1