mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
Updated schedule example with all combinations
This commit is contained in:
parent
53c407017f
commit
3adda3c766
4 changed files with 80 additions and 30 deletions
|
@ -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"
|
||||
|
|
|
@ -26,30 +26,93 @@ mod app {
|
|||
|
||||
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
|
||||
|
||||
let a: Result<foo::MyMono::SpawnHandle, ()> = foo::spawn_after(Seconds(1_u32));
|
||||
if let Ok(handle) = a {
|
||||
let _: Result<foo::MyMono::SpawnHandle, ()> = handle.reschedule_after(Seconds(1_u32));
|
||||
}
|
||||
// Task without message passing
|
||||
|
||||
let b: Result<bar::MyMono::SpawnHandle, u32> = bar::spawn_after(Seconds(2_u32), 0);
|
||||
if let Ok(handle) = b {
|
||||
let _: Result<u32, ()> = handle.cancel();
|
||||
}
|
||||
// Not default
|
||||
let _: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_at(MyMono::now());
|
||||
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)> =
|
||||
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))
|
||||
}
|
||||
|
||||
#[idle]
|
||||
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 {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Reference in a new issue