work on early/late resources

This commit is contained in:
Per Lindgren 2021-03-13 14:35:07 +01:00
parent 64f7a109a7
commit abd917ceff
5 changed files with 91 additions and 10 deletions

View file

@ -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<u32, U4> = 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());
// }
}

View file

@ -1,4 +1,4 @@
//! examples/task-local-minimal-early.rs
//! examples/minmal-task-local-early.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]

View file

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

View file

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

View file

@ -31,6 +31,9 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
}
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(),