1#include "mspm0_timebase.hpp"
10 NVIC_SetPriority(SysTick_IRQn, 0U);
11 DL_SYSTICK_enableInterrupt();
19 uint32_t milliseconds;
28SysTickSnapshot ReadSysTickSnapshot()
30 const uint32_t primask = __get_PRIMASK();
34 uint32_t pending_before;
35 uint32_t pending_after;
38 pending_before = SCB->ICSR & SCB_ICSR_PENDSTSET_Msk;
39 snapshot.value = DL_SYSTICK_getValue();
40 pending_after = SCB->ICSR & SCB_ICSR_PENDSTSET_Msk;
41 }
while (pending_before != pending_after);
43 if (pending_after != 0U)
45 ++snapshot.milliseconds;
47 __set_PRIMASK(primask);
54 const auto snapshot = ReadSysTickSnapshot();
57 const uint32_t elapsed = snapshot.value == 0U ? 0U : snapshot.period - snapshot.value;
59 static_cast<uint64_t
>(elapsed) * 1000ULL / snapshot.period);
64 return ReadSysTickSnapshot().milliseconds;
75extern "C" void SysTick_Handler(
void)
static volatile uint32_t sys_tick_ms
SysTick 毫秒计数器。 SysTick millisecond counter.
MSPM0Timebase()
构造函数 / Constructor
static void OnSysTickInterrupt()
SysTick 中断入口辅助函数。 Helper called from the SysTick interrupt path.
static void Sync(uint32_t ticks)
同步毫秒计数器。 Synchronize the millisecond counter.
微秒时间戳 / 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.
LibXR 命名空间 / LibXR namespace.