foxBMS  1.0.0
The foxBMS Battery Management System API Documentation
sys.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
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 2021-03-24 (date of last update)
47  * @ingroup ENGINE
48  * @prefix SYS
49  *
50  * @brief Sys driver implementation
51  */
52 
53 /*========== Includes =======================================================*/
54 #include "sys.h"
55 
56 #include "algorithm.h"
57 #include "bal.h"
58 #include "bms.h"
59 #include "can.h"
60 #include "contactor.h"
61 #include "diag.h"
62 #include "fram.h"
63 #include "imd.h"
64 #include "interlock.h"
65 #include "meas.h"
66 #include "os.h"
67 #include "sbc.h"
68 #include "sof.h"
69 #include "state_estimation.h"
70 
71 /*========== Macros and Definitions =========================================*/
72 
73 /** Saves the last state and the last substate */
74 #define SYS_SAVELASTSTATES(x) \
75  (x)->lastState = (x)->state; \
76  (x)->lastSubstate = (x)->substate
77 
78 /*========== Static Constant and Variable Definitions =======================*/
79 
80 /*========== Extern Constant and Variable Definitions =======================*/
81 
82 /** Symbolic names to check for multiple calls of #SYS_Trigger() */
84  SYS_MULTIPLE_CALLS_NO, /*!< no multiple calls, OK */
85  SYS_MULTIPLE_CALLS_YES, /*!< multiple calls, not OK */
87 
88 /** contains the state of the contactor state machine */
90  .timer = 0,
91  .triggerEntry = 0,
92  .stateRequest = SYS_STATE_NO_REQUEST,
94  .substate = SYS_ENTRY,
95  .lastState = SYS_STATEMACH_UNINITIALIZED,
96  .lastSubstate = SYS_ENTRY,
97  .illegalRequestsCounter = 0,
98  .initializationTimeout = 0,
99 };
100 
101 /*========== Static Function Prototypes =====================================*/
102 /**
103  * @brief check for multiple calls of state machine trigger function
104  * @details The trigger function is not reentrant, which means it cannot
105  * be called multiple times. This functions increments the
106  * triggerEntry counter once and must be called each time the
107  * trigger function is called. If triggerEntry is greater than
108  * one, there were multiple calls. For this function to work,
109  * triggerEntry must be decremented each time the trigger function
110  * is called, even if no processing do because the timer is
111  * non-zero.
112  * @param pSystemState state of the fake state machine
113  * @return #SYS_MULTIPLE_CALLS_YES if there were multiple calls,
114  * #SYS_MULTIPLE_CALLS_NO otherwise
115  */
117 
118 /**
119  * @brief Sets the next state, the next substate and the timer value
120  * of the state variable.
121  * @param pSystemState state of the example state machine
122  * @param nextState state to be transferred into
123  * @param nextSubstate substate to be transferred into
124  * @param idleTime wait time for the state machine
125  */
126 static void SYS_SetState(
127  SYS_STATE_s *pSystemState,
128  SYS_FSM_STATES_e nextState,
129  SYS_FSM_SUBSTATES_e nextSubstate,
130  uint16_t idleTime);
131 
132 /**
133  * @brief Sets the next substate and the timer value
134  * of the state variable.
135  * @param pSystemState state of the example state machine
136  * @param nextSubstate substate to be transferred into
137  * @param idleTime wait time for the state machine
138  */
139 static void SYS_SetSubstate(SYS_STATE_s *pSystemState, SYS_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime);
140 
141 /**
142  * @brief Defines the state transitions
143  * @details This function contains the implementation of the state
144  * machine, i.e., the sequence of states and substates.
145  * It is called by the trigger function every time
146  * the state machine timer has a non-zero value.
147  * @param pSystemState state of the example state machine
148  * @return TODO
149  */
151 
154 
155 /*========== Static Function Implementations ================================*/
157  FAS_ASSERT(pSystemState != NULL_PTR);
160  if (pSystemState->triggerEntry == 0u) {
161  pSystemState->triggerEntry++;
162  } else {
163  multipleCalls = SYS_MULTIPLE_CALLS_YES;
164  }
166  return multipleCalls;
167 }
168 
169 #pragma diag_push
170 #pragma diag_suppress 179
171 #pragma WEAK(SYS_SetState)
172 static void SYS_SetState(
173  SYS_STATE_s *pSystemState,
174  SYS_FSM_STATES_e nextState,
175  SYS_FSM_SUBSTATES_e nextSubstate,
176  uint16_t idleTime) {
177  FAS_ASSERT(pSystemState != NULL_PTR);
178 
179  pSystemState->timer = idleTime;
180 }
181 #pragma diag_pop
182 
183 #pragma diag_push
184 #pragma diag_suppress 179
185 #pragma WEAK(SYS_SetSubstate)
186 static void SYS_SetSubstate(SYS_STATE_s *pSystemState, SYS_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime) {
187  FAS_ASSERT(pSystemState != NULL_PTR);
188 }
189 #pragma diag_push
190 
192  STD_RETURN_TYPE_e ranStateMachine = STD_OK;
193 
197  STD_RETURN_TYPE_e balancingInitializationState = STD_OK;
198  BAL_RETURN_TYPE_e balancingGlobalEnableState = BAL_ERROR;
199  STD_RETURN_TYPE_e bmsState = STD_NOT_OK;
200 
201  switch (pSystemState->state) {
202  /****************************UNINITIALIZED***********************************/
204  /* waiting for Initialization Request */
205  stateRequest = SYS_TransferStateRequest();
206  if (stateRequest == SYS_STATE_INIT_REQUEST) {
207  SYS_SAVELASTSTATES(pSystemState);
208  pSystemState->timer = SYS_FSM_SHORT_TIME;
209  pSystemState->state = SYS_STATEMACH_INITIALIZATION;
210  pSystemState->substate = SYS_ENTRY;
211  } else if (stateRequest == SYS_STATE_NO_REQUEST) {
212  /* no actual request pending */
213  } else {
214  pSystemState->illegalRequestsCounter++; /* illegal request pending */
215  }
216  break;
217  /****************************INITIALIZATION**********************************/
219 
220  SYS_SAVELASTSTATES(pSystemState);
221  /* Initializations done here */
223  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
224  if (fram_deepDischargeFlags.deepDischargeFlag[stringNumber] == true) {
226  }
227  }
228 
229  pSystemState->timer = SYS_FSM_SHORT_TIME;
230  pSystemState->state = SYS_STATEMACH_INITIALIZE_SBC;
231  pSystemState->substate = SYS_ENTRY;
232  break;
233 
234  /**************************** INITIALIZE SBC *************************************/
236  SYS_SAVELASTSTATES(pSystemState);
237 
238  if (pSystemState->substate == SYS_ENTRY) {
240  pSystemState->timer = SYS_FSM_SHORT_TIME;
241  pSystemState->substate = SYS_WAIT_INITIALIZATION_SBC;
242  pSystemState->initializationTimeout = 0;
243  break;
244  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_SBC) {
246  if (sbcState == SBC_STATEMACHINE_RUNNING) {
247  pSystemState->timer = SYS_FSM_SHORT_TIME;
248  pSystemState->state = SYS_STATEMACH_INITIALIZED;
249  pSystemState->substate = SYS_ENTRY;
250  break;
251  } else {
252  if (pSystemState->initializationTimeout >
254  pSystemState->timer = SYS_FSM_SHORT_TIME;
255  pSystemState->state = SYS_STATEMACH_ERROR;
256  pSystemState->substate = SYS_SBC_INIT_ERROR;
257  break;
258  }
259  pSystemState->timer = SYS_FSM_SHORT_TIME;
260  pSystemState->initializationTimeout++;
261  break;
262  }
263  }
264  break;
265 
266  /****************************INITIALIZED*************************************/
268  SYS_SAVELASTSTATES(pSystemState);
269  /* Send CAN boot message directly on CAN */
271 
272  pSystemState->timer = SYS_FSM_SHORT_TIME;
274  pSystemState->substate = SYS_ENTRY;
275  break;
276 
277  /****************************INITIALIZE INTERLOCK*************************************/
279  SYS_SAVELASTSTATES(pSystemState);
280 
281  if (pSystemState->substate == SYS_ENTRY) {
283  pSystemState->timer = SYS_FSM_SHORT_TIME;
285  pSystemState->initializationTimeout = 0;
286  break;
287  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_INTERLOCK) {
288  interlockState = ILCK_GetState();
289  if (interlockState == ILCK_STATEMACH_WAIT_FIRST_REQUEST) {
291  pSystemState->timer = SYS_FSM_SHORT_TIME;
293  pSystemState->substate = SYS_ENTRY;
294  break;
295  } else {
296  if (pSystemState->initializationTimeout >
298  pSystemState->timer = SYS_FSM_SHORT_TIME;
299  pSystemState->state = SYS_STATEMACH_ERROR;
300  pSystemState->substate = SYS_ILCK_INIT_ERROR;
301  break;
302  }
303  pSystemState->timer = SYS_FSM_SHORT_TIME;
304  pSystemState->initializationTimeout++;
305  break;
306  }
307  }
308  break;
309 
310  /****************************INITIALIZE CONTACTORS*************************************/
311  /* TODO: check if necessary and add */
312 
313  /****************************INITIALIZE BALANCING*************************************/
315  SYS_SAVELASTSTATES(pSystemState);
316  if (pSystemState->substate == SYS_ENTRY) {
318  pSystemState->timer = SYS_FSM_SHORT_TIME;
319  pSystemState->substate = SYS_WAIT_INITIALIZATION_BAL;
320  pSystemState->initializationTimeout = 0;
321  break;
322  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BAL) {
323  balancingInitializationState = BAL_GetInitializationState();
324  if (balancingInitializationState == STD_OK) {
325  pSystemState->timer = SYS_FSM_SHORT_TIME;
327  break;
328  } else {
329  if (pSystemState->initializationTimeout >
331  pSystemState->timer = SYS_FSM_SHORT_TIME;
332  pSystemState->state = SYS_STATEMACH_ERROR;
333  pSystemState->substate = SYS_BAL_INIT_ERROR;
334  break;
335  }
336  pSystemState->timer = SYS_FSM_SHORT_TIME;
337  pSystemState->initializationTimeout++;
338  break;
339  }
340  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE) {
341  if (BALANCING_DEFAULT_INACTIVE == true) {
342  balancingGlobalEnableState = BAL_SetStateRequest(BAL_STATE_GLOBAL_DISABLE_REQUEST);
343  } else {
344  balancingGlobalEnableState = BAL_SetStateRequest(BAL_STATE_GLOBAL_ENABLE_REQUEST);
345  }
346  if (balancingGlobalEnableState == BAL_OK) {
347  pSystemState->timer = SYS_FSM_SHORT_TIME;
349  pSystemState->substate = SYS_ENTRY;
350  break;
351  } else {
352  if (pSystemState->initializationTimeout >
354  pSystemState->timer = SYS_FSM_SHORT_TIME;
355  pSystemState->state = SYS_STATEMACH_ERROR;
356  pSystemState->substate = SYS_BAL_INIT_ERROR;
357  break;
358  }
359  pSystemState->timer = SYS_FSM_SHORT_TIME;
360  pSystemState->initializationTimeout++;
361  break;
362  }
363  }
364  break;
365 
366  /****************************START FIRST MEAS CYCLE**************************/
368  SYS_SAVELASTSTATES(pSystemState);
369  if (pSystemState->substate == SYS_ENTRY) {
371  pSystemState->initializationTimeout = 0;
373  } else if (pSystemState->substate == SYS_WAIT_FIRST_MEASUREMENT_CYCLE) {
374  if (MEAS_IsFirstMeasurementCycleFinished() == true) {
375  /* allow initialization of algorithm module */
377  /* MEAS_RequestOpenWireCheck(); */ /*TODO: check with strings */
378  pSystemState->timer = SYS_FSM_SHORT_TIME;
379  if (CURRENT_SENSOR_PRESENT == true) {
381  } else {
382  pSystemState->state = SYS_STATEMACH_INITIALIZE_MISC;
383  }
384  pSystemState->substate = SYS_ENTRY;
385  break;
386  } else {
387  if (pSystemState->initializationTimeout >
389  pSystemState->timer = SYS_FSM_SHORT_TIME;
390  pSystemState->state = SYS_STATEMACH_ERROR;
391  pSystemState->substate = SYS_MEAS_INIT_ERROR;
392  break;
393  } else {
394  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
395  pSystemState->initializationTimeout++;
396  break;
397  }
398  }
399  }
400  break;
401 
402  /****************************CHECK CURRENT SENSOR PRESENCE*************************************/
404  SYS_SAVELASTSTATES(pSystemState);
405 
406  if (pSystemState->substate == SYS_ENTRY) {
407  pSystemState->initializationTimeout = 0;
408  CAN_EnablePeriodic(true);
409 #if CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED
410  /* If triggered mode is used, CAN trigger message needs to
411  * be transmitted and current sensor response has to be
412  * received afterwards. This may take some time, therefore
413  * delay has to be increased.
414  */
415  pSystemState->timer = SYS_FSM_LONG_TIME_MS;
416 #else /* CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
417  pSystemState->timer = SYS_FSM_SHORT_TIME;
418 #endif /* CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
420  } else if (pSystemState->substate == SYS_WAIT_CURRENT_SENSOR_PRESENCE) {
421  bool allSensorsPresent = true;
422  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
423  if (CAN_IsCurrentSensorPresent(stringNumber) == true) {
424  if (CAN_IsCurrentSensorCcPresent(stringNumber) == true) {
425  SOC_Init(true, stringNumber);
426  } else {
427  SOC_Init(false, stringNumber);
428  }
429  if (CAN_IsCurrentSensorEcPresent(stringNumber) == true) {
430  SOE_Init(true, stringNumber);
431  } else {
432  SOE_Init(false, stringNumber);
433  }
434  } else {
435  allSensorsPresent = false;
436  }
437  }
438 
439  if (allSensorsPresent == true) {
440  SOF_Init();
441 
442  pSystemState->timer = SYS_FSM_SHORT_TIME;
443  pSystemState->state = SYS_STATEMACH_INITIALIZE_MISC;
444  pSystemState->substate = SYS_ENTRY;
445  break;
446  } else {
447  if (pSystemState->initializationTimeout >
449  pSystemState->timer = SYS_FSM_SHORT_TIME;
450  pSystemState->state = SYS_STATEMACH_ERROR;
452  break;
453  } else {
454  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
455  pSystemState->initializationTimeout++;
456  break;
457  }
458  }
459  }
460  break;
461 
462  /****************************INITIALIZED_MISC*************************************/
464  SYS_SAVELASTSTATES(pSystemState);
465 
466  if (CURRENT_SENSOR_PRESENT == false) {
467  CAN_EnablePeriodic(true);
468  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
469  SOC_Init(false, stringNumber);
470  }
471  }
472 
473  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
474  pSystemState->state = SYS_STATEMACH_INITIALIZE_BMS;
475  pSystemState->substate = SYS_ENTRY;
476  break;
477 
478  /****************************INITIALIZE BMS*************************************/
480  SYS_SAVELASTSTATES(pSystemState);
481 
482  if (pSystemState->substate == SYS_ENTRY) {
484  pSystemState->timer = SYS_FSM_SHORT_TIME;
485  pSystemState->substate = SYS_WAIT_INITIALIZATION_BMS;
486  pSystemState->initializationTimeout = 0;
487  break;
488  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BMS) {
489  bmsState = BMS_GetInitializationState();
490  if (bmsState == STD_OK) {
491  pSystemState->timer = SYS_FSM_SHORT_TIME;
492  pSystemState->state = SYS_STATEMACH_RUNNING;
493  pSystemState->substate = SYS_ENTRY;
494  break;
495  } else {
496  if (pSystemState->initializationTimeout >
498  pSystemState->timer = SYS_FSM_SHORT_TIME;
499  pSystemState->state = SYS_STATEMACH_ERROR;
500  pSystemState->substate = SYS_BMS_INIT_ERROR;
501  break;
502  }
503  pSystemState->timer = SYS_FSM_SHORT_TIME;
504  pSystemState->initializationTimeout++;
505  break;
506  }
507  }
508  break;
509 
510  /****************************RUNNING*************************************/
512  SYS_SAVELASTSTATES(pSystemState);
513  pSystemState->timer = SYS_FSM_LONG_TIME;
514  break;
515 
516  /****************************ERROR*************************************/
517  case SYS_STATEMACH_ERROR:
518  SYS_SAVELASTSTATES(pSystemState);
519  pSystemState->timer = SYS_FSM_LONG_TIME;
520  break;
521  /***************************DEFAULT CASE*************************************/
522  default:
523  /* invalid state */
525  break;
526  }
527  return ranStateMachine;
528 }
529 
530 /**
531  * @brief transfers the current state request to the state machine.
532  *
533  * This function takes the current state request from #sys_state and transfers it to the state machine.
534  * It resets the value from #sys_state to #SYS_STATE_NO_REQUEST
535  *
536  * @return retVal current state request, taken from #SYS_STATE_REQUEST_e
537  *
538  */
541 
543  retval = sys_state.stateRequest;
546 
547  return (retval);
548 }
549 
552 
554  retVal = SYS_CheckStateRequest(stateRequest);
555 
556  if (retVal == SYS_OK) {
557  sys_state.stateRequest = stateRequest;
558  }
560 
561  return (retVal);
562 }
563 
564 /**
565  * @brief checks the state requests that are made.
566  *
567  * This function checks the validity of the state requests.
568  * The results of the checked is returned immediately.
569  *
570  * @param stateRequest state request to be checked
571  *
572  * @return result of the state request that was made, taken from SYS_RETURN_TYPE_e
573  */
576  if (stateRequest == SYS_STATE_ERROR_REQUEST) {
577  retval = SYS_OK;
578  } else {
580  /* init only allowed from the uninitialized state */
581  if (stateRequest == SYS_STATE_INIT_REQUEST) {
583  retval = SYS_OK;
584  } else {
585  retval = SYS_ALREADY_INITIALIZED;
586  }
587  } else {
588  retval = SYS_ILLEGAL_REQUEST;
589  }
590  } else {
591  retval = SYS_REQUEST_PENDING;
592  }
593  }
594  return retval;
595 }
596 
597 /*========== Extern Function Implementations ================================*/
598 
600  FAS_ASSERT(pSystemState != NULL_PTR);
601  bool earlyExit = false;
602  STD_RETURN_TYPE_e returnValue = STD_OK;
603 
604  /* Check multiple calls of function */
605  if (SYS_MULTIPLE_CALLS_YES == SYS_CheckMultipleCalls(pSystemState)) {
606  returnValue = STD_NOT_OK;
607  earlyExit = true;
608  }
609 
610  if (earlyExit == false) {
611  if (pSystemState->timer > 0u) {
612  if ((--pSystemState->timer) > 0u) {
613  pSystemState->triggerEntry--;
614  returnValue = STD_OK;
615  earlyExit = true;
616  }
617  }
618  }
619 
620  if (earlyExit == false) {
621  SYS_RunStateMachine(pSystemState);
622  pSystemState->triggerEntry--;
623  }
624  return returnValue;
625 }
626 
627 /*========== Externalized Static Function Implementations (Unit Test) =======*/
SYS_STATEMACH_ERROR
@ SYS_STATEMACH_ERROR
Definition: sys.h:115
SYS_SetSubstate
static void SYS_SetSubstate(SYS_STATE_s *pSystemState, SYS_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime)
Sets the next substate and the timer value of the state variable.
Definition: sys.c:186
os.h
Implementation of the tasks used by the system, headers.
sys.h
Sys driver header.
SYS_STATEMACH_INITIALIZATION
@ SYS_STATEMACH_INITIALIZATION
Definition: sys.h:103
algorithm.h
Headers for the driver for the storage in the EEPROM memory.
SYS_ILLEGAL_REQUEST
@ SYS_ILLEGAL_REQUEST
Definition: sys.h:152
SYS_WAIT_CURRENT_SENSOR_PRESENCE
@ SYS_WAIT_CURRENT_SENSOR_PRESENCE
Definition: sys.h:130
BALANCING_DEFAULT_INACTIVE
#define BALANCING_DEFAULT_INACTIVE
Definition: battery_system_cfg.h:220
SYS_Trigger
STD_RETURN_TYPE_e SYS_Trigger(SYS_STATE_s *pSystemState)
tick function, call this to advance the state machine
Definition: sys.c:599
SYS_MEAS_INIT_ERROR
@ SYS_MEAS_INIT_ERROR
Definition: sys.h:136
SYS_STATE::timer
uint16_t timer
Definition: sys.h:162
SYS_STATE::triggerEntry
uint8_t triggerEntry
Definition: sys.h:170
FRAM_DEEP_DISCHARGE_FLAG::deepDischargeFlag
bool deepDischargeFlag[BS_NR_OF_STRINGS]
Definition: fram_cfg.h:139
SYS_STATEMACH_INITIALIZE_MISC
@ SYS_STATEMACH_INITIALIZE_MISC
Definition: sys.h:112
CAN_IsCurrentSensorCcPresent
bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber)
get flag if CC message from current sensor is received.
Definition: can.c:398
SYS_BMS_INIT_ERROR
@ SYS_BMS_INIT_ERROR
Definition: sys.h:135
SYS_FSM_SUBSTATES_e
enum SYS_FSM_SUBSTATES SYS_FSM_SUBSTATES_e
STD_RETURN_TYPE_e
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
SYS_TransferStateRequest
static SYS_STATE_REQUEST_e SYS_TransferStateRequest(void)
transfers the current state request to the state machine.
Definition: sys.c:539
SOE_Init
void SOE_Init(bool ec_present, uint8_t stringNumber)
initializes startup state-of-energy (SOE) related values
Definition: soe_counting.c:292
BAL_GetInitializationState
STD_RETURN_TYPE_e BAL_GetInitializationState(void)
gets the initialization state.
Definition: bal_strategy_history.c:300
diag.h
Diagnosis driver header.
SYS_CHECK_MULTIPLE_CALLS
SYS_CHECK_MULTIPLE_CALLS
Definition: sys.c:83
SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE
@ SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE
Definition: sys.h:127
bms.h
bms driver header
sys_state
SYS_STATE_s sys_state
Definition: sys.c:89
SOC_Init
void SOC_Init(bool ccPresent, uint8_t stringNumber)
initializes startup SOC-related values like lookup from nonvolatile ram at startup
Definition: soc_counting.c:226
SYS_STATE_REQUEST_e
enum SYS_STATE_REQUEST SYS_STATE_REQUEST_e
SYS_ILCK_INIT_ERROR
@ SYS_ILCK_INIT_ERROR
Definition: sys.h:134
bal.h
Header for the driver for balancing.
SYS_STATE::substate
SYS_STATEMACH_SUB_e substate
Definition: sys.h:165
SBC_STATE_INIT_REQUEST
@ SBC_STATE_INIT_REQUEST
Definition: sbc.h:109
SYS_FSM_MEDIUM_TIME
#define SYS_FSM_MEDIUM_TIME
Definition: sys_cfg.h:80
SYS_STATE
Definition: sys.h:161
ILCK_STATE_INIT_REQUEST
@ ILCK_STATE_INIT_REQUEST
Definition: interlock.h:88
DIAG_Handler
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diag_id, 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:199
SYS_FSM_SHORT_TIME
#define SYS_FSM_SHORT_TIME
Definition: sys_cfg.h:74
SYS_STATE::state
SYS_STATEMACH_e state
Definition: sys.h:164
SYS_STATE::illegalRequestsCounter
uint32_t illegalRequestsCounter
Definition: sys.h:168
ILCK_STATEMACH_e
ILCK_STATEMACH_e
Definition: interlock.h:65
MEAS_IsFirstMeasurementCycleFinished
bool MEAS_IsFirstMeasurementCycleFinished(void)
Checks if the first MIC measurement cycle was made.
Definition: meas.c:107
SYS_SetState
static void SYS_SetState(SYS_STATE_s *pSystemState, SYS_FSM_STATES_e nextState, SYS_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime)
Sets the next state, the next substate and the timer value of the state variable.
Definition: sys.c:172
SYS_STATEMACH_INITIALIZE_BMS
@ SYS_STATEMACH_INITIALIZE_BMS
Definition: sys.h:109
FAS_ASSERT
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
MEAS_StartMeasurement
STD_RETURN_TYPE_e MEAS_StartMeasurement(void)
Makes the initialization request to the MIC state machine.
Definition: meas.c:111
SBC_STATEMACHINE_RUNNING
@ SBC_STATEMACHINE_RUNNING
Definition: sbc.h:135
SBC_STATEMACHINE_UNDEFINED
@ SBC_STATEMACHINE_UNDEFINED
Definition: sbc.h:137
SYS_STATEMACH_CHECK_CURRENT_SENSOR_PRESENCE
@ SYS_STATEMACH_CHECK_CURRENT_SENSOR_PRESENCE
Definition: sys.h:113
OS_ExitTaskCritical
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os.c:178
SYS_MULTIPLE_CALLS_NO
@ SYS_MULTIPLE_CALLS_NO
Definition: sys.c:84
ILCK_STATEMACH_UNDEFINED
@ ILCK_STATEMACH_UNDEFINED
Definition: interlock.h:73
CURRENT_SENSOR_PRESENT
#define CURRENT_SENSOR_PRESENT
Definition: battery_system_cfg.h:172
DIAG_STRING
@ DIAG_STRING
Definition: diag_cfg.h:215
SBC_GetState
SBC_STATEMACHINE_e SBC_GetState(SBC_STATE_s *pInstance)
gets the current state of passed state variable
Definition: sbc.c:230
SYS_OK
@ SYS_OK
Definition: sys.h:149
SYS_WAIT_FIRST_MEASUREMENT_CYCLE
@ SYS_WAIT_FIRST_MEASUREMENT_CYCLE
Definition: sys.h:129
STD_OK
@ STD_OK
Definition: fstd_types.h:72
SYS_SAVELASTSTATES
#define SYS_SAVELASTSTATES(x)
Definition: sys.c:74
SYS_STATE::initializationTimeout
uint16_t initializationTimeout
Definition: sys.h:169
SYS_FSM_STATES_e
enum SYS_FSM_STATES SYS_FSM_STATES_e
SYS_STATE::stateRequest
SYS_STATE_REQUEST_e stateRequest
Definition: sys.h:163
SYS_TASK_CYCLE_CONTEXT_MS
#define SYS_TASK_CYCLE_CONTEXT_MS
Definition: sys_cfg.h:68
SYS_STATEMACH_BAL_INITIALIZATION_TIMEOUT_MS
#define SYS_STATEMACH_BAL_INITIALIZATION_TIMEOUT_MS
Definition: sys_cfg.h:96
ILCK_STATEMACH_WAIT_FIRST_REQUEST
@ ILCK_STATEMACH_WAIT_FIRST_REQUEST
Definition: interlock.h:70
SYS_STATEMACH_UNINITIALIZED
@ SYS_STATEMACH_UNINITIALIZED
Definition: sys.h:102
OS_EnterTaskCritical
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os.c:174
state_estimation.h
Header for state-estimation module responsible for the estimation of state-of-charge (SOC),...
SYS_STATE_ERROR_REQUEST
@ SYS_STATE_ERROR_REQUEST
Definition: sys.h:143
STD_NOT_OK
@ STD_NOT_OK
Definition: fstd_types.h:73
BAL_STATE_GLOBAL_ENABLE_REQUEST
@ BAL_STATE_GLOBAL_ENABLE_REQUEST
Definition: bal.h:105
fram_deepDischargeFlags
FRAM_DEEP_DISCHARGE_FLAG_s fram_deepDischargeFlags
Definition: fram_cfg.c:76
SYS_STATEMACH_FIRST_MEASUREMENT_CYCLE
@ SYS_STATEMACH_FIRST_MEASUREMENT_CYCLE
Definition: sys.h:111
SYS_ALREADY_INITIALIZED
@ SYS_ALREADY_INITIALIZED
Definition: sys.h:153
FRAM_BLOCK_ID_DEEP_DISCHARGE_FLAG
@ FRAM_BLOCK_ID_DEEP_DISCHARGE_FLAG
Definition: fram_cfg.h:91
sof.h
Header for SOX module, responsible for current derating calculation.
BMS_GetInitializationState
STD_RETURN_TYPE_e BMS_GetInitializationState(void)
Gets the initialization state.
Definition: bms.c:592
BAL_STATE_GLOBAL_DISABLE_REQUEST
@ BAL_STATE_GLOBAL_DISABLE_REQUEST
Definition: bal.h:104
SYS_CheckStateRequest
static SYS_RETURN_TYPE_e SYS_CheckStateRequest(SYS_STATE_REQUEST_e stateRequest)
checks the state requests that are made.
Definition: sys.c:574
contactor.h
Headers for the driver for the contactors.
ILCK_GetState
ILCK_STATEMACH_e ILCK_GetState(void)
gets the current state.
Definition: interlock.c:302
SBC_STATEMACHINE_e
enum SBC_STATEMACHINE SBC_STATEMACHINE_e
ILCK_SetStateRequest
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:306
SYS_STATE_INIT_REQUEST
@ SYS_STATE_INIT_REQUEST
Definition: sys.h:142
DIAG_EVENT_NOT_OK
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:202
SYS_RETURN_TYPE_e
enum SYS_RETURN_TYPE SYS_RETURN_TYPE_e
sbc.h
Header for the driver for the SBC module.
BMS_STATE_INIT_REQUEST
@ BMS_STATE_INIT_REQUEST
Definition: bms.h:156
SOF_Init
void SOF_Init(void)
initializes the area for SOF (where derating starts and is fully active).
Definition: sof.c:342
SYS_WAIT_INITIALIZATION_BMS
@ SYS_WAIT_INITIALIZATION_BMS
Definition: sys.h:128
SYS_WAIT_INITIALIZATION_BAL
@ SYS_WAIT_INITIALIZATION_BAL
Definition: sys.h:126
CAN_IsCurrentSensorPresent
bool CAN_IsCurrentSensorPresent(uint8_t stringNumber)
set flag for presence of current sensor.
Definition: can.c:393
meas.h
Headers for the driver for the measurements needed by the BMS (e.g., I,V,T).
BAL_RETURN_TYPE_e
enum BAL_RETURN_TYPE BAL_RETURN_TYPE_e
sbc_stateMcuSupervisor
SBC_STATE_s sbc_stateMcuSupervisor
Definition: sbc.c:75
SYS_STATEMACH_INITIALIZE_BALANCING
@ SYS_STATEMACH_INITIALIZE_BALANCING
Definition: sys.h:108
SYS_BAL_INIT_ERROR
@ SYS_BAL_INIT_ERROR
Definition: sys.h:133
NULL_PTR
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
SYS_CURRENT_SENSOR_PRESENCE_ERROR
@ SYS_CURRENT_SENSOR_PRESENCE_ERROR
Definition: sys.h:137
SYS_RunStateMachine
static STD_RETURN_TYPE_e SYS_RunStateMachine(SYS_STATE_s *pSystemState)
Defines the state transitions.
Definition: sys.c:191
SYS_STATEMACH_INITIALIZE_SBC
@ SYS_STATEMACH_INITIALIZE_SBC
Definition: sys.h:105
SYS_REQUEST_PENDING
@ SYS_REQUEST_PENDING
Definition: sys.h:151
FRAM_Read
STD_RETURN_TYPE_e FRAM_Read(FRAM_BLOCK_ID_e blockId)
Reads a variable from the FRAM.
Definition: fram.c:160
ALGO_UnlockInitialization
void ALGO_UnlockInitialization(void)
Calling this function sets a signal that lets ALGO_Initialization() know that the initialization has ...
Definition: algorithm.c:107
imd.h
API header for the insulation monitoring device.
SYS_SendBootMessage
void SYS_SendBootMessage(uint8_t directTransmission)
Function to send out boot message with SW version.
Definition: sys_cfg.c:69
BAL_STATE_INIT_REQUEST
@ BAL_STATE_INIT_REQUEST
Definition: bal.h:100
SBC_SetStateRequest
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:214
BAL_SetStateRequest
BAL_RETURN_TYPE_e BAL_SetStateRequest(BAL_STATE_REQUEST_e stateRequest)
sets the current state request of the state variable bal_state.
Definition: bal_strategy_history.c:304
SYS_SetStateRequest
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:550
SYS_MULTIPLE_CALLS_YES
@ SYS_MULTIPLE_CALLS_YES
Definition: sys.c:85
SYS_STATE_NO_REQUEST
@ SYS_STATE_NO_REQUEST
Definition: sys.h:144
can.h
Header for the driver for the CAN module.
CAN_IsCurrentSensorEcPresent
bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber)
get flag if EC message from current sensor is received
Definition: can.c:403
ILCK_STATE_OPEN_REQUEST
@ ILCK_STATE_OPEN_REQUEST
Definition: interlock.h:89
SYS_STATEMACH_INITIALIZE_INTERLOCK
@ SYS_STATEMACH_INITIALIZE_INTERLOCK
Definition: sys.h:106
SYS_STATEMACH_INITIALIZATION_TIMEOUT_MS
#define SYS_STATEMACH_INITIALIZATION_TIMEOUT_MS
Definition: sys_cfg.h:91
SYS_STATEMACHINE_SBC_INIT_TIMEOUT_MS
#define SYS_STATEMACHINE_SBC_INIT_TIMEOUT_MS
Definition: sys_cfg.h:101
SYS_STATEMACH_RUNNING
@ SYS_STATEMACH_RUNNING
Definition: sys.h:110
SYS_CheckMultipleCalls
static SYS_CHECK_MULTIPLE_CALLS_e SYS_CheckMultipleCalls(SYS_STATE_s *pSystemState)
check for multiple calls of state machine trigger function
Definition: sys.c:156
SYS_STATEMACH_INITIALIZED
@ SYS_STATEMACH_INITIALIZED
Definition: sys.h:104
SYS_WAIT_INITIALIZATION_SBC
@ SYS_WAIT_INITIALIZATION_SBC
Definition: sys.h:123
SYS_ENTRY
@ SYS_ENTRY
Definition: sys.h:120
FAS_TRAP
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:108
interlock.h
Headers for the driver for the interlock.
SYS_WAIT_INITIALIZATION_INTERLOCK
@ SYS_WAIT_INITIALIZATION_INTERLOCK
Definition: sys.h:124
SYS_CHECK_MULTIPLE_CALLS_e
enum SYS_CHECK_MULTIPLE_CALLS SYS_CHECK_MULTIPLE_CALLS_e
DIAG_ID_DEEP_DISCHARGE_DETECTED
@ DIAG_ID_DEEP_DISCHARGE_DETECTED
Definition: diag_cfg.h:175
SYS_SBC_INIT_ERROR
@ SYS_SBC_INIT_ERROR
Definition: sys.h:131
BS_NR_OF_STRINGS
#define BS_NR_OF_STRINGS
Definition: battery_system_cfg.h:89
BMS_SetStateRequest
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:600
BAL_OK
@ BAL_OK
Definition: bal.h:113
CAN_EnablePeriodic
void CAN_EnablePeriodic(bool command)
enable/disable the periodic transmit/receive.
Definition: can.c:347
SYS_FSM_LONG_TIME
#define SYS_FSM_LONG_TIME
Definition: sys_cfg.h:86
fram.h
Header for the driver for the FRAM module.
BAL_ERROR
@ BAL_ERROR
Definition: bal.h:119