This commit is contained in:
Jorge Aparicio 2018-05-14 21:22:50 +02:00
parent 09c2e99989
commit d665ea95b3
66 changed files with 2556 additions and 709 deletions

View file

@ -1,14 +1,18 @@
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate panic_semihosting;
extern crate stm32f103xx;
use cortex_m::asm;
use cortex_m_rt::ExceptionFrame;
use rtfm::app;
app! {
@ -26,3 +30,17 @@ fn idle(_ctxt: idle::Context) -> ! {
asm::wfi();
}
}
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);
}

View file

@ -1,14 +1,18 @@
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate stm32f103xx;
use cortex_m::asm;
use rt::ExceptionFrame;
use rtfm::app;
app! {
@ -34,3 +38,17 @@ fn idle(_ctxt: idle::Context) -> ! {
}
fn exti0(_ctxt: exti0::Context) {}
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);
}

View file

@ -5,16 +5,16 @@
// # -Os
//
// init
// a(bl=8000000, now=8000180, input=0)
// a(bl=16000000, now=16000180, input=1)
// a(bl=24000000, now=24000180, input=2)
// a(st=8000000, now=8000180, input=0)
// a(st=16000000, now=16000180, input=1)
// a(st=24000000, now=24000180, input=2)
//
// # -O3
//
// init
// a(bl=8000000, now=8000168, input=0)
// a(bl=16000000, now=16000168, input=1)
// a(bl=24000000, now=24000168, input=2)
// a(st=8000000, now=8000168, input=0)
// a(st=16000000, now=16000168, input=1)
// a(st=24000000, now=24000168, input=2)
//
// # Indices (new)
//
@ -23,28 +23,32 @@
// ## -O3
//
// init
// a(bl=8000000, now=8000164, input=0)
// a(bl=16000000, now=16000164, input=1)
// a(st=8000000, now=8000164, input=0)
// a(st=16000000, now=16000164, input=1)
//
// ## -Os
//
// init
// a(bl=8000000, now=8000179, input=0)
// a(bl=16000000, now=16000179, input=1)
// a(st=8000000, now=8000179, input=0)
// a(st=16000000, now=16000179, input=1)
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
#[macro_use]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate stm32f103xx;
use cortex_m::asm;
use cortex_m::peripheral::{DWT, ITM};
use rt::ExceptionFrame;
use rtfm::app;
app! {
@ -55,14 +59,14 @@ app! {
},
init: {
async_after: [a],
schedule_now: [a],
},
free_interrupts: [EXTI0],
tasks: {
a: {
async_after: [a],
schedule_after: [a],
input: u16,
resources: [ITM],
},
@ -76,7 +80,7 @@ const S: u32 = 1_000 * MS;
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, 0).ok();
ctxt.tasks.a.schedule_now(&mut ctxt.priority, 0).ok();
init::LateResources { ITM: ctxt.core.ITM }
}
@ -92,18 +96,32 @@ fn a(mut ctxt: a::Context) {
let now = DWT::get_cycle_count();
let input = ctxt.input;
let bl = ctxt.baseline;
let st = ctxt.scheduled_time;
let itm = ctxt.resources.ITM;
iprintln!(
&mut itm.stim[0],
"a(bl={}, now={}, input={})",
bl,
"a(st={}, now={}, input={})",
st,
now,
input
);
ctxt.async
ctxt.tasks
.a
.post(&mut ctxt.threshold, 1 * S, input + 1)
.schedule_after(&mut ctxt.priority, 1 * 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);
}

View file

