Skip to main content

abi_definitions/
time.rs

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