rtic/examples/not-send.rs

67 lines
1.5 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 _;
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)]
2020-05-19 20:00:13 +02:00
mod app {
2020-05-26 12:48:24 +02:00
use super::NotSend;
#[resources]
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);
}
// 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" {
fn SSI0();
fn QEI0();
2018-11-03 17:02:41 +01:00
}
2020-04-22 12:58:14 +02:00
}