mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
Now late resources are always used
This commit is contained in:
parent
4d61437bb4
commit
e7f0d9c3e3
35 changed files with 124 additions and 70 deletions
|
@ -13,13 +13,15 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo])]
|
||||
fn init(cx: init::Context) {
|
||||
fn init(cx: init::Context) -> init::LateResources {
|
||||
// omitted: initialization of `CYCCNT`
|
||||
|
||||
hprintln!("init(baseline = {:?})", cx.start).unwrap();
|
||||
|
||||
// `foo` inherits the baseline of `init`: `Instant(0)`
|
||||
cx.spawn.foo().unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(schedule = [foo])]
|
||||
|
|
|
@ -13,10 +13,12 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
|
||||
hprintln!("init").unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle]
|
||||
|
|
|
@ -12,8 +12,10 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(binds = UART0, spawn = [foo, bar])]
|
||||
|
|
|
@ -19,9 +19,11 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init(spawn = [foo])]
|
||||
fn init(cx: init::Context) {
|
||||
fn init(cx: init::Context) -> init::LateResources {
|
||||
cx.spawn.foo().unwrap();
|
||||
cx.spawn.foo().unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle]
|
||||
|
|
|
@ -22,9 +22,11 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
rtic::pend(Interrupt::UART1);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
// Direct destructure
|
||||
|
|
|
@ -18,9 +18,11 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
rtic::pend(Interrupt::UART1);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(binds = UART0, resources = [shared])]
|
||||
|
|
|
@ -12,12 +12,14 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
// Pends the UART0 interrupt but its handler won't run until *after*
|
||||
// `init` returns because interrupts are disabled
|
||||
rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend
|
||||
|
||||
hprintln!("init").unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle]
|
||||
|
|
|
@ -11,8 +11,10 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
hprintln!("init").unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle]
|
||||
|
|
|
@ -11,7 +11,7 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965, peripherals = true)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(cx: init::Context) {
|
||||
fn init(cx: init::Context) -> init::LateResources {
|
||||
static mut X: u32 = 0;
|
||||
|
||||
// Cortex-M peripherals
|
||||
|
@ -26,5 +26,7 @@ const APP: () = {
|
|||
hprintln!("init").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -17,8 +17,10 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtic::pend(Interrupt::GPIOA);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
// when omitted priority is assumed to be `1`
|
||||
|
|
|
@ -11,8 +11,10 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo])]
|
||||
fn init(c: init::Context) {
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
c.spawn.foo(/* no message */).unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(spawn = [bar])]
|
||||
|
|
|
@ -23,9 +23,11 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init(spawn = [baz, quux])]
|
||||
fn init(c: init::Context) {
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
c.spawn.baz().unwrap();
|
||||
c.spawn.quux().unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(spawn = [bar])]
|
||||
|
|
|
@ -22,8 +22,10 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(resources = [&shared])]
|
||||
|
|
|
@ -15,10 +15,12 @@ const PERIOD: u32 = 8_000_000;
|
|||
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[init(schedule = [foo])]
|
||||
fn init(cx: init::Context) {
|
||||
fn init(cx: init::Context) -> init::LateResources {
|
||||
// omitted: initialization of `CYCCNT`
|
||||
|
||||
cx.schedule.foo(cx.start + PERIOD.cycles()).unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(schedule = [foo])]
|
||||
|
|
|
@ -9,8 +9,10 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn main(_: main::Context) {
|
||||
fn main(_: main::Context) -> main::LateResources {
|
||||
assert!(cortex_m::Peripherals::take().is_none());
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
main::LateResources {}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -20,13 +20,15 @@ pool!(P: [u8; 128]);
|
|||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
static mut MEMORY: [u8; 512] = [0; 512];
|
||||
|
||||
// Increase the capacity of the memory pool by ~4
|
||||
P::grow(MEMORY);
|
||||
|
||||
rtic::pend(Interrupt::I2C0);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(binds = I2C0, priority = 2, spawn = [foo, bar])]
|
||||
|
|
|
@ -11,8 +11,10 @@ use rtic::app;
|
|||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtic::pend(Interrupt::GPIOA);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(binds = GPIOA, priority = 1)]
|
||||
|
|
|
@ -11,8 +11,10 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [bar])]
|
||||
fn init(c: init::Context) {
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
c.spawn.bar().unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
|
|
|
@ -18,9 +18,11 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
rtic::pend(Interrupt::UART1);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
// `shared` cannot be accessed from this context
|
||||
|
|
|
@ -14,7 +14,7 @@ use rtic::cyccnt::{Instant, U32Ext as _};
|
|||
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[init(schedule = [foo, bar])]
|
||||
fn init(mut cx: init::Context) {
|
||||
fn init(mut cx: init::Context) -> init::LateResources {
|
||||
// Initialize (enable) the monotonic timer (CYCCNT)
|
||||
cx.core.DCB.enable_trace();
|
||||
// required on Cortex-M7 devices that software lock the DWT (e.g. STM32F7)
|
||||
|
@ -32,6 +32,8 @@ const APP: () = {
|
|||
|
||||
// Schedule `bar` to run 4e6 cycles in the future
|
||||
cx.schedule.bar(now + 4_000_000.cycles()).unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task]
|
||||
|
|
|
@ -20,12 +20,14 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init(resources = [shared])]
|
||||
fn init(c: init::Context) {
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
// this `message` will be sent to task `UART0`
|
||||
let message = MustBeSend;
|
||||
*c.resources.shared = Some(message);
|
||||
|
||||
rtic::pend(Interrupt::UART0);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(binds = UART0, resources = [shared])]
|
||||
|
|
|
@ -10,7 +10,9 @@ use panic_halt as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {}
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
// Cortex-M exception
|
||||
#[task(binds = SVCall)]
|
||||
|
|
|
@ -14,9 +14,11 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
#[cfg(never)]
|
||||
static mut BAR: u32 = 0;
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle]
|
||||
|
|
|
@ -9,8 +9,10 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
rtic::pend(lm3s6965::Interrupt::UART0)
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtic::pend(lm3s6965::Interrupt::UART0);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(binds = UART0)]
|
||||
|
|
|
@ -9,7 +9,9 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {}
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn main(_: main::Context) -> ! {
|
||||
|
|
|
@ -9,7 +9,9 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn main(_: main::Context) {
|
||||
fn main(_: main::Context) -> main::LateResources {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
main::LateResources {}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -31,7 +31,7 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init(resources = [o1, o4, o5, o6, s3])]
|
||||
fn init(c: init::Context) {
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
// owned by `init` == `&'static mut`
|
||||
let _: &'static mut u32 = c.resources.o1;
|
||||
|
||||
|
@ -42,6 +42,8 @@ const APP: () = {
|
|||
let _: &mut u32 = c.resources.o4;
|
||||
let _: &mut u32 = c.resources.o5;
|
||||
let _: &mut u32 = c.resources.s3;
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle(resources = [o2, &o4, s1, &s3])]
|
||||
|
|
|
@ -11,10 +11,12 @@ use rtic::cyccnt::{Instant, U32Ext as _};
|
|||
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[init(schedule = [foo, bar, baz])]
|
||||
fn init(c: init::Context) {
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
let _: Result<(), ()> = c.schedule.foo(c.start + 10.cycles());
|
||||
let _: Result<(), u32> = c.schedule.bar(c.start + 20.cycles(), 0);
|
||||
let _: Result<(), (u32, u32)> = c.schedule.baz(c.start + 30.cycles(), 0, 1);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle(schedule = [foo, bar, baz])]
|
||||
|
|
|
@ -10,10 +10,12 @@ use panic_halt as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo, bar, baz])]
|
||||
fn init(c: init::Context) {
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
let _: Result<(), ()> = c.spawn.foo();
|
||||
let _: Result<(), u32> = c.spawn.bar(0);
|
||||
let _: Result<(), (u32, u32)> = c.spawn.baz(0, 1);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle(spawn = [foo, bar, baz])]
|
||||
|
|
|
@ -9,8 +9,10 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [main])]
|
||||
fn init(cx: init::Context) {
|
||||
fn init(cx: init::Context) -> init::LateResources {
|
||||
cx.spawn.main().ok();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task]
|
||||
|
|
|
@ -11,8 +11,10 @@ use panic_semihosting as _;
|
|||
#[rtic::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo])]
|
||||
fn init(c: init::Context) {
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
c.spawn.foo().unwrap();
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[task(spawn = [bar, baz])]
|
||||
|
|
|
@ -17,7 +17,7 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[init(schedule = [foo], spawn = [foo])]
|
||||
fn init(cx: init::Context) {
|
||||
fn init(cx: init::Context) -> init::LateResources {
|
||||
let _: cyccnt::Instant = cx.start;
|
||||
let _: rtic::Peripherals = cx.core;
|
||||
let _: lm3s6965::Peripherals = cx.device;
|
||||
|
@ -25,6 +25,8 @@ const APP: () = {
|
|||
let _: init::Spawn = cx.spawn;
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
init::LateResources {}
|
||||
}
|
||||
|
||||
#[idle(schedule = [foo], spawn = [foo])]
|
||||
|
|
|
@ -21,5 +21,5 @@ proc-macro = true
|
|||
proc-macro2 = "1"
|
||||
quote = "1"
|
||||
syn = "1"
|
||||
rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.4.0" }
|
||||
rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "always_late_resources" }
|
||||
|
||||
|
|
|
@ -34,39 +34,31 @@ pub fn codegen(
|
|||
|
||||
let mut root_init = vec![];
|
||||
|
||||
let ret = {
|
||||
let late_fields = analysis
|
||||
.late_resources
|
||||
.iter()
|
||||
.flat_map(|resources| {
|
||||
resources.iter().map(|name| {
|
||||
let ty = &app.late_resources[name].ty;
|
||||
let cfgs = &app.late_resources[name].cfgs;
|
||||
let late_fields = analysis
|
||||
.late_resources
|
||||
.iter()
|
||||
.flat_map(|resources| {
|
||||
resources.iter().map(|name| {
|
||||
let ty = &app.late_resources[name].ty;
|
||||
let cfgs = &app.late_resources[name].cfgs;
|
||||
|
||||
quote!(
|
||||
#(#cfgs)*
|
||||
pub #name: #ty
|
||||
)
|
||||
})
|
||||
quote!(
|
||||
#(#cfgs)*
|
||||
pub #name: #ty
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !late_fields.is_empty() {
|
||||
let late_resources = util::late_resources_ident(&name);
|
||||
let late_resources = util::late_resources_ident(&name);
|
||||
|
||||
root_init.push(quote!(
|
||||
/// Resources initialized at runtime
|
||||
#[allow(non_snake_case)]
|
||||
pub struct #late_resources {
|
||||
#(#late_fields),*
|
||||
}
|
||||
));
|
||||
|
||||
Some(quote!(-> #name::LateResources))
|
||||
} else {
|
||||
None
|
||||
root_init.push(quote!(
|
||||
/// Resources initialized at runtime
|
||||
#[allow(non_snake_case)]
|
||||
pub struct #late_resources {
|
||||
#(#late_fields),*
|
||||
}
|
||||
};
|
||||
));
|
||||
|
||||
let mut locals_pat = None;
|
||||
let mut locals_new = None;
|
||||
|
@ -85,7 +77,7 @@ pub fn codegen(
|
|||
let user_init = Some(quote!(
|
||||
#(#attrs)*
|
||||
#[allow(non_snake_case)]
|
||||
fn #name(#(#locals_pat,)* #context: #name::Context) #ret {
|
||||
fn #name(#(#locals_pat,)* #context: #name::Context) -> #name::LateResources {
|
||||
#(#stmts)*
|
||||
}
|
||||
));
|
||||
|
|
|
@ -253,14 +253,12 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) ->
|
|||
|
||||
if let Context::Init = ctxt {
|
||||
let init = &app.inits.first().unwrap();
|
||||
if init.returns_late_resources {
|
||||
let late_resources = util::late_resources_ident(&init.name);
|
||||
let late_resources = util::late_resources_ident(&init.name);
|
||||
|
||||
items.push(quote!(
|
||||
#[doc(inline)]
|
||||
pub use super::#late_resources as LateResources;
|
||||
));
|
||||
}
|
||||
items.push(quote!(
|
||||
#[doc(inline)]
|
||||
pub use super::#late_resources as LateResources;
|
||||
));
|
||||
}
|
||||
|
||||
let doc = match ctxt {
|
||||
|
|
Loading…
Reference in a new issue