implement timer

This commit is contained in:
2025-05-20 12:29:16 +02:00
parent aff0259643
commit 5e8180ceaf
3 changed files with 25 additions and 10 deletions

18
src/timer.rs Normal file
View File

@@ -0,0 +1,18 @@
const TIMER_CLO: u32 = 0x3F00_3004;
fn read_clo() -> u32 {
unsafe { return core::ptr::read_volatile(TIMER_CLO as *const u32) }
}
pub unsafe fn sleep(microseconds: u32) {
let start = read_clo();
while read_clo() - start < microseconds {
core::arch::asm!("nop");
}
}
pub unsafe fn delay_nops(count: u32) {
for _ in 0..count {
core::arch::asm!("nop");
}
}