From abd917ceff64e5f4fd587ae1f124b575949dc233 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Sat, 13 Mar 2021 14:35:07 +0100 Subject: [PATCH] work on early/late resources --- examples/late.rs | 17 +++++----- examples/minimal-task-local-early.rs | 2 +- examples/minimal-task-local-type-early.rs | 38 +++++++++++++++++++++ examples/minimal-task-local-type-late.rs | 41 +++++++++++++++++++++++ macros/src/codegen/post_init.rs | 3 ++ 5 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 examples/minimal-task-local-type-early.rs create mode 100644 examples/minimal-task-local-type-late.rs diff --git a/examples/late.rs b/examples/late.rs index 3f480fb347..1e9859f20c 100644 --- a/examples/late.rs +++ b/examples/late.rs @@ -1,7 +1,7 @@ //! examples/late.rs #![deny(unsafe_code)] -#![deny(warnings)] +// #![deny(warnings)] #![no_main] #![no_std] @@ -20,7 +20,7 @@ mod app { // Late resources #[resources] struct Resources { - p: Producer<'static, u32, U4>, + // p: Producer<'static, u32, U4>, c: Consumer<'static, u32, U4>, #[task_local] #[init(Queue(i::Queue::new()))] @@ -29,12 +29,11 @@ mod app { #[init(resources = [q])] fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) { - // static mut Q: Queue = Queue(i::Queue::new()); - let (p, c) = cx.resources.q.split(); // Initialization of late resources - (init::LateResources { p, c }, init::Monotonics()) + // (init::LateResources { p, c }, init::Monotonics()) + (init::LateResources { c }, init::Monotonics()) } #[idle(resources = [c])] @@ -50,8 +49,8 @@ mod app { } } - #[task(binds = UART0, resources = [p])] - fn uart0(mut c: uart0::Context) { - c.resources.p.lock(|p| p.enqueue(42).unwrap()); - } + // #[task(binds = UART0, resources = [p])] + // fn uart0(mut c: uart0::Context) { + // c.resources.p.lock(|p| p.enqueue(42).unwrap()); + // } } diff --git a/examples/minimal-task-local-early.rs b/examples/minimal-task-local-early.rs index e77a8a8b57..23447814d3 100644 --- a/examples/minimal-task-local-early.rs +++ b/examples/minimal-task-local-early.rs @@ -1,4 +1,4 @@ -//! examples/task-local-minimal-early.rs +//! examples/minmal-task-local-early.rs #![deny(unsafe_code)] #![deny(warnings)] #![no_main] diff --git a/examples/minimal-task-local-type-early.rs b/examples/minimal-task-local-type-early.rs new file mode 100644 index 0000000000..da1f8e2900 --- /dev/null +++ b/examples/minimal-task-local-type-early.rs @@ -0,0 +1,38 @@ +//! examples/minimal-task-local-type-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}; + + pub struct TaskLocal { + x: u32, + } + #[resources] + struct Resources { + // A local (move), late resource + #[task_local] + #[init(TaskLocal {x : 42 })] + early: TaskLocal, + } + + #[init] + fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { + (init::LateResources {}, init::Monotonics()) + } + + // task_local is task_local + #[idle(resources = [early])] + fn idle(cx: idle::Context) -> ! { + hprintln!("IDLE:l = {}", cx.resources.early.x).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop { + cortex_m::asm::nop(); + } + } +} diff --git a/examples/minimal-task-local-type-late.rs b/examples/minimal-task-local-type-late.rs new file mode 100644 index 0000000000..051204b726 --- /dev/null +++ b/examples/minimal-task-local-type-late.rs @@ -0,0 +1,41 @@ +//! examples/minimal-task-local-type-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}; + pub struct TaskLocal { + x: u32, + } + #[resources] + struct Resources { + // A local (move), late resource + #[task_local] + late: crate::app::TaskLocal, + } + + #[init] + fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { + ( + init::LateResources { + late: TaskLocal { x: 42 }, + }, + init::Monotonics(), + ) + } + + // task_local is task_local + #[idle(resources = [late])] + fn idle(cx: idle::Context) -> ! { + hprintln!("IDLE:late = {}", cx.resources.late.x).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop { + cortex_m::asm::nop(); + } + } +} diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index c95ee7da75..733d6eecc4 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -31,6 +31,9 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { } for (i, (monotonic, _)) in app.monotonics.iter().enumerate() { + let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + stmts.push(quote!(#[doc = #doc])); + let idx = Index { index: i as u32, span: Span::call_site(),