rtic/examples/not-send.rs

58 lines
1.2 KiB
Rust
Raw Normal View History

2018-11-03 17:02:41 +01:00
//! `examples/not-send.rs`
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use core::marker::PhantomData;
use cortex_m_semihosting::debug;
use panic_halt as _;
2018-11-03 17:02:41 +01:00
use rtfm::app;
pub struct NotSend {
_0: PhantomData<*const ()>,
}
#[app(device = lm3s6965)]
const APP: () = {
static mut SHARED: Option<NotSend> = None;
#[init(spawn = [baz, quux])]
2019-04-21 20:10:40 +02:00
fn init(c: init::Context) {
c.spawn.baz().unwrap();
c.spawn.quux().unwrap();
2018-11-03 17:02:41 +01:00
}
#[task(spawn = [bar])]
2019-04-21 20:10:40 +02:00
fn foo(c: foo::Context) {
2018-11-03 17:02:41 +01:00
// scenario 1: message passed to task that runs at the same priority
2019-04-21 20:10:40 +02:00
c.spawn.bar(NotSend { _0: PhantomData }).ok();
2018-11-03 17:02:41 +01:00
}
#[task]
2019-04-21 20:10:40 +02:00
fn bar(_: bar::Context, _x: NotSend) {
2018-11-03 17:02:41 +01:00
// scenario 1
}
#[task(priority = 2, resources = [SHARED])]
fn baz(c: baz::Context) {
2018-11-03 17:02:41 +01:00
// scenario 2: resource shared between tasks that run at the same priority
2019-04-21 20:10:40 +02:00
*c.resources.SHARED = Some(NotSend { _0: PhantomData });
2018-11-03 17:02:41 +01:00
}
#[task(priority = 2, resources = [SHARED])]
fn quux(c: quux::Context) {
2018-11-03 17:02:41 +01:00
// scenario 2
2019-04-21 20:10:40 +02:00
let _not_send = c.resources.SHARED.take().unwrap();
2018-11-03 17:02:41 +01:00
debug::exit(debug::EXIT_SUCCESS);
}
extern "C" {
fn UART0();
fn UART1();
}
};