Skip to content
Snippets Groups Projects
Commit 5ff57e48 authored by Per Lindgren's avatar Per Lindgren
Browse files

nested examples

parent bed76109
No related branches found
No related tags found
No related merge requests found
//! Nesting claims and how the preemption threshold works
//!
//! If you run this program you'll hit the breakpoints as indicated by the
//! letters in the comments: A, then B, then C, etc.
#![deny(unsafe_code)]
#![feature(proc_macro)]
#![no_std]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f40x;
use stm32f40x::Interrupt;
use rtfm::{app, Resource, Threshold};
app! {
device: stm32f40x,
resources: {
static LOW: u64 = 0;
static HIGH: u64 = 0;
},
tasks: {
EXTI0: {
path: exti0,
priority: 1,
resources: [LOW, HIGH],
},
EXTI1: {
path: exti1,
priority: 2,
resources: [LOW],
},
EXTI2: {
path: exti2,
priority: 3,
resources: [HIGH],
},
EXTI3: {
path: exti0_new_stub,
priority: 1,
resources: [LOW, HIGH],
},
},
}
fn init(_p: init::Peripherals, _r: init::Resources) {}
#[inline(never)]
fn idle() -> ! {
// A
rtfm::bkpt();
// Sets task `exti0` as pending
//
// Because `exti0` has higher priority than `idle` it will be executed
// immediately
rtfm::set_pending(Interrupt::EXTI0); // ~> exti0
rtfm::set_pending(Interrupt::EXTI3); // ~> exti0
loop {
rtfm::wfi();
}
}
#[allow(non_snake_case)]
fn exti0_new_stub(t: &mut Threshold, r: EXTI3::Resources) {
let mut b = false; // first claim
rtfm::bkpt();
exti0_new(&mut b, t, r)
}
#[allow(non_snake_case)]
fn exti0_new(
b: &mut bool, // shulde be a newtype later
t: &mut Threshold,
EXTI3::Resources { mut LOW, mut HIGH }: EXTI3::Resources,
) {
LOW.claim_mut_new(b, t, |_low, b, t| {
rtfm::bkpt();
HIGH.claim_mut_new(b, t, |_high, _, _| {
rtfm::bkpt();
});
});
}
#[allow(non_snake_case)]
fn exti0(t: &mut Threshold, EXTI0::Resources { mut LOW, mut HIGH }: EXTI0::Resources) {
rtfm::bkpt();
LOW.claim_mut(t, |_low, t| {
rtfm::bkpt();
HIGH.claim_mut(t, |_high, _| {
rtfm::bkpt();
});
});
}
fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {
rtfm::bkpt();
}
fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) {
rtfm::bkpt();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment