34 uint32_t ms_old = HAL_GetTick();
35 uint32_t tick_value_old = SysTick->VAL;
36 uint32_t ms_new = HAL_GetTick();
37 uint32_t tick_value_new = SysTick->VAL;
39 auto time_diff = ms_new - ms_old;
40 uint32_t tick_load = SysTick->LOAD + 1;
44 return TimestampUS(
static_cast<uint64_t
>(ms_new) * 1000 + 1000 -
45 static_cast<uint64_t
>(tick_value_old) * 1000 / tick_load);
48 return TimestampUS(
static_cast<uint64_t
>(ms_new) * 1000 + 1000 -
49 static_cast<uint64_t
>(tick_value_new) * 1000 / tick_load);
67#ifdef HAL_TIM_MODULE_ENABLED
81 :
Timebase(static_cast<uint64_t>(UINT32_MAX) * 1000 + 999, UINT32_MAX)
97 uint32_t ms_old = HAL_GetTick();
98 uint32_t tick_value_old = __HAL_TIM_GET_COUNTER(
htim);
99 uint32_t ms_new = HAL_GetTick();
100 uint32_t tick_value_new = __HAL_TIM_GET_COUNTER(
htim);
102 uint32_t autoreload = __HAL_TIM_GET_AUTORELOAD(
htim) + 1;
104 uint32_t delta_ms = ms_new - ms_old;
108 return TimestampUS(
static_cast<uint64_t
>(ms_new) * 1000 +
109 static_cast<uint64_t
>(tick_value_old) * 1000 / autoreload);
112 return TimestampUS(
static_cast<uint64_t
>(ms_new) * 1000 +
113 static_cast<uint64_t
>(tick_value_new) * 1000 / autoreload);
133 static TIM_HandleTypeDef*
htim;
获取基于STM32 SysTick计数器的时间基准(微秒与毫秒) / Provides a timebase using STM32 SysTick timer (microseconds and mi...
TimestampUS _get_microseconds()
获取当前时间(微秒级) / Get current time in microseconds
TimestampMS _get_milliseconds()
获取当前时间(毫秒级) / Get current time in milliseconds
STM32Timebase()
默认构造函数 / Default constructor
基于硬件定时器的时间基准类 / Provides a timebase using hardware timer (TIM)
STM32TimerTimebase(TIM_HandleTypeDef *timer)
构造函数 / Constructor
TimestampUS _get_microseconds()
获取当前时间(微秒级) / Get current time in microseconds
static TIM_HandleTypeDef * htim
硬件定时器句柄指针 / Static pointer to hardware timer handle
TimestampMS _get_milliseconds()
获取当前时间(毫秒级) / Get current time in milliseconds
时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps.
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
表示微秒级时间戳的类。Class representing a timestamp in microseconds.