BMS_Typedefs.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. //##############################################################################
  2. //
  3. // FILE: BMS_Typedefs.h
  4. //
  5. // TITLE: Global Typedefs
  6. //
  7. //
  8. //##############################################################################
  9. //
  10. //==============================================================================
  11. // Change History:
  12. //==============================================================================
  13. // Datum: | Name | Version:| Change / Cause: | No
  14. //------------------------------------------------------------------------------
  15. // | | | | 002
  16. //------------------------------------------------------------------------------
  17. // | | | | 001
  18. //------------------------------------------------------------------------------
  19. // 05.07.13 | VR | 1.0 | New Build | 000
  20. //==============================================================================
  21. //==============================================================================
  22. // Comment Change / Cause:
  23. //==============================================================================
  24. // Change: 003 // 003
  25. //----------------------
  26. //
  27. //
  28. //==============================================================================
  29. // Change: 002 // 002
  30. //----------------------
  31. //
  32. //
  33. //==============================================================================
  34. // Change: 001 // 001
  35. //----------------------
  36. //
  37. //
  38. //==============================================================================
  39. #ifndef __BMS_TYPEDEFS_H__
  40. #define __BMS_TYPEDEFS_H__
  41. #include "BMS_Defines.h"
  42. // ***** Slave_Status_Flags ****************************************************
  43. typedef union {
  44. uint16_t R;
  45. struct { //Big Endian
  46. //High Byte
  47. uint16_t rsvd_h:8;
  48. //Low Byte
  49. uint16_t LTC_PEC_NOK:1;
  50. uint16_t LTC_Timeout:1;
  51. uint16_t LTC2_THSD:1;
  52. uint16_t LTC1_THSD:1;
  53. uint16_t LTC2_Temp_above80:1;
  54. uint16_t LTC1_Temp_above80:1;
  55. uint16_t LTC2_Temp_belowM40:1;
  56. uint16_t LTC1_Temp_belowM40:1;
  57. } B;
  58. } Slave_Status_Flags_t;
  59. // ***** Slave_Self_Test_Flags *************************************************
  60. typedef union {
  61. uint16_t R;
  62. struct { //Big Endian
  63. //High Byte
  64. uint16_t rsvd:1;
  65. uint16_t LTC2_Mux_NOK:1;
  66. uint16_t LTC2_RefH_NOK:1;
  67. uint16_t LTC2_RefL_NOK:1;
  68. uint16_t LTC2_TST2_NOK:1;
  69. uint16_t LTC2_TST1_NOK:1;
  70. uint16_t LTC2_VST2_NOK:1;
  71. uint16_t LTC2_VST1_NOK:1;
  72. //Low Byte
  73. uint16_t LTC_PEC_NOK:1;
  74. uint16_t LTC1_Mux_NOK:1;
  75. uint16_t LTC1_RefH_NOK:1;
  76. uint16_t LTC1_RefL_NOK:1;
  77. uint16_t LTC1_TST2_NOK:1;
  78. uint16_t LTC1_TST1_NOK:1;
  79. uint16_t LTC1_VST2_NOK:1;
  80. uint16_t LTC1_VST1_NOK:1;
  81. } B;
  82. } Slave_Self_Test_Flags_t;
  83. // ***** Slave_Control *********************************************************
  84. typedef struct {
  85. uint16_t Balancing_dV[MAX_CELLS];
  86. uint32_t Balancing_OnOff_Flags[MAX_SLAVES];
  87. union {
  88. uint8_t R[MAX_SLAVES];
  89. struct {
  90. uint8_t rsvd:5;
  91. uint8_t Fan2_RightLeft:1;
  92. uint8_t Fan2_OnOff:1;
  93. uint8_t Fan1_OnOff:1;
  94. } B[MAX_SLAVES];
  95. } FanCtrl;
  96. uint8_t Relais_OnOff[MAX_SLAVES];
  97. } Slave_Control_t;
  98. // ****** Slave_Status *********************************************************
  99. typedef struct {
  100. Slave_Status_Flags_t StatusFlags;
  101. Slave_Self_Test_Flags_t SelfTest_Flags;
  102. uint8_t LTC_PEC_FailCount;
  103. int8_t HeatSink_Temp;
  104. } Slave_Status_t;
  105. // ***** BSD (Battery Management System Slave Data ) ***************************
  106. typedef struct {
  107. uint16_t BlockVoltage [MAX_COUNT_UI];
  108. int16_t BlockCurrent [MAX_COUNT_UI];
  109. int32_t BlockCurrentSum;
  110. uint8_t BlockCounter [MAX_COUNT_UI];
  111. uint16_t CellVoltage [MAX_COUNT_VOLTAGE] [MAX_CELLS];
  112. int8_t CellTemperature [MAX_COUNT_TEMPERATURE] [MAX_CELLS];
  113. Slave_Status_t Slave_Status [MAX_COUNT_STATUS] [MAX_SLAVES];
  114. Slave_Control_t Balancer;
  115. uint16_t r_UI;
  116. uint16_t w_UI;
  117. uint16_t r_Voltage;
  118. uint16_t w_Voltage;
  119. uint16_t r_Temperature;
  120. uint16_t w_Temperature;
  121. uint16_t r_Status;
  122. uint16_t w_Status;
  123. uint16_t r_Balancer;
  124. uint16_t w_Balancer;
  125. } BSD_t;
  126. // ***** BSE ( Battery Management System Slave Errors ) ************************
  127. typedef struct {
  128. int16_t ErrorCell [MAX_CELLS];
  129. int16_t ErrorSlave [MAX_SLAVES];
  130. int16_t ErrorBMS;
  131. uint32_t CountVoltage;
  132. uint32_t CountTemperature;
  133. uint32_t CountStatus;
  134. } BSE_t;
  135. // ***** Main Contactor Feedback ***********************************************
  136. typedef union {
  137. uint8_t R;
  138. struct {
  139. uint8_t free :6;
  140. uint8_t b_MainContactorError :1;
  141. uint8_t b_MainContactorSwitch :1;
  142. } B;
  143. } b_MC_Fb_BMU_t;
  144. // ***** BMU_DICO ( Battery Management Unit to DICO ) **************************
  145. typedef struct {
  146. uint8_t voltageBattMax; // Maximum Battery Voltage
  147. uint8_t voltageBattMin; // Minimum Battery Voltage
  148. uint8_t currentBatMaxCharge; // Maximum Charge Current
  149. uint8_t currentBatMaxDischarge; // Maximum Discharge Current
  150. uint8_t batterySOC; // State Of Charge
  151. uint8_t voltageBattFb; // Total Battery Voltage
  152. uint8_t currentBattFb; // Total Battery Current
  153. b_MC_Fb_BMU_t b_MC_Fb_BMU; // Main Contactor Feedback
  154. } BMU_DICO_t;
  155. // ***** StatusByte_1_DCU ******************************************************
  156. typedef union {
  157. uint8_t R;
  158. struct {
  159. uint8_t b_motDir :1; // Direction Vehicle
  160. uint8_t b_reverse :1; // Reverse Active
  161. uint8_t b_neutral :1; // Neutral Active
  162. uint8_t b_drive :1; // Drive Active
  163. uint8_t b_PC_Activ :1; // Precharging Active
  164. uint8_t b_keyStart_DICO1:1; // Key Start Acknowledge
  165. uint8_t b_ini :1; // Initialisation Active
  166. uint8_t b_pulsEnGlobalFb:1; // Drive System Active
  167. } B;
  168. } b_StatusByte_1_DCU_t;
  169. // ***** StatusByte_2_DCU ******************************************************
  170. typedef union {
  171. uint8_t R;
  172. struct {
  173. uint8_t b_MC_Rq :1; // Main Contactor Request
  174. uint8_t b_PC_Rq :1; // Precharge Contactor Request
  175. uint8_t b_fan_Rq :1; // Fan Control Request
  176. uint8_t b_pumpOn_Rq :1; // Pump On Request
  177. uint8_t b_errorGen1SAE :1; // Charging Error
  178. uint8_t b_perfRedSys :1; // Performing Reduction System
  179. uint8_t b_warningSys :1; // Red Lamp Flashing System
  180. uint8_t b_errorSys :1; // Red Lamp System
  181. } B;
  182. } b_StatusByte_2_DCU_t;
  183. // ***** ErrorBuffer ***********************************************************
  184. typedef union {
  185. uint8_t R;
  186. struct {
  187. uint8_t b_errBufferIndication :1; // Error Buffer Indication
  188. uint8_t Reserved :3;
  189. uint8_t errCountMark :4; // Online Diagnoses Error Buffer Number
  190. } B;
  191. } b_ErrorBuffer_t;
  192. // ***** DICO1_EVCU ( DICO1 to Electronic Vehicle Control Unit ) ***************
  193. typedef struct {
  194. b_StatusByte_1_DCU_t b_StatusByte_1_DCU;
  195. b_StatusByte_2_DCU_t b_StatusByte_2_DCU;
  196. uint16_t rpmSys; // Drive Motor Speed;
  197. uint8_t tqRefSys; // Drive Motor Torque Reference;
  198. uint8_t tqSys; // Actual Drive Motor Torque Feedback;
  199. uint8_t powerBR_fb; // Brake Resistor Power Feedback;
  200. b_ErrorBuffer_t b_ErrorBufferIndication;
  201. } DICO1_EVCU_t;
  202. // ***** DiagnosticInverter1 ***************************************************
  203. typedef union {
  204. uint8_t R;
  205. struct {
  206. uint8_t diagnMotor1 :2; // Diagnostic / Inverter Motor 1
  207. uint8_t diagnMotor2 :2; // Diagnostic / Inverter Motor 2
  208. uint8_t diagnMotor3 :2; // Diagnostic / Inverter Motor 3
  209. uint8_t diagnMotor4 :2; // Diagnostic / Inverter Motor 4
  210. } B;
  211. } b_DiagnosticInverter1_t;
  212. // ***** DiagnosticInverter2 ***************************************************
  213. typedef union {
  214. uint8_t R;
  215. struct {
  216. uint8_t diagnGenerator1 :2; // Diagnostic Inverter / Generator 1
  217. uint8_t diagnGenerator2 :2; // Diagnostic Inverter / Generator 2
  218. uint8_t emergency_MC_Off :2; // Emergency Main Contactor Off
  219. uint8_t b_emergencyEngineOff:2; // Emergency Engine Off
  220. } B;
  221. } b_DiagnosticInverter2_t;
  222. // ***** DiagnosticInverter3 ***************************************************
  223. typedef union {
  224. uint8_t R;
  225. struct {
  226. uint8_t diagnAux1 :2; // Diagnostic Inverter / AUX-Mot 1
  227. uint8_t diagnAux2 :2; // Diagnostic Inverter / AUX-Mot 2
  228. uint8_t diagnDCDC1 :2; // Diagnostic DC/DC 1
  229. uint8_t diagnDCDC2 :2; // Diagnostic DC/DC 2
  230. } B;
  231. } b_DiagnosticInverter3_t;
  232. // ***** Current_HEV_Mode ******************************************************
  233. typedef union {
  234. uint8_t R;
  235. struct {
  236. uint8_t operationModeFb :4; // Current HEV Mode
  237. uint8_t diagnDICO :2; // Diagnostic DICO Master
  238. uint8_t b_startCE_extHyMode :2; // Engine start with 24 V starter
  239. } B;
  240. } b_Current_HEV_Mode_t;
  241. // ***** DICO2_EVCU ( DICO2 to Electronic Vehicle Control Unit ) ***************
  242. typedef struct {
  243. b_DiagnosticInverter1_t b_DiagnosticInverter1;
  244. b_DiagnosticInverter2_t b_DiagnosticInverter2;
  245. b_DiagnosticInverter3_t b_DiagnosticInverter3;
  246. b_Current_HEV_Mode_t b_Current_HEV_Mode;
  247. uint16_t powerGenerator1Fb; // Power Generator 1
  248. uint16_t rpmGenerator1Fb; // Speed Generator 1
  249. } DICO2_EVCU_t;
  250. // ***** ModeFeedback **********************************************************
  251. typedef union {
  252. uint16_t R;
  253. struct {
  254. uint16_t Reserved :13;
  255. uint16_t BMS_EoC :1;
  256. uint16_t Mode_Feedback :2;
  257. } B;
  258. } ModeFeedback_t;
  259. // ***** BMU1_EVCU ( Battery Management Unit to Electronic Vehicle Control Unit ) *
  260. typedef struct {
  261. ModeFeedback_t ModeFeedBack;
  262. } BMU1_EVCU_t;
  263. // ***** ModeRequest ***********************************************************
  264. typedef union {
  265. uint16_t R;
  266. struct {
  267. uint16_t Reserved :14;
  268. uint16_t Mode_Request :2;
  269. } B;
  270. } ModeRequest_t;
  271. // ***** EVCU1_BMU ( Electronic Vehicle Control Unit to Battery Management Unit ) *
  272. typedef struct {
  273. ModeRequest_t ModeRequest;
  274. } EVCU1_BMU_t;
  275. // ***** NLG5 Control Bitmap ***************************************************
  276. typedef union {
  277. uint8_t R;
  278. struct {
  279. uint8_t Reserved :5;
  280. uint8_t NLG5_C_CP_V :1; // Control Pilot Ventilation Request
  281. uint8_t NLG5_C_C_EL :1; // Clear Error Latch
  282. uint8_t NLG5_C_C_EN :1; // CAN enable
  283. } B;
  284. } NLG5_CTLB_t;
  285. // ***** NLG5 Control BMU to BRUSA *********************************************
  286. typedef struct {
  287. NLG5_CTLB_t NLG5_CTLB; // NLG5 Control Bitmap
  288. uint16_t NLG5_MC_MAX; // Mains Current Maximum
  289. uint16_t NLG5_OV_COM; // Output Voltage Command
  290. uint16_t NLG5_OC_COM; // Output Current Command
  291. } NLG5_CTL_t;
  292. // ***** NLG5 Status Bitmap 1 **************************************************
  293. typedef union {
  294. uint8_t R;
  295. struct {
  296. uint8_t NLG5_S_CP_DT :1; // Control pilot detected
  297. uint8_t NLG5_S_UM_II :1; // USA mains LEVEL II , 240V/32A/60Hz
  298. uint8_t NLG5_S_UM_I :1; // USA mains LEVEL I, 120V/12A/60Hz
  299. uint8_t NLG5_S_EUM :1; // Europe mains (230V/50Hz)
  300. uint8_t NLG5_S_FAN :1; // NLG5 Fan active
  301. uint8_t NLG5_S_WAR :1; // NLG5 general limit warning
  302. uint8_t NLG5_S_ERR :1; // NLG5 general error latch
  303. uint8_t NLG5_S_HE :1; // NLG5 power enable
  304. } B;
  305. } NLG5_STB1_t;
  306. // ***** NLG5 Status Bitmap 2 **************************************************
  307. typedef union {
  308. uint8_t R;
  309. struct {
  310. uint8_t NLG5_S_L_PMAX :1; // Limitation by NLG5 maximum power
  311. uint8_t NLG5_S_L_CP :1; // Limitation by control pilot
  312. uint8_t NLG5_S_L_PI :1; // Limitation by power indicator
  313. uint8_t NLG5_S_L_MC :1; // Limitation by mains current
  314. uint8_t NLG5_S_L_OC :1; // Limitation by output current
  315. uint8_t NLG5_S_L_OV :1; // Limitation by output voltage
  316. uint8_t NNLG5_S_BPD_II :1; // Limitation by output voltage
  317. uint8_t NLG5_S_BPD_I :1; // Bypass detection I
  318. } B;
  319. } NLG5_STB2_t;
  320. // ***** NLG5 Status Bitmap 3 **************************************************
  321. typedef union {
  322. uint8_t R;
  323. struct {
  324. uint8_t NLG5_S_L_T_BATT :1; // Limitation by battery temperature
  325. uint8_t NLG5_S_L_T_TR :1; // Limitation by temperature transformer
  326. uint8_t NLG5_S_L_T_DIO :1; // Limitation by temperature diodes
  327. uint8_t NLG5_S_L_T_POW :1; // Limitation by temperature power stage
  328. uint8_t NLG5_S_L_T_CPRIM:1; // Limitation by temperature Capacitors prim.
  329. uint8_t NLG5_S_L_MO_MAX :1; // Limitation by NLG5 maximum output voltage
  330. uint8_t NLG5_S_L_OC_MAX :1; // Limitation by NLG5 maximum output current
  331. uint8_t NLG5_S_L_MC_MAX :1; // Limitation by NLG5 maximum mains current
  332. } B;
  333. } NLG5_STB3_t;
  334. // ***** NLG5 Status BRUSA to BMU **********************************************
  335. typedef struct {
  336. NLG5_STB1_t NLG5_STB1; // NLG5 Status Bitmap 1/4
  337. NLG5_STB2_t NLG5_STB2; // NLG5 Status Bitmap 2/4
  338. NLG5_STB3_t NLG5_STB3; // NLG5 Status Bitmap 3/4
  339. uint8_t NLG5_STB4; // NLG5 Status Bitmap 4/4
  340. } NLG5_ST_t;
  341. // ***** CAN0 REQUEST TELEGRAM ****************
  342. typedef struct {
  343. union {
  344. uint8_t Byte[4];
  345. struct {
  346. uint8_t MasterAlive:3;
  347. uint8_t SetMode:5;
  348. uint8_t BalancingCell0_7;
  349. uint8_t BalancingCell8_15;
  350. uint8_t BalancingCell16_23;
  351. }Values;
  352. };
  353. }MASTER_X_BMS_TELEGRAM;
  354. // ***** CAN0 SLAVE 0 - 5 Telegram
  355. typedef struct{
  356. uint16_t SlaveAlive:3;
  357. uint16_t Vcell0:13;
  358. uint16_t Vcell1;
  359. uint16_t Vcell2;
  360. uint16_t Vcell3;
  361. }SLAVE_X0_5_BMS_TELEGRAM;
  362. // ***** CAN0 SLVAE 6 TELEGRAM
  363. typedef struct{
  364. uint8_t SlaveAlive:3;
  365. uint8_t SlaveMode:5;
  366. uint8_t reserved1:2;
  367. uint8_t SlaveError:6;
  368. uint16_t reserved2;
  369. uint16_t reserved3;
  370. uint16_t reserved4;
  371. }SLAVE_X6_BMS_TELEGRAM;
  372. // ***** CAN0 SLVAE 7 TELEGRAM
  373. typedef struct{
  374. uint8_t SlaveAlive:3;
  375. uint8_t MuxCounter:3;
  376. uint8_t reserverd1:2;
  377. int8_t TempHeatSink;
  378. int8_t TempSens0;
  379. int8_t TempSens1;
  380. int8_t TempSens2;
  381. int8_t TempSens3;
  382. uint16_t reserved2;
  383. }SLAVE_X7_BMS_TELEGRAM;
  384. // ***** CAN0 UI TELEGRAM
  385. typedef struct{
  386. uint8_t UIAlive:3;
  387. uint8_t UIMode:5;
  388. uint16_t Ubatt;
  389. uint16_t Ibatt;
  390. uint16_t reserved;
  391. uint8_t Checksum;
  392. }SLAVE_UI_BMS_TELEGRAM;
  393. typedef struct {
  394. uint8_t HS_closed:1;
  395. uint8_t LS_closed:1;
  396. uint8_t PRECHARGE_closed:1;
  397. uint8_t reseved:5;
  398. }BMS_MASTER_RELAY_STATE;
  399. typedef enum {
  400. BMS_CAN_ID_SEARCH_INIT=0,
  401. BMS_CAN_ID_SEARCH_CHECK_COMMUNICATION,
  402. BMS_CAN_ID_SEARCH_RECONFIGURE_CAN0_IDS,
  403. BMS_CAN_ID_SEARCH_SAFE_CONFIGURATION
  404. }BMS_CAN_ID_SEARCH_FSM_t;
  405. typedef union{
  406. uint16_t word;
  407. struct{
  408. uint16_t SOC_Initialized:1;
  409. uint16_t Slave_Can_Id_valid:1;
  410. uint16_t reserved:14;
  411. }Bit;
  412. }MASTER_STARTUP_STATE;
  413. typedef struct {
  414. uint8_t CanId;
  415. uint8_t SerialNr[8];
  416. }SLAVE_ID_t;
  417. typedef struct {
  418. MASTER_STARTUP_STATE state;
  419. BMS_CAN_ID_SEARCH_FSM_t fsmState;
  420. SLAVE_ID_t SlaveConfig[CAN0_MAX_NR_OF_SLAVES];
  421. float maxBatteryVoltage;
  422. float minBatteryVoltage;
  423. float startSoC;
  424. }MASTER_STARTUP_CONFIG_t;
  425. // states of RUNNING_MODE_FSM
  426. typedef enum {
  427. RUN_MODE_INIT=0,
  428. RUN_MODE_CHECK_FOR_ACTIVE_ERRORS,
  429. RUN_MODE_ES3_FSM,
  430. RUN_MODE_ES2_FSM,
  431. RUN_MODE_ES1_FSM,
  432. RUN_MODE_OPERATION,
  433. RUN_MODE_SYSTEM_POWER_DOWN
  434. }MASTER_RUNNING_MODE;
  435. // states of Master CAN0 Fsm
  436. typedef enum{
  437. OP_MODE_INIT=0,
  438. OP_MODE_CHECK_STARTUP_CONDITIONS,
  439. OP_MODE_SET_PRECHARGE_RELAY,
  440. OP_MODE_SET_MAIN_RELAY,
  441. OP_MODE_NORMAL,
  442. OP_MODE_SOC_LOW,
  443. OP_MODE_ERROR
  444. }MASTER_CAN0_OPERATION_MODE;
  445. typedef enum{
  446. ES1_FSM_INIT=0,
  447. ES1_FSM_CHECK_IF_ERROR_VALID,
  448. ES1_FSM_ERROR_REVOKED
  449. }MASTER_CAN0_ES1_STATE;
  450. typedef enum{
  451. ES2_FSM_INIT=0,
  452. ES2_FSM_CHECK_IF_ERROR_VALID,
  453. ES2_FSM_WAIT_FOR_SHUTDOWN,
  454. ES2_FSM_ERROR_REVOKED,
  455. ES2_FSM_SYSTEM_SHUTDOWN
  456. }MASTER_CAN0_ES2_STATE;
  457. typedef enum{
  458. ES3_FSM_INIT=0,
  459. ES3_FSM_CONNECT_TO_SERVICE_TOOL,
  460. ES3_FSM_SYSTEM_SHUTDOWN,
  461. ES3_FSM_SYSTEM_REPAIR,
  462. ES3_FSM_ERROR_REVOKED
  463. }MASTER_CAN0_ES3_STATE;
  464. typedef enum{
  465. RCT_INV_INACTIVE=0,
  466. RCT_INV_CAN_CONNECTED,
  467. RCT_INV_RELALY_CONNECTED,
  468. RCT_INV_RELAY_DISCONNECT
  469. }BMS_RCT_INVERTER_FSM_STATE_t;
  470. typedef struct {
  471. BMS_RCT_INVERTER_FSM_STATE_t state;
  472. uint8_t inverterCanOnline;
  473. uint8_t inverterIsCharging;
  474. float startupPwr;
  475. }BMS_RCT_INVERTER_t;
  476. typedef enum { INIT=0,
  477. CHECK_IF_SLAVE_ACTIVE,
  478. SEND_REQUEST_TELEGRAM,
  479. WAIT_FOR_SLAVE_RESPONSE,
  480. CHECK_CAN_DATA,
  481. DO_CALCULATIONS,
  482. RUNNING_MODE_FSM,
  483. HANDLE_CAN_ERROR,
  484. WAIT_FOR_NEXT_SLAVE_TIMESLOT,
  485. SEND_RECEIVE_INVERTER_DATA,
  486. WAIT_FOR_NEXT_COMMUNICATION_CYCLE,
  487. SHUT_DOWN_BMS,
  488. ERROR_UNKNOWN_STATE
  489. }MASTER_CAN0_FSM_STATE_t;
  490. typedef enum { ERROR_INIT=0,
  491. ERROR_CHECK_IF_SLAVE_ACTIVE,
  492. ERROR_SEND_REQUEST_TELEGRAM,
  493. ERROR_WAIT_FOR_SLAVE_RESPONSE,
  494. ERROR_CHECK_CAN_DATA,
  495. ERROR_DO_CALCULATIONS,
  496. ERROR_HANDLE_CAN_ERROR,
  497. ERROR_WAIT_FOR_NEXT_SLAVE_TIMESLOT,
  498. ERROR_SEND_RECEIVE_INVERTER_DATA,
  499. ERROR_WAIT_FOR_NEXT_COMMUNICATION_CYCLE,
  500. ERROR_SHUT_DOWN_BMS,
  501. ERROR_ERROR_UNKNOWN_STATE
  502. }MASTER_CAN0_ERROR_FSM_STATE_t;
  503. // states of Master CAN1 Fsm
  504. typedef enum { CAN1_INIT=0,
  505. CAN1_SEND_DATA,
  506. CAN1_WAIT_TILL_NEXT_TRANSMIT,
  507. CAN1_REQUEST_DATA,
  508. CAN1_WAIT_FOR_REQUEST_RESPONSE,
  509. CAN1_WAIT_FOR_NEXT_CYCLE
  510. }MASTER_CAN1_FSM_STATE_t;
  511. typedef enum { CAN1_FSM_INIT=0,
  512. CAN1_FSM_SEND_HIGH_PRIO_DATA,
  513. CAN1_FSM_SEND_LOW_PRIO_DATA,
  514. CAN1_FSM_SEND_REQUEST_DATA,
  515. CAN1_FSM_WAIT_FOR_RESPONSE,
  516. CAN1_FSM_SEND_ES_1,
  517. CAN1_FSM_SEND_ES_2,
  518. CAN1_FSM_SEND_ES_3,
  519. CAN1_FSM_ERROR
  520. }MASTER_CAN1_FSM_INVERTER_STATE_t;
  521. typedef enum { CAN1_FAST_RX_FSM_REQUEST_BATTERY_CURRENT=0,
  522. CAN1_FAST_RX_FSM_REQUEST_BATTERY_VOLTAGE,
  523. CAN1_FAST_RX_FSM_REQUEST_COMPLETE
  524. }MASTER_CAN1_FSM_FAST_REQUEST_STATE_t;
  525. // CONNECTIONS STATUS OF SLAVE
  526. typedef enum {
  527. NOT_CONNECTED=0,
  528. CONNECTED,
  529. DEBUG_SLAVE_SIMULATED,
  530. DEBUG_DATA_SIMULATED,
  531. TIMEOUT,
  532. TELEGRAM_LOST
  533. }SLAVE_CAN0_CONNECT_STATUS_t;
  534. typedef enum { MASTER_OPERATION_INIT=0,
  535. SET_PRECHARGE_RELAIS,
  536. SET_MAIN_RELAIS,
  537. MASTER_OPERATION_COMPLETE
  538. }MASTER_OPERATION_FSM_STATE_t;
  539. typedef struct{
  540. uint16_t SlaveErrorCounterRegister;
  541. uint32_t SlaveErrorStateRegister;
  542. uint8_t FailedComCnt;
  543. uint8_t WrongAliveCnt;
  544. }SLAVE_ERROR_STRUCT_t;
  545. typedef enum {
  546. SLAVE=0,
  547. UI
  548. }SLAVE_CAN0_TYPE_t;
  549. typedef enum {
  550. BMS_BALANCE_INIT=0,
  551. BMS_BALANCE_GET_VOLTAGE,
  552. BMS_BALANCE_BALANCE_CELLS,
  553. BMS_BALANCE_COOL,
  554. BMS_BALANCE_OFF
  555. }BMS_BALANCE_STATE_t;
  556. // fsm struct for running mode fsm
  557. typedef struct {
  558. MASTER_RUNNING_MODE RunningMode;
  559. MASTER_CAN0_OPERATION_MODE OperationMode;
  560. uint64_t OperationModeTimestamp;
  561. MASTER_CAN0_ES1_STATE ErrorState1fsm;
  562. uint64_t ErrorState2Timestamp;
  563. uint64_t ErrorState3Timestamp;
  564. MASTER_CAN0_ES2_STATE ErrorState2fsm;
  565. MASTER_CAN0_ES3_STATE ErrorState3fsm;
  566. uint32_t onCounter; // counter for relay closed time
  567. }BMS_RUNNING_MODE_t;
  568. // connection status of cells
  569. typedef enum {
  570. CELL_NOT_CONNECTED=0,
  571. CELL_BYPASSED,
  572. CELL_CONNECTED
  573. }CELL_STATE_t;
  574. typedef enum {
  575. TEMP_SENSOR_NOT_CONNECTED=0,
  576. TEMP_SENSOR_CONNECTED
  577. }TEMP_SENSOR_STATE_t;
  578. typedef struct {
  579. uint32_t valueId;
  580. float value;
  581. }BMS_CAN1_INVERTER_FLOAT_t;
  582. typedef struct {
  583. uint32_t valueId;
  584. uint32_t payload;
  585. }BMS_CAN1_INVERTER_CELL_DATA_t;
  586. typedef struct {
  587. uint32_t valueId;
  588. uint32_t value;
  589. }BMS_CAN1_INVERTER_INTEGER_32_t;
  590. typedef struct {
  591. uint32_t valueId;
  592. uint32_t value;
  593. }BMS_CAN1_INVERTER_INTEGER_16_t;
  594. typedef struct {
  595. uint32_t valueId;
  596. uint8_t globalBatteryStatus;
  597. uint8_t errorCode;
  598. uint8_t byte6;
  599. uint8_t byte7;
  600. }BMS_CAN1_INVERTER_BATTERY_STATUS_t;
  601. typedef struct {
  602. union {
  603. uint8_t Byte[14][8];
  604. struct {
  605. BMS_CAN1_INVERTER_INTEGER_32_t batteryModeExtra;
  606. BMS_CAN1_INVERTER_FLOAT_t maxBatteryChargeCurrent;
  607. BMS_CAN1_INVERTER_FLOAT_t maxBatteryChargeVoltage;
  608. BMS_CAN1_INVERTER_FLOAT_t maxBatteryDischargeCurrent;
  609. BMS_CAN1_INVERTER_FLOAT_t minBatteryDischargeVoltage;
  610. BMS_CAN1_INVERTER_FLOAT_t batteryCurrent;
  611. BMS_CAN1_INVERTER_FLOAT_t batteryVoltage;
  612. BMS_CAN1_INVERTER_FLOAT_t batterySOCtarget;
  613. BMS_CAN1_INVERTER_FLOAT_t batterySOC;
  614. BMS_CAN1_INVERTER_FLOAT_t batteryCapacity;
  615. BMS_CAN1_INVERTER_FLOAT_t batteryTemperature;
  616. BMS_CAN1_INVERTER_FLOAT_t batterySOH;
  617. BMS_CAN1_INVERTER_INTEGER_32_t batteryMode;
  618. BMS_CAN1_INVERTER_BATTERY_STATUS_t batteryStatus;
  619. }Values;
  620. };
  621. }BMS_CAN1_INVERTER_TX;
  622. typedef struct {
  623. union {
  624. uint8_t Byte[8];
  625. struct {
  626. uint32_t valueId;
  627. uint32_t requestId;
  628. };
  629. };
  630. }BMS_CAN1_INVERTER_REQUEST;
  631. /// Error handling
  632. typedef struct {
  633. union {
  634. uint32_t Word;
  635. struct{
  636. uint32_t SubsystemNr:5;
  637. uint32_t ErrorType:21;
  638. uint32_t CellNr:5;
  639. uint32_t active:1;
  640. }Slave;
  641. struct{
  642. uint32_t SubsystemNr:5;
  643. uint32_t ErrorCode:26;
  644. uint32_t active:1;
  645. }Master;
  646. struct{
  647. uint32_t SubsystemNr:5;
  648. uint32_t ErrorCode:26;
  649. uint32_t active:1;
  650. }UI;
  651. };
  652. }BMS_ERROR_STATE_t;
  653. typedef struct {
  654. uint8_t recoveryPending;
  655. uint64_t recoveryTimestamp;// used to determine timespan for inverter to be able to fix errors
  656. }BMS_ERROR_RECOVERY_STRUCT_t;
  657. typedef struct {
  658. BMS_ERROR_STATE_t ES1_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 1 errors
  659. BMS_ERROR_STATE_t ES2_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 2 errors
  660. BMS_ERROR_STATE_t ES3_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 3 errors
  661. BMS_ERROR_RECOVERY_STRUCT_t ES1_Error_Recovery[BMS_ERROR_ERROR_STACK_SIZE];
  662. BMS_ERROR_RECOVERY_STRUCT_t ES2_Error_Recovery[BMS_ERROR_ERROR_STACK_SIZE];
  663. uint8_t ES1_ErrorCounter;//Number of Class 1 errors
  664. uint8_t ES2_ErrorCounter;//Number of Class 2 errors
  665. uint8_t ES2_New_Error; // flag to mark newly occured errors
  666. uint8_t ES3_ErrorCounter;//Number of Class 3 errors
  667. }BMS_ERROR_BUFFER_t;
  668. typedef struct {
  669. BMS_ERROR_STATE_t ES1_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 1 errors
  670. BMS_ERROR_STATE_t ES2_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 2 errors
  671. BMS_ERROR_STATE_t ES3_Error[BMS_ERROR_ERROR_STACK_SIZE]; // Class 3 errors
  672. uint32_t counter;
  673. }BMS_ERROR_FRAM_DEBUG_t;
  674. typedef struct {
  675. float actualACpower;
  676. float phaseL1Voltage;
  677. float phaseL2Voltage;
  678. float phaseL3Voltage;
  679. float DCinputA_voltage;
  680. float DCinputB_voltage;
  681. uint16_t islandMode;
  682. float DCinputA_power;
  683. float DCinputB_power;
  684. float expectedInputPower;
  685. float batteryVoltage;
  686. float batteryCurrent;
  687. }BMS_CAN1_INVERTER_RX;
  688. typedef struct {
  689. BMS_CAN1_INVERTER_TX txStruct;
  690. BMS_CAN1_INVERTER_RX rxStruct;
  691. }BMS_CAN1_INVERTER;
  692. // ***** struct for selecting pending Master or Slave Telegram ********
  693. typedef struct {
  694. uint8_t nrOfRecTelegrams;
  695. uint8_t transmission_pending;
  696. uint32_t timestamp;
  697. MASTER_CAN0_FSM_STATE_t state;
  698. uint8_t slaveSelect;
  699. uint8_t telegramSelect;
  700. } MASTER_CAN0_STATE_t ;
  701. typedef struct {
  702. float I_max_charge_temp_max;
  703. float I_max_charge_temp_min;
  704. float I_max_charge_SoC ;
  705. float I_max_discharge_temp_max;
  706. float I_max_discharge_temp_min;
  707. float I_max_discharge_SoC ;
  708. float I_max_charge_derate;
  709. float I_max_discharge_derate;
  710. }MASTER_OVER_CURRENT_LIMITS_t;
  711. // ***** struct to contain slave DATA and status and to acess Mailboxes and registers*******
  712. typedef struct {
  713. SLAVE_CAN0_CONNECT_STATUS_t SlaveConnectionState;
  714. SLAVE_CAN0_TYPE_t SlaveType;
  715. CAN_MAILBOX* TxMailbox_ptr;
  716. MASTER_X_BMS_TELEGRAM* TxTelegram_ptr;
  717. uint16_t CellVoltage[MAX_SLAVE_CELLS];
  718. uint16_t minCellVoltage;
  719. uint16_t maxCellVoltage;
  720. uint32_t BlockVoltage;
  721. int8_t CellTemp[MAX_SLAVE_CELLS];
  722. CELL_STATE_t CellConnectionState[MAX_SLAVE_CELLS];
  723. TEMP_SENSOR_STATE_t TempSensConnectionState[MAX_SLAVE_CELLS];
  724. int8_t HeatSinkTemp;
  725. int8_t maxCellTemp;
  726. int8_t minCellTemp;
  727. uint8_t SlaveAliveCnt[CAN0_NR_OF_TELEGRAMS];
  728. uint8_t SlaveMode;
  729. uint8_t SlaveError;
  730. uint8_t SlaveTelegramsRecFlag;
  731. uint8_t Set_Mode;
  732. uint8_t Balance_Cell_0_7;
  733. uint8_t Balance_Cell_8_15;
  734. uint8_t Balance_Cell_16_23;
  735. uint8_t MuxCounter;
  736. uint8_t MasterAliveCnt;
  737. SLAVE_ERROR_STRUCT_t SlaveCanCommuniationError;
  738. }BMS_CAN0_SLAVE_t;
  739. typedef struct {
  740. uint8_t OffsetError:1;
  741. uint8_t SupplyError:1;
  742. uint8_t RelayOpen:1;
  743. uint8_t reserved:5;
  744. }BMS_CAN0_UI_ERRORS_t;
  745. typedef struct {
  746. uint16_t Ubatt;
  747. int16_t Ibatt;
  748. uint8_t Checksum;
  749. BMS_CAN0_UI_ERRORS_t Errors;
  750. uint32_t UbattFiFo[UI_VOLTAGE_FIFO_SIZE];
  751. uint32_t SystemVoltageFiFo[UI_VOLTAGE_FIFO_SIZE];
  752. int16_t IbattFiFo[UI_CURRENT_FIFO_SIZE];
  753. float Ibatt_Inverter_FIFO[UI_CURRENT_FIFO_SIZE];
  754. }BMS_CAN0_UI_t;
  755. typedef struct {
  756. uint8_t slaveNr;
  757. SLAVE_CAN0_TYPE_t type;
  758. SLAVE_CAN0_CONNECT_STATUS_t connectionSate;
  759. CELL_STATE_t cellConnectionState[MAX_SLAVE_CELLS];
  760. TEMP_SENSOR_STATE_t tempSensConnectionState[MAX_SLAVE_CELLS];
  761. }BMS_SLAVE_CONFIGURATION_t;
  762. typedef struct {
  763. uint8_t slaveNr;
  764. SLAVE_CAN0_TYPE_t type;
  765. SLAVE_CAN0_CONNECT_STATUS_t connectionSate;
  766. }BMS_UI_CONFIGURATION_t;
  767. typedef struct {
  768. uint32_t timestamp;
  769. MASTER_OPERATION_FSM_STATE_t FsmState;
  770. }BMS_MASTER_OPERATION_t;
  771. typedef struct {
  772. MASTER_CAN1_FSM_STATE_t fsmState;
  773. uint8_t txMsgNr;
  774. uint32_t timestamp;
  775. uint32_t delay;
  776. } MASTER_CAN1_STRUCT_t;
  777. typedef struct {
  778. MASTER_CAN1_FSM_INVERTER_STATE_t fsmState;
  779. MASTER_CAN1_FSM_FAST_REQUEST_STATE_t fastRxState;
  780. uint8_t fastRequestFsmRunning;
  781. uint8_t slowRequestFsmRunning;
  782. uint32_t highPrioMsgNr;
  783. uint8_t lowPrioMsgNr;
  784. uint8_t transmitErrorNrEs1;
  785. uint8_t transmitErrorNrEs2;
  786. uint8_t transmitErrorNrEs3;
  787. uint32_t requestTelegramNr;
  788. uint32_t timeoutCyclesCnt;
  789. uint32_t receivedTelegrams;
  790. uint32_t nrOfRecCurrentSamples;
  791. } MASTER_CAN1_INVERTER_STRUCT_t;
  792. typedef enum {
  793. BMS_SOC_IDLE=0,
  794. BMS_SOC_CHECK_CURRENT,
  795. BMS_SOC_CHARGE,
  796. BMS_SOC_CHARGE_AREA_FULL,
  797. BMS_SOC_CHARGE_AREA_HIGH,
  798. BMS_SOC_CHARGE_WAIT_FOR_RELAXATION,
  799. BMS_SOC_CHARGE_AREA_CHARGE,
  800. BMS_SOC_CHARGE_C_CNT,
  801. BMS_SOC_CHARGE_SMOOTHING,
  802. BMS_SOC_CHARGE_DERATE,
  803. BMS_SOC_DISCHARGE,
  804. BMS_SOC_DISCHARGE_AREA_EMPTY,
  805. BMS_SOC_DISCHARGE_AREA_LOW,
  806. BMS_SOC_DISCHARGE_WAIT_FOR_RELAXATION,
  807. BMS_SOC_DISCHARGE_AREA_DISCHARGE,
  808. BMS_SOC_DISCHARGE_C_CNT,
  809. BMS_SOC_DISCHARGE_SMOOTHING,
  810. BMS_SOC_DISCHARGE_DERATE,
  811. BMS_SOC_REST,
  812. BMS_SOC_READY
  813. }MASTER_SOC_ESTIMATOR_STATE_t;
  814. typedef enum {
  815. BMS_MASTER_TEMP_SENSOR_INITIATE_MEASUREMENT=0,
  816. BMS_MASTER_TEMP_SENSOR_UPDATE_MEASUREMENT
  817. }MASTER_TEMP_SENSOR_FSM_t;
  818. /*
  819. * Voltage Areas assigned with State of charge Area to support coulumb counting
  820. */
  821. typedef struct {
  822. float SoC_limit_high; // upper limit for SOC in Area [0...1]
  823. float SoC_limit_low; // lower limit of SOC in Area [0 ...1]
  824. uint16_t OCV_limit_high; // upper limit of Open Clamp Voltage in Area [mV]
  825. uint16_t OCV_limit_low; // lower limit of Open Clamp Voltage in Area [mV]
  826. uint16_t OCV_hysteresis; // hyseresis for detection of new Area [mV]
  827. } MASTER_SOC_ESTIMATOR_AREA_t;
  828. typedef struct {
  829. uint16_t U_bat_max; // Maximum Clamp Voltage => SoC = 100%
  830. uint16_t U_ocv_correct; // Open Clamp Voltage used to Correct Columb counting
  831. float Ri_charge; // Ri of cell at charging
  832. float U_ocv_SoC; // SoC @ U_ocv_correct
  833. } MASTER_SOC_ESTIMATOR_CHARGE_THRESHOLD_t;
  834. typedef struct {
  835. uint16_t U_bat_min; // Minimum Clamp Voltage => SoC = 0%
  836. uint16_t U_ocv_correct; // Open Clamp Voltage used to Correct Columb counting
  837. float Ri_discharge; // Ri of cell at discharging
  838. float U_ocv_SoC; // SoC @ U_ocv_correct
  839. } MASTER_SOC_ESTIMATOR_DISCHARGE_THRESHOLD_t;
  840. typedef struct {
  841. float SoC;
  842. uint16_t OCV;
  843. }MASTER_SOC_ESTIMATOR_INIT_SOC_LUT_t;
  844. /*
  845. *
  846. */
  847. typedef struct {
  848. float capacity;
  849. float SoC_Ah;
  850. float SoC_percentage;
  851. float SoC_percentage_smooth;
  852. float SoC_Ah_smooth;
  853. float delta_t;
  854. float MaxBatteryChargeCurrent;
  855. float MaxBatteryDischargeCurrent;
  856. float SoC_percentage_smooth_FiFo[SOC_SMOOTH_FIFO_SIZE];
  857. uint16_t Ocv_calc;
  858. uint16_t ChargeRelaxationWaitCnt;
  859. uint16_t DischargeRelaxationWaitCnt;
  860. uint16_t flags;
  861. uint16_t ChargeSmoothFlags;
  862. MASTER_SOC_ESTIMATOR_STATE_t state;
  863. MASTER_SOC_ESTIMATOR_CHARGE_THRESHOLD_t ChargeThreshold;
  864. MASTER_SOC_ESTIMATOR_DISCHARGE_THRESHOLD_t DischargeThreshold;
  865. } MASTER_SOC_ESTIMATOR_t;
  866. typedef struct {
  867. MASTER_OVER_CURRENT_LIMITS_t currentLimits;
  868. MASTER_STARTUP_CONFIG_t startupConfig;
  869. BMS_MASTER_RELAY_STATE relayState;
  870. MASTER_TEMP_SENSOR_FSM_t MasterTempSensState;
  871. int16_t masterTemp;
  872. BMS_RUNNING_MODE_t RunMode;
  873. uint32_t winterModeTimestamp;
  874. BMS_CAN0_SLAVE_t Slave[CAN0_MAX_NR_OF_SLAVES];
  875. BMS_CAN0_UI_t UI_Board;
  876. BMS_CAN0_SLAVE_t tempSlave;
  877. BMS_CAN0_UI_t temp_UI_Board;
  878. uint64_t reset_test_timestamp;
  879. uint32_t StateOfCharge; // SOC in mAs
  880. uint16_t minCellVoltage;
  881. uint16_t maxCellVoltage;
  882. int8_t minCellTemp;
  883. int8_t maxCellTemp;
  884. int8_t maxHeatSinkTemp;
  885. int8_t minHeatSinkTemp;
  886. float SoC_outside;
  887. MASTER_CAN0_FSM_STATE_t FsmState;
  888. MASTER_CAN0_ERROR_FSM_STATE_t FsmErrorState;
  889. BMS_ERROR_BUFFER_t ErrorBuffer;
  890. BMS_CAN1_INVERTER inverter;
  891. BMS_RCT_INVERTER_t inverterState;
  892. uint8_t slaveSelect;
  893. uint64_t timestamp;
  894. uint64_t time;
  895. uint64_t cycleTimestamp;
  896. uint64_t test_timestamp;
  897. uint8_t shutdown_initiated;
  898. uint8_t transmission_pending;
  899. uint8_t cycleCounter;
  900. uint32_t systemVoltage;
  901. uint8_t allValuesInitialized;
  902. uint8_t startCan1Comm;
  903. uint8_t NrOfSlaves;
  904. BMS_BALANCE_STATE_t balancerState;
  905. MASTER_SOC_ESTIMATOR_t SoC_estimator;
  906. uint8_t SoC_initialized;
  907. uint8_t ErrorFlags;
  908. MASTER_CAN1_INVERTER_STRUCT_t CAN1_fsmStruct;
  909. float UiInverterInconsistency;
  910. float UiSlaveInconsistency;
  911. } MASTER_CAN0_STRUCT_t;
  912. #endif /* ifndef*/