This commit is contained in:
2025-06-04 17:20:04 +02:00
parent a289dcfd17
commit c78d834742
8 changed files with 190 additions and 61 deletions

View File

@@ -4,13 +4,25 @@ fn read_clo() -> u32 {
unsafe { return core::ptr::read_volatile(TIMER_CLO as *const u32) }
}
pub fn sleep(microseconds: u32) {
/// Sleep for `us` microseconds
pub fn sleep_us(us: u32) {
let start = read_clo();
while read_clo() - start < microseconds {
while read_clo() - start < us {
unsafe { core::arch::asm!("nop") }
}
}
/// Sleep for `ms` milliseconds
pub fn sleep_ms(ms: u32) {
sleep_us(ms * 1000);
}
/// Sleep for `s` seconds
pub fn sleep_s(s: u32) {
sleep_us(s * 1000);
}
/// Wait for `count` operations to pass
pub fn delay_nops(count: u32) {
for _ in 0..count {
unsafe { core::arch::asm!("nop") }