Now with spawn/schedule from anywhere

This commit is contained in:
Emil Fresk 2020-10-11 18:38:38 +02:00
parent c83b15b643
commit 524273c96a
19 changed files with 172 additions and 694 deletions

View file

@ -13,7 +13,7 @@ use rtic::cyccnt::{Instant, U32Ext as _};
// NOTE: does NOT work on QEMU!
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
mod app {
#[init(schedule = [foo, bar])]
#[init()]
fn init(mut cx: init::Context) -> init::LateResources {
// Initialize (enable) the monotonic timer (CYCCNT)
cx.core.DCB.enable_trace();
@ -28,10 +28,10 @@ mod app {
hprintln!("init @ {:?}", now).unwrap();
// Schedule `foo` to run 8e6 cycles (clock cycles) in the future
cx.schedule.foo(now + 8_000_000.cycles()).unwrap();
foo::schedule(now + 8_000_000.cycles()).unwrap();
// Schedule `bar` to run 4e6 cycles in the future
cx.schedule.bar(now + 4_000_000.cycles()).unwrap();
bar::schedule(now + 4_000_000.cycles()).unwrap();
init::LateResources {}
}

View file

@ -11,8 +11,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init(spawn = [foo])]
fn init(_c: init::Context) {
fn init(_c: init::Context) -> init::LateResources {
foo::spawn(1, 2).unwrap();
init::LateResources {}
}
#[task()]

View file

@ -10,12 +10,14 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init(spawn = [foo, foo2])]
fn init(_c: init::Context) {
#[init]
fn init(_c: init::Context) -> init::LateResources {
foo::spawn(1, 2).unwrap();
init::LateResources {}
}
#[task()]
#[task]
fn foo(_c: foo::Context, x: i32, y: u32) {
hprintln!("foo {}, {}", x, y).unwrap();
if x == 2 {
@ -24,7 +26,7 @@ mod app {
foo2::spawn(2).unwrap();
}
#[task()]
#[task]
fn foo2(_c: foo2::Context, x: i32) {
hprintln!("foo2 {}", x).unwrap();
foo::spawn(x, 0).unwrap();