rtic/examples/not-send.rs

61 lines
1.3 KiB
Rust
Raw Permalink 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 _;
2020-06-11 19:18:29 +02:00
use rtic::app;
2018-11-03 17:02:41 +01:00
pub struct NotSend {
_0: PhantomData<*const ()>,
}
#[app(device = lm3s6965)]
const APP: () = {
2019-07-10 22:42:44 +02:00
struct Resources {
#[init(None)]
shared: Option<NotSend>,
}
2018-11-03 17:02:41 +01:00
#[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
}
2019-07-10 22:42:44 +02:00
#[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-07-10 22:42:44 +02:00
*c.resources.shared = Some(NotSend { _0: PhantomData });
2018-11-03 17:02:41 +01:00
}
2019-07-10 22:42:44 +02:00
#[task(priority = 2, resources = [shared])]
fn quux(c: quux::Context) {
2018-11-03 17:02:41 +01:00
// scenario 2
2019-07-10 22:42:44 +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();
}
};