# sleep.rs - source
Source of the Rust file `/home/runner/.cargo/git/checkouts/k210-soc-513b01293da09fa1/09a0742/src/sleep.rs`.
Keywords: rust, rustlang, rust-lang

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    use super::sysctl;
    use riscv::register::time;

    pub fn time_sleep(n: usize) {
        let start = time::read();
        while time::read() < start + n {}
    }

    pub fn usleep(n: usize) {
        let freq = sysctl::clock_get_freq(sysctl::clock::CPU) as usize / 62;
        time_sleep(freq * n / 1000000);
    }