libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
webasm_timebase.cpp
1#include "webasm_timebase.hpp"
2
3#include <chrono>
4
5namespace LibXR
6{
7namespace
8{
9std::chrono::system_clock::time_point g_start_time;
10} // namespace
11
13{
14 g_start_time = std::chrono::system_clock::now();
15 ConfigureWrapRange(UINT64_MAX, UINT32_MAX);
16 SetReady();
17}
18
20{
21 const auto now = std::chrono::system_clock::now();
22 const auto us =
23 std::chrono::duration_cast<std::chrono::microseconds>(now - g_start_time).count();
24 return MicrosecondTimestamp(static_cast<uint64_t>(us));
25}
26
27MillisecondTimestamp Timebase::GetMilliseconds()
28{
29 const auto now = std::chrono::system_clock::now();
30 const auto ms =
31 std::chrono::duration_cast<std::chrono::milliseconds>(now - g_start_time).count();
32 return MillisecondTimestamp(static_cast<uint32_t>(ms));
33}
34} // namespace LibXR
微秒时间戳 / 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.
WebAsmTimebase()
构造函数 / Constructor
LibXR 命名空间
Definition ch32_can.hpp:14