From 8df2ec11b0ee3209678dcc1b1a5baa479fa1dfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Wed, 22 Apr 2020 10:58:14 +0000 Subject: Examples using mod instead of const --- examples/baseline.rs | 4 ++-- examples/binds.rs | 4 ++-- examples/capacity.rs | 4 ++-- examples/cfg.rs | 4 ++-- examples/destructure.rs | 4 ++-- examples/generics.rs | 4 ++-- examples/hardware.rs | 4 ++-- examples/idle.rs | 4 ++-- examples/init.rs | 4 ++-- examples/late.rs | 4 ++-- examples/lock.rs | 4 ++-- examples/message.rs | 4 ++-- examples/not-send.rs | 4 ++-- examples/not-sync.rs | 4 ++-- examples/only-shared-access.rs | 4 ++-- examples/periodic.rs | 4 ++-- examples/peripherals-taken.rs | 4 ++-- examples/pool.rs | 4 ++-- examples/preempt.rs | 4 ++-- examples/ramfunc.rs | 4 ++-- examples/resource.rs | 4 ++-- examples/schedule.rs | 4 ++-- examples/shared-with-init.rs | 4 ++-- examples/smallest.rs | 2 +- examples/t-binds.rs | 4 ++-- examples/t-cfg-resources.rs | 9 ++++----- examples/t-cfg.rs | 4 ++-- examples/t-htask-main.rs | 4 ++-- examples/t-idle-main.rs | 4 ++-- examples/t-init-main.rs | 4 ++-- examples/t-late-not-send.rs | 4 ++-- examples/t-resource.rs | 4 ++-- examples/t-schedule.rs | 4 ++-- examples/t-spawn.rs | 4 ++-- examples/t-stask-main.rs | 4 ++-- examples/task.rs | 4 ++-- examples/types.rs | 4 ++-- 37 files changed, 75 insertions(+), 76 deletions(-) diff --git a/examples/baseline.rs b/examples/baseline.rs index f46b273..2d75dfa 100644 --- a/examples/baseline.rs +++ b/examples/baseline.rs @@ -11,7 +11,7 @@ use panic_semihosting as _; // NOTE: does NOT properly work on QEMU #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -const APP: () = { +mod APP { #[init(spawn = [foo])] fn init(cx: init::Context) { // omitted: initialization of `CYCCNT` @@ -51,4 +51,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/binds.rs b/examples/binds.rs index 82bf896..920124c 100644 --- a/examples/binds.rs +++ b/examples/binds.rs @@ -11,7 +11,7 @@ use panic_semihosting as _; // `examples/interrupt.rs` rewritten to use `binds` #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) { rtic::pend(Interrupt::UART0); @@ -45,4 +45,4 @@ const APP: () = { ) .unwrap(); } -}; +} diff --git a/examples/capacity.rs b/examples/capacity.rs index 00cec34..26c61a2 100644 --- a/examples/capacity.rs +++ b/examples/capacity.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) { rtic::pend(Interrupt::UART0); @@ -44,4 +44,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/cfg.rs b/examples/cfg.rs index 8eeeb2a..626181d 100644 --- a/examples/cfg.rs +++ b/examples/cfg.rs @@ -11,7 +11,7 @@ use cortex_m_semihosting::hprintln; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { #[cfg(debug_assertions)] // <- `true` when using the `dev` profile #[init(0)] @@ -66,4 +66,4 @@ const APP: () = { fn SSI0(); fn QEI0(); } -}; +} diff --git a/examples/destructure.rs b/examples/destructure.rs index 1756bd9..da0a4c1 100644 --- a/examples/destructure.rs +++ b/examples/destructure.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { // Some resources to work with #[init(0)] @@ -44,4 +44,4 @@ const APP: () = { hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap(); } -}; +} diff --git a/examples/generics.rs b/examples/generics.rs index 40ab81a..b67ed9c 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -11,7 +11,7 @@ use panic_semihosting as _; use rtic::{Exclusive, Mutex}; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { #[init(0)] shared: u32, @@ -49,7 +49,7 @@ const APP: () = { // second argument has type `Exclusive` advance(STATE, Exclusive(c.resources.shared)); } -}; +} // the second parameter is generic: it can be any type that implements the `Mutex` trait fn advance(state: &mut u32, mut shared: impl Mutex) { diff --git a/examples/hardware.rs b/examples/hardware.rs index 8105a74..7926650 100644 --- a/examples/hardware.rs +++ b/examples/hardware.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) { // Pends the UART0 interrupt but its handler won't run until *after* @@ -49,4 +49,4 @@ const APP: () = { ) .unwrap(); } -}; +} diff --git a/examples/idle.rs b/examples/idle.rs index 3d28dac..dbf7f98 100644 --- a/examples/idle.rs +++ b/examples/idle.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) { hprintln!("init").unwrap(); @@ -30,4 +30,4 @@ const APP: () = { cortex_m::asm::nop(); } } -}; +} diff --git a/examples/init.rs b/examples/init.rs index 315969f..c651136 100644 --- a/examples/init.rs +++ b/examples/init.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965, peripherals = true)] -const APP: () = { +mod APP { #[init] fn init(cx: init::Context) { static mut X: u32 = 0; @@ -27,4 +27,4 @@ const APP: () = { debug::exit(debug::EXIT_SUCCESS); } -}; +} diff --git a/examples/late.rs b/examples/late.rs index 60b9be0..8675c6a 100644 --- a/examples/late.rs +++ b/examples/late.rs @@ -15,7 +15,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { // Late resources struct Resources { p: Producer<'static, u32, U4>, @@ -49,4 +49,4 @@ const APP: () = { fn uart0(c: uart0::Context) { c.resources.p.enqueue(42).unwrap(); } -}; +} diff --git a/examples/lock.rs b/examples/lock.rs index 5e3bce2..4b16679 100644 --- a/examples/lock.rs +++ b/examples/lock.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { #[init(0)] shared: u32, @@ -59,4 +59,4 @@ const APP: () = { fn gpioc(_: gpioc::Context) { hprintln!("C").unwrap(); } -}; +} diff --git a/examples/message.rs b/examples/message.rs index 596f244..3e9633b 100644 --- a/examples/message.rs +++ b/examples/message.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init(spawn = [foo])] fn init(c: init::Context) { c.spawn.foo(/* no message */).unwrap(); @@ -49,4 +49,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/not-send.rs b/examples/not-send.rs index 16a874d..bcc049c 100644 --- a/examples/not-send.rs +++ b/examples/not-send.rs @@ -16,7 +16,7 @@ pub struct NotSend { } #[app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { #[init(None)] shared: Option, @@ -60,4 +60,4 @@ const APP: () = { fn SSI0(); fn QEI0(); } -}; +} diff --git a/examples/not-sync.rs b/examples/not-sync.rs index a7eaac8..0354ef1 100644 --- a/examples/not-sync.rs +++ b/examples/not-sync.rs @@ -15,7 +15,7 @@ pub struct NotSync { } #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { #[init(NotSync { _0: PhantomData })] shared: NotSync, @@ -42,4 +42,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/only-shared-access.rs b/examples/only-shared-access.rs index c022b03..fbc7bfd 100644 --- a/examples/only-shared-access.rs +++ b/examples/only-shared-access.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { key: u32, } @@ -35,4 +35,4 @@ const APP: () = { fn uart1(cx: uart1::Context) { hprintln!("UART1(key = {:#x})", cx.resources.key).unwrap(); } -}; +} diff --git a/examples/periodic.rs b/examples/periodic.rs index 405346e..cd887ca 100644 --- a/examples/periodic.rs +++ b/examples/periodic.rs @@ -13,7 +13,7 @@ const PERIOD: u32 = 8_000_000; // NOTE: does NOT work on QEMU! #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -const APP: () = { +mod APP { #[init(schedule = [foo])] fn init(cx: init::Context) { // omitted: initialization of `CYCCNT` @@ -35,4 +35,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/peripherals-taken.rs b/examples/peripherals-taken.rs index cd4ba0f..a1bd686 100644 --- a/examples/peripherals-taken.rs +++ b/examples/peripherals-taken.rs @@ -7,10 +7,10 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn main(_: main::Context) { assert!(cortex_m::Peripherals::take().is_none()); debug::exit(debug::EXIT_SUCCESS); } -}; +} diff --git a/examples/pool.rs b/examples/pool.rs index 824d5bd..eb65ed8 100644 --- a/examples/pool.rs +++ b/examples/pool.rs @@ -18,7 +18,7 @@ use rtic::app; pool!(P: [u8; 128]); #[app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) { static mut MEMORY: [u8; 512] = [0; 512]; @@ -66,4 +66,4 @@ const APP: () = { fn SSI0(); fn QEI0(); } -}; +} diff --git a/examples/preempt.rs b/examples/preempt.rs index 3cb1102..a20b36c 100644 --- a/examples/preempt.rs +++ b/examples/preempt.rs @@ -9,7 +9,7 @@ use panic_semihosting as _; use rtic::app; #[app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) { rtic::pend(Interrupt::GPIOA); @@ -34,4 +34,4 @@ const APP: () = { rtic::pend(Interrupt::GPIOB); hprintln!(" GPIOC - end").unwrap(); } -}; +} diff --git a/examples/ramfunc.rs b/examples/ramfunc.rs index 1f95d49..cfe22e3 100644 --- a/examples/ramfunc.rs +++ b/examples/ramfunc.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init(spawn = [bar])] fn init(c: init::Context) { c.spawn.bar().unwrap(); @@ -38,4 +38,4 @@ const APP: () = { #[link_section = ".data.UART1"] fn UART1(); } -}; +} diff --git a/examples/resource.rs b/examples/resource.rs index 2361fd0..a0954d6 100644 --- a/examples/resource.rs +++ b/examples/resource.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { // A resource #[init(0)] @@ -52,4 +52,4 @@ const APP: () = { hprintln!("UART1: shared = {}", cx.resources.shared).unwrap(); } -}; +} diff --git a/examples/schedule.rs b/examples/schedule.rs index 70a7a5e..f2e7ed8 100644 --- a/examples/schedule.rs +++ b/examples/schedule.rs @@ -12,7 +12,7 @@ use rtic::cyccnt::{Instant, U32Ext as _}; // NOTE: does NOT work on QEMU! #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -const APP: () = { +mod APP { #[init(schedule = [foo, bar])] fn init(mut cx: init::Context) { // Initialize (enable) the monotonic timer (CYCCNT) @@ -50,4 +50,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs index bd55f7e..03391bd 100644 --- a/examples/shared-with-init.rs +++ b/examples/shared-with-init.rs @@ -13,7 +13,7 @@ use rtic::app; pub struct MustBeSend; #[app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { #[init(None)] shared: Option, @@ -37,4 +37,4 @@ const APP: () = { debug::exit(debug::EXIT_SUCCESS); } } -}; +} diff --git a/examples/smallest.rs b/examples/smallest.rs index ec3fa97..d6f3b66 100644 --- a/examples/smallest.rs +++ b/examples/smallest.rs @@ -7,4 +7,4 @@ use panic_semihosting as _; // panic handler use rtic::app; #[app(device = lm3s6965)] -const APP: () = {}; +mod APP {} diff --git a/examples/t-binds.rs b/examples/t-binds.rs index 588ac46..8634c75 100644 --- a/examples/t-binds.rs +++ b/examples/t-binds.rs @@ -8,7 +8,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) {} @@ -23,7 +23,7 @@ const APP: () = { fn bar(c: bar::Context) { bar_trampoline(c) } -}; +} #[allow(dead_code)] fn foo_trampoline(_: foo::Context) {} diff --git a/examples/t-cfg-resources.rs b/examples/t-cfg-resources.rs index 4f7fd63..892d211 100644 --- a/examples/t-cfg-resources.rs +++ b/examples/t-cfg-resources.rs @@ -6,7 +6,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { // A resource #[init(0)] @@ -15,8 +15,7 @@ const APP: () = { // A conditionally compiled resource behind feature_x #[cfg(feature = "feature_x")] x: u32, - - dummy: (), + dummy: (), // dummy such that we have at least one late resource } #[init] @@ -25,7 +24,7 @@ const APP: () = { // The feature needs to be applied everywhere x is defined or used #[cfg(feature = "feature_x")] x: 0, - dummy: (), // dummy such that we have at least one late resource + dummy: () // dummy such that we have at least one late resource } } @@ -35,4 +34,4 @@ const APP: () = { cortex_m::asm::nop(); } } -}; +} diff --git a/examples/t-cfg.rs b/examples/t-cfg.rs index b6c9e47..da9a491 100644 --- a/examples/t-cfg.rs +++ b/examples/t-cfg.rs @@ -6,7 +6,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -const APP: () = { +mod APP { struct Resources { #[cfg(never)] #[init(0)] @@ -52,4 +52,4 @@ const APP: () = { fn SSI0(); fn QEI0(); } -}; +} diff --git a/examples/t-htask-main.rs b/examples/t-htask-main.rs index c4bebf9..6143bbd 100644 --- a/examples/t-htask-main.rs +++ b/examples/t-htask-main.rs @@ -7,7 +7,7 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) { rtic::pend(lm3s6965::Interrupt::UART0) @@ -17,4 +17,4 @@ const APP: () = { fn main(_: main::Context) { debug::exit(debug::EXIT_SUCCESS); } -}; +} diff --git a/examples/t-idle-main.rs b/examples/t-idle-main.rs index 051a9ee..89f93d0 100644 --- a/examples/t-idle-main.rs +++ b/examples/t-idle-main.rs @@ -7,7 +7,7 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) {} @@ -18,4 +18,4 @@ const APP: () = { cortex_m::asm::nop(); } } -}; +} diff --git a/examples/t-init-main.rs b/examples/t-init-main.rs index 6a6cd99..040c72f 100644 --- a/examples/t-init-main.rs +++ b/examples/t-init-main.rs @@ -7,9 +7,9 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn main(_: main::Context) { debug::exit(debug::EXIT_SUCCESS); } -}; +} diff --git a/examples/t-late-not-send.rs b/examples/t-late-not-send.rs index d2a9b63..7799018 100644 --- a/examples/t-late-not-send.rs +++ b/examples/t-late-not-send.rs @@ -12,7 +12,7 @@ pub struct NotSend { } #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { x: NotSend, #[init(None)] @@ -35,4 +35,4 @@ const APP: () = { cortex_m::asm::nop(); } } -}; +} diff --git a/examples/t-resource.rs b/examples/t-resource.rs index 81ba185..0864a8a 100644 --- a/examples/t-resource.rs +++ b/examples/t-resource.rs @@ -8,7 +8,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { #[init(0)] o1: u32, // init @@ -86,4 +86,4 @@ const APP: () = { // no `Mutex` proxy when co-owned by cooperative (same priority) tasks let _: &mut u32 = c.resources.s2; } -}; +} diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs index 3854aad..6753613 100644 --- a/examples/t-schedule.rs +++ b/examples/t-schedule.rs @@ -9,7 +9,7 @@ use panic_halt as _; use rtic::cyccnt::{Instant, U32Ext as _}; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -const APP: () = { +mod APP { #[init(schedule = [foo, bar, baz])] fn init(c: init::Context) { let _: Result<(), ()> = c.schedule.foo(c.start + 10.cycles()); @@ -61,4 +61,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/t-spawn.rs b/examples/t-spawn.rs index 35831cc..7a64e1c 100644 --- a/examples/t-spawn.rs +++ b/examples/t-spawn.rs @@ -8,7 +8,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init(spawn = [foo, bar, baz])] fn init(c: init::Context) { let _: Result<(), ()> = c.spawn.foo(); @@ -60,4 +60,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/t-stask-main.rs b/examples/t-stask-main.rs index f270940..edea430 100644 --- a/examples/t-stask-main.rs +++ b/examples/t-stask-main.rs @@ -7,7 +7,7 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init(spawn = [main])] fn init(cx: init::Context) { cx.spawn.main().ok(); @@ -24,4 +24,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/task.rs b/examples/task.rs index 12c4ac8..e515c93 100644 --- a/examples/task.rs +++ b/examples/task.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init(spawn = [foo])] fn init(c: init::Context) { c.spawn.foo().unwrap(); @@ -52,4 +52,4 @@ const APP: () = { fn SSI0(); fn QEI0(); } -}; +} diff --git a/examples/types.rs b/examples/types.rs index 5233f86..eafc9b1 100644 --- a/examples/types.rs +++ b/examples/types.rs @@ -10,7 +10,7 @@ use panic_semihosting as _; use rtic::cyccnt; #[rtic::app(device = lm3s6965, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] -const APP: () = { +mod APP { struct Resources { #[init(0)] shared: u32, @@ -60,4 +60,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} -- cgit v1.2.3 From 79b62797f549a71531bf5ede39cc6695871b7251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Wed, 22 Apr 2020 11:48:36 +0000 Subject: Update the test suite to use mod instead of const Changes MSRV to 1.42, failing tests updated to match 1.42. --- ui/single/exception-invalid.rs | 4 ++-- ui/single/exception-systick-used.rs | 4 ++-- ui/single/extern-interrupt-not-enough.rs | 4 ++-- ui/single/extern-interrupt-used.rs | 4 ++-- ui/single/locals-cfg.rs | 4 ++-- ui/single/locals-cfg.stderr | 8 ++++---- ui/single/resources-cfg.rs | 4 ++-- ui/single/task-priority-too-high.rs | 4 ++-- ui/single/task-priority-too-high.stderr | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ui/single/exception-invalid.rs b/ui/single/exception-invalid.rs index efe0621..9b6b001 100644 --- a/ui/single/exception-invalid.rs +++ b/ui/single/exception-invalid.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[task(binds = NonMaskableInt)] fn nmi(_: nmi::Context) {} -}; +} diff --git a/ui/single/exception-systick-used.rs b/ui/single/exception-systick-used.rs index 36ed174..02fd1c6 100644 --- a/ui/single/exception-systick-used.rs +++ b/ui/single/exception-systick-used.rs @@ -1,10 +1,10 @@ #![no_main] #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[task(binds = SysTick)] fn sys_tick(_: sys_tick::Context) {} #[task(schedule = [foo])] fn foo(_: foo::Context) {} -}; +} diff --git a/ui/single/extern-interrupt-not-enough.rs b/ui/single/extern-interrupt-not-enough.rs index 53820b5..18850d8 100644 --- a/ui/single/extern-interrupt-not-enough.rs +++ b/ui/single/extern-interrupt-not-enough.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[task] fn a(_: a::Context) {} -}; +} diff --git a/ui/single/extern-interrupt-used.rs b/ui/single/extern-interrupt-used.rs index 82f1bdd..dd79843 100644 --- a/ui/single/extern-interrupt-used.rs +++ b/ui/single/extern-interrupt-used.rs @@ -1,11 +1,11 @@ #![no_main] #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[task(binds = UART0)] fn a(_: a::Context) {} extern "C" { fn UART0(); } -}; +} diff --git a/ui/single/locals-cfg.rs b/ui/single/locals-cfg.rs index 54bba8a..5053cf3 100644 --- a/ui/single/locals-cfg.rs +++ b/ui/single/locals-cfg.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) { #[cfg(never)] @@ -47,4 +47,4 @@ const APP: () = { extern "C" { fn UART1(); } -}; +} diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index bb558fa..e572a41 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -28,10 +28,10 @@ error[E0425]: cannot find value `FOO` in this scope 44 | FOO; | ^^^ not found in this scope -error: duplicate lang item in crate `panic_halt`: `panic_impl`. +error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. | - = note: first defined in crate `std`. + = note: first defined in crate `std` (which `$CRATE` depends on) -error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. +error: duplicate lang item in crate `panic_halt`: `panic_impl`. | - = note: first defined in crate `panic_halt`. + = note: first defined in crate `panic_semihosting`. diff --git a/ui/single/resources-cfg.rs b/ui/single/resources-cfg.rs index df7ac80..fd03f58 100644 --- a/ui/single/resources-cfg.rs +++ b/ui/single/resources-cfg.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { struct Resources { #[cfg(never)] #[init(0)] @@ -72,4 +72,4 @@ const APP: () = { c.resources.s2; c.resources.o5; } -}; +} diff --git a/ui/single/task-priority-too-high.rs b/ui/single/task-priority-too-high.rs index 539c3f5..ed7dd86 100644 --- a/ui/single/task-priority-too-high.rs +++ b/ui/single/task-priority-too-high.rs @@ -3,7 +3,7 @@ use rtic::app; #[rtic::app(device = lm3s6965)] -const APP: () = { +mod APP { #[init] fn init(_: init::Context) {} @@ -35,4 +35,4 @@ const APP: () = { // this value is too high! #[task(binds = I2C0, priority = 9)] fn i2c0(_: i2c0::Context) {} -}; +} diff --git a/ui/single/task-priority-too-high.stderr b/ui/single/task-priority-too-high.stderr index eae6074..5854ae5 100644 --- a/ui/single/task-priority-too-high.stderr +++ b/ui/single/task-priority-too-high.stderr @@ -4,7 +4,7 @@ warning: unused import: `rtic::app` 3 | use rtic::app; | ^^^^^^^^^ | - = note: #[warn(unused_imports)] on by default + = note: `#[warn(unused_imports)]` on by default error[E0080]: evaluation of constant value failed --> $DIR/task-priority-too-high.rs:5:1 -- cgit v1.2.3 From 148ad4045e36f3c1d11d2708494c7628b3838df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Wed, 22 Apr 2020 12:10:43 +0000 Subject: Update documentation where const is replaced by mod --- macros/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 7b72c7f..2a439e1 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -15,8 +15,7 @@ mod tests; /// Attribute used to declare a RTIC application /// -/// This attribute must be applied to a `const` item of type `()`. The `const` item is effectively -/// used as a `mod` item: its value must be a block that contains items commonly found in modules, +/// This attribute must be applied to a module block that contains items commonly found in modules, /// like functions and `static` variables. /// /// The `app` attribute has one mandatory argument: @@ -34,7 +33,7 @@ mod tests; /// - `monotonic = `. This is a path to a zero-sized structure (e.g. `struct Foo;`) that /// implements the `Monotonic` trait. This argument must be provided to use the `schedule` API. /// -/// The items allowed in the block value of the `const` item are specified below: +/// The items allowed in the module block are specified below: /// /// # 1. `struct Resources` /// -- cgit v1.2.3 From c718413cb56f9c25d79c71e607079561923b1a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 19 May 2020 09:55:50 +0000 Subject: Generate mod instead of const, handle import of idle and init --- macros/src/codegen.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index fe4d59a..83e5ce8 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -26,6 +26,7 @@ mod util; // TODO document the syntax here or in `rtic-syntax` pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let mut const_app = vec![]; + let mut const_app_imports = vec![]; let mut mains = vec![]; let mut root = vec![]; let mut user = vec![]; @@ -41,6 +42,17 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let (const_app_idle, root_idle, user_idle, call_idle) = idle::codegen(app, analysis, extra); + if user_init.is_some() { + const_app_imports.push(quote!( + use super::init; + )) + } + if user_idle.is_some() { + const_app_imports.push(quote!( + use super::idle; + )) + } + user.push(quote!( #user_init @@ -111,10 +123,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#root_software_tasks)* /// Implementation details - // The user can't access the items within this `const` item - const #name: () = { + // the user can't access the items within this `const` item + mod #name { /// Always include the device crate which contains the vector table use #device as _; + #(#const_app_imports)* #(#const_app)* @@ -133,6 +146,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#const_app_schedule)* #(#mains)* - }; + } ) } -- cgit v1.2.3 From 5cfd9b92384a6e2d352e35de9da1b7a2b53cc2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 19 May 2020 18:00:13 +0000 Subject: Modules using lower-case in examples --- examples/baseline.rs | 2 +- examples/binds.rs | 2 +- examples/capacity.rs | 2 +- examples/cfg.rs | 2 +- examples/destructure.rs | 2 +- examples/generics.rs | 2 +- examples/hardware.rs | 2 +- examples/idle.rs | 2 +- examples/init.rs | 2 +- examples/late.rs | 2 +- examples/lock.rs | 2 +- examples/message.rs | 2 +- examples/not-send.rs | 2 +- examples/not-sync.rs | 2 +- examples/only-shared-access.rs | 2 +- examples/periodic.rs | 3 ++- examples/peripherals-taken.rs | 2 +- examples/pool.rs | 5 ++++- examples/preempt.rs | 2 +- examples/ramfunc.rs | 2 +- examples/resource.rs | 2 +- examples/schedule.rs | 2 +- examples/shared-with-init.rs | 2 +- examples/smallest.rs | 2 +- examples/t-binds.rs | 2 +- examples/t-cfg-resources.rs | 3 +-- examples/t-cfg.rs | 2 +- examples/t-htask-main.rs | 2 +- examples/t-idle-main.rs | 2 +- examples/t-init-main.rs | 2 +- examples/t-late-not-send.rs | 2 +- examples/t-resource.rs | 2 +- examples/t-schedule.rs | 2 +- examples/t-spawn.rs | 2 +- examples/t-stask-main.rs | 2 +- examples/task.rs | 2 +- examples/types.rs | 2 +- ui/single/exception-invalid.rs | 2 +- ui/single/exception-systick-used.rs | 2 +- ui/single/extern-interrupt-not-enough.rs | 2 +- ui/single/extern-interrupt-used.rs | 2 +- ui/single/locals-cfg.rs | 2 +- ui/single/resources-cfg.rs | 2 +- ui/single/task-priority-too-high.rs | 2 +- 44 files changed, 48 insertions(+), 45 deletions(-) diff --git a/examples/baseline.rs b/examples/baseline.rs index 2d75dfa..e517bf0 100644 --- a/examples/baseline.rs +++ b/examples/baseline.rs @@ -11,7 +11,7 @@ use panic_semihosting as _; // NOTE: does NOT properly work on QEMU #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -mod APP { +mod app { #[init(spawn = [foo])] fn init(cx: init::Context) { // omitted: initialization of `CYCCNT` diff --git a/examples/binds.rs b/examples/binds.rs index 920124c..9c73433 100644 --- a/examples/binds.rs +++ b/examples/binds.rs @@ -11,7 +11,7 @@ use panic_semihosting as _; // `examples/interrupt.rs` rewritten to use `binds` #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) { rtic::pend(Interrupt::UART0); diff --git a/examples/capacity.rs b/examples/capacity.rs index 26c61a2..7ccb086 100644 --- a/examples/capacity.rs +++ b/examples/capacity.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) { rtic::pend(Interrupt::UART0); diff --git a/examples/cfg.rs b/examples/cfg.rs index 626181d..16e6e07 100644 --- a/examples/cfg.rs +++ b/examples/cfg.rs @@ -11,7 +11,7 @@ use cortex_m_semihosting::hprintln; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { #[cfg(debug_assertions)] // <- `true` when using the `dev` profile #[init(0)] diff --git a/examples/destructure.rs b/examples/destructure.rs index da0a4c1..131c07f 100644 --- a/examples/destructure.rs +++ b/examples/destructure.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { // Some resources to work with #[init(0)] diff --git a/examples/generics.rs b/examples/generics.rs index b67ed9c..20e9ed7 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -11,7 +11,7 @@ use panic_semihosting as _; use rtic::{Exclusive, Mutex}; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { #[init(0)] shared: u32, diff --git a/examples/hardware.rs b/examples/hardware.rs index 7926650..831b029 100644 --- a/examples/hardware.rs +++ b/examples/hardware.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) { // Pends the UART0 interrupt but its handler won't run until *after* diff --git a/examples/idle.rs b/examples/idle.rs index dbf7f98..0db0545 100644 --- a/examples/idle.rs +++ b/examples/idle.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) { hprintln!("init").unwrap(); diff --git a/examples/init.rs b/examples/init.rs index c651136..aaf71f9 100644 --- a/examples/init.rs +++ b/examples/init.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965, peripherals = true)] -mod APP { +mod app { #[init] fn init(cx: init::Context) { static mut X: u32 = 0; diff --git a/examples/late.rs b/examples/late.rs index 8675c6a..f656efb 100644 --- a/examples/late.rs +++ b/examples/late.rs @@ -15,7 +15,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { // Late resources struct Resources { p: Producer<'static, u32, U4>, diff --git a/examples/lock.rs b/examples/lock.rs index 4b16679..61aed21 100644 --- a/examples/lock.rs +++ b/examples/lock.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { #[init(0)] shared: u32, diff --git a/examples/message.rs b/examples/message.rs index 3e9633b..3f14a5a 100644 --- a/examples/message.rs +++ b/examples/message.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init(spawn = [foo])] fn init(c: init::Context) { c.spawn.foo(/* no message */).unwrap(); diff --git a/examples/not-send.rs b/examples/not-send.rs index bcc049c..a296594 100644 --- a/examples/not-send.rs +++ b/examples/not-send.rs @@ -16,7 +16,7 @@ pub struct NotSend { } #[app(device = lm3s6965)] -mod APP { +mod app { struct Resources { #[init(None)] shared: Option, diff --git a/examples/not-sync.rs b/examples/not-sync.rs index 0354ef1..7415621 100644 --- a/examples/not-sync.rs +++ b/examples/not-sync.rs @@ -15,7 +15,7 @@ pub struct NotSync { } #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { #[init(NotSync { _0: PhantomData })] shared: NotSync, diff --git a/examples/only-shared-access.rs b/examples/only-shared-access.rs index fbc7bfd..221cc30 100644 --- a/examples/only-shared-access.rs +++ b/examples/only-shared-access.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { key: u32, } diff --git a/examples/periodic.rs b/examples/periodic.rs index cd887ca..2d4c73b 100644 --- a/examples/periodic.rs +++ b/examples/periodic.rs @@ -13,7 +13,8 @@ const PERIOD: u32 = 8_000_000; // NOTE: does NOT work on QEMU! #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -mod APP { +mod app { + #[init(schedule = [foo])] fn init(cx: init::Context) { // omitted: initialization of `CYCCNT` diff --git a/examples/peripherals-taken.rs b/examples/peripherals-taken.rs index a1bd686..b9267df 100644 --- a/examples/peripherals-taken.rs +++ b/examples/peripherals-taken.rs @@ -7,7 +7,7 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn main(_: main::Context) { assert!(cortex_m::Peripherals::take().is_none()); diff --git a/examples/pool.rs b/examples/pool.rs index eb65ed8..c87be77 100644 --- a/examples/pool.rs +++ b/examples/pool.rs @@ -18,7 +18,10 @@ use rtic::app; pool!(P: [u8; 128]); #[app(device = lm3s6965)] -mod APP { +mod app { + use crate::Box; + use crate::P; + #[init] fn init(_: init::Context) { static mut MEMORY: [u8; 512] = [0; 512]; diff --git a/examples/preempt.rs b/examples/preempt.rs index a20b36c..0219301 100644 --- a/examples/preempt.rs +++ b/examples/preempt.rs @@ -9,7 +9,7 @@ use panic_semihosting as _; use rtic::app; #[app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) { rtic::pend(Interrupt::GPIOA); diff --git a/examples/ramfunc.rs b/examples/ramfunc.rs index cfe22e3..789d787 100644 --- a/examples/ramfunc.rs +++ b/examples/ramfunc.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init(spawn = [bar])] fn init(c: init::Context) { c.spawn.bar().unwrap(); diff --git a/examples/resource.rs b/examples/resource.rs index a0954d6..4887b5e 100644 --- a/examples/resource.rs +++ b/examples/resource.rs @@ -10,7 +10,7 @@ use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { // A resource #[init(0)] diff --git a/examples/schedule.rs b/examples/schedule.rs index f2e7ed8..d5547b6 100644 --- a/examples/schedule.rs +++ b/examples/schedule.rs @@ -12,7 +12,7 @@ use rtic::cyccnt::{Instant, U32Ext as _}; // NOTE: does NOT work on QEMU! #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -mod APP { +mod app { #[init(schedule = [foo, bar])] fn init(mut cx: init::Context) { // Initialize (enable) the monotonic timer (CYCCNT) diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs index 03391bd..dcc31d3 100644 --- a/examples/shared-with-init.rs +++ b/examples/shared-with-init.rs @@ -13,7 +13,7 @@ use rtic::app; pub struct MustBeSend; #[app(device = lm3s6965)] -mod APP { +mod app { struct Resources { #[init(None)] shared: Option, diff --git a/examples/smallest.rs b/examples/smallest.rs index d6f3b66..b8cbf87 100644 --- a/examples/smallest.rs +++ b/examples/smallest.rs @@ -7,4 +7,4 @@ use panic_semihosting as _; // panic handler use rtic::app; #[app(device = lm3s6965)] -mod APP {} +mod app {} diff --git a/examples/t-binds.rs b/examples/t-binds.rs index 8634c75..7d7bd7d 100644 --- a/examples/t-binds.rs +++ b/examples/t-binds.rs @@ -8,7 +8,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) {} diff --git a/examples/t-cfg-resources.rs b/examples/t-cfg-resources.rs index 892d211..cf1c684 100644 --- a/examples/t-cfg-resources.rs +++ b/examples/t-cfg-resources.rs @@ -6,12 +6,11 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { // A resource #[init(0)] shared: u32, - // A conditionally compiled resource behind feature_x #[cfg(feature = "feature_x")] x: u32, diff --git a/examples/t-cfg.rs b/examples/t-cfg.rs index da9a491..7caabe2 100644 --- a/examples/t-cfg.rs +++ b/examples/t-cfg.rs @@ -6,7 +6,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -mod APP { +mod app { struct Resources { #[cfg(never)] #[init(0)] diff --git a/examples/t-htask-main.rs b/examples/t-htask-main.rs index 6143bbd..1954d56 100644 --- a/examples/t-htask-main.rs +++ b/examples/t-htask-main.rs @@ -7,7 +7,7 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) { rtic::pend(lm3s6965::Interrupt::UART0) diff --git a/examples/t-idle-main.rs b/examples/t-idle-main.rs index 89f93d0..8400f31 100644 --- a/examples/t-idle-main.rs +++ b/examples/t-idle-main.rs @@ -7,7 +7,7 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) {} diff --git a/examples/t-init-main.rs b/examples/t-init-main.rs index 040c72f..b4f126b 100644 --- a/examples/t-init-main.rs +++ b/examples/t-init-main.rs @@ -7,7 +7,7 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn main(_: main::Context) { debug::exit(debug::EXIT_SUCCESS); diff --git a/examples/t-late-not-send.rs b/examples/t-late-not-send.rs index 7799018..4f6d1af 100644 --- a/examples/t-late-not-send.rs +++ b/examples/t-late-not-send.rs @@ -12,7 +12,7 @@ pub struct NotSend { } #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { x: NotSend, #[init(None)] diff --git a/examples/t-resource.rs b/examples/t-resource.rs index 0864a8a..e18a1cd 100644 --- a/examples/t-resource.rs +++ b/examples/t-resource.rs @@ -8,7 +8,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { #[init(0)] o1: u32, // init diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs index 6753613..ef2eb08 100644 --- a/examples/t-schedule.rs +++ b/examples/t-schedule.rs @@ -9,7 +9,7 @@ use panic_halt as _; use rtic::cyccnt::{Instant, U32Ext as _}; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -mod APP { +mod app { #[init(schedule = [foo, bar, baz])] fn init(c: init::Context) { let _: Result<(), ()> = c.schedule.foo(c.start + 10.cycles()); diff --git a/examples/t-spawn.rs b/examples/t-spawn.rs index 7a64e1c..72143c5 100644 --- a/examples/t-spawn.rs +++ b/examples/t-spawn.rs @@ -8,7 +8,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init(spawn = [foo, bar, baz])] fn init(c: init::Context) { let _: Result<(), ()> = c.spawn.foo(); diff --git a/examples/t-stask-main.rs b/examples/t-stask-main.rs index edea430..373b505 100644 --- a/examples/t-stask-main.rs +++ b/examples/t-stask-main.rs @@ -7,7 +7,7 @@ use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init(spawn = [main])] fn init(cx: init::Context) { cx.spawn.main().ok(); diff --git a/examples/task.rs b/examples/task.rs index e515c93..f510df7 100644 --- a/examples/task.rs +++ b/examples/task.rs @@ -9,7 +9,7 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init(spawn = [foo])] fn init(c: init::Context) { c.spawn.foo().unwrap(); diff --git a/examples/types.rs b/examples/types.rs index eafc9b1..8c612b2 100644 --- a/examples/types.rs +++ b/examples/types.rs @@ -10,7 +10,7 @@ use panic_semihosting as _; use rtic::cyccnt; #[rtic::app(device = lm3s6965, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] -mod APP { +mod app { struct Resources { #[init(0)] shared: u32, diff --git a/ui/single/exception-invalid.rs b/ui/single/exception-invalid.rs index 9b6b001..04d9bc7 100644 --- a/ui/single/exception-invalid.rs +++ b/ui/single/exception-invalid.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[task(binds = NonMaskableInt)] fn nmi(_: nmi::Context) {} } diff --git a/ui/single/exception-systick-used.rs b/ui/single/exception-systick-used.rs index 02fd1c6..1c30b70 100644 --- a/ui/single/exception-systick-used.rs +++ b/ui/single/exception-systick-used.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[task(binds = SysTick)] fn sys_tick(_: sys_tick::Context) {} diff --git a/ui/single/extern-interrupt-not-enough.rs b/ui/single/extern-interrupt-not-enough.rs index 18850d8..f262403 100644 --- a/ui/single/extern-interrupt-not-enough.rs +++ b/ui/single/extern-interrupt-not-enough.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[task] fn a(_: a::Context) {} } diff --git a/ui/single/extern-interrupt-used.rs b/ui/single/extern-interrupt-used.rs index dd79843..89c2378 100644 --- a/ui/single/extern-interrupt-used.rs +++ b/ui/single/extern-interrupt-used.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[task(binds = UART0)] fn a(_: a::Context) {} diff --git a/ui/single/locals-cfg.rs b/ui/single/locals-cfg.rs index 5053cf3..7ec46ac 100644 --- a/ui/single/locals-cfg.rs +++ b/ui/single/locals-cfg.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) { #[cfg(never)] diff --git a/ui/single/resources-cfg.rs b/ui/single/resources-cfg.rs index fd03f58..e41ce42 100644 --- a/ui/single/resources-cfg.rs +++ b/ui/single/resources-cfg.rs @@ -1,7 +1,7 @@ #![no_main] #[rtic::app(device = lm3s6965)] -mod APP { +mod app { struct Resources { #[cfg(never)] #[init(0)] diff --git a/ui/single/task-priority-too-high.rs b/ui/single/task-priority-too-high.rs index ed7dd86..c01d685 100644 --- a/ui/single/task-priority-too-high.rs +++ b/ui/single/task-priority-too-high.rs @@ -3,7 +3,7 @@ use rtic::app; #[rtic::app(device = lm3s6965)] -mod APP { +mod app { #[init] fn init(_: init::Context) {} -- cgit v1.2.3 From 46bf583cc21bd8fa34e3163149b4327fcc08057e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 19 May 2020 19:03:19 +0000 Subject: Handle user hardware and software tasks and some resources --- macros/src/codegen.rs | 28 +++++++++++++++++++++++++--- macros/src/codegen/hardware_tasks.rs | 19 ++++++++++++++++++- macros/src/codegen/resources.rs | 12 +++++++++++- macros/src/codegen/software_tasks.rs | 18 +++++++++++++++++- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 83e5ce8..68f4fee 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -89,12 +89,12 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } )); - let (const_app_resources, mod_resources) = resources::codegen(app, analysis, extra); + let (const_app_resources, mod_resources, mod_resources_imports) = resources::codegen(app, analysis, extra); - let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) = + let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, user_hardware_tasks_imports) = hardware_tasks::codegen(app, analysis, extra); - let (const_app_software_tasks, root_software_tasks, user_software_tasks) = + let (const_app_software_tasks, root_software_tasks, user_software_tasks, user_software_tasks_imports) = software_tasks::codegen(app, analysis, extra); let const_app_dispatchers = dispatchers::codegen(app, analysis, extra); @@ -110,16 +110,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { quote!( #(#user)* + /// USER_HW_TASKS #(#user_hardware_tasks)* + /// USER_SW_TASKS #(#user_software_tasks)* + /// ROOT #(#root)* + /// MOD_RESOURCES #mod_resources + /// root_hardware_tasks #(#root_hardware_tasks)* + /// root_software_tasks #(#root_software_tasks)* /// Implementation details @@ -129,17 +135,33 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { use #device as _; #(#const_app_imports)* + /// User hardware_tasks + #(#user_hardware_tasks_imports)* + + /// User software_tasks + #(#user_software_tasks_imports)* + + /// Mod resources imports + #(#mod_resources_imports)* + + /// Const app #(#const_app)* + /// Const app resources #(#const_app_resources)* + /// Const app hw tasks #(#const_app_hardware_tasks)* + /// Const app sw tasks #(#const_app_software_tasks)* + /// Const app dispatchers #(#const_app_dispatchers)* + /// Const app spawn #(#const_app_spawn)* + /// Const app spawn end #(#const_app_timer_queue)* diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index 7f14b5e..4f60876 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -23,10 +23,13 @@ pub fn codegen( Vec, // user_hardware_tasks -- the `#[task]` functions written by the user Vec, + // user_hardware_tasks_imports -- the imports for `#[task]` functions written by the user + Vec, ) { let mut const_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; + let mut hardware_tasks_imports = vec![]; for (name, task) in &app.hardware_tasks { let (let_instant, instant) = if app.uses_schedule() { @@ -78,6 +81,13 @@ pub fn codegen( analysis, ); + // Add resources to imports + let name_res = format_ident!("{}Resources", name); + hardware_tasks_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_res; + )); + root.push(item); const_app.push(constructor); @@ -112,7 +122,14 @@ pub fn codegen( #(#stmts)* } )); + + hardware_tasks_imports.push(quote!( + #(#attrs)* + #[allow(non_snake_case)] + use super::#name; + )); + } - (const_app, root, user_tasks) + (const_app, root, user_tasks, hardware_tasks_imports) } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index 4196ee7..80e63c7 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -14,9 +14,12 @@ pub fn codegen( Vec, // mod_resources -- the `resources` module TokenStream2, + // mod_resources_imports -- the `resources` module imports + Vec, ) { let mut const_app = vec![]; let mut mod_resources = vec![]; + let mut mod_resources_imports = vec![]; for (name, res, expr, _) in app.resources(analysis) { let cfgs = &res.cfgs; @@ -82,6 +85,13 @@ pub fn codegen( ) }; + mod_resources_imports.push(quote!( + #[allow(non_camel_case_types)] + #(#cfgs)* + #cfg_core + use super::#name; + )); + const_app.push(util::impl_mutex( extra, cfgs, @@ -104,5 +114,5 @@ pub fn codegen( }) }; - (const_app, mod_resources) + (const_app, mod_resources, mod_resources_imports) } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index b56db41..07edd1d 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -22,10 +22,13 @@ pub fn codegen( Vec, // user_software_tasks -- the `#[task]` functions written by the user Vec, + // user_software_tasks_imports -- the imports for `#[task]` functions written by the user + Vec, ) { let mut const_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; + let mut software_tasks_imports = vec![]; for (name, task) in &app.software_tasks { let inputs = &task.inputs; @@ -112,6 +115,13 @@ pub fn codegen( analysis, ); + // Add resources to imports + let name_res = format_ident!("{}Resources", name); + software_tasks_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_res; + )); + root.push(item); const_app.push(constructor); @@ -141,6 +151,12 @@ pub fn codegen( #(#stmts)* } )); + software_tasks_imports.push(quote!( + #(#attrs)* + #(#cfgs)* + #[allow(non_snake_case)] + use super::#name; + )); root.push(module::codegen( Context::SoftwareTask(name), @@ -150,5 +166,5 @@ pub fn codegen( )); } - (const_app, root, user_tasks) + (const_app, root, user_tasks, software_tasks_imports) } -- cgit v1.2.3 From dcc31fb8843d228165b28af1c10d92266847ce90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 26 May 2020 10:48:24 +0000 Subject: Examples need to import the resources --- examples/late.rs | 4 ++++ examples/not-send.rs | 2 ++ examples/not-sync.rs | 3 +++ examples/shared-with-init.rs | 2 ++ examples/t-late-not-send.rs | 2 ++ 5 files changed, 13 insertions(+) diff --git a/examples/late.rs b/examples/late.rs index f656efb..2b99e3d 100644 --- a/examples/late.rs +++ b/examples/late.rs @@ -16,6 +16,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use heapless::{ + consts::*, + spsc::{Consumer, Producer}, + }; // Late resources struct Resources { p: Producer<'static, u32, U4>, diff --git a/examples/not-send.rs b/examples/not-send.rs index a296594..c0582d7 100644 --- a/examples/not-send.rs +++ b/examples/not-send.rs @@ -17,6 +17,8 @@ pub struct NotSend { #[app(device = lm3s6965)] mod app { + use super::NotSend; + struct Resources { #[init(None)] shared: Option, diff --git a/examples/not-sync.rs b/examples/not-sync.rs index 7415621..28c7618 100644 --- a/examples/not-sync.rs +++ b/examples/not-sync.rs @@ -16,6 +16,9 @@ pub struct NotSync { #[rtic::app(device = lm3s6965)] mod app { + use super::NotSync; + use core::marker::PhantomData; + struct Resources { #[init(NotSync { _0: PhantomData })] shared: NotSync, diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs index dcc31d3..9c4499e 100644 --- a/examples/shared-with-init.rs +++ b/examples/shared-with-init.rs @@ -14,6 +14,8 @@ pub struct MustBeSend; #[app(device = lm3s6965)] mod app { + use super::MustBeSend; + struct Resources { #[init(None)] shared: Option, diff --git a/examples/t-late-not-send.rs b/examples/t-late-not-send.rs index 4f6d1af..587ee73 100644 --- a/examples/t-late-not-send.rs +++ b/examples/t-late-not-send.rs @@ -13,6 +13,8 @@ pub struct NotSend { #[rtic::app(device = lm3s6965)] mod app { + use super::NotSend; + struct Resources { x: NotSend, #[init(None)] -- cgit v1.2.3 From 9fd052b876581e5aef3442b17c17b0b597f84a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 26 May 2020 10:52:10 +0000 Subject: Collect and generate required use-statements --- macros/src/codegen/idle.rs | 25 ++++++++++++++++++++++--- macros/src/codegen/init.rs | 28 +++++++++++++++++++++++++--- macros/src/codegen/resources.rs | 7 ++++++- macros/src/codegen/resources_struct.rs | 2 +- macros/src/codegen/software_tasks.rs | 3 +-- macros/src/codegen/spawn.rs | 4 ++-- 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs index d0bff3e..db454a5 100644 --- a/macros/src/codegen/idle.rs +++ b/macros/src/codegen/idle.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::quote; +use quote::{quote, format_ident}; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -23,6 +23,8 @@ pub fn codegen( Vec, // user_idle Option, + // user_idle_imports + Vec, // call_idle TokenStream2, ) { @@ -34,15 +36,25 @@ pub fn codegen( let mut locals_pat = None; let mut locals_new = None; + let mut user_idle_imports = vec![]; + + let name = &idle.name; + if !idle.args.resources.is_empty() { let (item, constructor) = resources_struct::codegen(Context::Idle, 0, &mut needs_lt, app, analysis); root_idle.push(item); const_app = Some(constructor); + + let name_resource = format_ident!("{}Resources", name); + user_idle_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_resource; + )); + } - let name = &idle.name; if !idle.locals.is_empty() { let (locals, pat) = locals::codegen(Context::Idle, &idle.locals, app); @@ -66,6 +78,12 @@ pub fn codegen( #(#stmts)* } )); + user_idle_imports.push(quote!( + #(#attrs)* + #[allow(non_snake_case)] + #cfg_core + use super::#name; + )); let locals_new = locals_new.iter(); let call_idle = quote!(crate::#name( @@ -73,12 +91,13 @@ pub fn codegen( #name::Context::new(&rtic::export::Priority::new(0)) )); - (const_app, root_idle, user_idle, call_idle) + (const_app, root_idle, user_idle, user_idle_imports, call_idle) } else { ( None, vec![], None, + vec![], quote!(loop { rtic::export::wfi() }), diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index e0b7d69..88a7a23 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::quote; +use quote::{quote, format_ident}; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -24,6 +24,8 @@ pub fn codegen( Vec, // user_init -- the `#[init]` function written by the user Option, + // user_init_imports -- the imports for `#[init]` functio written by the user + Vec, // call_init -- the call to the user `#[init]` if there's one Option, ) { @@ -34,6 +36,8 @@ pub fn codegen( let mut root_init = vec![]; + let mut user_init_imports = vec![]; + let ret = { let late_fields = analysis .late_resources @@ -62,6 +66,12 @@ pub fn codegen( } )); + let name_late = format_ident!("{}LateResources", name); + user_init_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_late; + )); + Some(quote!(-> #name::LateResources)) } else { None @@ -89,6 +99,12 @@ pub fn codegen( #(#stmts)* } )); + user_init_imports.push(quote!( + #(#attrs)* + #cfg_core + #[allow(non_snake_case)] + use super::#name; + )); let mut const_app = None; if !init.args.resources.is_empty() { @@ -97,6 +113,12 @@ pub fn codegen( root_init.push(item); const_app = Some(constructor); + + let name_late = format_ident!("{}Resources", name); + user_init_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_late; + )); } let locals_new = locals_new.iter(); @@ -106,8 +128,8 @@ pub fn codegen( root_init.push(module::codegen(Context::Init, needs_lt, app, extra)); - (const_app, root_init, user_init, call_init) + (const_app, root_init, user_init, user_init_imports, call_init) } else { - (None, vec![], None, None) + (None, vec![], None, vec![], None) } } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index 80e63c7..a326e68 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -89,7 +89,7 @@ pub fn codegen( #[allow(non_camel_case_types)] #(#cfgs)* #cfg_core - use super::#name; + use super::resources::#name; )); const_app.push(util::impl_mutex( @@ -107,6 +107,11 @@ pub fn codegen( let mod_resources = if mod_resources.is_empty() { quote!() } else { + // Also import the resource module + mod_resources_imports.push(quote!( + use super::resources; + )); + quote!(mod resources { use rtic::export::Priority; diff --git a/macros/src/codegen/resources_struct.rs b/macros/src/codegen/resources_struct.rs index dbbba30..92d5b66 100644 --- a/macros/src/codegen/resources_struct.rs +++ b/macros/src/codegen/resources_struct.rs @@ -165,7 +165,7 @@ pub fn codegen( let constructor = quote!( impl<#lt> #ident<#lt> { #[inline(always)] - unsafe fn new(#arg) -> Self { + pub unsafe fn new(#arg) -> Self { #ident { #(#values,)* } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 07edd1d..f3a0db1 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -145,14 +145,13 @@ pub fn codegen( #(#attrs)* #(#cfgs)* #[allow(non_snake_case)] - fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { + pub fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { use rtic::Mutex as _; #(#stmts)* } )); software_tasks_imports.push(quote!( - #(#attrs)* #(#cfgs)* #[allow(non_snake_case)] use super::#name; diff --git a/macros/src/codegen/spawn.rs b/macros/src/codegen/spawn.rs index 4b824f5..da28151 100644 --- a/macros/src/codegen/spawn.rs +++ b/macros/src/codegen/spawn.rs @@ -40,7 +40,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Result<(), #ty> { + pub fn #name(&self #(,#args)*) -> Result<(), #ty> { #let_instant #body } @@ -92,7 +92,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Result<(), #ty> { + pub fn #name(&self #(,#args)*) -> Result<(), #ty> { unsafe { #let_instant #spawn(self.priority() #instant #(,#untupled)*) -- cgit v1.2.3 From 0c7a619432e50eccfe019819b4ce3b0e6b9062df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 26 May 2020 10:55:13 +0000 Subject: Compose the use-statements, reduce debug-printouts --- macros/src/codegen.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 68f4fee..fde9490 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -30,17 +30,18 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let mut mains = vec![]; let mut root = vec![]; let mut user = vec![]; + let mut imports = vec![]; // Generate the `main` function let assertion_stmts = assertions::codegen(analysis); let pre_init_stmts = pre_init::codegen(&app, analysis, extra); - let (const_app_init, root_init, user_init, call_init) = init::codegen(app, analysis, extra); + let (const_app_init, root_init, user_init, user_init_imports, call_init) = init::codegen(app, analysis, extra); let post_init_stmts = post_init::codegen(&app, analysis); - let (const_app_idle, root_idle, user_idle, call_idle) = idle::codegen(app, analysis, extra); + let (const_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = idle::codegen(app, analysis, extra); if user_init.is_some() { const_app_imports.push(quote!( @@ -59,6 +60,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #user_idle )); + imports.push(quote!( + #(#user_init_imports)* + #(#user_idle_imports)* + )); + root.push(quote!( #(#root_init)* @@ -105,27 +111,23 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let const_app_schedule = schedule::codegen(app, extra); + + let user_imports = app.user_imports.clone(); let name = &app.name; let device = extra.device; quote!( #(#user)* - /// USER_HW_TASKS #(#user_hardware_tasks)* - /// USER_SW_TASKS #(#user_software_tasks)* - /// ROOT #(#root)* - /// MOD_RESOURCES #mod_resources - /// root_hardware_tasks #(#root_hardware_tasks)* - /// root_software_tasks #(#root_software_tasks)* /// Implementation details @@ -133,35 +135,27 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { mod #name { /// Always include the device crate which contains the vector table use #device as _; - #(#const_app_imports)* + #(#imports)* + #(#user_imports)* - /// User hardware_tasks #(#user_hardware_tasks_imports)* - /// User software_tasks #(#user_software_tasks_imports)* - /// Mod resources imports #(#mod_resources_imports)* /// Const app #(#const_app)* - /// Const app resources #(#const_app_resources)* - /// Const app hw tasks #(#const_app_hardware_tasks)* - /// Const app sw tasks #(#const_app_software_tasks)* - /// Const app dispatchers #(#const_app_dispatchers)* - /// Const app spawn #(#const_app_spawn)* - /// Const app spawn end #(#const_app_timer_queue)* -- cgit v1.2.3 From 2881cc8f435cfd348def7821ce79b705f141470b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 26 May 2020 13:48:43 +0000 Subject: Modify macro tests, use mod instead of const --- macros/src/tests/single.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macros/src/tests/single.rs b/macros/src/tests/single.rs index d669388..97cbbb3 100644 --- a/macros/src/tests/single.rs +++ b/macros/src/tests/single.rs @@ -8,7 +8,7 @@ fn analyze() { let (app, analysis) = rtic_syntax::parse2( quote!(device = pac), quote!( - const APP: () = { + mod app { #[task(priority = 1)] fn a(_: a::Context) {} @@ -20,7 +20,7 @@ fn analyze() { fn B(); fn A(); } - }; + } ), settings, ) -- cgit v1.2.3 From 86578b76fbd0a644f2d5008ac6c0661b40301a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 1 Sep 2020 20:49:15 +0000 Subject: Add format_ident imports --- macros/src/codegen/hardware_tasks.rs | 2 +- macros/src/codegen/software_tasks.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index 4f60876..8f2ab2f 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::quote; +use quote::{quote, format_ident}; use rtic_syntax::{ast::App, Context}; use crate::{ diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index f3a0db1..854c083 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::quote; +use quote::{quote, format_ident}; use rtic_syntax::{ast::App, Context}; use crate::{ -- cgit v1.2.3 From 6d234f9c95bb9971c6b79f4a7a0bb6ff44236afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 1 Sep 2020 20:49:44 +0000 Subject: Use dev-branch for mod_const --- macros/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 610890b..35511ee 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -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/AfoHT/rtic-syntax", branch = "mod_const", version = "0.4.0" } -- cgit v1.2.3 From a151974245a994ec4c30bb0518677c4b99dce7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 8 Sep 2020 15:22:32 +0000 Subject: cfg_core is gone, cargo fmt --- macros/src/codegen.rs | 26 ++++++++++++++++++-------- macros/src/codegen/hardware_tasks.rs | 3 +-- macros/src/codegen/idle.rs | 12 ++++++++---- macros/src/codegen/init.rs | 11 ++++++++--- macros/src/codegen/resources.rs | 1 - macros/src/codegen/software_tasks.rs | 2 +- 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index fde9490..e45f1a3 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -37,11 +37,13 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let pre_init_stmts = pre_init::codegen(&app, analysis, extra); - let (const_app_init, root_init, user_init, user_init_imports, call_init) = init::codegen(app, analysis, extra); + let (const_app_init, root_init, user_init, user_init_imports, call_init) = + init::codegen(app, analysis, extra); let post_init_stmts = post_init::codegen(&app, analysis); - let (const_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = idle::codegen(app, analysis, extra); + let (const_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = + idle::codegen(app, analysis, extra); if user_init.is_some() { const_app_imports.push(quote!( @@ -95,13 +97,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } )); - let (const_app_resources, mod_resources, mod_resources_imports) = resources::codegen(app, analysis, extra); + let (const_app_resources, mod_resources, mod_resources_imports) = + resources::codegen(app, analysis, extra); - let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, user_hardware_tasks_imports) = - hardware_tasks::codegen(app, analysis, extra); + let ( + const_app_hardware_tasks, + root_hardware_tasks, + user_hardware_tasks, + user_hardware_tasks_imports, + ) = hardware_tasks::codegen(app, analysis, extra); - let (const_app_software_tasks, root_software_tasks, user_software_tasks, user_software_tasks_imports) = - software_tasks::codegen(app, analysis, extra); + let ( + const_app_software_tasks, + root_software_tasks, + user_software_tasks, + user_software_tasks_imports, + ) = software_tasks::codegen(app, analysis, extra); let const_app_dispatchers = dispatchers::codegen(app, analysis, extra); @@ -111,7 +122,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let const_app_schedule = schedule::codegen(app, extra); - let user_imports = app.user_imports.clone(); let name = &app.name; let device = extra.device; diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index 8f2ab2f..a03fd77 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, format_ident}; +use quote::{format_ident, quote}; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -128,7 +128,6 @@ pub fn codegen( #[allow(non_snake_case)] use super::#name; )); - } (const_app, root, user_tasks, hardware_tasks_imports) diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs index db454a5..2aa9975 100644 --- a/macros/src/codegen/idle.rs +++ b/macros/src/codegen/idle.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, format_ident}; +use quote::{format_ident, quote}; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -52,7 +52,6 @@ pub fn codegen( #[allow(non_snake_case)] use super::#name_resource; )); - } if !idle.locals.is_empty() { @@ -81,7 +80,6 @@ pub fn codegen( user_idle_imports.push(quote!( #(#attrs)* #[allow(non_snake_case)] - #cfg_core use super::#name; )); @@ -91,7 +89,13 @@ pub fn codegen( #name::Context::new(&rtic::export::Priority::new(0)) )); - (const_app, root_idle, user_idle, user_idle_imports, call_idle) + ( + const_app, + root_idle, + user_idle, + user_idle_imports, + call_idle, + ) } else { ( None, diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 88a7a23..b350298 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, format_ident}; +use quote::{format_ident, quote}; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -101,7 +101,6 @@ pub fn codegen( )); user_init_imports.push(quote!( #(#attrs)* - #cfg_core #[allow(non_snake_case)] use super::#name; )); @@ -128,7 +127,13 @@ pub fn codegen( root_init.push(module::codegen(Context::Init, needs_lt, app, extra)); - (const_app, root_init, user_init, user_init_imports, call_init) + ( + const_app, + root_init, + user_init, + user_init_imports, + call_init, + ) } else { (None, vec![], None, vec![], None) } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index a326e68..d18a465 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -88,7 +88,6 @@ pub fn codegen( mod_resources_imports.push(quote!( #[allow(non_camel_case_types)] #(#cfgs)* - #cfg_core use super::resources::#name; )); diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 854c083..9e01115 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, format_ident}; +use quote::{format_ident, quote}; use rtic_syntax::{ast::App, Context}; use crate::{ -- cgit v1.2.3 From 5b17f8b599c75cf44f2d1bfb528c5dfa1f003ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Wed, 23 Sep 2020 13:32:42 +0000 Subject: Due to new module boundaries the schedule fn needs to be pub --- macros/src/codegen/schedule.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/macros/src/codegen/schedule.rs b/macros/src/codegen/schedule.rs index 46b0f38..5a88749 100644 --- a/macros/src/codegen/schedule.rs +++ b/macros/src/codegen/schedule.rs @@ -34,7 +34,7 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec { methods.push(quote!( #(#cfgs)* - fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> { + pub fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> { #body } )); @@ -49,7 +49,7 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec { items.push(quote!( #(#cfgs)* - unsafe fn #schedule( + pub unsafe fn #schedule( priority: &rtic::export::Priority, instant: #instant #(,#args)* @@ -62,7 +62,7 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec { methods.push(quote!( #(#cfgs)* #[inline(always)] - fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> { + pub fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> { unsafe { #schedule(self.priority(), instant #(,#untupled)*) } -- cgit v1.2.3 From 224e1991e0f4a6eb8d674ba129d8700b3b450d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 25 Sep 2020 13:24:53 +0000 Subject: Update new example to use mod {} --- examples/double_schedule.rs | 5 +++-- examples/t-cfg-resources.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/double_schedule.rs b/examples/double_schedule.rs index 6b3aec8..837f0d6 100644 --- a/examples/double_schedule.rs +++ b/examples/double_schedule.rs @@ -9,7 +9,8 @@ use panic_semihosting as _; use rtic::cyccnt::U32Ext; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] -const APP: () = { +mod app { + struct Resources { nothing: (), } @@ -34,4 +35,4 @@ const APP: () = { extern "C" { fn SSI0(); } -}; +} diff --git a/examples/t-cfg-resources.rs b/examples/t-cfg-resources.rs index cf1c684..190b32c 100644 --- a/examples/t-cfg-resources.rs +++ b/examples/t-cfg-resources.rs @@ -23,7 +23,7 @@ mod app { // The feature needs to be applied everywhere x is defined or used #[cfg(feature = "feature_x")] x: 0, - dummy: () // dummy such that we have at least one late resource + dummy: (), // dummy such that we have at least one late resource } } -- cgit v1.2.3 From abc50d2c58ef3470c67269a93a7f31fcd36bcea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 25 Sep 2020 13:36:00 +0000 Subject: Name collision with RTIC-main With modules the scoping is different and task names collide with main generated by RTIC --- examples/peripherals-taken.rs | 2 +- examples/t-htask-main.rs | 2 +- examples/t-idle-main.rs | 2 +- examples/t-init-main.rs | 2 +- examples/t-stask-main.rs | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/peripherals-taken.rs b/examples/peripherals-taken.rs index b9267df..10bc260 100644 --- a/examples/peripherals-taken.rs +++ b/examples/peripherals-taken.rs @@ -9,7 +9,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { #[init] - fn main(_: main::Context) { + fn taskmain(_: taskmain::Context) { assert!(cortex_m::Peripherals::take().is_none()); debug::exit(debug::EXIT_SUCCESS); } diff --git a/examples/t-htask-main.rs b/examples/t-htask-main.rs index 1954d56..998252e 100644 --- a/examples/t-htask-main.rs +++ b/examples/t-htask-main.rs @@ -14,7 +14,7 @@ mod app { } #[task(binds = UART0)] - fn main(_: main::Context) { + fn taskmain(_: taskmain::Context) { debug::exit(debug::EXIT_SUCCESS); } } diff --git a/examples/t-idle-main.rs b/examples/t-idle-main.rs index 8400f31..03a52cb 100644 --- a/examples/t-idle-main.rs +++ b/examples/t-idle-main.rs @@ -12,7 +12,7 @@ mod app { fn init(_: init::Context) {} #[idle] - fn main(_: main::Context) -> ! { + fn taskmain(_: taskmain::Context) -> ! { debug::exit(debug::EXIT_SUCCESS); loop { cortex_m::asm::nop(); diff --git a/examples/t-init-main.rs b/examples/t-init-main.rs index b4f126b..d081487 100644 --- a/examples/t-init-main.rs +++ b/examples/t-init-main.rs @@ -9,7 +9,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { #[init] - fn main(_: main::Context) { + fn taskmain(_: taskmain::Context) { debug::exit(debug::EXIT_SUCCESS); } } diff --git a/examples/t-stask-main.rs b/examples/t-stask-main.rs index 373b505..3e650f6 100644 --- a/examples/t-stask-main.rs +++ b/examples/t-stask-main.rs @@ -8,13 +8,13 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { - #[init(spawn = [main])] + #[init(spawn = [taskmain])] fn init(cx: init::Context) { - cx.spawn.main().ok(); + cx.spawn.taskmain().ok(); } #[task] - fn main(_: main::Context) { + fn taskmain(_: taskmain::Context) { debug::exit(debug::EXIT_SUCCESS); } -- cgit v1.2.3 From 262c15083bd4b40c638f91d7497d3d602d0b5d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 25 Sep 2020 13:58:22 +0000 Subject: Remove legacy 1.36.0 --- .github/workflows/build.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c687115..ed88c77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,6 @@ jobs: - x86_64-unknown-linux-gnu toolchain: - stable - - 1.36.0 steps: - name: Checkout uses: actions/checkout@v2 @@ -79,10 +78,6 @@ jobs: target: ${{ matrix.target }} override: true - - name: Disable optimisation profiles - if: matrix.toolchain == '1.36.0' - run: sed -i '/^\[profile.*build-override]$/,/^$/{/^#/!{/^$/!d}}' Cargo.toml - - name: cargo check uses: actions-rs/cargo@v1 with: @@ -306,7 +301,6 @@ jobs: - x86_64-unknown-linux-gnu toolchain: - stable - - 1.36.0 steps: - name: Checkout uses: actions/checkout@v2 @@ -340,10 +334,6 @@ jobs: target: ${{ matrix.target }} override: true - - name: Disable optimisation profiles - if: matrix.toolchain == '1.36.0' - run: sed -i '/^\[profile.*build-override]$/,/^$/{/^#/!{/^$/!d}}' Cargo.toml - - name: cargo check uses: actions-rs/cargo@v1 with: @@ -382,7 +372,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.36.0 + toolchain: stable target: thumbv7m-none-eabi override: true @@ -426,7 +416,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.36.0 + toolchain: stable target: thumbv6m-none-eabi override: true -- cgit v1.2.3 From ec936c3b51801280ee6edb365b784d515382b6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 25 Sep 2020 13:59:04 +0000 Subject: Update test suite output --- ui/single/locals-cfg.stderr | 12 ++++++++---- ui/single/task-priority-too-high.rs | 2 -- ui/single/task-priority-too-high.stderr | 16 +++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index e572a41..7637159 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -28,10 +28,14 @@ error[E0425]: cannot find value `FOO` in this scope 44 | FOO; | ^^^ not found in this scope -error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. +error: duplicate lang item in crate `panic_halt`: `panic_impl`. | - = note: first defined in crate `std` (which `$CRATE` depends on) + = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) + = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib + = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta -error: duplicate lang item in crate `panic_halt`: `panic_impl`. +error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. | - = note: first defined in crate `panic_semihosting`. + = note: the lang item is first defined in crate `panic_halt`. + = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta + = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_semihosting-805015f4a2d05965.rmeta diff --git a/ui/single/task-priority-too-high.rs b/ui/single/task-priority-too-high.rs index c01d685..fbafa4d 100644 --- a/ui/single/task-priority-too-high.rs +++ b/ui/single/task-priority-too-high.rs @@ -1,7 +1,5 @@ #![no_main] -use rtic::app; - #[rtic::app(device = lm3s6965)] mod app { #[init] diff --git a/ui/single/task-priority-too-high.stderr b/ui/single/task-priority-too-high.stderr index 5854ae5..e84ddd3 100644 --- a/ui/single/task-priority-too-high.stderr +++ b/ui/single/task-priority-too-high.stderr @@ -1,13 +1,7 @@ -warning: unused import: `rtic::app` - --> $DIR/task-priority-too-high.rs:3:5 - | -3 | use rtic::app; - | ^^^^^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - error[E0080]: evaluation of constant value failed - --> $DIR/task-priority-too-high.rs:5:1 + --> $DIR/task-priority-too-high.rs:3:1 + | +3 | #[rtic::app(device = lm3s6965)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `8_usize - 9_usize` which would overflow | -5 | #[rtic::app(device = lm3s6965)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) -- cgit v1.2.3 From 96df0a33b1096e807bdd15713b10c2f3fa39395c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 4 Jun 2020 15:24:21 +0000 Subject: All examples use #[resources] attribute --- examples/cfg.rs | 1 + examples/destructure.rs | 1 + examples/generics.rs | 1 + examples/late.rs | 1 + examples/lock.rs | 1 + examples/not-send.rs | 1 + examples/not-sync.rs | 1 + examples/only-shared-access.rs | 1 + examples/resource.rs | 1 + examples/shared-with-init.rs | 1 + examples/t-cfg-resources.rs | 2 +- examples/t-cfg.rs | 1 + examples/t-late-not-send.rs | 1 + examples/t-resource.rs | 1 + examples/types.rs | 1 + 15 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/cfg.rs b/examples/cfg.rs index 16e6e07..f484830 100644 --- a/examples/cfg.rs +++ b/examples/cfg.rs @@ -12,6 +12,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { #[cfg(debug_assertions)] // <- `true` when using the `dev` profile #[init(0)] diff --git a/examples/destructure.rs b/examples/destructure.rs index 131c07f..45d7319 100644 --- a/examples/destructure.rs +++ b/examples/destructure.rs @@ -11,6 +11,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { // Some resources to work with #[init(0)] diff --git a/examples/generics.rs b/examples/generics.rs index 20e9ed7..c65e651 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -12,6 +12,7 @@ use rtic::{Exclusive, Mutex}; #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { #[init(0)] shared: u32, diff --git a/examples/late.rs b/examples/late.rs index 2b99e3d..761c68f 100644 --- a/examples/late.rs +++ b/examples/late.rs @@ -21,6 +21,7 @@ mod app { spsc::{Consumer, Producer}, }; // Late resources + #[resources] struct Resources { p: Producer<'static, u32, U4>, c: Consumer<'static, u32, U4>, diff --git a/examples/lock.rs b/examples/lock.rs index 61aed21..6ce61dc 100644 --- a/examples/lock.rs +++ b/examples/lock.rs @@ -11,6 +11,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { #[init(0)] shared: u32, diff --git a/examples/not-send.rs b/examples/not-send.rs index c0582d7..45f7e4e 100644 --- a/examples/not-send.rs +++ b/examples/not-send.rs @@ -19,6 +19,7 @@ pub struct NotSend { mod app { use super::NotSend; + #[resources] struct Resources { #[init(None)] shared: Option, diff --git a/examples/not-sync.rs b/examples/not-sync.rs index 28c7618..7581642 100644 --- a/examples/not-sync.rs +++ b/examples/not-sync.rs @@ -19,6 +19,7 @@ mod app { use super::NotSync; use core::marker::PhantomData; + #[resources] struct Resources { #[init(NotSync { _0: PhantomData })] shared: NotSync, diff --git a/examples/only-shared-access.rs b/examples/only-shared-access.rs index 221cc30..91d0b7a 100644 --- a/examples/only-shared-access.rs +++ b/examples/only-shared-access.rs @@ -11,6 +11,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { key: u32, } diff --git a/examples/resource.rs b/examples/resource.rs index 4887b5e..4cd0f4c 100644 --- a/examples/resource.rs +++ b/examples/resource.rs @@ -11,6 +11,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { // A resource #[init(0)] diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs index 9c4499e..9f7e26a 100644 --- a/examples/shared-with-init.rs +++ b/examples/shared-with-init.rs @@ -16,6 +16,7 @@ pub struct MustBeSend; mod app { use super::MustBeSend; + #[resources] struct Resources { #[init(None)] shared: Option, diff --git a/examples/t-cfg-resources.rs b/examples/t-cfg-resources.rs index 190b32c..61eb4c7 100644 --- a/examples/t-cfg-resources.rs +++ b/examples/t-cfg-resources.rs @@ -7,6 +7,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { // A resource #[init(0)] @@ -16,7 +17,6 @@ mod app { x: u32, dummy: (), // dummy such that we have at least one late resource } - #[init] fn init(_: init::Context) -> init::LateResources { init::LateResources { diff --git a/examples/t-cfg.rs b/examples/t-cfg.rs index 7caabe2..3deb107 100644 --- a/examples/t-cfg.rs +++ b/examples/t-cfg.rs @@ -7,6 +7,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] mod app { + #[resources] struct Resources { #[cfg(never)] #[init(0)] diff --git a/examples/t-late-not-send.rs b/examples/t-late-not-send.rs index 587ee73..345d9ae 100644 --- a/examples/t-late-not-send.rs +++ b/examples/t-late-not-send.rs @@ -15,6 +15,7 @@ pub struct NotSend { mod app { use super::NotSend; + #[resources] struct Resources { x: NotSend, #[init(None)] diff --git a/examples/t-resource.rs b/examples/t-resource.rs index e18a1cd..94b527f 100644 --- a/examples/t-resource.rs +++ b/examples/t-resource.rs @@ -9,6 +9,7 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { #[init(0)] o1: u32, // init diff --git a/examples/types.rs b/examples/types.rs index 8c612b2..cd7e8a2 100644 --- a/examples/types.rs +++ b/examples/types.rs @@ -11,6 +11,7 @@ use rtic::cyccnt; #[rtic::app(device = lm3s6965, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] mod app { + #[resources] struct Resources { #[init(0)] shared: u32, -- cgit v1.2.3 From adff844b8c09e83b4a69fc5b7ac9bd133f09dbbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 4 Jun 2020 15:33:35 +0000 Subject: Add #[resources] to ui/single --- ui/single/resources-cfg.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/single/resources-cfg.rs b/ui/single/resources-cfg.rs index e41ce42..163927e 100644 --- a/ui/single/resources-cfg.rs +++ b/ui/single/resources-cfg.rs @@ -2,6 +2,7 @@ #[rtic::app(device = lm3s6965)] mod app { + #[resources] struct Resources { #[cfg(never)] #[init(0)] -- cgit v1.2.3 From 487fea45ce15ea375192f72ddb148dda8414873b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 4 Jun 2020 15:43:16 +0000 Subject: Keep user code as-is within the module, add example --- examples/resource-user-struct.rs | 60 ++++++++++++++++++++++++++++++++++++++++ macros/src/codegen.rs | 6 ++++ macros/src/lib.rs | 3 +- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 examples/resource-user-struct.rs diff --git a/examples/resource-user-struct.rs b/examples/resource-user-struct.rs new file mode 100644 index 0000000..132aa34 --- /dev/null +++ b/examples/resource-user-struct.rs @@ -0,0 +1,60 @@ +//! examples/resource.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::{debug, hprintln}; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965)] +mod app { + #[resources] + struct Resources { + // A resource + #[init(0)] + shared: u32, + } + + // Should not collide with the struct above + struct Resources2 { + // A resource + shared: u32, + } + + #[init] + fn init(_: init::Context) { + rtic::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART1); + } + + // `shared` cannot be accessed from this context + #[idle] + fn idle(_cx: idle::Context) -> ! { + debug::exit(debug::EXIT_SUCCESS); + + // error: no `resources` field in `idle::Context` + // _cx.resources.shared += 1; + + loop {} + } + + // `shared` can be accessed from this context + #[task(binds = UART0, resources = [shared])] + fn uart0(cx: uart0::Context) { + let shared: &mut u32 = cx.resources.shared; + *shared += 1; + + hprintln!("UART0: shared = {}", shared).unwrap(); + } + + // `shared` can be accessed from this context + #[task(binds = UART1, resources = [shared])] + fn uart1(cx: uart1::Context) { + *cx.resources.shared += 1; + + hprintln!("UART1: shared = {}", cx.resources.shared).unwrap(); + } +} diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index e45f1a3..f97f841 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -123,6 +123,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let const_app_schedule = schedule::codegen(app, extra); let user_imports = app.user_imports.clone(); + let user_code = app.user_code.clone(); let name = &app.name; let device = extra.device; quote!( @@ -148,6 +149,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#imports)* #(#user_imports)* + /// User code from within the module + #(#user_code)* + /// User code end + + #(#user_hardware_tasks_imports)* #(#user_software_tasks_imports)* diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 2a439e1..94e7eec 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -35,7 +35,8 @@ mod tests; /// /// The items allowed in the module block are specified below: /// -/// # 1. `struct Resources` +/// # 1. `#[resources] +/// struct ` /// /// 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 -- cgit v1.2.3 From 4b40ff00b6c91bc10a4e32bf19449da0ecb0e14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 4 Jun 2020 16:06:18 +0000 Subject: Workaround lint for now --- examples/resource-user-struct.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/resource-user-struct.rs b/examples/resource-user-struct.rs index 132aa34..dbda9a3 100644 --- a/examples/resource-user-struct.rs +++ b/examples/resource-user-struct.rs @@ -19,6 +19,7 @@ mod app { } // Should not collide with the struct above + #[allow(dead_code)] struct Resources2 { // A resource shared: u32, -- cgit v1.2.3 From 506e411be6b325b75e9de58c9b21b11032a7c3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 4 Jun 2020 16:56:13 +0000 Subject: Update run-pass tests for stable --- ui/single/locals-cfg.stderr | 8 +++--- ui/single/resources-cfg.stderr | 60 +++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index 7637159..145e7fd 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -31,11 +31,11 @@ error[E0425]: cannot find value `FOO` in this scope error: duplicate lang item in crate `panic_halt`: `panic_impl`. | = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) - = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib - = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta + = note: first definition in `std` loaded from /home/henrik/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib + = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/debug/deps/libpanic_halt-b597cb793434f3ed.rmeta error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. | = note: the lang item is first defined in crate `panic_halt`. - = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta - = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_semihosting-805015f4a2d05965.rmeta + = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/debug/deps/libpanic_halt-b597cb793434f3ed.rmeta + = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/debug/deps/libpanic_semihosting-2c8f1ababc34800c.rmeta diff --git a/ui/single/resources-cfg.stderr b/ui/single/resources-cfg.stderr index c47b95d..f1518a4 100644 --- a/ui/single/resources-cfg.stderr +++ b/ui/single/resources-cfg.stderr @@ -1,119 +1,119 @@ error[E0609]: no field `o1` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:45:21 + --> $DIR/resources-cfg.rs:46:21 | -45 | c.resources.o1; +46 | c.resources.o1; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o4` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:46:21 + --> $DIR/resources-cfg.rs:47:21 | -46 | c.resources.o4; +47 | c.resources.o4; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o5` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:47:21 + --> $DIR/resources-cfg.rs:48:21 | -47 | c.resources.o5; +48 | c.resources.o5; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o6` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:48:21 + --> $DIR/resources-cfg.rs:49:21 | -48 | c.resources.o6; +49 | c.resources.o6; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s3` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:49:21 + --> $DIR/resources-cfg.rs:50:21 | -49 | c.resources.s3; +50 | c.resources.s3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o2` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:54:21 + --> $DIR/resources-cfg.rs:55:21 | -54 | c.resources.o2; +55 | c.resources.o2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o4` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:55:21 + --> $DIR/resources-cfg.rs:56:21 | -55 | c.resources.o4; +56 | c.resources.o4; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s1` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:56:21 + --> $DIR/resources-cfg.rs:57:21 | -56 | c.resources.s1; +57 | c.resources.s1; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s3` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:57:21 + --> $DIR/resources-cfg.rs:58:21 | -57 | c.resources.s3; +58 | c.resources.s3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o3` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:64:21 + --> $DIR/resources-cfg.rs:65:21 | -64 | c.resources.o3; +65 | c.resources.o3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s1` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:65:21 + --> $DIR/resources-cfg.rs:66:21 | -65 | c.resources.s1; +66 | c.resources.s1; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s2` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:66:21 + --> $DIR/resources-cfg.rs:67:21 | -66 | c.resources.s2; +67 | c.resources.s2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s3` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:67:21 + --> $DIR/resources-cfg.rs:68:21 | -67 | c.resources.s3; +68 | c.resources.s3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s2` on type `uart1Resources<'_>` - --> $DIR/resources-cfg.rs:72:21 + --> $DIR/resources-cfg.rs:73:21 | -72 | c.resources.s2; +73 | c.resources.s2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o5` on type `uart1Resources<'_>` - --> $DIR/resources-cfg.rs:73:21 + --> $DIR/resources-cfg.rs:74:21 | -73 | c.resources.o5; +74 | c.resources.o5; | ^^ unknown field | = note: available fields are: `__marker__` -- cgit v1.2.3 From 3ab2c049c5a4338dac19b7fdb522f3612c69c746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 4 Jun 2020 17:05:25 +0000 Subject: Remove stale comment --- macros/src/codegen.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index f97f841..26d7dc2 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -142,7 +142,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#root_software_tasks)* /// Implementation details - // the user can't access the items within this `const` item mod #name { /// Always include the device crate which contains the vector table use #device as _; -- cgit v1.2.3 From 19b35d7aad36fe329976274b8c6ffd5591826ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 8 Jun 2020 07:42:19 +0000 Subject: Pool example need to import things into the mod --- examples/pool.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/pool.rs b/examples/pool.rs index c87be77..27408d5 100644 --- a/examples/pool.rs +++ b/examples/pool.rs @@ -20,7 +20,9 @@ pool!(P: [u8; 128]); #[app(device = lm3s6965)] mod app { use crate::Box; - use crate::P; + + // Import the memory pool into scope + use super::P; #[init] fn init(_: init::Context) { -- cgit v1.2.3 From d7bd8c838a5c4e1ae6d28fa60e5e5969acbe1db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 8 Jun 2020 08:06:09 +0000 Subject: Import panic_halt so semihosting is not attempted ARMv6 would otherwise differ in output compared to ARMv7 --- ui/single/locals-cfg.rs | 1 + ui/single/locals-cfg.stderr | 24 +++++++-------- ui/single/resources-cfg.rs | 1 + ui/single/resources-cfg.stderr | 66 +++++++++++++++++++++++------------------- 4 files changed, 50 insertions(+), 42 deletions(-) diff --git a/ui/single/locals-cfg.rs b/ui/single/locals-cfg.rs index 7ec46ac..e04e5b9 100644 --- a/ui/single/locals-cfg.rs +++ b/ui/single/locals-cfg.rs @@ -1,4 +1,5 @@ #![no_main] +use panic_halt as _; #[rtic::app(device = lm3s6965)] mod app { diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index 145e7fd..c26a334 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -1,34 +1,34 @@ error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:10:9 + --> $DIR/locals-cfg.rs:11:9 | -10 | FOO; +11 | FOO; | ^^^ not found in this scope error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:18:9 + --> $DIR/locals-cfg.rs:19:9 | -18 | FOO; +19 | FOO; | ^^^ not found in this scope error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:28:9 + --> $DIR/locals-cfg.rs:29:9 | -28 | FOO; +29 | FOO; | ^^^ not found in this scope error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:36:9 + --> $DIR/locals-cfg.rs:37:9 | -36 | FOO; +37 | FOO; | ^^^ not found in this scope error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:44:9 + --> $DIR/locals-cfg.rs:45:9 | -44 | FOO; +45 | FOO; | ^^^ not found in this scope -error: duplicate lang item in crate `panic_halt`: `panic_impl`. +error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `panic_impl`. | = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) = note: first definition in `std` loaded from /home/henrik/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib @@ -36,6 +36,6 @@ error: duplicate lang item in crate `panic_halt`: `panic_impl`. error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. | - = note: the lang item is first defined in crate `panic_halt`. + = note: the lang item is first defined in crate `panic_halt` (which `$CRATE` depends on) = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/debug/deps/libpanic_halt-b597cb793434f3ed.rmeta = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/debug/deps/libpanic_semihosting-2c8f1ababc34800c.rmeta diff --git a/ui/single/resources-cfg.rs b/ui/single/resources-cfg.rs index 163927e..f2569e9 100644 --- a/ui/single/resources-cfg.rs +++ b/ui/single/resources-cfg.rs @@ -1,4 +1,5 @@ #![no_main] +use panic_halt as _; #[rtic::app(device = lm3s6965)] mod app { diff --git a/ui/single/resources-cfg.stderr b/ui/single/resources-cfg.stderr index f1518a4..530c782 100644 --- a/ui/single/resources-cfg.stderr +++ b/ui/single/resources-cfg.stderr @@ -1,119 +1,125 @@ +error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `panic_impl`. + | + = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) + = note: first definition in `std` loaded from /home/henrik/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib + = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/debug/deps/libpanic_halt-b597cb793434f3ed.rmeta + error[E0609]: no field `o1` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:46:21 + --> $DIR/resources-cfg.rs:47:21 | -46 | c.resources.o1; +47 | c.resources.o1; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o4` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:47:21 + --> $DIR/resources-cfg.rs:48:21 | -47 | c.resources.o4; +48 | c.resources.o4; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o5` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:48:21 + --> $DIR/resources-cfg.rs:49:21 | -48 | c.resources.o5; +49 | c.resources.o5; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o6` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:49:21 + --> $DIR/resources-cfg.rs:50:21 | -49 | c.resources.o6; +50 | c.resources.o6; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s3` on type `initResources<'_>` - --> $DIR/resources-cfg.rs:50:21 + --> $DIR/resources-cfg.rs:51:21 | -50 | c.resources.s3; +51 | c.resources.s3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o2` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:55:21 + --> $DIR/resources-cfg.rs:56:21 | -55 | c.resources.o2; +56 | c.resources.o2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o4` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:56:21 + --> $DIR/resources-cfg.rs:57:21 | -56 | c.resources.o4; +57 | c.resources.o4; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s1` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:57:21 + --> $DIR/resources-cfg.rs:58:21 | -57 | c.resources.s1; +58 | c.resources.s1; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s3` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:58:21 + --> $DIR/resources-cfg.rs:59:21 | -58 | c.resources.s3; +59 | c.resources.s3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o3` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:65:21 + --> $DIR/resources-cfg.rs:66:21 | -65 | c.resources.o3; +66 | c.resources.o3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s1` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:66:21 + --> $DIR/resources-cfg.rs:67:21 | -66 | c.resources.s1; +67 | c.resources.s1; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s2` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:67:21 + --> $DIR/resources-cfg.rs:68:21 | -67 | c.resources.s2; +68 | c.resources.s2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s3` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:68:21 + --> $DIR/resources-cfg.rs:69:21 | -68 | c.resources.s3; +69 | c.resources.s3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s2` on type `uart1Resources<'_>` - --> $DIR/resources-cfg.rs:73:21 + --> $DIR/resources-cfg.rs:74:21 | -73 | c.resources.s2; +74 | c.resources.s2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o5` on type `uart1Resources<'_>` - --> $DIR/resources-cfg.rs:74:21 + --> $DIR/resources-cfg.rs:75:21 | -74 | c.resources.o5; +75 | c.resources.o5; | ^^ unknown field | = note: available fields are: `__marker__` -- cgit v1.2.3 From fa4dcdd6e19a0e24eacb442436813caaaa433c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 29 Sep 2020 11:56:11 +0000 Subject: Annotate the resource struct --- examples/double_schedule.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/double_schedule.rs b/examples/double_schedule.rs index 837f0d6..b1b78b8 100644 --- a/examples/double_schedule.rs +++ b/examples/double_schedule.rs @@ -11,6 +11,7 @@ use rtic::cyccnt::U32Ext; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] mod app { + #[resources] struct Resources { nothing: (), } -- cgit v1.2.3 From b4ec6f5eff212dee6aa1523653262980bc676c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 29 Sep 2020 12:01:36 +0000 Subject: Fix test output to match GHA runner --- ui/single/locals-cfg.stderr | 8 ++++---- ui/single/resources-cfg.stderr | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index c26a334..39d56df 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -31,11 +31,11 @@ error[E0425]: cannot find value `FOO` in this scope error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `panic_impl`. | = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) - = note: first definition in `std` loaded from /home/henrik/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib - = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/debug/deps/libpanic_halt-b597cb793434f3ed.rmeta + = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib + = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. | = note: the lang item is first defined in crate `panic_halt` (which `$CRATE` depends on) - = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/debug/deps/libpanic_halt-b597cb793434f3ed.rmeta - = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/debug/deps/libpanic_semihosting-2c8f1ababc34800c.rmeta + = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta + = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_semihosting-805015f4a2d05965.rmeta diff --git a/ui/single/resources-cfg.stderr b/ui/single/resources-cfg.stderr index 530c782..9c39e56 100644 --- a/ui/single/resources-cfg.stderr +++ b/ui/single/resources-cfg.stderr @@ -1,8 +1,8 @@ error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `panic_impl`. | = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) - = note: first definition in `std` loaded from /home/henrik/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib - = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/debug/deps/libpanic_halt-b597cb793434f3ed.rmeta + = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib + = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta error[E0609]: no field `o1` on type `initResources<'_>` --> $DIR/resources-cfg.rs:47:21 -- cgit v1.2.3 From 96e6350c0dfae37c3ea8032b4cc3113e37323ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 1 Oct 2020 16:17:15 +0000 Subject: Rename const_app to mod_app --- macros/src/codegen.rs | 50 ++++++++++++++++++------------------ macros/src/codegen/hardware_tasks.rs | 10 ++++---- macros/src/codegen/idle.rs | 14 +++------- macros/src/codegen/init.rs | 14 +++------- macros/src/codegen/resources.rs | 10 ++++---- macros/src/codegen/software_tasks.rs | 18 ++++++------- 6 files changed, 52 insertions(+), 64 deletions(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 26d7dc2..f230d39 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -25,8 +25,8 @@ mod util; // TODO document the syntax here or in `rtic-syntax` pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { - let mut const_app = vec![]; - let mut const_app_imports = vec![]; + let mut mod_app = vec![]; + let mut mod_app_imports = vec![]; let mut mains = vec![]; let mut root = vec![]; let mut user = vec![]; @@ -37,21 +37,21 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let pre_init_stmts = pre_init::codegen(&app, analysis, extra); - let (const_app_init, root_init, user_init, user_init_imports, call_init) = + let (mod_app_init, root_init, user_init, user_init_imports, call_init) = init::codegen(app, analysis, extra); let post_init_stmts = post_init::codegen(&app, analysis); - let (const_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = + let (mod_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = idle::codegen(app, analysis, extra); if user_init.is_some() { - const_app_imports.push(quote!( + mod_app_imports.push(quote!( use super::init; )) } if user_idle.is_some() { - const_app_imports.push(quote!( + mod_app_imports.push(quote!( use super::idle; )) } @@ -73,10 +73,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#root_idle)* )); - const_app.push(quote!( - #const_app_init + mod_app.push(quote!( + #mod_app_init - #const_app_idle + #mod_app_idle )); let main = util::suffixed("main"); @@ -97,30 +97,30 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } )); - let (const_app_resources, mod_resources, mod_resources_imports) = + let (mod_app_resources, mod_resources, mod_resources_imports) = resources::codegen(app, analysis, extra); let ( - const_app_hardware_tasks, + mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, user_hardware_tasks_imports, ) = hardware_tasks::codegen(app, analysis, extra); let ( - const_app_software_tasks, + mod_app_software_tasks, root_software_tasks, user_software_tasks, user_software_tasks_imports, ) = software_tasks::codegen(app, analysis, extra); - let const_app_dispatchers = dispatchers::codegen(app, analysis, extra); + let mod_app_dispatchers = dispatchers::codegen(app, analysis, extra); - let const_app_spawn = spawn::codegen(app, analysis, extra); + let mod_app_spawn = spawn::codegen(app, analysis, extra); - let const_app_timer_queue = timer_queue::codegen(app, analysis, extra); + let mod_app_timer_queue = timer_queue::codegen(app, analysis, extra); - let const_app_schedule = schedule::codegen(app, extra); + let mod_app_schedule = schedule::codegen(app, extra); let user_imports = app.user_imports.clone(); let user_code = app.user_code.clone(); @@ -159,22 +159,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#mod_resources_imports)* - /// Const app - #(#const_app)* + /// app module + #(#mod_app)* - #(#const_app_resources)* + #(#mod_app_resources)* - #(#const_app_hardware_tasks)* + #(#mod_app_hardware_tasks)* - #(#const_app_software_tasks)* + #(#mod_app_software_tasks)* - #(#const_app_dispatchers)* + #(#mod_app_dispatchers)* - #(#const_app_spawn)* + #(#mod_app_spawn)* - #(#const_app_timer_queue)* + #(#mod_app_timer_queue)* - #(#const_app_schedule)* + #(#mod_app_schedule)* #(#mains)* } diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index a03fd77..25f1df4 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -14,7 +14,7 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors + // mod_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors Vec, // root_hardware_tasks -- items that must be placed in the root of the crate: // - `${task}Locals` structs @@ -26,7 +26,7 @@ pub fn codegen( // user_hardware_tasks_imports -- the imports for `#[task]` functions written by the user Vec, ) { - let mut const_app = vec![]; + let mut mod_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; let mut hardware_tasks_imports = vec![]; @@ -52,7 +52,7 @@ pub fn codegen( let symbol = task.args.binds.clone(); let priority = task.args.priority; - const_app.push(quote!( + mod_app.push(quote!( #[allow(non_snake_case)] #[no_mangle] unsafe fn #symbol() { @@ -90,7 +90,7 @@ pub fn codegen( root.push(item); - const_app.push(constructor); + mod_app.push(constructor); } root.push(module::codegen( @@ -130,5 +130,5 @@ pub fn codegen( )); } - (const_app, root, user_tasks, hardware_tasks_imports) + (mod_app, root, user_tasks, hardware_tasks_imports) } diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs index 2aa9975..2e2932d 100644 --- a/macros/src/codegen/idle.rs +++ b/macros/src/codegen/idle.rs @@ -14,7 +14,7 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app_idle -- the `${idle}Resources` constructor + // mod_app_idle -- the `${idle}Resources` constructor Option, // root_idle -- items that must be placed in the root of the crate: // - the `${idle}Locals` struct @@ -31,7 +31,7 @@ pub fn codegen( if app.idles.len() > 0 { let idle = &app.idles.first().unwrap(); let mut needs_lt = false; - let mut const_app = None; + let mut mod_app = None; let mut root_idle = vec![]; let mut locals_pat = None; let mut locals_new = None; @@ -45,7 +45,7 @@ pub fn codegen( resources_struct::codegen(Context::Idle, 0, &mut needs_lt, app, analysis); root_idle.push(item); - const_app = Some(constructor); + mod_app = Some(constructor); let name_resource = format_ident!("{}Resources", name); user_idle_imports.push(quote!( @@ -89,13 +89,7 @@ pub fn codegen( #name::Context::new(&rtic::export::Priority::new(0)) )); - ( - const_app, - root_idle, - user_idle, - user_idle_imports, - call_idle, - ) + (mod_app, root_idle, user_idle, user_idle_imports, call_idle) } else { ( None, diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index b350298..77d186e 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -14,7 +14,7 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app_idle -- the `${init}Resources` constructor + // mod_app_idle -- the `${init}Resources` constructor Option, // root_init -- items that must be placed in the root of the crate: // - the `${init}Locals` struct @@ -105,13 +105,13 @@ pub fn codegen( use super::#name; )); - let mut const_app = None; + let mut mod_app = None; if !init.args.resources.is_empty() { let (item, constructor) = resources_struct::codegen(Context::Init, 0, &mut needs_lt, app, analysis); root_init.push(item); - const_app = Some(constructor); + mod_app = Some(constructor); let name_late = format_ident!("{}Resources", name); user_init_imports.push(quote!( @@ -127,13 +127,7 @@ pub fn codegen( root_init.push(module::codegen(Context::Init, needs_lt, app, extra)); - ( - const_app, - root_init, - user_init, - user_init_imports, - call_init, - ) + (mod_app, root_init, user_init, user_init_imports, call_init) } else { (None, vec![], None, vec![], None) } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index d18a465..38ea524 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -10,14 +10,14 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app -- the `static [mut]` variables behind the proxies + // mod_app -- the `static [mut]` variables behind the proxies Vec, // mod_resources -- the `resources` module TokenStream2, // mod_resources_imports -- the `resources` module imports Vec, ) { - let mut const_app = vec![]; + let mut mod_app = vec![]; let mut mod_resources = vec![]; let mut mod_resources_imports = vec![]; @@ -42,7 +42,7 @@ pub fn codegen( }; let attrs = &res.attrs; - const_app.push(quote!( + mod_app.push(quote!( #[allow(non_upper_case_globals)] #(#attrs)* #(#cfgs)* @@ -91,7 +91,7 @@ pub fn codegen( use super::resources::#name; )); - const_app.push(util::impl_mutex( + mod_app.push(util::impl_mutex( extra, cfgs, true, @@ -118,5 +118,5 @@ pub fn codegen( }) }; - (const_app, mod_resources, mod_resources_imports) + (mod_app, mod_resources, mod_resources_imports) } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 9e01115..4ae37e4 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -13,7 +13,7 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app_software_tasks -- free queues, buffers and `${task}Resources` constructors + // mod_app_software_tasks -- free queues, buffers and `${task}Resources` constructors Vec, // root_software_tasks -- items that must be placed in the root of the crate: // - `${task}Locals` structs @@ -25,7 +25,7 @@ pub fn codegen( // user_software_tasks_imports -- the imports for `#[task]` functions written by the user Vec, ) { - let mut const_app = vec![]; + let mut mod_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; let mut software_tasks_imports = vec![]; @@ -51,7 +51,7 @@ pub fn codegen( Box::new(|| util::link_section_uninit(true)), ) }; - const_app.push(quote!( + mod_app.push(quote!( /// Queue version of a free-list that keeps track of empty slots in /// the following buffers static mut #fq: #fq_ty = #fq_expr; @@ -59,13 +59,13 @@ pub fn codegen( // Generate a resource proxy if needed if let Some(ceiling) = ceiling { - const_app.push(quote!( + mod_app.push(quote!( struct #fq<'a> { priority: &'a rtic::export::Priority, } )); - const_app.push(util::impl_mutex( + mod_app.push(util::impl_mutex( extra, &[], false, @@ -85,7 +85,7 @@ pub fn codegen( let instants = util::instants_ident(name); let uninit = mk_uninit(); - const_app.push(quote!( + mod_app.push(quote!( #uninit /// Buffer that holds the instants associated to the inputs of a task static mut #instants: @@ -96,7 +96,7 @@ pub fn codegen( let uninit = mk_uninit(); let inputs = util::inputs_ident(name); - const_app.push(quote!( + mod_app.push(quote!( #uninit /// Buffer that holds the inputs of a task static mut #inputs: [core::mem::MaybeUninit<#input_ty>; #cap_lit] = @@ -124,7 +124,7 @@ pub fn codegen( root.push(item); - const_app.push(constructor); + mod_app.push(constructor); } // `${task}Locals` @@ -165,5 +165,5 @@ pub fn codegen( )); } - (const_app, root, user_tasks, software_tasks_imports) + (mod_app, root, user_tasks, software_tasks_imports) } -- cgit v1.2.3 From 163edd7579222560caf6598cf8071f4201c277c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 1 Oct 2020 16:59:27 +0000 Subject: Start updating the book --- book/en/src/by-example/app.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/book/en/src/by-example/app.md b/book/en/src/by-example/app.md index 9a073ac..4262391 100644 --- a/book/en/src/by-example/app.md +++ b/book/en/src/by-example/app.md @@ -7,7 +7,7 @@ This is the smallest possible RTIC application: ``` All RTIC applications use the [`app`] attribute (`#[app(..)]`). This attribute -must be applied to a `const` item that contains items. The `app` attribute has +must be applied to a `mod`-item. The `app` attribute has a mandatory `device` argument that takes a *path* as a value. This path must point to a *peripheral access crate* (PAC) generated using [`svd2rust`] **v0.14.x** or newer. The `app` attribute will expand into a suitable entry @@ -17,16 +17,9 @@ point so it's not required to use the [`cortex_m_rt::entry`] attribute. [`svd2rust`]: https://crates.io/crates/svd2rust [`cortex_m_rt::entry`]: ../../../api/cortex_m_rt_macros/attr.entry.html -> **ASIDE**: Some of you may be wondering why we are using a `const` item as a -> module and not a proper `mod` item. The reason is that using attributes on -> modules requires a feature gate, which requires a nightly toolchain. To make -> RTIC work on stable we use the `const` item instead. When more parts of macros -> 1.2 are stabilized we'll move from a `const` item to a `mod` item and -> eventually to a crate level attribute (`#![app]`). - ## `init` -Within the pseudo-module the `app` attribute expects to find an initialization +Within the `app` module the attribute expects to find an initialization function marked with the `init` attribute. This function must have signature `fn(init::Context) [-> init::LateResources]` (the return type is not always required). @@ -60,7 +53,7 @@ $ cargo run --example init ## `idle` A function marked with the `idle` attribute can optionally appear in the -pseudo-module. This function is used as the special *idle task* and must have +module. This function is used as the special *idle task* and must have signature `fn(idle::Context) - > !`. When present, the runtime will execute the `idle` task after `init`. Unlike -- cgit v1.2.3 From fb61a78cdd99e27914cc355f721c04d901dd3ae4 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 1 Oct 2020 20:01:25 +0200 Subject: Added `bare_metal::CriticalSection` to `init::Context` --- Cargo.toml | 1 + macros/src/codegen/module.rs | 8 ++++++++ src/export.rs | 1 + 3 files changed, 10 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index d4ad4ef..6fe5fce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,7 @@ cortex-m-rtic-macros = { path = "macros", version = "0.5.2" } rtic-core = "0.3.0" cortex-m-rt = "0.6.9" heapless = "0.5.0" +bare-metal = "1.0.0" [build-dependencies] version_check = "0.9" diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 863f6c5..359c1cc 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -47,6 +47,14 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) -> values.push(quote!(device: #device::Peripherals::steal())); } + lt = Some(quote!('a)); + fields.push(quote!( + /// Critical section token for init + pub cs: rtic::export::CriticalSection<#lt> + )); + + values.push(quote!(cs: rtic::export::CriticalSection::new())); + values.push(quote!(core)); } diff --git a/src/export.rs b/src/export.rs index 8a5d4e3..1e64941 100644 --- a/src/export.rs +++ b/src/export.rs @@ -4,6 +4,7 @@ use core::{ }; pub use crate::tq::{NotReady, TimerQueue}; +pub use bare_metal::CriticalSection; #[cfg(armv7m)] pub use cortex_m::register::basepri; pub use cortex_m::{ -- cgit v1.2.3 From 86001c46bcae85c9448d63dde534bd218301f0e4 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 1 Oct 2020 20:16:00 +0200 Subject: Fixing test errors --- ui/single/locals-cfg.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index bb558fa..49695cb 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -28,10 +28,10 @@ error[E0425]: cannot find value `FOO` in this scope 44 | FOO; | ^^^ not found in this scope -error: duplicate lang item in crate `panic_halt`: `panic_impl`. +error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. | = note: first defined in crate `std`. -error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. +error: duplicate lang item in crate `panic_halt`: `panic_impl`. | - = note: first defined in crate `panic_halt`. + = note: first defined in crate `panic_semihosting`. -- cgit v1.2.3 From 0cc556a75aaee64a90ecab94854b3fc669cb61ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 1 Oct 2020 19:12:54 +0000 Subject: Remove all of heterogeneous and homogeneous from the book --- book/en/src/SUMMARY.md | 2 -- book/en/src/heterogeneous.md | 6 ------ book/en/src/homogeneous.md | 6 ------ 3 files changed, 14 deletions(-) delete mode 100644 book/en/src/heterogeneous.md delete mode 100644 book/en/src/homogeneous.md diff --git a/book/en/src/SUMMARY.md b/book/en/src/SUMMARY.md index 25aef81..a573cbb 100644 --- a/book/en/src/SUMMARY.md +++ b/book/en/src/SUMMARY.md @@ -21,5 +21,3 @@ - [Ceiling analysis](./internals/ceilings.md) - [Software tasks](./internals/tasks.md) - [Timer queue](./internals/timer-queue.md) -- [Homogeneous multi-core support](./homogeneous.md) -- [Heterogeneous multi-core support](./heterogeneous.md) diff --git a/book/en/src/heterogeneous.md b/book/en/src/heterogeneous.md deleted file mode 100644 index d2c3d6c..0000000 --- a/book/en/src/heterogeneous.md +++ /dev/null @@ -1,6 +0,0 @@ -# Heterogeneous multi-core support - -This section covers the *experimental* heterogeneous multi-core support provided -by RTIC behind the `heterogeneous` Cargo feature. - -**Content coming soon** diff --git a/book/en/src/homogeneous.md b/book/en/src/homogeneous.md deleted file mode 100644 index bcf6d2b..0000000 --- a/book/en/src/homogeneous.md +++ /dev/null @@ -1,6 +0,0 @@ -# Homogeneous multi-core support - -This section covers the *experimental* homogeneous multi-core support provided -by RTIC behind the `homogeneous` Cargo feature. - -**Content coming soon** -- cgit v1.2.3 From 5082f70e5e2d021d16632f6e2c07608f6bd8fc29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 1 Oct 2020 19:13:22 +0000 Subject: Remove exports related to heterogeneous multi-core support --- src/export.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/export.rs b/src/export.rs index 1e64941..27f7f5f 100644 --- a/src/export.rs +++ b/src/export.rs @@ -16,8 +16,6 @@ pub use cortex_m::{ use heapless::spsc::SingleCore; pub use heapless::{consts, i::Queue as iQueue, spsc::Queue}; pub use heapless::{i::BinaryHeap as iBinaryHeap, BinaryHeap}; -#[cfg(feature = "heterogeneous")] -pub use microamp::shared; pub type SCFQ = Queue; pub type SCRQ = Queue<(T, u8), N, u8, SingleCore>; -- cgit v1.2.3 From 9ca10b0d8c735a06a3a0a3623a7fc5d09b5e948c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 2 Oct 2020 09:33:28 +0000 Subject: Add migration to 0.6 along with updated documentation --- book/en/src/by-example.md | 2 +- book/en/src/by-example/resources.md | 4 +- book/en/src/by-example/tasks.md | 4 +- book/en/src/by-example/tips.md | 4 +- book/en/src/by-example/types-send-sync.md | 2 +- book/en/src/internals/access.md | 12 ++-- book/en/src/internals/ceilings.md | 4 +- book/en/src/internals/critical-sections.md | 24 +++---- book/en/src/internals/interrupt-configuration.md | 4 +- book/en/src/internals/late-resources.md | 8 +-- book/en/src/internals/non-reentrancy.md | 8 +-- book/en/src/internals/tasks.md | 24 +++---- book/en/src/internals/timer-queue.md | 28 ++++---- book/en/src/migration.md | 85 +++++++++++++++++++++--- 14 files changed, 140 insertions(+), 73 deletions(-) diff --git a/book/en/src/by-example.md b/book/en/src/by-example.md index d452722..38985da 100644 --- a/book/en/src/by-example.md +++ b/book/en/src/by-example.md @@ -9,7 +9,7 @@ is required to follow along. [repository]: https://github.com/rtic-rs/cortex-m-rtic -To run the examples on your laptop / PC you'll need the `qemu-system-arm` +To run the examples on your computer you'll need the `qemu-system-arm` program. Check [the embedded Rust book] for instructions on how to set up an embedded development environment that includes QEMU. diff --git a/book/en/src/by-example/resources.md b/book/en/src/by-example/resources.md index b9e92d1..d63d135 100644 --- a/book/en/src/by-example/resources.md +++ b/book/en/src/by-example/resources.md @@ -4,11 +4,11 @@ The framework provides an abstraction to share data between any of the contexts we saw in the previous section (task handlers, `init` and `idle`): resources. Resources are data visible only to functions declared within the `#[app]` -pseudo-module. The framework gives the user complete control over which context +module. The framework gives the user complete control over which context can access which resource. All resources are declared as a single `struct` within the `#[app]` -pseudo-module. Each field in the structure corresponds to a different resource. +module. Each field in the structure corresponds to a different resource. Resources can optionally be given an initial value using the `#[init]` attribute. Resources that are not given an initial value are referred to as *late* resources and are covered in more detail in a follow-up section in this diff --git a/book/en/src/by-example/tasks.md b/book/en/src/by-example/tasks.md index d0b5acb..9fefd02 100644 --- a/book/en/src/by-example/tasks.md +++ b/book/en/src/by-example/tasks.md @@ -92,7 +92,7 @@ following snippet: ``` rust #[rtic::app(..)] -const APP: () = { +mod app { #[init(spawn = [foo, bar])] fn init(cx: init::Context) { cx.spawn.foo().unwrap(); @@ -113,5 +113,5 @@ const APP: () = { fn bar(cx: bar::Context, payload: i32) { // .. } -}; +} ``` diff --git a/book/en/src/by-example/tips.md b/book/en/src/by-example/tips.md index b191b9d..0b6555e 100644 --- a/book/en/src/by-example/tips.md +++ b/book/en/src/by-example/tips.md @@ -139,7 +139,7 @@ $ tail target/rtic-expansion.rs ``` rust #[doc = r" Implementation details"] -const APP: () = { +mod app { #[doc = r" Always include the device crate which contains the vector table"] use lm3s6965 as _; #[no_mangle] @@ -152,7 +152,7 @@ const APP: () = { rtic::export::wfi() } } -}; +} ``` Or, you can use the [`cargo-expand`] sub-command. This sub-command will expand diff --git a/book/en/src/by-example/types-send-sync.md b/book/en/src/by-example/types-send-sync.md index 41cd9ba..9cdb889 100644 --- a/book/en/src/by-example/types-send-sync.md +++ b/book/en/src/by-example/types-send-sync.md @@ -1,6 +1,6 @@ # Types, Send and Sync -Every function within the `APP` pseudo-module has a `Context` structure as its +Every function within the `app` module has a `Context` structure as its first parameter. All the fields of these structures have predictable, non-anonymous types so you can write plain functions that take them as arguments. diff --git a/book/en/src/internals/access.md b/book/en/src/internals/access.md index 6433707..3894470 100644 --- a/book/en/src/internals/access.md +++ b/book/en/src/internals/access.md @@ -15,7 +15,7 @@ To achieve the fine-grained access control where tasks can only access the static variables (resources) that they have specified in their RTIC attribute the RTIC framework performs a source code level transformation. This transformation consists of placing the resources (static variables) specified by -the user *inside* a `const` item and the user code *outside* the `const` item. +the user *inside* a module and the user code *outside* the module. This makes it impossible for the user code to refer to these static variables. Access to the resources is then given to each task using a `Resources` struct @@ -29,7 +29,7 @@ happens behind the scenes: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { static mut X: u64: 0; static mut Y: bool: 0; @@ -49,7 +49,7 @@ const APP: () = { } // .. -}; +} ``` The framework produces codes like this: @@ -103,8 +103,8 @@ pub mod bar { } /// Implementation details -const APP: () = { - // everything inside this `const` item is hidden from user code +mod app { + // everything inside this module is hidden from user code static mut X: u64 = 0; static mut Y: bool = 0; @@ -154,5 +154,5 @@ const APP: () = { // .. }); } -}; +} ``` diff --git a/book/en/src/internals/ceilings.md b/book/en/src/internals/ceilings.md index 49d248a..07bd0ad 100644 --- a/book/en/src/internals/ceilings.md +++ b/book/en/src/internals/ceilings.md @@ -28,7 +28,7 @@ An example to illustrate the ceiling analysis: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { struct Resources { // accessed by `foo` (prio = 1) and `bar` (prio = 2) // -> CEILING = 2 @@ -80,5 +80,5 @@ const APP: () = { } // .. -}; +} ``` diff --git a/book/en/src/internals/critical-sections.md b/book/en/src/internals/critical-sections.md index f95a5a7..a064ad0 100644 --- a/book/en/src/internals/critical-sections.md +++ b/book/en/src/internals/critical-sections.md @@ -32,7 +32,7 @@ The example below shows the different types handed out to each task: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mut app { struct Resources { #[init(0)] x: u64, @@ -57,7 +57,7 @@ const APP: () = { } // .. -}; +} ``` Now let's see how these types are created by the framework. @@ -99,7 +99,7 @@ pub mod bar { } } -const APP: () = { +mod app { static mut x: u64 = 0; impl rtic::Mutex for resources::x { @@ -129,7 +129,7 @@ const APP: () = { // .. }) } -}; +} ``` ## `lock` @@ -225,7 +225,7 @@ Consider this program: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { struct Resources { #[init(0)] x: u64, @@ -277,7 +277,7 @@ const APP: () = { } // .. -}; +} ``` The code generated by the framework looks like this: @@ -315,7 +315,7 @@ pub mod foo { } } -const APP: () = { +mod app { use cortex_m::register::basepri; #[no_mangle] @@ -368,7 +368,7 @@ const APP: () = { } // repeat for resource `y` -}; +} ``` At the end the compiler will optimize the function `foo` into something like @@ -430,7 +430,7 @@ handler through preemption. This is best observed in the following example: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { struct Resources { #[init(0)] x: u64, @@ -484,7 +484,7 @@ const APP: () = { // .. } -}; +} ``` IMPORTANT: let's say we *forget* to roll back `BASEPRI` in `UART1` -- this would @@ -493,7 +493,7 @@ be a bug in the RTIC code generator. ``` rust // code generated by RTIC -const APP: () = { +mod app { // .. #[no_mangle] @@ -513,7 +513,7 @@ const APP: () = { // BUG: FORGOT to roll back the BASEPRI to the snapshot value we took before basepri::write(initial); } -}; +} ``` The consequence is that `idle` will run at a dynamic priority of `2` and in fact diff --git a/book/en/src/internals/interrupt-configuration.md b/book/en/src/internals/interrupt-configuration.md index 278707c..7aec9c9 100644 --- a/book/en/src/internals/interrupt-configuration.md +++ b/book/en/src/internals/interrupt-configuration.md @@ -13,7 +13,7 @@ This example gives you an idea of the code that the RTIC framework runs: ``` rust #[rtic::app(device = lm3s6965)] -const APP: () = { +mod app { #[init] fn init(c: init::Context) { // .. user code .. @@ -28,7 +28,7 @@ const APP: () = { fn foo(c: foo::Context) { // .. user code .. } -}; +} ``` The framework generates an entry point that looks like this: diff --git a/book/en/src/internals/late-resources.md b/book/en/src/internals/late-resources.md index ad2a5e5..f3a0b0a 100644 --- a/book/en/src/internals/late-resources.md +++ b/book/en/src/internals/late-resources.md @@ -10,7 +10,7 @@ initialize late resources. ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { struct Resources { x: Thing, } @@ -34,7 +34,7 @@ const APP: () = { } // .. -}; +} ``` The code generated by the framework looks like this: @@ -69,7 +69,7 @@ pub mod foo { } /// Implementation details -const APP: () = { +mod app { // uninitialized static static mut x: MaybeUninit = MaybeUninit::uninit(); @@ -101,7 +101,7 @@ const APP: () = { // .. }) } -}; +} ``` An important detail here is that `interrupt::enable` behaves like a *compiler diff --git a/book/en/src/internals/non-reentrancy.md b/book/en/src/internals/non-reentrancy.md index 0b0e4a7..17b34d0 100644 --- a/book/en/src/internals/non-reentrancy.md +++ b/book/en/src/internals/non-reentrancy.md @@ -12,7 +12,7 @@ are discouraged from directly invoking an interrupt handler. ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { #[init] fn init(c: init::Context) { .. } @@ -39,7 +39,7 @@ const APP: () = { // in aliasing of the static variable `X` unsafe { UART0() } } -}; +} ``` The RTIC framework must generate the interrupt handler code that calls the user @@ -57,7 +57,7 @@ fn bar(c: bar::Context) { // .. user code .. } -const APP: () = { +mod app { // everything in this block is not visible to user code #[no_mangle] @@ -69,7 +69,7 @@ const APP: () = { unsafe fn USART1() { bar(..); } -}; +} ``` ## By hardware diff --git a/book/en/src/internals/tasks.md b/book/en/src/internals/tasks.md index 995a885..a533dc0 100644 --- a/book/en/src/internals/tasks.md +++ b/book/en/src/internals/tasks.md @@ -28,7 +28,7 @@ Consider this example: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { // .. #[interrupt(binds = UART0, priority = 2, spawn = [bar, baz])] @@ -51,7 +51,7 @@ const APP: () = { extern "C" { fn UART1(); } -}; +} ``` The framework produces the following task dispatcher which consists of an @@ -62,7 +62,7 @@ fn bar(c: bar::Context) { // .. user code .. } -const APP: () = { +mod app { use heapless::spsc::Queue; use cortex_m::register::basepri; @@ -110,7 +110,7 @@ const APP: () = { // BASEPRI invariant basepri::write(snapshot); } -}; +} ``` ## Spawning a task @@ -144,7 +144,7 @@ mod foo { } } -const APP: () = { +mod app { // .. // Priority ceiling for the producer endpoint of the `RQ1` @@ -194,7 +194,7 @@ const APP: () = { } } } -}; +} ``` Using `bar_FQ` to limit the number of `bar` tasks that can be spawned may seem @@ -211,7 +211,7 @@ fn baz(c: baz::Context, input: u64) { // .. user code .. } -const APP: () = { +mod app { // .. // Now we show the full contents of the `Ready` struct @@ -263,13 +263,13 @@ const APP: () = { } } } -}; +} ``` And now let's look at the real implementation of the task dispatcher: ``` rust -const APP: () = { +mod app { // .. #[no_mangle] @@ -304,7 +304,7 @@ const APP: () = { // BASEPRI invariant basepri::write(snapshot); } -}; +} ``` `INPUTS` plus `FQ`, the free queue, is effectively a memory pool. However, @@ -357,7 +357,7 @@ Consider the following example: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { #[idle(spawn = [foo, bar])] fn idle(c: idle::Context) -> ! { // .. @@ -382,7 +382,7 @@ const APP: () = { fn quux(c: quux::Context) { // .. } -}; +} ``` This is how the ceiling analysis would go: diff --git a/book/en/src/internals/timer-queue.md b/book/en/src/internals/timer-queue.md index 0eba106..fcd345c 100644 --- a/book/en/src/internals/timer-queue.md +++ b/book/en/src/internals/timer-queue.md @@ -12,7 +12,7 @@ Let's see how this in implemented in code. Consider the following program: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { // .. #[task(capacity = 2, schedule = [foo])] @@ -24,7 +24,7 @@ const APP: () = { extern "C" { fn UART0(); } -}; +} ``` ## `schedule` @@ -46,7 +46,7 @@ mod foo { } } -const APP: () = { +mod app { type Instant = ::Instant; // all tasks that can be `schedule`-d @@ -100,7 +100,7 @@ const APP: () = { } } } -}; +} ``` This looks very similar to the `Spawn` implementation. In fact, the same @@ -123,7 +123,7 @@ is up. Let's see the associated code. ``` rust -const APP: () = { +mod app { #[no_mangle] fn SysTick() { const PRIORITY: u8 = 1; @@ -146,7 +146,7 @@ const APP: () = { } } } -}; +} ``` This looks similar to a task dispatcher except that instead of running the @@ -197,7 +197,7 @@ able to insert the task in the timer queue; this lets us omit runtime checks. ## System timer priority -The priority of the system timer can't set by the user; it is chosen by the +The priority of the system timer can't be set by the user; it is chosen by the framework. To ensure that lower priority tasks don't prevent higher priority tasks from running we choose the priority of the system timer to be the maximum of all the `schedule`-able tasks. @@ -222,7 +222,7 @@ To illustrate, consider the following example: ``` rust #[rtic::app(device = ..)] -const APP: () = { +mod app { #[task(priority = 3, spawn = [baz])] fn foo(c: foo::Context) { // .. @@ -237,7 +237,7 @@ const APP: () = { fn baz(c: baz::Context) { // .. } -}; +} ``` The ceiling analysis would go like this: @@ -246,7 +246,7 @@ The ceiling analysis would go like this: `SysTick` must run at the highest priority between these two, that is `3`. - `foo::Spawn` (prio = 3) and `bar::Schedule` (prio = 2) contend over the - consumer endpoind of `baz_FQ`; this leads to a priority ceiling of `3`. + consumer endpoint of `baz_FQ`; this leads to a priority ceiling of `3`. - `bar::Schedule` (prio = 2) has exclusive access over the consumer endpoint of `foo_FQ`; thus the priority ceiling of `foo_FQ` is effectively `2`. @@ -270,7 +270,7 @@ run; this `Instant` is read in the task dispatcher and passed to the user code as part of the task context. ``` rust -const APP: () = { +mod app { // .. #[no_mangle] @@ -303,7 +303,7 @@ const APP: () = { // BASEPRI invariant basepri::write(snapshot); } -}; +} ``` Conversely, the `spawn` implementation needs to write a value to the `INSTANTS` @@ -333,7 +333,7 @@ mod foo { } } -const APP: () = { +mod app { impl<'a> foo::Spawn<'a> { /// Spawns the `baz` task pub fn baz(&self, message: u64) -> Result<(), u64> { @@ -364,5 +364,5 @@ const APP: () = { } } } -}; +} ``` diff --git a/book/en/src/migration.md b/book/en/src/migration.md index 6cca64d..ab45c29 100644 --- a/book/en/src/migration.md +++ b/book/en/src/migration.md @@ -1,14 +1,81 @@ -# Migrating from v0.4.x to v0.5.0 +# Migration of RTIC + +## Migrating from v0.5.x to v0.6.0 + +This section describes how to upgrade from v0.5.x to v0.6.0 of the RTIC framework. + +### `Cargo.toml` - version bump + +Change the version of `cortex-m-rtic` to `"0.6.0"`. + +### Module instead of Const + +With the support of attributes on modules the `const APP` workaround is not needed. + +Change + +``` rust +#[rtic::app(/* .. */)] +const APP: () = { + [code here] +}; +``` + +into + +``` rust +#[rtic::app(/* .. */)] +mod app { + [code here] +} +``` + +Now that a regular Rust module is used it means it is possible to have custom +user code within that module. +Additionally, it means that `use`-statements for resources etc may be required. + +### Init always returns late resources + +In order to make the API more symmetric the #[init]-task always returns a late resource. + +From this: + +``` rust +#[rtic::app(device = lm3s6965)] +mod app { + #[init] + fn init(_: init::Context) { + rtic::pend(Interrupt::UART0); + } + [more code] +} +``` + +to this: + +``` rust +#[rtic::app(device = lm3s6965)] +mod app { + #[init] + fn init(_: init::Context) -> init::LateResources { + rtic::pend(Interrupt::UART0); + + init::LateResources {} + } + [more code] +} +``` + +## Migrating from v0.4.x to v0.5.0 This section covers how to upgrade an application written against RTIC v0.4.x to the version v0.5.0 of the framework. -## `Cargo.toml` +### `Cargo.toml` First, the version of the `cortex-m-rtic` dependency needs to be updated to `"0.5.0"`. The `timer-queue` feature needs to be removed. - ``` toml [dependencies.cortex-m-rtic] # change this @@ -22,7 +89,7 @@ features = ["timer-queue"] # ^^^^^^^^^^^^^ ``` -## `Context` argument +### `Context` argument All functions inside the `#[rtic::app]` item need to take as first argument a `Context` structure. This `Context` type will contain the variables that were @@ -74,7 +141,7 @@ const APP: () = { }; ``` -## Resources +### Resources The syntax used to declare resources has been changed from `static mut` variables to a `struct Resources`. @@ -98,7 +165,7 @@ const APP: () = { }; ``` -## Device peripherals +### Device peripherals If your application was accessing the device peripherals in `#[init]` through the `device` variable then you'll need to add `peripherals = true` to the @@ -136,7 +203,7 @@ const APP: () = { }; ``` -## `#[interrupt]` and `#[exception]` +### `#[interrupt]` and `#[exception]` The `#[interrupt]` and `#[exception]` attributes have been removed. To declare hardware tasks in v0.5.x use the `#[task]` attribute with the `binds` argument. @@ -182,7 +249,7 @@ const APP: () = { }; ``` -## `schedule` +### `schedule` The `timer-queue` feature has been removed. To use the `schedule` API one must first define the monotonic timer the runtime will use using the `monotonic` @@ -194,7 +261,7 @@ Also, the `Duration` and `Instant` types and the `U32Ext` trait have been moved into the `rtic::cyccnt` module. This module is only available on ARMv7-M+ devices. The removal of the `timer-queue` also brings back the `DWT` peripheral inside the core peripherals struct, this will need to be enabled by the application -inside `init`. +inside `init`. Change this: -- cgit v1.2.3 From baa2edfe72ec2e33a84dfebc6c4baf2c2b8d55c2 Mon Sep 17 00:00:00 2001 From: Daniel Carosone Date: Fri, 2 Oct 2020 19:38:00 +1000 Subject: close console text blocks on a new line fixes #369 --- book/en/src/by-example/app.md | 12 ++++++++---- book/en/src/by-example/new.md | 3 ++- book/en/src/by-example/resources.md | 12 ++++++++---- book/en/src/by-example/tasks.md | 9 ++++++--- book/en/src/by-example/tips.md | 12 ++++++++---- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/book/en/src/by-example/app.md b/book/en/src/by-example/app.md index 9a073ac..344cefc 100644 --- a/book/en/src/by-example/app.md +++ b/book/en/src/by-example/app.md @@ -55,7 +55,8 @@ process. ``` console $ cargo run --example init -{{#include ../../../../ci/expected/init.run}}``` +{{#include ../../../../ci/expected/init.run}} +``` ## `idle` @@ -86,7 +87,8 @@ in LLVM which miss-optimizes empty loops to a `UDF` instruction in release mode. ``` console $ cargo run --example idle -{{#include ../../../../ci/expected/idle.run}}``` +{{#include ../../../../ci/expected/idle.run}} +``` ## Hardware tasks @@ -107,7 +109,8 @@ mut` variables are safe to use within a hardware task. ``` console $ cargo run --example hardware -{{#include ../../../../ci/expected/hardware.run}}``` +{{#include ../../../../ci/expected/hardware.run}} +``` So far all the RTIC applications we have seen look no different than the applications one can write using only the `cortex-m-rt` crate. From this point @@ -139,7 +142,8 @@ The following example showcases the priority based scheduling of tasks. ``` console $ cargo run --example preempt -{{#include ../../../../ci/expected/preempt.run}}``` +{{#include ../../../../ci/expected/preempt.run}} +``` Note that the task `gpiob` does *not* preempt task `gpioc` because its priority is the *same* as `gpioc`'s. However, once `gpioc` terminates the execution of diff --git a/book/en/src/by-example/new.md b/book/en/src/by-example/new.md index abcc36d..866a9fa 100644 --- a/book/en/src/by-example/new.md +++ b/book/en/src/by-example/new.md @@ -63,4 +63,5 @@ $ cargo add panic-semihosting ``` console $ # NOTE: I have uncommented the `runner` option in `.cargo/config` $ cargo run -{{#include ../../../../ci/expected/init.run}}``` +{{#include ../../../../ci/expected/init.run}} +``` diff --git a/book/en/src/by-example/resources.md b/book/en/src/by-example/resources.md index b9e92d1..d67a72f 100644 --- a/book/en/src/by-example/resources.md +++ b/book/en/src/by-example/resources.md @@ -29,7 +29,8 @@ access to a resource named `shared`. ``` console $ cargo run --example resource -{{#include ../../../../ci/expected/resource.run}}``` +{{#include ../../../../ci/expected/resource.run}} +``` Note that the `shared` resource cannot be accessed from `idle`. Attempting to do so results in a compile error. @@ -71,7 +72,8 @@ lowest priority handler. ``` console $ cargo run --example lock -{{#include ../../../../ci/expected/lock.run}}``` +{{#include ../../../../ci/expected/lock.run}} +``` ## Late resources @@ -97,7 +99,8 @@ the consumer resource. ``` console $ cargo run --example late -{{#include ../../../../ci/expected/late.run}}``` +{{#include ../../../../ci/expected/late.run}} +``` ## Only shared access @@ -127,4 +130,5 @@ any kind of lock. ``` console $ cargo run --example only-shared-access -{{#include ../../../../ci/expected/only-shared-access.run}}``` +{{#include ../../../../ci/expected/only-shared-access.run}} +``` diff --git a/book/en/src/by-example/tasks.md b/book/en/src/by-example/tasks.md index d0b5acb..345e224 100644 --- a/book/en/src/by-example/tasks.md +++ b/book/en/src/by-example/tasks.md @@ -25,7 +25,8 @@ priorities. The three software tasks are mapped to 2 interrupts handlers. ``` console $ cargo run --example task -{{#include ../../../../ci/expected/task.run}}``` +{{#include ../../../../ci/expected/task.run}} +``` ## Message passing @@ -41,7 +42,8 @@ The example below showcases three tasks, two of them expect a message. ``` console $ cargo run --example message -{{#include ../../../../ci/expected/message.run}}``` +{{#include ../../../../ci/expected/message.run}} +``` ## Capacity @@ -63,7 +65,8 @@ fail (panic). ``` console $ cargo run --example capacity -{{#include ../../../../ci/expected/capacity.run}}``` +{{#include ../../../../ci/expected/capacity.run}} +``` ## Error handling diff --git a/book/en/src/by-example/tips.md b/book/en/src/by-example/tips.md index b191b9d..5a44708 100644 --- a/book/en/src/by-example/tips.md +++ b/book/en/src/by-example/tips.md @@ -24,7 +24,8 @@ Here's one such example: ``` console $ cargo run --example generics -{{#include ../../../../ci/expected/generics.run}}``` +{{#include ../../../../ci/expected/generics.run}} +``` Using generics also lets you change the static priorities of tasks during development without having to rewrite a bunch code every time. @@ -47,7 +48,8 @@ the program has been compiled using the `dev` profile. $ cargo run --example cfg --release $ cargo run --example cfg -{{#include ../../../../ci/expected/cfg.run}}``` +{{#include ../../../../ci/expected/cfg.run}} +``` ## Running tasks from RAM @@ -78,7 +80,8 @@ Running this program produces the expected output. ``` console $ cargo run --example ramfunc -{{#include ../../../../ci/expected/ramfunc.run}}``` +{{#include ../../../../ci/expected/ramfunc.run}} +``` One can look at the output of `cargo-nm` to confirm that `bar` ended in RAM (`0x2000_0000`), whereas `foo` ended in Flash (`0x0000_0000`). @@ -115,7 +118,8 @@ Here's an example where `heapless::Pool` is used to "box" buffers of 128 bytes. ``` ``` console $ cargo run --example pool -{{#include ../../../../ci/expected/pool.run}}``` +{{#include ../../../../ci/expected/pool.run}} +``` ## Inspecting the expanded code -- cgit v1.2.3 From e6bc673621093c72f932cc38043c9fa951745450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 2 Oct 2020 09:42:50 +0000 Subject: Clarify the need for resources-attribute --- book/en/src/by-example/resources.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/book/en/src/by-example/resources.md b/book/en/src/by-example/resources.md index d63d135..62efdc6 100644 --- a/book/en/src/by-example/resources.md +++ b/book/en/src/by-example/resources.md @@ -9,6 +9,8 @@ can access which resource. All resources are declared as a single `struct` within the `#[app]` module. Each field in the structure corresponds to a different resource. +The `struct` must be annotated with the following attribute: `#[resources]`. + Resources can optionally be given an initial value using the `#[init]` attribute. Resources that are not given an initial value are referred to as *late* resources and are covered in more detail in a follow-up section in this -- cgit v1.2.3 From 1482a251867bfb31708e8c7273db4bee1e67df36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 2 Oct 2020 09:55:25 +0000 Subject: Describe the resource struct attribute migration steps --- book/en/src/migration.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/book/en/src/migration.md b/book/en/src/migration.md index ab45c29..7be3094 100644 --- a/book/en/src/migration.md +++ b/book/en/src/migration.md @@ -66,6 +66,37 @@ mod app { } ``` +### Resources struct - #[resources] + +Previously the RTIC resources had to be in in a struct named exactly "Resources": + +``` rust +struct Resources { + // Resources defined in here +} +``` + +With RTIC v0.6.0 the resources struct is annotated similarly like +`#[task]`, `#[init]`, `#[idle]`: with an attribute `#[resources]` + +``` rust +#[resources] +struct Resources { + // Resources defined in here +} +``` + +In fact, the name of the struct is now up to the developer: + +``` rust +#[resources] +struct whateveryouwant { + // Resources defined in here +} +``` + +would work equally well. + ## Migrating from v0.4.x to v0.5.0 This section covers how to upgrade an application written against RTIC v0.4.x to -- cgit v1.2.3 From 65522e407778c38f86f4d3252b46fe54ed5909e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 2 Oct 2020 11:50:34 +0000 Subject: Update ui-test --- ui/single/locals-cfg.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index 1b46cea..39d56df 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -34,8 +34,8 @@ error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `p = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta -error: duplicate lang item in crate `panic_halt`: `panic_impl`. +error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. | = note: the lang item is first defined in crate `panic_halt` (which `$CRATE` depends on) = note: first definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta - = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_semihosting-805015f4a2d05965.rmeta \ No newline at end of file + = note: second definition in `panic_semihosting` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_semihosting-805015f4a2d05965.rmeta -- cgit v1.2.3 From 40c7119d7a3bf4dc7cd67be629cfe874d1c04851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 2 Oct 2020 12:36:34 +0000 Subject: Prepare the book for v0.6 --- book/en/src/preface.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/book/en/src/preface.md b/book/en/src/preface.md index 419f067..041b3bd 100644 --- a/book/en/src/preface.md +++ b/book/en/src/preface.md @@ -13,8 +13,10 @@ There is a translation of this book in [Russian]. [Russian]: ../ru/index.html -This is the documentation of v0.5.x of RTIC; for the documentation of version -v0.4.x go [here](/0.4). +This is the documentation of v0.6.x of RTIC; for the documentation of version + +* v0.5.x go [here](/0.5). +* v0.4.x go [here](/0.4). {{#include ../../../README.md:7:46}} -- cgit v1.2.3 From 6eff28bf50a4048f7ef897351c97996b3bbf8b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 2 Oct 2020 12:37:44 +0000 Subject: Remove leftover v1.36 hacks --- .github/workflows/build.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ed88c77..b1655f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -376,9 +376,6 @@ jobs: target: thumbv7m-none-eabi override: true - - name: Disable optimisation profiles - run: sed -i '/^\[profile.*build-override]$/,/^$/{/^#/!{/^$/!d}}' Cargo.toml - - uses: actions-rs/cargo@v1 with: use-cross: false @@ -420,9 +417,6 @@ jobs: target: thumbv6m-none-eabi override: true - - name: Disable optimisation profiles - run: sed -i '/^\[profile.*build-override]$/,/^$/{/^#/!{/^$/!d}}' Cargo.toml - - uses: actions-rs/cargo@v1 with: use-cross: false -- cgit v1.2.3 From f0f982facadab2da5d8cdaf214829a9e19f4249e Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sat, 3 Oct 2020 15:30:15 +0200 Subject: Updated documentation to include the critical section token in init --- book/en/src/by-example/app.md | 7 ++++--- examples/init.rs | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/book/en/src/by-example/app.md b/book/en/src/by-example/app.md index 344cefc..23bff68 100644 --- a/book/en/src/by-example/app.md +++ b/book/en/src/by-example/app.md @@ -33,15 +33,16 @@ required). This initialization function will be the first part of the application to run. The `init` function will run *with interrupts disabled* and has exclusive access -to Cortex-M and, optionally, device specific peripherals through the `core` and -`device` fields of `init::Context`. +to Cortex-M where the `bare_metal::CriticalSection` token is available as `cs`. +And optionally, device specific peripherals through the `core` and `device` fields +of `init::Context`. `static mut` variables declared at the beginning of `init` will be transformed into `&'static mut` references that are safe to access. [`rtic::Peripherals`]: ../../api/rtic/struct.Peripherals.html -The example below shows the types of the `core` and `device` fields and +The example below shows the types of the `core`, `device` and `cs` fields, and showcases safe access to a `static mut` variable. The `device` field is only available when the `peripherals` argument is set to `true` (it defaults to `false`). diff --git a/examples/init.rs b/examples/init.rs index 315969f..1623ca7 100644 --- a/examples/init.rs +++ b/examples/init.rs @@ -23,6 +23,10 @@ const APP: () = { // Safe access to local `static mut` variable let _x: &'static mut u32 = X; + // Access to the critical section token, + // to indicate that this is a critical seciton + let _cs_token: bare_metal::CriticalSection = cx.cs; + hprintln!("init").unwrap(); debug::exit(debug::EXIT_SUCCESS); -- cgit v1.2.3 From 3021048b779cb94dfe2f4422ea412d59d2eeb7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 5 Oct 2020 07:50:30 +0000 Subject: The stable book should build from branch --- .github/workflows/build.yml | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c687115..e6271c8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -594,27 +594,30 @@ jobs: - name: Build books run: | langs=( en ru ) - latest=0.5 - vers=( 0.4.x ) + devver=dev + stable=$(git tag | grep v | tail -n 1 | cut -c2-4) + vers=( 0.5.x 0.4.x ) # Create directories td=$(mktemp -d) - mkdir -p $td/$latest/book/ - cp -r target/doc $td/$latest/api + mkdir -p $td/$devver/book/ + cp -r target/doc $td/$devver/api - # sed fixes - sed 's|URL|rtic/index.html|g' redirect.html > $td/$latest/api/index.html - sed 's|URL|0.5|g' redirect.html > $td/index.html - sed 's|URL|book/en|g' redirect.html > $td/$latest/index.html + # Redirect the main site to the stable release + sed "s|URL|$stable|g" redirect.html > $td/index.html + + # Create the redirects for dev-version + sed 's|URL|rtic/index.html|g' redirect.html > $td/$devver/api/index.html + sed 's|URL|book/en|g' redirect.html > $td/$devver/index.html # Build books for lang in ${langs[@]}; do ( cd book/$lang && mdbook build ) - cp -r book/$lang/book $td/$latest/book/$lang - cp LICENSE-* $td/$latest/book/$lang/ + cp -r book/$lang/book $td/$devver/book/$lang + cp LICENSE-* $td/$devver/book/$lang/ done - # Build older versions + # Build older versions, including stable root=$(pwd) for ver in ${vers[@]}; do prefix=${ver%.*} @@ -639,6 +642,9 @@ jobs: rm -rf $src done + # Create alias for the stable release + ln -s $td/$stable $td/stable + # Forward CNAME file cp CNAME $td/ mv $td/ bookstodeploy -- cgit v1.2.3 From 2f3dafe711912fbb45c14419cf410250a69f3b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 5 Oct 2020 07:56:53 +0000 Subject: Ensure pre-releases are not included --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e6271c8..22f13fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -595,7 +595,7 @@ jobs: run: | langs=( en ru ) devver=dev - stable=$(git tag | grep v | tail -n 1 | cut -c2-4) + stable=$(git tag | grep v | grep -v "-" | tail -n 1 | cut -c2-4) vers=( 0.5.x 0.4.x ) # Create directories -- cgit v1.2.3 From 03bff3dd808d1d75b774953a2c9804905029e7cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 5 Oct 2020 08:09:43 +0000 Subject: v must be first in the tag, document the version --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22f13fa..0fb1464 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -595,7 +595,11 @@ jobs: run: | langs=( en ru ) devver=dev - stable=$(git tag | grep v | grep -v "-" | tail -n 1 | cut -c2-4) + # Query git for tagged releases, all releases start with "v" + # followed by MAJOR.MINOR.PATCH, see semver.org + # Then remove all pre-releases/tags with hyphens (-). + # The latest release is last, finally trim "v" and PATCH + stable=$(git tag | grep "^v" | grep -v "-" | tail -n 1 | cut -c2-4) vers=( 0.5.x 0.4.x ) # Create directories -- cgit v1.2.3 From 95503b6bdff3f392450d1972b0c499b79a9c2092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 5 Oct 2020 08:24:33 +0000 Subject: Use latest rtic-syntax master --- macros/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 35511ee..610890b 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -21,5 +21,5 @@ proc-macro = true proc-macro2 = "1" quote = "1" syn = "1" -rtic-syntax = { git = "https://github.com/AfoHT/rtic-syntax", branch = "mod_const", version = "0.4.0" } +rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.4.0" } -- cgit v1.2.3 From 3aaa223be1a0eab4444caaf1b0daa6d250832e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 5 Oct 2020 09:19:43 +0000 Subject: Fix broken symlink --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4bc1028..56183c3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -578,7 +578,7 @@ jobs: - name: Build books run: | langs=( en ru ) - devver=dev + devver=( dev ) # Query git for tagged releases, all releases start with "v" # followed by MAJOR.MINOR.PATCH, see semver.org # Then remove all pre-releases/tags with hyphens (-). @@ -631,7 +631,7 @@ jobs: done # Create alias for the stable release - ln -s $td/$stable $td/stable + ln -s $stable $td/stable # Forward CNAME file cp CNAME $td/ -- cgit v1.2.3 From 3fed6a944e73e1a077d218f77c0957cfdd508688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 5 Oct 2020 10:07:43 +0000 Subject: Use a full copy of the book instead of symlink --- .github/workflows/build.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56183c3..b6aed4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -586,6 +586,8 @@ jobs: stable=$(git tag | grep "^v" | grep -v "-" | tail -n 1 | cut -c2-4) vers=( 0.5.x 0.4.x ) + echo "Stable version: $stable" + # Create directories td=$(mktemp -d) mkdir -p $td/$devver/book/ @@ -630,8 +632,8 @@ jobs: rm -rf $src done - # Create alias for the stable release - ln -s $stable $td/stable + # Copy the stable book to the stable alias + cp -r $td/$stable $td/stable # Forward CNAME file cp CNAME $td/ -- cgit v1.2.3 From a38952fbd4f972c2016093a852a35aadc479ac72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 5 Oct 2020 10:44:57 +0000 Subject: Unable to use git for tags --- .github/workflows/build.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6aed4e..1d5773e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -579,13 +579,14 @@ jobs: run: | langs=( en ru ) devver=( dev ) - # Query git for tagged releases, all releases start with "v" - # followed by MAJOR.MINOR.PATCH, see semver.org - # Then remove all pre-releases/tags with hyphens (-). - # The latest release is last, finally trim "v" and PATCH - stable=$(git tag | grep "^v" | grep -v "-" | tail -n 1 | cut -c2-4) + # The latest stable must be the first element in the array vers=( 0.5.x 0.4.x ) + # All releases start with "v" + # followed by MAJOR.MINOR.PATCH, see semver.org + # Retain MAJOR.MINOR as $stable + stable=${vers%.*} + echo "Stable version: $stable" # Create directories -- cgit v1.2.3 From 7261685b7fa3d555c29a4cd9f8dd208d985c182c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Mon, 5 Oct 2020 09:35:07 +0000 Subject: Separate example check and run-pass tests --- .github/workflows/build.yml | 49 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1d5773e..e53672b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,7 +85,7 @@ jobs: command: check args: --target=${{ matrix.target }} - # Verify all examples + # Verify all examples, checks checkexamples: name: checkexamples runs-on: ubuntu-20.04 @@ -140,6 +140,51 @@ jobs: command: check args: --examples --target=${{ matrix.target }} --features __min_r1_43,${{ env.V7 }} + # Verify the example output with run-pass tests + testexamples: + name: testexamples + runs-on: ubuntu-20.04 + strategy: + matrix: + target: + - thumbv7m-none-eabi + - thumbv6m-none-eabi + toolchain: + - stable + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Cache cargo dependencies + uses: actions/cache@v2 + with: + path: | + - ~/.cargo/bin/ + - ~/.cargo/registry/index/ + - ~/.cargo/registry/cache/ + - ~/.cargo/git/db/ + key: ${{ runner.OS }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.OS }}-cargo-${{ hashFiles('**/Cargo.lock') }} + ${{ runner.OS }}-cargo- + + - name: Cache build output dependencies + uses: actions/cache@v2 + with: + path: target + key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }} + ${{ runner.OS }}-build- + + - name: Install Rust ${{ matrix.toolchain }} with target (${{ matrix.target }}) + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + target: ${{ matrix.target }} + override: true + components: llvm-tools-preview + # Use precompiled binutils - name: cargo install cargo-binutils uses: actions-rs/install@v0.1 @@ -657,6 +702,7 @@ jobs: - style - check - checkexamples + - testexamples - checkmacros - testv7 - testv6 @@ -673,6 +719,7 @@ jobs: - style - check - checkexamples + - testexamples - checkmacros - testv7 - testv6 -- cgit v1.2.3