-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
periph/countdown: introduce Countdown timer interface #17159
base: master
Are you sure you want to change the base?
Conversation
febe804
to
5ab8297
Compare
0e3fb10
to
88d0de3
Compare
Murdock results❌ FAILED ddb027f Update cpu/sam0_common/periph/countdown.c
ArtifactsThis only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see inline
uint32_t ticks_per_unit; /**< counter ticks per base unit */ | ||
uint8_t base_unit; /**< base unit (ns, µs, …) of the counter */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this increase complexity? Why not just uint32_t freq_hz
?
What if ticks_per_unit ends up being 1.5
? This would add up to large errors quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was that you typically don't (or shouldn't) need to care about the timer frequency.
So you only tell countdown_init()
about the time range you want to have for the countdown and then it figures out the best frequency on it's own (where ticks_per_unit
would be a whole number).
I think it was then easier to calculate the actual timeouts based on that (since you can just multiply with ticks_per_unit
).
It's been a while since I while since I wrote this, might have to take a look at the API again to see if it still makes sense.
Ping? :) |
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Marian Buschsieweke <[email protected]>
Contribution description
When working on speeding up the DOSE driver, I noticed that we don't have a fast interface to set countdowns.
The
periph_timer
API is targeted towards timekeeping with a continuously running timer. This means that for setting an alarm, we first have to read the current time, add the alarm period, then set the alarm.When reading the current time involves syncing clock domains, this becomes a costly process that does not allow us to keep up with line data rates of 1 MBit/s (10 µs/byte on UART).
Then there are timers (SysTick) that don't have a notion of 'current time', but will count down from a set time until they reach zero.
This prompted me to introduce a new API explicitly for countdown devices that is targeted towards speedy operation.
It is split into a low-level device API and a high-level user API which allows the device drivers to remain simple and to share common code across implementations.
As an example, a period extension has been implemented
periph_countdown_long
that allows to set alarms further in the future than the hardware timer would allow.This is of course more expensive than a normal
countdown_set()
so it should not be used in time critical sections.countdown_start()
however remains fast.So far implementations are provided for Cortex-M SysTick and Atmel SAM Tc and Tcc timers (tested on
samr21-xpro
andsamr54-xpro
).Testing procedure
A test application is provided in
tests/periph_countdown
.It will execute API tests on all available Countdown timers, then benchmark the API operations.
samr21-xpro
same54-xpro
Issues/PRs references
useful for #17097