libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::MSPM0Timebase Class Reference
Inheritance diagram for LibXR::MSPM0Timebase:
[legend]
Collaboration diagram for LibXR::MSPM0Timebase:
[legend]

Public Member Functions

MicrosecondTimestamp _get_microseconds () override
 纯虚函数,获取当前时间的微秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in microseconds (implemented by derived classes).
 
MillisecondTimestamp _get_milliseconds () override
 纯虚函数,获取当前时间的毫秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in milliseconds (implemented by derived classes).
 
- Public Member Functions inherited from LibXR::Timebase
 Timebase (uint64_t max_valid_us=UINT64_MAX, uint32_t max_valid_ms=UINT32_MAX)
 默认构造函数,初始化全局时间基指针。 Default constructor, initializing the global timebase pointer.
 

Static Public Member Functions

static void OnSysTickInterrupt ()
 
static void Sync (uint32_t ticks)
 
- Static Public Member Functions inherited from LibXR::Timebase
static MicrosecondTimestamp GetMicroseconds ()
 获取当前时间的微秒级时间戳。 Gets the current timestamp in microseconds.
 
static MillisecondTimestamp GetMilliseconds ()
 获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
 
static void DelayMicroseconds (uint32_t us)
 微秒级延时 / Delay in microseconds
 

Static Public Attributes

static volatile uint32_t sys_tick_ms
 
- Static Public Attributes inherited from LibXR::Timebase
static Timebasetimebase = nullptr
 静态指针,用于存储全局时间基对象。 Static pointer storing the global timebase instance.
 

Detailed Description

Definition at line 9 of file mspm0_timebase.hpp.

Constructor & Destructor Documentation

◆ MSPM0Timebase()

MSPM0Timebase::MSPM0Timebase ( )

Definition at line 5 of file mspm0_timebase.cpp.

6 : Timebase(static_cast<uint64_t>(UINT32_MAX) * 1000 + 999, UINT32_MAX)
7{
8}
Timebase(uint64_t max_valid_us=UINT64_MAX, uint32_t max_valid_ms=UINT32_MAX)
默认构造函数,初始化全局时间基指针。 Default constructor, initializing the global timebase pointer.
Definition timebase.hpp:30

Member Function Documentation

◆ _get_microseconds()

MicrosecondTimestamp MSPM0Timebase::_get_microseconds ( )
overridevirtual

纯虚函数,获取当前时间的微秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in microseconds (implemented by derived classes).

该函数需要在派生类中实现,以提供具体的时间获取机制。 This function must be implemented in derived classes to provide the actual time retrieval mechanism.

Returns
返回当前的时间戳(单位:微秒)。 Returns the current timestamp (in microseconds).

Implements LibXR::Timebase.

Definition at line 10 of file mspm0_timebase.cpp.

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}
表示微秒级时间戳的类。Class representing a timestamp in microseconds.

◆ _get_milliseconds()

MillisecondTimestamp MSPM0Timebase::_get_milliseconds ( )
overridevirtual

纯虚函数,获取当前时间的毫秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in milliseconds (implemented by derived classes).

该函数需要在派生类中实现,以提供具体的时间获取机制。 This function must be implemented in derived classes to provide the actual time retrieval mechanism.

Returns
返回当前的时间戳(单位:毫秒)。 Returns the current timestamp (in milliseconds).

Implements LibXR::Timebase.

Definition at line 44 of file mspm0_timebase.cpp.

44{ return sys_tick_ms; }

◆ OnSysTickInterrupt()

void MSPM0Timebase::OnSysTickInterrupt ( )
static

Definition at line 45 of file mspm0_timebase.cpp.

45{ sys_tick_ms++; }

◆ Sync()

void MSPM0Timebase::Sync ( uint32_t ticks)
static

Definition at line 46 of file mspm0_timebase.cpp.

46{ sys_tick_ms = ticks; }

Field Documentation

◆ sys_tick_ms

volatile uint32_t LibXR::MSPM0Timebase::sys_tick_ms
inlinestatic

Definition at line 22 of file mspm0_timebase.hpp.


The documentation for this class was generated from the following files: