mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-29 15:04:32 +01:00
task local early now with RacyCell
This commit is contained in:
parent
4b370c3d60
commit
37530fd687
4 changed files with 62 additions and 36 deletions
58
examples/binds.rs
Normal file
58
examples/binds.rs
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -55,9 +55,11 @@ pub fn codegen(
|
||||||
};
|
};
|
||||||
|
|
||||||
let attrs = &res.attrs;
|
let attrs = &res.attrs;
|
||||||
|
|
||||||
|
let doc = format!(" RTIC internal: {}:{}", file!(), line!());
|
||||||
mod_app.push(quote!(
|
mod_app.push(quote!(
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
#[doc(hidden)]
|
#[doc = #doc]
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
#section
|
#section
|
||||||
|
|
|
@ -91,7 +91,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
} else {
|
} else {
|
||||||
values.push(quote!(
|
values.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
#name: &#mut_ #mangled_name
|
#name: #mangled_name.get_mut_unchecked()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue