libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
stm32_timebase.hpp
1#pragma once
2
3#include "main.h"
4#include "timebase.hpp"
5
6namespace LibXR
7{
13class STM32Timebase : public Timebase
14{
15 public:
22
33 {
38
39 auto time_diff = ms_new - ms_old;
40 uint32_t tick_load = SysTick->LOAD + 1;
41 switch (time_diff)
42 {
43 case 0:
44 return TimestampUS(static_cast<uint64_t>(ms_new) * 1000 + 1000 -
45 static_cast<uint64_t>(tick_value_old) * 1000 / tick_load);
46 case 1:
47 /* 中断发生在两次读取之间 / Interrupt happened between two reads */
48 return TimestampUS(static_cast<uint64_t>(ms_new) * 1000 + 1000 -
49 static_cast<uint64_t>(tick_value_new) * 1000 / tick_load);
50 default:
51 /* 中断耗时过长(超过1ms),程序异常 / Indicates that interrupt took more than
52 * 1ms, an error case */
53 ASSERT(false);
54 }
55
56 return 0;
57 }
58
65};
66
67#ifdef HAL_TIM_MODULE_ENABLED
68
74{
75 public:
85
96 {
101
103
105 switch (delta_ms)
106 {
107 case 0:
108 return TimestampUS(static_cast<uint64_t>(ms_new) * 1000 +
109 static_cast<uint64_t>(tick_value_old) * 1000 / autoreload);
110 case 1:
111 /* 中断发生在两次读取之间 / Interrupt happened between two reads */
112 return TimestampUS(static_cast<uint64_t>(ms_new) * 1000 +
113 static_cast<uint64_t>(tick_value_new) * 1000 / autoreload);
114 default:
115 /* 中断耗时过长(超过1ms),程序异常 / Indicates that interrupt took more than
116 * 1ms, an error case */
117 ASSERT(false);
118 }
119
120 return 0;
121 }
122
129
133 static TIM_HandleTypeDef* htim; // NOLINT
134};
135
136#endif
137
138} // namespace LibXR
获取基于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.
Definition timebase.hpp:18
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
表示微秒级时间戳的类。Class representing a timestamp in microseconds.
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值