# timer.rs - source
Source of the Rust file `src/timer.rs`.
Keywords: rust, rustlang, rust-lang

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18

    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;

    pub fn get_time() -> usize {
        time::read()
    }

    pub fn get_time_ms() -> usize {
        time::read() / (CLOCK_FREQ / MSEC_PER_SEC)
    }

    pub fn set_next_trigger() {
        set_timer(get_time() + CLOCK_FREQ / TICKS_PER_SEC);
    }