Sound Byte Libs 29c5ff3
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 hal {
21namespace timing {
22
23/**
24 * @brief System time interface for platform-independent timing
25 *
26 * Template interface that platform implementations must provide.
27 * Applications and patterns use this instead of accessing platform directly.
28 *
29 * @tparam PlatformTimer Platform-specific timer implementation
30 */
31template<typename PlatformTimer>
33public:
34 /**
35 * @brief Get system time in milliseconds
36 *
37 * Returns monotonic millisecond counter for timing operations.
38 * Wraps after ~49 days at 1ms resolution.
39 *
40 * @return Milliseconds since system start
41 */
42 static uint32_t millis() {
43 return PlatformTimer::millis();
44 }
45
46 /**
47 * @brief Get system time in microseconds
48 *
49 * Returns monotonic microsecond counter for high-resolution timing.
50 * Wraps after ~71 minutes at 1μs resolution.
51 *
52 * @return Microseconds since system start
53 */
54 static uint32_t micros() {
55 return PlatformTimer::micros();
56 }
57
58 /**
59 * @brief Blocking delay in milliseconds
60 *
61 * Busy-wait delay. Blocks execution for specified duration.
62 * Use NonBlockingDelay for cooperative scheduling.
63 *
64 * @param ms Delay duration in milliseconds
65 */
66 static void delayMs(uint32_t ms) {
67 PlatformTimer::delayMs(ms);
68 }
69
70 /**
71 * @brief Blocking delay in microseconds
72 *
73 * Busy-wait delay. Blocks execution for specified duration.
74 *
75 * @param us Delay duration in microseconds
76 */
77 static void delayUs(uint32_t us) {
78 PlatformTimer::delayUs(us);
79 }
80};
81
82} // namespace timing
83} // namespace hal
84} // namespace sbl
85
86#endif // SBL_HAL_TIMING_SYSTEM_TIME_HPP_
System time interface for platform-independent timing.
static uint32_t millis()
Get system time in milliseconds.
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.
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24