372: Now late resources are always used r=AfoHT a=korken89

Awaits the PR in `rtic-syntax`: https://github.com/rtic-rs/rtic-syntax/pull/32

Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
This commit is contained in:
bors[bot] 2020-10-05 18:26:00 +00:00 committed by GitHub
commit 12aa9807c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 169 additions and 109 deletions

View file

@ -13,13 +13,15 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
mod 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])]

View file

@ -13,10 +13,12 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn init(_: init::Context) {
fn init(_: init::Context) -> init::LateResources {
rtic::pend(Interrupt::UART0);
hprintln!("init").unwrap();
init::LateResources {}
}
#[idle]

View file

@ -12,8 +12,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn init(_: init::Context) {
fn init(_: init::Context) -> init::LateResources {
rtic::pend(Interrupt::UART0);
init::LateResources {}
}
#[task(binds = UART0, spawn = [foo, bar])]

View file

@ -20,9 +20,11 @@ mod 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]

View file

@ -23,9 +23,11 @@ mod app {
}
#[init]
fn init(_: init::Context) {
fn init(_: init::Context) -> init::LateResources {
rtic::pend(Interrupt::UART0);
rtic::pend(Interrupt::UART1);
init::LateResources {}
}
// Direct destructure

View file

@ -19,9 +19,11 @@ mod 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])]

View file

@ -12,12 +12,14 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod 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]

View file

