sys/xtimer: multiple hardware timer support#9308
sys/xtimer: multiple hardware timer support#9308ZetaR60 wants to merge 2 commits intoRIOT-OS:masterfrom
Conversation
|
@ZetaR60 Send me an email, we should coordinate timer subsystem improvements to avoid doing the same work twice. |
|
Just to add my thoughts: using 3 timers is a high usage of resources or not? But maybe it is possible to just change the xtimer divider instead of using 2 timers. Maybe changing the divider if next target allows it to the biggest divider that is possible. This could allow multiple divider. Before take timer value converted to fastest tick base, add to xtimer_now counter, set timer to zero, change divider. In the overflow add one highest counter timer circle, based on actual divider. When new timer is set ensure divider is se to fastest tick base. When timer is fired set highest tick base. Take into Account that timer value is not in fastest tick base when read out. Something like this could work, IMHO. |
|
@Josar Thanks for the feedback. The reason for having a 3 timer example with different prescaler settings is to show that you can perform that trick with swapping the system clock prescaler and counter prescaler to get significant power gains. It is a use case for having multiple timers with the same API, which would not be possible if RTC support was added to xtimer in a simple way. As for your other suggestions: this PR will probably change radically or may be canceled depending on how other devs are working on xtimer. I will leave it up for now, and see how things go. |
|
@ZetaR60 I understand that, but what I meant is two timer one rtc for sleep and precision and one xtimer with changeable prescaler. It was also no criticism just a idea I was thinking about in the last days. One nice feature I was thinking about is interconnect the xtimer with the rtc. As the xtimer might slack or be too fast. If it is configured to be too fast it can be slowed down in every overflow cycle by comparing to the rtc and just wait some ticks. But I will first work on two other xtimer related things. #9211 #8990 |
Contribution description
This is a very WIP PR to add support for multiple hardware timers to xtimer. A hardware abstraction layer interfaces xtimer to the low-level timers, allowing easy addition and maintenance of low-level timers. Configuration should be reverse-compatible with the old configuration (requiring no alterations to board.h), but multiple timers can be added by creating an xtimer_params.h file, in the style of how the drivers work. I intend to have periph/timer, periph/rtt, and periph/rtc support added. It may also be possible to add support for drivers/ds1307 and similar discrete RTC modules, but I do not have one of these lying around.
One of my primary reasons for adding this is to create better support for sleep modes in xtimer. Consider the following example atmega1284p setup:
If the xtimer_sleep time is very short, then the 1MHz timer is used. If it is medium, then the 125kHz timer is used. If it is long then the 32 Hz timer is used. Here is the current used in different power modes (according to the datasheet at 3.3V):
Current state
sys/include/xtimer/hal.his incompletesys/xtimer/xtimer_hal.cis messy and does not reflect intended changesys/xtimer/xtimer.candsys/xtimer/xtimer_core.chaven't been altered yetxtimer headers may require some further alterations.
Nothing has been tested yet.
Posted mainly for discussion.
Issues/PRs references
This affects discussion of div / frac requirements in #9280 and #9283