Use Relaxed atomics with fence instead of SeqCst
This commit is contained in:
parent
406f3b7cbf
commit
91aaea761e
@ -1,6 +1,6 @@
|
|||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
|
||||||
|
|
||||||
use embassy::time::Clock;
|
use embassy::time::Clock;
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ impl<T: Instance> RTC<T> {
|
|||||||
|
|
||||||
fn next_period(&self) {
|
fn next_period(&self) {
|
||||||
interrupt::free(|cs| {
|
interrupt::free(|cs| {
|
||||||
let period = self.period.fetch_add(1, Ordering::SeqCst) + 1;
|
let period = self.period.fetch_add(1, Ordering::Relaxed) + 1;
|
||||||
let t = (period as u64) << 23;
|
let t = (period as u64) << 23;
|
||||||
|
|
||||||
for n in 0..ALARM_COUNT {
|
for n in 0..ALARM_COUNT {
|
||||||
@ -231,7 +231,8 @@ impl<T: Instance> RTC<T> {
|
|||||||
impl<T: Instance> embassy::time::Clock for RTC<T> {
|
impl<T: Instance> embassy::time::Clock for RTC<T> {
|
||||||
fn now(&self) -> u64 {
|
fn now(&self) -> u64 {
|
||||||
// `period` MUST be read before `counter`, see comment at the top for details.
|
// `period` MUST be read before `counter`, see comment at the top for details.
|
||||||
let period = self.period.load(Ordering::SeqCst);
|
let period = self.period.load(Ordering::Relaxed);
|
||||||
|
compiler_fence(Ordering::Acquire);
|
||||||
let counter = self.rtc.counter.read().bits();
|
let counter = self.rtc.counter.read().bits();
|
||||||
calc_now(period, counter)
|
calc_now(period, counter)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user