In the function void halSleep( uint16 osal_timeout ). I found there is one potential timer roll over issue that I am not very sure whether it is a bug.
During sleep timer setup process inside halSleep( uint16 osal_timeout ), the function void halSleepSetTimer(uint32 timeout) will first read the sleep timer value from registers (ST2,ST1, ST0) and assign this to halSleepTimerStart,
then later(after sleep time expires and sleep timer INT occurs), it will calculate the timer elapsed by calling
halAccumulatedSleepTime += (HalTimerElapsed() / TICK_COUNT);
where HalTimerElapsed() reads current sleep timer value from registers (ST2,ST1, ST0) and calculates the timer by subtracting halSleepTimerStart,
if sleep timer rolls over between halSleepSetTimer and HalTimerElapsed, then halSleepTimerStart could have a very high value(such as 0xFFFFFFF5) and later time reading will have low value (such as 0x000000001), subtracting ticks -= halSleepTimerStart in HalTimerElapsed() function will calculate a wrong value here as halAccumulatedSleepTime .(In this example, the real time elapsed should be 0x0000000C, but calculated value is 0xF000000C),
and this wrong value halAccumulatedSleepTime will be used later for osal_adjust_timers()(TimerElapsed()), which causes some other problems?
I am not sure whether I understand this correctly, some one can help me ?
Thanks
Rui