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;
|
2019-06-13 23:56:59 +02:00
|
|
|
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])]
|
2019-06-13 23:56:59 +02:00
|
|
|
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])]
|
2019-06-13 23:56:59 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-06-26 23:46:09 +02:00
|
|
|
// RTIC requires that unused interrupts are declared in an extern block when
|
|
|
|
// using software tasks; these free interrupts will be used to dispatch the
|
|
|
|
// software tasks.
|
2018-11-03 17:02:41 +01:00
|
|
|
extern "C" {
|
2020-06-26 23:46:09 +02:00
|
|
|
fn SSI0();
|
|
|
|
fn QEI0();
|
2018-11-03 17:02:41 +01:00
|
|
|
}
|
|
|
|
};
|