From 1087f2ee64a5be1aedf3b702ccb5d86cc64708d9 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 11 Mar 2021 19:12:02 +0100 Subject: Added interface for cancel/reschedule Use wrapping add for marker No need to store handle to queue Remove unnecessary `SpawnHandle::new` Fix test Updated interface to follow proposal --- examples/t-schedule.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs index bd0ab66..6b6245e 100644 --- a/examples/t-schedule.rs +++ b/examples/t-schedule.rs @@ -26,18 +26,29 @@ mod app { let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000); - let _: Result<(), ()> = foo::spawn_after(Seconds(1_u32)); - let _: Result<(), u32> = bar::spawn_after(Seconds(2_u32), 0); - let _: Result<(), (u32, u32)> = baz::spawn_after(Seconds(3_u32), 0, 1); + let a: Result = foo::spawn_after(Seconds(1_u32)); + if let Ok(handle) = a { + let _: Result = handle.reschedule_after(Seconds(1_u32)); + } + + let b: Result = bar::spawn_after(Seconds(2_u32), 0); + if let Ok(handle) = b { + let _: Result = handle.cancel(); + } + + let _: Result = + baz::spawn_after(Seconds(3_u32), 0, 1); (init::LateResources {}, init::Monotonics(mono)) } #[idle] fn idle(_: idle::Context) -> ! { - let _: Result<(), ()> = foo::spawn_at(MyMono::now() + Seconds(3_u32)); - let _: Result<(), u32> = bar::spawn_at(MyMono::now() + Seconds(4_u32), 0); - let _: Result<(), (u32, u32)> = baz::spawn_at(MyMono::now() + Seconds(5_u32), 0, 1); + let _: Result = foo::spawn_at(MyMono::now() + Seconds(3_u32)); + let _: Result = + bar::spawn_at(MyMono::now() + Seconds(4_u32), 0); + let _: Result = + baz::spawn_at(MyMono::now() + Seconds(5_u32), 0, 1); loop { cortex_m::asm::nop(); -- cgit v1.2.3 From 3adda3c7664b92e0a14ceb446a2082933647ba52 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sat, 20 Mar 2021 08:38:37 +0100 Subject: Updated schedule example with all combinations --- Cargo.toml | 3 +- examples/t-schedule.rs | 93 +++++++++++++++++++++++++++++++++++++------- macros/src/codegen/module.rs | 12 ------ src/lib.rs | 2 +- 4 files changed, 80 insertions(+), 30 deletions(-) (limited to 'examples') diff --git a/Cargo.toml b/Cargo.toml index b02df9f..0d762df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ license = "MIT OR Apache-2.0" name = "cortex-m-rtic" readme = "README.md" repository = "https://github.com/rtic-rs/cortex-m-rtic" - version = "0.6.0-alpha.1" [lib] @@ -58,7 +57,7 @@ rtic-monotonic = "0.1.0-alpha.0" rtic-core = "0.3.1" heapless = "0.6.1" bare-metal = "1.0.0" -generic-array = "*" +generic-array = "0.14" [dependencies.dwt-systick-monotonic] version = "0.1.0-alpha.0" diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs index 6b6245e..890b316 100644 --- a/examples/t-schedule.rs +++ b/examples/t-schedule.rs @@ -26,30 +26,93 @@ mod app { let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000); - let a: Result = foo::spawn_after(Seconds(1_u32)); - if let Ok(handle) = a { - let _: Result = handle.reschedule_after(Seconds(1_u32)); - } + // Task without message passing - let b: Result = bar::spawn_after(Seconds(2_u32), 0); - if let Ok(handle) = b { - let _: Result = handle.cancel(); - } + // Not default + let _: Result = foo::MyMono::spawn_at(MyMono::now()); + let handle: Result = foo::MyMono::spawn_after(Seconds(1_u32)); + let _: Result = + handle.unwrap().reschedule_after(Seconds(1_u32)); + + let handle: Result = foo::MyMono::spawn_after(Seconds(1_u32)); + let _: Result = handle.unwrap().reschedule_at(MyMono::now()); + + let handle: Result = foo::MyMono::spawn_after(Seconds(1_u32)); + let _: Result<(), ()> = handle.unwrap().cancel(); + + // Using default + let _: Result = foo::spawn_at(MyMono::now()); + let handle: Result = foo::spawn_after(Seconds(1_u32)); + let _: Result = handle.unwrap().reschedule_after(Seconds(1_u32)); + + let handle: Result = foo::spawn_after(Seconds(1_u32)); + let _: Result = handle.unwrap().reschedule_at(MyMono::now()); + + let handle: Result = foo::spawn_after(Seconds(1_u32)); + let _: Result<(), ()> = handle.unwrap().cancel(); + + // Task with single message passing + + // Not default + let _: Result = bar::MyMono::spawn_at(MyMono::now(), 0); + let handle: Result = + bar::MyMono::spawn_after(Seconds(1_u32), 0); + let _: Result = + handle.unwrap().reschedule_after(Seconds(1_u32)); + + let handle: Result = + bar::MyMono::spawn_after(Seconds(1_u32), 0); + let _: Result = handle.unwrap().reschedule_at(MyMono::now()); + + let handle: Result = + bar::MyMono::spawn_after(Seconds(1_u32), 0); + let _: Result = handle.unwrap().cancel(); + // Using default + let _: Result = bar::spawn_at(MyMono::now(), 0); + let handle: Result = bar::spawn_after(Seconds(1_u32), 0); + let _: Result = handle.unwrap().reschedule_after(Seconds(1_u32)); + + let handle: Result = bar::spawn_after(Seconds(1_u32), 0); + let _: Result = handle.unwrap().reschedule_at(MyMono::now()); + + let handle: Result = bar::spawn_after(Seconds(1_u32), 0); + let _: Result = handle.unwrap().cancel(); + + // Task with multiple message passing + + // Not default let _: Result = - baz::spawn_after(Seconds(3_u32), 0, 1); + baz::MyMono::spawn_at(MyMono::now(), 0, 1); + let handle: Result = + baz::MyMono::spawn_after(Seconds(1_u32), 0, 1); + let _: Result = + handle.unwrap().reschedule_after(Seconds(1_u32)); + + let handle: Result = + baz::MyMono::spawn_after(Seconds(1_u32), 0, 1); + let _: Result = handle.unwrap().reschedule_at(MyMono::now()); + + let handle: Result = + baz::MyMono::spawn_after(Seconds(1_u32), 0, 1); + let _: Result<(u32, u32), ()> = handle.unwrap().cancel(); + + // Using default + let _: Result = baz::spawn_at(MyMono::now(), 0, 1); + let handle: Result = baz::spawn_after(Seconds(1_u32), 0, 1); + let _: Result = handle.unwrap().reschedule_after(Seconds(1_u32)); + + let handle: Result = baz::spawn_after(Seconds(1_u32), 0, 1); + let _: Result = handle.unwrap().reschedule_at(MyMono::now()); + + let handle: Result = baz::spawn_after(Seconds(1_u32), 0, 1); + let _: Result<(u32, u32), ()> = handle.unwrap().cancel(); (init::LateResources {}, init::Monotonics(mono)) } #[idle] fn idle(_: idle::Context) -> ! { - let _: Result = foo::spawn_at(MyMono::now() + Seconds(3_u32)); - let _: Result = - bar::spawn_at(MyMono::now() + Seconds(4_u32), 0); - let _: Result = - baz::spawn_at(MyMono::now() + Seconds(5_u32), 0, 1); - loop { cortex_m::asm::nop(); } diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 5a594c6..e15aab1 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -319,18 +319,6 @@ pub fn codegen( marker: u32, } - // TODO: remove - impl core::fmt::Debug for SpawnHandle - { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let handle = unsafe { &#app_path::#tq as *const _ as u32 }; - f.debug_struct("SpawnHandle") - .field("marker", &self.marker) - .field("handle", &handle) - .finish() - } - } - impl SpawnHandle { pub fn cancel(self) -> Result<#ty, ()> { rtic::export::interrupt::free(|_| unsafe { diff --git a/src/lib.rs b/src/lib.rs index a88ea81..a4abc4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ #![deny(missing_docs)] #![deny(rust_2018_compatibility)] #![deny(rust_2018_idioms)] -// #![deny(warnings)] +#![deny(warnings)] #![no_std] use cortex_m::{interrupt::InterruptNumber, peripheral::NVIC}; -- cgit v1.2.3 From ae691952c328757113047bf696e934316789b844 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 7 Apr 2021 11:09:21 +0200 Subject: Updated dwt-systick-monotonic --- examples/double_schedule.rs | 7 ++----- examples/periodic.rs | 7 ++----- examples/schedule.rs | 7 ++----- examples/t-schedule.rs | 7 ++----- examples/types.rs | 7 ++----- 5 files changed, 10 insertions(+), 25 deletions(-) (limited to 'examples') diff --git a/examples/double_schedule.rs b/examples/double_schedule.rs index 403f358..9da57ae 100644 --- a/examples/double_schedule.rs +++ b/examples/double_schedule.rs @@ -9,14 +9,11 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965, dispatchers = [SSI0])] mod app { - use dwt_systick_monotonic::{ - consts::{U0, U8}, - DwtSystick, - }; + use dwt_systick_monotonic::DwtSystick; use rtic::time::duration::Seconds; #[monotonic(binds = SysTick, default = true)] - type MyMono = DwtSystick; // 8 MHz + type MyMono = DwtSystick<8_000_000>; // 8 MHz #[init] fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { diff --git a/examples/periodic.rs b/examples/periodic.rs index 82c2128..01061c9 100644 --- a/examples/periodic.rs +++ b/examples/periodic.rs @@ -10,14 +10,11 @@ use panic_semihosting as _; // NOTE: does NOT work on QEMU! #[rtic::app(device = lm3s6965, dispatchers = [SSI0])] mod app { - use dwt_systick_monotonic::{ - consts::{U0, U8}, - DwtSystick, - }; + use dwt_systick_monotonic::DwtSystick; use rtic::time::duration::Seconds; #[monotonic(binds = SysTick, default = true)] - type MyMono = DwtSystick; // 8 MHz + type MyMono = DwtSystick<8_000_000>; // 8 MHz #[init] fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { diff --git a/examples/schedule.rs b/examples/schedule.rs index d6d4499..b89e519 100644 --- a/examples/schedule.rs +++ b/examples/schedule.rs @@ -11,14 +11,11 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965, dispatchers = [SSI0])] mod app { use cortex_m_semihosting::hprintln; - use dwt_systick_monotonic::{ - consts::{U0, U8}, - DwtSystick, - }; + use dwt_systick_monotonic::DwtSystick; use rtic::time::duration::Seconds; #[monotonic(binds = SysTick, default = true)] - type MyMono = DwtSystick; // 8 MHz + type MyMono = DwtSystick<8_000_000>; // 8 MHz #[init()] fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs index 890b316..ef04c45 100644 --- a/examples/t-schedule.rs +++ b/examples/t-schedule.rs @@ -9,14 +9,11 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965, dispatchers = [SSI0])] mod app { - use dwt_systick_monotonic::{ - consts::{U0, U8}, - DwtSystick, - }; + use dwt_systick_monotonic::DwtSystick; use rtic::time::duration::Seconds; #[monotonic(binds = SysTick, default = true)] - type MyMono = DwtSystick; // 8 MHz + type MyMono = DwtSystick<8_000_000>; // 8 MHz #[init] fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { diff --git a/examples/types.rs b/examples/types.rs index ff7deb8..cdcf80c 100644 --- a/examples/types.rs +++ b/examples/types.rs @@ -10,13 +10,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965, peripherals = true, dispatchers = [SSI0])] mod app { use cortex_m_semihosting::debug; - use dwt_systick_monotonic::{ - consts::{U0, U8}, - DwtSystick, - }; + use dwt_systick_monotonic::DwtSystick; #[monotonic(binds = SysTick, default = true)] - type MyMono = DwtSystick; // 8 MHz + type MyMono = DwtSystick<8_000_000>; // 8 MHz #[resources] struct Resources { -- cgit v1.2.3