sggt/App/APP_WU/Src/timer.c

108 lines
2.1 KiB
C

/*
* @Author: wujunchao wujunchao@wuxismart.com
* @Date: 2024-12-27 11:44:23
* @LastEditors: wujunchao wujunchao@wuxismart.com
* @LastEditTime: 2025-04-01 16:21:10
* @FilePath: \signal_generator\App\APP_WU\timer.c
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
#include "timer.h"
int heart_1000ms_flag = 0;
int heart_1000ms_cnt = 0;
int battery_3000ms_flag = 0;
int battery_3000ms_cnt = 0;
int plot_1500ms_flag = 0;
int plot_1500ms_cnt = 0;
int twk_1000ms_flag = 0;
int twk_1000ms_cnt = 0;
int input_500ms_flag = 0;
int input_500ms_cnt = 0;
void duty_tim3(void)
{
freq_signal.over_cnt++;
}
void duty_tim6(void)
{
lv_tick_inc(1);
heart_1000ms_cnt++;
if( heart_1000ms_cnt >= 1000)
{
heart_1000ms_cnt = 0;
heart_1000ms_flag = 1;
}
battery_3000ms_cnt++;
if( battery_3000ms_cnt >= 3000)
{
battery_3000ms_cnt = 0;
battery_3000ms_flag = 1;
}
plot_1500ms_cnt++;
if( plot_1500ms_cnt >= 1500)
{
plot_1500ms_cnt = 0;
plot_1500ms_flag = 1;
}
twk_1000ms_cnt++;
if( twk_1000ms_cnt >= 1000)
{
twk_1000ms_cnt = 0;
twk_1000ms_flag = 1;
}
input_500ms_cnt++;
if( input_500ms_cnt >= 500)
{
input_500ms_cnt = 0;
input_500ms_flag = 1;
}
}
void delay_cnt(uint16_t cnt)
{
while(cnt > 0)
{
cnt--;
}
}
#define CPU_FREQUENCY_MHZ 165.888 // STM32时钟主频
void wu_delay_us(__IO uint32_t delay)
{
int last, curr, val;
int temp;
while (delay != 0)
{
temp = delay > 900 ? 900 : delay;
last = SysTick->VAL;
curr = last - CPU_FREQUENCY_MHZ * temp;
if (curr >= 0)
{
do
{
val = SysTick->VAL;
}
while ((val < last) && (val >= curr));
}
else
{
curr += CPU_FREQUENCY_MHZ * 1000;
do
{
val = SysTick->VAL;
}
while ((val <= last) || (val > curr));
}
delay -= temp;
}
}