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: [PATCH] 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 f46b273d4b..2d75dfaa45 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 82bf89640f..920124cf32 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 00cec34459..26c61a250a 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 8eeeb2a93a..626181de3b 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 1756bd9e75..da0a4c1d0e 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 40ab81ac75..b67ed9ca39 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 8105a7420d..7926650c1f 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 3d28dac8a7..dbf7f983bf 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 315969f045..c651136e4f 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 60b9be0046..8675c6ac73 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 5e3bce2500..4b16679e9b 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 596f244904..3e9633bd2f 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 16a874dc0f..bcc049c326 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 a7eaac8e7f..0354ef1015 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 c022b037d2..fbc7bfd42a 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 405346e390..cd887ca52e 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 cd4ba0f0ed..a1bd686832 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 824d5bd86b..eb65ed8271 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 3cb11029b4..a20b36ccb5 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 1f95d496ef..cfe22e392d 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 2361fd0033..a0954d604d 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 70a7a5e328..f2e7ed8804 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 bd55f7efd5..03391bddc1 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 ec3fa970d7..d6f3b66cc2 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 588ac46fa6..8634c7595c 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 4f7fd635a7..892d211450 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 b6c9e47207..da9a49109d 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 c4bebf94dc..6143bbd73f 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 051a9ee812..89f93d0a98 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 6a6cd99164..040c72fa19 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 d2a9b63ce9..77990182b5 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 81ba18563f..0864a8ab27 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 3854aad36b..6753613356 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 35831ccf9d..7a64e1ccf4 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 f270940454..edea4309ee 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 12c4ac8355..e515c936cc 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 5233f868b1..eafc9b1d1d 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(); } -}; +}