Files
ODrive/Firmware/MotorControl/taskTimer.hpp
T
2020-08-25 21:40:24 -04:00

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);
}
};