@ -4,30 +4,30 @@
//
// ## -Os
//
// a(bl=16000000, now=16000248, input=0)
// b(bl=24000000, now=24000251, input=0)
// a(bl=32000000, now=32000248, input=1)
// b(bl=48000000, now=48000283, input=1)
// a(bl=48000000, now=48002427, input=2)
// a(bl=64000000, now=64000248, input=3)
// b(bl=72000000, now=72000251, input=2)
// a(bl=80000000, now=80000248, input=4)
// b(bl=96000000, now=96000283, input=3)
// a(bl=96000000, now=96002427, input=5)
// 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
//
// init
// a(bl=16000000, now=16000231, input=0)
// b(bl=24000000, now=24000230, input=0)
// a(bl=32000000, now=32000231, input=1)
// b(bl=48000000, now=48000259, input=1)
// a(bl=48000000, now=48002397, input=2)
// a(bl=64000000, now=64000231, input=3)
// b(bl=72000000, now=72000230, input=2)
// a(bl=80000000, now=80000231, input=4)
// b(bl=96000000, now=96000259, input=3)
// a(bl=96000000, now=96002397, input=5)
// 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)
//
@ -36,44 +36,48 @@
// ## -O3
//
// init
// a(bl=16000000, now=16000193, input=0)
// b(bl=24000000, now=24000196, input=0)
// a(bl=32000000, now=32000193, input=1)
// b(bl=48000000, now=48000225, input=1)
// a(bl=48000000, now=48001958, input=2)
// a(bl=64000000, now=64000193, input=3)
// b(bl=72000000, now=72000196, input=2)
// a(bl=80000000, now=80000193, input=4)
// b(bl=96000000, now=96000225, input=3)
// a(bl=96000000, now=96001958, input=5)
// 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
// a(bl=16000000, now=16000257, input=0)
// b(bl=24000000, now=24000252, input=0)
// a(bl=32000000, now=32000257, input=1)
// b(bl=48000000, now=48000284, input=1)
// a(bl=48000000, now=48002326, input=2)
// a(bl=64000000, now=64000257, input=3)
// b(bl=72000000, now=72000252, input=2)
// a(bl=80000000, now=80000257, input=4)
// b(bl=96000000, now=96000284, input=3)
// a(bl=96000000, now=96002326, input=5)
// 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)
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
#[macro_use]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate stm32f103xx;
use cortex_m::asm;
use cortex_m::peripheral::{DWT, ITM};
use rt::ExceptionFrame;
use rtfm::{app, Resource};
app! {
@ -84,20 +88,20 @@ app! {
},
init: {
async_after: [a, b],
schedule_now: [a, b],
},
free_interrupts: [EXTI0, EXTI1],
tasks: {
a: {
async_after: [a],
schedule_after: [a],
input: u16,
resources: [ITM],
},
b: {
async_after: [b],
schedule_after: [b],
input: u16,
priority: 2,
resources: [ITM],
@ -112,8 +116,8 @@ const S: u32 = 1_000 * MS;
fn init(mut ctxt: init::Context) -> init::LateResources {
iprintln!(&mut ctxt.core.ITM.stim[0], "init");
ctxt.async.a.post(&mut ctxt.threshold, 2 * S, 0).ok();
ctxt.async.b.post(&mut ctxt.threshold, 3 * S, 0).ok();
ctxt.tasks.a.schedule_now(&mut ctxt.priority, 0).ok();
ctxt.tasks.b.schedule_now(&mut ctxt.priority, 0).ok();
init::LateResources { ITM: ctxt.core.ITM }
}
@ -129,36 +133,50 @@ fn a(mut ctxt: a::Context) {
let now = DWT::get_cycle_count();
let input = ctxt.input;
let bl = ctxt.baseline;
ctxt.resources.ITM.claim_mut(&mut ctxt.threshold, |itm, _| {
let st = ctxt.scheduled_time;
ctxt.resources.ITM.claim_mut(&mut ctxt.priority, |itm, _| {
iprintln!(
&mut itm.stim[0],
"a(bl={}, now={}, input={})",
bl,
"a(st={}, now={}, input={})",
st,
now,
input
);
});
ctxt.async
ctxt.tasks
.a
.post(&mut ctxt.threshold, 2 * S, input + 1)
.schedule_after(&mut ctxt.priority, 2 * S, input + 1)
.ok();
}
fn b(mut ctxt: b::Context) {
let now = DWT::get_cycle_count();
let bl = ctxt.baseline;
let st = ctxt.scheduled_time;
let input = ctxt.input;
let t = &mut ctxt.threshold;
let t = &mut ctxt.priority;
iprintln!(
&mut ctxt.resources.ITM.borrow_mut(t).stim[0],
"b(bl={}, now={}, input={})",
bl,
"b(st={}, now={}, input={})",
st,
now,
input,
);
ctxt.async.b.post(t, 3 * S, input + 1).ok();
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);
}

View file

@ -65,16 +65,20 @@
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
#[macro_use]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate stm32f103xx;
use cortex_m::asm;
use cortex_m::peripheral::{DWT, ITM};
use rt::ExceptionFrame;
use rtfm::{app, Resource};
app! {
@ -85,19 +89,19 @@ app! {
},
init: {
async_after: [a, b],
schedule_now: [a, b],
},
free_interrupts: [EXTI0, EXTI1],
tasks: {
a: {
async_after: [a],
schedule_after: [a],
resources: [ITM],
},
b: {
async_after: [b],
schedule_after: [b],
priority: 2,
resources: [ITM],
},
@ -111,8 +115,8 @@ const S: u32 = 1_000 * MS;
fn init(mut ctxt: init::Context) -> init::LateResources {
iprintln!(&mut ctxt.core.ITM.stim[0], "init");
ctxt.async.a.post(&mut ctxt.threshold, 2 * S, ()).ok();
ctxt.async.b.post(&mut ctxt.threshold, 3 * S, ()).ok();
ctxt.tasks.a.schedule_now(&mut ctxt.priority).ok();
ctxt.tasks.b.schedule_now(&mut ctxt.priority).ok();
init::LateResources { ITM: ctxt.core.ITM }
}
@ -127,25 +131,39 @@ fn idle(_ctxt: idle::Context) -> ! {
fn a(mut ctxt: a::Context) {
let now = DWT::get_cycle_count();
let bl = ctxt.baseline;
ctxt.resources.ITM.claim_mut(&mut ctxt.threshold, |itm, _| {
iprintln!(&mut itm.stim[0], "a(bl={}, now={})", bl, now);
let st = ctxt.scheduled_time;
ctxt.resources.ITM.claim_mut(&mut ctxt.priority, |itm, _| {
iprintln!(&mut itm.stim[0], "a(st={}, now={})", st, now);
});
ctxt.async.a.post(&mut ctxt.threshold, 2 * S, ()).ok();
ctxt.tasks.a.schedule_after(&mut ctxt.priority, 2 * S).ok();
}
fn b(mut ctxt: b::Context) {
let now = DWT::get_cycle_count();
let bl = ctxt.baseline;
let t = &mut ctxt.threshold;
let st = ctxt.scheduled_time;
let t = &mut ctxt.priority;
iprintln!(
&mut ctxt.resources.ITM.borrow_mut(t).stim[0],
"b(bl={}, now={})",
bl,
"b(st={}, now={})",
st,
now
);
ctxt.async.b.post(t, 3 * S, ()).ok();
ctxt.tasks.b.schedule_after(t, 3 * S).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);
}

View file

@ -5,13 +5,13 @@
// ## -Os
//
// init
// a(bl=8000000, now=8000180)
// a(bl=16000000, now=16000180)
// a(st=8000000, now=8000180)
// a(st=16000000, now=16000180)
//
// ## -O3
//
// a(bl=8000000, now=8000168)
// a(bl=16000000, now=16000168)
// a(st=8000000, now=8000168)
// a(st=16000000, now=16000168)
//
// # Indices (new)
//
@ -20,29 +20,34 @@
// ## -Os
//
// init
// a(bl=8000000, now=8000176)
// a(bl=16000000, now=16000176)
// a(st=8000000, now=8000176)
// a(st=16000000, now=16000176)
//
// ## -O3
//
// init
// a(bl=0, now=68)
// a(bl=8000000, now=8000165)
// a(bl=16000000, now=16000165)
// a(st=0, now=68)
// a(st=8000000, now=8000165)
// a(st=16000000, now=16000165)
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
#[macro_use]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
// extern crate panic_itm;
extern crate stm32f103xx;
use cortex_m::asm;
use cortex_m::peripheral::{DWT, ITM};
use rt::ExceptionFrame;
use rtfm::app;
app! {
@ -53,14 +58,14 @@ app! {
},
init: {
async: [a],
schedule_now: [a],
},
free_interrupts: [EXTI0],
tasks: {
a: {
async_after: [a],
schedule_after: [a],
resources: [ITM],
},
},
@ -73,7 +78,7 @@ const S: u32 = 1_000 * MS;
fn init(mut ctxt: init::Context) -> init::LateResources {
iprintln!(&mut ctxt.core.ITM.stim[0], "init");
ctxt.async.a.post(&mut ctxt.threshold, ()).ok();
ctxt.tasks.a.schedule_now(&mut ctxt.priority).ok();
init::LateResources { ITM: ctxt.core.ITM }
}
@ -88,9 +93,23 @@ fn idle(_ctxt: idle::Context) -> ! {
fn a(mut ctxt: a::Context) {
let now = DWT::get_cycle_count();
let bl = ctxt.baseline;
let st = ctxt.scheduled_time;
let itm = ctxt.resources.ITM;
iprintln!(&mut itm.stim[0], "a(bl={}, now={})", bl, now);
iprintln!(&mut itm.stim[0], "a(st={}, now={})", st, now);
ctxt.async.a.post(&mut ctxt.threshold, 1 * S, ()).ok();
ctxt.tasks.a.schedule_after(&mut ctxt.priority, 1 * S).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);
}

View file

@ -1,15 +1,19 @@
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
#[macro_use]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate stm32f103xx;
use cortex_m::asm;
use cortex_m::peripheral::{DWT, ITM};
use rt::ExceptionFrame;
use rtfm::app;
app! {
@ -24,7 +28,7 @@ app! {
tasks: {
exti0: {
interrupt: EXTI0,
async_after: [a],
schedule_after: [a],
resources: [ITM],
},
@ -38,7 +42,7 @@ const S: u32 = 8_000_000;
#[inline(always)]
fn init(ctxt: init::Context) -> init::LateResources {
unsafe { rtfm::set_pending(stm32f103xx::Interrupt::EXTI0) }
rtfm::_impl::trigger(stm32f103xx::Interrupt::EXTI0);
init::LateResources { ITM: ctxt.core.ITM }
}
@ -54,21 +58,35 @@ fn exti0(mut ctxt: exti0::Context) {
let now = DWT::get_cycle_count();
iprintln!(
&mut ctxt.resources.ITM.stim[0],
"exti0(bl={}, now={})",
ctxt.baseline,
"exti0(st={}, now={})",
ctxt.start_time,
now
);
let t = &mut ctxt.threshold;
ctxt.async.a.post(t, 1 * S, ()).ok();
let t = &mut ctxt.priority;
ctxt.tasks.a.schedule_after(t, 1 * S).ok();
}
fn a(ctxt: a::Context) {
let now = DWT::get_cycle_count();
iprintln!(
&mut ctxt.resources.ITM.stim[0],
"a(bl={}, now={})",
ctxt.baseline,
"a(st={}, now={})",
ctxt.scheduled_time,
now
);
}
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);
}

View file

@ -1,14 +1,18 @@
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate stm32f103xx;
use cortex_m::asm;
use rt::ExceptionFrame;
use rtfm::app;
app! {
@ -19,7 +23,7 @@ app! {
tasks: {
exti0: {
interrupt: EXTI0,
async_after: [a],
schedule_after: [a],
},
a: {},
@ -41,9 +45,21 @@ fn idle(_ctxt: idle::Context) -> ! {
}
fn exti0(mut ctxt: exti0::Context) {
ctxt.async.a.post(&mut ctxt.threshold, 1 * S, ()).ok();
ctxt.tasks.a.schedule_after(&mut ctxt.priority, 1 * S).ok();
}
fn a(_ctxt: a::Context) {
asm::bkpt();
}
exception!(HardFault, hard_fault);
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("HardFault at {:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}

View file

@ -1,15 +1,19 @@
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
#[macro_use]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate stm32f103xx;
use cortex_m::asm;
use cortex_m::peripheral::{DWT, ITM};
use rt::ExceptionFrame;
use rtfm::app;
app! {
@ -24,7 +28,7 @@ app! {
tasks: {
exti0: {
interrupt: EXTI0,
async: [a],
schedule_now: [a],
resources: [ITM],
},
@ -36,7 +40,7 @@ app! {
#[inline(always)]
fn init(ctxt: init::Context) -> init::LateResources {
unsafe { rtfm::set_pending(stm32f103xx::Interrupt::EXTI0) }
rtfm::_impl::trigger(stm32f103xx::Interrupt::EXTI0);
init::LateResources { ITM: ctxt.core.ITM }
}
@ -52,21 +56,35 @@ fn exti0(mut ctxt: exti0::Context) {
let now = DWT::get_cycle_count();
iprintln!(
&mut ctxt.resources.ITM.stim[0],
"exti0(bl={}, now={})",
ctxt.baseline,
"exti0(st={}, now={})",
ctxt.start_time,
now
);
let t = &mut ctxt.threshold;
ctxt.async.a.post(t, ()).ok();
let t = &mut ctxt.priority;
ctxt.tasks.a.schedule_now(t).ok();
}
fn a(ctxt: a::Context) {
let now = DWT::get_cycle_count();
iprintln!(
&mut ctxt.resources.ITM.stim[0],
"a(bl={}, now={})",
ctxt.baseline,
"a(st={}, now={})",
ctxt.scheduled_time,
now
);
}
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);
}

View file

@ -9,21 +9,25 @@
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate panic_semihosting;
extern crate stm32f103xx;
use cortex_m::asm;
use rt::ExceptionFrame;
use rtfm::app;
app! {
device: stm32f103xx,
init: {
async: [a],
schedule_now: [a],
},
free_interrupts: [EXTI1],
@ -31,7 +35,7 @@ app! {
tasks: {
exti0: {
interrupt: EXTI0,
async: [a],
schedule_now: [a],
},
a: {},
@ -39,7 +43,9 @@ app! {
}
#[inline(always)]
fn init(_ctxt: init::Context) -> init::LateResources {
fn init(mut ctxt: init::Context) -> init::LateResources {
ctxt.tasks.a.schedule_now(&mut ctxt.priority).unwrap();
init::LateResources {}
}
@ -51,9 +57,21 @@ fn idle(_ctxt: idle::Context) -> ! {
}
fn exti0(mut ctxt: exti0::Context) {
ctxt.async.a.post(&mut ctxt.threshold, ()).ok();
ctxt.tasks.a.schedule_now(&mut ctxt.priority).ok();
}
fn a(_ctxt: a::Context) {
asm::bkpt();
}
exception!(HardFault, hard_fault);
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("HardFault at {:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}

View file

@ -1,14 +1,18 @@
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_main]
#![no_std]
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_rtfm as rtfm;
extern crate panic_abort;
extern crate stm32f103xx;
use cortex_m::asm;
use rt::ExceptionFrame;
use rtfm::app;
pub struct Foo(u32);
@ -24,8 +28,8 @@ app! {
free_interrupts: [EXTI0],
init: {
async: [a],
async_after: [b],
schedule_now: [a],
schedule_after: [b],
},
tasks: {
@ -54,3 +58,17 @@ fn idle(_ctxt: idle::Context) -> ! {
fn a(_ctxt: a::Context) {}
fn b(_ctxt: b::Context) {}
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);
}