CELIS/SYSTEM/dc300.h

170 lines
4.5 KiB
C
Raw Permalink Normal View History

#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) /*ָ<><D6B8><EFBFBD><EFBFBD>1<EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>*/
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˲ʱ<CBB2><CAB1>ѹ<EFBFBD><D1B9>ѹ
uint16_t Bus_OverVolt_Fault :1; // BUS<55><53>Ч<EFBFBD><D0A7>ѹ<EFBFBD><D1B9>ѹ
uint16_t Bat_OverVolt_Fault_INS :1; // Bat˲ʱ<CBB2><CAB1>ѹ<EFBFBD><D1B9>ѹ
uint16_t Bat_OverVolt_Fault :1; // Bat˲<74><CBB2>Ч<EFBFBD><D0A7>ѹ<EFBFBD><D1B9>ѹ
uint16_t Buck_OverCurr_Fault_INS :1; // Buck˲ʱ<CBB2><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t Buck_OverCurr_Fault :1; // Buck<63><6B>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t Buck_OCP :1; // Buck<63><6B><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t Over_Temp_Fault :1; // <09><><EFBFBD>¹<EFBFBD><C2B9><EFBFBD>
uint16_t Bus_UnderVolt_Fault :1; // BUS<55><53>ѹ<EFBFBD><D1B9>ѹ
uint16_t Bat_UnderVolt_Faul :1; // Bat<61><74>ѹ<EFBFBD><D1B9>ѹ
uint16_t Reserved :6; // Ԥ<><D4A4>
}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<><31><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ģʽ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>200V <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
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; //<2F><><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD>
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() /*ȡ<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ȱʡ<C8B1><CAA1><EFBFBD><EFBFBD>*/
#define POWER_ON 1
#define POWER_OFF 2
#define DC_CHARGE_IDLE 0x01 //<2F><><EFBFBD><EFBFBD>
#define DC_CHARGE_START 0x02 //<2F><>ʼ
#define DC_CHARGE_ING 0x04 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#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 Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>60A
#define DCDC_MAX_InductanceTemp 120 // <20><>
#define DCDC_MAX_DC_IGBTTemp 95//<2F><>
#define DCDC_MAX_CapacitanceTemp 80 // <20><>
#define DCDC_MAX_DCBoxTemp2 80//<2F><>
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[];
//<2F><><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD>
typedef struct
{
uint16_t MaxCurrent ;//<2F><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t index ;//<2F><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t OverLoadFlag;
}dcdownload_t;
#endif