Question about hwtimer_now implementation..

Hello folks,

Thanks for the replies. My problem was the timer code wasn't quite making sense to me in terms of using a counting up value, and the low overflow threshold.

The FRDM-KL46Z is very similar to the Kinetis boards. The PIT module has two 32-bit channels each running at 24mhz. The channels can be chained together.

The solution I came up with is to use one channel for the time now value, and the other channel to provide the RIOT timer. Also, I modified vtimer, hwtimer, and board timer code to use 64-bit unsigned integers for the tick values - now a overflow doesn't happen until some 59,000+ years from boot, not in a few seconds as was previously happening.

I highly suggest going with a different implementation for the higher level timers to use a larger integer, or split it into seconds & microseconds (like timex_t). A 32-bit value is just way too low since a 1-mhz timer will overflow in just over a hour, or in a few seconds for boards like the KL46Z or Kinetis which have a higher clock rate.

The particular project I want to use this on has the requirement of both using short timers, in microseconds & seconds, and long timers that have durations in hours.

Thanks again for the help,

-- Michael

Hi Michael and everyone,

the timer structure we are using in RIOT at the moment is subject to some ongoing discussions at the moment. I think most of us agree, that we want to give the timer system a major overhaul, to make it cope better with the different requirements that arise from heterogeneous hardware support and wider time-spans.

For the current system it is important to understand the role of the different timers that we have at the moment: - vtimer: timer to be used in actual user application and networking code - hwtimer: not suited for long intervals, should be used by the vtimer and some device drivers that have strict timing requirements - periph/timer: very light weight abstraction of the actual MCU hardware timers - cpu/hwtimer.c: This file simply maps peripheral timers to the channels of the hwtimer (you can map more than 1 peripheral timer to the hwtimer...)

Hope this helps for now, I hope we get to re-designing the timer infrastructure soon...

Cheers, Hauke