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
11namespace
12{
13#if SOC_SYSTIMER_SUPPORTED
14systimer_hal_context_t g_systimer_hal = {};
15bool g_systimer_ready = false;
16#endif
17} // namespace
18
20{
21 ConfigureWrapRange(UINT64_MAX, UINT32_MAX);
22#if SOC_SYSTIMER_SUPPORTED
23 if (!g_systimer_ready)
24 {
25 systimer_hal_init(&g_systimer_hal);
26
27 systimer_hal_tick_rate_ops_t tick_rate_ops = {
28 .ticks_to_us = systimer_ticks_to_us,
29 .us_to_ticks = systimer_us_to_ticks,
30 };
31 systimer_hal_set_tick_rate_ops(&g_systimer_hal, &tick_rate_ops);
32 systimer_hal_enable_counter(&g_systimer_hal, SYSTIMER_COUNTER_ESPTIMER);
33 g_systimer_ready = true;
34 }
35#endif
36 SetReady();
37}
38
40{
41#if SOC_SYSTIMER_SUPPORTED
42 if (g_systimer_ready)
43 {
44 return systimer_hal_get_time(&g_systimer_hal, SYSTIMER_COUNTER_ESPTIMER);
45 }
46#endif
47 return static_cast<MicrosecondTimestamp>(esp_timer_get_time());
48}
49
50MillisecondTimestamp IRAM_ATTR Timebase::GetMilliseconds()
51{
52 return MillisecondTimestamp(static_cast<uint32_t>(GetMicroseconds() / 1000ULL));
53}
54
55} // namespace LibXR
ESP32Timebase()
构造函数 / 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