mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 12:55:23 +01:00
update tests and examples
with task! gone 3 types of errors / gotchas have been eliminated 🎉
This commit is contained in:
parent
0b5afce771
commit
aa22494549
17 changed files with 68 additions and 230 deletions
|
|
@ -3,7 +3,6 @@
|
|||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use(task)]
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
|
|
@ -13,18 +12,19 @@ app! {
|
|||
device: stm32f103xx,
|
||||
|
||||
resources: {
|
||||
static STATE: bool = false;
|
||||
static ON: bool = false;
|
||||
},
|
||||
|
||||
idle: {
|
||||
resources: [STATE],
|
||||
resources: [ON],
|
||||
},
|
||||
|
||||
tasks: {
|
||||
EXTI0: {
|
||||
enabled: true,
|
||||
path: exti0,
|
||||
priority: 1,
|
||||
resources: [STATE],
|
||||
resources: [ON],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -32,12 +32,12 @@ app! {
|
|||
fn init(_p: init::Peripherals, _r: init::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
|
||||
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
|
||||
state //~ error cannot infer an appropriate lifetime
|
||||
});
|
||||
|
|
@ -45,6 +45,4 @@ fn idle(t: &mut Threshold, r: idle::Resources) -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
task!(EXTI0, exti0);
|
||||
|
||||
fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {}
|
||||
|
|
|
|||
|
|
@ -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) {}
|
||||
|
|
@ -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) {}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use(task)]
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
|
|
@ -13,25 +12,28 @@ app! {
|
|||
device: stm32f103xx,
|
||||
|
||||
resources: {
|
||||
static STATE: bool = false;
|
||||
static ON: bool = false;
|
||||
static MAX: u8 = 0;
|
||||
},
|
||||
|
||||
tasks: {
|
||||
EXTI0: {
|
||||
enabled: true,
|
||||
path: exti0,
|
||||
priority: 1,
|
||||
resources: [MAX, STATE],
|
||||
resources: [MAX, ON],
|
||||
},
|
||||
|
||||
EXTI1: {
|
||||
enabled: true,
|
||||
path: exti1,
|
||||
priority: 2,
|
||||
resources: [STATE],
|
||||
resources: [ON],
|
||||
},
|
||||
|
||||
EXTI2: {
|
||||
enabled: true,
|
||||
path: exti2,
|
||||
priority: 16,
|
||||
resources: [MAX],
|
||||
},
|
||||
|
|
@ -44,29 +46,23 @@ fn idle() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
task!(EXTI0, exti0);
|
||||
|
||||
fn exti0(mut t: &mut Threshold, mut r: EXTI0::Resources) {
|
||||
// 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
|
||||
r.MAX.claim_mut(&mut t, |max, _| **max += 1);
|
||||
}
|
||||
|
||||
task!(EXTI1, exti1);
|
||||
|
||||
fn exti1(mut t: &mut Threshold, r: EXTI1::Resources) {
|
||||
// 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
|
||||
}
|
||||
|
||||
if **r.STATE {
|
||||
if **r.ON {
|
||||
// OK
|
||||
}
|
||||
}
|
||||
|
||||
task!(EXTI2, exti2);
|
||||
|
||||
fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) {}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use(task)]
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
use rtfm::{app, Threshold};
|
||||
use rtfm::app;
|
||||
|
||||
app! { //~ error attempt to subtract with overflow
|
||||
device: stm32f103xx,
|
||||
|
||||
tasks: {
|
||||
SYS_TICK: {
|
||||
path: sys_tick,
|
||||
// ERROR priority must be in the range [1, 16]
|
||||
priority: 17,
|
||||
},
|
||||
|
|
@ -25,6 +25,4 @@ fn idle() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
task!(SYS_TICK, sys_tick);
|
||||
|
||||
fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {}
|
||||
fn sys_tick() {}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use(task)]
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
use rtfm::{app, Threshold};
|
||||
use rtfm::app;
|
||||
|
||||
app! { //~ error attempt to subtract with overflow
|
||||
device: stm32f103xx,
|
||||
|
||||
tasks: {
|
||||
SYS_TICK: {
|
||||
path: sys_tick,
|
||||
// ERROR priority must be in the range [1, 16]
|
||||
priority: 0,
|
||||
},
|
||||
|
|
@ -25,6 +25,4 @@ fn idle() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
task!(SYS_TICK, sys_tick);
|
||||
|
||||
fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {}
|
||||
fn sys_tick() {}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use(task)]
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
|
|
@ -19,12 +18,14 @@ app! {
|
|||
tasks: {
|
||||
EXTI0: {
|
||||
enabled: true,
|
||||
path: exti0,
|
||||
priority: 1,
|
||||
resources: [STATE],
|
||||
},
|
||||
|
||||
EXTI1: {
|
||||
enabled: true,
|
||||
path: exti1,
|
||||
priority: 2,
|
||||
resources: [STATE],
|
||||
},
|
||||
|
|
@ -37,14 +38,10 @@ fn idle() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
task!(EXTI0, exti0);
|
||||
|
||||
fn exti0(mut t: &mut Threshold, r: EXTI0::Resources) {
|
||||
// ERROR token should not outlive the critical section
|
||||
let t = r.STATE.claim(&mut t, |_state, t| t);
|
||||
//~^ error cannot infer an appropriate lifetime
|
||||
}
|
||||
|
||||
task!(EXTI1, exti1);
|
||||
|
||||
fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use(task)]
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
|
|
@ -19,6 +18,7 @@ app! { //~ error bound `rtfm::Threshold: core::marker::Send` is not satisfied
|
|||
tasks: {
|
||||
EXTI0: {
|
||||
enabled: true,
|
||||
path: exti0,
|
||||
priority: 1,
|
||||
resources: [TOKEN],
|
||||
},
|
||||
|
|
@ -31,6 +31,4 @@ fn idle() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
task!(EXTI0, exti0);
|
||||
|
||||
fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use(task)]
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
|
|
@ -20,12 +19,14 @@ app! {
|
|||
tasks: {
|
||||
EXTI0: {
|
||||
enabled: true,
|
||||
path: exti0,
|
||||
priority: 1,
|
||||
resources: [A, B],
|
||||
},
|
||||
|
||||
EXTI1: {
|
||||
enabled: true,
|
||||
path: exti1,
|
||||
priority: 2,
|
||||
resources: [A, B],
|
||||
},
|
||||
|
|
@ -38,8 +39,6 @@ fn idle() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
task!(EXTI0, exti0);
|
||||
|
||||
fn exti0(mut ot: &mut Threshold, r: EXTI0::Resources) {
|
||||
r.A.claim(&mut ot, |_a, mut _it| {
|
||||
//~^ 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) {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue