2018-11-03 17:02:41 +01:00
|
|
|
//! examples/late.rs
|
|
|
|
|
|
|
|
#![deny(unsafe_code)]
|
|
|
|
#![deny(warnings)]
|
|
|
|
#![no_main]
|
|
|
|
#![no_std]
|
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
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-10-15 18:50:17 +02:00
|
|
|
use cortex_m_semihosting::{debug, hprintln};
|
2021-04-03 19:30:34 +02:00
|
|
|
use heapless::spsc::{Consumer, Producer, Queue};
|
2020-10-15 18:50:17 +02:00
|
|
|
use lm3s6965::Interrupt;
|
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
#[shared]
|
|
|
|
struct Shared {
|
2021-04-03 19:30:34 +02:00
|
|
|
p: Producer<'static, u32, 5>,
|
|
|
|
c: Consumer<'static, u32, 5>,
|
2019-06-13 23:56:59 +02:00
|
|
|
}
|
2018-11-03 17:02:41 +01:00
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
#[local]
|
|
|
|
struct Local {}
|
2018-11-03 17:02:41 +01:00
|
|
|
|
2021-04-03 19:30:34 +02:00
|
|
|
#[init(local = [q: Queue<u32, 5> = Queue::new()])]
|
2023-01-07 17:59:39 +01:00
|
|
|
fn init(cx: init::Context) -> (Shared, Local) {
|
2021-07-07 22:50:59 +02:00
|
|
|
let (p, c) = cx.local.q.split();
|
2018-11-03 17:02:41 +01:00
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
// Initialization of shared resources
|
2023-01-07 17:59:39 +01:00
|
|
|
(Shared { p, c }, Local {})
|
2018-11-03 17:02:41 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
#[idle(shared = [c])]
|
2020-10-22 21:36:32 +02:00
|
|
|
fn idle(mut c: idle::Context) -> ! {
|
2018-11-03 17:02:41 +01:00
|
|
|
loop {
|
2021-07-07 22:50:59 +02:00
|
|
|
if let Some(byte) = c.shared.c.lock(|c| c.dequeue()) {
|
2023-01-02 14:34:05 +01:00
|
|
|
hprintln!("received message: {}", byte).unwrap();
|
2018-11-03 17:02:41 +01:00
|
|
|
|
2021-09-22 13:22:45 +02:00
|
|
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
2018-11-03 17:02:41 +01:00
|
|
|
} else {
|
2020-06-11 19:18:29 +02:00
|
|
|
rtic::pend(Interrupt::UART0);
|
2018-11-03 17:02:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
#[task(binds = UART0, shared = [p])]
|
2020-10-22 21:36:32 +02:00
|
|
|
fn uart0(mut c: uart0::Context) {
|
2021-07-07 22:50:59 +02:00
|
|
|
c.shared.p.lock(|p| p.enqueue(42).unwrap());
|
2018-11-03 17:02:41 +01:00
|
|
|
}
|
2020-04-22 12:58:14 +02:00
|
|
|
}
|