foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
sys.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file sys.c
44  * @author foxBMS Team
45  * @date 2020-02-24 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup ENGINE
49  * @prefix SYS
50  *
51  * @brief Sys driver implementation
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "general.h"
56 
57 #include "sys.h"
58 
59 #include "algorithm.h"
60 #include "bal.h"
61 #include "bms.h"
62 #include "can.h"
63 #include "contactor.h"
64 #include "diag.h"
65 #include "fram.h"
66 #include "fstd_types.h"
67 #include "imd.h"
68 #include "interlock.h"
69 #include "meas.h"
70 #include "os.h"
71 #include "sbc.h"
72 #include "sof_trapezoid.h"
73 #include "state_estimation.h"
74 
75 #include <stdint.h>
76 
77 /*========== Macros and Definitions =========================================*/
78 
79 /** Saves the last state and the last substate */
80 #define SYS_SAVELASTSTATES(x) \
81  (x)->lastState = (x)->state; \
82  (x)->lastSubstate = (x)->substate
83 
84 /** Magic number that is searched by the #SYS_GeneralMacroBist(). */
85 #define SYS_BIST_GENERAL_MAGIC_NUMBER (42u)
86 
87 /*========== Static Constant and Variable Definitions =======================*/
88 
89 /*========== Extern Constant and Variable Definitions =======================*/
90 
91 /** Symbolic names to check for multiple calls of #SYS_Trigger() */
92 typedef enum {
93  SYS_MULTIPLE_CALLS_NO, /*!< no multiple calls, OK */
94  SYS_MULTIPLE_CALLS_YES, /*!< multiple calls, not OK */
96 
97 /** contains the state of the contactor state machine */
99  .timer = 0,
100  .triggerEntry = 0,
101  .stateRequest = SYS_STATE_NO_REQUEST,
103  .substate = SYS_ENTRY,
104  .lastState = SYS_STATEMACH_UNINITIALIZED,
105  .lastSubstate = SYS_ENTRY,
106  .illegalRequestsCounter = 0,
107  .initializationTimeout = 0,
108 };
109 
110 /*========== Static Function Prototypes =====================================*/
111 /**
112  * @brief check for multiple calls of state machine trigger function
113  * @details The trigger function is not reentrant, which means it cannot
114  * be called multiple times. This functions increments the
115  * triggerEntry counter once and must be called each time the
116  * trigger function is called. If triggerEntry is greater than
117  * one, there were multiple calls. For this function to work,
118  * triggerEntry must be decremented each time the trigger function
119  * is called, even if no processing do because the timer is
120  * non-zero.
121  * @param pSystemState state of the fake state machine
122  * @return #SYS_MULTIPLE_CALLS_YES if there were multiple calls,
123  * #SYS_MULTIPLE_CALLS_NO otherwise
124  */
126 
127 /**
128  * @brief Defines the state transitions
129  * @details This function contains the implementation of the state
130  * machine, i.e., the sequence of states and substates.
131  * It is called by the trigger function every time
132  * the state machine timer has a non-zero value.
133  * @param pSystemState state of the example state machine
134  * @return TODO
135  */
137 
140 
141 /*========== Static Function Implementations ================================*/
143  FAS_ASSERT(pSystemState != NULL_PTR);
146  if (pSystemState->triggerEntry == 0u) {
147  pSystemState->triggerEntry++;
148  } else {
149  multipleCalls = SYS_MULTIPLE_CALLS_YES;
150  }
152  return multipleCalls;
153 }
154 
156  STD_RETURN_TYPE_e ranStateMachine = STD_OK;
157 
160  STD_RETURN_TYPE_e balancingInitializationState = STD_OK;
161  BAL_RETURN_TYPE_e balancingGlobalEnableState = BAL_ERROR;
162  STD_RETURN_TYPE_e bmsState = STD_NOT_OK;
163  bool imdInitialized = false;
164 
165  switch (pSystemState->state) {
166  /****************************UNINITIALIZED***********************************/
168  /* waiting for Initialization Request */
169  stateRequest = SYS_TransferStateRequest();
170  if (stateRequest == SYS_STATE_INITIALIZATION_REQUEST) {
171  SYS_SAVELASTSTATES(pSystemState);
172  pSystemState->timer = SYS_FSM_SHORT_TIME;
173  pSystemState->state = SYS_STATEMACH_INITIALIZATION;
174  pSystemState->substate = SYS_ENTRY;
175  } else if (stateRequest == SYS_STATE_NO_REQUEST) {
176  /* no actual request pending */
177  } else {
178  pSystemState->illegalRequestsCounter++; /* illegal request pending */
179  }
180  break;
181  /****************************INITIALIZATION**********************************/
183 
184  SYS_SAVELASTSTATES(pSystemState);
185  /* Initializations done here */
187  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
190  }
191  }
192 
193  pSystemState->timer = SYS_FSM_SHORT_TIME;
194  pSystemState->state = SYS_STATEMACH_INITIALIZE_SBC;
195  pSystemState->substate = SYS_ENTRY;
196  break;
197 
198  /**************************** INITIALIZE SBC *************************************/
200  SYS_SAVELASTSTATES(pSystemState);
201 
202  if (pSystemState->substate == SYS_ENTRY) {
204  pSystemState->timer = SYS_FSM_SHORT_TIME;
205  pSystemState->substate = SYS_WAIT_INITIALIZATION_SBC;
206  pSystemState->initializationTimeout = 0;
207  break;
208  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_SBC) {
210  if (sbcState == SBC_STATEMACHINE_RUNNING) {
211  pSystemState->timer = SYS_FSM_SHORT_TIME;
212  pSystemState->state = SYS_STATEMACH_INITIALIZE_CAN;
213  pSystemState->substate = SYS_ENTRY;
214  break;
215  } else {
216  if (pSystemState->initializationTimeout >
218  pSystemState->timer = SYS_FSM_SHORT_TIME;
219  pSystemState->state = SYS_STATEMACH_ERROR;
220  pSystemState->substate = SYS_SBC_INITIALIZATION_ERROR;
221  break;
222  }
223  pSystemState->timer = SYS_FSM_SHORT_TIME;
224  pSystemState->initializationTimeout++;
225  break;
226  }
227  } else {
228  FAS_ASSERT(FAS_TRAP); /* substate does not exist in this state */
229  }
230  break;
231 
232  /**************************** INITIALIZE CAN TRANSCEIVER ****************************/
234  CAN_Initialize();
235  pSystemState->timer = SYS_FSM_SHORT_TIME;
236  pSystemState->state = SYS_STATEMACH_SYSTEM_BIST;
237  pSystemState->substate = SYS_ENTRY;
238  break;
239 
240  /**************************** EXECUTE STARTUP BIST **********************************/
242  SYS_SAVELASTSTATES(pSystemState);
243  /* run BIST functions */
246 
247  pSystemState->timer = SYS_FSM_SHORT_TIME;
248  pSystemState->state = SYS_STATEMACH_INITIALIZED;
249  pSystemState->substate = SYS_ENTRY;
250  break;
251 
252  /****************************INITIALIZED*************************************/
254  SYS_SAVELASTSTATES(pSystemState);
255  /* Send CAN boot message directly on CAN */
257 
258  pSystemState->timer = SYS_FSM_SHORT_TIME;
260  pSystemState->substate = SYS_ENTRY;
261  break;
262 
263  /****************************INITIALIZE INTERLOCK*************************************/
265  SYS_SAVELASTSTATES(pSystemState);
267  pSystemState->timer = SYS_FSM_SHORT_TIME;
269  pSystemState->substate = SYS_ENTRY;
270  pSystemState->initializationTimeout = 0;
271  break;
272 
273  /****************************INITIALIZE CONTACTORS*************************************/
274  /* TODO: check if necessary and add */
275 
276  /****************************INITIALIZE BALANCING*************************************/
278  SYS_SAVELASTSTATES(pSystemState);
279  if (pSystemState->substate == SYS_ENTRY) {
281  pSystemState->timer = SYS_FSM_SHORT_TIME;
282  pSystemState->substate = SYS_WAIT_INITIALIZATION_BAL;
283  pSystemState->initializationTimeout = 0;
284  break;
285  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BAL) {
286  balancingInitializationState = BAL_GetInitializationState();
287  if (balancingInitializationState == STD_OK) {
288  pSystemState->timer = SYS_FSM_SHORT_TIME;
290  break;
291  } else {
292  if (pSystemState->initializationTimeout >
294  pSystemState->timer = SYS_FSM_SHORT_TIME;
295  pSystemState->state = SYS_STATEMACH_ERROR;
296  pSystemState->substate = SYS_BAL_INITIALIZATION_ERROR;
297  break;
298  }
299  pSystemState->timer = SYS_FSM_SHORT_TIME;
300  pSystemState->initializationTimeout++;
301  break;
302  }
303  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE) {
304  if (BS_BALANCING_DEFAULT_INACTIVE == true) {
305  balancingGlobalEnableState = BAL_SetStateRequest(BAL_STATE_GLOBAL_DISABLE_REQUEST);
306  } else {
307  balancingGlobalEnableState = BAL_SetStateRequest(BAL_STATE_GLOBAL_ENABLE_REQUEST);
308  }
309  if (balancingGlobalEnableState == BAL_OK) {
310  pSystemState->timer = SYS_FSM_SHORT_TIME;
312  pSystemState->substate = SYS_ENTRY;
313  break;
314  } else {
315  if (pSystemState->initializationTimeout >
317  pSystemState->timer = SYS_FSM_SHORT_TIME;
318  pSystemState->state = SYS_STATEMACH_ERROR;
319  pSystemState->substate = SYS_BAL_INITIALIZATION_ERROR;
320  break;
321  }
322  pSystemState->timer = SYS_FSM_SHORT_TIME;
323  pSystemState->initializationTimeout++;
324  break;
325  }
326  }
327  break;
328 
329  /****************************START FIRST MEAS CYCLE**************************/
331  SYS_SAVELASTSTATES(pSystemState);
332  if (pSystemState->substate == SYS_ENTRY) {
334  pSystemState->initializationTimeout = 0;
336  } else if (pSystemState->substate == SYS_WAIT_FIRST_MEASUREMENT_CYCLE) {
337  if (MEAS_IsFirstMeasurementCycleFinished() == true) {
338  /* allow initialization of algorithm module */
340  /* MEAS_RequestOpenWireCheck(); */ /*TODO: check with strings */
341  pSystemState->timer = SYS_FSM_SHORT_TIME;
342  if (BS_CURRENT_SENSOR_PRESENT == true) {
344  } else {
345  pSystemState->state = SYS_STATEMACH_INITIALIZE_MISC;
346  }
347  pSystemState->substate = SYS_ENTRY;
348  break;
349  } else {
350  if (pSystemState->initializationTimeout >
352  pSystemState->timer = SYS_FSM_SHORT_TIME;
353  pSystemState->state = SYS_STATEMACH_ERROR;
354  pSystemState->substate = SYS_MEAS_INITIALIZATION_ERROR;
355  break;
356  } else {
357  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
358  pSystemState->initializationTimeout++;
359  break;
360  }
361  }
362  }
363  break;
364 
365  /****************************CHECK CURRENT SENSOR PRESENCE*************************************/
367  SYS_SAVELASTSTATES(pSystemState);
368 
369  if (pSystemState->substate == SYS_ENTRY) {
370  pSystemState->initializationTimeout = 0;
371  CAN_EnablePeriodic(true);
372 #if defined(CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED)
373  /* If triggered mode is used, CAN trigger message needs to
374  * be transmitted and current sensor response has to be
375  * received afterwards. This may take some time, therefore
376  * delay has to be increased.
377  */
378  pSystemState->timer = SYS_FSM_LONG_TIME_MS;
379 #else /* defined(CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED) */
380  pSystemState->timer = SYS_FSM_LONG_TIME;
381 #endif /* defined(CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED) */
383  } else if (pSystemState->substate == SYS_WAIT_CURRENT_SENSOR_PRESENCE) {
384  bool allSensorsPresent = true;
385  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
386  if (CAN_IsCurrentSensorPresent(s) == true) {
387  if (CAN_IsCurrentSensorCcPresent(s) == true) {
388  SE_InitializeSoc(true, s);
389  } else {
390  SE_InitializeSoc(false, s);
391  }
392  if (CAN_IsCurrentSensorEcPresent(s) == true) {
393  SE_InitializeSoe(true, s);
394  } else {
395  SE_InitializeSoe(false, s);
396  }
397  SE_InitializeSoh(s);
398  } else {
399  allSensorsPresent = false;
400  }
401  }
402 
403  if (allSensorsPresent == true) {
404  SOF_Init();
405 
406  pSystemState->timer = SYS_FSM_SHORT_TIME;
407  pSystemState->state = SYS_STATEMACH_INITIALIZE_MISC;
408  pSystemState->substate = SYS_ENTRY;
409  break;
410  } else {
411  if (pSystemState->initializationTimeout >
413  pSystemState->timer = SYS_FSM_SHORT_TIME;
414  pSystemState->state = SYS_STATEMACH_ERROR;
416  break;
417  } else {
418  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
419  pSystemState->initializationTimeout++;
420  break;
421  }
422  }
423  } else {
424  FAS_ASSERT(FAS_TRAP); /* substate does not exist in this state */
425  }
426  break;
427 
428  /****************************INITIALIZED_MISC*************************************/
430  SYS_SAVELASTSTATES(pSystemState);
431 
432  if (BS_CURRENT_SENSOR_PRESENT == false) {
433  CAN_EnablePeriodic(true);
434  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
435  SE_InitializeSoc(false, s);
436  SE_InitializeSoe(false, s);
437  SE_InitializeSoh(s);
438  }
439  }
440 
441  pSystemState->initializationTimeout = 0u;
442  pSystemState->timer = SYS_FSM_SHORT_TIME;
443  pSystemState->state = SYS_STATEMACH_INITIALIZE_IMD;
444  pSystemState->substate = SYS_ENTRY;
445  break;
446 
447  /****************************INITIALIZED_IMD*************************************/
448 
450  SYS_SAVELASTSTATES(pSystemState);
451 
452  if (pSystemState->substate == SYS_ENTRY) {
454  /* Request inquired successfully */
455  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
456  pSystemState->state = SYS_STATEMACH_INITIALIZE_BMS;
457  pSystemState->substate = SYS_ENTRY;
458  pSystemState->initializationTimeout = 0u;
459  } else {
460  /* Request declined -> retry max. 3 times */
461  pSystemState->initializationTimeout++;
462  pSystemState->timer = SYS_FSM_SHORT_TIME;
464  /* Switch to error state */
465  pSystemState->timer = SYS_FSM_SHORT_TIME;
466  pSystemState->state = SYS_STATEMACH_ERROR;
467  pSystemState->substate = SYS_IMD_INITIALIZATION_ERROR;
468  }
469  }
470  break;
471  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_IMD) {
472  imdInitialized = IMD_GetInitializationState();
473  if (imdInitialized == true) {
474  pSystemState->timer = SYS_FSM_SHORT_TIME;
475  pSystemState->state = SYS_STATEMACH_INITIALIZE_BMS;
476  pSystemState->substate = SYS_ENTRY;
477  break;
478  } else {
479  if (pSystemState->initializationTimeout >
481  pSystemState->timer = SYS_FSM_SHORT_TIME;
482  pSystemState->state = SYS_STATEMACH_ERROR;
483  pSystemState->substate = SYS_IMD_INITIALIZATION_ERROR;
484  break;
485  }
486  pSystemState->timer = SYS_FSM_SHORT_TIME;
487  pSystemState->initializationTimeout++;
488  break;
489  }
490  } else {
491  FAS_ASSERT(FAS_TRAP); /* substate does not exist in this state */
492  }
493  break;
494 
495  /****************************INITIALIZE BMS*************************************/
497  SYS_SAVELASTSTATES(pSystemState);
498 
499  if (pSystemState->substate == SYS_ENTRY) {
501  pSystemState->timer = SYS_FSM_SHORT_TIME;
502  pSystemState->substate = SYS_WAIT_INITIALIZATION_BMS;
503  pSystemState->initializationTimeout = 0;
504  break;
505  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BMS) {
506  bmsState = BMS_GetInitializationState();
507  if (bmsState == STD_OK) {
508  pSystemState->timer = SYS_FSM_SHORT_TIME;
509  pSystemState->state = SYS_STATEMACH_RUNNING;
510  pSystemState->substate = SYS_ENTRY;
511  break;
512  } else {
513  if (pSystemState->initializationTimeout >
515  pSystemState->timer = SYS_FSM_SHORT_TIME;
516  pSystemState->state = SYS_STATEMACH_ERROR;
517  pSystemState->substate = SYS_BMS_INITIALIZATION_ERROR;
518  break;
519  }
520  pSystemState->timer = SYS_FSM_SHORT_TIME;
521  pSystemState->initializationTimeout++;
522  break;
523  }
524  } else {
525  FAS_ASSERT(FAS_TRAP); /* substate does not exist in this state */
526  }
527  break;
528 
529  /****************************RUNNING*************************************/
531  SYS_SAVELASTSTATES(pSystemState);
532  pSystemState->timer = SYS_FSM_LONG_TIME;
533  break;
534 
535  /****************************ERROR*************************************/
536  case SYS_STATEMACH_ERROR:
537  SYS_SAVELASTSTATES(pSystemState);
538  pSystemState->timer = SYS_FSM_LONG_TIME;
539  break;
540  /***************************DEFAULT CASE*************************************/
541  default:
542  /* invalid state */
544  break;
545  }
546  return ranStateMachine;
547 }
548 
549 /**
550  * @brief transfers the current state request to the state machine.
551  *
552  * This function takes the current state request from #sys_state and transfers it to the state machine.
553  * It resets the value from #sys_state to #SYS_STATE_NO_REQUEST
554  *
555  * @return retVal current state request, taken from #SYS_STATE_REQUEST_e
556  *
557  */
560 
562  retval = sys_state.stateRequest;
565 
566  return (retval);
567 }
568 
571 
573  retVal = SYS_CheckStateRequest(stateRequest);
574 
575  if (retVal == SYS_OK) {
576  sys_state.stateRequest = stateRequest;
577  }
579 
580  return (retVal);
581 }
582 
583 /**
584  * @brief checks the state requests that are made.
585  *
586  * This function checks the validity of the state requests.
587  * The results of the checked is returned immediately.
588  *
589  * @param stateRequest state request to be checked
590  *
591  * @return result of the state request that was made, taken from SYS_RETURN_TYPE_e
592  */
595  if (stateRequest == SYS_STATE_ERROR_REQUEST) {
596  retval = SYS_OK;
597  } else {
599  /* init only allowed from the uninitialized state */
600  if (stateRequest == SYS_STATE_INITIALIZATION_REQUEST) {
602  retval = SYS_OK;
603  } else {
604  retval = SYS_ALREADY_INITIALIZED;
605  }
606  } else {
607  retval = SYS_ILLEGAL_REQUEST;
608  }
609  } else {
610  retval = SYS_REQUEST_PENDING;
611  }
612  }
613  return retval;
614 }
615 
616 /*========== Extern Function Implementations ================================*/
617 
618 extern void SYS_GeneralMacroBist(void) {
619  const uint8_t dummy[GEN_REPEAT_MAXIMUM_REPETITIONS] = {
621  for (uint8_t i = 0u; i < GEN_REPEAT_MAXIMUM_REPETITIONS; i++) {
623  }
624 }
625 
627  FAS_ASSERT(pSystemState != NULL_PTR);
628  bool earlyExit = false;
629  STD_RETURN_TYPE_e returnValue = STD_OK;
630 
631  /* Check multiple calls of function */
632  if (SYS_MULTIPLE_CALLS_YES == SYS_CheckMultipleCalls(pSystemState)) {
633  returnValue = STD_NOT_OK;
634  earlyExit = true;
635  }
636 
637  if (earlyExit == false) {
638  if (pSystemState->timer > 0u) {
639  if ((--pSystemState->timer) > 0u) {
640  pSystemState->triggerEntry--;
641  returnValue = STD_OK;
642  earlyExit = true;
643  }
644  }
645  }
646 
647  if (earlyExit == false) {
648  SYS_RunStateMachine(pSystemState);
649  pSystemState->triggerEntry--;
650  }
651  return returnValue;
652 }
653 
654 /*========== Externalized Static Function Implementations (Unit Test) =======*/
655 #ifdef UNITY_UNIT_TEST
656 #endif
void ALGO_UnlockInitialization(void)
Calling this function sets a signal that lets ALGO_Initialization() know that the initialization has ...
Definition: algorithm.c:110
Headers for the driver for the storage in the EEPROM memory.
Header for the driver for balancing.
STD_RETURN_TYPE_e BAL_GetInitializationState(void)
gets the initialization state.
BAL_RETURN_TYPE_e
Definition: bal.h:115
@ BAL_ERROR
Definition: bal.h:122
@ BAL_OK
Definition: bal.h:116
@ BAL_STATE_GLOBAL_ENABLE_REQUEST
Definition: bal.h:108
@ BAL_STATE_INIT_REQUEST
Definition: bal.h:103
@ BAL_STATE_GLOBAL_DISABLE_REQUEST
Definition: bal.h:107
BAL_RETURN_TYPE_e BAL_SetStateRequest(BAL_STATE_REQUEST_e stateRequest)
sets the current state request of the state variable bal_state.
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_BALANCING_DEFAULT_INACTIVE
Defines whether balancing shall be available or not.
#define BS_CURRENT_SENSOR_PRESENT
BMS_RETURN_TYPE_e BMS_SetStateRequest(BMS_STATE_REQUEST_e statereq)
sets the current state request of the state variable bms_state.
Definition: bms.c:811
STD_RETURN_TYPE_e BMS_GetInitializationState(void)
Gets the initialization state.
Definition: bms.c:803
bms driver header
@ BMS_STATE_INIT_REQUEST
Definition: bms.h:164
bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber)
get flag if CC message from current sensor is received.
Definition: can.c:1019
bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber)
get flag if EC message from current sensor is received
Definition: can.c:1024
bool CAN_IsCurrentSensorPresent(uint8_t stringNumber)
set flag for presence of current sensor.
Definition: can.c:1014
void CAN_Initialize(void)
Enables the CAN transceiver.. This function sets th pins to enable the CAN transceiver....
Definition: can.c:910
void CAN_EnablePeriodic(bool command)
Enables periodic sending per CAN. This is used to prevent sending uninitialized data per CAN (e....
Definition: can.c:1006
Header for the driver for the CAN module.
Headers for the driver for the contactors.
void DATA_ExecuteDataBist(void)
Executes a built-in self-test for the database module.
Definition: database.c:363
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diagId, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
Definition: diag.c:246
Diagnosis driver header.
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:268
@ DIAG_STRING
Definition: diag_cfg.h:281
@ DIAG_ID_DEEP_DISCHARGE_DETECTED
Definition: diag_cfg.h:229
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:255
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:129
FRAM_RETURN_TYPE_e FRAM_ReadData(FRAM_BLOCK_ID_e blockId)
Reads a variable from the FRAM.
Definition: fram.c:211
Header for the driver for the FRAM module.
FRAM_DEEP_DISCHARGE_FLAG_s fram_deepDischargeFlags
Definition: fram_cfg.c:77
@ FRAM_BLOCK_ID_DEEP_DISCHARGE_FLAG
Definition: fram_cfg.h:108
Definition of foxBMS standard types.
STD_RETURN_TYPE_e
Definition: fstd_types.h:82
@ STD_NOT_OK
Definition: fstd_types.h:84
@ STD_OK
Definition: fstd_types.h:83
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
General macros and definitions for the whole platform.
#define GEN_REPEAT_U(x, n)
Macro that helps to generate a series of literals (for array initializers).
Definition: general.h:250
#define GEN_STRIP(x)
Definition: general.h:261
#define GEN_REPEAT_MAXIMUM_REPETITIONS
Definition: general.h:225
bool IMD_GetInitializationState(void)
Gets the initialization state.
Definition: imd.c:524
IMD_RETURN_TYPE_e IMD_RequestInitialization(void)
Request initialization of IMD state machine.
Definition: imd.c:512
API header for the insulation monitoring device.
@ IMD_REQUEST_OK
Definition: imd.h:78
ILCK_RETURN_TYPE_e ILCK_SetStateRequest(ILCK_STATE_REQUEST_e statereq)
sets the current state request of the state variable ilck_state.
Definition: interlock.c:254
Headers for the driver for the interlock.
@ ILCK_STATE_INITIALIZATION_REQUEST
Definition: interlock.h:86
STD_RETURN_TYPE_e MEAS_StartMeasurement(void)
Makes the initialization request to the AFE state machine.
Definition: meas.c:117
bool MEAS_IsFirstMeasurementCycleFinished(void)
Checks if the first AFE measurement cycle was made.
Definition: meas.c:113
Headers for the driver for the measurements needed by the BMS (e.g., I,V,T).
Declaration of the OS wrapper interface.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:154
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:150
SBC_STATEMACHINE_e SBC_GetState(SBC_STATE_s *pInstance)
gets the current state of passed state variable
Definition: sbc.c:269
SBC_STATE_s sbc_stateMcuSupervisor
Definition: sbc.c:78
SBC_RETURN_TYPE_e SBC_SetStateRequest(SBC_STATE_s *pInstance, SBC_STATE_REQUEST_e stateRequest)
sets the current state request of passed state variable
Definition: sbc.c:253
Header for the driver for the SBC module.
SBC_STATEMACHINE_e
Definition: sbc.h:133
@ SBC_STATEMACHINE_RUNNING
Definition: sbc.h:137
@ SBC_STATEMACHINE_UNDEFINED
Definition: sbc.h:139
@ SBC_STATE_INIT_REQUEST
Definition: sbc.h:111
void SOF_Init(void)
initializes the area for SOF (where derating starts and is fully active).
Header for SOX module, responsible for current derating calculation.
void SE_InitializeSoe(bool ec_present, uint8_t stringNumber)
Wrapper for algorithm specific SOE initialization.
void SE_InitializeSoc(bool ccPresent, uint8_t stringNumber)
Wrapper for algorithm specific SOC initialization.
void SE_InitializeSoh(uint8_t stringNumber)
Wrapper for algorithm specific SOH initialization.
Header for state-estimation module responsible for the estimation of state-of-charge (SOC),...
bool deepDischargeFlag[BS_NR_OF_STRINGS]
Definition: fram_cfg.h:159
uint16_t timer
Definition: sys.h:171
uint16_t initializationTimeout
Definition: sys.h:178
uint32_t illegalRequestsCounter
Definition: sys.h:177
SYS_STATE_REQUEST_e stateRequest
Definition: sys.h:172
SYS_STATEMACH_SUB_e substate
Definition: sys.h:174
SYS_STATEMACH_e state
Definition: sys.h:173
uint8_t triggerEntry
Definition: sys.h:179
static SYS_STATE_REQUEST_e SYS_TransferStateRequest(void)
transfers the current state request to the state machine.
Definition: sys.c:558
SYS_CHECK_MULTIPLE_CALLS_e
Definition: sys.c:92
@ SYS_MULTIPLE_CALLS_YES
Definition: sys.c:94
@ SYS_MULTIPLE_CALLS_NO
Definition: sys.c:93
#define SYS_SAVELASTSTATES(x)
Definition: sys.c:80
#define SYS_BIST_GENERAL_MAGIC_NUMBER
Definition: sys.c:85
SYS_RETURN_TYPE_e SYS_SetStateRequest(SYS_STATE_REQUEST_e stateRequest)
sets the current state request of the state variable sys_state.
Definition: sys.c:569
static STD_RETURN_TYPE_e SYS_RunStateMachine(SYS_STATE_s *pSystemState)
Defines the state transitions.
Definition: sys.c:155
static SYS_RETURN_TYPE_e SYS_CheckStateRequest(SYS_STATE_REQUEST_e stateRequest)
checks the state requests that are made.
Definition: sys.c:593
SYS_STATE_s sys_state
Definition: sys.c:98
STD_RETURN_TYPE_e SYS_Trigger(SYS_STATE_s *pSystemState)
tick function, call this to advance the state machine
Definition: sys.c:626
void SYS_GeneralMacroBist(void)
Definition: sys.c:618
static SYS_CHECK_MULTIPLE_CALLS_e SYS_CheckMultipleCalls(SYS_STATE_s *pSystemState)
check for multiple calls of state machine trigger function
Definition: sys.c:142
Sys driver header.
@ SYS_BAL_INITIALIZATION_ERROR
Definition: sys.h:141
@ SYS_WAIT_FIRST_MEASUREMENT_CYCLE
Definition: sys.h:137
@ SYS_WAIT_INITIALIZATION_IMD
Definition: sys.h:135
@ SYS_SBC_INITIALIZATION_ERROR
Definition: sys.h:139
@ SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE
Definition: sys.h:134
@ SYS_BMS_INITIALIZATION_ERROR
Definition: sys.h:144
@ SYS_WAIT_INITIALIZATION_BMS
Definition: sys.h:136
@ SYS_WAIT_INITIALIZATION_SBC
Definition: sys.h:130
@ SYS_WAIT_INITIALIZATION_BAL
Definition: sys.h:133
@ SYS_CURRENT_SENSOR_PRESENCE_ERROR
Definition: sys.h:146
@ SYS_MEAS_INITIALIZATION_ERROR
Definition: sys.h:145
@ SYS_WAIT_CURRENT_SENSOR_PRESENCE
Definition: sys.h:138
@ SYS_IMD_INITIALIZATION_ERROR
Definition: sys.h:143
@ SYS_ENTRY
Definition: sys.h:127
SYS_RETURN_TYPE_e
Definition: sys.h:157
@ SYS_OK
Definition: sys.h:158
@ SYS_REQUEST_PENDING
Definition: sys.h:160
@ SYS_ALREADY_INITIALIZED
Definition: sys.h:162
@ SYS_ILLEGAL_REQUEST
Definition: sys.h:161
SYS_STATE_REQUEST_e
Definition: sys.h:150
@ SYS_STATE_INITIALIZATION_REQUEST
Definition: sys.h:151
@ SYS_STATE_NO_REQUEST
Definition: sys.h:153
@ SYS_STATE_ERROR_REQUEST
Definition: sys.h:152
@ SYS_STATEMACH_INITIALIZE_CAN
Definition: sys.h:112
@ SYS_STATEMACH_SYSTEM_BIST
Definition: sys.h:109
@ SYS_STATEMACH_INITIALIZE_SBC
Definition: sys.h:111
@ SYS_STATEMACH_UNINITIALIZED
Definition: sys.h:107
@ SYS_STATEMACH_INITIALIZE_BALANCING
Definition: sys.h:115
@ SYS_STATEMACH_INITIALIZATION
Definition: sys.h:108
@ SYS_STATEMACH_INITIALIZE_IMD
Definition: sys.h:121
@ SYS_STATEMACH_INITIALIZE_MISC
Definition: sys.h:119
@ SYS_STATEMACH_INITIALIZED
Definition: sys.h:110
@ SYS_STATEMACH_RUNNING
Definition: sys.h:117
@ SYS_STATEMACH_ERROR
Definition: sys.h:122
@ SYS_STATEMACH_FIRST_MEASUREMENT_CYCLE
Definition: sys.h:118
@ SYS_STATEMACH_INITIALIZE_BMS
Definition: sys.h:116
@ SYS_STATEMACH_CHECK_CURRENT_SENSOR_PRESENCE
Definition: sys.h:120
@ SYS_STATEMACH_INITIALIZE_INTERLOCK
Definition: sys.h:113
void SYS_SendBootMessage(void)
Function to send out boot message with SW version.
Definition: sys_cfg.c:74
#define SYS_FSM_MEDIUM_TIME
Definition: sys_cfg.h:82
#define SYS_STATEMACH_BAL_INITIALIZATION_TIMEOUT_MS
Definition: sys_cfg.h:100
#define SYS_STATEMACH_INITIALIZATION_TIMEOUT_MS
Definition: sys_cfg.h:94
#define SYS_FSM_LONG_TIME
Definition: sys_cfg.h:88
#define SYS_STATEMACHINE_SBC_INIT_TIMEOUT_MS
Definition: sys_cfg.h:103
#define SYS_STATEMACH_INITIALIZATION_REQUEST_RETRY_COUNTER
Definition: sys_cfg.h:91
#define SYS_STATEMACH_IMD_INITIALIZATION_TIMEOUT_MS
Definition: sys_cfg.h:97
#define SYS_TASK_CYCLE_CONTEXT_MS
Definition: sys_cfg.h:70
#define SYS_FSM_SHORT_TIME
Definition: sys_cfg.h:76