aboutsummaryrefslogtreecommitdiff
path: root/examples/late.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/late.rs')
-rw-r--r--examples/late.rs49
1 files changed, 26 insertions, 23 deletions
diff --git a/examples/late.rs b/examples/late.rs
index 622008a..761c68f 100644
--- a/examples/late.rs
+++ b/examples/late.rs
@@ -5,50 +5,53 @@
#![no_main]
#![no_std]
-extern crate panic_semihosting;
-
use cortex_m_semihosting::{debug, hprintln};
use heapless::{
consts::*,
+ i,
spsc::{Consumer, Producer, Queue},
};
use lm3s6965::Interrupt;
-use rtfm::app;
-
-#[app(device = lm3s6965)]
-const APP: () = {
+use panic_semihosting as _;
+
+#[rtic::app(device = lm3s6965)]
+mod app {
+ use heapless::{
+ consts::*,
+ spsc::{Consumer, Producer},
+ };
// Late resources
- static mut P: Producer<'static, u32, U4> = ();
- static mut C: Consumer<'static, u32, U4> = ();
+ #[resources]
+ struct Resources {
+ p: Producer<'static, u32, U4>,
+ c: Consumer<'static, u32, U4>,
+ }
#[init]
- fn init() -> init::LateResources {
- // NOTE: we use `Option` here to work around the lack of
- // a stable `const` constructor
- static mut Q: Option<Queue<u32, U4>> = None;
+ fn init(_: init::Context) -> init::LateResources {
+ static mut Q: Queue<u32, U4> = Queue(i::Queue::new());
- *Q = Some(Queue::new());
- let (p, c) = Q.as_mut().unwrap().split();
+ let (p, c) = Q.split();
// Initialization of late resources
- init::LateResources { P: p, C: c }
+ init::LateResources { p, c }
}
- #[idle(resources = [C])]
- fn idle() -> ! {
+ #[idle(resources = [c])]
+ fn idle(c: idle::Context) -> ! {
loop {
- if let Some(byte) = resources.C.dequeue() {
+ if let Some(byte) = c.resources.c.dequeue() {
hprintln!("received message: {}", byte).unwrap();
debug::exit(debug::EXIT_SUCCESS);
} else {
- rtfm::pend(Interrupt::UART0);
+ rtic::pend(Interrupt::UART0);
}
}
}
- #[interrupt(resources = [P])]
- fn UART0() {
- resources.P.enqueue(42).unwrap();
+ #[task(binds = UART0, resources = [p])]
+ fn uart0(c: uart0::Context) {
+ c.resources.p.enqueue(42).unwrap();
}
-};
+}