Skip to content
Snippets Groups Projects
Commit 91d9972f authored by Vivian Roest's avatar Vivian Roest :gay_pride_flag:
Browse files

Check if rtc compare event has triggered before waiting for interrupt

parent a658fff7
No related branches found
No related tags found
1 merge request!7Fix loops running quicker than timer
Pipeline #817279 failed
......@@ -4,6 +4,7 @@ use core::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use core::time::Duration;
use nrf51_pac::interrupt;
use crate::led::Led;
use crate::mutex::Mutex;
use crate::once_cell::OnceCell;
/// Delay for a number of CPU cycles. Very inaccurate
......@@ -181,6 +182,14 @@ unsafe fn RTC0() {
/// Wait for the next interrupt configured by `set_interrupt_frequency`.
pub fn wait_for_next_tick() {
RTC.modify(|rtc| {
if rtc.is_event_triggered(RtcInterrupt::Compare0) {
// the compare register has already triggered
TIMER_FLAG.store(false, Ordering::SeqCst);
return;
}
});
while !TIMER_FLAG.load(Ordering::SeqCst) {
cortex_m::asm::wfi();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment