RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

Use multiple timers to implement the 'hwtimer' core module

Open rousselk opened this issue 13 years ago • 5 comments

In order to offer more than 3 or 4 available instances of 'hwtimer' for a given system --- a feature that may prove useful and even necessary if "hard real-time" applications are to be built upon RIOT --- we will need to use more than one hardware timer to implement this core module.

The main problem to do this is that different hardware timers have different, independent counters; and as such, they may have different counter values at the same given instant.

Actually, the value of the reference counter is not an issue when you only use hwtimers in a relative manner (that is: use the hwtimer_set(), hwtimer_wait()/hwtimer_spin() functions) ; you only need to now the current counter value for a given timer when you use the hwtimer_set_absolute() function. Is such a function really needed? I couldn't find a place where it was used in current RIOT code...

if we need to keep the hwtimer_set_absolute() function, we will need to handle the different counter values problem: either the index of the timer to set must be specified so as the correct target counter value can be pre-calculated, or the function must adjust the target value given according to the timer that will be set. In any case, the signature of the hwtimer_arch_now() function will need to be modified, so as to pass as a parameter the index of the timer whose counter shall be read.

What is your opinion on this subject?

rousselk avatar Aug 23 '13 08:08 rousselk

I would prefer to save the offset of timerA and timerB at init and just user timerA counter for all functions. Whenever accesing timerB the value has to be adjusted with the offset to match timerA.

mmbabel avatar Aug 23 '13 12:08 mmbabel

Some initial thoughts on this issue: 1.) I agree that we need to extend the hwtimer implementation to use more than one timer. 2.) the only call of hwtimer_set_absolute() is in vtimer. Since we're planning to redesign this module, I don't see any reason for having such a function. 3.) We need to deal with the issue that the different timers might run at different speed anyway.

OlegHahm avatar Aug 26 '13 22:08 OlegHahm

re: 2) If we do not want to stick to the same issue that vtimer only supports only hwtimer in a specified range of bitwidth i see no way to avoid such a function to get notfied on the overflow. Also when no other part of RIOT uses this function, applications can may depend on this function. re: 3) When running different speed on the timers and setting the hwtimer in ticks, the signature of the functions has to be changed to make the hwtimer selectable, else you set an amount of ticks and do not know how long this will be (depending on the used timer). That way also the hwtimer_set_absolute() function can be called with the timer to use. But it will definitly not lighten the use of the hwtimers.

mmbabel avatar Aug 26 '13 23:08 mmbabel

re: 2) Maybe the vtimer module could be notified of overflow conditions by a callback mechanism? I too don't feel really comfortable with this hwtimer_set_absolute() function... As for the applications, I thought that, until now, hwtimer was to be used only by system modules (not applications) because of the limited number of hwtimer instances.

re: 3) Having timers with different speeds/frequencies will make the module much more complex. Maybe should we save this issue for later, and ensure that for now all the used timers run at the same speed?

rousselk avatar Aug 27 '13 08:08 rousselk

Will be superseded by xtimers.

OlegHahm avatar Aug 17 '15 21:08 OlegHahm