pub trait Hal {
fn virt_to_phys(va: usize) -> usize;
fn current_ms() -> u64;
fn flush_dcache();
}
pub(crate) fn wait_until(cond: impl Fn() -> bool) {
while !cond() {
core::hint::spin_loop();
}
}
pub(crate) fn wait_until_timeout<H: Hal>(cond: impl Fn() -> bool, timeout: u64) -> bool {
let start = H::current_ms();
loop {
if cond() {
return true;
}
if H::current_ms() - start > timeout {
return false;
}
core::hint::spin_loop();
}
}