-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtime.rs
More file actions
40 lines (31 loc) · 983 Bytes
/
Copy pathtime.rs
File metadata and controls
40 lines (31 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::hal::{self, Machinelike};
use crate::{sched, sync};
static TICKS: sync::atomic::AtomicU64 = sync::atomic::AtomicU64::new(0);
pub fn tick() -> u64 {
TICKS.load(sync::atomic::Ordering::Acquire)
}
pub fn mono_now() -> u64 {
// TODO: This will break on SMP systems without native u64 atomic store.
sync::atomic::irq_free(|| hal::Machine::monotonic_now())
}
pub fn mono_freq() -> u64 {
hal::Machine::monotonic_freq()
}
pub fn to_secs(cnt: u64, hz: u32, digits: u8) -> (u64, u64) {
let secs = cnt / (hz as u64);
let rem = cnt % (hz as u64);
let frac = (rem * 10_u64.pow(digits as u32)) / (hz as u64);
(secs, frac)
}
/// cbindgen:ignore
/// cbindgen:no-export
#[unsafe(no_mangle)]
pub extern "C" fn systick_hndlr() {
let tick = TICKS.fetch_add(1, sync::atomic::Ordering::Release) + 1;
sync::atomic::irq_free(|| {
hal::Machine::do_tick();
});
if sched::needs_reschedule(tick) {
sched::reschedule();
}
}