From d4d5713e5ac586e662d53468f8852ea09d1634c1 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Sat, 13 Mar 2021 15:24:53 +0100 Subject: [PATCH] added working examples --- ..._resource.rs => minimal-early-resource.rs} | 4 +- ...e_resource.rs => minimal-late-resource.rs} | 4 +- examples/minimal-task-local-early.rs | 7 +-- examples/minimal-task-local-late.rs | 1 + examples/minimal-task-local-to-shared.rs | 38 ++++++++++++++ examples/minimal-task-local-to-task-local.rs | 39 ++++++++++++++ examples/minimal-task-local-type-early.rs | 1 + examples/minimal-task-local-type-late.rs | 1 + ...imal-task-local-type-to-task-local-type.rs | 51 +++++++++++++++++++ 9 files changed, 141 insertions(+), 5 deletions(-) rename examples/{minimal_early_resource.rs => minimal-early-resource.rs} (75%) rename examples/{minimal_late_resource.rs => minimal-late-resource.rs} (81%) create mode 100644 examples/minimal-task-local-to-shared.rs create mode 100644 examples/minimal-task-local-to-task-local.rs create mode 100644 examples/minimal-task-local-type-to-task-local-type.rs diff --git a/examples/minimal_early_resource.rs b/examples/minimal-early-resource.rs similarity index 75% rename from examples/minimal_early_resource.rs rename to examples/minimal-early-resource.rs index f6b6a1a5a8..2fd1db6d76 100644 --- a/examples/minimal_early_resource.rs +++ b/examples/minimal-early-resource.rs @@ -1,4 +1,4 @@ -//! examples/idle.rs +//! examples/minimal-early-resource.rs #![deny(unsafe_code)] #![deny(warnings)] @@ -9,6 +9,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; #[resources] struct Resources { @@ -18,6 +19,7 @@ mod app { #[idle(resources = [resource_x])] fn idle(_: idle::Context) -> ! { + debug::exit(debug::EXIT_SUCCESS); loop { cortex_m::asm::nop(); } diff --git a/examples/minimal_late_resource.rs b/examples/minimal-late-resource.rs similarity index 81% rename from examples/minimal_late_resource.rs rename to examples/minimal-late-resource.rs index 2419b8d7d2..faa1a350c0 100644 --- a/examples/minimal_late_resource.rs +++ b/examples/minimal-late-resource.rs @@ -1,4 +1,4 @@ -//! examples/minimal_late_resource.rs +//! examples/minimal-late-resource.rs #![deny(unsafe_code)] #![deny(warnings)] @@ -9,6 +9,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; #[resources] struct Resources { @@ -22,6 +23,7 @@ mod app { #[idle(resources = [resource_x])] fn idle(_: idle::Context) -> ! { + debug::exit(debug::EXIT_SUCCESS); loop { cortex_m::asm::nop(); } diff --git a/examples/minimal-task-local-early.rs b/examples/minimal-task-local-early.rs index 23447814d3..013b39c400 100644 --- a/examples/minimal-task-local-early.rs +++ b/examples/minimal-task-local-early.rs @@ -1,4 +1,5 @@ -//! examples/minmal-task-local-early.rs +//! examples/minimal-task-local-early.rs + #![deny(unsafe_code)] #![deny(warnings)] #![no_main] @@ -12,7 +13,7 @@ mod app { #[resources] struct Resources { - // A local (move), late resource + // A local (move), early resource #[task_local] #[init(42)] early: u32, @@ -26,7 +27,7 @@ mod app { // task_local is task_local #[idle(resources = [early])] fn idle(cx: idle::Context) -> ! { - hprintln!("IDLE:l = {}", cx.resources.early).unwrap(); + hprintln!("IDLE:early = {}", cx.resources.early).unwrap(); debug::exit(debug::EXIT_SUCCESS); loop { cortex_m::asm::nop(); diff --git a/examples/minimal-task-local-late.rs b/examples/minimal-task-local-late.rs index 9815516cf7..22eea63b76 100644 --- a/examples/minimal-task-local-late.rs +++ b/examples/minimal-task-local-late.rs @@ -1,4 +1,5 @@ //! examples/minimal-task-local-late.rs + #![deny(unsafe_code)] #![deny(warnings)] #![no_main] diff --git a/examples/minimal-task-local-to-shared.rs b/examples/minimal-task-local-to-shared.rs new file mode 100644 index 0000000000..eaf7af594c --- /dev/null +++ b/examples/minimal-task-local-to-shared.rs @@ -0,0 +1,38 @@ +//! examples/minimal-task-local-early.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}; + + #[resources] + struct Resources { + shared: u32, + + #[task_local] + #[init(42)] + init_resource: u32, + } + + #[init(resources = [ init_resource ])] + fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { + let ir = *cx.resources.init_resource; + (init::LateResources { shared: ir }, init::Monotonics()) + } + + // task_local is task_local + #[idle(resources = [shared])] + fn idle(mut cx: idle::Context) -> ! { + hprintln!("IDLE:shared = {}", cx.resources.shared.lock(|s| *s)).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop { + cortex_m::asm::nop(); + } + } +} diff --git a/examples/minimal-task-local-to-task-local.rs b/examples/minimal-task-local-to-task-local.rs new file mode 100644 index 0000000000..499f3df1a4 --- /dev/null +++ b/examples/minimal-task-local-to-task-local.rs @@ -0,0 +1,39 @@ +//! examples/minimal-task-local-to-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}; + + #[resources] + struct Resources { + #[task_local] + shared: u32, + + #[task_local] + #[init(42)] + init_resource: u32, + } + + #[init(resources = [ init_resource ])] + fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { + let ir = *cx.resources.init_resource; + (init::LateResources { shared: ir }, init::Monotonics()) + } + + // task_local is task_local + #[idle(resources = [shared])] + fn idle(cx: idle::Context) -> ! { + hprintln!("IDLE:shared = {}", cx.resources.shared).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop { + cortex_m::asm::nop(); + } + } +} diff --git a/examples/minimal-task-local-type-early.rs b/examples/minimal-task-local-type-early.rs index da1f8e2900..387412ebb2 100644 --- a/examples/minimal-task-local-type-early.rs +++ b/examples/minimal-task-local-type-early.rs @@ -1,4 +1,5 @@ //! examples/minimal-task-local-type-early.rs + #![deny(unsafe_code)] #![deny(warnings)] #![no_main] diff --git a/examples/minimal-task-local-type-late.rs b/examples/minimal-task-local-type-late.rs index 051204b726..f484b2d56b 100644 --- a/examples/minimal-task-local-type-late.rs +++ b/examples/minimal-task-local-type-late.rs @@ -1,4 +1,5 @@ //! examples/minimal-task-local-type-late.rs + #![deny(unsafe_code)] #![deny(warnings)] #![no_main] diff --git a/examples/minimal-task-local-type-to-task-local-type.rs b/examples/minimal-task-local-type-to-task-local-type.rs new file mode 100644 index 0000000000..d46b169ca9 --- /dev/null +++ b/examples/minimal-task-local-type-to-task-local-type.rs @@ -0,0 +1,51 @@ +//! examples/minmal-task-local-to-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}; + + pub struct InitType { + x: u32, + } + + pub struct TaskLocal { + y: u32, + } + + #[resources] + struct Resources { + #[task_local] + #[init(InitType { x: 0 })] + init_resource: InitType, + + #[task_local] + local: crate::app::TaskLocal, + } + + #[init(resources = [ init_resource ])] + fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { + let y = cx.resources.init_resource.x; + ( + init::LateResources { + local: TaskLocal { y }, + }, + init::Monotonics(), + ) + } + + // task_local is task_local + #[idle(resources = [local])] + fn idle(cx: idle::Context) -> ! { + hprintln!("IDLE:shared = {}", cx.resources.local.y).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop { + cortex_m::asm::nop(); + } + } +}