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

Unified Callback Timer API #1831

Merged
merged 3 commits into from
Sep 15, 2019
Merged

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Sep 13, 2019

Add CallbackTimer class template to support HardwareTimer, SimpleTimer and Timer.

  • Contains common logic and checks for all callback timer types
  • Templated for best performance (no VMT)
  • Added TimerCallback supporting void* arg parameter (in addition to existing InterruptCallback)
  • Templated methods added with compile-time checks on interval (so code won't compile if out of range)
  • Added methods to support setting/checking/querying intervals directly in timer ticks
  • Timer intervals stored internally in timer ticks, so querying the value confirms the actual time in use accounting for rounding, etc.

Note that delegate callbacks are supported only by the Timer class, which now also has an AutoDelete variant.

Improve Host timer queue implementation to handles multiple timers properly, fixes bug where all timers get cancelled instead of just one.

Add os_timer_arm_ticks() function so software timers are programmed in ticks instead of microseconds or milliseconds

  • Used instead of os_timer_arm_us provides simpler and more flexible timer interface.
  • Avoids un-necessary (and potentially inaccurate) time conversions
  • Timers can be used with USE_US_TIMER=0 for 3.2us tick resolution, providing basic range of 1'54" (with SimpleTimer)
  • Default is still USE_US_TIMER=1 for 0.2us tick resolution and reduced 0'7"9s range (without using Timer class)

Update samples to use improved timer API and add timers module to HostTests

Update linker script to apply IRAM section attributes for templated code

Templates ignore section attributes so requires entries in linker script for IRAM code.

…mer and Timer.

- Contains common logic and checks for all callback timer types
- Templated for best performance (no VMT)
- Added `TimerCallback` supporting void* arg parameter (in addition to existing `InterruptCallback`)
- Templated methods added with compile-time checks on interval (so code won't compile if out of range)
- Added methods to support setting/checking/querying intervals directly in timer ticksn
- Timer intervals stored internally in timer ticks, so querying the value confirms the actual time in use accounting for rounding, etc.

Note that delegate callbacks are supported only by the Timer class, which now also has an AutoDelete variant.

Host timer queue implementation improved, handles multiple timers properly (fixes bug where all timers get cancelled instead of just one).

Add `os_timer_arm_ticks()` function so software timers are programmed in ticks instead of microseconds or milliseconds

- Used instead of `os_timer_arm_us` provides simpler and more flexible timer interface.
- Avoids un-necessary (and potentially inaccurate) time conversions
- Timers can be used with `USE_US_TIMER=0` for 3.2us tick resolution, providing basic range of 1'54" (with SimpleTimer)
- Default is still `USE_US_TIMER=1` for 0.2us tick resolution and reduced 0'7"9s range (without using Timer class)
…ipt for IRAM code.

In the source code you'll see quite a bit of `__forceinline` as well as `IRAM_ATTR`, which is mainly for safety
and to indicate functions/methods may be used from interrupt context.

Unfortunately, marking templated code with `IRAM_ATTR` is not sufficient to get it into IRAM:

https://stackoverflow.com/questions/36279162/section-attribute-of-a-function-template-is-silently-ignored-in-gcc

So the linker script needs to be updated to catch all such instances. To do this requires splitting the `.text` output
segment into two parts, called `.text` and `.text1`. The rBoot script also needs to know about both segments
so they both end up in the ROM image it creates.

Using `CallbackTimer` as an example, most of the code gets inlined anyway and as it's called from task context
this actually uses very little IRAM.

More details here:

esp8266/Arduino#5922
@mikee47 mikee47 changed the title Implement CallbackTimer class and upgrade software timer API Unified Callback Timer API Sep 13, 2019
@slaff slaff added this to the 4.0.0 milestone Sep 13, 2019
@slaff
Copy link
Contributor

slaff commented Sep 14, 2019

@mikee47 Tested and happy with this PR?

@mikee47
Copy link
Contributor Author

mikee47 commented Sep 14, 2019

@slaff Yes, tested and happy :-)

@slaff slaff removed the 3 - Review label Sep 15, 2019
@slaff slaff merged commit d5c7409 into SmingHub:develop Sep 15, 2019
@mikee47 mikee47 deleted the feature/callback-timers branch September 15, 2019 16:20
@slaff slaff mentioned this pull request Sep 28, 2019
4 tasks
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.

2 participants