1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078 |
- //##############################################################################
- //
- // FILE: BMS_Typedefs.h
- //
- // TITLE: Global Typedefs
- //
- //
- //##############################################################################
- //
- //==============================================================================
- // Change History:
- //==============================================================================
- // Datum: | Name | Version:| Change / Cause: | No
- //------------------------------------------------------------------------------
- // | | | | 002
- //------------------------------------------------------------------------------
- // | | | | 001
- //------------------------------------------------------------------------------
- // 05.07.13 | VR | 1.0 | New Build | 000
- //==============================================================================
- //==============================================================================
- // Comment Change / Cause:
- //==============================================================================
- // Change: 003 // 003
- //----------------------
- //
- //
- //==============================================================================
- // Change: 002 // 002
- //----------------------
- //
- //
- //==============================================================================
- // Change: 001 // 001
- //----------------------
- //
- //
- //==============================================================================
- #ifndef __BMS_TYPEDEFS_H__
- #define __BMS_TYPEDEFS_H__
- #include "BMS_Defines.h"
- // ***** Slave_Status_Flags ****************************************************
- typedef union {
- uint16_t R;
- struct { //Big Endian
- //High Byte
- uint16_t rsvd_h:8;
-
- //Low Byte
- uint16_t LTC_PEC_NOK:1;
- uint16_t LTC_Timeout:1;
- uint16_t LTC2_THSD:1;
- uint16_t LTC1_THSD:1;
- uint16_t LTC2_Temp_above80:1;
- uint16_t LTC1_Temp_above80:1;
- uint16_t LTC2_Temp_belowM40:1;
- uint16_t LTC1_Temp_belowM40:1;
- } B;
- } Slave_Status_Flags_t;
-
- // ***** Slave_Self_Test_Flags *************************************************
- typedef union {
- uint16_t R;
- struct { //Big Endian
- //High Byte
- uint16_t rsvd:1;
- uint16_t LTC2_Mux_NOK:1;
- uint16_t LTC2_RefH_NOK:1;
- uint16_t LTC2_RefL_NOK:1;
- uint16_t LTC2_TST2_NOK:1;
- uint16_t LTC2_TST1_NOK:1;
- uint16_t LTC2_VST2_NOK:1;
- uint16_t LTC2_VST1_NOK:1;
-
- //Low Byte
- uint16_t LTC_PEC_NOK:1;
- uint16_t LTC1_Mux_NOK:1;
- uint16_t LTC1_RefH_NOK:1;
- uint16_t LTC1_RefL_NOK:1;
- uint16_t LTC1_TST2_NOK:1;
- uint16_t LTC1_TST1_NOK:1;
- uint16_t LTC1_VST2_NOK:1;
- uint16_t LTC1_VST1_NOK:1;
- } B;
- } Slave_Self_Test_Flags_t;
-
-
-
- // ***** Slave_Control *********************************************************
- typedef struct {
- uint16_t Balancing_dV[MAX_CELLS];
- uint32_t Balancing_OnOff_Flags[MAX_SLAVES];
- union {
- uint8_t R[MAX_SLAVES];
- struct {
- uint8_t rsvd:5;
- uint8_t Fan2_RightLeft:1;
- uint8_t Fan2_OnOff:1;
- uint8_t Fan1_OnOff:1;
- } B[MAX_SLAVES];
- } FanCtrl;
- uint8_t Relais_OnOff[MAX_SLAVES];
- } Slave_Control_t;
-
-
- // ****** Slave_Status *********************************************************
- typedef struct {
- Slave_Status_Flags_t StatusFlags;
- Slave_Self_Test_Flags_t SelfTest_Flags;
- uint8_t LTC_PEC_FailCount;
- int8_t HeatSink_Temp;
- } Slave_Status_t;
-
-
- // ***** BSD (Battery Management System Slave Data ) ***************************
- typedef struct {
- uint16_t BlockVoltage [MAX_COUNT_UI];
- int16_t BlockCurrent [MAX_COUNT_UI];
- int32_t BlockCurrentSum;
- uint8_t BlockCounter [MAX_COUNT_UI];
- uint16_t CellVoltage [MAX_COUNT_VOLTAGE] [MAX_CELLS];
- int8_t CellTemperature [MAX_COUNT_TEMPERATURE] [MAX_CELLS];
- Slave_Status_t Slave_Status [MAX_COUNT_STATUS] [MAX_SLAVES];
- Slave_Control_t Balancer;
- uint16_t r_UI;
- uint16_t w_UI;
- uint16_t r_Voltage;
- uint16_t w_Voltage;
- uint16_t r_Temperature;
- uint16_t w_Temperature;
- uint16_t r_Status;
- uint16_t w_Status;
- uint16_t r_Balancer;
- uint16_t w_Balancer;
- } BSD_t;
- // ***** BSE ( Battery Management System Slave Errors ) ************************
- typedef struct {
- int16_t ErrorCell [MAX_CELLS];
- int16_t ErrorSlave [MAX_SLAVES];
- int16_t ErrorBMS;
- uint32_t CountVoltage;
- uint32_t CountTemperature;
- uint32_t CountStatus;
- } BSE_t;
- // ***** Main Contactor Feedback ***********************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t free :6;
- uint8_t b_MainContactorError :1;
- uint8_t b_MainContactorSwitch :1;
-
-
- } B;
- } b_MC_Fb_BMU_t;
- // ***** BMU_DICO ( Battery Management Unit to DICO ) **************************
- typedef struct {
- uint8_t voltageBattMax; // Maximum Battery Voltage
- uint8_t voltageBattMin; // Minimum Battery Voltage
- uint8_t currentBatMaxCharge; // Maximum Charge Current
- uint8_t currentBatMaxDischarge; // Maximum Discharge Current
- uint8_t batterySOC; // State Of Charge
- uint8_t voltageBattFb; // Total Battery Voltage
- uint8_t currentBattFb; // Total Battery Current
- b_MC_Fb_BMU_t b_MC_Fb_BMU; // Main Contactor Feedback
- } BMU_DICO_t;
- // ***** StatusByte_1_DCU ******************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t b_motDir :1; // Direction Vehicle
- uint8_t b_reverse :1; // Reverse Active
- uint8_t b_neutral :1; // Neutral Active
- uint8_t b_drive :1; // Drive Active
- uint8_t b_PC_Activ :1; // Precharging Active
- uint8_t b_keyStart_DICO1:1; // Key Start Acknowledge
- uint8_t b_ini :1; // Initialisation Active
- uint8_t b_pulsEnGlobalFb:1; // Drive System Active
- } B;
- } b_StatusByte_1_DCU_t;
- // ***** StatusByte_2_DCU ******************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t b_MC_Rq :1; // Main Contactor Request
- uint8_t b_PC_Rq :1; // Precharge Contactor Request
- uint8_t b_fan_Rq :1; // Fan Control Request
- uint8_t b_pumpOn_Rq :1; // Pump On Request
- uint8_t b_errorGen1SAE :1; // Charging Error
- uint8_t b_perfRedSys :1; // Performing Reduction System
- uint8_t b_warningSys :1; // Red Lamp Flashing System
- uint8_t b_errorSys :1; // Red Lamp System
- } B;
- } b_StatusByte_2_DCU_t;
- // ***** ErrorBuffer ***********************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t b_errBufferIndication :1; // Error Buffer Indication
- uint8_t Reserved :3;
- uint8_t errCountMark :4; // Online Diagnoses Error Buffer Number
- } B;
- } b_ErrorBuffer_t;
- // ***** DICO1_EVCU ( DICO1 to Electronic Vehicle Control Unit ) ***************
- typedef struct {
- b_StatusByte_1_DCU_t b_StatusByte_1_DCU;
- b_StatusByte_2_DCU_t b_StatusByte_2_DCU;
- uint16_t rpmSys; // Drive Motor Speed;
- uint8_t tqRefSys; // Drive Motor Torque Reference;
- uint8_t tqSys; // Actual Drive Motor Torque Feedback;
- uint8_t powerBR_fb; // Brake Resistor Power Feedback;
- b_ErrorBuffer_t b_ErrorBufferIndication;
- } DICO1_EVCU_t;
- // ***** DiagnosticInverter1 ***************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t diagnMotor1 :2; // Diagnostic / Inverter Motor 1
- uint8_t diagnMotor2 :2; // Diagnostic / Inverter Motor 2
- uint8_t diagnMotor3 :2; // Diagnostic / Inverter Motor 3
- uint8_t diagnMotor4 :2; // Diagnostic / Inverter Motor 4
- } B;
- } b_DiagnosticInverter1_t;
- // ***** DiagnosticInverter2 ***************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t diagnGenerator1 :2; // Diagnostic Inverter / Generator 1
- uint8_t diagnGenerator2 :2; // Diagnostic Inverter / Generator 2
- uint8_t emergency_MC_Off :2; // Emergency Main Contactor Off
- uint8_t b_emergencyEngineOff:2; // Emergency Engine Off
- } B;
- } b_DiagnosticInverter2_t;
- // ***** DiagnosticInverter3 ***************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t diagnAux1 :2; // Diagnostic Inverter / AUX-Mot 1
- uint8_t diagnAux2 :2; // Diagnostic Inverter / AUX-Mot 2
- uint8_t diagnDCDC1 :2; // Diagnostic DC/DC 1
- uint8_t diagnDCDC2 :2; // Diagnostic DC/DC 2
- } B;
- } b_DiagnosticInverter3_t;
- // ***** Current_HEV_Mode ******************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t operationModeFb :4; // Current HEV Mode
- uint8_t diagnDICO :2; // Diagnostic DICO Master
- uint8_t b_startCE_extHyMode :2; // Engine start with 24 V starter
- } B;
- } b_Current_HEV_Mode_t;
- // ***** DICO2_EVCU ( DICO2 to Electronic Vehicle Control Unit ) ***************
- typedef struct {
- b_DiagnosticInverter1_t b_DiagnosticInverter1;
- b_DiagnosticInverter2_t b_DiagnosticInverter2;
- b_DiagnosticInverter3_t b_DiagnosticInverter3;
- b_Current_HEV_Mode_t b_Current_HEV_Mode;
- uint16_t powerGenerator1Fb; // Power Generator 1
- uint16_t rpmGenerator1Fb; // Speed Generator 1
- } DICO2_EVCU_t;
- // ***** ModeFeedback **********************************************************
- typedef union {
- uint16_t R;
- struct {
- uint16_t Reserved :13;
- uint16_t BMS_EoC :1;
- uint16_t Mode_Feedback :2;
- } B;
- } ModeFeedback_t;
- // ***** BMU1_EVCU ( Battery Management Unit to Electronic Vehicle Control Unit ) *
- typedef struct {
- ModeFeedback_t ModeFeedBack;
- } BMU1_EVCU_t;
- // ***** ModeRequest ***********************************************************
- typedef union {
- uint16_t R;
- struct {
- uint16_t Reserved :14;
- uint16_t Mode_Request :2;
- } B;
- } ModeRequest_t;
- // ***** EVCU1_BMU ( Electronic Vehicle Control Unit to Battery Management Unit ) *
- typedef struct {
- ModeRequest_t ModeRequest;
- } EVCU1_BMU_t;
- // ***** NLG5 Control Bitmap ***************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t Reserved :5;
- uint8_t NLG5_C_CP_V :1; // Control Pilot Ventilation Request
- uint8_t NLG5_C_C_EL :1; // Clear Error Latch
- uint8_t NLG5_C_C_EN :1; // CAN enable
- } B;
- } NLG5_CTLB_t;
- // ***** NLG5 Control BMU to BRUSA *********************************************
- typedef struct {
- NLG5_CTLB_t NLG5_CTLB; // NLG5 Control Bitmap
- uint16_t NLG5_MC_MAX; // Mains Current Maximum
- uint16_t NLG5_OV_COM; // Output Voltage Command
- uint16_t NLG5_OC_COM; // Output Current Command
- } NLG5_CTL_t;
- // ***** NLG5 Status Bitmap 1 **************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t NLG5_S_CP_DT :1; // Control pilot detected
- uint8_t NLG5_S_UM_II :1; // USA mains LEVEL II , 240V/32A/60Hz
- uint8_t NLG5_S_UM_I :1; // USA mains LEVEL I, 120V/12A/60Hz
- uint8_t NLG5_S_EUM :1; // Europe mains (230V/50Hz)
- uint8_t NLG5_S_FAN :1; // NLG5 Fan active
- uint8_t NLG5_S_WAR :1; // NLG5 general limit warning
- uint8_t NLG5_S_ERR :1; // NLG5 general error latch
- uint8_t NLG5_S_HE :1; // NLG5 power enable
- } B;
- } NLG5_STB1_t;
- // ***** NLG5 Status Bitmap 2 **************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t NLG5_S_L_PMAX :1; // Limitation by NLG5 maximum power
- uint8_t NLG5_S_L_CP :1; // Limitation by control pilot
- uint8_t NLG5_S_L_PI :1; // Limitation by power indicator
- uint8_t NLG5_S_L_MC :1; // Limitation by mains current
- uint8_t NLG5_S_L_OC :1; // Limitation by output current
- uint8_t NLG5_S_L_OV :1; // Limitation by output voltage
- uint8_t NNLG5_S_BPD_II :1; // Limitation by output voltage
- uint8_t NLG5_S_BPD_I :1; // Bypass detection I
- } B;
- } NLG5_STB2_t;
- // ***** NLG5 Status Bitmap 3 **************************************************
- typedef union {
- uint8_t R;
- struct {
- uint8_t NLG5_S_L_T_BATT :1; // Limitation by battery temperature
- uint8_t NLG5_S_L_T_TR :1; // Limitation by temperature transformer
- uint8_t NLG5_S_L_T_DIO :1; // Limitation by temperature diodes
- uint8_t NLG5_S_L_T_POW :1; // Limitation by temperature power stage
- uint8_t NLG5_S_L_T_CPRIM:1; // Limitation by temperature Capacitors prim.
- uint8_t NLG5_S_L_MO_MAX :1; // Limitation by NLG5 maximum output voltage
- uint8_t NLG5_S_L_OC_MAX :1; // Limitation by NLG5 maximum output current
- uint8_t NLG5_S_L_MC_MAX :1; // Limitation by NLG5 maximum mains current
- } B;
- } NLG5_STB3_t;
- // ***** NLG5 Status BRUSA to BMU **********************************************
- typedef struct {
- NLG5_STB1_t NLG5_STB1; // NLG5 Status Bitmap 1/4
- NLG5_STB2_t NLG5_STB2; // NLG5 Status Bitmap 2/4
- NLG5_STB3_t NLG5_STB3; // NLG5 Status Bitmap 3/4
- uint8_t NLG5_STB4; // NLG5 Status Bitmap 4/4
- } NLG5_ST_t;
- // ***** CAN0 REQUEST TELEGRAM ****************
- typedef struct {
- union {
- uint8_t Byte[4];
- struct {
- uint8_t MasterAlive:3;
- uint8_t SetMode:5;
- uint8_t BalancingCell0_7;
- uint8_t BalancingCell8_15;
- uint8_t BalancingCell16_23;
- }Values;
- };
- }MASTER_X_BMS_TELEGRAM;
- // ***** CAN0 SLAVE 0 - 5 Telegram
- typedef struct{
- uint16_t SlaveAlive:3;
- uint16_t Vcell0:13;
- uint16_t Vcell1;
- uint16_t Vcell2;
- uint16_t Vcell3;
- }SLAVE_X0_5_BMS_TELEGRAM;
- // ***** CAN0 SLVAE 6 TELEGRAM
- typedef struct{
- uint8_t SlaveAlive:3;
- uint8_t SlaveMode:5;
- uint8_t reserved1:2;
- uint8_t SlaveError:6;
- uint16_t reserved2;
- uint16_t reserved3;
- uint16_t reserved4;
- }SLAVE_X6_BMS_TELEGRAM;
- // ***** CAN0 SLVAE 7 TELEGRAM
- typedef struct{
- uint8_t SlaveAlive:3;
- uint8_t MuxCounter:3;
- uint8_t reserverd1:2;
- int8_t TempHeatSink;
- int8_t TempSens0;
- int8_t TempSens1;
- int8_t TempSens2;
- int8_t TempSens3;
- uint16_t reserved2;
- }SLAVE_X7_BMS_TELEGRAM;
- // ***** CAN0 UI TELEGRAM
- typedef struct{
- uint8_t UIAlive:3;
- uint8_t UIMode:5;
- uint16_t Ubatt;
- uint16_t Ibatt;
- uint16_t reserved;
- uint8_t Checksum;
- }SLAVE_UI_BMS_TELEGRAM;
- typedef struct {
- uint8_t HS_closed:1;
- uint8_t LS_closed:1;
- uint8_t PRECHARGE_closed:1;
- uint8_t reseved:5;
- }BMS_MASTER_RELAY_STATE;
- typedef enum {
- BMS_CAN_ID_SEARCH_INIT=0,
- BMS_CAN_ID_SEARCH_CHECK_COMMUNICATION,
- BMS_CAN_ID_SEARCH_RECONFIGURE_CAN0_IDS,
- BMS_CAN_ID_SEARCH_SAFE_CONFIGURATION
- }BMS_CAN_ID_SEARCH_FSM_t;
- typedef union{
- uint16_t word;
- struct{
- uint16_t SOC_Initialized:1;
- uint16_t Slave_Can_Id_valid:1;
- uint16_t reserved:14;
- }Bit;
- }MASTER_STARTUP_STATE;
- typedef struct {
- uint8_t CanId;
- uint8_t SerialNr[8];
- }SLAVE_ID_t;
- typedef struct {
- MASTER_STARTUP_STATE state;
- BMS_CAN_ID_SEARCH_FSM_t fsmState;
- SLAVE_ID_t SlaveConfig[CAN0_MAX_NR_OF_SLAVES];
- float maxBatteryVoltage;
- float minBatteryVoltage;
- float startSoC;
- }MASTER_STARTUP_CONFIG_t;
- // states of RUNNING_MODE_FSM
- typedef enum {
- RUN_MODE_INIT=0,
- RUN_MODE_CHECK_FOR_ACTIVE_ERRORS,
- RUN_MODE_ES3_FSM,
- RUN_MODE_ES2_FSM,
- RUN_MODE_ES1_FSM,
- RUN_MODE_OPERATION,
- RUN_MODE_SYSTEM_POWER_DOWN
- }MASTER_RUNNING_MODE;
- // states of Master CAN0 Fsm
- typedef enum{
- OP_MODE_INIT=0,
- OP_MODE_CHECK_STARTUP_CONDITIONS,
- OP_MODE_SET_PRECHARGE_RELAY,
- OP_MODE_SET_MAIN_RELAY,
- OP_MODE_NORMAL,
- OP_MODE_SOC_LOW,
- OP_MODE_ERROR
- }MASTER_CAN0_OPERATION_MODE;
- typedef enum{
- ES1_FSM_INIT=0,
- ES1_FSM_CHECK_IF_ERROR_VALID,
- ES1_FSM_ERROR_REVOKED
- }MASTER_CAN0_ES1_STATE;
- typedef enum{
- ES2_FSM_INIT=0,
- ES2_FSM_CHECK_IF_ERROR_VALID,
- ES2_FSM_WAIT_FOR_SHUTDOWN,
- ES2_FSM_ERROR_REVOKED,
- ES2_FSM_SYSTEM_SHUTDOWN
- }MASTER_CAN0_ES2_STATE;
- typedef enum{
- ES3_FSM_INIT=0,
- ES3_FSM_CONNECT_TO_SERVICE_TOOL,
- ES3_FSM_SYSTEM_SHUTDOWN,
- ES3_FSM_SYSTEM_REPAIR,
- ES3_FSM_ERROR_REVOKED
- }MASTER_CAN0_ES3_STATE;
- typedef enum{
- RCT_INV_INACTIVE=0,
- RCT_INV_CAN_CONNECTED,
- RCT_INV_RELALY_CONNECTED,
- RCT_INV_RELAY_DISCONNECT
- }BMS_RCT_INVERTER_FSM_STATE_t;
- typedef struct {
- BMS_RCT_INVERTER_FSM_STATE_t state;
- uint8_t inverterCanOnline;
- uint8_t inverterIsCharging;
- float startupPwr;
- }BMS_RCT_INVERTER_t;
- typedef enum { INIT=0,
- CHECK_IF_SLAVE_ACTIVE,
- SEND_REQUEST_TELEGRAM,
- WAIT_FOR_SLAVE_RESPONSE,
- CHECK_CAN_DATA,
- DO_CALCULATIONS,
- RUNNING_MODE_FSM,
- HANDLE_CAN_ERROR,
- WAIT_FOR_NEXT_SLAVE_TIMESLOT,
- SEND_RECEIVE_INVERTER_DATA,
- WAIT_FOR_NEXT_COMMUNICATION_CYCLE,
- SHUT_DOWN_BMS,
- ERROR_UNKNOWN_STATE
- }MASTER_CAN0_FSM_STATE_t;
- typedef enum { ERROR_INIT=0,
- ERROR_CHECK_IF_SLAVE_ACTIVE,
- ERROR_SEND_REQUEST_TELEGRAM,
- ERROR_WAIT_FOR_SLAVE_RESPONSE,
- ERROR_CHECK_CAN_DATA,
- ERROR_DO_CALCULATIONS,
- ERROR_HANDLE_CAN_ERROR,
- ERROR_WAIT_FOR_NEXT_SLAVE_TIMESLOT,
- ERROR_SEND_RECEIVE_INVERTER_DATA,
- ERROR_WAIT_FOR_NEXT_COMMUNICATION_CYCLE,
- ERROR_SHUT_DOWN_BMS,
- ERROR_ERROR_UNKNOWN_STATE
- }MASTER_CAN0_ERROR_FSM_STATE_t;
- // states of Master CAN1 Fsm
- typedef enum { CAN1_INIT=0,
- CAN1_SEND_DATA,
- CAN1_WAIT_TILL_NEXT_TRANSMIT,
- CAN1_REQUEST_DATA,
- CAN1_WAIT_FOR_REQUEST_RESPONSE,
- CAN1_WAIT_FOR_NEXT_CYCLE
- }MASTER_CAN1_FSM_STATE_t;
- typedef enum { CAN1_FSM_INIT=0,
- CAN1_FSM_SEND_HIGH_PRIO_DATA,
- CAN1_FSM_SEND_LOW_PRIO_DATA,
- CAN1_FSM_SEND_REQUEST_DATA,
- CAN1_FSM_WAIT_FOR_RESPONSE,
- CAN1_FSM_SEND_ES_1,
- CAN1_FSM_SEND_ES_2,
- CAN1_FSM_SEND_ES_3,
- CAN1_FSM_ERROR
- }MASTER_CAN1_FSM_INVERTER_STATE_t;
- typedef enum { CAN1_FAST_RX_FSM_REQUEST_BATTERY_CURRENT=0,
- CAN1_FAST_RX_FSM_REQUEST_BATTERY_VOLTAGE,
- CAN1_FAST_RX_FSM_REQUEST_COMPLETE
- }MASTER_CAN1_FSM_FAST_REQUEST_STATE_t;
- // CONNECTIONS STATUS OF SLAVE
- typedef enum {
- NOT_CONNECTED=0,
- CONNECTED,
- DEBUG_SLAVE_SIMULATED,
- DEBUG_DATA_SIMULATED,
- TIMEOUT,
- TELEGRAM_LOST
- }SLAVE_CAN0_CONNECT_STATUS_t;
- typedef enum { MASTER_OPERATION_INIT=0,
- SET_PRECHARGE_RELAIS,
- SET_MAIN_RELAIS,
- MASTER_OPERATION_COMPLETE
- }MASTER_OPERATION_FSM_STATE_t;
- typedef struct{
- uint16_t SlaveErrorCounterRegister;
- uint32_t SlaveErrorStateRegister;
- uint8_t FailedComCnt;
- uint8_t WrongAliveCnt;
- }SLAVE_ERROR_STRUCT_t;
- typedef enum {
- SLAVE=0,
- UI
- }SLAVE_CAN0_TYPE_t;
- typedef enum {
- BMS_BALANCE_INIT=0,
- BMS_BALANCE_GET_VOLTAGE,
- BMS_BALANCE_BALANCE_CELLS,
- BMS_BALANCE_COOL,
- BMS_BALANCE_OFF
- }BMS_BALANCE_STATE_t;
- // fsm struct for running mode fsm
- typedef struct {
- MASTER_RUNNING_MODE RunningMode;
- MASTER_CAN0_OPERATION_MODE OperationMode;
- uint64_t OperationModeTimestamp;
- MASTER_CAN0_ES1_STATE ErrorState1fsm;
- uint64_t ErrorState2Timestamp;
- uint64_t ErrorState3Timestamp;
- MASTER_CAN0_ES2_STATE ErrorState2fsm;
- MASTER_CAN0_ES3_STATE ErrorState3fsm;
- uint32_t onCounter; // counter for relay closed time
- }BMS_RUNNING_MODE_t;
- // connection status of cells
- typedef enum {
- CELL_NOT_CONNECTED=0,
- CELL_BYPASSED,
- CELL_CONNECTED
- }CELL_STATE_t;
- typedef enum {
- TEMP_SENSOR_NOT_CONNECTED=0,
- TEMP_SENSOR_CONNECTED
- }TEMP_SENSOR_STATE_t;
- typedef struct {
- uint32_t valueId;
- float value;
- }BMS_CAN1_INVERTER_FLOAT_t;
- typedef struct {
- uint32_t valueId;
- uint32_t payload;
- }BMS_CAN1_INVERTER_CELL_DATA_t;
- typedef struct {
- uint32_t valueId;
- uint32_t value;
- }BMS_CAN1_INVERTER_INTEGER_32_t;
- typedef struct {
- uint32_t valueId;
- uint32_t value;
- }BMS_CAN1_INVERTER_INTEGER_16_t;
- typedef struct {
- uint32_t valueId;
- uint8_t globalBatteryStatus;
- uint8_t errorCode;
- uint8_t byte6;
- uint8_t byte7;
- }BMS_CAN1_INVERTER_BATTERY_STATUS_t;
- typedef struct {
- union {
- uint8_t Byte[14][8];
- struct {
- BMS_CAN1_INVERTER_INTEGER_32_t batteryModeExtra;
- BMS_CAN1_INVERTER_FLOAT_t maxBatteryChargeCurrent;
- BMS_CAN1_INVERTER_FLOAT_t maxBatteryChargeVoltage;
- BMS_CAN1_INVERTER_FLOAT_t maxBatteryDischargeCurrent;
- BMS_CAN1_INVERTER_FLOAT_t minBatteryDischargeVoltage;
- BMS_CAN1_INVERTER_FLOAT_t batteryCurrent;
- BMS_CAN1_INVERTER_FLOAT_t batteryVoltage;
- BMS_CAN1_INVERTER_FLOAT_t batterySOCtarget;
- BMS_CAN1_INVERTER_FLOAT_t batterySOC;
- BMS_CAN1_INVERTER_FLOAT_t batteryCapacity;
- BMS_CAN1_INVERTER_FLOAT_t batteryTemperature;
- BMS_CAN1_INVERTER_FLOAT_t batterySOH;
- BMS_CAN1_INVERTER_INTEGER_32_t batteryMode;
- BMS_CAN1_INVERTER_BATTERY_STATUS_t batteryStatus;
-
- }Values;
- };
- }BMS_CAN1_INVERTER_TX;
- typedef struct {
- union {
- uint8_t Byte[8];
- struct {
- uint32_t valueId;
- uint32_t requestId;
- };
- };
- }BMS_CAN1_INVERTER_REQUEST;
- /// Error handling
- typedef struct {
- union {
- uint32_t Word;
- struct{
- uint32_t SubsystemNr:5;
- uint32_t ErrorType:21;
- uint32_t CellNr:5;
- uint32_t active:1;
- }Slave;
- struct{
- uint32_t SubsystemNr:5;
- uint32_t ErrorCode:26;
- uint32_t active:1;
- }Master;
- struct{
- uint32_t SubsystemNr:5;
- uint32_t ErrorCode:26;
- uint32_t active:1;
- }UI;
- };
- }BMS_ERROR_STATE_t;
- typedef struct {
- uint8_t recoveryPending;
- uint64_t recoveryTimestamp;// used to determine timespan for inverter to be able to fix errors
- }BMS_ERROR_RECOVERY_STRUCT_t;
- typedef struct {
- BMS_ERROR_STATE_t ES1_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 1 errors
- BMS_ERROR_STATE_t ES2_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 2 errors
- BMS_ERROR_STATE_t ES3_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 3 errors
- BMS_ERROR_RECOVERY_STRUCT_t ES1_Error_Recovery[BMS_ERROR_ERROR_STACK_SIZE];
- BMS_ERROR_RECOVERY_STRUCT_t ES2_Error_Recovery[BMS_ERROR_ERROR_STACK_SIZE];
- uint8_t ES1_ErrorCounter;//Number of Class 1 errors
- uint8_t ES2_ErrorCounter;//Number of Class 2 errors
- uint8_t ES2_New_Error; // flag to mark newly occured errors
- uint8_t ES3_ErrorCounter;//Number of Class 3 errors
- }BMS_ERROR_BUFFER_t;
- typedef struct {
- BMS_ERROR_STATE_t ES1_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 1 errors
- BMS_ERROR_STATE_t ES2_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 2 errors
- BMS_ERROR_STATE_t ES3_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 3 errors
- uint32_t counter;
- }BMS_ERROR_FRAM_DEBUG_t;
- typedef struct {
- float actualACpower;
- float phaseL1Voltage;
- float phaseL2Voltage;
- float phaseL3Voltage;
- float DCinputA_voltage;
- float DCinputB_voltage;
- uint16_t islandMode;
- float DCinputA_power;
- float DCinputB_power;
- float expectedInputPower;
- float batteryVoltage;
- float batteryCurrent;
- }BMS_CAN1_INVERTER_RX;
- typedef struct {
- BMS_CAN1_INVERTER_TX txStruct;
- BMS_CAN1_INVERTER_RX rxStruct;
- }BMS_CAN1_INVERTER;
- // ***** struct for selecting pending Master or Slave Telegram ********
- typedef struct {
- uint8_t nrOfRecTelegrams;
- uint8_t transmission_pending;
- uint32_t timestamp;
- MASTER_CAN0_FSM_STATE_t state;
- uint8_t slaveSelect;
- uint8_t telegramSelect;
- } MASTER_CAN0_STATE_t ;
- typedef struct {
- float I_max_charge_temp_max;
- float I_max_charge_temp_min;
- float I_max_charge_SoC ;
- float I_max_discharge_temp_max;
- float I_max_discharge_temp_min;
- float I_max_discharge_SoC ;
- float I_max_charge_derate;
- float I_max_discharge_derate;
- }MASTER_OVER_CURRENT_LIMITS_t;
- // ***** struct to contain slave DATA and status and to acess Mailboxes and registers*******
- typedef struct {
- SLAVE_CAN0_CONNECT_STATUS_t SlaveConnectionState;
- SLAVE_CAN0_TYPE_t SlaveType;
- CAN_MAILBOX* TxMailbox_ptr;
- MASTER_X_BMS_TELEGRAM* TxTelegram_ptr;
- uint16_t CellVoltage[MAX_SLAVE_CELLS];
- uint16_t minCellVoltage;
- uint16_t maxCellVoltage;
- uint32_t BlockVoltage;
- int8_t CellTemp[MAX_SLAVE_CELLS];
- CELL_STATE_t CellConnectionState[MAX_SLAVE_CELLS];
- TEMP_SENSOR_STATE_t TempSensConnectionState[MAX_SLAVE_CELLS];
- int8_t HeatSinkTemp;
- int8_t maxCellTemp;
- int8_t minCellTemp;
- uint8_t SlaveAliveCnt[CAN0_NR_OF_TELEGRAMS];
- uint8_t SlaveMode;
- uint8_t SlaveError;
- uint8_t SlaveTelegramsRecFlag;
- uint8_t Set_Mode;
- uint8_t Balance_Cell_0_7;
- uint8_t Balance_Cell_8_15;
- uint8_t Balance_Cell_16_23;
- uint8_t MuxCounter;
- uint8_t MasterAliveCnt;
- SLAVE_ERROR_STRUCT_t SlaveCanCommuniationError;
- }BMS_CAN0_SLAVE_t;
- typedef struct {
- uint8_t OffsetError:1;
- uint8_t SupplyError:1;
- uint8_t RelayOpen:1;
- uint8_t reserved:5;
- }BMS_CAN0_UI_ERRORS_t;
- typedef struct {
- uint16_t Ubatt;
- int16_t Ibatt;
- uint8_t Checksum;
- BMS_CAN0_UI_ERRORS_t Errors;
- uint32_t UbattFiFo[UI_VOLTAGE_FIFO_SIZE];
- uint32_t SystemVoltageFiFo[UI_VOLTAGE_FIFO_SIZE];
- int16_t IbattFiFo[UI_CURRENT_FIFO_SIZE];
- float Ibatt_Inverter_FIFO[UI_CURRENT_FIFO_SIZE];
- }BMS_CAN0_UI_t;
- typedef struct {
- uint8_t slaveNr;
- SLAVE_CAN0_TYPE_t type;
- SLAVE_CAN0_CONNECT_STATUS_t connectionSate;
- CELL_STATE_t cellConnectionState[MAX_SLAVE_CELLS];
- TEMP_SENSOR_STATE_t tempSensConnectionState[MAX_SLAVE_CELLS];
- }BMS_SLAVE_CONFIGURATION_t;
- typedef struct {
- uint8_t slaveNr;
- SLAVE_CAN0_TYPE_t type;
- SLAVE_CAN0_CONNECT_STATUS_t connectionSate;
- }BMS_UI_CONFIGURATION_t;
- typedef struct {
- uint32_t timestamp;
- MASTER_OPERATION_FSM_STATE_t FsmState;
- }BMS_MASTER_OPERATION_t;
- typedef struct {
- MASTER_CAN1_FSM_STATE_t fsmState;
- uint8_t txMsgNr;
- uint32_t timestamp;
- uint32_t delay;
- } MASTER_CAN1_STRUCT_t;
- typedef struct {
- MASTER_CAN1_FSM_INVERTER_STATE_t fsmState;
- MASTER_CAN1_FSM_FAST_REQUEST_STATE_t fastRxState;
- uint8_t fastRequestFsmRunning;
- uint8_t slowRequestFsmRunning;
- uint32_t highPrioMsgNr;
- uint8_t lowPrioMsgNr;
- uint8_t transmitErrorNrEs1;
- uint8_t transmitErrorNrEs2;
- uint8_t transmitErrorNrEs3;
- uint32_t requestTelegramNr;
- uint32_t timeoutCyclesCnt;
- uint32_t receivedTelegrams;
- uint32_t nrOfRecCurrentSamples;
- } MASTER_CAN1_INVERTER_STRUCT_t;
- typedef enum {
- BMS_SOC_IDLE=0,
- BMS_SOC_CHECK_CURRENT,
- BMS_SOC_CHARGE,
- BMS_SOC_CHARGE_AREA_FULL,
- BMS_SOC_CHARGE_AREA_HIGH,
- BMS_SOC_CHARGE_WAIT_FOR_RELAXATION,
- BMS_SOC_CHARGE_AREA_CHARGE,
- BMS_SOC_CHARGE_C_CNT,
- BMS_SOC_CHARGE_SMOOTHING,
- BMS_SOC_CHARGE_DERATE,
- BMS_SOC_DISCHARGE,
- BMS_SOC_DISCHARGE_AREA_EMPTY,
- BMS_SOC_DISCHARGE_AREA_LOW,
- BMS_SOC_DISCHARGE_WAIT_FOR_RELAXATION,
- BMS_SOC_DISCHARGE_AREA_DISCHARGE,
- BMS_SOC_DISCHARGE_C_CNT,
- BMS_SOC_DISCHARGE_SMOOTHING,
- BMS_SOC_DISCHARGE_DERATE,
- BMS_SOC_REST,
- BMS_SOC_READY
- }MASTER_SOC_ESTIMATOR_STATE_t;
- typedef enum {
- BMS_MASTER_TEMP_SENSOR_INITIATE_MEASUREMENT=0,
- BMS_MASTER_TEMP_SENSOR_UPDATE_MEASUREMENT
- }MASTER_TEMP_SENSOR_FSM_t;
- /*
- * Voltage Areas assigned with State of charge Area to support coulumb counting
- */
- typedef struct {
- float SoC_limit_high; // upper limit for SOC in Area [0...1]
- float SoC_limit_low; // lower limit of SOC in Area [0 ...1]
- uint16_t OCV_limit_high; // upper limit of Open Clamp Voltage in Area [mV]
- uint16_t OCV_limit_low; // lower limit of Open Clamp Voltage in Area [mV]
- uint16_t OCV_hysteresis; // hyseresis for detection of new Area [mV]
- } MASTER_SOC_ESTIMATOR_AREA_t;
- typedef struct {
- uint16_t U_bat_max; // Maximum Clamp Voltage => SoC = 100%
- uint16_t U_ocv_correct; // Open Clamp Voltage used to Correct Columb counting
- float Ri_charge; // Ri of cell at charging
- float U_ocv_SoC; // SoC @ U_ocv_correct
- } MASTER_SOC_ESTIMATOR_CHARGE_THRESHOLD_t;
- typedef struct {
- uint16_t U_bat_min; // Minimum Clamp Voltage => SoC = 0%
- uint16_t U_ocv_correct; // Open Clamp Voltage used to Correct Columb counting
- float Ri_discharge; // Ri of cell at discharging
- float U_ocv_SoC; // SoC @ U_ocv_correct
- } MASTER_SOC_ESTIMATOR_DISCHARGE_THRESHOLD_t;
- typedef struct {
- float SoC;
- uint16_t OCV;
- }MASTER_SOC_ESTIMATOR_INIT_SOC_LUT_t;
- /*
- *
- */
- typedef struct {
- float capacity;
- float SoC_Ah;
- float SoC_percentage;
- float SoC_percentage_smooth;
- float SoC_Ah_smooth;
- float delta_t;
- float MaxBatteryChargeCurrent;
- float MaxBatteryDischargeCurrent;
- float SoC_percentage_smooth_FiFo[SOC_SMOOTH_FIFO_SIZE];
- uint16_t Ocv_calc;
- uint16_t ChargeRelaxationWaitCnt;
- uint16_t DischargeRelaxationWaitCnt;
- uint16_t flags;
- uint16_t ChargeSmoothFlags;
- MASTER_SOC_ESTIMATOR_STATE_t state;
- MASTER_SOC_ESTIMATOR_CHARGE_THRESHOLD_t ChargeThreshold;
- MASTER_SOC_ESTIMATOR_DISCHARGE_THRESHOLD_t DischargeThreshold;
- } MASTER_SOC_ESTIMATOR_t;
- typedef struct {
- MASTER_OVER_CURRENT_LIMITS_t currentLimits;
- MASTER_STARTUP_CONFIG_t startupConfig;
- BMS_MASTER_RELAY_STATE relayState;
- MASTER_TEMP_SENSOR_FSM_t MasterTempSensState;
- int16_t masterTemp;
- BMS_RUNNING_MODE_t RunMode;
- uint32_t winterModeTimestamp;
- BMS_CAN0_SLAVE_t Slave[CAN0_MAX_NR_OF_SLAVES];
- BMS_CAN0_UI_t UI_Board;
- BMS_CAN0_SLAVE_t tempSlave;
- BMS_CAN0_UI_t temp_UI_Board;
- uint64_t reset_test_timestamp;
- uint32_t StateOfCharge; // SOC in mAs
- uint16_t minCellVoltage;
- uint16_t maxCellVoltage;
- int8_t minCellTemp;
- int8_t maxCellTemp;
- int8_t maxHeatSinkTemp;
- int8_t minHeatSinkTemp;
- float SoC_outside;
- MASTER_CAN0_FSM_STATE_t FsmState;
- MASTER_CAN0_ERROR_FSM_STATE_t FsmErrorState;
- BMS_ERROR_BUFFER_t ErrorBuffer;
- BMS_CAN1_INVERTER inverter;
- BMS_RCT_INVERTER_t inverterState;
- uint8_t slaveSelect;
- uint64_t timestamp;
- uint64_t time;
- uint64_t cycleTimestamp;
- uint8_t transmission_pending;
- uint8_t cycleCounter;
- uint32_t systemVoltage;
- uint8_t allValuesInitialized;
- uint8_t startCan1Comm;
- uint8_t NrOfSlaves;
- BMS_BALANCE_STATE_t balancerState;
- MASTER_SOC_ESTIMATOR_t SoC_estimator;
- uint8_t SoC_initialized;
- uint8_t ErrorFlags;
- MASTER_CAN1_INVERTER_STRUCT_t CAN1_fsmStruct;
- float UiInverterInconsistency;
- float UiSlaveInconsistency;
- } MASTER_CAN0_STRUCT_t;
- #endif /* ifndef*/
|