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
5MSPM0Timebase::MSPM0Timebase()
6 : Timebase(static_cast<uint64_t>(UINT32_MAX) * 1000 + 999, UINT32_MAX)
7{
8}
9
11{
12 do
13 {
14 uint32_t tick_old = sys_tick_ms;
15 uint32_t val_old = DL_SYSTICK_getValue();
16 uint32_t tick_new = sys_tick_ms;
17 uint32_t val_new = DL_SYSTICK_getValue();
18
19 auto tick_diff = tick_new - tick_old;
20
21 uint32_t cycles_per_ms = DL_SYSTICK_getPeriod() + 1;
22
23 switch (tick_diff)
24 {
25 case 0:
27 static_cast<uint64_t>(tick_new) * 1000 +
28 static_cast<uint64_t>(DL_SYSTICK_getPeriod() - val_old) * 1000 /
29 cycles_per_ms);
30 case 1:
31 /* 中断发生在两次读取之间 / Interrupt happened between two reads */
33 static_cast<uint64_t>(tick_new) * 1000 +
34 static_cast<uint64_t>(DL_SYSTICK_getPeriod() - val_new) * 1000 /
35 cycles_per_ms);
36 default:
37 /* 中断耗时过长(超过1ms),程序异常 / Indicates that interrupt took more than
38 * 1ms, an error case */
39 continue;
40 }
41 } while (true);
42}
43
45void MSPM0Timebase::OnSysTickInterrupt() { sys_tick_ms++; }
46void MSPM0Timebase::Sync(uint32_t ticks) { sys_tick_ms = ticks; }
47
48extern "C" void SysTick_Handler(void) // NOLINT
49{
50 LibXR::MSPM0Timebase::OnSysTickInterrupt();
51}
MillisecondTimestamp _get_milliseconds() override
纯虚函数,获取当前时间的毫秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in milliseconds...
MicrosecondTimestamp _get_microseconds() override
纯虚函数,获取当前时间的微秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in microseconds...
表示微秒级时间戳的类。Class representing a timestamp in microseconds.
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps.
Definition timebase.hpp:18
LibXR 命名空间
Definition ch32_can.hpp:14