9ceb218f80
Co-authored-by: Cursor <cursoragent@cursor.com>
58 lines
1.4 KiB
C
58 lines
1.4 KiB
C
#include "tim/app_tim.h"
|
|
#include "bms/bms_interface.h"
|
|
#include "gd32h7xx.h"
|
|
#include "sys_drv_init.h"
|
|
|
|
void v_app_tim_init(void)
|
|
{
|
|
timer_parameter_struct timer_initpara;
|
|
|
|
/* TIMER7: generate update interrupt periodically. */
|
|
rcu_periph_clock_enable(RCU_TIMER7);
|
|
timer_deinit(TIMER7);
|
|
timer_struct_para_init(&timer_initpara);
|
|
|
|
timer_initpara.prescaler = 23999U;
|
|
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
|
|
timer_initpara.counterdirection = TIMER_COUNTER_UP;
|
|
timer_initpara.period = 9U;
|
|
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
|
|
timer_initpara.repetitioncounter = 0U;
|
|
timer_init(TIMER7, &timer_initpara);
|
|
|
|
timer_interrupt_flag_clear(TIMER7, TIMER_INT_FLAG_UP);
|
|
timer_interrupt_enable(TIMER7, TIMER_INT_UP);
|
|
timer_enable(TIMER7);
|
|
}
|
|
|
|
void v_app_tim_irq_handler(void)
|
|
{
|
|
if (RESET != timer_interrupt_flag_get(TIMER7, TIMER_INT_FLAG_UP))
|
|
{
|
|
timer_interrupt_flag_clear(TIMER7, TIMER_INT_FLAG_UP);
|
|
v_app_tim_tick_1ms();
|
|
}
|
|
}
|
|
|
|
void v_app_tim_tick_1ms(void)
|
|
{
|
|
static U16_T cnt = 0U;
|
|
|
|
cnt++;
|
|
|
|
/* Run LED heartbeat from timer context (independent from IdleHook). */
|
|
if ((cnt % 500U) == 0U)
|
|
{
|
|
RUN_LED_TOGGLE();
|
|
WATCKDOG_TOGGLE();
|
|
}
|
|
|
|
if ((cnt % 10U) == 0U)
|
|
{
|
|
v_bms_add_timer(); /* 10ms */
|
|
}
|
|
|
|
v_delay_set_tymer_val(); /* bms timeout counter */
|
|
}
|
|
|