/****************************************************************************
* 文件名: VariableInit.c
* 内容简述: 变量初始化	
* 
* 文件历史:
* 版本号  日期       作者    说明
*
*/
#include "hc32f4xx.h"
#include "variable.h"
#include "hc32_ll.h"
#include "def.h"
//__IO u32 RegularConvData_Tab1[CH1_MAX];//DMA 缓冲数组 
//__IO u32 RegularConvData_Tab2[CH2_MAX];//DMA 缓冲数组 

u32 PCLK0_read=0,PCLK1_read=0,PCLK2_read=0,PCLK3_read=0,PCLK4=0,EXCLK_read=0,HCLK_read=0;
u32 vcoIn_read=0,vcoOut_read=0;
u16 u16AdcValue=0;

union ui_x sum,Uc,t_state[8],VOT_state;
u8 rsv_buf[22];
unsigned short int set_buf[12];

union ui_x rxd_set[12] = {
{MAX_I_LIMIT},  /*限流值*/
{0x0101},           /*开关机命令*/				    
{DEFAULT_VOS},  	//浮充电压默认值53.60V
{DEFAULT_VOS},   	//均充电压默认值55.20V
{0},   //输出过压保护值58.00V
{0},   //43.00V
{0},   //输入过压保护值286.00 V
{0},   //输入欠压保护值100.00 V
{0},   //50.00 A
{0},   //107.0 
{DEFAULT_VOS},   //
{0x0F0F},
};

u16 Vout_Loop_sample=0,IotU16=0,VotU16=0,Moudle_Temp=0,Vin_sample=0;
signed  int I_err=0;
u16 I_err_abs=0;
int32_t IotErrI32=0,IotKiI32=0,IotKpiI32=0,IotKpI32=0;
int32_t Temp_KIerr=0;
u16  PULSE_VALU_I=0;
u16 I_limit =I_LIMIT_DEF;
u16 I_limit_turnback=I_LIMIT_DEF;
u32 f_ctrl_cnt=0;
u16  f_ctrl_cnt_COMP=0;
u16  iot_sample=0;
signed  short int V_err=0;
u32 CtrlU16=0;
u16 IotU16_flt=0;
u32 IotU16_flt_sum=0;


signed  int Vot_Eerr=0;
u16 V_err_abs=0;
int32_t VotKpI32=0,VotKpi32=0,VoT_KIerr=0,Vot_KiI32=0,VoT_MIerr=0;
int32_t VotU32_flt_sum=0,VotU32_KP_sum;
int32_t VotU32_flt=0;

u16 V_limit =V_LIMIT_DEF;

u16  PULSE_VALU_V=0;
u32  PULSE_VALU_cnt=0;

u16 local_addr=0;
u16 cnt_485_stop=0;
signed int vot_gain=1,iot_gain=1,vos_gain=1,iot_offset=0,vot_offset=0,vos_offset=0;//

u16 cnt_10_s=0;
u32 cur_vos=0,vos=DEFAULT_VOS,vos16=0,vos_out=0;  
u16 time_cnt=0;
u16  V_set_default=0,C_set_default=0;

u32  AV_IOT_DOWM=0,SUM_IOT_DOWN=0;
signed short int BC_IOT=0;
u8   PRT_single_modle_cnt=0;
signed short int prc_comp=0;
int16_t prt_err=0;
u16 prc_delay_cnt=0,every_prc_cnt=0;
u8  Prt_start_flag=1,Prt_stop_flag=0,Prt_derection=0,Ref_flag=0;
u32 sum_prt=0,sum_iot_prt=0;
u16  IOT_AV=0,IOT_PRT_AV=0;

u8   Prt_num=0,Prt_num_dc=0;
u16  Prt_sample_can=0;
u8   Prt_flag=0;
u8 ModNumLocal=0;//本机模块地址
u8  Right_I=0,Right_V=0;
signed short int  I_offset=0,V_offset=0;


