1#![no_std]
8
9pub mod power;
10
11#[repr(transparent)]
13#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct InstantMono(pub i64);
15
16impl core::ops::Add<i64> for InstantMono {
17 type Output = Self;
18
19 #[inline]
20 fn add(self, rhs: i64) -> Self {
21 Self(self.0 + rhs)
22 }
23}
24
25#[repr(transparent)]
27#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
28pub struct InstantMonoTicks(pub i64);
29
30#[repr(transparent)]
32#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
33pub struct InstantBoot(pub i64);
34
35#[repr(transparent)]
37#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
38pub struct InstantBootTicks(pub i64);
39
40#[repr(transparent)]
42#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
43pub struct DurationMono(pub i64);
44
45#[repr(transparent)]
47#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
48pub struct DurationMonoTicks(pub i64);
49
50#[repr(transparent)]
52#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
53pub struct DurationBoot(pub i64);
54
55#[repr(transparent)]
57#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
58pub struct DurationBootTicks(pub i64);
59
60unsafe extern "C" {
61 fn cpp_timer_current_mono_ticks() -> InstantMonoTicks;
62 fn cpp_timer_current_boot_ticks() -> InstantBootTicks;
63 fn cpp_current_mono_time() -> InstantMono;
64 fn cpp_current_boot_time() -> InstantBoot;
65}
66
67#[inline]
69pub fn timer_current_mono_ticks() -> InstantMonoTicks {
70 unsafe { cpp_timer_current_mono_ticks() }
73}
74
75#[inline]
77pub fn timer_current_boot_ticks() -> InstantBootTicks {
78 unsafe { cpp_timer_current_boot_ticks() }
81}
82
83#[inline]
85pub fn current_mono_time() -> InstantMono {
86 unsafe { cpp_current_mono_time() }
89}
90
91#[inline]
93pub fn current_boot_time() -> InstantBoot {
94 unsafe { cpp_current_boot_time() }
97}
98
99#[cfg(test)]
100mod tests {
101 use super::*;
102
103 #[test]
104 fn test_time_ordering_and_equality() {
105 assert!(DurationMono(10) < DurationMono(20));
106 assert_eq!(DurationMono(15), DurationMono(15));
107 assert!(InstantMono(100) < InstantMono(200));
108 assert_eq!(InstantMono(100) + 50, InstantMono(150));
109 }
110}