rtic/examples/periodic.rs

96 lines
1.6 KiB
Rust
Raw Normal View History

// # Pointers (old)
//
// ~52~ 40 bytes .bss
//
// ## -Os
2018-05-04 05:39:06 +02:00
//
2018-04-29 08:45:31 +02:00
// init
// a(bl=8000000, now=8000180)
// a(bl=16000000, now=16000180)
//
// ## -O3
//
2018-04-29 08:45:31 +02:00
// a(bl=8000000, now=8000168)
// a(bl=16000000, now=16000168)
//
// # Indices (new)
//
// 28 bytes .bss
//
// ## -Os
//
// init
// a(bl=8000000, now=8000176)
// a(bl=16000000, now=16000176)
//
// ## -O3
//
// init
// a(bl=8000000, now=8000167)
// a(bl=16000000, now=16000167)
2018-04-29 08:45:31 +02:00
#![deny(unsafe_code)]
#![deny(warnings)]
2018-04-29 08:45:31 +02:00
#![feature(proc_macro)]
#![no_std]
#[macro_use]
extern crate cortex_m;
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::asm;
use cortex_m::peripheral::{DWT, ITM};
use rtfm::app;
2018-04-29 08:45:31 +02:00
app! {
device: stm32f103xx,
resources: {
static ITM: ITM;
},
init: {
async_after: [a],
},
free_interrupts: [EXTI0],
tasks: {
a: {
async_after: [a],
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");
ctxt.async.a.post(&mut ctxt.threshold, 1 * S, ()).ok();
init::LateResources { ITM: ctxt.core.ITM }
}
#[inline(always)]
fn idle(_ctxt: idle::Context) -> ! {
2018-04-29 08:45:31 +02:00
loop {
asm::wfi();
}
}
fn a(mut ctxt: a::Context) {
let now = DWT::get_cycle_count();
let bl = ctxt.baseline;
let itm = ctxt.resources.ITM;
iprintln!(&mut itm.stim[0], "a(bl={}, now={})", bl, now);
ctxt.async.a.post(&mut ctxt.threshold, 1 * S, ()).ok();
}