rtic/tests/cfail/lock.rs

79 lines
1.6 KiB
Rust
Raw Normal View History

#![deny(unsafe_code)]
2017-07-18 22:14:39 +02:00
#![deny(warnings)]
#![feature(const_fn)]
#![feature(proc_macro)]
2018-05-14 21:22:50 +02:00
#![no_main]
2017-07-24 03:51:58 +02:00
#![no_std]
2017-07-18 22:14:39 +02:00
extern crate cortex_m_rtfm as rtfm;
2018-05-07 17:46:26 +02:00
extern crate panic_itm;
2017-07-18 22:14:39 +02:00
extern crate stm32f103xx;
2018-05-01 14:01:51 +02:00
use rtfm::{app, Resource};
2017-07-18 22:14:39 +02:00
app! {
device: stm32f103xx,
resources: {
static ON: bool = false;
2017-07-24 03:51:58 +02:00
static MAX: u8 = 0;
2018-05-01 14:01:51 +02:00
static OWNED: bool = false;
2017-07-18 22:14:39 +02:00
},
tasks: {
2018-05-01 14:01:51 +02:00
exti0: {
interrupt: EXTI0,
// priority: 1,
resources: [MAX, ON],
2017-07-18 22:14:39 +02:00
},
2018-05-01 14:01:51 +02:00
exti1: {
interrupt: EXTI1,
2017-07-18 22:14:39 +02:00
priority: 2,
2018-05-01 14:01:51 +02:00
resources: [ON, OWNED],
2017-07-18 22:14:39 +02:00
},
2018-05-01 14:01:51 +02:00
exti2: {
interrupt: EXTI2,
2017-07-18 22:14:39 +02:00
priority: 16,
resources: [MAX],
},
},
}
2018-05-01 14:01:51 +02:00
fn init(_ctxt: init::Context) -> init::LateResources {
init::LateResources {}
}
2017-07-18 22:14:39 +02:00
2018-05-01 14:01:51 +02:00
fn idle(_ctxt: idle::Context) -> ! {
2017-07-18 22:14:39 +02:00
loop {}
}
2018-05-01 14:01:51 +02:00
#[allow(non_snake_case)]
fn exti0(mut ctxt: exti0::Context) {
let exti0::Resources { ON, mut MAX } = ctxt.resources;
2018-05-14 21:22:50 +02:00
let p = &mut ctxt.priority;
2018-05-01 14:01:51 +02:00
// ERROR need to lock to access the resource because priority < ceiling
2018-05-01 14:01:51 +02:00
{
2018-05-14 21:22:50 +02:00
let _on = ON.borrow(p);
2018-05-01 14:01:51 +02:00
//~^ error type mismatch resolving
}
2017-07-18 22:14:39 +02:00
// OK need to lock to access the resource
2018-05-14 21:22:50 +02:00
if ON.claim(p, |on, _| *on) {}
2017-07-18 22:14:39 +02:00
// OK can claim a resource with maximum ceiling
2018-05-14 21:22:50 +02:00
MAX.claim_mut(p, |max, _| *max += 1);
2017-07-18 22:14:39 +02:00
}
2018-05-01 14:01:51 +02:00
#[allow(non_snake_case)]
fn exti1(ctxt: exti1::Context) {
let exti1::Resources { OWNED, .. } = ctxt.resources;
2017-07-18 22:14:39 +02:00
2018-05-01 14:01:51 +02:00
// OK to directly access the resource because this task is the only owner
if *OWNED {}
2017-07-18 22:14:39 +02:00
}
2017-07-24 03:51:58 +02:00
2018-05-01 14:01:51 +02:00
fn exti2(_ctxt: exti2::Context) {}