2#include "ch32_timebase.hpp"
17 uint32_t cnt_old = SysTick->CNT;
19 uint32_t cnt_new = SysTick->CNT;
21 auto tick_diff = tick_new - tick_old;
22 uint32_t tick_cmp = SysTick->CMP + 1;
27 static_cast<uint64_t
>(cnt_old) * 1000 / tick_cmp);
31 static_cast<uint64_t
>(cnt_new) * 1000 / tick_cmp);
void Sync(uint32_t ticks)
同步毫秒计数器。 Synchronize the millisecond counter.
static void OnSysTickInterrupt()
SysTick 中断入口辅助函数。 Helper called from the SysTick interrupt path.
static volatile uint32_t sys_tick_ms_
SysTick 毫秒计数器。 SysTick millisecond counter.
CH32Timebase()
构造函数 / Constructor
微秒时间戳 / 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.