2024-12-09 09:53:43 +00:00
|
|
|
|
|
|
|
|
|
#include "checkTime.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _timeData {
|
|
|
|
|
/* 程序执行前的时间 */
|
|
|
|
|
uint32_t time_ms1;
|
|
|
|
|
uint16_t time_tick1;
|
|
|
|
|
|
|
|
|
|
/* 程序执行完的时间 */
|
|
|
|
|
uint32_t time_ms2;
|
|
|
|
|
uint16_t time_tick2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 程序执行所用的时间(ms) */
|
|
|
|
|
float time_s;
|
|
|
|
|
}timeData;
|
|
|
|
|
|
|
|
|
|
static timeData checkTimeData;
|
|
|
|
|
|
|
|
|
|
volatile static uint32_t hw_sys_tick_ms = 0; //ms 自增计数变量
|
|
|
|
|
|
2024-12-10 10:29:05 +00:00
|
|
|
|
float checkAbnormalTime;
|
|
|
|
|
|
|
|
|
|
|
2024-12-09 09:53:43 +00:00
|
|
|
|
#define tim TIM15
|
|
|
|
|
#define timLard 36000.0
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* hw_inc_tick函数
|
|
|
|
|
*
|
|
|
|
|
* 本函数用于递增硬件系统的毫秒计时器hw_sys_tick_ms。
|
|
|
|
|
* 每次调用此函数,hw_sys_tick_ms将增加1。
|
|
|
|
|
*
|
|
|
|
|
* 注意:此函数没有输入参数和返回值。
|
|
|
|
|
*/
|
|
|
|
|
void hw_inc_tick(void)
|
|
|
|
|
{
|
|
|
|
|
++hw_sys_tick_ms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkTimeInit(void)
|
|
|
|
|
{
|
|
|
|
|
checkTimeData.time_ms1 = hw_sys_tick_ms;
|
|
|
|
|
checkTimeData.time_tick1 = tim->CNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float getCheckTime(void)
|
|
|
|
|
{
|
|
|
|
|
checkTimeData.time_ms2 = hw_sys_tick_ms;
|
|
|
|
|
checkTimeData.time_tick2 = tim->CNT;
|
|
|
|
|
|
|
|
|
|
checkTimeData.time_s = checkTimeData.time_ms2 - checkTimeData.time_ms1
|
|
|
|
|
+ (checkTimeData.time_tick2 - checkTimeData.time_tick1) / timLard;
|
|
|
|
|
|
|
|
|
|
return checkTimeData.time_s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|