BMS_Typedefs.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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. uint32_t OperationModeTimestamp;
  561. MASTER_CAN0_ES1_STATE ErrorState1fsm;
  562. uint32_t ErrorState2Timestamp;
  563. uint32_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. uint32_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. uint16_t Ubatt;
  741. int16_t Ibatt;
  742. uint8_t Checksum;
  743. uint32_t UbattFiFo[UI_VOLTAGE_FIFO_SIZE];
  744. uint32_t SystemVoltageFiFo[UI_VOLTAGE_FIFO_SIZE];
  745. int16_t IbattFiFo[UI_CURRENT_FIFO_SIZE];
  746. float Ibatt_Inverter_FIFO[UI_CURRENT_FIFO_SIZE];
  747. }BMS_CAN0_UI_t;
  748. typedef struct {
  749. uint8_t slaveNr;
  750. SLAVE_CAN0_TYPE_t type;
  751. SLAVE_CAN0_CONNECT_STATUS_t connectionSate;
  752. CELL_STATE_t cellConnectionState[MAX_SLAVE_CELLS];
  753. TEMP_SENSOR_STATE_t tempSensConnectionState[MAX_SLAVE_CELLS];
  754. }BMS_SLAVE_CONFIGURATION_t;
  755. typedef struct {
  756. uint8_t slaveNr;
  757. SLAVE_CAN0_TYPE_t type;
  758. SLAVE_CAN0_CONNECT_STATUS_t connectionSate;
  759. }BMS_UI_CONFIGURATION_t;
  760. typedef struct {
  761. uint32_t timestamp;
  762. MASTER_OPERATION_FSM_STATE_t FsmState;
  763. }BMS_MASTER_OPERATION_t;
  764. typedef struct {
  765. MASTER_CAN1_FSM_STATE_t fsmState;
  766. uint8_t txMsgNr;
  767. uint32_t timestamp;
  768. uint32_t delay;
  769. } MASTER_CAN1_STRUCT_t;
  770. typedef struct {
  771. MASTER_CAN1_FSM_INVERTER_STATE_t fsmState;
  772. MASTER_CAN1_FSM_FAST_REQUEST_STATE_t fastRxState;
  773. uint8_t fastRequestFsmRunning;
  774. uint8_t slowRequestFsmRunning;
  775. uint32_t highPrioMsgNr;
  776. uint8_t lowPrioMsgNr;
  777. uint8_t transmitErrorNrEs1;
  778. uint8_t transmitErrorNrEs2;
  779. uint8_t transmitErrorNrEs3;
  780. uint32_t requestTelegramNr;
  781. uint32_t timeoutCyclesCnt;
  782. uint32_t receivedTelegrams;
  783. uint32_t nrOfRecCurrentSamples;
  784. } MASTER_CAN1_INVERTER_STRUCT_t;
  785. typedef enum {
  786. BMS_SOC_IDLE=0,
  787. BMS_SOC_CHECK_CURRENT,
  788. BMS_SOC_CHARGE,
  789. BMS_SOC_CHARGE_AREA_FULL,
  790. BMS_SOC_CHARGE_AREA_HIGH,
  791. BMS_SOC_CHARGE_WAIT_FOR_RELAXATION,
  792. BMS_SOC_CHARGE_AREA_CHARGE,
  793. BMS_SOC_CHARGE_C_CNT,
  794. BMS_SOC_CHARGE_SMOOTHING,
  795. BMS_SOC_CHARGE_DERATE,
  796. BMS_SOC_DISCHARGE,
  797. BMS_SOC_DISCHARGE_AREA_EMPTY,
  798. BMS_SOC_DISCHARGE_AREA_LOW,
  799. BMS_SOC_DISCHARGE_WAIT_FOR_RELAXATION,
  800. BMS_SOC_DISCHARGE_AREA_DISCHARGE,
  801. BMS_SOC_DISCHARGE_C_CNT,
  802. BMS_SOC_DISCHARGE_SMOOTHING,
  803. BMS_SOC_DISCHARGE_DERATE,
  804. BMS_SOC_REST,
  805. BMS_SOC_READY
  806. }MASTER_SOC_ESTIMATOR_STATE_t;
  807. typedef enum {
  808. BMS_MASTER_TEMP_SENSOR_INITIATE_MEASUREMENT=0,
  809. BMS_MASTER_TEMP_SENSOR_UPDATE_MEASUREMENT
  810. }MASTER_TEMP_SENSOR_FSM_t;
  811. /*
  812. * Voltage Areas assigned with State of charge Area to support coulumb counting
  813. */
  814. typedef struct {
  815. float SoC_limit_high; // upper limit for SOC in Area [0...1]
  816. float SoC_limit_low; // lower limit of SOC in Area [0 ...1]
  817. uint16_t OCV_limit_high; // upper limit of Open Clamp Voltage in Area [mV]
  818. uint16_t OCV_limit_low; // lower limit of Open Clamp Voltage in Area [mV]
  819. uint16_t OCV_hysteresis; // hyseresis for detection of new Area [mV]
  820. } MASTER_SOC_ESTIMATOR_AREA_t;
  821. typedef struct {
  822. uint16_t U_bat_max; // Maximum Clamp Voltage => SoC = 100%
  823. uint16_t U_ocv_correct; // Open Clamp Voltage used to Correct Columb counting
  824. float Ri_charge; // Ri of cell at charging
  825. float U_ocv_SoC; // SoC @ U_ocv_correct
  826. } MASTER_SOC_ESTIMATOR_CHARGE_THRESHOLD_t;
  827. typedef struct {
  828. uint16_t U_bat_min; // Minimum Clamp Voltage => SoC = 0%
  829. uint16_t U_ocv_correct; // Open Clamp Voltage used to Correct Columb counting
  830. float Ri_discharge; // Ri of cell at discharging
  831. float U_ocv_SoC; // SoC @ U_ocv_correct
  832. } MASTER_SOC_ESTIMATOR_DISCHARGE_THRESHOLD_t;
  833. typedef struct {
  834. float SoC;
  835. uint16_t OCV;
  836. }MASTER_SOC_ESTIMATOR_INIT_SOC_LUT_t;
  837. /*
  838. *
  839. */
  840. typedef struct {
  841. float capacity;
  842. float SoC_Ah;
  843. float SoC_percentage;
  844. float SoC_percentage_smooth;
  845. float SoC_Ah_smooth;
  846. float delta_t;
  847. float MaxBatteryChargeCurrent;
  848. float MaxBatteryDischargeCurrent;
  849. float SoC_percentage_smooth_FiFo[SOC_SMOOTH_FIFO_SIZE];
  850. uint16_t Ocv_calc;
  851. uint16_t ChargeRelaxationWaitCnt;
  852. uint16_t DischargeRelaxationWaitCnt;
  853. uint16_t flags;
  854. uint16_t ChargeSmoothFlags;
  855. MASTER_SOC_ESTIMATOR_STATE_t state;
  856. MASTER_SOC_ESTIMATOR_CHARGE_THRESHOLD_t ChargeThreshold;
  857. MASTER_SOC_ESTIMATOR_DISCHARGE_THRESHOLD_t DischargeThreshold;
  858. } MASTER_SOC_ESTIMATOR_t;
  859. typedef struct {
  860. MASTER_OVER_CURRENT_LIMITS_t currentLimits;
  861. MASTER_STARTUP_CONFIG_t startupConfig;
  862. BMS_MASTER_RELAY_STATE relayState;
  863. MASTER_TEMP_SENSOR_FSM_t MasterTempSensState;
  864. int16_t masterTemp;
  865. BMS_RUNNING_MODE_t RunMode;
  866. uint32_t winterModeTimestamp;
  867. BMS_CAN0_SLAVE_t Slave[CAN0_MAX_NR_OF_SLAVES];
  868. BMS_CAN0_UI_t UI_Board;
  869. BMS_CAN0_SLAVE_t tempSlave;
  870. BMS_CAN0_UI_t temp_UI_Board;
  871. uint32_t reset_test_timestamp;
  872. uint32_t StateOfCharge; // SOC in mAs
  873. uint16_t minCellVoltage;
  874. uint16_t maxCellVoltage;
  875. int8_t minCellTemp;
  876. int8_t maxCellTemp;
  877. int8_t maxHeatSinkTemp;
  878. int8_t minHeatSinkTemp;
  879. float SoC_outside;
  880. MASTER_CAN0_FSM_STATE_t FsmState;
  881. MASTER_CAN0_ERROR_FSM_STATE_t FsmErrorState;
  882. BMS_ERROR_BUFFER_t ErrorBuffer;
  883. BMS_CAN1_INVERTER inverter;
  884. BMS_RCT_INVERTER_t inverterState;
  885. uint8_t slaveSelect;
  886. uint32_t timestamp;
  887. uint32_t time;
  888. uint32_t cycleTimestamp;
  889. uint8_t transmission_pending;
  890. uint8_t cycleCounter;
  891. uint32_t systemVoltage;
  892. uint8_t allValuesInitialized;
  893. uint8_t startCan1Comm;
  894. uint8_t NrOfSlaves;
  895. BMS_BALANCE_STATE_t balancerState;
  896. MASTER_SOC_ESTIMATOR_t SoC_estimator;
  897. uint8_t SoC_initialized;
  898. uint8_t ErrorFlags;
  899. MASTER_CAN1_INVERTER_STRUCT_t CAN1_fsmStruct;
  900. float UiInverterInconsistency;
  901. float UiSlaveInconsistency;
  902. } MASTER_CAN0_STRUCT_t;
  903. #endif /* ifndef*/