diff options
author | 2020-10-15 16:42:30 +0000 | |
---|---|---|
committer | 2020-10-15 16:42:30 +0000 | |
commit | 355cb82d0693fe108ac28ec8a0d77e8aab4e6e06 (patch) | |
tree | 67c0eadf6d8a98a2691b816d46a5103d159d6bbc /examples/types.rs | |
parent | f9303cef1cf5b2d57d26e7667289fbdccf959ea8 (diff) | |
parent | 6808cc7cdf1512a7b10dd43f268f430a676c606e (diff) | |
download | rtic-355cb82d0693fe108ac28ec8a0d77e8aab4e6e06.tar.gz rtic-355cb82d0693fe108ac28ec8a0d77e8aab4e6e06.tar.zst rtic-355cb82d0693fe108ac28ec8a0d77e8aab4e6e06.zip |
Merge #390
390: Spawn and schedule from anywhere r=AfoHT a=korken89
This PR moves RTIC to the spawn and schedule from anywhere syntax.
Notable changes:
* We do no longer support non-`Send` types.
* Some extra code is generated as any task may spawn/schedule any task. However Rust/LLVM does a great job optimizing away non used instantiations (no real code-size difference observed).
* Worst case priority inversion has increased, but it is now predictable.
Upsides:
* With this we should be able to support async/await.
* RTIC tasks can now be callbacks (spawned and scheduled).
* RTIC tasks can be stored.
Needs the following PR to land first: https://github.com/rtic-rs/rtic-syntax/pull/34
The following now works:
```rust
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
mod app {
#[init]
fn init(mut cx: init::Context) -> init::LateResources {
// Init stuff...
// New spawn syntax
foo::spawn().unwrap();
// New schedule syntax
bar::schedule(now + 4_000_000.cycles()).unwrap();
init::LateResources {}
}
#[task]
fn foo(_: foo::Context) {}
#[task]
fn bar(_: bar::Context) {}
extern "C" {
fn SSI0();
}
}
```
Co-authored-by: Per Lindgren <per.lindgren@ltu.se>
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'examples/types.rs')
-rw-r--r-- | examples/types.rs | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/examples/types.rs b/examples/types.rs index 251d004c..b55a98c6 100644 --- a/examples/types.rs +++ b/examples/types.rs @@ -17,44 +17,35 @@ mod app { shared: u32, } - #[init(schedule = [foo], spawn = [foo])] + #[init] fn init(cx: init::Context) -> init::LateResources { let _: cyccnt::Instant = cx.start; let _: rtic::Peripherals = cx.core; let _: lm3s6965::Peripherals = cx.device; - let _: init::Schedule = cx.schedule; - let _: init::Spawn = cx.spawn; debug::exit(debug::EXIT_SUCCESS); init::LateResources {} } - #[idle(schedule = [foo], spawn = [foo])] - fn idle(cx: idle::Context) -> ! { - let _: idle::Schedule = cx.schedule; - let _: idle::Spawn = cx.spawn; - + #[idle] + fn idle(_: idle::Context) -> ! { loop { cortex_m::asm::nop(); } } - #[task(binds = UART0, resources = [shared], schedule = [foo], spawn = [foo])] + #[task(binds = UART0, resources = [shared])] fn uart0(cx: uart0::Context) { let _: cyccnt::Instant = cx.start; let _: resources::shared = cx.resources.shared; - let _: uart0::Schedule = cx.schedule; - let _: uart0::Spawn = cx.spawn; } - #[task(priority = 2, resources = [shared], schedule = [foo], spawn = [foo])] + #[task(priority = 2, resources = [shared])] fn foo(cx: foo::Context) { let _: cyccnt::Instant = cx.scheduled; let _: &mut u32 = cx.resources.shared; let _: foo::Resources = cx.resources; - let _: foo::Schedule = cx.schedule; - let _: foo::Spawn = cx.spawn; } // RTIC requires that unused interrupts are declared in an extern block when |