rtc: use SeqCst for periods.

This commit is contained in:
Dario Nieuwenhuis 2021-02-15 01:22:38 +01:00
parent 9d5e2d3881
commit 406f3b7cbf

View File

@ -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::Relaxed) + 1; let period = self.period.fetch_add(1, Ordering::SeqCst) + 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,7 @@ 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::Relaxed); let period = self.period.load(Ordering::SeqCst);
let counter = self.rtc.counter.read().bits(); let counter = self.rtc.counter.read().bits();
calc_now(period, counter) calc_now(period, counter)
} }