diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-05 18:22:41 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-05 18:22:41 +0000 |
| commit | 539d4b1674bc5ee0e12f06c4d09cc6f770df2d8a (patch) | |
| tree | 2f898acf652c6d36ee77cad3e7517af2054271e3 /rtic-monotonics/src/nrf/rtc.rs | |
| parent | 72ae46083e64acc012c6b85d3ef7a115657a01e3 (diff) | |
| parent | 0bb5814443f3b8e5c1d20c1ede7fed8265e653ec (diff) | |
Merge #723
723: Fix monotonics race r=AfoHT a=korken89
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'rtic-monotonics/src/nrf/rtc.rs')
| -rw-r--r-- | rtic-monotonics/src/nrf/rtc.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/rtic-monotonics/src/nrf/rtc.rs b/rtic-monotonics/src/nrf/rtc.rs index 03610c0..2e23389 100644 --- a/rtic-monotonics/src/nrf/rtc.rs +++ b/rtic-monotonics/src/nrf/rtc.rs @@ -189,13 +189,18 @@ macro_rules! make_rtc { // and the flag here. critical_section::with(|_| { let rtc = unsafe { &*$rtc::PTR }; - let cnt = rtc.counter.read().bits() as u64; + let cnt = rtc.counter.read().bits(); + // OVERFLOW HAPPENS HERE race needs to be handled let ovf = if Self::is_overflow() { $overflow.load(Ordering::Relaxed) + 1 } else { $overflow.load(Ordering::Relaxed) } as u64; + // Check and fix if above race happened + let new_cnt = rtc.counter.read().bits(); + let cnt = if new_cnt >= cnt { cnt } else { new_cnt } as u64; + Self::Instant::from_ticks((ovf << 24) | cnt) }) } |
