Skip to main content

abi_definitions/
time.rs

1use core::ffi::{c_int, c_void};
2
3use time::get_instance;
4
5pub type XilaTime = u64;
6
7#[repr(C)]
8pub struct XilaTimePrecision {
9    seconds: XilaTime,
10    nanoseconds: u32,
11}
12
13#[repr(u8)]
14pub enum XilaTimeClockIdentifier {
15    Monotonic,
16    Realtime,
17}
18
19#[repr(u8)]
20pub enum XilaTimerFlags {
21    Absolute,
22}
23
24/// Retrieve the current time since the system startup in microseconds.
25///
26/// # Returns
27///
28/// The current time since the system startup in microseconds.
29#[unsafe(no_mangle)]
30pub extern "C" fn xila_time_get_time_since_startup_microseconds() -> u64 {
31    get_instance()
32        .get_current_time_since_startup()
33        .unwrap_or_default()
34        .as_micros() as u64
35}
36
37#[unsafe(no_mangle)]
38pub extern "C" fn xila_time_get_cpu() -> u64 {
39    todo!()
40}
41
42/// Retrieve the current time since the system startup in milliseconds.
43///
44/// # Safety
45///
46/// This function is unsafe because it dereferences raw pointers.
47#[unsafe(no_mangle)]
48pub unsafe extern "C" fn xila_time_get_resolution(
49    _clock_identifier: XilaTimeClockIdentifier,
50    _resolution: *mut XilaTime,
51) -> u32 {
52    todo!()
53}
54
55/// Retrieve the current time since the system startup in milliseconds.
56///
57/// # Safety
58///
59/// This function is unsafe because it dereferences raw pointers.
60#[unsafe(no_mangle)]
61pub extern "C" fn xila_time_get_time(
62    _clock_identifier: XilaTimeClockIdentifier,
63    _precision: u64,
64    _time: *mut XilaTime,
65) -> u32 {
66    todo!()
67}
68
69#[unsafe(no_mangle)]
70pub extern "C" fn xila_time_nano_sleep(
71    _clock_identifier: XilaTimeClockIdentifier,
72    _flags: XilaTimerFlags,
73    _time: *const c_void,
74    _remaining: *mut XilaTime,
75) -> c_int {
76    0
77}
78
79#[unsafe(no_mangle)]
80pub extern "C" fn xila_time_dummy(_: XilaTimePrecision) -> XilaTime {
81    0
82}