mirror of
https://github.com/iceHtwoO/novaOS.git
synced 2026-04-17 04:32:27 +00:00
implement timer
This commit is contained in:
18
src/timer.rs
Normal file
18
src/timer.rs
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user