libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
timebase.hpp
1#pragma once
2
3#include "libxr_time.hpp"
4
5namespace LibXR
6{
7
18{
19 public:
30 Timebase(uint64_t max_valid_us = UINT64_MAX, uint32_t max_valid_ms = UINT32_MAX)
31 {
32 libxr_timebase_max_valid_ms = max_valid_ms;
33 libxr_timebase_max_valid_us = max_valid_us;
34 timebase = this;
35 }
36
50
64
69 static inline void DelayMicroseconds(uint32_t us)
70 {
71 if (us == 0u)
72 {
73 return;
74 }
75
76 const uint64_t START = static_cast<uint64_t>(Timebase::GetMicroseconds());
77 while ((static_cast<uint64_t>(Timebase::GetMicroseconds()) - START) < us)
78 {
79 // busy-wait
80 }
81 }
82
95 virtual MicrosecondTimestamp _get_microseconds() = 0; // NOLINT
96
110
119 static inline Timebase* timebase = nullptr; // NOLINT
120};
121
122} // namespace LibXR
表示微秒级时间戳的类。Class representing a timestamp in microseconds.
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps.
Definition timebase.hpp:18
static Timebase * timebase
静态指针,用于存储全局时间基对象。 Static pointer storing the global timebase instance.
Definition timebase.hpp:119
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
virtual MillisecondTimestamp _get_milliseconds()=0
纯虚函数,获取当前时间的毫秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in milliseconds...
virtual MicrosecondTimestamp _get_microseconds()=0
纯虚函数,获取当前时间的微秒级时间戳(由派生类实现)。 Pure virtual function for obtaining the current timestamp in microseconds...
static MicrosecondTimestamp GetMicroseconds()
获取当前时间的微秒级时间戳。 Gets the current timestamp in microseconds.
Definition timebase.hpp:49
static MillisecondTimestamp GetMilliseconds()
获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
Definition timebase.hpp:63
static void DelayMicroseconds(uint32_t us)
微秒级延时 / Delay in microseconds
Definition timebase.hpp:69
LibXR 命名空间
Definition ch32_can.hpp:14