mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-30 15:34:33 +01:00
work on early/late resources
This commit is contained in:
parent
64f7a109a7
commit
abd917ceff
5 changed files with 91 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
//! examples/late.rs
|
//! examples/late.rs
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
#![deny(warnings)]
|
// #![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ mod app {
|
||||||
// Late resources
|
// Late resources
|
||||||
#[resources]
|
#[resources]
|
||||||
struct Resources {
|
struct Resources {
|
||||||
p: Producer<'static, u32, U4>,
|
// p: Producer<'static, u32, U4>,
|
||||||
c: Consumer<'static, u32, U4>,
|
c: Consumer<'static, u32, U4>,
|
||||||
#[task_local]
|
#[task_local]
|
||||||
#[init(Queue(i::Queue::new()))]
|
#[init(Queue(i::Queue::new()))]
|
||||||
|
@ -29,12 +29,11 @@ mod app {
|
||||||
|
|
||||||
#[init(resources = [q])]
|
#[init(resources = [q])]
|
||||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
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();
|
let (p, c) = cx.resources.q.split();
|
||||||
|
|
||||||
// Initialization of late resources
|
// Initialization of late resources
|
||||||
(init::LateResources { p, c }, init::Monotonics())
|
// (init::LateResources { p, c }, init::Monotonics())
|
||||||
|
(init::LateResources { c }, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(resources = [c])]
|
#[idle(resources = [c])]
|
||||||
|
@ -50,8 +49,8 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0, resources = [p])]
|
// #[task(binds = UART0, resources = [p])]
|
||||||
fn uart0(mut c: uart0::Context) {
|
// fn uart0(mut c: uart0::Context) {
|
||||||
c.resources.p.lock(|p| p.enqueue(42).unwrap());
|
// c.resources.p.lock(|p| p.enqueue(42).unwrap());
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! examples/task-local-minimal-early.rs
|
//! examples/minmal-task-local-early.rs
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
38
examples/minimal-task-local-type-early.rs
Normal file
38
examples/minimal-task-local-type-early.rs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
examples/minimal-task-local-type-late.rs
Normal file
41
examples/minimal-task-local-type-late.rs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,9 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, (monotonic, _)) in app.monotonics.iter().enumerate() {
|
for (i, (monotonic, _)) in app.monotonics.iter().enumerate() {
|
||||||
|
let doc = format!(" RTIC internal: {}:{}", file!(), line!());
|
||||||
|
stmts.push(quote!(#[doc = #doc]));
|
||||||
|
|
||||||
let idx = Index {
|
let idx = Index {
|
||||||
index: i as u32,
|
index: i as u32,
|
||||||
span: Span::call_site(),
|
span: Span::call_site(),
|
||||||
|
|
Loading…
Reference in a new issue