rtic/examples/late.rs

58 lines
1.2 KiB
Rust
Raw Normal View History

2018-11-03 17:02:41 +01:00
//! examples/late.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use cortex_m_semihosting::{debug, hprintln};
2018-11-03 17:02:41 +01:00
use heapless::{
consts::*,
2019-08-21 10:17:27 +02:00
i,
2018-11-03 17:02:41 +01:00
spsc::{Consumer, Producer, Queue},
};
use lm3s6965::Interrupt;
use panic_semihosting as _;
2018-11-03 17:02:41 +01:00
2020-06-11 19:18:29 +02:00
#[rtic::app(device = lm3s6965)]
2020-05-19 20:00:13 +02:00
mod app {
2020-05-26 12:48:24 +02:00
use heapless::{
consts::*,
spsc::{Consumer, Producer},
};
2018-11-03 17:02:41 +01:00
// Late resources
#[resources]
2019-07-10 22:42:44 +02:00
struct Resources {
p: Producer<'static, u32, U4>,
c: Consumer<'static, u32, U4>,
}
2018-11-03 17:02:41 +01:00
#[init]
2019-04-21 20:10:40 +02:00
fn init(_: init::Context) -> init::LateResources {
2019-08-21 10:17:27 +02:00
static mut Q: Queue<u32, U4> = Queue(i::Queue::new());
2018-11-03 17:02:41 +01:00
2019-08-21 10:17:27 +02:00
let (p, c) = Q.split();
2018-11-03 17:02:41 +01:00
// Initialization of late resources
2019-07-10 22:42:44 +02:00
init::LateResources { p, c }
2018-11-03 17:02:41 +01:00
}
2019-07-10 22:42:44 +02:00
#[idle(resources = [c])]
2019-04-21 20:10:40 +02:00
fn idle(c: idle::Context) -> ! {
2018-11-03 17:02:41 +01:00
loop {
2019-07-10 22:42:44 +02:00
if let Some(byte) = c.resources.c.dequeue() {
hprintln!("received message: {}", byte).unwrap();
2018-11-03 17:02:41 +01:00
debug::exit(debug::EXIT_SUCCESS);
} else {
2020-06-11 19:18:29 +02:00
rtic::pend(Interrupt::UART0);
2018-11-03 17:02:41 +01:00
}
}
}
2019-07-10 22:42:44 +02:00
#[task(binds = UART0, resources = [p])]
2019-06-20 06:19:59 +02:00
fn uart0(c: uart0::Context) {
2019-07-10 22:42:44 +02:00
c.resources.p.enqueue(42).unwrap();
2018-11-03 17:02:41 +01:00
}
2020-04-22 12:58:14 +02:00
}