foxBMS  1.1.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 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 2021-06-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 /** Magic number that is searched by the #SYS_GeneralMacroBist(). */
79 #define SYS_BIST_GENERAL_MAGIC_NUMBER (42u)
80 
81 /*========== Static Constant and Variable Definitions =======================*/
82 
83 /*========== Extern Constant and Variable Definitions =======================*/
84 
85 /** Symbolic names to check for multiple calls of #SYS_Trigger() */
87  SYS_MULTIPLE_CALLS_NO, /*!< no multiple calls, OK */
88  SYS_MULTIPLE_CALLS_YES, /*!< multiple calls, not OK */
90 
91 /** contains the state of the contactor state machine */
93  .timer = 0,
94  .triggerEntry = 0,
95  .stateRequest = SYS_STATE_NO_REQUEST,
97  .substate = SYS_ENTRY,
98  .lastState = SYS_STATEMACH_UNINITIALIZED,
99  .lastSubstate = SYS_ENTRY,
100  .illegalRequestsCounter = 0,
101  .initializationTimeout = 0,
102 };
103 
104 /*========== Static Function Prototypes =====================================*/
105 /**
106  * @brief check for multiple calls of state machine trigger function
107  * @details The trigger function is not reentrant, which means it cannot
108  * be called multiple times. This functions increments the
109  * triggerEntry counter once and must be called each time the
110  * trigger function is called. If triggerEntry is greater than
111  * one, there were multiple calls. For this function to work,
112  * triggerEntry must be decremented each time the trigger function
113  * is called, even if no processing do because the timer is
114  * non-zero.
115  * @param pSystemState state of the fake state machine
116  * @return #SYS_MULTIPLE_CALLS_YES if there were multiple calls,
117  * #SYS_MULTIPLE_CALLS_NO otherwise
118  */
120 
121 /**
122  * @brief Sets the next state, the next substate and the timer value
123  * of the state variable.
124  * @param pSystemState state of the example state machine
125  * @param nextState state to be transferred into
126  * @param nextSubstate substate to be transferred into
127  * @param idleTime wait time for the state machine
128  */
129 static void SYS_SetState(
130  SYS_STATE_s *pSystemState,
131  SYS_FSM_STATES_e nextState,
132  SYS_FSM_SUBSTATES_e nextSubstate,
133  uint16_t idleTime);
134 
135 /**
136  * @brief Sets the next substate and the timer value
137  * of the state variable.
138  * @param pSystemState state of the example state machine
139  * @param nextSubstate substate to be transferred into
140  * @param idleTime wait time for the state machine
141  */
142 static void SYS_SetSubstate(SYS_STATE_s *pSystemState, SYS_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime);
143 
144 /**
145  * @brief Defines the state transitions
146  * @details This function contains the implementation of the state
147  * machine, i.e., the sequence of states and substates.
148  * It is called by the trigger function every time
149  * the state machine timer has a non-zero value.
150  * @param pSystemState state of the example state machine
151  * @return TODO
152  */
154 
157 
158 /*========== Static Function Implementations ================================*/
160  FAS_ASSERT(pSystemState != NULL_PTR);
163  if (pSystemState->triggerEntry == 0u) {
164  pSystemState->triggerEntry++;
165  } else {
166  multipleCalls = SYS_MULTIPLE_CALLS_YES;
167  }
169  return multipleCalls;
170 }
171 
172 #pragma diag_push
173 #pragma diag_suppress 179
174 #pragma WEAK(SYS_SetState)
175 static void SYS_SetState(
176  SYS_STATE_s *pSystemState,
177  SYS_FSM_STATES_e nextState,
178  SYS_FSM_SUBSTATES_e nextSubstate,
179  uint16_t idleTime) {
180  FAS_ASSERT(pSystemState != NULL_PTR);
181 
182  pSystemState->timer = idleTime;
183 }
184 #pragma diag_pop
185 
186 #pragma diag_push
187 #pragma diag_suppress 179
188 #pragma WEAK(SYS_SetSubstate)
189 static void SYS_SetSubstate(SYS_STATE_s *pSystemState, SYS_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime) {
190  FAS_ASSERT(pSystemState != NULL_PTR);
191 }
192 #pragma diag_push
193 
195  STD_RETURN_TYPE_e ranStateMachine = STD_OK;
196 
200  STD_RETURN_TYPE_e balancingInitializationState = STD_OK;
201  BAL_RETURN_TYPE_e balancingGlobalEnableState = BAL_ERROR;
202  STD_RETURN_TYPE_e bmsState = STD_NOT_OK;
203 
204  switch (pSystemState->state) {
205  /****************************UNINITIALIZED***********************************/
207  /* waiting for Initialization Request */
208  stateRequest = SYS_TransferStateRequest();
209  if (stateRequest == SYS_STATE_INIT_REQUEST) {
210  SYS_SAVELASTSTATES(pSystemState);
211  pSystemState->timer = SYS_FSM_SHORT_TIME;
212  pSystemState->state = SYS_STATEMACH_INITIALIZATION;
213  pSystemState->substate = SYS_ENTRY;
214  } else if (stateRequest == SYS_STATE_NO_REQUEST) {
215  /* no actual request pending */
216  } else {
217  pSystemState->illegalRequestsCounter++; /* illegal request pending */
218  }
219  break;
220  /****************************INITIALIZATION**********************************/
222 
223  SYS_SAVELASTSTATES(pSystemState);
224  /* Initializations done here */
226  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
227  if (fram_deepDischargeFlags.deepDischargeFlag[stringNumber] == true) {
229  }
230  }
231 
232  pSystemState->timer = SYS_FSM_SHORT_TIME;
233  pSystemState->state = SYS_STATEMACH_INITIALIZE_SBC;
234  pSystemState->substate = SYS_ENTRY;
235  break;
236 
237  /**************************** INITIALIZE SBC *************************************/
239  SYS_SAVELASTSTATES(pSystemState);
240 
241  if (pSystemState->substate == SYS_ENTRY) {
243  pSystemState->timer = SYS_FSM_SHORT_TIME;
244  pSystemState->substate = SYS_WAIT_INITIALIZATION_SBC;
245  pSystemState->initializationTimeout = 0;
246  break;
247  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_SBC) {
249  if (sbcState == SBC_STATEMACHINE_RUNNING) {
250  pSystemState->timer = SYS_FSM_SHORT_TIME;
251  pSystemState->state = SYS_STATEMACH_SYSTEM_BIST;
252  pSystemState->substate = SYS_ENTRY;
253  break;
254  } else {
255  if (pSystemState->initializationTimeout >
257  pSystemState->timer = SYS_FSM_SHORT_TIME;
258  pSystemState->state = SYS_STATEMACH_ERROR;
259  pSystemState->substate = SYS_SBC_INIT_ERROR;
260  break;
261  }
262  pSystemState->timer = SYS_FSM_SHORT_TIME;
263  pSystemState->initializationTimeout++;
264  break;
265  }
266  }
267  break;
268  /**************************** EXECUTE STARTUP BIST **********************************/
270  SYS_SAVELASTSTATES(pSystemState);
271  /* run BIST functions */
274 
275  pSystemState->timer = SYS_FSM_SHORT_TIME;
276  pSystemState->state = SYS_STATEMACH_INITIALIZED;
277  pSystemState->substate = SYS_ENTRY;
278  break;
279 
280  /****************************INITIALIZED*************************************/
282  SYS_SAVELASTSTATES(pSystemState);
283  /* Send CAN boot message directly on CAN */
285 
286  pSystemState->timer = SYS_FSM_SHORT_TIME;
288  pSystemState->substate = SYS_ENTRY;
289  break;
290 
291  /****************************INITIALIZE INTERLOCK*************************************/
293  SYS_SAVELASTSTATES(pSystemState);
294 
295  if (pSystemState->substate == SYS_ENTRY) {
297  pSystemState->timer = SYS_FSM_SHORT_TIME;
299  pSystemState->initializationTimeout = 0;
300  break;
301  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_INTERLOCK) {
302  interlockState = ILCK_GetState();
303  if (interlockState == ILCK_STATEMACH_WAIT_FIRST_REQUEST) {
305  pSystemState->timer = SYS_FSM_SHORT_TIME;
307  pSystemState->substate = SYS_ENTRY;
308  break;
309  } else {
310  if (pSystemState->initializationTimeout >
312  pSystemState->timer = SYS_FSM_SHORT_TIME;
313  pSystemState->state = SYS_STATEMACH_ERROR;
314  pSystemState->substate = SYS_ILCK_INIT_ERROR;
315  break;
316  }
317  pSystemState->timer = SYS_FSM_SHORT_TIME;
318  pSystemState->initializationTimeout++;
319  break;
320  }
321  }
322  break;
323 
324  /****************************INITIALIZE CONTACTORS*************************************/
325  /* TODO: check if necessary and add */
326 
327  /****************************INITIALIZE BALANCING*************************************/
329  SYS_SAVELASTSTATES(pSystemState);
330  if (pSystemState->substate == SYS_ENTRY) {
332  pSystemState->timer = SYS_FSM_SHORT_TIME;
333  pSystemState->substate = SYS_WAIT_INITIALIZATION_BAL;
334  pSystemState->initializationTimeout = 0;
335  break;
336  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BAL) {
337  balancingInitializationState = BAL_GetInitializationState();
338  if (balancingInitializationState == STD_OK) {
339  pSystemState->timer = SYS_FSM_SHORT_TIME;
341  break;
342  } else {
343  if (pSystemState->initializationTimeout >
345  pSystemState->timer = SYS_FSM_SHORT_TIME;
346  pSystemState->state = SYS_STATEMACH_ERROR;
347  pSystemState->substate = SYS_BAL_INIT_ERROR;
348  break;
349  }
350  pSystemState->timer = SYS_FSM_SHORT_TIME;
351  pSystemState->initializationTimeout++;
352  break;
353  }
354  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE) {
355  if (BALANCING_DEFAULT_INACTIVE == true) {
356  balancingGlobalEnableState = BAL_SetStateRequest(BAL_STATE_GLOBAL_DISABLE_REQUEST);
357  } else {
358  balancingGlobalEnableState = BAL_SetStateRequest(BAL_STATE_GLOBAL_ENABLE_REQUEST);
359  }
360  if (balancingGlobalEnableState == BAL_OK) {
361  pSystemState->timer = SYS_FSM_SHORT_TIME;
363  pSystemState->substate = SYS_ENTRY;
364  break;
365  } else {
366  if (pSystemState->initializationTimeout >
368  pSystemState->timer = SYS_FSM_SHORT_TIME;
369  pSystemState->state = SYS_STATEMACH_ERROR;
370  pSystemState->substate = SYS_BAL_INIT_ERROR;
371  break;
372  }
373  pSystemState->timer = SYS_FSM_SHORT_TIME;
374  pSystemState->initializationTimeout++;
375  break;
376  }
377  }
378  break;
379 
380  /****************************START FIRST MEAS CYCLE**************************/
382  SYS_SAVELASTSTATES(pSystemState);
383  if (pSystemState->substate == SYS_ENTRY) {
385  pSystemState->initializationTimeout = 0;
387  } else if (pSystemState->substate == SYS_WAIT_FIRST_MEASUREMENT_CYCLE) {
388  if (MEAS_IsFirstMeasurementCycleFinished() == true) {
389  /* allow initialization of algorithm module */
391  /* MEAS_RequestOpenWireCheck(); */ /*TODO: check with strings */
392  pSystemState->timer = SYS_FSM_SHORT_TIME;
393  if (CURRENT_SENSOR_PRESENT == true) {
395  } else {
396  pSystemState->state = SYS_STATEMACH_INITIALIZE_MISC;
397  }
398  pSystemState->substate = SYS_ENTRY;
399  break;
400  } else {
401  if (pSystemState->initializationTimeout >
403  pSystemState->timer = SYS_FSM_SHORT_TIME;
404  pSystemState->state = SYS_STATEMACH_ERROR;
405  pSystemState->substate = SYS_MEAS_INIT_ERROR;
406  break;
407  } else {
408  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
409  pSystemState->initializationTimeout++;
410  break;
411  }
412  }
413  }
414  break;
415 
416  /****************************CHECK CURRENT SENSOR PRESENCE*************************************/
418  SYS_SAVELASTSTATES(pSystemState);
419 
420  if (pSystemState->substate == SYS_ENTRY) {
421  pSystemState->initializationTimeout = 0;
422  CAN_EnablePeriodic(true);
423 #if CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED
424  /* If triggered mode is used, CAN trigger message needs to
425  * be transmitted and current sensor response has to be
426  * received afterwards. This may take some time, therefore
427  * delay has to be increased.
428  */
429  pSystemState->timer = SYS_FSM_LONG_TIME_MS;
430 #else /* CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
431  pSystemState->timer = SYS_FSM_LONG_TIME;
432 #endif /* CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
434  } else if (pSystemState->substate == SYS_WAIT_CURRENT_SENSOR_PRESENCE) {
435  bool allSensorsPresent = true;
436  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
437  if (CAN_IsCurrentSensorPresent(stringNumber) == true) {
438  if (CAN_IsCurrentSensorCcPresent(stringNumber) == true) {
439  SE_SocInit(true, stringNumber);
440  } else {
441  SE_SocInit(false, stringNumber);
442  }
443  if (CAN_IsCurrentSensorEcPresent(stringNumber) == true) {
444  SE_SoeInit(true, stringNumber);
445  } else {
446  SE_SoeInit(false, stringNumber);
447  }
448  } else {
449  allSensorsPresent = false;
450  }
451  }
452 
453  if (allSensorsPresent == true) {
454  SOF_Init();
455 
456  pSystemState->timer = SYS_FSM_SHORT_TIME;
457  pSystemState->state = SYS_STATEMACH_INITIALIZE_MISC;
458  pSystemState->substate = SYS_ENTRY;
459  break;
460  } else {
461  if (pSystemState->initializationTimeout >
463  pSystemState->timer = SYS_FSM_SHORT_TIME;
464  pSystemState->state = SYS_STATEMACH_ERROR;
466  break;
467  } else {
468  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
469  pSystemState->initializationTimeout++;
470  break;
471  }
472  }
473  }
474  break;
475 
476  /****************************INITIALIZED_MISC*************************************/
478  SYS_SAVELASTSTATES(pSystemState);
479 
480  if (CURRENT_SENSOR_PRESENT == false) {
481  CAN_EnablePeriodic(true);
482  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
483  SE_SocInit(false, stringNumber);
484  SE_SoeInit(false, stringNumber);
485  }
486  }
487 
488  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
489  pSystemState->state = SYS_STATEMACH_INITIALIZE_BMS;
490  pSystemState->substate = SYS_ENTRY;
491  break;
492 
493  /****************************INITIALIZE BMS*************************************/
495  SYS_SAVELASTSTATES(pSystemState);
496 
497  if (pSystemState->substate == SYS_ENTRY) {
499  pSystemState->timer = SYS_FSM_SHORT_TIME;
500  pSystemState->substate = SYS_WAIT_INITIALIZATION_BMS;
501  pSystemState->initializationTimeout = 0;
502  break;
503  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BMS) {
504  bmsState = BMS_GetInitializationState();
505  if (bmsState == STD_OK) {
506  pSystemState->timer = SYS_FSM_SHORT_TIME;
507  pSystemState->state = SYS_STATEMACH_RUNNING;
508  pSystemState->substate = SYS_ENTRY;
509  break;
510  } else {
511  if (pSystemState->initializationTimeout >
513  pSystemState->timer = SYS_FSM_SHORT_TIME;
514  pSystemState->state = SYS_STATEMACH_ERROR;
515  pSystemState->substate = SYS_BMS_INIT_ERROR;
516  break;
517  }
518  pSystemState->timer = SYS_FSM_SHORT_TIME;
519  pSystemState->initializationTimeout++;
520  break;
521  }
522  }
523  break;
524 
525  /****************************RUNNING*************************************/
527  SYS_SAVELASTSTATES(pSystemState);
528  pSystemState->timer = SYS_FSM_LONG_TIME;
529  break;
530 
531  /****************************ERROR*************************************/
532  case SYS_STATEMACH_ERROR:
533  SYS_SAVELASTSTATES(pSystemState);
534  pSystemState->timer = SYS_FSM_LONG_TIME;
535  break;
536  /***************************DEFAULT CASE*************************************/
537  default:
538  /* invalid state */
540  break;
541  }
542  return ranStateMachine;
543 }
544 
545 /**
546  * @brief transfers the current state request to the state machine.
547  *
548  * This function takes the current state request from #sys_state and transfers it to the state machine.
549  * It resets the value from #sys_state to #SYS_STATE_NO_REQUEST
550  *
551  * @return retVal current state request, taken from #SYS_STATE_REQUEST_e
552  *
553  */
556 
558  retval = sys_state.stateRequest;
561 
562  return (retval);
563 }
564 
567 
569  retVal = SYS_CheckStateRequest(stateRequest);
570 
571  if (retVal == SYS_OK) {
572  sys_state.stateRequest = stateRequest;
573  }
575 
576  return (retVal);
577 }
578 
579 /**
580  * @brief checks the state requests that are made.
581  *
582  * This function checks the validity of the state requests.
583  * The results of the checked is returned immediately.
584  *
585  * @param stateRequest state request to be checked
586  *
587  * @return result of the state request that was made, taken from SYS_RETURN_TYPE_e
588  */
591  if (stateRequest == SYS_STATE_ERROR_REQUEST) {
592  retval = SYS_OK;
593  } else {
595  /* init only allowed from the uninitialized state */
596  if (stateRequest == SYS_STATE_INIT_REQUEST) {
598  retval = SYS_OK;
599  } else {
600  retval = SYS_ALREADY_INITIALIZED;
601  }
602  } else {
603  retval = SYS_ILLEGAL_REQUEST;
604  }
605  } else {
606  retval = SYS_REQUEST_PENDING;
607  }
608  }
609  return retval;
610 }
611 
612 /*========== Extern Function Implementations ================================*/
613 
614 extern void SYS_GeneralMacroBist(void) {
615  const uint8_t dummy[REPEAT_MAXIMUM_REPETITIONS] = {
617  for (uint8_t i = 0u; i < REPEAT_MAXIMUM_REPETITIONS; i++) {
619  }
620 }
621 
623  FAS_ASSERT(pSystemState != NULL_PTR);
624  bool earlyExit = false;
625  STD_RETURN_TYPE_e returnValue = STD_OK;
626 
627  /* Check multiple calls of function */
628  if (SYS_MULTIPLE_CALLS_YES == SYS_CheckMultipleCalls(pSystemState)) {
629  returnValue = STD_NOT_OK;
630  earlyExit = true;
631  }
632 
633  if (earlyExit == false) {
634  if (pSystemState->timer > 0u) {
635  if ((--pSystemState->timer) > 0u) {
636  pSystemState->triggerEntry--;
637  returnValue = STD_OK;
638  earlyExit = true;
639  }
640  }
641  }
642 
643  if (earlyExit == false) {
644  SYS_RunStateMachine(pSystemState);
645  pSystemState->triggerEntry--;
646  }
647  return returnValue;
648 }
649 
650 /*========== Externalized Static Function Implementations (Unit Test) =======*/
void ALGO_UnlockInitialization(void)
Calling this function sets a signal that lets ALGO_Initialization() know that the initialization has ...
Definition: algorithm.c:105
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_ERROR
Definition: bal.h:119
@ BAL_OK
Definition: bal.h:113
BAL_RETURN_TYPE_e BAL_SetStateRequest(BAL_STATE_REQUEST_e stateRequest)
sets the current state request of the state variable bal_state.
@ BAL_STATE_GLOBAL_ENABLE_REQUEST
Definition: bal.h:105
@ BAL_STATE_INIT_REQUEST
Definition: bal.h:100
@ BAL_STATE_GLOBAL_DISABLE_REQUEST
Definition: bal.h:104
enum BAL_RETURN_TYPE BAL_RETURN_TYPE_e
#define BS_NR_OF_STRINGS
#define CURRENT_SENSOR_PRESENT
#define BALANCING_DEFAULT_INACTIVE
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:633
STD_RETURN_TYPE_e BMS_GetInitializationState(void)
Gets the initialization state.
Definition: bms.c:625
bms driver header
@ BMS_STATE_INIT_REQUEST
Definition: bms.h:156
bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber)
get flag if CC message from current sensor is received.
Definition: can.c:425
bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber)
get flag if EC message from current sensor is received
Definition: can.c:430
bool CAN_IsCurrentSensorPresent(uint8_t stringNumber)
set flag for presence of current sensor.
Definition: can.c:420
void CAN_EnablePeriodic(bool command)
enable/disable the periodic transmit/receive.
Definition: can.c:374
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:294
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:226
Diagnosis driver header.
@ DIAG_STRING
Definition: diag_cfg.h:248
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:235
@ DIAG_ID_DEEP_DISCHARGE_DETECTED
Definition: diag_cfg.h:208
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:108
STD_RETURN_TYPE_e FRAM_Read(FRAM_BLOCK_ID_e blockId)
Reads a variable from the FRAM.
Definition: fram.c:160
Header for the driver for the FRAM module.
FRAM_DEEP_DISCHARGE_FLAG_s fram_deepDischargeFlags
Definition: fram_cfg.c:76
@ FRAM_BLOCK_ID_DEEP_DISCHARGE_FLAG
Definition: fram_cfg.h:91
@ STD_NOT_OK
Definition: fstd_types.h:73
@ STD_OK
Definition: fstd_types.h:72
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
#define STRIP(x)
Definition: general.h:268
#define REPEAT_MAXIMUM_REPETITIONS
Definition: general.h:231
#define REPEAT_U(x, n)
Macro that helps to generate a series of literals (for array initializers).
Definition: general.h:256
API header for the insulation monitoring device.
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
ILCK_STATEMACH_e ILCK_GetState(void)
gets the current state.
Definition: interlock.c:302
Headers for the driver for the interlock.
ILCK_STATEMACH_e
Definition: interlock.h:65
@ ILCK_STATEMACH_WAIT_FIRST_REQUEST
Definition: interlock.h:70
@ ILCK_STATEMACH_UNDEFINED
Definition: interlock.h:73
@ ILCK_STATE_OPEN_REQUEST
Definition: interlock.h:89
@ ILCK_STATE_INIT_REQUEST
Definition: interlock.h:88
STD_RETURN_TYPE_e MEAS_StartMeasurement(void)
Makes the initialization request to the MIC state machine.
Definition: meas.c:111
bool MEAS_IsFirstMeasurementCycleFinished(void)
Checks if the first MIC measurement cycle was made.
Definition: meas.c:107
Headers for the driver for the measurements needed by the BMS (e.g., I,V,T).
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os.c:178
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os.c:174
Implementation of the tasks used by the system, headers.
SBC_STATEMACHINE_e SBC_GetState(SBC_STATE_s *pInstance)
gets the current state of passed state variable
Definition: sbc.c:230
SBC_STATE_s sbc_stateMcuSupervisor
Definition: sbc.c:75
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
Header for the driver for the SBC module.
@ SBC_STATEMACHINE_RUNNING
Definition: sbc.h:135
@ SBC_STATEMACHINE_UNDEFINED
Definition: sbc.h:137
@ SBC_STATE_INIT_REQUEST
Definition: sbc.h:109
enum SBC_STATEMACHINE SBC_STATEMACHINE_e
void SOF_Init(void)
initializes the area for SOF (where derating starts and is fully active).
Definition: sof.c:342
Header for SOX module, responsible for current derating calculation.
void SE_SoeInit(bool ec_present, uint8_t stringNumber)
Wrapper for algorithm specific SOE initialization.
void SE_SocInit(bool cc_present, uint8_t stringNumber)
Wrapper for algorithm specific SOC 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:139
Definition: sys.h:162
uint32_t illegalRequestsCounter
Definition: sys.h:169
SYS_STATE_REQUEST_e stateRequest
Definition: sys.h:164
uint8_t triggerEntry
Definition: sys.h:171
uint16_t timer
Definition: sys.h:163
uint16_t initializationTimeout
Definition: sys.h:170
SYS_STATEMACH_SUB_e substate
Definition: sys.h:166
SYS_STATEMACH_e state
Definition: sys.h:165
static SYS_STATE_REQUEST_e SYS_TransferStateRequest(void)
transfers the current state request to the state machine.
Definition: sys.c:554
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:175
#define SYS_SAVELASTSTATES(x)
Definition: sys.c:74
SYS_CHECK_MULTIPLE_CALLS
Definition: sys.c:86
@ SYS_MULTIPLE_CALLS_YES
Definition: sys.c:88
@ SYS_MULTIPLE_CALLS_NO
Definition: sys.c:87
#define SYS_BIST_GENERAL_MAGIC_NUMBER
Definition: sys.c:79
enum SYS_CHECK_MULTIPLE_CALLS SYS_CHECK_MULTIPLE_CALLS_e
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:565
static STD_RETURN_TYPE_e SYS_RunStateMachine(SYS_STATE_s *pSystemState)
Defines the state transitions.
Definition: sys.c:194
static SYS_RETURN_TYPE_e SYS_CheckStateRequest(SYS_STATE_REQUEST_e stateRequest)
checks the state requests that are made.
Definition: sys.c:589
SYS_STATE_s sys_state
Definition: sys.c:92
STD_RETURN_TYPE_e SYS_Trigger(SYS_STATE_s *pSystemState)
tick function, call this to advance the state machine
Definition: sys.c:622
void SYS_GeneralMacroBist(void)
Definition: sys.c:614
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:189
static SYS_CHECK_MULTIPLE_CALLS_e SYS_CheckMultipleCalls(SYS_STATE_s *pSystemState)
check for multiple calls of state machine trigger function
Definition: sys.c:159
Sys driver header.
enum SYS_FSM_STATES SYS_FSM_STATES_e
@ SYS_STATEMACH_SYSTEM_BIST
Definition: sys.h:104
@ SYS_STATEMACH_INITIALIZE_SBC
Definition: sys.h:106
@ SYS_STATEMACH_UNINITIALIZED
Definition: sys.h:102
@ SYS_STATEMACH_INITIALIZE_BALANCING
Definition: sys.h:109
@ SYS_STATEMACH_INITIALIZATION
Definition: sys.h:103
@ SYS_STATEMACH_INITIALIZE_MISC
Definition: sys.h:113
@ SYS_STATEMACH_INITIALIZED
Definition: sys.h:105
@ SYS_STATEMACH_RUNNING
Definition: sys.h:111
@ SYS_STATEMACH_ERROR
Definition: sys.h:116
@ SYS_STATEMACH_FIRST_MEASUREMENT_CYCLE
Definition: sys.h:112
@ SYS_STATEMACH_INITIALIZE_BMS
Definition: sys.h:110
@ SYS_STATEMACH_CHECK_CURRENT_SENSOR_PRESENCE
Definition: sys.h:114
@ SYS_STATEMACH_INITIALIZE_INTERLOCK
Definition: sys.h:107
@ SYS_OK
Definition: sys.h:150
@ SYS_REQUEST_PENDING
Definition: sys.h:152
@ SYS_ALREADY_INITIALIZED
Definition: sys.h:154
@ SYS_ILLEGAL_REQUEST
Definition: sys.h:153
enum SYS_FSM_SUBSTATES SYS_FSM_SUBSTATES_e
enum SYS_RETURN_TYPE SYS_RETURN_TYPE_e
@ SYS_STATE_NO_REQUEST
Definition: sys.h:145
@ SYS_STATE_INIT_REQUEST
Definition: sys.h:143
@ SYS_STATE_ERROR_REQUEST
Definition: sys.h:144
@ SYS_WAIT_FIRST_MEASUREMENT_CYCLE
Definition: sys.h:130
@ SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE
Definition: sys.h:128
@ SYS_BAL_INIT_ERROR
Definition: sys.h:134
@ SYS_ILCK_INIT_ERROR
Definition: sys.h:135
@ SYS_WAIT_INITIALIZATION_BMS
Definition: sys.h:129
@ SYS_SBC_INIT_ERROR
Definition: sys.h:132
@ SYS_WAIT_INITIALIZATION_SBC
Definition: sys.h:124
@ SYS_WAIT_INITIALIZATION_BAL
Definition: sys.h:127
@ SYS_WAIT_INITIALIZATION_INTERLOCK
Definition: sys.h:125
@ SYS_CURRENT_SENSOR_PRESENCE_ERROR
Definition: sys.h:138
@ SYS_MEAS_INIT_ERROR
Definition: sys.h:137
@ SYS_WAIT_CURRENT_SENSOR_PRESENCE
Definition: sys.h:131
@ SYS_BMS_INIT_ERROR
Definition: sys.h:136
@ SYS_ENTRY
Definition: sys.h:121
enum SYS_STATE_REQUEST SYS_STATE_REQUEST_e
void SYS_SendBootMessage(void)
Function to send out boot message with SW version.
Definition: sys_cfg.c:69
#define SYS_FSM_MEDIUM_TIME
Definition: sys_cfg.h:80
#define SYS_STATEMACH_BAL_INITIALIZATION_TIMEOUT_MS
Definition: sys_cfg.h:96
#define SYS_STATEMACH_INITIALIZATION_TIMEOUT_MS
Definition: sys_cfg.h:91
#define SYS_FSM_LONG_TIME
Definition: sys_cfg.h:86
#define SYS_STATEMACHINE_SBC_INIT_TIMEOUT_MS
Definition: sys_cfg.h:101
#define SYS_TASK_CYCLE_CONTEXT_MS
Definition: sys_cfg.h:68
#define SYS_FSM_SHORT_TIME
Definition: sys_cfg.h:74