Updated schedule example with all combinations

This commit is contained in:
Emil Fresk 2021-03-20 08:38:37 +01:00
parent 53c407017f
commit 3adda3c766
4 changed files with 80 additions and 30 deletions

View file

@ -13,7 +13,6 @@ license = "MIT OR Apache-2.0"
name = "cortex-m-rtic" name = "cortex-m-rtic"
readme = "README.md" readme = "README.md"
repository = "https://github.com/rtic-rs/cortex-m-rtic" repository = "https://github.com/rtic-rs/cortex-m-rtic"
version = "0.6.0-alpha.1" version = "0.6.0-alpha.1"
[lib] [lib]
@ -58,7 +57,7 @@ rtic-monotonic = "0.1.0-alpha.0"
rtic-core = "0.3.1" rtic-core = "0.3.1"
heapless = "0.6.1" heapless = "0.6.1"
bare-metal = "1.0.0" bare-metal = "1.0.0"
generic-array = "*" generic-array = "0.14"
[dependencies.dwt-systick-monotonic] [dependencies.dwt-systick-monotonic]
version = "0.1.0-alpha.0" version = "0.1.0-alpha.0"

View file

@ -26,30 +26,93 @@ mod app {
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000); let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
let a: Result<foo::MyMono::SpawnHandle, ()> = foo::spawn_after(Seconds(1_u32)); // Task without message passing
if let Ok(handle) = a {
let _: Result<foo::MyMono::SpawnHandle, ()> = handle.reschedule_after(Seconds(1_u32));
}
let b: Result<bar::MyMono::SpawnHandle, u32> = bar::spawn_after(Seconds(2_u32), 0); // Not default
if let Ok(handle) = b { let _: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_at(MyMono::now());
let _: Result<u32, ()> = handle.cancel(); let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(Seconds(1_u32));
} let _: Result<foo::MyMono::SpawnHandle, ()> =
handle.unwrap().reschedule_after(Seconds(1_u32));
let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(Seconds(1_u32));
let _: Result<foo::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_at(MyMono::now());
let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(Seconds(1_u32));
let _: Result<(), ()> = handle.unwrap().cancel();
// Using default
let _: Result<foo::SpawnHandle, ()> = foo::spawn_at(MyMono::now());
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(Seconds(1_u32));
let _: Result<foo::SpawnHandle, ()> = handle.unwrap().reschedule_after(Seconds(1_u32));
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(Seconds(1_u32));
let _: Result<foo::SpawnHandle, ()> = handle.unwrap().reschedule_at(MyMono::now());
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(Seconds(1_u32));
let _: Result<(), ()> = handle.unwrap().cancel();
// Task with single message passing
// Not default
let _: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_at(MyMono::now(), 0);
let handle: Result<bar::MyMono::SpawnHandle, u32> =
bar::MyMono::spawn_after(Seconds(1_u32), 0);
let _: Result<bar::MyMono::SpawnHandle, ()> =
handle.unwrap().reschedule_after(Seconds(1_u32));
let handle: Result<bar::MyMono::SpawnHandle, u32> =
bar::MyMono::spawn_after(Seconds(1_u32), 0);
let _: Result<bar::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_at(MyMono::now());
let handle: Result<bar::MyMono::SpawnHandle, u32> =
bar::MyMono::spawn_after(Seconds(1_u32), 0);
let _: Result<u32, ()> = handle.unwrap().cancel();
// Using default
let _: Result<bar::SpawnHandle, u32> = bar::spawn_at(MyMono::now(), 0);
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(Seconds(1_u32), 0);
let _: Result<bar::SpawnHandle, ()> = handle.unwrap().reschedule_after(Seconds(1_u32));
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(Seconds(1_u32), 0);
let _: Result<bar::SpawnHandle, ()> = handle.unwrap().reschedule_at(MyMono::now());
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(Seconds(1_u32), 0);
let _: Result<u32, ()> = handle.unwrap().cancel();
// Task with multiple message passing
// Not default
let _: Result<baz::MyMono::SpawnHandle, (u32, u32)> = let _: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::spawn_after(Seconds(3_u32), 0, 1); baz::MyMono::spawn_at(MyMono::now(), 0, 1);
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::MyMono::spawn_after(Seconds(1_u32), 0, 1);
let _: Result<baz::MyMono::SpawnHandle, ()> =
handle.unwrap().reschedule_after(Seconds(1_u32));
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::MyMono::spawn_after(Seconds(1_u32), 0, 1);
let _: Result<baz::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_at(MyMono::now());
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::MyMono::spawn_after(Seconds(1_u32), 0, 1);
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
// Using default
let _: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_at(MyMono::now(), 0, 1);
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(Seconds(1_u32), 0, 1);
let _: Result<baz::SpawnHandle, ()> = handle.unwrap().reschedule_after(Seconds(1_u32));
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(Seconds(1_u32), 0, 1);
let _: Result<baz::SpawnHandle, ()> = handle.unwrap().reschedule_at(MyMono::now());
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(Seconds(1_u32), 0, 1);
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
(init::LateResources {}, init::Monotonics(mono)) (init::LateResources {}, init::Monotonics(mono))
} }
#[idle] #[idle]
fn idle(_: idle::Context) -> ! { fn idle(_: idle::Context) -> ! {
let _: Result<foo::MyMono::SpawnHandle, ()> = foo::spawn_at(MyMono::now() + Seconds(3_u32));
let _: Result<bar::MyMono::SpawnHandle, u32> =
bar::spawn_at(MyMono::now() + Seconds(4_u32), 0);
let _: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::spawn_at(MyMono::now() + Seconds(5_u32), 0, 1);
loop { loop {
cortex_m::asm::nop(); cortex_m::asm::nop();
} }

View file

@ -319,18 +319,6 @@ pub fn codegen(
marker: u32, 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 { impl SpawnHandle {
pub fn cancel(self) -> Result<#ty, ()> { pub fn cancel(self) -> Result<#ty, ()> {
rtic::export::interrupt::free(|_| unsafe { rtic::export::interrupt::free(|_| unsafe {

View file

@ -32,7 +32,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
#![deny(rust_2018_compatibility)] #![deny(rust_2018_compatibility)]
#![deny(rust_2018_idioms)] #![deny(rust_2018_idioms)]
// #![deny(warnings)] #![deny(warnings)]
#![no_std] #![no_std]
use cortex_m::{interrupt::InterruptNumber, peripheral::NVIC}; use cortex_m::{interrupt::InterruptNumber, peripheral::NVIC};