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