1#include "hpm_timebase.hpp"
7MCHTMR_Type* g_timer = HPM_MCHTMR;
8uint32_t g_clock_hz = 0u;
10static inline uint64_t ConvertTicksToTime(uint64_t ticks, uint32_t freq_hz,
13 if (freq_hz == 0u)
return 0u;
15 const uint64_t whole = ticks / freq_hz;
16 const uint64_t rem = ticks - (whole * freq_hz);
17 const uint64_t frac = (rem * scale) / freq_hz;
18 return whole * scale + frac;
25 g_clock_hz = clock_get_frequency(clock);
32 const uint64_t ticks = mchtmr_get_count(g_timer);
38 const uint64_t ticks = mchtmr_get_count(g_timer);
HPMTimebase(MCHTMR_Type *timer=HPM_MCHTMR, clock_name_t clock=clock_mchtmr0)
构造 HPM 时间基对象 / Construct an HPM timebase object.
微秒时间戳 / Microsecond timestamp
毫秒时间戳 / Millisecond timestamp
static void ConfigureWrapRange(uint64_t max_valid_us, uint32_t max_valid_ms) noexcept
配置时间戳回绕上界。 Configure the timestamp wraparound limits.
static void SetReady(bool ready=true) noexcept
设置时间基就绪状态。 Set the timebase ready flag.
static MicrosecondTimestamp GetMicroseconds()
获取当前时间的微秒级时间戳。 Gets the current timestamp in microseconds.
static MillisecondTimestamp GetMilliseconds()
获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.