os/
timer.rs

1//! RISC-V timer-related functionality
2
3use crate::config::CLOCK_FREQ;
4use crate::sbi::set_timer;
5use riscv::register::time;
6
7const TICKS_PER_SEC: usize = 100;
8const MSEC_PER_SEC: usize = 1000;
9
10/// read the `mtime` register
11pub fn get_time() -> usize {
12    time::read()
13}
14
15/// get current time in milliseconds
16pub fn get_time_ms() -> usize {
17    time::read() / (CLOCK_FREQ / MSEC_PER_SEC)
18}
19
20/// set the next timer interrupt
21pub fn set_next_trigger() {
22    set_timer(get_time() + CLOCK_FREQ / TICKS_PER_SEC);
23}