modify time driver to not require portable-atomic
This commit is contained in:
parent
6126183db8
commit
00d66cce1d
1 changed files with 9 additions and 11 deletions
|
@ -1,11 +1,11 @@
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::{mem, ptr};
|
use core::{mem, ptr};
|
||||||
|
|
||||||
|
use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering};
|
||||||
use critical_section::CriticalSection;
|
use critical_section::CriticalSection;
|
||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex;
|
use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex;
|
||||||
use embassy_time_driver::{AlarmHandle, Driver};
|
use embassy_time_driver::{AlarmHandle, Driver};
|
||||||
use portable_atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering};
|
|
||||||
|
|
||||||
use crate::interrupt::InterruptExt;
|
use crate::interrupt::InterruptExt;
|
||||||
use crate::{interrupt, pac};
|
use crate::{interrupt, pac};
|
||||||
|
@ -171,7 +171,8 @@ impl RtcDriver {
|
||||||
fn next_period(&self) {
|
fn next_period(&self) {
|
||||||
critical_section::with(|cs| {
|
critical_section::with(|cs| {
|
||||||
let r = rtc();
|
let r = rtc();
|
||||||
let period = self.period.fetch_add(1, Ordering::Relaxed) + 1;
|
let period = self.period.load(Ordering::Relaxed) + 1;
|
||||||
|
self.period.store(period, Ordering::Relaxed);
|
||||||
let t = (period as u64) << 23;
|
let t = (period as u64) << 23;
|
||||||
|
|
||||||
for n in 0..ALARM_COUNT {
|
for n in 0..ALARM_COUNT {
|
||||||
|
@ -219,18 +220,15 @@ impl Driver for RtcDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
|
unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
|
||||||
let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
|
critical_section::with(|_| {
|
||||||
if x < ALARM_COUNT as u8 {
|
let id = self.alarm_count.load(Ordering::Relaxed);
|
||||||
Some(x + 1)
|
if id < ALARM_COUNT as u8 {
|
||||||
|
self.alarm_count.store(id + 1, Ordering::Relaxed);
|
||||||
|
Some(AlarmHandle::new(id))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
match id {
|
|
||||||
Ok(id) => Some(AlarmHandle::new(id)),
|
|
||||||
Err(_) => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) {
|
fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) {
|
||||||
|
|
Loading…
Reference in a new issue