rtic/examples/periodic-preemption-payload.rs

176 lines
4 KiB
Rust
Raw Permalink Normal View History

// # Pointers (old)
//
// ~104~ 88 bytes .bss
//
// ## -Os
2018-05-04 05:39:06 +02:00
//
2018-05-14 21:22:50 +02:00
// a(st=16000000, now=16000248, input=0)
// b(st=24000000, now=24000251, input=0)
// a(st=32000000, now=32000248, input=1)
// b(st=48000000, now=48000283, input=1)
// a(st=48000000, now=48002427, input=2)
// a(st=64000000, now=64000248, input=3)
// b(st=72000000, now=72000251, input=2)
// a(st=80000000, now=80000248, input=4)
// b(st=96000000, now=96000283, input=3)
// a(st=96000000, now=96002427, input=5)
//
// ## -O3
//
2018-04-29 08:45:31 +02:00
// init
2018-05-14 21:22:50 +02:00
// a(st=16000000, now=16000231, input=0)
// b(st=24000000, now=24000230, input=0)
// a(st=32000000, now=32000231, input=1)
// b(st=48000000, now=48000259, input=1)
// a(st=48000000, now=48002397, input=2)
// a(st=64000000, now=64000231, input=3)
// b(st=72000000, now=72000230, input=2)
// a(st=80000000, now=80000231, input=4)
// b(st=96000000, now=96000259, input=3)
// a(st=96000000, now=96002397, input=5)
//
// # Indices (new)
//
// 56 bytes .bss
//
// ## -O3
//
2018-05-07 18:34:20 +02:00
// init
2018-05-14 21:22:50 +02:00
// a(st=16000000, now=16000193, input=0)
// b(st=24000000, now=24000196, input=0)
// a(st=32000000, now=32000193, input=1)
// b(st=48000000, now=48000225, input=1)
// a(st=48000000, now=48001958, input=2)
// a(st=64000000, now=64000193, input=3)
// b(st=72000000, now=72000196, input=2)
// a(st=80000000, now=80000193, input=4)
// b(st=96000000, now=96000225, input=3)
// a(st=96000000, now=96001958, input=5)
//
// ## -Os
//
// init
2018-05-14 21:22:50 +02:00
// a(st=16000000, now=16000257, input=0)
// b(st=24000000, now=24000252, input=0)
// a(st=32000000, now=32000257, input=1)
// b(st=48000000, now=48000284, input=1)
// a(st=48000000, now=48002326, input=2)
// a(st=64000000, now=64000257, input=3)
// b(st=72000000, now=72000252, input=2)
// a(st=80000000, now=80000257, input=4)
// b(st=96000000, now=96000284, input=3)
// a(st=96000000, now=96002326, input=5)
2018-04-29 08:45:31 +02:00
#![deny(unsafe_code)]
#![deny(warnings)]
2018-04-29 08:45:31 +02:00
#![feature(proc_macro)]
2018-05-29 12:23:09 +02:00
#![feature(proc_macro_gen)]
2018-05-14 21:22:50 +02:00
#![no_main]
2018-04-29 08:45:31 +02:00
#![no_std]
#[macro_use]
extern crate cortex_m;
2018-05-14 21:22:50 +02:00
#[macro_use]
extern crate cortex_m_rt as rt;
2018-04-29 08:45:31 +02:00
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
2018-04-29 08:45:31 +02:00
extern crate stm32f103xx;
use cortex_m::peripheral::{DWT, ITM};
2018-05-14 21:22:50 +02:00
use rt::ExceptionFrame;
2018-05-17 23:14:24 +02:00
use rtfm::app;
2018-04-29 08:45:31 +02:00
app! {
device: stm32f103xx,
resources: {
static ITM: ITM;
},
init: {
2018-05-14 21:22:50 +02:00
schedule_now: [a, b],
2018-04-29 08:45:31 +02:00
},
free_interrupts: [EXTI0, EXTI1],
tasks: {
a: {
2018-05-14 21:22:50 +02:00
schedule_after: [a],
2018-05-07 18:34:20 +02:00
input: u16,
2018-04-29 08:45:31 +02:00
resources: [ITM],
},
b: {
2018-05-14 21:22:50 +02:00
schedule_after: [b],
2018-05-07 18:34:20 +02:00
input: u16,
2018-04-29 08:45:31 +02:00
priority: 2,
resources: [ITM],
},
},
}
const MS: u32 = 8_000;
const S: u32 = 1_000 * MS;
#[inline(always)]
fn init(mut ctxt: init::Context) -> init::LateResources {
iprintln!(&mut ctxt.core.ITM.stim[0], "init");
2018-05-14 21:22:50 +02:00
ctxt.tasks.a.schedule_now(&mut ctxt.priority, 0).ok();
ctxt.tasks.b.schedule_now(&mut ctxt.priority, 0).ok();
2018-04-29 08:45:31 +02:00
init::LateResources { ITM: ctxt.core.ITM }
}
fn a(mut ctxt: a::Context) {
let now = DWT::get_cycle_count();
let input = ctxt.input;
2018-05-14 21:22:50 +02:00
let st = ctxt.scheduled_time;
ctxt.resources.ITM.claim_mut(&mut ctxt.priority, |itm, _| {
2018-04-29 08:45:31 +02:00
iprintln!(
&mut itm.stim[0],
2018-05-14 21:22:50 +02:00
"a(st={}, now={}, input={})",
st,
2018-04-29 08:45:31 +02:00
now,
input
);
});
2018-05-14 21:22:50 +02:00
ctxt.tasks
2018-04-29 08:45:31 +02:00
.a
2018-05-14 21:22:50 +02:00
.schedule_after(&mut ctxt.priority, 2 * S, input + 1)
2018-04-29 08:45:31 +02:00
.ok();
}
fn b(mut ctxt: b::Context) {
let now = DWT::get_cycle_count();
2018-05-14 21:22:50 +02:00
let st = ctxt.scheduled_time;
2018-04-29 08:45:31 +02:00
let input = ctxt.input;
2018-05-14 21:22:50 +02:00
let t = &mut ctxt.priority;
2018-04-29 08:45:31 +02:00
iprintln!(
&mut ctxt.resources.ITM.borrow_mut(t).stim[0],
2018-05-14 21:22:50 +02:00
"b(st={}, now={}, input={})",
st,
2018-04-29 08:45:31 +02:00
now,
input,
);
2018-05-14 21:22:50 +02:00
ctxt.tasks.b.schedule_after(t, 3 * S, input + 1).ok();
}
exception!(HardFault, hard_fault);
#[inline(always)]
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("HardFault at {:#?}", ef);
}
exception!(*, default_handler);
#[inline(always)]
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
2018-04-29 08:45:31 +02:00
}