Skip to content
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

Gp timer api #332

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Gp timer api #332

wants to merge 6 commits into from

Conversation

Vollbrecht
Copy link
Collaborator

@Vollbrecht Vollbrecht commented Nov 3, 2023

First draft using the gptimer api introduced in ESP-IDF 5.

Pros about the new api:

  • It allows for dynamically updating counter + reload counter + and auto_reload even in ISR
  • It manages all underlying hardware timer in a pool.
  • new callback gives the handle to the driver directly + an event item containg counter + reload value

Cons:

  • it manages all underlying hardware timer in a pool so the user has no infuence of what actual hardware timer / group is run.

Most of this first draft mimics the implementation of the old api. A noticeable change is that i introduced marker traits for ISR and nonISR safe methods. The advantage of this is that we don't need a runtime check on each driver method. The isr itself will return a special TimerDriverInISR struct that is just a thin wrapper around the underlying handle. This ISRDriver only exposes the isr safe methods. To reduce code duplication i implemented most methods in the defined traits itself. The only one small downside of this is the user of the driver needs to import the traits in his context with hal::timer::gptimer::{ISRMethods, NonISRsaveMethods} otherwise he doesn't have any methods on the TimerDriver. I think this tradeoff is worthwhile, but needs proper documentation on the object so people don't forget.

To allow this driver to work we need to make sure that in the complete codebase we dont use the old driver in any way. It will lead into a hardfault at runtime (esp-idf checks for this case). The simplest way currently was to just featuregate this driver, but to not make a breaking change with the old driver introduces some amount of #[cfg(not(feature = "gp_timer_api"))]

TODO:

  • fix thread safety duo to array indexing
  • expose all api possibility ( get_capture_count etc )
  • ETM events for communication directly with other peripheral without CPU( esp32c6 feature)
  • create convininence methods around wall-clock, one_shot and periodic timer

@Vollbrecht
Copy link
Collaborator Author

while this if functional, i am waiting and check what is currently happening on esp-idf master. It seems they outsourced the gptimer driver into an external component. If they port it into esp-idf 5.2 we may need to revisit the imports in esp-idf-sys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant