Hi,
I'm trying to implement A CPU usage monitor for the RTFM framework in the current version of RTFM 0.5.1.
I'm calling wfi in a lock and the program is not waking up.
The program wakes properly when wfi in not in a critical section.
I've read the RTFM doc but I must be missing something.
I'm not sure if my code is wrong or that interrupts are disabled in critical sections.
#[idle(resources = [sleep_time,itm])]
fn idle(cx: idle::Context) -> ! {
let mut itm = cx.resources.itm;
// let mut sleep_time = cx.resources.sleep_time;
itm.lock(|itm| {
iprintln!(&mut itm.stim[0], "idle");
});
rtfm::pend(Interrupt::SPI1);
loop {
// this code does not wake up
//
// sleep_time.lock(|sleep_time: &mut u32| {
// let before = cortex_m::peripheral::DWT::get_cycle_count();
// cortex_m::asm::wfi();
// let after = cortex_m::peripheral::DWT::get_cycle_count();
// let elapsed = after.wrapping_sub(before);
// *sleep_time += elapsed;
// });
cortex_m::asm::wfi();
}
}