From e865cbb2e59a95962d7e4d45c31f9ff1e4ba6579 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 16 Apr 2019 21:54:19 +0200 Subject: book: resources shared with init must also be `Send` --- examples/shared-with-init.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/shared-with-init.rs (limited to 'examples/shared-with-init.rs') diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs new file mode 100644 index 00000000..5ddd2cc3 --- /dev/null +++ b/examples/shared-with-init.rs @@ -0,0 +1,38 @@ +//! `examples/shared-with-init.rs` + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +extern crate panic_halt; + +use cortex_m_semihosting::debug; +use lm3s6965::Interrupt; +use rtfm::app; + +pub struct MustBeSend; + +#[app(device = lm3s6965)] +const APP: () = { + static mut SHARED: Option = None; + + #[init(resources = [SHARED])] + fn init() { + // this `message` will be sent to task `UART0` + let message = MustBeSend; + *resources.SHARED = Some(message); + + rtfm::pend(Interrupt::UART0); + } + + #[interrupt(resources = [SHARED])] + fn UART0() { + if let Some(message) = resources.SHARED.take() { + // `message` has been received + drop(message); + + debug::exit(debug::EXIT_SUCCESS); + } + } +}; -- cgit v1.2.3