2019-04-16 21:54:19 +02:00
|
|
|
//! `examples/shared-with-init.rs`
|
|
|
|
|
|
|
|
#![deny(unsafe_code)]
|
|
|
|
#![deny(warnings)]
|
|
|
|
#![no_main]
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
use cortex_m_semihosting::debug;
|
|
|
|
use lm3s6965::Interrupt;
|
2021-03-03 09:48:54 +01:00
|
|
|
use panic_semihosting as _;
|
2020-06-11 19:18:29 +02:00
|
|
|
use rtic::app;
|
2019-04-16 21:54:19 +02:00
|
|
|
|
|
|
|
pub struct MustBeSend;
|
|
|
|
|
|
|
|
#[app(device = lm3s6965)]
|
|
|
|
const APP: () = {
|
2019-07-10 22:42:44 +02:00
|
|
|
struct Resources {
|
|
|
|
#[init(None)]
|
|
|
|
shared: Option<MustBeSend>,
|
|
|
|
}
|
2019-04-16 21:54:19 +02:00
|
|
|
|
2019-07-10 22:42:44 +02:00
|
|
|
#[init(resources = [shared])]
|
2019-04-21 20:10:40 +02:00
|
|
|
fn init(c: init::Context) {
|
2019-04-16 21:54:19 +02:00
|
|
|
// this `message` will be sent to task `UART0`
|
|
|
|
let message = MustBeSend;
|
2019-07-10 22:42:44 +02:00
|
|
|
*c.resources.shared = Some(message);
|
2019-04-16 21:54:19 +02:00
|
|
|
|
2020-06-11 19:18:29 +02:00
|
|
|
rtic::pend(Interrupt::UART0);
|
2019-04-16 21:54:19 +02:00
|
|
|
}
|
|
|
|
|
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() {
|
2019-04-16 21:54:19 +02:00
|
|
|
// `message` has been received
|
|
|
|
drop(message);
|
|
|
|
|
|
|
|
debug::exit(debug::EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|