Internal Interface Wrap
API reference
Loading...
Searching...
No Matches
HfTime.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <cstdint>
36
37#include "McuSelect.h"
38
39#if defined(HF_TARGET_MCU_ESP32) || defined(HF_TARGET_MCU_ESP32S2) || \
40 defined(HF_TARGET_MCU_ESP32S3) || defined(HF_TARGET_MCU_ESP32C3) || \
41 defined(HF_TARGET_MCU_ESP32C2) || defined(HF_TARGET_MCU_ESP32C6) || \
42 defined(HF_TARGET_MCU_ESP32H2)
43# include "EspTime.h"
44 namespace hf_time { using ::hf_time::esp32::MonotonicUs;
45 using ::hf_time::esp32::InitMonotonic; }
46
47#elif defined(HF_TARGET_MCU_STM32F4) || defined(HF_TARGET_MCU_STM32H7)
48# include "Stm32Time.h"
49 namespace hf_time { using ::hf_time::stm32::MonotonicUs;
50 using ::hf_time::stm32::InitMonotonic; }
51
52#elif defined(HF_TARGET_MCU_RP2040)
53# include "Rp2040Time.h"
54 namespace hf_time { using ::hf_time::rp2040::MonotonicUs;
55 using ::hf_time::rp2040::InitMonotonic; }
56
57#elif defined(HF_TARGET_MCU_NONE)
58 // Software-only / unit-test build: monotonic clock is a stub. Tests
59 // that need a controllable clock should inject their own.
60 namespace hf_time {
61 inline std::uint64_t MonotonicUs() noexcept { return 0; }
62 inline void InitMonotonic() noexcept {}
63 }
64
65#else
66# error "HfTime: no implementation for this target — set HF_TARGET_MCU_* (see McuSelect.h)"
67#endif
68
69namespace hf_time {
70
78inline std::uint64_t MonotonicMs() noexcept {
79 return MonotonicUs() / 1000ULL;
80}
81
83inline std::uint64_t ElapsedUs(std::uint64_t t0) noexcept {
84 return MonotonicUs() - t0;
85}
86
87} // namespace hf_time
ESP32-family implementation of the high-resolution monotonic time source consumed via HfTime....
Centralized MCU platform selection and configuration header.
void InitMonotonic() noexcept
No-op on ESP-IDF: the high-resolution timer is started by the system bootstrap before app_main runs.
Definition EspTime.h:36
std::uint64_t MonotonicUs() noexcept
Microseconds since boot from the hardware-backed timer.
Definition EspTime.h:47
Definition EspTime.h:27
std::uint64_t ElapsedUs(std::uint64_t t0) noexcept
Convenience: elapsed-since-t0 in microseconds.
Definition HfTime.h:83
std::uint64_t MonotonicMs() noexcept
Convenience milliseconds view of the monotonic counter.
Definition HfTime.h:78