u32  AV_IOT_LINE=0,SUM_IOT_LINE=0;
signed short int BC_IOT_LINE=0;
u8  Line_Loss_K=0;
u8  Comm_para_cfg=2;

u16  ctrl_step=1000,ctrl_step_cnt=0;
u8   sr_open_flag=0;
u8  sr_cnt=0;

u32 sum_prc_iot=0;
u16 prc_iot=0;


u16 VOT_AV=0;
u16 cnt_2_5s=0;

u16 av_prt=0,prt=0,av_vot=0;
u16  VOT_FLT=0;
u32  SUM_VOT_FLT=0;
u32 sum_vot=0;
u16 Vin_flt=0;
u32 sum_vin=0;
u8  VREF_FALG=0;
u16 state_buf[7];
u8 flag=0,I_limit_flag=1;


u16  Vout_over_alarm_cnt=Time_36ms;
u16 uo_over_cnt=0;
u16 uo_no_over_cnt=OV_FILTER_MAX_CNT;
u8  Vout_no_over_flag=1;
u16 vout_alarm_cnt=10;
u16  P_TEMP=0, I_limit_min=0,I_limt_TEMP=I_LIMIT_26_25A,I_limit_REF=I_LIMIT_26_25A,I_limit_max=0;
u32  P_TEMP_DELAY=Time_30s,P_TEMP_DELAY_CNT=0; 
u32  power_down_cnt=0,power_down_T=Time_3s,power_recover_cnt=0,power_up_T=Time_3s;
u8  P_TEMP_DOWN_FLAG=0,P_TEMP_FLAG=0;

u16 limit_alarm_cnt=10;

u8 apwr_ui_addr_state=0;

u8 DC_SHORT_FLAG=0;
u32 DC_short_cnt=0,DC_short_T=Time_48s ,DC_short_TON=Time_8s ,DC_short_TOFF=Time_40s;
u8   OVER_T_FLAG=0;
u32  OTP_TIME=Time_1s,OTP_CNT=0;//5min
u16  OT_TEMP=0,Temp_Dis_comm=0;
signed  int Temp_Dis=0;
u16 tmp_over_cnt=10;
u16  TEMP_SHUT=TEMP_110_Degree,TEMP_BOOT=TEMP_95_Degree;
u8  SMALL_FAULT_cnt=0,SLEEP_INS_cnt=0,UI_FAULT_cnt=0;
u32 cnt_on_relay=0;
u8   pwm_open_flag=0;
u8 ins=FAULT_SHUT_RL1_INS;
u16 fault_cnt=FAULT_SET_CNT,ok_cnt=OK_SET_CNT,STATE_485_UP_cnt=Time_4s;


u16 Add_cnt=0;
u8 Det_V_Addr_Flg=0;
u16 A0_line=0;
u16 Vin_over_delay_cnt=0,Vin_down_delay_cnt=0;

u16 V_set_comm=0,I_set_comm=0;



u16 SR_LEADING=0,SR_LAGGING=0;

u16  Fre_V_limit=0;
u16  SR_table_cnt=0;
u8   IOT_x_cnt=0,Vin_y_cnt=0;

u8   sr_on_cmp=0;

u8   OC_pwm_off_flag=0;
u16  OC_pwm_off_cnt=0;
u16 V_limit_ref=0;

u8  Vin_Vo_T_vin_cnt=0,Vin_Vo_T_vo_cnt=0;
u16 Vin_sample_T=0,Vin_sample_f=0;

u16  T_SET=0; //VIN和VOUT查出来的频率
u16  T_FB=0;  //FB查出来的频率

u8  Vin_Vo_f_vin_cnt=0, Vin_Vo_f_vo_cnt=0;
u8 Short_Flag=0;
u8 VOT_DUTY=0;
int16_t VOT_B=0,FB_M=0;
u8 CV_flag=0;
u8 VO_OK=0;
u8 SR_flag=0;
int16_t VOT_s=0,SR_D=0,VOT_F=0;
u16 VOT_Save_last[4];

int32_t SUM_ERR=0;
u16  add0=0;
u32  sum_add0=0;
u16  add0_flt=0;
u8 can_peripheral_init_delay=0;

u16  Trim_sample=0,Trim_sample_flt=0;
u32  Sum_Trim_sample=0;

u16 prt_err_abs=0;
u32 Vout_vref=0;
signed short int BC_IOT_abs=0,prc_comp_abs=0;
u32 vos_prt=0;
u8  start_ok_flag=0;
u16 ADCData_Record[1000] = {0},pADCData = 0;
u16 pADCData_read = 0;
signed  int vos_I_limit=0,I_err_alarm=0,sum_I_limit=0,limit_I_err=0,last_sum_I_limit=0;
signed  int  I_err_fast=0;
u16 ABS_I_err=0;
u8 power_limit_cnt=0;
u16 VOT_power_limit=0;
u32  Prt_off_delay_cnt=0;
u8 prt_off_falg=0;
u32  Prt_on_delay_cnt=0;
u16  delay_cnt=0;
u16  VOT_B_ABS=0;
u16  VOT_B_ABS_second=0;
u16  ceshi_adc_data_abs=0,ceshi_sample=0;
signed  int  ceshi_adc_data_err=0;

int32_t Temp_KDerr=0,VotKd32=0;
signed  short int  V_err_last=0;
signed  short int  V_err_last_two=0;
int32_t Temp_KDerr_two=0;

int32_t IotU32_flt_sum=0;
int32_t IotU32_flt=0; 
u8 LVD_delay_flag=0;
u16  LVD_delay_cnt=0;
u8 Short_restart_cnt=0;
u16 T_FB_ref=830;

u8   Vb_OV_low_flag=0,Vb_OV_high_flag=0;
u8  Vbus_falling_flag=0,Vbus_rising_flag=0;
u32 Temp_KIerr_delt=0;
u32 VotFltI32_delt=0;
u16 Vin_k=0;
u16 SR_D_ABS=0;

u16  TEMP_SHUT_REF=TEMP_95_Degree,TEMP_BOOT_REF=TEMP_90_Degree;
u16  IotU16_flt_temp=0;
u16  TEMP_SHUT_value=TEMP_95_Degree,TEMP_BOOT_value=TEMP_90_Degree;

u16 TEMP_CTROL_FRE_CNT=0;
u8 Addr_over_Flg=0;
u8  Comm_Vref_flag=0;
u8  jiao_zhun_flag=0;
u8 burst_flag=0;
u8 llc_burst_flag=0;
u16 PrdU16=0;
u8 LLC_SHUT_flag=0,SR_SHUT_flag=0;
u32 u32TxBuf[EXAMPLE_SPI_BUF_LEN] = {0x22556677};
u32 u32RxBuf[EXAMPLE_SPI_BUF_LEN];

spi_comm_data__all  spi_comm_data;
u16 PrdU16_half=0,PrdU16_quarter=0,PrdU16_quarter3=0;
u16 PrdU16_half_dead=0,PrdU16_dead=0,PrdU16_quarter_dead=0;

u32 PrdU16_half_ctrolbit=0,PrdU16_dead_ctrolbit=0;
u32 SR_PWM_value_32=0;
u16 SR_PWM_value_16=0;

u32 PrdU16_resonant_dead_ctrolbit=0;
u16 PrdU16_resonant_half_dead=0;

u8 f_vot_cnt=0;
u16 Fre_V_Limit=0; 

u8  ip_over_flag=0,iot_over_flag=0,vout_over_flag=0;

u16  phase1_dead_var=0,phase2_dead_var=0;

u16  phase1_dead_time=0, phase2_dead_time=0;
u32  ADDR_CESHI=0;

