libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::CH32Timebase Class Reference

CH32 硬件计数器时间基准 / CH32 hardware-counter timebase. More...

#include <ch32_timebase.hpp>

Inheritance diagram for LibXR::CH32Timebase:
[legend]
Collaboration diagram for LibXR::CH32Timebase:
[legend]

Public Member Functions

 CH32Timebase ()
 构造函数 / Constructor
 
- Public Member Functions inherited from LibXR::Timebase
 Timebase ()=default
 默认构造函数。 Default constructor.
 
 Timebase (const Timebase &)=delete
 禁止拷贝构造。 Copy construction is disabled.
 
Timebase & operator= (const Timebase &)=delete
 禁止拷贝赋值。 Copy assignment is disabled.
 

Additional Inherited Members

- Static Public Member Functions inherited from LibXR::Timebase
static MicrosecondTimestamp GetMicroseconds ()
 获取当前时间的微秒级时间戳。 Gets the current timestamp in microseconds.
 
static MillisecondTimestamp GetMilliseconds ()
 获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
 
static bool IsReady () noexcept
 检查时间基是否已经初始化。 Check whether the active timebase backend is initialized.
 
static void DelayMicroseconds (uint32_t us)
 微秒级延时 / Delay in microseconds
 
- Static Protected Member Functions inherited from LibXR::Timebase
static void SetReady (bool ready=true) noexcept
 设置时间基就绪状态。 Set the timebase ready flag.
 
static void ConfigureWrapRange (uint64_t max_valid_us, uint32_t max_valid_ms) noexcept
 配置时间戳回绕上界。 Configure the timestamp wraparound limits.
 
static uint64_t GetConfiguredWrapRangeUs () noexcept
 读取当前配置的微秒回绕上界。 Read the configured microsecond wraparound limit.
 
static uint32_t GetConfiguredWrapRangeMs () noexcept
 读取当前配置的毫秒回绕上界。 Read the configured millisecond wraparound limit.
 

Detailed Description

CH32 硬件计数器时间基准 / CH32 hardware-counter timebase.

Note
BSP 必须预先将 SysTick 配置为 HCLK 驱动的 64 位自由运行向上计数器。 使用期间不得停止、清零计数器或改变 HCLK;HCLK 不低于 1 MHz。 The BSP must configure SysTick as a 64-bit, HCLK-driven, free-running up-counter before initialization. The counter must not be stopped or reset, and HCLK must remain unchanged and at least 1 MHz during use.
微秒和毫秒均由硬件计数值换算,不依赖 SysTick 中断的软件计数。 初始化完成后可在任务或中断中读取,比较值和 tick 中断由 BSP 管理。 Microseconds and milliseconds are derived from the hardware counter without a software interrupt count. Reads are allowed from tasks or interrupts after initialization; the BSP manages compare deadlines and tick interrupts.

Definition at line 24 of file ch32_timebase.hpp.

Constructor & Destructor Documentation

◆ CH32Timebase()

CH32Timebase::CH32Timebase ( )

构造函数 / Constructor

缓存计数器时钟频率,配置时间戳回绕范围并标记时间基就绪。 Cache the counter clock frequency, configure timestamp wrap ranges, and mark the timebase ready.

Definition at line 47 of file ch32_timebase.cpp.

48{
49 const uint32_t control = SysTick->CTLR;
50 ASSERT((control & (SYSTICK_ENABLE | SYSTICK_CLOCK_HCLK)) ==
51 (SYSTICK_ENABLE | SYSTICK_CLOCK_HCLK) &&
52 (control & (SYSTICK_AUTO_RELOAD | SYSTICK_COUNT_DOWN)) == 0U &&
53 SystemCoreClock >= MICROSECONDS_PER_SECOND);
54
55 timebase_clock_hz = SystemCoreClock;
56 ConfigureWrapRange(CyclesToUnits(UINT64_MAX, MICROSECONDS_PER_SECOND), UINT32_MAX);
57 SetReady();
58}
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

The documentation for this class was generated from the following files: