2018-05-04 10:59:23 +02:00
|
|
|
// # Pointers (old)
|
|
|
|
//
|
|
|
|
// ~52~ 40 bytes .bss
|
|
|
|
//
|
|
|
|
// ## -Os
|
2018-05-04 05:39:06 +02:00
|
|
|
//
|
2018-04-29 08:45:31 +02:00
|
|
|
// init
|
2018-05-14 21:22:50 +02:00
|
|
|
// a(st=8000000, now=8000180)
|
|
|
|
// a(st=16000000, now=16000180)
|
2018-04-29 08:45:31 +02:00
|
|
|
//
|
2018-05-04 10:59:23 +02:00
|
|
|
// ## -O3
|
|
|
|
//
|
2018-05-14 21:22:50 +02:00
|
|
|
// a(st=8000000, now=8000168)
|
|
|
|
// a(st=16000000, now=16000168)
|
2018-05-04 10:59:23 +02:00
|
|
|
//
|
|
|
|
// # Indices (new)
|
|
|
|
//
|
2018-05-07 18:34:20 +02:00
|
|
|
// 32 bytes .bss
|
2018-05-04 10:59:23 +02:00
|
|
|
//
|
|
|
|
// ## -Os
|
|
|
|
//
|
|
|
|
// init
|
2018-05-14 21:22:50 +02:00
|
|
|
// a(st=8000000, now=8000176)
|
|
|
|
// a(st=16000000, now=16000176)
|
2018-05-04 10:59:23 +02:00
|
|
|
//
|
|
|
|
// ## -O3
|
|
|
|
//
|
|
|
|
// init
|
2018-05-14 21:22:50 +02:00
|
|
|
// a(st=0, now=68)
|
|
|
|
// a(st=8000000, now=8000165)
|
|
|
|
// a(st=16000000, now=16000165)
|
2018-04-29 08:45:31 +02:00
|
|
|
|
2018-05-01 12:05:53 +02:00
|
|
|
#![deny(unsafe_code)]
|
|
|
|
#![deny(warnings)]
|
2018-04-29 08:45:31 +02:00
|
|
|
#![feature(proc_macro)]
|
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;
|
2018-05-01 12:05:53 +02:00
|
|
|
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-01 12:05:53 +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],
|
2018-04-29 08:45:31 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
free_interrupts: [EXTI0],
|
|
|
|
|
|
|
|
tasks: {
|
|
|
|
a: {
|
2018-05-14 21:22:50 +02:00
|
|
|
schedule_after: [a],
|
2018-04-29 08:45:31 +02:00
|
|
|
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).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();
|
|
|
|
|
2018-05-14 21:22:50 +02:00
|
|
|
let st = ctxt.scheduled_time;
|
2018-04-29 08:45:31 +02:00
|
|
|
let itm = ctxt.resources.ITM;
|
2018-05-14 21:22:50 +02:00
|
|
|
iprintln!(&mut itm.stim[0], "a(st={}, now={})", st, now);
|
|
|
|
|
|
|
|
ctxt.tasks.a.schedule_after(&mut ctxt.priority, 1 * S).ok();
|
|
|
|
}
|
2018-04-29 08:45:31 +02:00
|
|
|
|
2018-05-14 21:22:50 +02:00
|
|
|
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
|
|
|
}
|