update tests and examples

with task! gone 3 types of errors / gotchas have been eliminated 🎉
This commit is contained in:
Jorge Aparicio 2017-07-27 11:40:15 -05:00
parent 0b5afce771
commit aa22494549
17 changed files with 68 additions and 230 deletions

View file

@ -5,7 +5,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -16,6 +15,7 @@ app! {
resources: { resources: {
static CO_OWNED: u32 = 0; static CO_OWNED: u32 = 0;
static ON: bool = false;
static OWNED: bool = false; static OWNED: bool = false;
static SHARED: bool = false; static SHARED: bool = false;
}, },
@ -31,12 +31,14 @@ app! {
tasks: { tasks: {
SYS_TICK: { SYS_TICK: {
path: sys_tick,
priority: 1, priority: 1,
resources: [CO_OWNED, SHARED], resources: [CO_OWNED, ON, SHARED],
}, },
TIM2: { TIM2: {
enabled: true, enabled: true,
path: tim2,
priority: 1, priority: 1,
resources: [CO_OWNED], resources: [CO_OWNED],
}, },
@ -59,18 +61,12 @@ fn idle_(t: &mut Threshold, mut r: idle::Resources) -> ! {
} }
} }
task!(SYS_TICK, sys_tick, Local { fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
static STATE: bool = true; **r.ON = !**r.ON;
});
fn sys_tick(_t: &mut Threshold, l: &mut Local, r: SYS_TICK::Resources) {
*l.STATE = !*l.STATE;
**r.CO_OWNED += 1; **r.CO_OWNED += 1;
} }
task!(TIM2, tim2);
fn tim2(_t: &mut Threshold, r: TIM2::Resources) { fn tim2(_t: &mut Threshold, r: TIM2::Resources) {
**r.CO_OWNED += 1; **r.CO_OWNED += 1;
} }

View file

