libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
esp_timebase.cpp
1#include "esp_timebase.hpp"
2
3#include "esp_attr.h"
4#if SOC_SYSTIMER_SUPPORTED
5#include "esp_private/systimer.h"
6#endif
7
8namespace LibXR
9{
10
11ESP32Timebase::ESP32Timebase() : Timebase(static_cast<uint64_t>(UINT64_MAX), UINT32_MAX)
12{
13#if SOC_SYSTIMER_SUPPORTED
14 systimer_hal_init(&systimer_hal_);
15
16 systimer_hal_tick_rate_ops_t tick_rate_ops = {
17 .ticks_to_us = systimer_ticks_to_us,
18 .us_to_ticks = systimer_us_to_ticks,
19 };
20 systimer_hal_set_tick_rate_ops(&systimer_hal_, &tick_rate_ops);
21 systimer_hal_enable_counter(&systimer_hal_, SYSTIMER_COUNTER_ESPTIMER);
22 systimer_ready_ = true;
23#endif
24}
25
27{
28#if SOC_SYSTIMER_SUPPORTED
29 if (systimer_ready_)
30 {
31 return systimer_hal_get_time(&systimer_hal_, SYSTIMER_COUNTER_ESPTIMER);
32 }
33#endif
34 return static_cast<MicrosecondTimestamp>(esp_timer_get_time());
35}
36
38{
39 return MillisecondTimestamp(static_cast<uint32_t>(_get_microseconds() / 1000ULL));
40}
41
42} // namespace LibXR
ESP32Timebase()
构造函数 / Constructor
MicrosecondTimestamp _get_microseconds() override
获取当前微秒计数 / Get current timestamp in microseconds
MillisecondTimestamp _get_milliseconds() override
获取当前毫秒计数 / Get current timestamp in milliseconds
表示微秒级时间戳的类。Class representing a timestamp in microseconds.
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps.
Definition timebase.hpp:18
LibXR 命名空间
Definition ch32_can.hpp:14