1#include "stm32_timebase.hpp"
6 :
Timebase(static_cast<uint64_t>(UINT32_MAX) * 1000 + 999, UINT32_MAX)
14 uint32_t tick_old = HAL_GetTick();
15 uint32_t cnt_old = SysTick->VAL;
16 uint32_t tick_new = HAL_GetTick();
17 uint32_t cnt_new = SysTick->VAL;
19 auto time_diff = tick_new - tick_old;
20 uint32_t tick_load = SysTick->LOAD + 1;
25 static_cast<uint64_t
>(cnt_old) * 1000 / tick_load);
29 static_cast<uint64_t
>(cnt_new) * 1000 / tick_load);
40#ifdef HAL_TIM_MODULE_ENABLED
45 :
Timebase(static_cast<uint64_t>(UINT32_MAX) * 1000 + 999, UINT32_MAX)
54 uint32_t tick_old = HAL_GetTick();
55 uint32_t cnt_old = __HAL_TIM_GET_COUNTER(
htim);
56 uint32_t tick_new = HAL_GetTick();
57 uint32_t cnt_new = __HAL_TIM_GET_COUNTER(
htim);
59 uint32_t autoreload = __HAL_TIM_GET_AUTORELOAD(
htim) + 1;
61 uint32_t delta_ms = tick_new - tick_old;
66 static_cast<uint64_t
>(cnt_old) * 1000 / autoreload);
70 static_cast<uint64_t
>(cnt_new) * 1000 / autoreload);
表示微秒级时间戳的类。Class representing a timestamp in microseconds.
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
MillisecondTimestamp _get_milliseconds()
获取当前时间(毫秒级) / Get current time in milliseconds
STM32Timebase()
默认构造函数 / Default constructor
MicrosecondTimestamp _get_microseconds()
获取当前时间(微秒级) / Get current time in microseconds
STM32TimerTimebase(TIM_HandleTypeDef *timer)
构造函数 / Constructor
MillisecondTimestamp _get_milliseconds()
获取当前时间(毫秒级) / Get current time in milliseconds
static TIM_HandleTypeDef * htim
硬件定时器句柄指针 / Static pointer to hardware timer handle
MicrosecondTimestamp _get_microseconds()
获取当前时间(微秒级) / Get current time in microseconds
时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps.