mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-24 02:49:34 +01:00
Examples using mod instead of const
This commit is contained in:
parent
4d61437bb4
commit
8df2ec11b0
37 changed files with 75 additions and 76 deletions
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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<u32>`
|
||||
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<T = u32>) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct NotSend {
|
|||
}
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
mod APP {
|
||||
struct Resources {
|
||||
#[init(None)]
|
||||
shared: Option<NotSend>,
|
||||
|
@ -60,4 +60,4 @@ const APP: () = {
|
|||
fn SSI0();
|
||||
fn QEI0();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use rtic::app;
|
|||
pub struct MustBeSend;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
mod APP {
|
||||
struct Resources {
|
||||
#[init(None)]
|
||||
shared: Option<MustBeSend>,
|
||||
|
@ -37,4 +37,4 @@ const APP: () = {
|
|||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,4 +7,4 @@ use panic_semihosting as _; // panic handler
|
|||
use rtic::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {};
|
||||
mod APP {}
|
||||
|
|
|
@ -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) {}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue