picoem_common/clock/mod.rs
1/// Master cycle counter. All timing in the emulator derives from this.
2///
3/// At 150 MHz, a u64 counter wraps after ~3,900 years.
4///
5/// The authoritative system-clock frequency lives in
6/// [`crate::bus::Bus`]'s clock tree (see `bus/clocks.rs`). Callers who
7/// need Hz should use `emu.bus.sys_clk_hz()`.
8pub struct Clock {
9 /// Monotonically increasing system clock cycle count.
10 pub cycles: u64,
11}
12
13impl Clock {
14 pub fn new() -> Self {
15 Self { cycles: 0 }
16 }
17
18 #[inline(always)]
19 pub fn advance(&mut self, n: u64) {
20 self.cycles += n;
21 }
22}
23
24impl Default for Clock {
25 fn default() -> Self {
26 Self::new()
27 }
28}