|
|
|
@ -1,24 +1,6 @@
|
|
|
|
|
use riscv::register::*;
|
|
|
|
|
use super::sbi;
|
|
|
|
|
use mips::registers::cp0;
|
|
|
|
|
use log::*;
|
|
|
|
|
|
|
|
|
|
#[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 read_epoch() -> u64 {
|
|
|
|
|
// TODO: support RTC
|
|
|
|
|
0
|
|
|
|
@ -27,7 +9,7 @@ pub fn read_epoch() -> u64 {
|
|
|
|
|
/// Enable timer interrupt
|
|
|
|
|
pub fn init() {
|
|
|
|
|
// Enable supervisor timer interrupt
|
|
|
|
|
unsafe { sie::set_stimer(); }
|
|
|
|
|
cp0::status::enable_hard_int5(); // IP(7), timer interrupt
|
|
|
|
|
set_next();
|
|
|
|
|
info!("timer: init end");
|
|
|
|
|
}
|
|
|
|
@ -36,5 +18,6 @@ pub fn init() {
|
|
|
|
|
pub fn set_next() {
|
|
|
|
|
// 100Hz @ QEMU
|
|
|
|
|
let timebase = 250000;
|
|
|
|
|
sbi::set_timer(get_cycle() + timebase);
|
|
|
|
|
cp0::count::write_u32(0);
|
|
|
|
|
cp0::compare::write_u32(timebase);
|
|
|
|
|
}
|
|
|
|
|