206 lines
4.7 KiB
C
206 lines
4.7 KiB
C
#include <stdbool.h>
|
||
|
||
#include "chipid.h"
|
||
#include "delay.h"
|
||
#include "sys.h"
|
||
#include "timer.h"
|
||
#include "usart.h"
|
||
#include "can.h"
|
||
#include "bsp_can.h"
|
||
#include "adc.h"
|
||
#include "ads1015.h"
|
||
#include "dc300.h"
|
||
#include "KC.h"
|
||
#include "CDZ_State.h"
|
||
#include "KC.h"
|
||
#include "CDZ_DATA.h"
|
||
#include "Sleep.h"
|
||
#include "Err_code.h"
|
||
#include "Err_Info_Process.h"
|
||
#include "uds_config.h"
|
||
#include "mm_config.h"
|
||
#include "GUNDiscriminate.h"
|
||
#include "Filtering.h"
|
||
#include "Single_event_receiver.h"
|
||
#include "SecTimer.h"
|
||
#include "kC_Features.h"
|
||
#include "24cxx.h"
|
||
#include "Task_1MS.h"
|
||
#include "Flash_StorageData.h"
|
||
#include "SEN_DCUMessage.h"
|
||
|
||
extern void IWDG_Init(void); //初始化看门狗
|
||
extern void app_can_init(void); //
|
||
extern void app_can_handle(void); //
|
||
extern void IWDG_Feed(void);
|
||
void CHIP_RESET(void);
|
||
void LED_Ctrl(void);
|
||
|
||
int main(void)
|
||
{
|
||
RCC_ClocksTypeDef RCC_Clockstemp;
|
||
SystemInit();
|
||
__ASM(" CPSIE I");
|
||
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);
|
||
SysTick_Init();
|
||
RCC_GetClocksFreq(&RCC_Clockstemp);
|
||
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
|
||
Init_KC_GPIO();
|
||
InitCAN_SendMaster();
|
||
ee_Init();
|
||
BSP_BKP_Init();
|
||
Adc_Init();
|
||
ADS1115_Init();
|
||
uart2_init(256000);//串口2初始化 蓝牙模块 4G模块
|
||
uart4_init(115200);//串口4初始化 打印串口
|
||
TIM3_Int_Init(499,719); //719分频后是50k, 500计数值之后就是100hz
|
||
Flash_InIt();
|
||
initializeBMS_default_parameters();
|
||
UdsApi_BootSwAddr_Get();
|
||
IWDG_Init();
|
||
app_can_init();
|
||
printf("版本号 %s\r\n",ApplicationVersion);
|
||
RTC_Init();
|
||
CHIP_RESET();
|
||
Filter_INIT();
|
||
CDZ_SYS.work_pattern = 1;//debug模式 1关 0开
|
||
OPEN_32_L0_RELAY();
|
||
OPEN_AC_RELAY();
|
||
CLOSE_CC2_CC_RELAY();
|
||
CLOSE_CC1_CP_RELAY();
|
||
CLOSE_GUN_TEMP_RELAY();
|
||
while(1)
|
||
{
|
||
TimeTaskDispatch_Flag();
|
||
app_can_handle();
|
||
if(TimeTaskData.F_Time_1MS == SET)
|
||
{
|
||
TimeTaskData.F_Time_1MS = RESET;
|
||
if(CDZ_SYS.work_pattern && Err_Read(3) == false && Err_Read(4) == false){
|
||
AppCtrOnoffHandle();
|
||
}
|
||
Blue_Receive_Parser();
|
||
UdsApi_1ms_task();
|
||
|
||
Sampl_Funtion.CC_Voltag();
|
||
Sampl_Funtion.KL30_Voltage();
|
||
Sampl_Funtion.TEMP1_Voltage();
|
||
Sampl_Funtion.GUN_TEMP();
|
||
|
||
Signal_Filtering();//各种回检信号滤波
|
||
DTC_FalseAlarm();
|
||
AC_Realy_AdhesionTreatment();
|
||
IWDG_Feed();
|
||
}
|
||
else if(TimeTaskData.F_Time_5MS == SET)
|
||
{
|
||
TimeTaskData.F_Time_5MS = RESET;
|
||
Debug_Mode();
|
||
Scan_work();
|
||
// work_mode This_WorkState = Get_Sampl_Data.WorkMode();
|
||
// printf("e=%d\r\n",This_WorkState);
|
||
}
|
||
else if(TimeTaskData.F_Time_10MS == SET)
|
||
{
|
||
TimeTaskData.F_Time_10MS = RESET;
|
||
Volt_SamplData.BAT_B_Reverse_Voltage = GetSampleVolt(2);
|
||
UdsApi_10ms_task();
|
||
// Pwr_BatVoltRangeMonitor();
|
||
// printf("S=%f\r\n",(Volt_SamplData.CC_Volt*5.1f)/(5.0f-Volt_SamplData.CC_Volt)+0.12f);
|
||
}
|
||
else if(TimeTaskData.F_Time_20MS == SET)
|
||
{
|
||
TimeTaskData.F_Time_20MS = RESET;
|
||
DCU_External_Failure();//外部故障
|
||
DCU_Internal_Failure();//内部故障
|
||
}
|
||
else if(TimeTaskData.F_Time_50MS == SET)
|
||
{
|
||
TimeTaskData.F_Time_50MS = RESET;
|
||
SEND_Fault_Level();//故障等级
|
||
GUN_TEMP_Filter();//枪座温度滤波
|
||
Calculate_Charging_Current();//计算充电电流
|
||
LED_Ctrl();
|
||
}
|
||
else if(TimeTaskData.F_Time_100MS == SET)
|
||
{
|
||
TimeTaskData.F_Time_100MS = RESET;
|
||
AC_DC_Adhesion_Detection();
|
||
eventDosomething();//事件处理
|
||
}
|
||
else if(TimeTaskData.F_Time_1000MS == SET)
|
||
{
|
||
// printf("1S\r\n");
|
||
TimeTaskData.F_Time_1000MS = RESET;
|
||
// if(!CDZ_SYS.work_pattern){
|
||
// Debug_Mode();
|
||
// }
|
||
Print_Debug_Info();
|
||
BluetoothConnectProcess();
|
||
PwrManageWorkPlus();
|
||
Write_Flash();
|
||
// printf("RTC_GetCounter is %d\r\n",RTC_GetCounter());
|
||
UdsApi_NVM_Init();
|
||
}
|
||
}
|
||
}
|
||
|
||
void CHIP_RESET(void)
|
||
{
|
||
if(0 != (RCC->CSR & 0x80000000))//低功耗复位标志
|
||
{
|
||
printf("低功耗复位\r\n");
|
||
}
|
||
else if(0 != (RCC->CSR & 0x40000000))//窗口看门狗复位标志
|
||
{
|
||
printf("窗口看门狗复位\r\n");
|
||
}
|
||
else if(0 != (RCC->CSR & 0x20000000))//独立看门狗复位标志
|
||
{
|
||
printf("独立看门狗复位\r\n");
|
||
}
|
||
|
||
else if(0 != (RCC->CSR & 0x10000000))//软件复位标志
|
||
{
|
||
printf("软件复位\r\n");
|
||
}
|
||
else if(0 != (RCC->CSR & 0x08000000))//上电/掉电复位标志
|
||
{
|
||
printf("上电/掉电复位\r\n");
|
||
|
||
}
|
||
else if(0 != (RCC->CSR & 0x04000000))//引脚复位标志
|
||
{
|
||
printf("引脚复位\r\n");
|
||
|
||
}
|
||
else if(0 != (RCC->CSR & 0x02000000))//BOR 复位标志
|
||
{
|
||
printf("BOR复位\r\n");
|
||
}
|
||
|
||
RCC->CSR |= 0x01000000;//清除复位标志
|
||
|
||
}
|
||
|
||
void LED_Ctrl(void)
|
||
{
|
||
static uint32_t timer = 0,timeout = 0;
|
||
static uint32_t timerout = 1000;
|
||
|
||
timerout=SysInfo.This_State == STATE_AC_Charge||Get_Sampl_Data.WorkMode()==DC_Charging?100:1000;
|
||
if(TickOut(&timer, timerout) == true)
|
||
{
|
||
if(timeout++%2)
|
||
{
|
||
CLOSE_MCU_RUN();
|
||
}
|
||
else
|
||
{
|
||
OPEN_MCU_RUN();
|
||
}
|
||
TickOut(&timer, 0);
|
||
}
|
||
}
|
||
|