rtic/examples/shared-with-init.rs

46 lines
975 B
Rust
Raw Normal View History

//! `examples/shared-with-init.rs`
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_halt as _;
2020-06-11 19:18:29 +02:00
use rtic::app;
pub struct MustBeSend;
#[app(device = lm3s6965)]
2020-05-19 20:00:13 +02:00
mod app {
2020-10-21 20:20:26 +02:00
use super::MustBeSend;
2020-10-15 18:50:17 +02:00
use cortex_m_semihosting::debug;
use lm3s6965::Interrupt;
2020-05-26 12:48:24 +02:00
#[resources]
2019-07-10 22:42:44 +02:00
struct Resources {
#[init(None)]
shared: Option<MustBeSend>,
}
2019-07-10 22:42:44 +02:00
#[init(resources = [shared])]
2020-10-01 19:38:49 +02:00
fn init(c: init::Context) -> init::LateResources {
// this `message` will be sent to task `UART0`
let message = MustBeSend;
2019-07-10 22:42:44 +02:00
*c.resources.shared = Some(message);
2020-06-11 19:18:29 +02:00
rtic::pend(Interrupt::UART0);
2020-10-01 19:38:49 +02:00
init::LateResources {}
}
2019-07-10 22:42:44 +02:00
#[task(binds = UART0, resources = [shared])]
2019-06-20 06:19:59 +02:00
fn uart0(c: uart0::Context) {
2019-07-10 22:42:44 +02:00
if let Some(message) = c.resources.shared.take() {
// `message` has been received
drop(message);
debug::exit(debug::EXIT_SUCCESS);
}
}
2020-04-22 12:58:14 +02:00
}