rtic/book/en/src/by-example/tips_monotonic_impl.md

36 lines
2 KiB
Markdown
Raw Normal View History

2021-09-22 13:22:45 +02:00
# Implementing a `Monotonic` timer for scheduling
2021-12-18 22:36:11 +01:00
The framework is flexible because it can use any timer which has compare-match and optionally
supporting overflow interrupts for scheduling.
The single requirement to make a timer usable with RTIC is implementing the
[`rtic_monotonic::Monotonic`] trait.
2021-09-22 13:22:45 +02:00
2021-12-18 22:36:11 +01:00
Implementing time counting that supports large time spans is generally **difficult**, in RTIC 0.5
implementing time handling was a common problem.
Moreover, the relation between time and timers used for scheduling was difficult to understand.
2021-09-22 13:22:45 +02:00
For RTIC 1.0 we instead assume the user has a time library, e.g. [`fugit`] or [`embedded_time`],
2021-12-18 22:36:11 +01:00
as the basis for all time-based operations when implementing `Monotonic`.
This makes it much easier to correctly implement the `Monotonic` trait allowing the use of
almost any timer in the system for scheduling.
2021-12-18 22:36:11 +01:00
The trait documents the requirements for each method,
and for inspiration here is a list of `Monotonic` implementations:
2021-11-10 13:46:34 +01:00
- [`STM32F411 series`], implemented for the 32-bit timers
- [`Nordic nRF52 series Timer`], implemented for the 32-bit timers
- [`Nordic nRF52 series RTC`], implemented for the RTCs
- [`Systick based`], runs at a fixed interrupt (tick) rate - with some overhead but simple and with support for large time spans
- [`DWT and Systick based`], a more efficient (tickless) implementation - requires both `SysTick` and `DWT`, supports both high resolution and large time spans
If you know of more implementations feel free to add them to this list.
2021-09-22 13:22:45 +02:00
[`rtic_monotonic::Monotonic`]: https://docs.rs/rtic-monotonic/
2021-11-10 09:28:03 +01:00
[`fugit`]: https://docs.rs/fugit/
2021-09-22 13:22:45 +02:00
[`embedded_time`]: https://docs.rs/embedded_time/
2021-11-10 13:46:34 +01:00
[`STM32F411 series`]: https://github.com/kalkyl/f411-rtic/blob/main/src/bin/mono.rs
[`Nordic nRF52 series Timer`]: https://github.com/kalkyl/nrf-play/blob/main/src/bin/mono.rs
[`Nordic nRF52 series RTC`]: https://gist.github.com/korken89/fe94a475726414dd1bce031c76adc3dd
[`Systick based`]: https://github.com/rtic-rs/systick-monotonic
[`DWT and Systick based`]: https://github.com/rtic-rs/dwt-systick-monotonic