mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
update examples
This commit is contained in:
parent
a452700628
commit
1b4b006bab
23 changed files with 159 additions and 235 deletions
|
@ -9,24 +9,23 @@ extern crate panic_semihosting;
|
|||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
// NOTE: does NOT properly work on QEMU
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo])]
|
||||
fn init() {
|
||||
hprintln!("init(baseline = {:?})", start).unwrap();
|
||||
fn init(c: init::Context) {
|
||||
hprintln!("init(baseline = {:?})", c.start).unwrap();
|
||||
|
||||
// `foo` inherits the baseline of `init`: `Instant(0)`
|
||||
spawn.foo().unwrap();
|
||||
c.spawn.foo().unwrap();
|
||||
}
|
||||
|
||||
#[task(schedule = [foo])]
|
||||
fn foo() {
|
||||
fn foo(c: foo::Context) {
|
||||
static mut ONCE: bool = true;
|
||||
|
||||
hprintln!("foo(baseline = {:?})", scheduled).unwrap();
|
||||
hprintln!("foo(baseline = {:?})", c.scheduled).unwrap();
|
||||
|
||||
if *ONCE {
|
||||
*ONCE = false;
|
||||
|
@ -38,11 +37,11 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt(spawn = [foo])]
|
||||
fn UART0() {
|
||||
hprintln!("UART0(baseline = {:?})", start).unwrap();
|
||||
fn UART0(c: UART0::Context) {
|
||||
hprintln!("UART0(baseline = {:?})", c.start).unwrap();
|
||||
|
||||
// `foo` inherits the baseline of `UART0`: its `start` time
|
||||
spawn.foo().unwrap();
|
||||
c.spawn.foo().unwrap();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
|
|
@ -9,20 +9,19 @@ extern crate panic_semihosting;
|
|||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
// `examples/interrupt.rs` rewritten to use `binds`
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
rtfm::pend(Interrupt::UART0);
|
||||
|
||||
hprintln!("init").unwrap();
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle() -> ! {
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
hprintln!("idle").unwrap();
|
||||
|
||||
rtfm::pend(Interrupt::UART0);
|
||||
|
@ -33,7 +32,7 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt(binds = UART0)]
|
||||
fn foo() {
|
||||
fn foo(_: foo::Context) {
|
||||
static mut TIMES: u32 = 0;
|
||||
|
||||
*TIMES += 1;
|
||||
|
|
|
@ -9,32 +9,31 @@ extern crate panic_semihosting;
|
|||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
rtfm::pend(Interrupt::UART0);
|
||||
}
|
||||
|
||||
#[interrupt(spawn = [foo, bar])]
|
||||
fn UART0() {
|
||||
spawn.foo(0).unwrap();
|
||||
spawn.foo(1).unwrap();
|
||||
spawn.foo(2).unwrap();
|
||||
spawn.foo(3).unwrap();
|
||||
fn UART0(c: UART0::Context) {
|
||||
c.spawn.foo(0).unwrap();
|
||||
c.spawn.foo(1).unwrap();
|
||||
c.spawn.foo(2).unwrap();
|
||||
c.spawn.foo(3).unwrap();
|
||||
|
||||
spawn.bar().unwrap();
|
||||
c.spawn.bar().unwrap();
|
||||
}
|
||||
|
||||
#[task(capacity = 4)]
|
||||
fn foo(x: u32) {
|
||||
fn foo(_: foo::Context, x: u32) {
|
||||
hprintln!("foo({})", x).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar() {
|
||||
fn bar(_: bar::Context) {
|
||||
hprintln!("bar").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
|
|
@ -9,25 +9,24 @@ extern crate panic_semihosting;
|
|||
|
||||
#[cfg(debug_assertions)]
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[cfg(debug_assertions)] // <- `true` when using the `dev` profile
|
||||
static mut COUNT: u32 = 0;
|
||||
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
// ..
|
||||
}
|
||||
|
||||
#[task(priority = 3, resources = [COUNT], spawn = [log])]
|
||||
fn foo() {
|
||||
fn foo(c: foo::Context) {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
*resources.COUNT += 1;
|
||||
*c.resources.COUNT += 1;
|
||||
|
||||
spawn.log(*resources.COUNT).ok();
|
||||
c.spawn.log(*c.resources.COUNT).ok();
|
||||
}
|
||||
|
||||
// this wouldn't compile in `release` mode
|
||||
|
@ -38,7 +37,7 @@ const APP: () = {
|
|||
|
||||
#[cfg(debug_assertions)]
|
||||
#[task]
|
||||
fn log(n: u32) {
|
||||
fn log(_: log::Context, n: u32) {
|
||||
hprintln!(
|
||||
"foo has been called {} time{}",
|
||||
n,
|
||||
|
|
|
@ -9,25 +9,25 @@ extern crate panic_semihosting;
|
|||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::{app, Mutex};
|
||||
use rtfm::Mutex;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static mut SHARED: u32 = 0;
|
||||
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
rtfm::pend(Interrupt::UART0);
|
||||
rtfm::pend(Interrupt::UART1);
|
||||
}
|
||||
|
||||
#[interrupt(resources = [SHARED])]
|
||||
fn UART0() {
|
||||
fn UART0(c: UART0::Context) {
|
||||
static mut STATE: u32 = 0;
|
||||
|
||||
hprintln!("UART0(STATE = {})", *STATE).unwrap();
|
||||
|
||||
advance(STATE, resources.SHARED);
|
||||
advance(STATE, c.resources.SHARED);
|
||||
|
||||
rtfm::pend(Interrupt::UART1);
|
||||
|
||||
|
@ -35,17 +35,17 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt(priority = 2, resources = [SHARED])]
|
||||
fn UART1() {
|
||||
fn UART1(mut c: UART1::Context) {
|
||||
static mut STATE: u32 = 0;
|
||||
|
||||
hprintln!("UART1(STATE = {})", *STATE).unwrap();
|
||||
|
||||
// just to show that `SHARED` can be accessed directly and ..
|
||||
*resources.SHARED += 0;
|
||||
*c.resources.SHARED += 0;
|
||||
// .. also through a (no-op) `lock`
|
||||
resources.SHARED.lock(|shared| *shared += 0);
|
||||
c.resources.SHARED.lock(|shared| *shared += 0);
|
||||
|
||||
advance(STATE, resources.SHARED);
|
||||
advance(STATE, c.resources.SHARED);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -8,17 +8,16 @@
|
|||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
hprintln!("init").unwrap();
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle() -> ! {
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
static mut X: u32 = 0;
|
||||
|
||||
// Safe access to local `static mut` variable
|
||||
|
|
|
@ -8,19 +8,18 @@
|
|||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(c: init::Context) {
|
||||
static mut X: u32 = 0;
|
||||
|
||||
// Cortex-M peripherals
|
||||
let _core: rtfm::Peripherals = core;
|
||||
let _core: rtfm::Peripherals = c.core;
|
||||
|
||||
// Device specific peripherals
|
||||
let _device: lm3s6965::Peripherals = device;
|
||||
let _device: lm3s6965::Peripherals = c.device;
|
||||
|
||||
// Safe access to local `static mut` variable
|
||||
let _x: &'static mut u32 = X;
|
||||
|
|
|
@ -9,12 +9,11 @@ extern crate panic_semihosting;
|
|||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
// Pends the UART0 interrupt but its handler won't run until *after*
|
||||
// `init` returns because interrupts are disabled
|
||||
rtfm::pend(Interrupt::UART0);
|
||||
|
@ -23,7 +22,7 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[idle]
|
||||
fn idle() -> ! {
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
// interrupts are enabled again; the `UART0` handler runs at this point
|
||||
|
||||
hprintln!("idle").unwrap();
|
||||
|
@ -36,7 +35,7 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt]
|
||||
fn UART0() {
|
||||
fn UART0(_: UART0::Context) {
|
||||
static mut TIMES: u32 = 0;
|
||||
|
||||
// Safe access to local `static mut` variable
|
||||
|
|
|
@ -13,16 +13,15 @@ use heapless::{
|
|||
spsc::{Consumer, Producer, Queue},
|
||||
};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
// Late resources
|
||||
static mut P: Producer<'static, u32, U4> = ();
|
||||
static mut C: Consumer<'static, u32, U4> = ();
|
||||
|
||||
#[init]
|
||||
fn init() -> init::LateResources {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
// NOTE: we use `Option` here to work around the lack of
|
||||
// a stable `const` constructor
|
||||
static mut Q: Option<Queue<u32, U4>> = None;
|
||||
|
@ -35,9 +34,9 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[idle(resources = [C])]
|
||||
fn idle() -> ! {
|
||||
fn idle(c: idle::Context) -> ! {
|
||||
loop {
|
||||
if let Some(byte) = resources.C.dequeue() {
|
||||
if let Some(byte) = c.resources.C.dequeue() {
|
||||
hprintln!("received message: {}", byte).unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
@ -48,7 +47,7 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt(resources = [P])]
|
||||
fn UART0() {
|
||||
resources.P.enqueue(42).unwrap();
|
||||
fn UART0(c: UART0::Context) {
|
||||
c.resources.P.enqueue(42).unwrap();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -9,24 +9,23 @@ extern crate panic_semihosting;
|
|||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static mut SHARED: u32 = 0;
|
||||
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
rtfm::pend(Interrupt::GPIOA);
|
||||
}
|
||||
|
||||
// when omitted priority is assumed to be `1`
|
||||
#[interrupt(resources = [SHARED])]
|
||||
fn GPIOA() {
|
||||
fn GPIOA(mut c: GPIOA::Context) {
|
||||
hprintln!("A").unwrap();
|
||||
|
||||
// the lower priority task requires a critical section to access the data
|
||||
resources.SHARED.lock(|shared| {
|
||||
c.resources.SHARED.lock(|shared| {
|
||||
// data can only be modified within this critical section (closure)
|
||||
*shared += 1;
|
||||
|
||||
|
@ -47,15 +46,15 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt(priority = 2, resources = [SHARED])]
|
||||
fn GPIOB() {
|
||||
fn GPIOB(mut c: GPIOB::Context) {
|
||||
// the higher priority task does *not* need a critical section
|
||||
*resources.SHARED += 1;
|
||||
*c.resources.SHARED += 1;
|
||||
|
||||
hprintln!("D - SHARED = {}", *resources.SHARED).unwrap();
|
||||
hprintln!("D - SHARED = {}", *c.resources.SHARED).unwrap();
|
||||
}
|
||||
|
||||
#[interrupt(priority = 3)]
|
||||
fn GPIOC() {
|
||||
fn GPIOC(_: GPIOC::Context) {
|
||||
hprintln!("C").unwrap();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,41 +8,40 @@
|
|||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo])]
|
||||
fn init() {
|
||||
spawn.foo(/* no message */).unwrap();
|
||||
fn init(c: init::Context) {
|
||||
c.spawn.foo(/* no message */).unwrap();
|
||||
}
|
||||
|
||||
#[task(spawn = [bar])]
|
||||
fn foo() {
|
||||
fn foo(c: foo::Context) {
|
||||
static mut COUNT: u32 = 0;
|
||||
|
||||
hprintln!("foo").unwrap();
|
||||
|
||||
spawn.bar(*COUNT).unwrap();
|
||||
c.spawn.bar(*COUNT).unwrap();
|
||||
*COUNT += 1;
|
||||
}
|
||||
|
||||
#[task(spawn = [baz])]
|
||||
fn bar(x: u32) {
|
||||
fn bar(c: bar::Context, x: u32) {
|
||||
hprintln!("bar({})", x).unwrap();
|
||||
|
||||
spawn.baz(x + 1, x + 2).unwrap();
|
||||
c.spawn.baz(x + 1, x + 2).unwrap();
|
||||
}
|
||||
|
||||
#[task(spawn = [foo])]
|
||||
fn baz(x: u32, y: u32) {
|
||||
fn baz(c: baz::Context, x: u32, y: u32) {
|
||||
hprintln!("baz({}, {})", x, y).unwrap();
|
||||
|
||||
if x + y > 4 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
spawn.foo().unwrap();
|
||||
c.spawn.foo().unwrap();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
|
|
@ -21,32 +21,32 @@ const APP: () = {
|
|||
static mut SHARED: Option<NotSend> = None;
|
||||
|
||||
#[init(spawn = [baz, quux])]
|
||||
fn init() {
|
||||
spawn.baz().unwrap();
|
||||
spawn.quux().unwrap();
|
||||
fn init(c: init::Context) {
|
||||
c.spawn.baz().unwrap();
|
||||
c.spawn.quux().unwrap();
|
||||
}
|
||||
|
||||
#[task(spawn = [bar])]
|
||||
fn foo() {
|
||||
fn foo(c: foo::Context) {
|
||||
// scenario 1: message passed to task that runs at the same priority
|
||||
spawn.bar(NotSend { _0: PhantomData }).ok();
|
||||
c.spawn.bar(NotSend { _0: PhantomData }).ok();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar(_x: NotSend) {
|
||||
fn bar(_: bar::Context, _x: NotSend) {
|
||||
// scenario 1
|
||||
}
|
||||
|
||||
#[task(priority = 2, resources = [SHARED])]
|
||||
fn baz() {
|
||||
fn baz(mut c: baz::Context) {
|
||||
// scenario 2: resource shared between tasks that run at the same priority
|
||||
*resources.SHARED = Some(NotSend { _0: PhantomData });
|
||||
*c.resources.SHARED = Some(NotSend { _0: PhantomData });
|
||||
}
|
||||
|
||||
#[task(priority = 2, resources = [SHARED])]
|
||||
fn quux() {
|
||||
fn quux(mut c: quux::Context) {
|
||||
// scenario 2
|
||||
let _not_send = resources.SHARED.take().unwrap();
|
||||
let _not_send = c.resources.SHARED.take().unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -10,29 +10,28 @@ extern crate panic_halt;
|
|||
use core::marker::PhantomData;
|
||||
|
||||
use cortex_m_semihosting::debug;
|
||||
use rtfm::app;
|
||||
|
||||
pub struct NotSync {
|
||||
_0: PhantomData<*const ()>,
|
||||
}
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static SHARED: NotSync = NotSync { _0: PhantomData };
|
||||
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#[task(resources = [SHARED])]
|
||||
fn foo() {
|
||||
let _: &NotSync = resources.SHARED;
|
||||
fn foo(c: foo::Context) {
|
||||
let _: &NotSync = c.resources.SHARED;
|
||||
}
|
||||
|
||||
#[task(resources = [SHARED])]
|
||||
fn bar() {
|
||||
let _: &NotSync = resources.SHARED;
|
||||
fn bar(c: bar::Context) {
|
||||
let _: &NotSync = c.resources.SHARED;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
|
|
@ -8,24 +8,24 @@
|
|||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use rtfm::{app, Instant};
|
||||
use rtfm::Instant;
|
||||
|
||||
const PERIOD: u32 = 8_000_000;
|
||||
|
||||
// NOTE: does NOT work on QEMU!
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(schedule = [foo])]
|
||||
fn init() {
|
||||
schedule.foo(Instant::now() + PERIOD.cycles()).unwrap();
|
||||
fn init(c: init::Context) {
|
||||
c.schedule.foo(Instant::now() + PERIOD.cycles()).unwrap();
|
||||
}
|
||||
|
||||
#[task(schedule = [foo])]
|
||||
fn foo() {
|
||||
fn foo(c: foo::Context) {
|
||||
let now = Instant::now();
|
||||
hprintln!("foo(scheduled = {:?}, now = {:?})", scheduled, now).unwrap();
|
||||
hprintln!("foo(scheduled = {:?}, now = {:?})", c.scheduled, now).unwrap();
|
||||
|
||||
schedule.foo(scheduled + PERIOD.cycles()).unwrap();
|
||||
c.schedule.foo(c.scheduled + PERIOD.cycles()).unwrap();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
|
|
@ -8,18 +8,17 @@
|
|||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [bar])]
|
||||
fn init() {
|
||||
spawn.bar().unwrap();
|
||||
fn init(c: init::Context) {
|
||||
c.spawn.bar().unwrap();
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
#[task]
|
||||
fn foo() {
|
||||
fn foo(_: foo::Context) {
|
||||
hprintln!("foo").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
@ -29,8 +28,8 @@ const APP: () = {
|
|||
#[inline(never)]
|
||||
#[link_section = ".data.bar"]
|
||||
#[task(priority = 2, spawn = [foo])]
|
||||
fn bar() {
|
||||
spawn.foo().unwrap();
|
||||
fn bar(c: bar::Context) {
|
||||
c.spawn.foo().unwrap();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
|
|
@ -9,21 +9,20 @@ extern crate panic_semihosting;
|
|||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
// A resource
|
||||
static mut SHARED: u32 = 0;
|
||||
|
||||
#[init]
|
||||
fn init() {
|
||||
fn init(_: init::Context) {
|
||||
rtfm::pend(Interrupt::UART0);
|
||||
rtfm::pend(Interrupt::UART1);
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle() -> ! {
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
// error: `SHARED` can't be accessed from this context
|
||||
|
@ -34,17 +33,17 @@ const APP: () = {
|
|||
|
||||
// `SHARED` can be access from this context
|
||||
#[interrupt(resources = [SHARED])]
|
||||
fn UART0() {
|
||||
*resources.SHARED += 1;
|
||||
fn UART0(mut c: UART0::Context) {
|
||||
*c.resources.SHARED += 1;
|
||||
|
||||
hprintln!("UART0: SHARED = {}", resources.SHARED).unwrap();
|
||||
hprintln!("UART0: SHARED = {}", c.resources.SHARED).unwrap();
|
||||
}
|
||||
|
||||
// `SHARED` can be access from this context
|
||||
#[interrupt(resources = [SHARED])]
|
||||
fn UART1() {
|
||||
*resources.SHARED += 1;
|
||||
fn UART1(mut c: UART1::Context) {
|
||||
*c.resources.SHARED += 1;
|
||||
|
||||
hprintln!("UART1: SHARED = {}", resources.SHARED).unwrap();
|
||||
hprintln!("UART1: SHARED = {}", c.resources.SHARED).unwrap();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,31 +8,31 @@
|
|||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use rtfm::{app, Instant};
|
||||
use rtfm::Instant;
|
||||
|
||||
// NOTE: does NOT work on QEMU!
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(schedule = [foo, bar])]
|
||||
fn init() {
|
||||
fn init(c: init::Context) {
|
||||
let now = Instant::now();
|
||||
|
||||
hprintln!("init @ {:?}", now).unwrap();
|
||||
|
||||
// Schedule `foo` to run 8e6 cycles (clock cycles) in the future
|
||||
schedule.foo(now + 8_000_000.cycles()).unwrap();
|
||||
c.schedule.foo(now + 8_000_000.cycles()).unwrap();
|
||||
|
||||
// Schedule `bar` to run 4e6 cycles in the future
|
||||
schedule.bar(now + 4_000_000.cycles()).unwrap();
|
||||
c.schedule.bar(now + 4_000_000.cycles()).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn foo() {
|
||||
fn foo(_: foo::Context) {
|
||||
hprintln!("foo @ {:?}", Instant::now()).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar() {
|
||||
fn bar(_: bar::Context) {
|
||||
hprintln!("bar @ {:?}", Instant::now()).unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,17 +18,17 @@ const APP: () = {
|
|||
static mut SHARED: Option<MustBeSend> = None;
|
||||
|
||||
#[init(resources = [SHARED])]
|
||||
fn init() {
|
||||
fn init(c: init::Context) {
|
||||
// this `message` will be sent to task `UART0`
|
||||
let message = MustBeSend;
|
||||
*resources.SHARED = Some(message);
|
||||
*c.resources.SHARED = Some(message);
|
||||
|
||||
rtfm::pend(Interrupt::UART0);
|
||||
}
|
||||
|
||||
#[interrupt(resources = [SHARED])]
|
||||
fn UART0() {
|
||||
if let Some(message) = resources.SHARED.take() {
|
||||
fn UART0(c: UART0::Context) {
|
||||
if let Some(message) = c.resources.SHARED.take() {
|
||||
// `message` has been received
|
||||
drop(message);
|
||||
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
//! examples/singleton.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use alloc_singleton::stable::pool::{Box, Pool};
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[Singleton(Send)]
|
||||
static mut M: [u32; 2] = [0; 2];
|
||||
|
||||
static mut P: Pool<M> = ();
|
||||
|
||||
#[init(resources = [M])]
|
||||
fn init() -> init::LateResources {
|
||||
rtfm::pend(Interrupt::I2C0);
|
||||
|
||||
init::LateResources {
|
||||
P: Pool::new(resources.M),
|
||||
}
|
||||
}
|
||||
|
||||
#[interrupt(
|
||||
priority = 2,
|
||||
resources = [P],
|
||||
spawn = [foo, bar],
|
||||
)]
|
||||
fn I2C0() {
|
||||
spawn.foo(resources.P.alloc(1).unwrap()).unwrap();
|
||||
spawn.bar(resources.P.alloc(2).unwrap()).unwrap();
|
||||
}
|
||||
|
||||
#[task(resources = [P])]
|
||||
fn foo(x: Box<M>) {
|
||||
hprintln!("foo({})", x).unwrap();
|
||||
|
||||
resources.P.lock(|p| p.dealloc(x));
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#[task(priority = 2, resources = [P])]
|
||||
fn bar(x: Box<M>) {
|
||||
hprintln!("bar({})", x).unwrap();
|
||||
|
||||
resources.P.dealloc(x);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn UART0();
|
||||
fn UART1();
|
||||
}
|
||||
};
|
|
@ -13,5 +13,5 @@ use rtfm::app;
|
|||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init() {}
|
||||
fn init(_: init::Context) {}
|
||||
};
|
||||
|
|
|
@ -9,14 +9,13 @@ extern crate panic_semihosting;
|
|||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static KEY: u32 = ();
|
||||
|
||||
#[init]
|
||||
fn init() -> init::LateResources {
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
rtfm::pend(Interrupt::UART0);
|
||||
rtfm::pend(Interrupt::UART1);
|
||||
|
||||
|
@ -24,14 +23,14 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt(resources = [KEY])]
|
||||
fn UART0() {
|
||||
hprintln!("UART0(KEY = {:#x})", resources.KEY).unwrap();
|
||||
fn UART0(c: UART0::Context) {
|
||||
hprintln!("UART0(KEY = {:#x})", c.resources.KEY).unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#[interrupt(priority = 2, resources = [KEY])]
|
||||
fn UART1() {
|
||||
hprintln!("UART1(KEY = {:#x})", resources.KEY).unwrap();
|
||||
fn UART1(c: UART1::Context) {
|
||||
hprintln!("UART1(KEY = {:#x})", c.resources.KEY).unwrap();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,38 +8,37 @@
|
|||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo])]
|
||||
fn init() {
|
||||
spawn.foo().unwrap();
|
||||
fn init(c: init::Context) {
|
||||
c.spawn.foo().unwrap();
|
||||
}
|
||||
|
||||
#[task(spawn = [bar, baz])]
|
||||
fn foo() {
|
||||
fn foo(c: foo::Context) {
|
||||
hprintln!("foo").unwrap();
|
||||
|
||||
// spawns `bar` onto the task scheduler
|
||||
// `foo` and `bar` have the same priority so `bar` will not run until
|
||||
// after `foo` terminates
|
||||
spawn.bar().unwrap();
|
||||
c.spawn.bar().unwrap();
|
||||
|
||||
// spawns `baz` onto the task scheduler
|
||||
// `baz` has higher priority than `foo` so it immediately preempts `foo`
|
||||
spawn.baz().unwrap();
|
||||
c.spawn.baz().unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar() {
|
||||
fn bar(_: bar::Context) {
|
||||
hprintln!("bar").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#[task(priority = 2)]
|
||||
fn baz() {
|
||||
fn baz(_: baz::Context) {
|
||||
hprintln!("baz").unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,45 +8,45 @@
|
|||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::debug;
|
||||
use rtfm::{app, Exclusive, Instant};
|
||||
use rtfm::{Exclusive, Instant};
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static mut SHARED: u32 = 0;
|
||||
|
||||
#[init(schedule = [foo], spawn = [foo])]
|
||||
fn init() {
|
||||
let _: Instant = start;
|
||||
let _: rtfm::Peripherals = core;
|
||||
let _: lm3s6965::Peripherals = device;
|
||||
let _: init::Schedule = schedule;
|
||||
let _: init::Spawn = spawn;
|
||||
fn init(c: init::Context) {
|
||||
let _: Instant = c.start;
|
||||
let _: rtfm::Peripherals = c.core;
|
||||
let _: lm3s6965::Peripherals = c.device;
|
||||
let _: init::Schedule = c.schedule;
|
||||
let _: init::Spawn = c.spawn;
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#[exception(schedule = [foo], spawn = [foo])]
|
||||
fn SVCall() {
|
||||
let _: Instant = start;
|
||||
let _: SVCall::Schedule = schedule;
|
||||
let _: SVCall::Spawn = spawn;
|
||||
fn SVCall(c: SVCall::Context) {
|
||||
let _: Instant = c.start;
|
||||
let _: SVCall::Schedule = c.schedule;
|
||||
let _: SVCall::Spawn = c.spawn;
|
||||
}
|
||||
|
||||
#[interrupt(resources = [SHARED], schedule = [foo], spawn = [foo])]
|
||||
fn UART0() {
|
||||
let _: Instant = start;
|
||||
let _: resources::SHARED = resources.SHARED;
|
||||
let _: UART0::Schedule = schedule;
|
||||
let _: UART0::Spawn = spawn;
|
||||
fn UART0(c: UART0::Context) {
|
||||
let _: Instant = c.start;
|
||||
let _: resources::SHARED = c.resources.SHARED;
|
||||
let _: UART0::Schedule = c.schedule;
|
||||
let _: UART0::Spawn = c.spawn;
|
||||
}
|
||||
|
||||
#[task(priority = 2, resources = [SHARED], schedule = [foo], spawn = [foo])]
|
||||
fn foo() {
|
||||
let _: Instant = scheduled;
|
||||
let _: Exclusive<u32> = resources.SHARED;
|
||||
let _: foo::Resources = resources;
|
||||
let _: foo::Schedule = schedule;
|
||||
let _: foo::Spawn = spawn;
|
||||
fn foo(c: foo::Context) {
|
||||
let _: Instant = c.scheduled;
|
||||
let _: Exclusive<u32> = c.resources.SHARED;
|
||||
let _: foo::Resources = c.resources;
|
||||
let _: foo::Schedule = c.schedule;
|
||||
let _: foo::Spawn = c.spawn;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
|
Loading…
Reference in a new issue