2020-09-08 19:51:10 +02:00
|
|
|
//! examples/static.rs
|
2020-03-04 15:06:03 +01:00
|
|
|
|
|
|
|
#![deny(unsafe_code)]
|
|
|
|
#![deny(warnings)]
|
|
|
|
#![no_main]
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
use panic_semihosting as _;
|
|
|
|
|
2020-09-08 19:51:10 +02:00
|
|
|
#[rtic::app(device = lm3s6965)]
|
|
|
|
mod app {
|
|
|
|
|
2020-10-15 18:50:17 +02:00
|
|
|
use cortex_m_semihosting::{debug, hprintln};
|
|
|
|
use heapless::{
|
|
|
|
consts::*,
|
|
|
|
i,
|
|
|
|
spsc::{Consumer, Producer, Queue},
|
|
|
|
};
|
|
|
|
use lm3s6965::Interrupt;
|
2020-09-08 19:51:10 +02:00
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
#[shared]
|
|
|
|
struct Shared {
|
2020-10-21 20:33:55 +02:00
|
|
|
p: Producer<'static, u32, U4>,
|
2020-03-04 15:06:03 +01:00
|
|
|
c: Consumer<'static, u32, U4>,
|
|
|
|
}
|
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
#[local]
|
|
|
|
struct Local {}
|
2020-03-04 15:06:03 +01:00
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
#[init(local = [q: Queue<u32, U4> = Queue(i::Queue::new())])]
|
|
|
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
|
|
|
let (p, c) = cx.local.q.split();
|
2020-03-04 15:06:03 +01:00
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
(Shared { p, c }, Local {}, init::Monotonics())
|
2020-03-04 15:06:03 +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) -> ! {
|
2020-03-04 15:06:03 +01:00
|
|
|
loop {
|
2021-07-07 22:50:59 +02:00
|
|
|
if let Some(byte) = c.shared.c.lock(|c| c.dequeue()) {
|
2020-03-04 15:06:03 +01:00
|
|
|
hprintln!("received message: {}", byte).unwrap();
|
|
|
|
|
|
|
|
debug::exit(debug::EXIT_SUCCESS);
|
|
|
|
} else {
|
2020-09-08 19:51:10 +02:00
|
|
|
rtic::pend(Interrupt::UART0);
|
2020-03-04 15:06:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-07 22:50:59 +02:00
|
|
|
#[task(binds = UART0, shared = [p], local = [kalle: u32 = 0])]
|
2020-10-22 21:36:32 +02:00
|
|
|
fn uart0(mut c: uart0::Context) {
|
2021-07-07 22:50:59 +02:00
|
|
|
*c.local.kalle += 1;
|
|
|
|
c.shared.p.lock(|p| p.enqueue(42).unwrap());
|
2020-03-04 15:06:03 +01:00
|
|
|
}
|
2020-09-08 19:51:10 +02:00
|
|
|
}
|