emerald_std/
clock.rs

1pub use kernel_user_link::clock::{ClockTime, ClockType};
2use kernel_user_link::{
3    call_syscall,
4    syscalls::{SyscallError, SYS_GET_TIME, SYS_SLEEP},
5};
6
7/// # Safety
8/// This function assumes that `seconds` and `nanoseconds` are valid, nanoseconds should be less than 1_000_000_000.
9pub unsafe fn sleep(seconds: u64, nanoseconds: u64) -> Result<(), SyscallError> {
10    unsafe {
11        call_syscall!(
12            SYS_SLEEP,
13            seconds,     // seconds
14            nanoseconds, // nanoseconds
15        )
16        .map(|e| assert!(e == 0))
17    }
18}
19
20/// # Safety
21/// There are no safety requirements for this function.
22/// Its just that it's a wrapper around a syscall.
23pub unsafe fn get_time(time_type: ClockType) -> Result<ClockTime, SyscallError> {
24    let mut time = ClockTime {
25        seconds: 0,
26        nanoseconds: 0,
27    };
28    unsafe {
29        call_syscall!(
30            SYS_GET_TIME,
31            time_type as u64,                   // time_type
32            &mut time as *mut ClockTime as u64, // time
33        )
34        .map(|e| assert!(e == 0))
35        .map(|_| time)
36    }
37}