aboutsummaryrefslogtreecommitdiff
path: root/examples/late.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/late.rs')
-rw-r--r--examples/late.rs29
1 files changed, 14 insertions, 15 deletions
diff --git a/examples/late.rs b/examples/late.rs
index 0074fb32..2eb12d6a 100644
--- a/examples/late.rs
+++ b/examples/late.rs
@@ -5,38 +5,37 @@
#![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 panic_semihosting as _;
#[rtfm::app(device = lm3s6965)]
const APP: () = {
// Late resources
- static mut P: Producer<'static, u32, U4> = ();
- static mut C: Consumer<'static, u32, U4> = ();
+ struct Resources {
+ p: Producer<'static, u32, U4>,
+ c: Consumer<'static, u32, U4>,
+ }
#[init]
fn init(_: init::Context) -> 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;
+ 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])]
+ #[idle(resources = [c])]
fn idle(c: idle::Context) -> ! {
loop {
- if let Some(byte) = c.resources.C.dequeue() {
+ if let Some(byte) = c.resources.c.dequeue() {
hprintln!("received message: {}", byte).unwrap();
debug::exit(debug::EXIT_SUCCESS);
@@ -46,8 +45,8 @@ const APP: () = {
}
}
- #[interrupt(resources = [P])]
- fn UART0(c: UART0::Context) {
- c.resources.P.enqueue(42).unwrap();
+ #[task(binds = UART0, resources = [p])]
+ fn uart0(c: uart0::Context) {
+ c.resources.p.enqueue(42).unwrap();
}
};