mirror of
https://github.com/LearningOS/rust-based-os-comp2022.git
synced 2026-05-09 07:11:25 +08:00
add os[1-8]-ref for os refereces, add guide, add README
This commit is contained in:
23
os6-ref/src/timer.rs
Normal file
23
os6-ref/src/timer.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
//! RISC-V timer-related functionality
|
||||
|
||||
use crate::config::CLOCK_FREQ;
|
||||
use crate::sbi::set_timer;
|
||||
use riscv::register::time;
|
||||
|
||||
const TICKS_PER_SEC: usize = 100;
|
||||
const MICRO_PER_SEC: usize = 1_000_000;
|
||||
|
||||
/// read the `mtime` register
|
||||
pub fn get_time() -> usize {
|
||||
time::read()
|
||||
}
|
||||
|
||||
/// get current time in microseconds
|
||||
pub fn get_time_us() -> usize {
|
||||
time::read() / (CLOCK_FREQ / MICRO_PER_SEC)
|
||||
}
|
||||
|
||||
/// set the next timer interrupt
|
||||
pub fn set_next_trigger() {
|
||||
set_timer(get_time() + CLOCK_FREQ / TICKS_PER_SEC);
|
||||
}
|
||||
Reference in New Issue
Block a user