From e2364aae3eebf3326534bd4818d0312a03817538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 8 Sep 2020 17:51:10 +0000 Subject: Updated examples and rtic-name --- examples/local-cfg-task-local.rs | 65 -------------------- examples/local-cfg.rs | 127 --------------------------------------- examples/local.rs | 79 ------------------------ examples/local_err.rs | 82 ------------------------- examples/local_minimal.rs | 30 --------- examples/static.rs | 15 +++-- examples/task-local-minimal.rs | 33 ++++++++++ examples/task-local.rs | 82 +++++++++++++++++++++++++ 8 files changed, 125 insertions(+), 388 deletions(-) delete mode 100644 examples/local-cfg-task-local.rs delete mode 100644 examples/local-cfg.rs delete mode 100644 examples/local.rs delete mode 100644 examples/local_err.rs delete mode 100644 examples/local_minimal.rs create mode 100644 examples/task-local-minimal.rs create mode 100644 examples/task-local.rs (limited to 'examples') diff --git a/examples/local-cfg-task-local.rs b/examples/local-cfg-task-local.rs deleted file mode 100644 index 4906911..0000000 --- a/examples/local-cfg-task-local.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! examples/local-cfg-task-local.rs - -#![deny(unsafe_code)] -//#![deny(warnings)] -#![no_main] -#![no_std] - -use cortex_m_semihosting::hprintln; -use cortex_m_semihosting::debug; -use lm3s6965::Interrupt; -use panic_semihosting as _; - -#[rtfm::app(device = lm3s6965)] -const APP: () = { - struct Resources { - // A local (move), early resource - #[cfg(feature = "feature_l1")] - #[task_local] - #[init(1)] - l1: u32, - - // A local (move), late resource - #[task_local] - l2: u32, - } - - #[init] - fn init(_: init::Context) -> init::LateResources { - rtfm::pend(Interrupt::UART0); - rtfm::pend(Interrupt::UART1); - init::LateResources { - #[cfg(feature = "feature_l2")] - l2: 2, - #[cfg(not(feature = "feature_l2"))] - l2: 5 - } - } - - // l1 ok (task_local) - #[idle(resources =[#[cfg(feature = "feature_l1")]l1])] - fn idle(_cx: idle::Context) -> ! { - #[cfg(feature = "feature_l1")] - hprintln!("IDLE:l1 = {}", _cx.resources.l1).unwrap(); - debug::exit(debug::EXIT_SUCCESS); - loop {} - } - - // l2 ok (task_local) - #[task(priority = 1, binds = UART0, resources = [ - #[cfg(feature = "feature_l2")]l2, - ])] - fn uart0(_cx: uart0::Context) { - #[cfg(feature = "feature_l2")] - hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap(); - } - - // l2 error, conflicting with uart0 for l2 (task_local) - #[task(priority = 1, binds = UART1, resources = [ - #[cfg(not(feature = "feature_l2"))]l2 - ])] - fn uart1(_cx: uart1::Context) { - #[cfg(not(feature = "feature_l2"))] - hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap(); - } -}; diff --git a/examples/local-cfg.rs b/examples/local-cfg.rs deleted file mode 100644 index b916550..0000000 --- a/examples/local-cfg.rs +++ /dev/null @@ -1,127 +0,0 @@ -//! examples/local.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -#[cfg( - any( - feature = "feature_s", - feature = "feature_e1", - feature = "feature_e2", - feature = "feature_l1", - feature = "feature_l2" - ) - ) -] -use cortex_m_semihosting::hprintln; -use cortex_m_semihosting::debug; -use lm3s6965::Interrupt; -use panic_semihosting as _; - -#[rtfm::app(device = lm3s6965)] -const APP: () = { - struct Resources { - // An early resource - #[cfg(feature = "feature_s")] - #[init(0)] - shared: u32, - - // A local (move), early resource - #[cfg(feature = "feature_l1")] - #[task_local] - #[init(1)] - l1: u32, - - // An exclusive, early resource - #[cfg(feature = "feature_e1")] - #[lock_free] - #[init(1)] - e1: u32, - - // A local (move), late resource - #[task_local] - #[cfg(feature = "feature_l2")] - l2: u32, - - // An exclusive, late resource - #[cfg(feature = "feature_e2")] - #[lock_free] - e2: u32, - } - - #[init] - fn init(_: init::Context) -> init::LateResources { - rtfm::pend(Interrupt::UART0); - rtfm::pend(Interrupt::UART1); - init::LateResources { - #[cfg(feature = "feature_e2")] - e2: 2, - #[cfg(feature = "feature_l2")] - l2: 2 - } - } - - // `shared` cannot be accessed from this context - // l1 ok (task_local) - // e2 ok (lock_free) - #[idle(resources =[#[cfg(feature = "feature_l1")]l1, e2])] - fn idle(_cx: idle::Context) -> ! { - #[cfg(feature = "feature_l1")] - hprintln!("IDLE:l1 = {}", _cx.resources.l1).unwrap(); - #[cfg(feature = "feature_e2")] - hprintln!("IDLE:e2 = {}", _cx.resources.e2).unwrap(); - debug::exit(debug::EXIT_SUCCESS); - loop {} - } - - // `shared` can be accessed from this context - // l2 ok (task_local) - // e1 ok (lock_free) - #[task(priority = 1, binds = UART0, resources = [shared, #[cfg(feature = "feature_l2")]l2, #[cfg(feature = "feature_e1")]e1])] - fn uart0(_cx: uart0::Context) { - #[cfg(feature = "feature_s")] - let shared: &mut u32 = _cx.resources.shared; - - #[cfg(feature = "feature_s")] - { - *shared += 1; - } - - #[cfg(feature = "feature_e1")] - { - // Unless put in a closure, the following error: - // error[E0658]: attributes on expressions are experimental - // --> examples/local-cfg.rs:69:9 - // 69 | #[cfg(feature = "feature_x")] - // | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - // = note: see issue #15701 - // for more information - *_cx.resources.e1 += 10; - } - #[cfg(feature = "feature_s")] - hprintln!("UART0: shared = {}", shared).unwrap(); - #[cfg(feature = "feature_l2")] - hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap(); - #[cfg(feature = "feature_e1")] - hprintln!("UART0:e1 = {}", _cx.resources.e1).unwrap(); - } - - // `shared` can be accessed from this context - // e1 ok (lock_free) - #[task(priority = 1, binds = UART1, resources = [#[cfg(feature = "feature_s")]shared, #[cfg(feature = "feature_e1")]e1])] - fn uart1(_cx: uart1::Context) { - #[cfg(feature = "feature_s")] - let shared: &mut u32 = _cx.resources.shared; - #[cfg(feature = "feature_s")] - { - *shared += 1; - } - - #[cfg(feature = "feature_s")] - hprintln!("UART1: shared = {}", shared).unwrap(); - #[cfg(feature = "feature_e1")] - hprintln!("UART1:e1 = {}", _cx.resources.e1).unwrap(); - } -}; diff --git a/examples/local.rs b/examples/local.rs deleted file mode 100644 index 802ab20..0000000 --- a/examples/local.rs +++ /dev/null @@ -1,79 +0,0 @@ -//! examples/local.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use cortex_m_semihosting::{debug, hprintln}; -use lm3s6965::Interrupt; -use panic_semihosting as _; - -#[rtfm::app(device = lm3s6965)] -const APP: () = { - 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 { - rtfm::pend(Interrupt::UART0); - rtfm::pend(Interrupt::UART1); - init::LateResources { e2: 2, l2: 2 } - } - - // `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 {} - } - - // `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(cx: uart0::Context) { - let shared: &mut u32 = cx.resources.shared; - *shared += 1; - *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(cx: uart1::Context) { - let shared: &mut u32 = cx.resources.shared; - *shared += 1; - - hprintln!("UART1: shared = {}", shared).unwrap(); - hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap(); - } -}; diff --git a/examples/local_err.rs b/examples/local_err.rs deleted file mode 100644 index 3be593a..0000000 --- a/examples/local_err.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! examples/local_err.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -// errors here, since we cannot bail compilation or generate stubs -// run cargo expand, then you see the root of the problem... -use cortex_m_semihosting::{debug, hprintln}; -use lm3s6965::Interrupt; -use panic_semihosting as _; - -#[rtfm::app(device = lm3s6965)] -const APP: () = { - 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 { - rtfm::pend(Interrupt::UART0); - rtfm::pend(Interrupt::UART1); - init::LateResources { e2: 2, l2: 2 } - } - - // `shared` cannot be accessed from this context - // l1 ok - // l2 rejeceted (not task_local) - // e2 ok - #[idle(resources =[l1, l2, 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 {} - } - - // `shared` can be accessed from this context - // l2 rejected (not task_local) - // e1 rejected (not lock_free) - #[task(priority = 1, binds = UART0, resources = [shared, l2, e1])] - fn uart0(cx: uart0::Context) { - let shared: &mut u32 = cx.resources.shared; - *shared += 1; - *cx.resources.e1 += 10; - hprintln!("UART0: shared = {}", shared).unwrap(); - hprintln!("UART0:l2 = {}", cx.resources.l2).unwrap(); - hprintln!("UART0:e1 = {}", cx.resources.e1).unwrap(); - } - - // l2 rejected (not task_local) - #[task(priority = 2, binds = UART1, resources = [shared, l2, e1])] - fn uart1(cx: uart1::Context) { - let shared: &mut u32 = cx.resources.shared; - *shared += 1; - - hprintln!("UART1: shared = {}", shared).unwrap(); - hprintln!("UART1:l2 = {}", cx.resources.l2).unwrap(); - hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap(); - } -}; diff --git a/examples/local_minimal.rs b/examples/local_minimal.rs deleted file mode 100644 index 13531c5..0000000 --- a/examples/local_minimal.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! examples/local_minimal.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -use cortex_m_semihosting::{debug, hprintln}; -use panic_semihosting as _; - -#[rtfm::app(device = lm3s6965)] -const APP: () = { - struct Resources { - // A local (move), late resource - #[task_local] - l: u32, - } - - #[init] - fn init(_: init::Context) -> init::LateResources { - init::LateResources { l: 42 } - } - - // l is task_local - #[idle(resources =[l])] - fn idle(cx: idle::Context) -> ! { - hprintln!("IDLE:l = {}", cx.resources.l).unwrap(); - debug::exit(debug::EXIT_SUCCESS); - loop {} - } -}; diff --git a/examples/static.rs b/examples/static.rs index ddcb11e..9c3110c 100644 --- a/examples/static.rs +++ b/examples/static.rs @@ -1,4 +1,4 @@ -//! examples/late.rs +//! examples/static.rs #![deny(unsafe_code)] #![deny(warnings)] @@ -14,9 +14,14 @@ use heapless::{ use lm3s6965::Interrupt; use panic_semihosting as _; -#[rtfm::app(device = lm3s6965)] -const APP: () = { +#[rtic::app(device = lm3s6965)] +mod app { + + use crate::U4; + use crate::{Consumer, Producer}; + // Late resources + #[resources] struct Resources { p: Producer<'static, u32, U4>, c: Consumer<'static, u32, U4>, @@ -40,7 +45,7 @@ const APP: () = { debug::exit(debug::EXIT_SUCCESS); } else { - rtfm::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART0); } } } @@ -51,4 +56,4 @@ const APP: () = { *KALLE += 1; c.resources.p.enqueue(42).unwrap(); } -}; +} diff --git a/examples/task-local-minimal.rs b/examples/task-local-minimal.rs new file mode 100644 index 0000000..fd5ac68 --- /dev/null +++ b/examples/task-local-minimal.rs @@ -0,0 +1,33 @@ +//! examples/task-local_minimal.rs +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::{debug, hprintln}; +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965)] +mod app { + #[resources] + struct Resources { + // A local (move), late resource + #[task_local] + l: u32, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + init::LateResources { l: 42 } + } + + // l is task_local + #[idle(resources =[l])] + fn idle(cx: idle::Context) -> ! { + hprintln!("IDLE:l = {}", cx.resources.l).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop { + cortex_m::asm::nop(); + } + } +} diff --git a/examples/task-local.rs b/examples/task-local.rs new file mode 100644 index 0000000..8f0dfc7 --- /dev/null +++ b/examples/task-local.rs @@ -0,0 +1,82 @@ +//! examples/task-local.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::{debug, hprintln}; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965)] +mod app { + #[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 { + rtic::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART1); + init::LateResources { e2: 2, l2: 2 } + } + + // `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(cx: uart0::Context) { + let shared: &mut u32 = cx.resources.shared; + *shared += 1; + *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(cx: uart1::Context) { + let shared: &mut u32 = cx.resources.shared; + *shared += 1; + + hprintln!("UART1: shared = {}", shared).unwrap(); + hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap(); + } +} -- cgit v1.2.3