libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::LinuxTimebase Class Reference

Linux 时间基准实现 / Linux timebase implementation. More...

#include <linux_timebase.hpp>

Inheritance diagram for LibXR::LinuxTimebase:
[legend]
Collaboration diagram for LibXR::LinuxTimebase:
[legend]

Public Member Functions

MicrosecondTimestamp _get_microseconds ()
 获取当前微秒计数 / Get current timestamp in microseconds
 
MillisecondTimestamp _get_milliseconds ()
 获取当前毫秒计数 / Get current timestamp in milliseconds
 
- 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 Private Member Functions

static int64_t GetElapsedMicroseconds ()
 

Additional Inherited Members

- 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 inherited from LibXR::Timebase
static Timebasetimebase = nullptr
 静态指针,用于存储全局时间基对象。 Static pointer storing the global timebase instance.
 

Detailed Description

Linux 时间基准实现 / Linux timebase implementation.

Definition at line 13 of file linux_timebase.hpp.

Member Function Documentation

◆ _get_microseconds()

MicrosecondTimestamp LibXR::LinuxTimebase::_get_microseconds ( )
inlinevirtual

获取当前微秒计数 / Get current timestamp in microseconds

Returns
MicrosecondTimestamp 微秒时间戳 / Microsecond timestamp

Implements LibXR::Timebase.

Definition at line 21 of file linux_timebase.hpp.

22 {
23 return MicrosecondTimestamp(static_cast<uint64_t>(GetElapsedMicroseconds()));
24 }

◆ _get_milliseconds()

MillisecondTimestamp LibXR::LinuxTimebase::_get_milliseconds ( )
inlinevirtual

获取当前毫秒计数 / Get current timestamp in milliseconds

Returns
MillisecondTimestamp 毫秒时间戳 / Millisecond timestamp

Implements LibXR::Timebase.

Definition at line 31 of file linux_timebase.hpp.

32 {
33 return MillisecondTimestamp(static_cast<uint32_t>(GetElapsedMicroseconds() / 1000LL));
34 }

◆ GetElapsedMicroseconds()

static int64_t LibXR::LinuxTimebase::GetElapsedMicroseconds ( )
inlinestaticprivate

Definition at line 37 of file linux_timebase.hpp.

38 {
39 struct timespec ts = {};
40 clock_gettime(CLOCK_MONOTONIC, &ts);
41 return static_cast<int64_t>(ts.tv_sec - libxr_linux_start_time_spec.tv_sec) * 1000000LL +
42 static_cast<int64_t>(ts.tv_nsec - libxr_linux_start_time_spec.tv_nsec) / 1000LL;
43 }

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