-
Notifications
You must be signed in to change notification settings - Fork 235
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
[RFC] Timer abstraction design #1479
Comments
I guess we also need a way to know what a tick is (i.e. the timer frequency) I also guess we will have this in addition to the "lower level" drivers for those timer-peripherals which is good since even if the abstraction won't (and probably can't) support everything a specific timer can do user code can still use the timer directly while most other code can use the abstraction. Having "AnyTimer" is also a good idea I like the general idea - most likely we will find additional functions we would like to have but this seems like a good start |
I just had a thought, maybe these trait methods should be all Whilst technically some of these changes mutate the peripheral, register writes are atomic, so maybe we don't care given that this is quite a low-level trait? I can foresee mutability issues with embassy time drivers already as they all take What do you think? |
|
This will be split into 3 PRs: |
Just to update,
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This issue is for tracking progress on our current timer abstraction work, which has been discussed in detail amongst our team. Please open a new issue or discussion for other topics. |
Rationale
Copying from #1318 (comment):
We currently have no shared API between timers, i.e TIMG and SYSTIMER are completely different and cannot be abstracted over, but in reality they all do the same things:
If we can abstract over this, I see several benefits:
InterruptHandler
in esp-wifi and assign it to the chosen timer.embassy_time_driver::time_driver_impl!
worksInitial design
In a nutshell, I believe the way to go about this is to abstract over the building blocks of timer behavior, like
set_target
,clear_interrupt
,enable_interrupt
. After we have that we can then create concrete structures for specific timer behaviors.The timer trait
This is probably where we need the most input, as it needs to support the use cases we need for all the timers we have. As a starting point this is my definition:
Behaviour encapsulation
To encapsulate one shot timer behaviour we can create a
OneShotTimer
that could look like this:What about the generic parameter?
In the OP I stated that we might be able to remove the embassy features, but if we know we need to store a timer in a
static
and it has a generic paramter we're going to have a bad time. I am hoping that for esp-wifi's usecase this won't matter, but regardless, I have an idea:AnyTimer
.AnyTimer
, much likeAnyPin
allows for runtime selection of a timer. Now that theTimer
trait exists, we can implTimer
forAnyTimer
and boom, we have a single type than can be used for more than one timer.The text was updated successfully, but these errors were encountered: