CELIS/USER/main.c

206 lines
4.7 KiB
C
Raw Normal View History

2024-08-09 06:24:48 +00:00
#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); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD>
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(); //<2F><><EFBFBD><EFBFBD>NVIC<49>жϷ<D0B6><CFB7><EFBFBD>2:2λ<32><CEBB>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><32><CEBB>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD>
Init_KC_GPIO();
InitCAN_SendMaster();
ee_Init();
BSP_BKP_Init();
Adc_Init();
ADS1115_Init();
uart2_init(256000);//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>ʼ<EFBFBD><CABC> <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3> 4Gģ<47><C4A3>
uart4_init(115200);//<2F><><EFBFBD><EFBFBD>4<EFBFBD><34>ʼ<EFBFBD><CABC> <20><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
TIM3_Int_Init(499,719); //719<31><39>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>50k, 500<30><30><EFBFBD><EFBFBD>ֵ֮<D6B5><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100hz
Flash_InIt();
initializeBMS_default_parameters();
UdsApi_BootSwAddr_Get();
IWDG_Init();
app_can_init();
printf("<EFBFBD><EFBFBD><EFBFBD> %s\r\n",ApplicationVersion);
RTC_Init();
CHIP_RESET();
Filter_INIT();
CDZ_SYS.work_pattern = 1;//debugģʽ 1<><31> 0<><30>
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();//<2F><><EFBFBD>ֻؼ<D6BB><D8BC>ź<EFBFBD><C5BA>˲<EFBFBD>
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();//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
DCU_Internal_Failure();//<2F>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
}
else if(TimeTaskData.F_Time_50MS == SET)
{
TimeTaskData.F_Time_50MS = RESET;
SEND_Fault_Level();//<2F><><EFBFBD>ϵȼ<CFB5>
GUN_TEMP_Filter();//ǹ<><C7B9><EFBFBD><EFBFBD><C2B6>˲<EFBFBD>
Calculate_Charging_Current();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LED_Ctrl();
}
else if(TimeTaskData.F_Time_100MS == SET)
{
TimeTaskData.F_Time_100MS = RESET;
AC_DC_Adhesion_Detection();
eventDosomething();//<2F>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
}
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))//<2F>͹<EFBFBD><CDB9>ĸ<EFBFBD>λ<EFBFBD><CEBB>־
{
printf("<EFBFBD>͹<EFBFBD><EFBFBD>ĸ<EFBFBD>λ\r\n");
}
else if(0 != (RCC->CSR & 0x40000000))//<2F><><EFBFBD>ڿ<EFBFBD><DABF>Ź<EFBFBD><C5B9><EFBFBD>λ<EFBFBD><CEBB>־
{
printf("<EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD>λ\r\n");
}
else if(0 != (RCC->CSR & 0x20000000))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>λ<EFBFBD><CEBB>־
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD>λ\r\n");
}
else if(0 != (RCC->CSR & 0x10000000))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>־
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ\r\n");
}
else if(0 != (RCC->CSR & 0x08000000))//<2F>ϵ<EFBFBD>/<2F><><EFBFBD>縴λ<E7B8B4><CEBB>־
{
printf("<EFBFBD>ϵ<EFBFBD>/<2F><><EFBFBD>縴λ\r\n");
}
else if(0 != (RCC->CSR & 0x04000000))//<2F><><EFBFBD>Ÿ<EFBFBD>λ<EFBFBD><CEBB>־
{
printf("<EFBFBD><EFBFBD><EFBFBD>Ÿ<EFBFBD>λ\r\n");
}
else if(0 != (RCC->CSR & 0x02000000))//BOR <20><>λ<EFBFBD><CEBB>־
{
printf("BOR<EFBFBD><EFBFBD>λ\r\n");
}
RCC->CSR |= 0x01000000;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>־
}
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);
}
}