osiris/
time.rs

1use hal::Machinelike;
2
3use crate::{sched, sync};
4
5static TICKS: sync::atomic::AtomicU64 = sync::atomic::AtomicU64::new(0);
6
7pub fn tick() -> u64 {
8    TICKS.load(sync::atomic::Ordering::Acquire)
9}
10
11pub fn mono_now() -> u64 {
12    // TODO: This will break on SMP systems without native u64 atomic store.
13    sync::atomic::irq_free(|| hal::Machine::monotonic_now())
14}
15
16pub fn mono_freq() -> u64 {
17    hal::Machine::monotonic_freq()
18}
19
20/// cbindgen:ignore
21/// cbindgen:no-export
22#[unsafe(no_mangle)]
23pub extern "C" fn systick_hndlr() {
24    let tick = TICKS.fetch_add(1, sync::atomic::Ordering::Release) + 1;
25
26    if sched::needs_reschedule(tick) {
27        sched::reschedule();
28    }
29}