From 0dcb0c4e497b23bf68b7ac0d3d918ab3d3c209be Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 31 Oct 2021 10:09:40 +0100 Subject: New monotonic trait working --- macros/src/codegen.rs | 15 +++------------ macros/src/codegen/module.rs | 30 ++++++++++++------------------ macros/src/codegen/software_tasks.rs | 2 +- 3 files changed, 16 insertions(+), 31 deletions(-) (limited to 'macros') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index f07326b..422de5f 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -108,10 +108,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let name = &monotonic.ident; let name_str = &name.to_string(); let ident = util::monotonic_ident(&name_str); - let panic_str = &format!( - "Use of monotonic '{}' before it was passed to the runtime", - name_str - ); let doc = &format!( "This module holds the static implementation for `{}::now()`", name_str @@ -131,18 +127,13 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { pub mod #name { /// Read the current time from this monotonic - pub fn now() -> rtic::time::Instant { + pub fn now() -> ::Instant { rtic::export::interrupt::free(|_| { use rtic::Monotonic as _; - use rtic::time::Clock as _; if let Some(m) = unsafe{ &mut *super::super::#ident.get_mut() } { - if let Ok(v) = m.try_now() { - v - } else { - unreachable!("Your monotonic is not infallible!") - } + m.now() } else { - panic!(#panic_str); + ::zero() } }) } diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index c59a814..996af64 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -266,7 +266,6 @@ pub fn codegen( let tq = util::tq_ident(&monotonic.ident.to_string()); let t = util::schedule_t_ident(); let m = &monotonic.ident; - let mono_type = &monotonic.ident; let m_ident = util::monotonic_ident(&monotonic_name); let m_isr = &monotonic.args.binds; let enum_ = util::interrupt_ident(); @@ -349,15 +348,17 @@ pub fn codegen( } #[inline] - pub fn reschedule_after(self, duration: D) -> Result - where D: rtic::time::duration::Duration + rtic::time::fixed_point::FixedPoint, - D::T: Into<<#mono_type as rtic::time::Clock>::T>, - { + pub fn reschedule_after( + self, + duration: <#m as rtic::Monotonic>::Duration + ) -> Result { self.reschedule_at(monotonics::#m::now() + duration) } - pub fn reschedule_at(self, instant: rtic::time::Instant<#mono_type>) -> Result - { + pub fn reschedule_at( + self, + instant: <#m as rtic::Monotonic>::Instant + ) -> Result { rtic::export::interrupt::free(|_| unsafe { let marker = #tq_marker.get().read(); #tq_marker.get_mut().write(marker.wrapping_add(1)); @@ -375,19 +376,12 @@ pub fn codegen( /// This will use the time `Instant::new(0)` as baseline if called in `#[init]`, /// so if you use a non-resetable timer use `spawn_at` when in `#[init]` #[allow(non_snake_case)] - pub fn #internal_spawn_after_ident( - duration: D + pub fn #internal_spawn_after_ident( + duration: <#m as rtic::Monotonic>::Duration #(,#args)* ) -> Result<#name::#m::SpawnHandle, #ty> - where D: rtic::time::duration::Duration + rtic::time::fixed_point::FixedPoint, - D::T: Into<<#mono_type as rtic::time::Clock>::T>, { - - let instant = if rtic::export::interrupt::free(|_| unsafe { (&*#m_ident.get()).is_none() }) { - rtic::time::Instant::new(0) - } else { - monotonics::#m::now() - }; + let instant = monotonics::#m::now(); #internal_spawn_at_ident(instant + duration #(,#untupled)*) } @@ -396,7 +390,7 @@ pub fn codegen( /// Spawns the task at a fixed time instant #[allow(non_snake_case)] pub fn #internal_spawn_at_ident( - instant: rtic::time::Instant<#mono_type> + instant: <#m as rtic::Monotonic>::Instant #(,#args)* ) -> Result<#name::#m::SpawnHandle, #ty> { unsafe { diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 1669a3f..2008b6c 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -73,7 +73,7 @@ pub fn codegen( #[allow(non_upper_case_globals)] #[doc(hidden)] static #instants: - rtic::RacyCell<[core::mem::MaybeUninit>; #cap_lit]> = + rtic::RacyCell<[core::mem::MaybeUninit<<#mono_type as rtic::Monotonic>::Instant>; #cap_lit]> = rtic::RacyCell::new([#(#elems,)*]); )); } -- cgit v1.2.3 From 5ab5112271a9dbef6d875ad89706fc726e126b95 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 9 Nov 2021 10:35:58 +0100 Subject: Update versions and changelog --- CHANGELOG.md | 6 +++++- Cargo.toml | 9 ++++----- macros/Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'macros') diff --git a/CHANGELOG.md b/CHANGELOG.md index c86bb03..9ee854f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [v0.6.0-rc.4] - 2021-11-09 + +- Updated to use the new generic `Monotonic` trait ## [v0.6.0-rc.3] - 2021-11-08 @@ -444,7 +447,8 @@ Yanked due to a soundness issue in `init`; the issue has been mostly fixed in v0 - Initial release -[Unreleased]: https://github.com/rtic-rs/cortex-m-rtic/compare/v0.6.0-rc.3...HEAD +[Unreleased]: https://github.com/rtic-rs/cortex-m-rtic/compare/v0.6.0-rc.4...HEAD +[v0.6.0-rc.4]: https://github.com/rtic-rs/cortex-m-rtic/compare/v0.6.0-rc.3...v0.6.0-rc.4 [v0.6.0-rc.3]: https://github.com/rtic-rs/cortex-m-rtic/compare/v0.6.0-rc.2...v0.6.0-rc.3 [v0.6.0-rc.2]: https://github.com/rtic-rs/cortex-m-rtic/compare/v0.6.0-rc.1...v0.6.0-rc.2 [v0.6.0-rc.1]: https://github.com/rtic-rs/cortex-m-rtic/compare/v0.6.0-rc.0...v0.6.0-rc.1 diff --git a/Cargo.toml b/Cargo.toml index 7cdf7f9..ed6efba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,16 +14,15 @@ name = "cortex-m-rtic" readme = "README.md" repository = "https://github.com/rtic-rs/cortex-m-rtic" -version = "0.6.0-rc.3" +version = "0.6.0-rc.4" [lib] name = "rtic" [dependencies] cortex-m = "0.7.0" -cortex-m-rtic-macros = { path = "macros", version = "0.6.0-rc.3" } -# rtic-monotonic = "0.1.0-rc.1" -rtic-monotonic = { git = "https://github.com/rtic-rs/rtic-monotonic.git", branch = "master" } +cortex-m-rtic-macros = { path = "macros", version = "0.6.0-rc.4" } +rtic-monotonic = "0.1.0-rc.2" rtic-core = "0.3.1" heapless = "0.7.7" bare-metal = "1.0.0" @@ -34,7 +33,7 @@ version_check = "0.9" [dev-dependencies] lm3s6965 = "0.1.3" cortex-m-semihosting = "0.3.3" -systick-monotonic = { git = "https://github.com/rtic-rs/systick-monotonic.git", branch = "new-trait-and-time-lib" } +systick-monotonic = "0.1.0-rc.2" [dev-dependencies.panic-semihosting] features = ["exit"] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index de335bc..394c177 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0" name = "cortex-m-rtic-macros" readme = "../README.md" repository = "https://github.com/rtic-rs/cortex-m-rtic" -version = "0.6.0-rc.3" +version = "0.6.0-rc.4" [lib] proc-macro = true -- cgit v1.2.3