parent
aeb7fce0e6
commit
ee242b44b2
@ -1 +1 @@
|
||||
Subproject commit a3d2a13c0e656936631c6f420a393c2c0038ecc8
|
||||
Subproject commit ef046c88fdb7ed0f416f29e034d4679f0e7a2573
|
@ -0,0 +1,33 @@
|
||||
use super::riscv::register::*;
|
||||
use super::bbl::sbi;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn get_cycle() -> u64 {
|
||||
time::read() as u64
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn get_cycle() -> u64 {
|
||||
loop {
|
||||
let hi = timeh::read();
|
||||
let lo = time::read();
|
||||
let tmp = timeh::read();
|
||||
if hi == tmp {
|
||||
return ((hi as u64) << 32) | (lo as u64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
// Enable supervisor timer interrupt
|
||||
unsafe { sie::set_stimer(); }
|
||||
|
||||
set_next();
|
||||
println!("timer: init end");
|
||||
}
|
||||
|
||||
pub fn set_next() {
|
||||
// 100Hz @ QEMU
|
||||
let timebase = 100000;
|
||||
sbi::set_timer(get_cycle() + timebase);
|
||||
}
|
Loading…
Reference in new issue