From 37530fd687cad35a66eab75a36e660743ba9c4f9 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Fri, 12 Mar 2021 01:30:20 +0100 Subject: [PATCH] task local early now with RacyCell --- examples/binds.rs | 58 ++++++++++++++++++++++++++ examples/task-local-minimal.rs | 34 --------------- macros/src/codegen/resources.rs | 4 +- macros/src/codegen/resources_struct.rs | 2 +- 4 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 examples/binds.rs delete mode 100644 examples/task-local-minimal.rs diff --git a/examples/binds.rs b/examples/binds.rs new file mode 100644 index 0000000000..fbdf86c78c --- /dev/null +++ b/examples/binds.rs @@ -0,0 +1,58 @@ +//! 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; + + #[resources] + struct Resources { + // A local (move), late resource + #[task_local] + #[init(0)] + times: u32, + } + + #[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, resources = [times])] + fn foo(cx: foo::Context) { + let times = cx.resources.times; + *times += 1; + + hprintln!( + "foo called {} time{}", + *times, + if *times > 1 { "s" } else { "" } + ) + .unwrap(); + } +} diff --git a/examples/task-local-minimal.rs b/examples/task-local-minimal.rs deleted file mode 100644 index 29132f00c5..0000000000 --- a/examples/task-local-minimal.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! examples/task-local_minimal.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 { - // A local (move), late resource - #[task_local] - task_local: u32, - } - - #[init] - fn init(_: init::Context) -> (init::LateResources, init::Monotonics) { - (init::LateResources { task_local: 42 }, init::Monotonics()) - } - - // task_local is task_local - #[idle(resources =[task_local])] - fn idle(cx: idle::Context) -> ! { - hprintln!("IDLE:l = {}", cx.resources.task_local).unwrap(); - debug::exit(debug::EXIT_SUCCESS); - loop { - cortex_m::asm::nop(); - } - } -} diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index 68eea4d24d..ad01ccbf3d 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -55,9 +55,11 @@ pub fn codegen( }; let attrs = &res.attrs; + + let doc = format!(" RTIC internal: {}:{}", file!(), line!()); mod_app.push(quote!( #[allow(non_upper_case_globals)] - #[doc(hidden)] + #[doc = #doc] #(#attrs)* #(#cfgs)* #section diff --git a/macros/src/codegen/resources_struct.rs b/macros/src/codegen/resources_struct.rs index 6a21c3197c..036a34da00 100644 --- a/macros/src/codegen/resources_struct.rs +++ b/macros/src/codegen/resources_struct.rs @@ -91,7 +91,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, } else { values.push(quote!( #(#cfgs)* - #name: &#mut_ #mangled_name + #name: #mangled_name.get_mut_unchecked() )); } }