pub fn millis() -> usize {
MILLIS.load(Ordering::Relaxed)
}
pub async fn sleep_millis(duration: usize) {
let current = millis();
let target = current.wrapping_add(duration);
poll_fn(|ctx| {
if target < current {
if super::MILLIS.load(Ordering::Relaxed) >= current {
Poll::Pending
} else {
if super::MILLIS.load(Ordering::Relaxed) >= target {
Poll::Ready(())
} else {
Poll::Pending
}
}
} else {
if super::MILLIS.load(Ordering::Relaxed) >= target {
Poll::Ready(())
} else {
Poll::Pending
}
}
})
.await;
}
static MILLIS: Value = Value::new(0);
static SYSTICK_WAKERS: WakerSet = WakerSet::new();
pub extern "C" fn systick_intr() {
let millis = MILLIS.load(Ordering::Relaxed);
let millis = millis.wrapping_add(1);
MILLIS.store(millis, Ordering::Relaxed);
SYSTICK_WAKERS.wake();
}