Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
system_time.hpp
Go to the documentation of this file.
1/**
2 * @file system_time.hpp
3 * @brief System timing functions for cooperative scheduling
4 * @ingroup hal
5 *
6 * Provides basic system time functions (millis/micros/delay) that
7 * patterns and application code can use without directly accessing
8 * platform implementations.
9 *
10 * These are fundamental HAL functions that wrap platform-specific
11 * timing hardware (SysTick, hardware timers, etc).
12 */
13
14#ifndef SBL_HAL_TIMING_SYSTEM_TIME_HPP_
15#define SBL_HAL_TIMING_SYSTEM_TIME_HPP_
16
17#include <cstdint>
18
19namespace sbl {
20namespace core {
21namespace hal {
22namespace timing {
23
24/**
25 * @brief System time interface for platform-independent timing
26 *
27 * Template interface that platform implementations must provide.
28 * Applications and patterns use this instead of accessing platform directly.
29 *
30 * @tparam PlatformTimer Platform-specific timer implementation
31 */
32template<typename PlatformTimer>
34public:
35 /**
36 * @brief Get system time in milliseconds
37 *
38 * Returns monotonic millisecond counter for timing operations.
39 * Wraps after ~49 days at 1ms resolution.
40 *
41 * @return Milliseconds since system start
42 */
43 static uint32_t millis() {
44 return PlatformTimer::millis();
45 }
46
47 /**
48 * @brief Get system time in microseconds
49 *
50 * Returns monotonic microsecond counter for high-resolution timing.
51 * Wraps after ~71 minutes at 1μs resolution.
52 *
53 * @return Microseconds since system start
54 */
55 static uint32_t micros() {
56 return PlatformTimer::micros();
57 }
58
59 /**
60 * @brief Blocking delay in milliseconds
61 *
62 * Busy-wait delay. Blocks execution for specified duration.
63 * Use NonBlockingDelay for cooperative scheduling.
64 *
65 * @param ms Delay duration in milliseconds
66 */
67 static void delayMs(uint32_t ms) {
68 PlatformTimer::delayMs(ms);
69 }
70
71 /**
72 * @brief Blocking delay in microseconds
73 *
74 * Busy-wait delay. Blocks execution for specified duration.
75 *
76 * @param us Delay duration in microseconds
77 */
78 static void delayUs(uint32_t us) {
79 PlatformTimer::delayUs(us);
80 }
81};
82
83} // namespace timing
84} // namespace hal
85} // namespace core
86} // namespace sbl
87
88#endif // SBL_HAL_TIMING_SYSTEM_TIME_HPP_
System time interface for platform-independent timing.
static uint32_t micros()
Get system time in microseconds.
static void delayMs(uint32_t ms)
Blocking delay in milliseconds.
static void delayUs(uint32_t us)
Blocking delay in microseconds.
static uint32_t millis()
Get system time in milliseconds.
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24