BMS STM32 V4.0.0.0

This commit is contained in:
2026-08-25 17:30:40 +08:00
commit 3ae7bcb054
313 changed files with 115734 additions and 0 deletions
+231
View File
@@ -0,0 +1,231 @@
/**
******************************************************************************
* @file tim.c
* @author Jerry
* @version V2.1
* @date 19-April-2022
* @brief tim program body.
******************************************************************************
* @attention
*
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "global.h"
uint32_t tmrSys = 0;
uint32_t tmrTemp[20];
//10MS
void uf_TIM3_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 10000-1;
TIM_TimeBaseStructure.TIM_Prescaler = 72-1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //主定时器 优先级:0,0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig(TIM3, TIM_IT_Update,ENABLE );
TIM_Cmd(TIM3, ENABLE); //使能TIMx外设
}
//10ms中断
void TIM3_IRQHandler(void) //TIM3中断
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除TIMx的中断待处理位:TIM 中断源
tmrSys++;
KEY_TIM_Moni();
Cali_SOC_Moni();
Screen_TIM_Moni(); //[陶晶驰]
CAN_TIM_Moni();
MODBUS_TIM_Moni();
MODBUS1_TIM_Moni();
// DI_TIM_Moni();
// DI_Ctrl();
OCC2_TIM_Moni();
OCC2_Ctrl();
#if Addr_SetAuto
//休眠时,地址变动暂停
if(sleep_flag == 0)
{
if(paraMem.addr_FREE_Flg == 0) ADDR_Rank_Moni();
if(paraMem.addr_FREE_Flg == 0) ADDR_Assign_Moni();
}
#endif
//只有RTC时钟有问题时,才会启用下列函数
if(LSEErrFlag==1)
{
SLEEP_TIM_Moni(); //休眠的倒计时
SLEEP2_TIM_Moni(); //休眠2的倒计时
UVOff_TIM_Moni(); //欠压强制复位的倒计时
FCCCali_TIM_Moni(); //容量校准要在12h内的倒计时
}
if(Screen_RevFlg == 1) //屏幕收到完整一帧去处理
{
Screen_RevCount++;
if(Screen_RevCount > 1)
{
Screen_RevFlg = 0;
Screen_RevCount = 0;
//Screen_IT_Update();
Screen_RevHandlerFlg = 1;
}
}
if(MODBUS_RevFlg == 1) //MODBUS收到完整一帧去处理
{
MODBUS_RevCount++;
if(MODBUS_RevCount > 1)
{
MODBUS_RevFlg = 0;
MODBUS_RevCount = 0;
MODBUS_IT_TIMUpdate();
}
}
if(MODBUS1_RevFlg == 1) //MODBUS1收到完整一帧去处理
{
MODBUS1_RevCount++;
if(MODBUS1_RevCount > 1)
{
MODBUS1_RevFlg = 0;
MODBUS1_RevCount = 0;
MODBUS1_IT_TIMUpdate();
}
}
/*三选一模块*/
#if BLE_Conn
BLE_TIM_Moni(); //BLE无通信定时初始化
if(BLE_RevFlg == 1) //BLE收到完整一帧去处理
{
BLE_RevCount++;
if(BLE_RevCount > 3)
{
BLE_RevFlg = 0;
BLE_RevCount = 0;
BLE_IT_Update();
}
}
#endif
#if WIFI_Conn
WIFI_TIM_Moni(); //WIFI无通信定时初始化
if(WIFI_RevFlg == 1) //WIFI收到完整一帧去处理
{
WIFI_RevCount++;
if(WIFI_RevCount > 3)
{
WIFI_RevFlg = 0;
WIFI_RevCount = 0;
WIFI_IT_Update();
}
}
#endif
#if LTE_Conn
LTE_TIM_Moni(); //LTE无通信定时初始化
if(LTE_RevFlg == 1) //LTE收到完整一帧去处理
{
LTE_RevCount++;
if(LTE_RevCount > 3)
{
LTE_RevFlg = 0;
LTE_RevCount = 0;
//有回复,清零等待倒计时
LTE_WaitRxFlg = 0;
LTE_WaitRxDelay = 0;
if(LTE_OTA_Flag == 0)
{
LTE_4G_IT_Update();
}
else
{
LTE_OTA_IT_Update();
}
}
}
#endif
}
}
/**************************************************************************
** 函数名: TIMER_Update
** 输 入: nothing
** 输 出: tmrSys value
** 备 注:tmrSys do ++ in the SysTick_Handler function
***************************************************************************/
uint32_t TIMER_Update(void)
{
return tmrSys;
}
/**************************************************************************
** 函数名:
** 输 入:
** 输 出:
** 备 注:
***************************************************************************/
uint32_t TIMER_IsOut(uint32_t cnt, uint32_t tmr)
{
uint32_t tmp = tmrSys;
tmp = cnt > tmp ? ( (uint32_t)(-1) - cnt + tmp ) : ( tmp-cnt );
if(tmp>=tmr)
return 1;
else
return 0;
}
/**************************************************************************
** 函数名:
** 输 入:
** 输 出:
** 备 注:
***************************************************************************/
uint32_t TIMER_IsOther(uint32_t cnt, uint32_t tmr)
{
uint32_t tmp = tmrSys;
uint32_t tmp1;
tmp = cnt > tmp ? ( (uint32_t)(-1) - cnt + tmp ) : ( tmp-cnt );
tmp1 = tmp>=tmr ? (tmp - tmr): (tmr-tmp);
return tmp1;
}