From 4b370c3d602a1e43d0bc4f1c8deff629e838c784 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Thu, 11 Mar 2021 23:27:54 +0100 Subject: [PATCH] added .no to not yet supported examples --- Cargo.toml | 6 +-- examples/binds.rs | 51 -------------------- examples/destructure.rs | 51 -------------------- examples/generics.rs | 67 -------------------------- examples/hardware.rs | 55 --------------------- examples/idle.rs | 36 -------------- examples/init.rs | 37 --------------- examples/late.rs | 54 --------------------- examples/message.rs | 48 ------------------- examples/not-sync.rs | 43 ----------------- examples/only-shared-access.rs | 40 ---------------- examples/pool.rs | 68 -------------------------- examples/static.rs | 57 ---------------------- examples/t-late-not-send.rs | 42 ---------------- examples/t-resource.rs | 81 ------------------------------- examples/task-local-minimal.rs | 12 ++--- examples/task-local.rs | 87 ---------------------------------- 17 files changed, 9 insertions(+), 826 deletions(-) delete mode 100644 examples/binds.rs delete mode 100644 examples/destructure.rs delete mode 100644 examples/generics.rs delete mode 100644 examples/hardware.rs delete mode 100644 examples/idle.rs delete mode 100644 examples/init.rs delete mode 100644 examples/late.rs delete mode 100644 examples/message.rs delete mode 100644 examples/not-sync.rs delete mode 100644 examples/only-shared-access.rs delete mode 100644 examples/pool.rs delete mode 100644 examples/static.rs delete mode 100644 examples/t-late-not-send.rs delete mode 100644 examples/t-resource.rs delete mode 100644 examples/task-local.rs diff --git a/Cargo.toml b/Cargo.toml index 7a3d30e7e8..2f2182fdc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,9 +23,9 @@ name = "rtic" name = "periodic" required-features = ["__v7"] -[[example]] -name = "pool" -required-features = ["__v7"] +# [[example]] +# name = "pool" +# required-features = ["__v7"] [[example]] name = "spawn_after" diff --git a/examples/binds.rs b/examples/binds.rs deleted file mode 100644 index 9cbe299486..0000000000 --- a/examples/binds.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! examples/binds.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -// `examples/interrupt.rs` rewritten to use `binds` -#[rtic::app(device = lm3s6965)] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use lm3s6965::Interrupt; - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - rtic::pend(Interrupt::UART0); - - hprintln!("init").unwrap(); - - (init::LateResources {}, init::Monotonics()) - } - - #[idle] - fn idle(_: idle::Context) -> ! { - hprintln!("idle").unwrap(); - - rtic::pend(Interrupt::UART0); - - debug::exit(debug::EXIT_SUCCESS); - - loop { - cortex_m::asm::nop(); - } - } - - #[task(binds = UART0)] - fn foo(_: foo::Context) { - static mut TIMES: u32 = 0; - - *TIMES += 1; - - hprintln!( - "foo called {} time{}", - *TIMES, - if *TIMES > 1 { "s" } else { "" } - ) - .unwrap(); - } -} diff --git a/examples/destructure.rs b/examples/destructure.rs deleted file mode 100644 index d085e4bf3f..0000000000 --- a/examples/destructure.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! examples/destructure.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965)] -mod app { - use cortex_m_semihosting::hprintln; - use lm3s6965::Interrupt; - - #[resources] - struct Resources { - // Some resources to work with - #[init(0)] - a: u32, - #[init(0)] - b: u32, - #[init(0)] - c: u32, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - rtic::pend(Interrupt::UART0); - rtic::pend(Interrupt::UART1); - - (init::LateResources {}, init::Monotonics()) - } - - // Direct destructure - #[task(binds = UART0, resources = [&a, &b, &c])] - fn uart0(cx: uart0::Context) { - let a = cx.resources.a; - let b = cx.resources.b; - let c = cx.resources.c; - - hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap(); - } - - // De-structure-ing syntax - #[task(binds = UART1, resources = [&a, &b, &c])] - fn uart1(cx: uart1::Context) { - let uart1::Resources { a, b, c } = cx.resources; - - hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap(); - } -} diff --git a/examples/generics.rs b/examples/generics.rs deleted file mode 100644 index eabfff7ece..0000000000 --- a/examples/generics.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! examples/generics.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use cortex_m_semihosting::hprintln; -use panic_semihosting as _; -use rtic::Mutex; - -#[rtic::app(device = lm3s6965)] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use lm3s6965::Interrupt; - - #[resources] - struct Resources { - #[init(0)] - shared: u32, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - rtic::pend(Interrupt::UART0); - rtic::pend(Interrupt::UART1); - - (init::LateResources {}, init::Monotonics()) - } - - #[task(binds = UART0, resources = [shared])] - fn uart0(c: uart0::Context) { - static mut STATE: u32 = 0; - - hprintln!("UART0(STATE = {})", *STATE).unwrap(); - - // second argument has type `resources::shared` - super::advance(STATE, c.resources.shared); - - rtic::pend(Interrupt::UART1); - - debug::exit(debug::EXIT_SUCCESS); - } - - #[task(binds = UART1, priority = 2, resources = [shared])] - fn uart1(c: uart1::Context) { - static mut STATE: u32 = 0; - - hprintln!("UART1(STATE = {})", *STATE).unwrap(); - - // second argument has type `resources::shared` - super::advance(STATE, c.resources.shared); - } -} - -// the second parameter is generic: it can be any type that implements the `Mutex` trait -fn advance(state: &mut u32, mut shared: impl Mutex) { - *state += 1; - - let (old, new) = shared.lock(|shared: &mut u32| { - let old = *shared; - *shared += *state; - (old, *shared) - }); - - hprintln!("shared: {} -> {}", old, new).unwrap(); -} diff --git a/examples/hardware.rs b/examples/hardware.rs deleted file mode 100644 index 3cf988073f..0000000000 --- a/examples/hardware.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! examples/hardware.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965)] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use lm3s6965::Interrupt; - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - // Pends the UART0 interrupt but its handler won't run until *after* - // `init` returns because interrupts are disabled - rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend - - hprintln!("init").unwrap(); - - (init::LateResources {}, init::Monotonics()) - } - - #[idle] - fn idle(_: idle::Context) -> ! { - // interrupts are enabled again; the `UART0` handler runs at this point - - hprintln!("idle").unwrap(); - - rtic::pend(Interrupt::UART0); - - debug::exit(debug::EXIT_SUCCESS); - - loop { - cortex_m::asm::nop(); - } - } - - #[task(binds = UART0)] - fn uart0(_: uart0::Context) { - static mut TIMES: u32 = 0; - - // Safe access to local `static mut` variable - *TIMES += 1; - - hprintln!( - "UART0 called {} time{}", - *TIMES, - if *TIMES > 1 { "s" } else { "" } - ) - .unwrap(); - } -} diff --git a/examples/idle.rs b/examples/idle.rs deleted file mode 100644 index db03dc708a..0000000000 --- a/examples/idle.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! examples/idle.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965)] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - hprintln!("init").unwrap(); - - (init::LateResources {}, init::Monotonics()) - } - - #[idle] - fn idle(_: idle::Context) -> ! { - static mut X: u32 = 0; - - // Safe access to local `static mut` variable - let _x: &'static mut u32 = X; - - hprintln!("idle").unwrap(); - - debug::exit(debug::EXIT_SUCCESS); - - loop { - cortex_m::asm::nop(); - } - } -} diff --git a/examples/init.rs b/examples/init.rs deleted file mode 100644 index 9de7958147..0000000000 --- a/examples/init.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! examples/init.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, peripherals = true)] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - - #[init] - fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { - static mut X: u32 = 0; - - // Cortex-M peripherals - let _core: cortex_m::Peripherals = cx.core; - - // Device specific peripherals - let _device: lm3s6965::Peripherals = cx.device; - - // Safe access to local `static mut` variable - let _x: &'static mut u32 = X; - - // Access to the critical section token, - // to indicate that this is a critical seciton - let _cs_token: bare_metal::CriticalSection = cx.cs; - - hprintln!("init").unwrap(); - - debug::exit(debug::EXIT_SUCCESS); - - (init::LateResources {}, init::Monotonics()) - } -} diff --git a/examples/late.rs b/examples/late.rs deleted file mode 100644 index e65b6e6971..0000000000 --- a/examples/late.rs +++ /dev/null @@ -1,54 +0,0 @@ -//! examples/late.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965)] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use heapless::{ - consts::*, - i, - spsc::{Consumer, Producer, Queue}, - }; - use lm3s6965::Interrupt; - - // Late resources - #[resources] - struct Resources { - p: Producer<'static, u32, U4>, - c: Consumer<'static, u32, U4>, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - static mut Q: Queue = Queue(i::Queue::new()); - - let (p, c) = Q.split(); - - // Initialization of late resources - (init::LateResources { p, c }, init::Monotonics()) - } - - #[idle(resources = [c])] - fn idle(mut c: idle::Context) -> ! { - loop { - if let Some(byte) = c.resources.c.lock(|c| c.dequeue()) { - hprintln!("received message: {}", byte).unwrap(); - - debug::exit(debug::EXIT_SUCCESS); - } else { - rtic::pend(Interrupt::UART0); - } - } - } - - #[task(binds = UART0, resources = [p])] - fn uart0(mut c: uart0::Context) { - c.resources.p.lock(|p| p.enqueue(42).unwrap()); - } -} diff --git a/examples/message.rs b/examples/message.rs deleted file mode 100644 index 722e73a710..0000000000 --- a/examples/message.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! examples/message.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - foo::spawn(/* no message */).unwrap(); - - (init::LateResources {}, init::Monotonics()) - } - - #[task] - fn foo(_: foo::Context) { - static mut COUNT: u32 = 0; - - hprintln!("foo").unwrap(); - - bar::spawn(*COUNT).unwrap(); - *COUNT += 1; - } - - #[task] - fn bar(_: bar::Context, x: u32) { - hprintln!("bar({})", x).unwrap(); - - baz::spawn(x + 1, x + 2).unwrap(); - } - - #[task] - fn baz(_: baz::Context, x: u32, y: u32) { - hprintln!("baz({}, {})", x, y).unwrap(); - - if x + y > 4 { - debug::exit(debug::EXIT_SUCCESS); - } - - foo::spawn().unwrap(); - } -} diff --git a/examples/not-sync.rs b/examples/not-sync.rs deleted file mode 100644 index f01d40432a..0000000000 --- a/examples/not-sync.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! `examples/not-sync.rs` - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use core::marker::PhantomData; -use panic_semihosting as _; - -pub struct NotSync { - _0: PhantomData<*const ()>, -} - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use super::NotSync; - use core::marker::PhantomData; - use cortex_m_semihosting::debug; - - #[resources] - struct Resources { - #[init(NotSync { _0: PhantomData })] - shared: NotSync, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - debug::exit(debug::EXIT_SUCCESS); - - (init::LateResources {}, init::Monotonics()) - } - - #[task(resources = [&shared])] - fn foo(c: foo::Context) { - let _: &NotSync = c.resources.shared; - } - - #[task(resources = [&shared])] - fn bar(c: bar::Context) { - let _: &NotSync = c.resources.shared; - } -} diff --git a/examples/only-shared-access.rs b/examples/only-shared-access.rs deleted file mode 100644 index 2c6ad4c4be..0000000000 --- a/examples/only-shared-access.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! examples/static.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965)] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use lm3s6965::Interrupt; - - #[resources] - struct Resources { - key: u32, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - rtic::pend(Interrupt::UART0); - rtic::pend(Interrupt::UART1); - - (init::LateResources { key: 0xdeadbeef }, init::Monotonics()) - } - - #[task(binds = UART0, resources = [&key])] - fn uart0(cx: uart0::Context) { - let key: &u32 = cx.resources.key; - hprintln!("UART0(key = {:#x})", key).unwrap(); - - debug::exit(debug::EXIT_SUCCESS); - } - - #[task(binds = UART1, priority = 2, resources = [&key])] - fn uart1(cx: uart1::Context) { - hprintln!("UART1(key = {:#x})", cx.resources.key).unwrap(); - } -} diff --git a/examples/pool.rs b/examples/pool.rs deleted file mode 100644 index 44405b4911..0000000000 --- a/examples/pool.rs +++ /dev/null @@ -1,68 +0,0 @@ -//! examples/pool.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use heapless::{ - pool, - pool::singleton::{Box, Pool}, -}; -use panic_semihosting as _; -use rtic::app; - -// Declare a pool of 128-byte memory blocks -pool!(P: [u8; 128]); - -#[app(device = lm3s6965, dispatchers = [SSI0, QEI0])] -mod app { - use crate::{Box, Pool}; - use cortex_m_semihosting::{debug, hprintln}; - use lm3s6965::Interrupt; - - // Import the memory pool into scope - use super::P; - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - static mut MEMORY: [u8; 512] = [0; 512]; - - // Increase the capacity of the memory pool by ~4 - P::grow(MEMORY); - - rtic::pend(Interrupt::I2C0); - - (init::LateResources {}, init::Monotonics()) - } - - #[task(binds = I2C0, priority = 2)] - fn i2c0(_: i2c0::Context) { - // claim a memory block, leave it uninitialized and .. - let x = P::alloc().unwrap().freeze(); - - // .. send it to the `foo` task - foo::spawn(x).ok().unwrap(); - - // send another block to the task `bar` - bar::spawn(P::alloc().unwrap().freeze()).ok().unwrap(); - } - - #[task] - fn foo(_: foo::Context, x: Box

) { - hprintln!("foo({:?})", x.as_ptr()).unwrap(); - - // explicitly return the block to the pool - drop(x); - - debug::exit(debug::EXIT_SUCCESS); - } - - #[task(priority = 2)] - fn bar(_: bar::Context, x: Box

) { - hprintln!("bar({:?})", x.as_ptr()).unwrap(); - - // this is done automatically so we can omit the call to `drop` - // drop(x); - } -} diff --git a/examples/static.rs b/examples/static.rs deleted file mode 100644 index cbbc539962..0000000000 --- a/examples/static.rs +++ /dev/null @@ -1,57 +0,0 @@ -//! examples/static.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965)] -mod app { - - use cortex_m_semihosting::{debug, hprintln}; - use heapless::{ - consts::*, - i, - spsc::{Consumer, Producer, Queue}, - }; - use lm3s6965::Interrupt; - - // Late resources - #[resources] - struct Resources { - p: Producer<'static, u32, U4>, - c: Consumer<'static, u32, U4>, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - static mut Q: Queue = Queue(i::Queue::new()); - - let (p, c) = Q.split(); - - // Initialization of late resources - (init::LateResources { p, c }, init::Monotonics()) - } - - #[idle(resources = [c])] - fn idle(mut c: idle::Context) -> ! { - loop { - if let Some(byte) = c.resources.c.lock(|c| c.dequeue()) { - hprintln!("received message: {}", byte).unwrap(); - - debug::exit(debug::EXIT_SUCCESS); - } else { - rtic::pend(Interrupt::UART0); - } - } - } - - #[task(binds = UART0, resources = [p])] - fn uart0(mut c: uart0::Context) { - static mut KALLE: u32 = 0; - *KALLE += 1; - c.resources.p.lock(|p| p.enqueue(42).unwrap()); - } -} diff --git a/examples/t-late-not-send.rs b/examples/t-late-not-send.rs deleted file mode 100644 index 579f843675..0000000000 --- a/examples/t-late-not-send.rs +++ /dev/null @@ -1,42 +0,0 @@ -//! [compile-pass] late resources don't need to be `Send` if they are owned by `idle` - -#![no_main] -#![no_std] - -use core::marker::PhantomData; - -use panic_semihosting as _; - -pub struct NotSend { - _0: PhantomData<*const ()>, -} - -#[rtic::app(device = lm3s6965)] -mod app { - use super::NotSend; - use core::marker::PhantomData; - - #[resources] - struct Resources { - x: NotSend, - #[init(None)] - y: Option, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - ( - init::LateResources { - x: NotSend { _0: PhantomData }, - }, - init::Monotonics(), - ) - } - - #[idle(resources = [x, y])] - fn idle(_: idle::Context) -> ! { - loop { - cortex_m::asm::nop(); - } - } -} diff --git a/examples/t-resource.rs b/examples/t-resource.rs deleted file mode 100644 index 6e83069d7b..0000000000 --- a/examples/t-resource.rs +++ /dev/null @@ -1,81 +0,0 @@ -//! [compile-pass] Check code generation of resources - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965)] -mod app { - #[resources] - struct Resources { - #[init(0)] - o1: u32, // init - #[init(0)] - o2: u32, // idle - #[init(0)] - o3: u32, // EXTI0 - #[init(0)] - o4: u32, // idle - #[init(0)] - o5: u32, // EXTI1 - #[init(0)] - o6: u32, // init - #[init(0)] - s1: u32, // idle & uart0 - #[init(0)] - s2: u32, // uart0 & uart1 - #[init(0)] - s3: u32, // idle & uart0 - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - (init::LateResources {}, init::Monotonics()) - } - - #[idle(resources = [o2, &o4, s1, &s3])] - fn idle(mut c: idle::Context) -> ! { - // owned by `idle` == `&'static mut` - let _: resources::o2 = c.resources.o2; - - // owned by `idle` == `&'static` if read-only - let _: &u32 = c.resources.o4; - - // shared with `idle` == `Mutex` - c.resources.s1.lock(|_| {}); - - // `&` if read-only - let _: &u32 = c.resources.s3; - - loop { - cortex_m::asm::nop(); - } - } - - #[task(binds = UART0, resources = [o3, s1, s2, &s3])] - fn uart0(c: uart0::Context) { - // owned by interrupt == `&mut` - let _: resources::o3 = c.resources.o3; - - // no `Mutex` proxy when access from highest priority task - let _: resources::s1 = c.resources.s1; - - // no `Mutex` proxy when co-owned by cooperative (same priority) tasks - let _: resources::s2 = c.resources.s2; - - // `&` if read-only - let _: &u32 = c.resources.s3; - } - - #[task(binds = UART1, resources = [s2, &o5])] - fn uart1(c: uart1::Context) { - // owned by interrupt == `&` if read-only - let _: &u32 = c.resources.o5; - - // no `Mutex` proxy when co-owned by cooperative (same priority) tasks - let _: resources::s2 = c.resources.s2; - } -} diff --git a/examples/task-local-minimal.rs b/examples/task-local-minimal.rs index f83493c29d..29132f00c5 100644 --- a/examples/task-local-minimal.rs +++ b/examples/task-local-minimal.rs @@ -1,6 +1,6 @@ //! examples/task-local_minimal.rs #![deny(unsafe_code)] -#![deny(warnings)] +//#![deny(warnings)] #![no_main] #![no_std] @@ -14,18 +14,18 @@ mod app { struct Resources { // A local (move), late resource #[task_local] - l: u32, + task_local: u32, } #[init] fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - (init::LateResources { l: 42 }, init::Monotonics()) + (init::LateResources { task_local: 42 }, init::Monotonics()) } - // l is task_local - #[idle(resources =[l])] + // task_local is task_local + #[idle(resources =[task_local])] fn idle(cx: idle::Context) -> ! { - hprintln!("IDLE:l = {}", cx.resources.l).unwrap(); + hprintln!("IDLE:l = {}", cx.resources.task_local).unwrap(); debug::exit(debug::EXIT_SUCCESS); loop { cortex_m::asm::nop(); diff --git a/examples/task-local.rs b/examples/task-local.rs deleted file mode 100644 index 3020c3b3af..0000000000 --- a/examples/task-local.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! examples/task-local.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965)] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use lm3s6965::Interrupt; - - #[resources] - struct Resources { - // An early resource - #[init(0)] - shared: u32, - - // A local (move), early resource - #[task_local] - #[init(1)] - l1: u32, - - // An exclusive, early resource - #[lock_free] - #[init(1)] - e1: u32, - - // A local (move), late resource - #[task_local] - l2: u32, - - // An exclusive, late resource - #[lock_free] - e2: u32, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - rtic::pend(Interrupt::UART0); - rtic::pend(Interrupt::UART1); - (init::LateResources { e2: 2, l2: 2 }, init::Monotonics()) - } - - // `shared` cannot be accessed from this context - // l1 ok (task_local) - // e2 ok (lock_free) - #[idle(resources =[l1, e2])] - fn idle(cx: idle::Context) -> ! { - hprintln!("IDLE:l1 = {}", cx.resources.l1).unwrap(); - hprintln!("IDLE:e2 = {}", cx.resources.e2).unwrap(); - debug::exit(debug::EXIT_SUCCESS); - loop { - cortex_m::asm::nop(); - } - } - - // `shared` can be accessed from this context - // l2 ok (task_local) - // e1 ok (lock_free) - #[task(priority = 1, binds = UART0, resources = [shared, l2, e1])] - fn uart0(mut cx: uart0::Context) { - let shared = cx.resources.shared.lock(|shared| { - *shared += 1; - *shared - }); - *cx.resources.e1 += 10; - hprintln!("UART0: shared = {}", shared).unwrap(); - hprintln!("UART0:l2 = {}", cx.resources.l2).unwrap(); - hprintln!("UART0:e1 = {}", cx.resources.e1).unwrap(); - } - - // `shared` can be accessed from this context - // e1 ok (lock_free) - #[task(priority = 1, binds = UART1, resources = [shared, e1])] - fn uart1(mut cx: uart1::Context) { - let shared = cx.resources.shared.lock(|shared| { - *shared += 1; - *shared - }); - - hprintln!("UART1: shared = {}", shared).unwrap(); - hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap(); - } -}