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() )); } }