/***************************************************************************** * * File : device.h * Compiler : IAR C 6.30 * Revision : $Revision: 1.0 $ * Date : $Date: 2015 / 03 / 13 * Updated by : $Author: Jongkwang Woo * * Support mail : spirit0305@naver.com * * Description : Header file for device.c * ****************************************************************************/ #ifndef _DEVICE_PARAM_H_ #define _DEVICE_PARAM_H_ #include #define DEVICE_NAME "LFPS-48100S" #define DEVICE_TYPE 48100 #define DEVICE_REV "1.0" #define DEVICE_MAX_CELL 15 #define DEVICE_MAX_TEMP 6 #define BIT(x) (unsigned short)(0x0001 << x) typedef union { u16 value; struct { u16 DSG_S : 1; // LSB 0 // Dischage Fet Control u16 CHG_S : 1; // LSB 1 // Charge Fet Control u16 ZVC_S : 1; // LSB 2 // Pre-charge Fet Control u16 RXM : 1; // LSB 3 u16 FD : 1; // LSB 4 u16 FC : 1; // LSB 5 u16 MD : 1; // LSB 6 u16 INIT : 1; // LSB 7 u16 DSG_C : 1; // MSB 8 // Dischage Fet Status u16 CHG_C : 1; // MSB 9 // Charge Fet Status u16 ZVC_C : 1; // MSB 10 // Pre-charge Fet Status u16 CB : 1; // MSB 11 // Cell Balancing Flag u16 AFE : 1; // MSB 12 // AFE PL455 Comm Status u16 TDA : 1; // MSB 13 u16 TCA : 1; // MSB 14 u16 ACB : 1; // MSB 15 } bit; } TBATTERY_STATUS, *pBATTERY_STATUS; typedef union { u16 value; struct { u16 afe_fail : 1; // LSB 0 // Dischage Fet Control u16 temp_sensor : 1; // LSB 1 // Charge Fet Control u16 ZVC_S : 1; // LSB 2 // Pre-charge Fet Control u16 RXM : 1; // LSB 3 u16 FD : 1; // LSB 4 u16 FC : 1; // LSB 5 u16 MD : 1; // LSB 6 u16 INIT : 1; // LSB 7 u16 DSG_C : 1; // MSB 8 // Dischage Fet Status u16 CHG_C : 1; // MSB 9 // Charge Fet Status u16 ZVC_C : 1; // MSB 10 // Pre-charge Fet Status u16 CB : 1; // MSB 11 // Cell Balancing Flag u16 AFE : 1; // MSB 12 // AFE PL455 Comm Status u16 TDA : 1; // MSB 13 u16 TCA : 1; // MSB 14 u16 ACB : 1; // MSB 15 } bit; } TBATTERY_ERROR, *pBATTERY_ERROR; typedef struct { u16 voltage[DEVICE_MAX_CELL + 1]; // 2bytes * (15 + 1) = 32bytes struct { struct { u16 value; // 2bytes u16 num; // 2bytes } Max, Min; // 4bytes + 4bytes = 8bytes u16 avg; // 2bytes u16 diff; // 2bytes } avg; // 12bytes } TCELL_STATUS, *PCELL_STATUS; // 44bytes typedef struct { s16 temperature[DEVICE_MAX_TEMP]; struct { struct { s16 value; u16 num; } Max, Min; s16 avg; s16 diff; } avg; } TTEMP_STATUS, *PTEMP_STATUS; typedef struct { struct { u16 value; u16 num; } Max, Min; u16 avg; u16 diff; } TAVG_VALUE, *PAVG_VALUE; typedef struct { s16 value; u16 num; } TMinMax, *PMinMax; typedef struct { u32 Heartbeat; // Offset 0 u32 ManufactureDate; // Offset 4 u32 FwVersion; // Offset 8 u32 RemainingCapacity; // Offset 20 u32 CycleCount; // Offset 24 u16 BatVoltage; // Offset 26 s16 Current; // Offset 28 s16 DCurrent; // Offset 30 s16 CCurrent; // Offset 32 u16 RelativeStateOfCharge; // Offset 34 u16 StateOfHealth; // Offset 36 u16 Reserved; // Offset 38 TCELL_STATUS Cell; TTEMP_STATUS Temp; } TDEVICE_VALUE, *PDEVICE_VALUE; typedef union { u16 value; struct { u16 over_voltage : 1; // 0x0001 u16 cell_over_voltage : 1; // 0x0002 u16 under_voltage : 1; // 0x0004 u16 cell_under_voltage : 1; // 0x0008 u16 chg_over_current : 1; // 0x0010 u16 dsg_over_current : 1; // 0x0020 u16 reserved1 : 2; // u16 chg_high_temp : 1; // 0x0100 u16 dsg_high_temp : 1; // 0x0200 u16 chg_low_temp : 1; // 0x0400 u16 dsg_low_temp : 1; // 0x0800 u16 low_capacity : 1; // 0x1000 u16 reserved2 : 1; // u16 cell_voltage_diff : 1; // u16 reserved3 : 1; // } bit; } TWarning; typedef union { u16 value; struct { u16 over_voltage : 1; // 0x0001 u16 cell_over_voltage : 1; // 0x0002 u16 under_voltage : 1; // 0x0004 u16 cell_under_voltage : 1; // 0x0008 u16 chg_over_current : 1; // 0x0010 u16 dsg_over_current : 1; // 0x0020 u16 reserved1 : 1; // 0x4000 u16 critial_over_current: 1; // 0x8000 u16 chg_high_temp : 1; // 0x0100 u16 dsg_high_temp : 1; // 0x0200 u16 chg_low_temp : 1; // 0x0400 u16 dsg_low_temp : 1; // 0x0800 u16 temp_diff : 1; // 0x1000 u16 short_circuit : 1; // 0x2000 u16 cell_voltage_diff : 1; // 0x4000 u16 afe_fail : 1; // 0x8000 } bit; } TProtection; typedef union { u16 value; struct { u16 cell_00 : 1; u16 cell_01 : 1; u16 cell_02 : 1; u16 cell_03 : 1; u16 cell_04 : 1; u16 cell_05 : 1; u16 cell_06 : 1; u16 cell_07 : 1; u16 cell_08 : 1; u16 cell_09 : 1; u16 cell_10 : 1; u16 cell_11 : 1; u16 cell_12 : 1; u16 cell_13 : 1; u16 cell_14 : 1; u16 cell_flag : 1; } bit; } TCellBalanceData, *PCellBalanceData; typedef union { u16 uValue; struct { u16 cell0 : 1; u16 cell1 : 1; u16 cell2 : 1; u16 cell3 : 1; u16 cell4 : 1; u16 cell5 : 1; u16 cell6 : 1; u16 cell7 : 1; u16 cell8 : 1; u16 cell9 : 1; u16 cell10 : 1; u16 cell11 : 1; u16 cell12 : 1; u16 cell13 : 1; u16 cell14 : 1; u16 reserved : 1; } Bit; } TCELL_BIT, *PCELL_BIT; typedef union { u16 uValue; struct { u16 temp0 : 1; u16 temp1 : 1; u16 temp2 : 1; u16 temp3 : 1; u16 temp4 : 1; u16 temp5 : 1; u16 temp6 : 1; u16 temp7 : 1; u16 reserved : 8; } Bit; } TTEMP_BIT, *PTEMP_BIT; typedef struct { TBATTERY_STATUS battery_status; // 2 16 bit u16 op_status; // 4 16 bit u16 alarm_status; // 6 16 bit TWarning warning; // 8 16 bit TProtection protection; // 10 16 bit TCellBalanceData cellbalance; // 12 16 bit u16 auto_balancing; // 14 16 bit TBATTERY_ERROR error; // 16 16 bit TCELL_BIT cov_warning_cell; // 18 16 bit TCELL_BIT cov_protection_cell; // 20 16 bit TCELL_BIT cuv_warning_cell; // 22 16 bit TCELL_BIT cuv_protection_cell; // 24 16 bit TTEMP_BIT otd_warning_temp; // 26 16 bit TTEMP_BIT otd_protection_temp; // 28 16 bit TTEMP_BIT otc_warning_temp; // 30 16 bit TTEMP_BIT otc_protection_temp; // 32 16 bit TTEMP_BIT ltd_warning_temp; // 34 16 bit TTEMP_BIT ltd_protection_temp; // 36 16 bit TTEMP_BIT ltc_warning_temp; // 38 16 bit TTEMP_BIT ltc_protection_temp; // 40 16 bit } TDEVICE_STATUS, *PDEVICE_STATUS; typedef struct _TDEVICE_DEVICE_INFO { u8 ManufacturerNameSize; u8 ManufacturerName[11]; u8 DeviceNameSize; u8 DeviceName[7]; u8 DeviceChemistrySize; u8 DeviceChemistry[4]; u8 CellQuantity; } TDEVICE_DEVICE_INFO, *PDEVICE_DEVICE_INFO; #pragma pack(2) typedef struct { u16 COV_Threshold; // ST COV Threshold (Offset 0) u16 COV_Warning; // ST COV Warning (Offset 2) u16 COV_Recovery; // ST COV Recovery (Offset 4) u16 CUV_Threshold; // CUV Threshold (Offset 6) u16 CUV_Warning; // CUV Warning (Offset 8) u16 CUV_Recovery; // CUV Recovery (Offset 10) u16 SOV_Threshold; // ST COV Threshold (Offset 0) u16 SOV_Warning; // ST COV Warning (Offset 2) u16 SOV_Recovery; // ST COV Recovery (Offset 4) u16 SUV_Threshold; // CUV Threshold (Offset 6) u16 SUV_Warning; // CUV Warning (Offset 8) u16 SUV_Recovery; // CUV Recovery (Offset 10) } TDEVICE_PARAM_VOLTAGE_VALUE, *PDEVICE_PARAM_VOLTAGE_VALUE; // C.2.2 Current (Subclass 671) typedef struct { s16 OC_Chg_Threshold; // OC Chg Threshold (Offset 0) A s16 OC_Chg_Warning; // OC Chg Warning (Offset 2) A s16 OC_Chg_Recovery; // OC Chg Recovery (Offset 4) A s16 OC_Chg_Rec_Time; // OC Chg Recovery Time (Offset 6) Sec s16 OC_Dsg_Threshold; // OC Dsg Threshole (Offset 8) A s16 OC_Dsg_Warning; // OC Dsg Warning (Offset 10) A s16 OC_Dsg_Recovery; // OC Dsg Recovery (Offset 12) A s16 OC_Dsg_Rec_Time; // OC Dsg Recovery Time (Offset 14) Sec } TDEVICE_PARAM_CURRENT_VALUE, *PDEVICE_PARAM_CURRENT_VALUE; // C.2.3 Temperature (Subclass 690) typedef struct { s16 OT_Chg_Threshold; // (Offset 0) 0.1C s16 OT_Chg_Warning; // (Offset 2) 0.1C s16 OT_Chg_Recovery; // (Offset 6) 0.1C s16 OT_Dsg_Threshold; // (Offset 8) 0.1C s16 OT_Dsg_Warning; // (Offset 10) 0.1C s16 OT_Dsg_Recovery; // (Offset 14) 0.1C s16 LT_Chg_Threshold; // (Offset 16) 0.1C s16 LT_Chg_Warning; // (Offset 18) 0.1C s16 LT_Chg_Recovery; // (Offset 22) 0.1C s16 LT_Dsg_Threshold; // (Offset 16) 0.1C s16 LT_Dsg_Warning; // (Offset 18) 0.1C s16 LT_Dsg_Recovery; // (Offset 22) 0.1C s16 Open_Thermistor; // Open Thermistor (Offset 24) s16 Recovery_Thermistor; // Recovery Thermistor (Offset 26) } TDEVICE_PARAM_TEMPERATURE_VALUE, *PDEVICE_PARAM_TEMPERATURE_VALUE; typedef struct { s16 Low_Soc_Warning; // (Offset 0) 0.1C s16 Low_Soc_Recovery; // (Offset 6) 0.1C } TDEVICE_PARAM_SOC_VALUE, *PDEVICE_PARAM_SOC_VALUE; typedef struct { u16 Cell_Voltage_Diff_Threshold; // (Offset 0) mV u16 Cell_Voltage_Diff_Warning; // (Offset 2) mV u16 Cell_Voltage_Diff_Recovery; // (Offset 4) mV u16 Cell_Voltage_Diff_Time; // (Offset 6) Sec } TDEVICE_PARAM_CELL_VOLTAGE_DIFF_VALUE, *PDEVICE_PARAM_CELL_VOLTAGE_DIFF_VALUE; typedef struct { TDEVICE_PARAM_VOLTAGE_VALUE voltage; TDEVICE_PARAM_CURRENT_VALUE current; TDEVICE_PARAM_TEMPERATURE_VALUE temperature; TDEVICE_PARAM_SOC_VALUE soc; TDEVICE_PARAM_CELL_VOLTAGE_DIFF_VALUE cv_diff; } TDEVICE_PARAM_SAFETY_VALUE, *PDEVICE_PARAM_SAFETY_VALUE; // SBS Configuration typedef struct { u16 System_ID; // System ID (Offset 0) u16 Design_Voltage; // Design Voltage (Offset 2) u16 Spec_Info; // Spec Info (Offset 4) u16 Manuf_Date; // Manuf Date (Offset 6) u16 Ser_Num; // Ser. Num. (Offset 8) u16 Cycle_Count; // Cycle Count (Offset 10) u16 CC_Threshold; // CC Threshold (Offset 12) u16 Design_Capacity; // Design Capacity (Offset 16) u16 Design_Energy; // Design Energy (Offset 18) u16 Full_Charge_Capacity; // Full Charge Capacity(Offset 20) } TDEVICE_SBS_DATA_VALUE, *PDEVICE_SBS_DATA_VALUE; typedef struct { TDEVICE_SBS_DATA_VALUE data; } TDEVICE_SBS_VALUE, *PDEVICE_SBS_VALUE; // Charge Control Configuration typedef struct { s16 ST_Chg_Voltage; // (Offset 0) mV s16 ST_Chg_Current; // (Offset 2) A } TDEVICE_CHG_CTRL_CFG_CHG_CFG_VALUE, *PDEVICE_CHG_CTRL_CFG_CHG_CFG_VALUE; typedef struct { s16 Taper_Current; // (Offset 0) mA s16 Taper_Voltage; // (Offset 2) mV s16 Current_Taper_Window; // (Offset 4) S s16 FC_Set; // (Offset 6) % s16 FC_Clear; // (Offset 8) % s16 FD_Set; // (Offset 10) % s16 FD_Clear; // (Offset 12) % s16 Reserved; // (Offset 12) % } TDEVICE_CHG_CTRL_CFG_TERM_CFG_VALUE, *PDEVICE_CHG_CTRL_CFG_TERM_CFG_VALUE; typedef struct { s16 Cell_Balance_Threshold; // (Offset 0) mV s16 Cell_Balance_Window; // (Offset 2) mV s16 Cell_Balance_Min; // (Offset 4) mV s16 Cell_Balance_Interval; // (offset 6) S } TDEVICE_CHG_CTRL_CFG_CELL_BAL_CFG_VALUE, *PDEVICE_CHG_CTRL_CFG_CELL_BAL_CFG_VALUE; typedef struct { s16 Discharge_Detection_Threshold; // Discharge Detection Threshold (Offset 0) s16 Charge_Detection_Threshold; // Charge Detection Threshold (Offset 2) s16 Quit_Current; // Quit Current (Offset 4) u8 Discharge_Relax_Time; // Discharge Relax Time (Offset 6) u8 Charge_Relax_Time; // Charge Relax Time (Offset 8) } TDEVICE_CHG_CTRL_CURRENT_THR_VALUE, *PDEVICE_CHG_CTRL_CURRENT_THR_VALUE; typedef struct _TDEVICE_CHG_CTRL_VALUE { TDEVICE_CHG_CTRL_CFG_CHG_CFG_VALUE chg_cfg; TDEVICE_CHG_CTRL_CFG_TERM_CFG_VALUE term_cfg; TDEVICE_CHG_CTRL_CFG_CELL_BAL_CFG_VALUE cell_bal_cfg; TDEVICE_CHG_CTRL_CURRENT_THR_VALUE current_thr; } TDEVICE_CHG_CTRL_VALUE, *PDEVICE_CHG_CTRL_VALUE; // Calibration // Voltage (Subclass 0) typedef struct { s16 Cell_Scale_0; // Cell Scale 0 (Offset 0) s16 Cell_Scale_1; // Cell Scale 1 (Offset 2) s32 BAT_Gain; // Pack Offset (Offset 8) s32 BAT_Offset; // BAT Offset (Offset 10) } TDEVICE_CAL_VOLTAGE_VALUE, *PDEVICE_CAL_VOLTAGE_VALUE; // Current (Subclass 12) typedef struct { s32 CC1_Gain; // CC Gain (Offset 0) s32 CC1_Offset; // CC Delta (Offset 4) s32 CC2_Gain; // CC Gain (Offset 0) s32 CC2_Offset; // CC Delta (Offset 4) s32 DC_Gain; // DC Gain (Offset 8) s32 DC_Offset; // DC Delta (Offset 12) } TDEVICE_CAL_CURRENT_VALUE, *PDEVICE_CAL_CURRENT_VALUE; // Current Offset (Subclass 20) typedef struct { s16 Int_Power; // Internal Power Consumption (Offset 0) s16 Relay_Power; // Relay Power Consumption (Offset 2) } TDEVICE_CAL_CURRENT_OFFSET_VALUE, *PDEVICE_CAL_CURRENT_OFFSET_VALUE; typedef struct { s16 Charge_Offset; // Charge Offset (Offset 0) s16 Discharge_Offset; // Discharge Offset (Offset 2) } TDEVICE_CAL_CURRENT_DEADBAND_VALUE, *PDEVICE_CAL_CURRENT_DEADBAND_VALUE; typedef struct _TDEVICE_CAL_VALUE { TDEVICE_CAL_VOLTAGE_VALUE voltage; TDEVICE_CAL_CURRENT_VALUE current; TDEVICE_CAL_CURRENT_OFFSET_VALUE current_offset; TDEVICE_CAL_CURRENT_DEADBAND_VALUE current_deadband; } TDEVICE_CAL_VALUE, *PDEVICE_CAL_VALUE; typedef struct { uint32_t initdata; TDEVICE_DEVICE_INFO info; TDEVICE_PARAM_SAFETY_VALUE safety; TDEVICE_CHG_CTRL_VALUE chg_ctrl; TDEVICE_SBS_VALUE sbs; TDEVICE_CAL_VALUE cal; } TDEVICE_PARAM, *PDEVICE_PARAM; // Setting value typedef struct _TDEVICE_SET_VALUE { u8 Flag; u8 Busy; u16 SubClass; u16 Offset; u16 Size; u16 Value; } TDEVICE_SET_VALUE, *PDEVICE_SET_VALUE; extern TDEVICE_VALUE device_value, bakdevice_value, dis_device_value; extern TDEVICE_STATUS device_status, dis_device_status; extern TDEVICE_PARAM device_param, dis_device_param; int device_get_prop_status(I2C_TypeDef *client); int device_get_prop_charge_type(I2C_TypeDef *client); int device_get_property_info(void); void device_status_backup(void); void SetDefaultParameterDEVICE(void); void CfgUpdateData(void); void device_reg_set_check(void); int32_t device_reg_set(u16 subclass, u16 offset, u16 size, u16 value); void Load_Param(void); void Save_Param(void); void LoadFwInfo(void); uint32_t SaveFwInfo(void); void Param_Init(u8 flag, u8 factory); #define INV_INIT_DATA 0xAAAA4001 typedef struct _TDEVICE_INV { uint32_t initdata; uint32_t ManufactureDate; uint8_t SerialNo[16]; uint8_t ModuleNo[32]; } TDEVICE_INV, *PDEVICE_INV; extern TDEVICE_INV device_inv, dis_device_inv; void Save_InvData(void); void Load_InvData(void); void Inv_Init(void); #endif