#ifndef _DC300_H_ #define _DC300_H_ #include "stm32f10x.h" #define BIT(x) (1LL << (x)) #define mExistCode(code,codeID) (code & BIT(codeID)) #define mExistFault(faultID) mExistCode(((uint16_t*)&ModuleInfo.faultcode)[faultID >> 4],faultID & 0x0F) #define mSetBit(code, codeID) code |= (BIT(codeID)) #define mSetFaultCode(faultID) ((uint16_t*)&ModuleInfo.faultcode)[faultID >> 4] |= BIT(faultID & 0x0F) #define mClrBit(code,codeID) code &= ~(BIT(codeID)) #define mClrFaultCode(faultID) ((uint16_t*)&ModuleInfo.faultcode)[faultID >> 4] &= ~BIT(faultID & 0x0F) #pragma pack (1) /*指定按1字节对齐*/ typedef enum { Bus_OverVolt_Fault_INS, Bus_OverVolt_Fault, Bat_OverVolt_Fault_INS, Bat_OverVolt_Fault, Buck_OverCurr_Fault_INS, Buck_OverCurr_Fault, Buck_OCP, Over_Temp_Fault, Bus_UnderVolt_Fault, Bat_UnderVolt_Faul, }faultGroup0E_t; typedef union { uint8_t data[2]; struct { // -------------------------Byte0------------------------- uint16_t Bus_OverVolt_Fault_INS :1; // BUS瞬时电压过压 uint16_t Bus_OverVolt_Fault :1; // BUS有效电压过压 uint16_t Bat_OverVolt_Fault_INS :1; // Bat瞬时电压过压 uint16_t Bat_OverVolt_Fault :1; // Bat瞬有效电压过压 uint16_t Buck_OverCurr_Fault_INS :1; // Buck瞬时电流过流 uint16_t Buck_OverCurr_Fault :1; // Buck有效电流过流 uint16_t Buck_OCP :1; // Buck电流硬件过流 uint16_t Over_Temp_Fault :1; // 过温故障 uint16_t Bus_UnderVolt_Fault :1; // BUS电压低压 uint16_t Bat_UnderVolt_Faul :1; // Bat电压低压 uint16_t Reserved :6; // 预留 }bits; }dcfault_sts_t; typedef struct { uint8_t switch_Onoff; uint16_t over_volt; uint16_t under_volt; uint16_t over_curr; uint16_t max_power; uint16_t target_volt; uint16_t target_curr; uint16_t cdz_input_volt; uint16_t cdz_input_curr; uint8_t contactor_swirch; int16_t currentadjust; //0.1A -12.8--+12.8A uint16_t bmsRequire_volt; uint16_t bmsRequire_curr; uint8_t bmsRequire_volt_mode; //1就是老化模式 输出可以大于200V 其他就是正常模式 uint16_t communicationflag; //模块当前状态 uint8_t state; uint16_t current_volt; uint16_t current_curr; uint16_t input_volt; uint16_t input_curr; uint16_t sample_bat_volt; uint16_t faultcode; //故障代码 int8_t Modul_Temp; int8_t Inductance_Temp; int8_t temp3; int8_t temp4; uint8_t version[16]; }dcmodule_info_t; typedef struct { uint8_t head; uint8_t type; uint8_t cmd; uint8_t len; uint8_t data[64]; uint16_t crc; }dcsendframe_t; #pragma pack() /*取消指定对齐,恢复缺省对齐*/ #define POWER_ON 1 #define POWER_OFF 2 #define DC_CHARGE_IDLE 0x01 //空闲 #define DC_CHARGE_START 0x02 //开始 #define DC_CHARGE_ING 0x04 //充电中 #define DC_CHARGE_END 0x05 //停止 #define DC_CHARGE_FAST 0x06 //?? #define DC_CHARGE_SLOW 0x07 //?? #define DC_CHARGE_SLOW2 0x08 //??2 #define DC_CHARGE_SLOW3 0x09 //??3 #define DC_CHARGE_SLOW3END 0x0A //??3 extern uint8_t g_DC_ChargeStep; void ReadDCVersion(void); void ControlDCFrame(void); void SettingParamDCFrame(void); void DCDC_Power_Handle(void); void dc300FrameParser(void); void TakeDCPowerOn(void); void TakeDCPowerOff(void); uint8_t GetDCPowerFaultCode(void); uint8_t GetDCPowerPowerState(void); void ClearDCPowerPowerComState(void); uint8_t UpdataDCPowerReqCur(uint16_t current); dcmodule_info_t * GetDCPowerInfo(void); extern dcmodule_info_t ModuleInfo; #define DCDC_MAX_CHARGE_VOLTAGE 1500 // 200v 0.1V #define DCDC_TOTAL_CAPACITY 1000 #define DCDC_CURRENT_VOLTAGE 3000 #define DCDC_MAX_CHARGE_CUR 1000 //100A #define DCDC_MAX_POWER 120 //10K #define DCDC_MAX_REQ_VOLTAGE 1300 // 200v 0.1V #define DCDC_MAX_REQ_CUR 600 //60A 默认请求电流60A #define DCDC_MAX_InductanceTemp 120 // 度 #define DCDC_MAX_DC_IGBTTemp 95//度 #define DCDC_MAX_CapacitanceTemp 80 // 度 #define DCDC_MAX_DCBoxTemp2 80//度 extern uint8_t DCPowerPowerComState(void); extern uint8_t IsDCDCPowerOn(void); typedef struct { uint8_t index; uint8_t * data; }fault_info_t; extern fault_info_t fault_info_Table[]; //降载逻辑 typedef struct { uint16_t MaxCurrent ;//降载的最大电流 uint16_t index ;//降载的最大电流 uint8_t OverLoadFlag; }dcdownload_t; #endif