libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
mspm0_timebase.cpp
1#include "mspm0_timebase.hpp"
2
3using namespace LibXR;
4
6{
7 ConfigureWrapRange(static_cast<uint64_t>(UINT32_MAX) * 1000ULL + 999ULL, UINT32_MAX);
8 SetReady();
9}
10
12{
13 do
14 {
15 uint32_t tick_old = sys_tick_ms;
16 uint32_t val_old = DL_SYSTICK_getValue();
17 uint32_t tick_new = sys_tick_ms;
18 uint32_t val_new = DL_SYSTICK_getValue();
19
20 auto tick_diff = tick_new - tick_old;
21
22 uint32_t cycles_per_ms = DL_SYSTICK_getPeriod();
23
24 switch (tick_diff)
25 {
26 case 0:
28 static_cast<uint64_t>(tick_new) * 1000 +
29 static_cast<uint64_t>(DL_SYSTICK_getPeriod() - val_old) * 1000 /
30 cycles_per_ms);
31 case 1:
32 /* 中断发生在两次读取之间 / Interrupt happened between two reads */
34 static_cast<uint64_t>(tick_new) * 1000 +
35 static_cast<uint64_t>(DL_SYSTICK_getPeriod() - val_new) * 1000 /
36 cycles_per_ms);
37 default:
38 /* 中断耗时过长(超过1ms),程序异常 / Indicates that interrupt took more
39 * than 1ms, an error case */
40 continue;
41 }
42 } while (true);
43}
44
47void MSPM0Timebase::Sync(uint32_t ticks) { sys_tick_ms = ticks; }
48
49extern "C" void SysTick_Handler(void) // NOLINT
50{
52}
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.
Definition timebase.hpp:95
static void SetReady(bool ready=true) noexcept
设置时间基就绪状态。 Set the timebase ready flag.
Definition timebase.hpp:85
static MicrosecondTimestamp GetMicroseconds()
获取当前时间的微秒级时间戳。 Gets the current timestamp in microseconds.
static MillisecondTimestamp GetMilliseconds()
获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
LibXR 命名空间
Definition ch32_can.hpp:14