use crate::config::CLOCK_FREQ;
use crate::sbi::set_timer;
use riscv::register::time;
const TICKS_PER_SEC: usize = 100;
const MSEC_PER_SEC: usize = 1000;
#[allow(dead_code)]
const MICRO_PER_SEC: usize = 1_000_000;
pub fn get_time() -> usize {
time::read()
}
#[allow(dead_code)]
pub fn get_time_ms() -> usize {
time::read() * MSEC_PER_SEC / CLOCK_FREQ
}
#[allow(dead_code)]
pub fn get_time_us() -> usize {
time::read() * MICRO_PER_SEC / CLOCK_FREQ
}
pub fn set_next_trigger() {
set_timer(get_time() + CLOCK_FREQ / TICKS_PER_SEC);
}