diff options
| author | Finomnis <Finomnis@users.noreply.github.com> | 2024-04-11 00:00:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-10 22:00:38 +0000 |
| commit | 8c23e178f3838bcdd13662a2ffefd39ec144e869 (patch) | |
| tree | f2d2cefcd6bb2876e74ee6035b5489a4a2d9590f /examples/lm3s6965 | |
| parent | e4cc5fd17b8a2df332af0ee25c8bd7092e66afb0 (diff) | |
Monotonic rewrite (#874)
* Rework timer_queue and monotonic architecture
Goals:
* make Monotonic purely internal
* make Monotonic purely tick passed, no fugit involved
* create a wrapper struct in the user's code via a macro that then
converts the "now" from the tick based monotonic to a fugit based
timestamp
We need to proxy the delay functions of the timer queue anyway,
so we could simply perform the conversion in those proxy functions.
* Update cargo.lock
* Update readme of rtic-time
* CI: ESP32: Redact esp_image: Too volatile
* Fixup: Changelog double entry rebase mistake
---------
Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
Diffstat (limited to 'examples/lm3s6965')
| -rw-r--r-- | examples/lm3s6965/Cargo.lock | 9 | ||||
| -rw-r--r-- | examples/lm3s6965/examples/async-delay.rs | 13 | ||||
| -rw-r--r-- | examples/lm3s6965/examples/async-timeout.rs | 25 |
3 files changed, 24 insertions, 23 deletions
diff --git a/examples/lm3s6965/Cargo.lock b/examples/lm3s6965/Cargo.lock index 076a156..848a06f 100644 --- a/examples/lm3s6965/Cargo.lock +++ b/examples/lm3s6965/Cargo.lock @@ -362,7 +362,6 @@ dependencies = [ "critical-section", "rtic-core", "rtic-macros", - "rtic-monotonics", ] [[package]] @@ -392,12 +391,11 @@ dependencies = [ [[package]] name = "rtic-monotonics" -version = "1.5.0" +version = "2.0.0" dependencies = [ "atomic-polyfill", "cfg-if", "cortex-m", - "embedded-hal 1.0.0", "fugit", "rtic-time", ] @@ -417,9 +415,12 @@ dependencies = [ [[package]] name = "rtic-time" -version = "1.3.0" +version = "2.0.0" dependencies = [ "critical-section", + "embedded-hal 1.0.0", + "embedded-hal-async", + "fugit", "futures-util", "rtic-common", ] diff --git a/examples/lm3s6965/examples/async-delay.rs b/examples/lm3s6965/examples/async-delay.rs index 9ccfc02..0f151cb 100644 --- a/examples/lm3s6965/examples/async-delay.rs +++ b/examples/lm3s6965/examples/async-delay.rs @@ -11,7 +11,9 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)] mod app { use cortex_m_semihosting::{debug, hprintln}; - use rtic_monotonics::systick::*; + use rtic_monotonics::systick::prelude::*; + + systick_monotonic!(Mono, 100); #[shared] struct Shared {} @@ -23,8 +25,7 @@ mod app { fn init(cx: init::Context) -> (Shared, Local) { hprintln!("init"); - let systick_token = rtic_monotonics::create_systick_token!(); - Systick::start(cx.core.SYST, 12_000_000, systick_token); + Mono::start(cx.core.SYST, 12_000_000); foo::spawn().ok(); bar::spawn().ok(); @@ -36,21 +37,21 @@ mod app { #[task] async fn foo(_cx: foo::Context) { hprintln!("hello from foo"); - Systick::delay(100.millis()).await; + Mono::delay(100.millis()).await; hprintln!("bye from foo"); } #[task] async fn bar(_cx: bar::Context) { hprintln!("hello from bar"); - Systick::delay(200.millis()).await; + Mono::delay(200.millis()).await; hprintln!("bye from bar"); } #[task] async fn baz(_cx: baz::Context) { hprintln!("hello from baz"); - Systick::delay(300.millis()).await; + Mono::delay(300.millis()).await; hprintln!("bye from baz"); debug::exit(debug::EXIT_SUCCESS); diff --git a/examples/lm3s6965/examples/async-timeout.rs b/examples/lm3s6965/examples/async-timeout.rs index e5e129f..169b132 100644 --- a/examples/lm3s6965/examples/async-timeout.rs +++ b/examples/lm3s6965/examples/async-timeout.rs @@ -8,13 +8,13 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; -use rtic_monotonics::systick::*; +use rtic_monotonics::systick::prelude::*; +systick_monotonic!(Mono, 100); #[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)] mod app { use super::*; use futures::{future::FutureExt, select_biased}; - use rtic_monotonics::Monotonic; #[shared] struct Shared {} @@ -27,8 +27,7 @@ mod app { fn init(cx: init::Context) -> (Shared, Local) { hprintln!("init"); - let systick_token = rtic_monotonics::create_systick_token!(); - Systick::start(cx.core.SYST, 12_000_000, systick_token); + Mono::start(cx.core.SYST, 12_000_000); // ANCHOR_END: init foo::spawn().ok(); @@ -42,19 +41,19 @@ mod app { // Call hal with short relative timeout using `select_biased` select_biased! { v = hal_get(1).fuse() => hprintln!("hal returned {}", v), - _ = Systick::delay(200.millis()).fuse() => hprintln!("timeout", ), // this will finish first + _ = Mono::delay(200.millis()).fuse() => hprintln!("timeout", ), // this will finish first } // Call hal with long relative timeout using `select_biased` select_biased! { v = hal_get(1).fuse() => hprintln!("hal returned {}", v), // hal finish first - _ = Systick::delay(1000.millis()).fuse() => hprintln!("timeout", ), + _ = Mono::delay(1000.millis()).fuse() => hprintln!("timeout", ), } // ANCHOR_END: select_biased // ANCHOR: timeout_after_basic // Call hal with long relative timeout using monotonic `timeout_after` - match Systick::timeout_after(1000.millis(), hal_get(1)).await { + match Mono::timeout_after(1000.millis(), hal_get(1)).await { Ok(v) => hprintln!("hal returned {}", v), _ => hprintln!("timeout"), } @@ -62,20 +61,20 @@ mod app { // ANCHOR: timeout_at_basic // get the current time instance - let mut instant = Systick::now(); + let mut instant = Mono::now(); // do this 3 times for n in 0..3 { // absolute point in time without drift instant += 1000.millis(); - Systick::delay_until(instant).await; + Mono::delay_until(instant).await; // absolute point in time for timeout let timeout = instant + 500.millis(); - hprintln!("now is {:?}, timeout at {:?}", Systick::now(), timeout); + hprintln!("now is {:?}, timeout at {:?}", Mono::now(), timeout); - match Systick::timeout_at(timeout, hal_get(n)).await { - Ok(v) => hprintln!("hal returned {} at time {:?}", v, Systick::now()), + match Mono::timeout_at(timeout, hal_get(n)).await { + Ok(v) => hprintln!("hal returned {} at time {:?}", v, Mono::now()), _ => hprintln!("timeout"), } } @@ -90,7 +89,7 @@ async fn hal_get(n: u32) -> u32 { // emulate some delay time dependent on n let d = 350.millis() + n * 100.millis(); hprintln!("the hal takes a duration of {:?}", d); - Systick::delay(d).await; + Mono::delay(d).await; // emulate some return value 5 } |