@ -4,7 +4,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -17,12 +16,14 @@ app! {
tasks: { tasks: {
EXTI0: { EXTI0: {
enabled: true, enabled: true,
path: exti0,
priority: 1, priority: 1,
resources: [GPIOA, SPI1], resources: [GPIOA, SPI1],
}, },
EXTI1: { EXTI1: {
enabled: true, enabled: true,
path: exti1,
priority: 2, priority: 2,
resources: [GPIOA, SPI1], resources: [GPIOA, SPI1],
}, },
@ -54,15 +55,11 @@ where
}); });
} }
task!(EXTI0, exti0);
// this task needs critical sections to access the resources // this task needs critical sections to access the resources
fn exti0(t: &mut Threshold, r: EXTI0::Resources) { fn exti0(t: &mut Threshold, r: EXTI0::Resources) {
work(t, &r.GPIOA, &r.SPI1); work(t, &r.GPIOA, &r.SPI1);
} }
task!(EXTI1, exti1);
// this task has direct access to the resources // this task has direct access to the resources
fn exti1(t: &mut Threshold, r: EXTI1::Resources) { fn exti1(t: &mut Threshold, r: EXTI1::Resources) {
work(t, r.GPIOA, r.SPI1); work(t, r.GPIOA, r.SPI1);

View file

@ -1,11 +1,9 @@
//! Using paths and modules //! Using paths and modules
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -16,6 +14,7 @@ app! {
resources: { resources: {
static CO_OWNED: u32 = 0; static CO_OWNED: u32 = 0;
static ON: bool = false;
static OWNED: bool = false; static OWNED: bool = false;
static SHARED: bool = false; static SHARED: bool = false;
}, },
@ -31,12 +30,14 @@ app! {
tasks: { tasks: {
SYS_TICK: { SYS_TICK: {
path: tasks::sys_tick,
priority: 1, priority: 1,
resources: [CO_OWNED, SHARED], resources: [CO_OWNED, ON, SHARED],
}, },
TIM2: { TIM2: {
enabled: true, enabled: true,
path: tasks::tim2,
priority: 1, priority: 1,
resources: [CO_OWNED], resources: [CO_OWNED],
}, },
@ -66,19 +67,13 @@ mod main {
pub mod tasks { pub mod tasks {
use rtfm::Threshold; use rtfm::Threshold;
task!(SYS_TICK, sys_tick, Locals { pub fn sys_tick(_t: &mut Threshold, r: ::SYS_TICK::Resources) {
static STATE: bool = true; **r.ON = !**r.ON;
});
fn sys_tick(_t: &mut Threshold, l: &mut Locals, r: ::SYS_TICK::Resources) {
*l.STATE = !*l.STATE;
**r.CO_OWNED += 1; **r.CO_OWNED += 1;
} }
task!(TIM2, tim2); pub fn tim2(_t: &mut Threshold, r: ::TIM2::Resources) {
fn tim2(_t: &mut Threshold, r: ::TIM2::Resources) {
**r.CO_OWNED += 1; **r.CO_OWNED += 1;
} }
} }

View file

@ -8,7 +8,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -26,18 +25,21 @@ app! {
tasks: { tasks: {
EXTI0: { EXTI0: {
enabled: true, enabled: true,
path: exti0,
priority: 1, priority: 1,
resources: [LOW, HIGH], resources: [LOW, HIGH],
}, },
EXTI1: { EXTI1: {
enabled: true, enabled: true,
path: exti1,
priority: 2, priority: 2,
resources: [LOW], resources: [LOW],
}, },
EXTI2: { EXTI2: {
enabled: true, enabled: true,
path: exti2,
priority: 3, priority: 3,
resources: [HIGH], resources: [HIGH],
}, },
@ -58,8 +60,6 @@ fn idle() -> ! {
} }
} }
task!(EXTI0, exti0);
fn exti0(t: &mut Threshold, r: EXTI0::Resources) { fn exti0(t: &mut Threshold, r: EXTI0::Resources) {
// because this task has a priority of 1 the preemption threshold is also 1 // because this task has a priority of 1 the preemption threshold is also 1
@ -113,15 +113,11 @@ fn exti0(t: &mut Threshold, r: EXTI0::Resources) {
// ~> exti1 // ~> exti1
} }
task!(EXTI1, exti1);
fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) { fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {
// B, H // B, H
rtfm::bkpt(); rtfm::bkpt();
} }
task!(EXTI2, exti2);
fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) { fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) {
// D, G // D, G
rtfm::bkpt(); rtfm::bkpt();

View file

@ -1,12 +1,10 @@
//! An application with one task //! An application with one task
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
extern crate cortex_m; extern crate cortex_m;
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -16,6 +14,15 @@ use rtfm::{app, Threshold};
app! { app! {
device: stm32f103xx, device: stm32f103xx,
// Here resources are declared
//
// Resources are static variables that are safe to share across tasks
resources: {
// declaration of resources looks exactly like declaration of static
// variables
static ON: bool = false;
},
// Here tasks are declared // Here tasks are declared
// //
// Each task corresponds to an interrupt or an exception. Every time the // Each task corresponds to an interrupt or an exception. Every time the
@ -24,7 +31,11 @@ app! {
tasks: { tasks: {
// Here we declare that we'll use the SYS_TICK exception as a task // Here we declare that we'll use the SYS_TICK exception as a task
SYS_TICK: { SYS_TICK: {
// Path to the task *handler*
path: sys_tick,
// This is the priority of the task. // This is the priority of the task.
//
// 1 is the lowest priority a task can have. // 1 is the lowest priority a task can have.
// The maximum priority is determined by the number of priority bits // The maximum priority is determined by the number of priority bits
// the device has. This device has 4 priority bits so 16 is the // the device has. This device has 4 priority bits so 16 is the
@ -34,12 +45,12 @@ app! {
// These are the *resources* associated with this task // These are the *resources* associated with this task
// //
// The peripherals that the task needs can be listed here // The peripherals that the task needs can be listed here
resources: [GPIOC], resources: [GPIOC, ON],
}, },
} }
} }
fn init(p: init::Peripherals) { fn init(p: init::Peripherals, _r: init::Resources) {
// power on GPIOC // power on GPIOC
p.RCC.apb2enr.modify(|_, w| w.iopcen().enabled()); p.RCC.apb2enr.modify(|_, w| w.iopcen().enabled());
@ -62,26 +73,15 @@ fn idle() -> ! {
} }
} }
// This binds the `sys_tick` handler to the `SYS_TICK` task
//
// This particular handler has local state associated to it. The value of the
// `STATE` variable will be preserved across invocations of this handler
task!(SYS_TICK, sys_tick, Locals {
static STATE: bool = false;
});
// This is the task handler of the SYS_TICK exception // This is the task handler of the SYS_TICK exception
// //
// `t` is the preemption threshold token. We won't use it this time.
// `l` is the data local to this task. The type here must match the one declared
// in `task!`.
// `r` is the resources this task has access to. `SYS_TICK::Resources` has one // `r` is the resources this task has access to. `SYS_TICK::Resources` has one
// field per resource declared in `app!`. // field per every resource declared in `app!`.
fn sys_tick(_t: &mut Threshold, l: &mut Locals, r: SYS_TICK::Resources) { fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
// toggle state // toggle state
*l.STATE = !*l.STATE; **r.ON = !**r.ON;
if *l.STATE { if **r.ON {
// set the pin PC13 high // set the pin PC13 high
r.GPIOC.bsrr.write(|w| w.bs13().set()); r.GPIOC.bsrr.write(|w| w.bs13().set());
} else { } else {

View file

@ -1,11 +1,9 @@
//! Two tasks running at different priorities with access to the same resource //! Two tasks running at different priorities with access to the same resource
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -21,12 +19,14 @@ app! {
tasks: { tasks: {
// the task `SYS_TICK` has higher priority than `TIM2` // the task `SYS_TICK` has higher priority than `TIM2`
SYS_TICK: { SYS_TICK: {
path: sys_tick,
priority: 2, priority: 2,
resources: [COUNTER], resources: [COUNTER],
}, },
TIM2: { TIM2: {
enabled: true, enabled: true,
path: tim2,
priority: 1, priority: 1,
resources: [COUNTER], resources: [COUNTER],
}, },
@ -43,8 +43,6 @@ fn idle() -> ! {
} }
} }
task!(SYS_TICK, sys_tick);
fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
// .. // ..
@ -55,8 +53,6 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
// .. // ..
} }
task!(TIM2, tim2);
fn tim2(t: &mut Threshold, mut r: TIM2::Resources) { fn tim2(t: &mut Threshold, mut r: TIM2::Resources) {
// .. // ..

View file

@ -5,7 +5,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -23,6 +22,7 @@ app! {
tasks: { tasks: {
SYS_TICK: { SYS_TICK: {
path: sys_tick,
priority: 1, priority: 1,
// Both this task and TIM2 have access to the `COUNTER` resource // Both this task and TIM2 have access to the `COUNTER` resource
resources: [COUNTER], resources: [COUNTER],
@ -34,6 +34,7 @@ app! {
// indicates if the interrupt will be enabled or disabled once // indicates if the interrupt will be enabled or disabled once
// `idle` starts // `idle` starts
enabled: true, enabled: true,
path: tim2,
priority: 1, priority: 1,
resources: [COUNTER], resources: [COUNTER],
}, },
@ -52,8 +53,6 @@ fn idle() -> ! {
} }
} }
task!(SYS_TICK, sys_tick);
// As both tasks are running at the same priority one can't preempt the other. // As both tasks are running at the same priority one can't preempt the other.
// Thus both tasks have direct access to the resource // Thus both tasks have direct access to the resource
fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
@ -64,8 +63,6 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
// .. // ..
} }
task!(TIM2, tim2);
fn tim2(_t: &mut Threshold, r: TIM2::Resources) { fn tim2(_t: &mut Threshold, r: TIM2::Resources) {
// .. // ..

View file

@ -3,7 +3,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -13,18 +12,19 @@ app! {
device: stm32f103xx, device: stm32f103xx,
resources: { resources: {
static STATE: bool = false; static ON: bool = false;
}, },
idle: { idle: {
resources: [STATE], resources: [ON],
}, },
tasks: { tasks: {
EXTI0: { EXTI0: {
enabled: true, enabled: true,
path: exti0,
priority: 1, priority: 1,
resources: [STATE], resources: [ON],
}, },
}, },
} }
@ -32,12 +32,12 @@ app! {
fn init(_p: init::Peripherals, _r: init::Resources) {} fn init(_p: init::Peripherals, _r: init::Resources) {}
fn idle(t: &mut Threshold, r: idle::Resources) -> ! { fn idle(t: &mut Threshold, r: idle::Resources) -> ! {
let state = rtfm::atomic(|cs| { let state = rtfm::atomic(t, |t| {
// ERROR borrow can't escape this *global* critical section // ERROR borrow can't escape this *global* critical section
r.STATE.borrow(cs) //~ error cannot infer an appropriate lifetime r.ON.borrow(t) //~ error cannot infer an appropriate lifetime
}); });
let state = r.STATE.claim(t, |state, _t| { let state = r.ON.claim(t, |state, _t| {
// ERROR borrow can't escape this critical section // ERROR borrow can't escape this critical section
state //~ error cannot infer an appropriate lifetime state //~ error cannot infer an appropriate lifetime
}); });
@ -45,6 +45,4 @@ fn idle(t: &mut Threshold, r: idle::Resources) -> ! {
loop {} loop {}
} }
task!(EXTI0, exti0);
fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {}

View file

@ -1,40 +0,0 @@
#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! {
device: stm32f103xx,
resources: {
static ON: bool = false;
},
tasks: {
EXTI0: {
enabled: true,
path: exti0,
priority: 1,
resources: [ON],
},
},
}
fn init(_p: init::Peripherals, _r: init::Resources) {}
fn idle() -> ! {
loop {}
}
fn exti0(_r: EXTI0::Resources) {}
// ERROR can't override the task handler specified in `app!`
task!(EXTI0, exti1);
//~^ error cannot find value `EXTI0`
fn exti1(_t: &mut Threshold, _r: EXTI0::Resources) {}

View file

@ -1,36 +0,0 @@
// error-pattern: the name `EXTI0` is defined multiple times
#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! {
device: stm32f103xx,
tasks: {
EXTI0: {
enabled: true,
priority: 1,
},
},
}
fn init(_p: init::Peripherals) {}
fn idle() -> ! {
loop {}
}
task!(EXTI0, exti0);
fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {}
task!(EXTI0, exti1);
fn exti1(_t: &mut Threshold, _r: EXTI0::Resources) {}

View file

@ -1,45 +0,0 @@
#![deny(warnings)]
#![feature(const_fn)]
#![feature(proc_macro)]
#![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! {
device: stm32f103xx,
tasks: {
EXTI0: {
enabled: true,
priority: 1,
},
}
}
fn init(_p: init::Peripherals) {}
fn idle() -> ! {
loop {}
}
task!(EXTI0, exti0, Old {
static TOKEN: Option<Threshold> = None;
});
fn exti0(nt: &mut Threshold, old: &mut Old, _r: EXTI0::Resources) {
if let Some(ot) = old.TOKEN.take() {
let _: (Threshold, Threshold) = (*nt, ot);
//~^ error cannot move out of borrowed content
return
}
// ERROR can't store a threshold token in a local variable, otherwise you
// would end up with two threshold tokens in a task (see `if let` above)
*old.TOKEN = Some(*nt);
//~^ error cannot move out of borrowed content
}

View file

@ -3,7 +3,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -13,25 +12,28 @@ app! {
device: stm32f103xx, device: stm32f103xx,
resources: { resources: {
static STATE: bool = false; static ON: bool = false;
static MAX: u8 = 0; static MAX: u8 = 0;
}, },
tasks: { tasks: {
EXTI0: { EXTI0: {
enabled: true, enabled: true,
path: exti0,
priority: 1, priority: 1,
resources: [MAX, STATE], resources: [MAX, ON],
}, },
EXTI1: { EXTI1: {
enabled: true, enabled: true,
path: exti1,
priority: 2, priority: 2,
resources: [STATE], resources: [ON],
}, },
EXTI2: { EXTI2: {
enabled: true, enabled: true,
path: exti2,
priority: 16, priority: 16,
resources: [MAX], resources: [MAX],
}, },
@ -44,29 +46,23 @@ fn idle() -> ! {
loop {} loop {}
} }
task!(EXTI0, exti0);
fn exti0(mut t: &mut Threshold, mut r: EXTI0::Resources) { fn exti0(mut t: &mut Threshold, mut r: EXTI0::Resources) {
// OK need to lock to access the resource // OK need to lock to access the resource
if r.STATE.claim(&mut t, |state, _| **state) {} if r.ON.claim(&mut t, |on, _| **on) {}
// OK can claim a resource with maximum ceiling // OK can claim a resource with maximum ceiling
r.MAX.claim_mut(&mut t, |max, _| **max += 1); r.MAX.claim_mut(&mut t, |max, _| **max += 1);
} }
task!(EXTI1, exti1);
fn exti1(mut t: &mut Threshold, r: EXTI1::Resources) { fn exti1(mut t: &mut Threshold, r: EXTI1::Resources) {
// ERROR no need to lock. Has direct access because priority == ceiling // ERROR no need to lock. Has direct access because priority == ceiling
if (**r.STATE).claim(&mut t, |state, _| **state) { if (**r.ON).claim(&mut t, |on, _| **on) {
//~^ error no method named `claim` found for type //~^ error no method named `claim` found for type
} }
if **r.STATE { if **r.ON {
// OK // OK
} }
} }
task!(EXTI2, exti2);
fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) {} fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) {}

View file

@ -2,17 +2,17 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
use rtfm::{app, Threshold}; use rtfm::app;
app! { //~ error attempt to subtract with overflow app! { //~ error attempt to subtract with overflow
device: stm32f103xx, device: stm32f103xx,
tasks: { tasks: {
SYS_TICK: { SYS_TICK: {
path: sys_tick,
// ERROR priority must be in the range [1, 16] // ERROR priority must be in the range [1, 16]
priority: 17, priority: 17,
}, },
@ -25,6 +25,4 @@ fn idle() -> ! {
loop {} loop {}
} }
task!(SYS_TICK, sys_tick); fn sys_tick() {}
fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {}

View file

@ -2,17 +2,17 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
use rtfm::{app, Threshold}; use rtfm::app;
app! { //~ error attempt to subtract with overflow app! { //~ error attempt to subtract with overflow
device: stm32f103xx, device: stm32f103xx,
tasks: { tasks: {
SYS_TICK: { SYS_TICK: {
path: sys_tick,
// ERROR priority must be in the range [1, 16] // ERROR priority must be in the range [1, 16]
priority: 0, priority: 0,
}, },
@ -25,6 +25,4 @@ fn idle() -> ! {
loop {} loop {}
} }
task!(SYS_TICK, sys_tick); fn sys_tick() {}
fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {}

View file

@ -3,7 +3,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -19,12 +18,14 @@ app! {
tasks: { tasks: {
EXTI0: { EXTI0: {
enabled: true, enabled: true,
path: exti0,
priority: 1, priority: 1,
resources: [STATE], resources: [STATE],
}, },
EXTI1: { EXTI1: {
enabled: true, enabled: true,
path: exti1,
priority: 2, priority: 2,
resources: [STATE], resources: [STATE],
}, },
@ -37,14 +38,10 @@ fn idle() -> ! {
loop {} loop {}
} }
task!(EXTI0, exti0);
fn exti0(mut t: &mut Threshold, r: EXTI0::Resources) { fn exti0(mut t: &mut Threshold, r: EXTI0::Resources) {
// ERROR token should not outlive the critical section // ERROR token should not outlive the critical section
let t = r.STATE.claim(&mut t, |_state, t| t); let t = r.STATE.claim(&mut t, |_state, t| t);
//~^ error cannot infer an appropriate lifetime //~^ error cannot infer an appropriate lifetime
} }
task!(EXTI1, exti1);
fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {}

View file

@ -3,7 +3,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -19,6 +18,7 @@ app! { //~ error bound `rtfm::Threshold: core::marker::Send` is not satisfied
tasks: { tasks: {
EXTI0: { EXTI0: {
enabled: true, enabled: true,
path: exti0,
priority: 1, priority: 1,
resources: [TOKEN], resources: [TOKEN],
}, },
@ -31,6 +31,4 @@ fn idle() -> ! {
loop {} loop {}
} }
task!(EXTI0, exti0);
fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {}

View file

@ -3,7 +3,6 @@
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx; extern crate stm32f103xx;
@ -20,12 +19,14 @@ app! {
tasks: { tasks: {
EXTI0: { EXTI0: {
enabled: true, enabled: true,
path: exti0,
priority: 1, priority: 1,
resources: [A, B], resources: [A, B],
}, },
EXTI1: { EXTI1: {
enabled: true, enabled: true,
path: exti1,
priority: 2, priority: 2,
resources: [A, B], resources: [A, B],
}, },
@ -38,8 +39,6 @@ fn idle() -> ! {
loop {} loop {}
} }
task!(EXTI0, exti0);
fn exti0(mut ot: &mut Threshold, r: EXTI0::Resources) { fn exti0(mut ot: &mut Threshold, r: EXTI0::Resources) {
r.A.claim(&mut ot, |_a, mut _it| { r.A.claim(&mut ot, |_a, mut _it| {
//~^ error cannot borrow `ot` as mutable more than once at a time //~^ error cannot borrow `ot` as mutable more than once at a time
@ -49,6 +48,4 @@ fn exti0(mut ot: &mut Threshold, r: EXTI0::Resources) {
}); });
} }
task!(EXTI1, exti1);
fn exti1(_t: &mut Threshold, r: EXTI1::Resources) {} fn exti1(_t: &mut Threshold, r: EXTI1::Resources) {}