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(-) (limited to 'examples') 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 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 +- 37 files changed, 41 insertions(+), 38 deletions(-) (limited to 'examples') 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, -- 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(+) (limited to 'examples') 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 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(-) (limited to 'examples') 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(-) (limited to 'examples') 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 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(-) (limited to 'examples') 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 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 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 examples/resource-user-struct.rs (limited to 'examples') 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(); + } +} -- 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(+) (limited to 'examples') 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 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(-) (limited to 'examples') 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 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(+) (limited to 'examples') 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 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 --- examples/init.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples') 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