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
17{
18 public:
23 Timebase() = default;
24
29 Timebase(const Timebase&) = delete;
30
35 Timebase& operator=(const Timebase&) = delete;
36
45
54
59 [[nodiscard]] static bool IsReady() noexcept { return ready_; }
60
65 static inline void DelayMicroseconds(uint32_t us)
66 {
67 if (us == 0u)
68 {
69 return;
70 }
71
72 const uint64_t START = static_cast<uint64_t>(Timebase::GetMicroseconds());
73 while ((static_cast<uint64_t>(Timebase::GetMicroseconds()) - START) < us)
74 {
75 // busy-wait
76 }
77 }
78
79 protected:
85 static void SetReady(bool ready = true) noexcept { ready_ = ready; }
86
95 static void ConfigureWrapRange(uint64_t max_valid_us, uint32_t max_valid_ms) noexcept
96 {
97 Detail::ConfigureTimebaseWrapRange(max_valid_us, max_valid_ms);
98 }
99
104 [[nodiscard]] static uint64_t GetConfiguredWrapRangeUs() noexcept
105 {
106 return Detail::TimebaseMaxValidUs();
107 }
108
113 [[nodiscard]] static uint32_t GetConfiguredWrapRangeMs() noexcept
114 {
115 return Detail::TimebaseMaxValidMs();
116 }
117
118 private:
123 static inline bool ready_ = false;
124};
125
126} // namespace LibXR
微秒时间戳 / Microsecond timestamp
毫秒时间戳 / Millisecond timestamp
时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps.
Definition timebase.hpp:17
static bool ready_
时间基是否已完成初始化。 Whether the timebase backend has been initialized.
Definition timebase.hpp:123
Timebase()=default
默认构造函数。 Default constructor.
static void ConfigureWrapRange(uint64_t max_valid_us, uint32_t max_valid_ms) noexcept
配置时间戳回绕上界。 Configure the timestamp wraparound limits.
Definition timebase.hpp:95
Timebase(const Timebase &)=delete
禁止拷贝构造。 Copy construction is disabled.
Timebase & operator=(const Timebase &)=delete
禁止拷贝赋值。 Copy assignment is disabled.
static bool IsReady() noexcept
检查时间基是否已经初始化。 Check whether the active timebase backend is initialized.
Definition timebase.hpp:59
static uint32_t GetConfiguredWrapRangeMs() noexcept
读取当前配置的毫秒回绕上界。 Read the configured millisecond wraparound limit.
Definition timebase.hpp:113
static uint64_t GetConfiguredWrapRangeUs() noexcept
读取当前配置的微秒回绕上界。 Read the configured microsecond wraparound limit.
Definition timebase.hpp:104
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.
static void DelayMicroseconds(uint32_t us)
微秒级延时 / Delay in microseconds
Definition timebase.hpp:65
LibXR 命名空间
Definition ch32_can.hpp:14