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

GetTick and DelayUntilMs/DelayUntilUs utilities for Delay? #511

Open
romancardenas opened this issue Aug 10, 2022 · 1 comment
Open

GetTick and DelayUntilMs/DelayUntilUs utilities for Delay? #511

romancardenas opened this issue Aug 10, 2022 · 1 comment

Comments

@romancardenas
Copy link
Contributor

Hi! I think it would be nice to add a DelayUntil utility to delays. In this way, we can have actual periodic tasks, regardless of the time consumed by a task when executing. To do so, we would need to add the following methods to delays:

  • getTick(&self) → X (I'm not sure which the return value should be): it returns the current internal clock tick value.
  • delayUntilMs(&mut self, baseline_tick: X, ms: u16): it waits the given amount of milliseconds FROM THE BASELINE.
  • delayUntilUs(&mut self, baseline_tick: X, us: u32): it waits the given amount of microseconds FROM THE BASELINE.

With that, we could do something like this:

let tick = timer.getTick();  // tick now represents the time
do_stuff(); // this takes time...
timer.delayUntilMs(tick, 1_000); // we wait one second starting from before we triggered do_stuff

Thus, we would not delay for one second, but 1 second SINCE WE CAPTURED THE BASELINE.

What do you think? Is there anything I'm missing that makes this a bad idea?

@romancardenas
Copy link
Contributor Author

Maybe it is better to implement this feature in the cortex-m crate, so more HALs would benefit from it. I opened this issue in the cortex_m GitHub repo.

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

No branches or pull requests

1 participant