@ -11,8 +11,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn init(_: init::Context) {
fn init(_: init::Context) -> init::LateResources {
hprintln!("init").unwrap();
init::LateResources {}
}
#[idle]

View file

@ -11,7 +11,7 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965, peripherals = true)]
mod app {
#[init]
fn init(cx: init::Context) {
fn init(cx: init::Context) -> init::LateResources {
static mut X: u32 = 0;
// Cortex-M peripherals
@ -30,5 +30,7 @@ mod app {
hprintln!("init").unwrap();
debug::exit(debug::EXIT_SUCCESS);
init::LateResources {}
}
}

View file

@ -18,8 +18,10 @@ mod 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`

View file

@ -11,8 +11,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod 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])]

View file

@ -26,9 +26,11 @@ mod 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])]

View file

@ -26,8 +26,10 @@ mod app {
}
#[init]
fn init(_: init::Context) {
fn init(_: init::Context) -> init::LateResources {
debug::exit(debug::EXIT_SUCCESS);
init::LateResources {}
}
#[task(resources = [&shared])]

View file

@ -16,10 +16,12 @@ const PERIOD: u32 = 8_000_000;
mod 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])]

View file

@ -9,8 +9,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn taskmain(_: taskmain::Context) {
fn init(_: init::Context) -> init::LateResources {
assert!(cortex_m::Peripherals::take().is_none());
debug::exit(debug::EXIT_SUCCESS);
init::LateResources {}
}
}

View file

@ -25,13 +25,15 @@ mod app {
use super::P;
#[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])]

View file

@ -11,8 +11,10 @@ use rtic::app;
#[app(device = lm3s6965)]
mod app {
#[init]
fn init(_: init::Context) {
fn init(_: init::Context) -> init::LateResources {
rtic::pend(Interrupt::GPIOA);
init::LateResources {}
}
#[task(binds = GPIOA, priority = 1)]

View file

@ -11,8 +11,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init(spawn = [bar])]
fn init(c: init::Context) {
fn init(c: init::Context) -> init::LateResources {
c.spawn.bar().unwrap();
init::LateResources {}
}
#[inline(never)]

View file

@ -26,9 +26,11 @@ mod 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

View file

@ -19,9 +19,11 @@ mod 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

View file

@ -14,7 +14,7 @@ use rtic::cyccnt::{Instant, U32Ext as _};
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
mod 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 @@ mod app {
// Schedule `bar` to run 4e6 cycles in the future
cx.schedule.bar(now + 4_000_000.cycles()).unwrap();
init::LateResources {}
}
#[task]

View file

@ -23,12 +23,14 @@ mod 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])]

View file

@ -10,7 +10,9 @@ use panic_halt as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn init(_: init::Context) {}
fn init(_: init::Context) -> init::LateResources {
init::LateResources {}
}
// Cortex-M exception
#[task(binds = SVCall)]

View file

@ -15,9 +15,11 @@ mod app {
}
#[init]
fn init(_: init::Context) {
fn init(_: init::Context) -> init::LateResources {
#[cfg(never)]
static mut BAR: u32 = 0;
init::LateResources {}
}
#[idle]

View file

@ -9,8 +9,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod 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)]

View file

@ -9,7 +9,9 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn init(_: init::Context) {}
fn init(_: init::Context) -> init::LateResources {
init::LateResources {}
}
#[idle]
fn taskmain(_: taskmain::Context) -> ! {

View file

@ -9,7 +9,9 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn taskmain(_: taskmain::Context) {
fn init(_: init::Context) -> init::LateResources {
debug::exit(debug::EXIT_SUCCESS);
init::LateResources {}
}
}

View file

@ -32,7 +32,7 @@ mod 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;
@ -43,6 +43,8 @@ mod 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])]

View file

@ -11,10 +11,12 @@ use rtic::cyccnt::{Instant, U32Ext as _};
#[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)]
mod 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])]

View file

@ -10,10 +10,12 @@ use panic_halt as _;
#[rtic::app(device = lm3s6965)]
mod 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])]

View file

@ -9,8 +9,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init(spawn = [taskmain])]
fn init(cx: init::Context) {
fn init(cx: init::Context) -> init::LateResources {
cx.spawn.taskmain().ok();
init::LateResources {}
}
#[task]

View file

@ -11,8 +11,10 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod 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])]

View file

@ -18,7 +18,7 @@ mod 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;
@ -26,6 +26,8 @@ mod app {
let _: init::Spawn = cx.spawn;
debug::exit(debug::EXIT_SUCCESS);
init::LateResources {}
}
#[idle(schedule = [foo], spawn = [foo])]

View file

@ -36,9 +36,6 @@ pub fn codegen(
let mut root_init = vec![];
let mut user_init_imports = vec![];
let ret = {
let late_fields = analysis
.late_resources
.iter()
@ -55,7 +52,7 @@ pub fn codegen(
})
.collect::<Vec<_>>();
if !late_fields.is_empty() {
let mut user_init_imports = vec![];
let late_resources = util::late_resources_ident(&name);
root_init.push(quote!(
@ -72,12 +69,6 @@ pub fn codegen(
use super::#name_late;
));
Some(quote!(-> #name::LateResources))
} else {
None
}
};
let mut locals_pat = None;
let mut locals_new = None;
if !init.locals.is_empty() {
@ -95,7 +86,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)*
}
));

View file

@ -261,7 +261,6 @@ 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);
items.push(quote!(
@ -269,7 +268,6 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) ->
pub use super::#late_resources as LateResources;
));
}
}
let doc = match ctxt {
Context::Idle => "Idle loop",

View file

@ -35,8 +35,7 @@ mod tests;
///
/// The items allowed in the module block are specified below:
///
/// # 1. `#[resources]
/// struct <resource-name>`
/// # 1. `#[resources] struct <resource-name>`
///
/// This structure contains the declaration of all the resources used by the application. Each field
/// in this structure corresponds to a different resource. Each resource may optionally be given an

View file

@ -4,11 +4,13 @@ use panic_halt as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn init(_: init::Context) {
fn init(_: init::Context) -> init::LateResources {
#[cfg(never)]
static mut FOO: u32 = 0;
FOO;
init::LateResources {}
}
#[idle]

View file

@ -5,27 +5,27 @@ error[E0425]: cannot find value `FOO` in this scope
| ^^^ not found in this scope
error[E0425]: cannot find value `FOO` in this scope
--> $DIR/locals-cfg.rs:19:9
--> $DIR/locals-cfg.rs:21:9
|
19 | FOO;
21 | FOO;
| ^^^ not found in this scope
error[E0425]: cannot find value `FOO` in this scope
--> $DIR/locals-cfg.rs:29:9
--> $DIR/locals-cfg.rs:31:9
|
29 | FOO;
31 | FOO;
| ^^^ not found in this scope
error[E0425]: cannot find value `FOO` in this scope
--> $DIR/locals-cfg.rs:37:9
--> $DIR/locals-cfg.rs:39:9
|
37 | FOO;
39 | FOO;
| ^^^ not found in this scope
error[E0425]: cannot find value `FOO` in this scope
--> $DIR/locals-cfg.rs:45:9
--> $DIR/locals-cfg.rs:47:9
|
45 | FOO;
47 | FOO;
| ^^^ not found in this scope
error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `panic_impl`.

View file

@ -43,12 +43,14 @@ mod app {
}
#[init(resources = [o1, o4, o5, o6, s3])]
fn init(c: init::Context) {
fn init(c: init::Context) -> init::LateResources {
c.resources.o1;
c.resources.o4;
c.resources.o5;
c.resources.o6;
c.resources.s3;
init::LateResources {}
}
#[idle(resources = [o2, &o4, s1, &s3])]

View file

@ -45,81 +45,81 @@ error[E0609]: no field `s3` on type `initResources<'_>`
= note: available fields are: `__marker__`
error[E0609]: no field `o2` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:56:21
--> $DIR/resources-cfg.rs:58:21
|
56 | c.resources.o2;
58 | c.resources.o2;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `o4` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:57:21
--> $DIR/resources-cfg.rs:59:21
|
57 | c.resources.o4;
59 | c.resources.o4;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s1` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:58:21
--> $DIR/resources-cfg.rs:60:21
|
58 | c.resources.s1;
60 | c.resources.s1;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s3` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:59:21
--> $DIR/resources-cfg.rs:61:21
|
59 | c.resources.s3;
61 | c.resources.s3;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `o3` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:66:21
--> $DIR/resources-cfg.rs:68:21
|
66 | c.resources.o3;
68 | c.resources.o3;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s1` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:67:21
--> $DIR/resources-cfg.rs:69:21
|
67 | c.resources.s1;
69 | c.resources.s1;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s2` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:68:21
--> $DIR/resources-cfg.rs:70:21
|
68 | c.resources.s2;
70 | c.resources.s2;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s3` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:69:21
--> $DIR/resources-cfg.rs:71:21
|
69 | c.resources.s3;
71 | c.resources.s3;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s2` on type `uart1Resources<'_>`
--> $DIR/resources-cfg.rs:74:21
--> $DIR/resources-cfg.rs:76:21
|
74 | c.resources.s2;
76 | c.resources.s2;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `o5` on type `uart1Resources<'_>`
--> $DIR/resources-cfg.rs:75:21
--> $DIR/resources-cfg.rs:77:21
|
75 | c.resources.o5;
77 | c.resources.o5;
| ^^ unknown field
|
= note: available fields are: `__marker__`

View file

@ -3,7 +3,9 @@
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
fn init(_: init::Context) {}
fn init(_: init::Context) -> init::LateResources {
init::LateResources {}
}
#[task(binds = GPIOA, priority = 1)]
fn gpioa(_: gpioa::Context) {}