mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-19 02:43:27 +08:00
27 lines
631 B
C++
27 lines
631 B
C++
#pragma once
|
|
|
|
#include <tim.h>
|
|
#include <stdint.h>
|
|
#include <algorithm>
|
|
|
|
inline uint16_t sample_TIM13(){
|
|
constexpr uint16_t clocks_per_cnt = (uint16_t)((float)TIM_1_8_CLOCK_HZ / (float)TIM_APB1_CLOCK_HZ);
|
|
return clocks_per_cnt * htim13.Instance->CNT; // TODO: Use a hw_config
|
|
}
|
|
|
|
struct TaskTimer {
|
|
uint32_t startTime = 0;
|
|
uint32_t endTime = 0;
|
|
uint32_t length = 0;
|
|
uint32_t maxLength = 0;
|
|
|
|
void beginTimer(){
|
|
startTime = sample_TIM13();
|
|
}
|
|
|
|
void stopTimer(){
|
|
endTime = sample_TIM13();
|
|
length = endTime - startTime;
|
|
maxLength = std::max(maxLength, length);
|
|
}
|
|
}; |