ssh_stamp_hal/traits/timer.rs
1// SPDX-FileCopyrightText: 2026 Roman Valls Guimera <brainstorm@nopcode.org>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5//! Timer operations trait.
6
7use core::future::Future;
8
9/// Timer hardware abstraction.
10///
11/// Provides time measurement and delays. Implementations typically wrap
12/// system tick timers or RTOS timer facilities.
13///
14/// # Example
15///
16/// ```ignore
17/// async fn measure_time<T: TimerHal>(timer: &T) -> u64 {
18/// let start = timer.now_millis();
19/// some_operation().await;
20/// timer.now_millis() - start
21/// }
22/// ```
23pub trait TimerHal {
24 /// Get current time in microseconds since boot.
25 ///
26 /// Returns a monotonically increasing counter of microseconds since
27 /// system startup. May wrap around on long-running systems.
28 fn now_micros(&self) -> u64;
29
30 /// Get current time in milliseconds since boot.
31 ///
32 /// Convenience wrapper around [`Self::now_micros`] with millisecond resolution.
33 fn now_millis(&self) -> u64 {
34 self.now_micros() / 1000
35 }
36
37 /// Wait for specified duration.
38 ///
39 /// Asynchronously waits for the specified number of milliseconds.
40 /// This is an async operation that yields to the executor.
41 ///
42 /// # Arguments
43 ///
44 /// * `millis` - Duration to wait in milliseconds.
45 fn delay(&self, millis: u64) -> impl Future<Output = ()>;
46}