blob: f240e511fafd5b49f9e9b1a27ff316a355f39a70 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
//! `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 _;
use rtfm::app;
pub struct NotSend {
_0: PhantomData<*const ()>,
}
#[app(device = lm3s6965)]
const APP: () = {
static mut SHARED: Option<NotSend> = None;
#[init(spawn = [baz, quux])]
fn init(c: init::Context) {
c.spawn.baz().unwrap();
c.spawn.quux().unwrap();
}
#[task(spawn = [bar])]
fn foo(c: foo::Context) {
// scenario 1: message passed to task that runs at the same priority
c.spawn.bar(NotSend { _0: PhantomData }).ok();
}
#[task]
fn bar(_: bar::Context, _x: NotSend) {
// scenario 1
}
#[task(priority = 2, resources = [SHARED])]
fn baz(c: baz::Context) {
// scenario 2: resource shared between tasks that run at the same priority
*c.resources.SHARED = Some(NotSend { _0: PhantomData });
}
#[task(priority = 2, resources = [SHARED])]
fn quux(c: quux::Context) {
// scenario 2
let _not_send = c.resources.SHARED.take().unwrap();
debug::exit(debug::EXIT_SUCCESS);
}
extern "C" {
fn UART0();
fn UART1();
}
};
|