mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 21:05:35 +01:00
book: resources shared with init must also be Send
This commit is contained in:
parent
c4bad51deb
commit
e865cbb2e5
3 changed files with 47 additions and 0 deletions
38
examples/shared-with-init.rs
Normal file
38
examples/shared-with-init.rs
Normal file
|
|
@ -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<MustBeSend> = 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue