libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
linux_timebase.cpp
1#include "linux_timebase.hpp"
2
3namespace LibXR
4{
5namespace
6{
7int64_t GetElapsedMicroseconds()
8{
9 timespec ts = {};
10 clock_gettime(CLOCK_MONOTONIC, &ts);
11 return static_cast<int64_t>(ts.tv_sec - libxr_linux_start_time_spec.tv_sec) *
12 1000000LL +
13 static_cast<int64_t>(ts.tv_nsec - libxr_linux_start_time_spec.tv_nsec) / 1000LL;
14}
15} // namespace
16
18{
19 (void)clock_gettime(CLOCK_MONOTONIC, &libxr_linux_start_time_spec);
20 ConfigureWrapRange(UINT64_MAX, UINT32_MAX);
21 SetReady();
22}
23
25{
26 return MicrosecondTimestamp(static_cast<uint64_t>(GetElapsedMicroseconds()));
27}
28
29MillisecondTimestamp Timebase::GetMilliseconds()
30{
31 return MillisecondTimestamp(static_cast<uint32_t>(GetElapsedMicroseconds() / 1000LL));
32}
33} // namespace LibXR
LinuxTimebase()
构造函数 / Constructor
微秒时间戳 / Microsecond timestamp
static void ConfigureWrapRange(uint64_t max_valid_us, uint32_t max_valid_ms) noexcept
配置时间戳回绕上界。 Configure the timestamp wraparound limits.
Definition timebase.hpp:95
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.
LibXR 命名空间
Definition ch32_can.hpp:14