foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests 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-10-12 (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 
199  STD_RETURN_TYPE_e balancingInitializationState = STD_OK;
200  BAL_RETURN_TYPE_e balancingGlobalEnableState = BAL_ERROR;
201  STD_RETURN_TYPE_e bmsState = STD_NOT_OK;
202 
203  switch (pSystemState->state) {
204  /****************************UNINITIALIZED***********************************/
206  /* waiting for Initialization Request */
207  stateRequest = SYS_TransferStateRequest();
208  if (stateRequest == SYS_STATE_INIT_REQUEST) {
209  SYS_SAVELASTSTATES(pSystemState);
210  pSystemState->timer = SYS_FSM_SHORT_TIME;
211  pSystemState->state = SYS_STATEMACH_INITIALIZATION;
212  pSystemState->substate = SYS_ENTRY;
213  } else if (stateRequest == SYS_STATE_NO_REQUEST) {
214  /* no actual request pending */
215  } else {
216  pSystemState->illegalRequestsCounter++; /* illegal request pending */
217  }
218  break;
219  /****************************INITIALIZATION**********************************/
221 
222  SYS_SAVELASTSTATES(pSystemState);
223  /* Initializations done here */
225  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
226  if (fram_deepDischargeFlags.deepDischargeFlag[stringNumber] == true) {
228  }
229  }
230 
231  pSystemState->timer = SYS_FSM_SHORT_TIME;
232  pSystemState->state = SYS_STATEMACH_INITIALIZE_SBC;
233  pSystemState->substate = SYS_ENTRY;
234  break;
235 
236  /**************************** INITIALIZE SBC *************************************/
238  SYS_SAVELASTSTATES(pSystemState);
239 
240  if (pSystemState->substate == SYS_ENTRY) {
242  pSystemState->timer = SYS_FSM_SHORT_TIME;
243  pSystemState->substate = SYS_WAIT_INITIALIZATION_SBC;
244  pSystemState->initializationTimeout = 0;
245  break;
246  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_SBC) {
248  if (sbcState == SBC_STATEMACHINE_RUNNING) {
249  pSystemState->timer = SYS_FSM_SHORT_TIME;
250  pSystemState->state = SYS_STATEMACH_INITIALIZE_CAN;
251  pSystemState->substate = SYS_ENTRY;
252  break;
253  } else {
254  if (pSystemState->initializationTimeout >
256  pSystemState->timer = SYS_FSM_SHORT_TIME;
257  pSystemState->state = SYS_STATEMACH_ERROR;
258  pSystemState->substate = SYS_SBC_INIT_ERROR;
259  break;
260  }
261  pSystemState->timer = SYS_FSM_SHORT_TIME;
262  pSystemState->initializationTimeout++;
263  break;
264  }
265  }
266  break;
267 
268  /**************************** INITIALIZE CAN TRANSCEIVER ****************************/
270  CAN_Initialize();
271  pSystemState->timer = SYS_FSM_SHORT_TIME;
272  pSystemState->state = SYS_STATEMACH_SYSTEM_BIST;
273  pSystemState->substate = SYS_ENTRY;
274  break;
275 
276  /**************************** EXECUTE STARTUP BIST **********************************/
278  SYS_SAVELASTSTATES(pSystemState);
279  /* run BIST functions */
282 
283  pSystemState->timer = SYS_FSM_SHORT_TIME;
284  pSystemState->state = SYS_STATEMACH_INITIALIZED;
285  pSystemState->substate = SYS_ENTRY;
286  break;
287 
288  /****************************INITIALIZED*************************************/
290  SYS_SAVELASTSTATES(pSystemState);
291  /* Send CAN boot message directly on CAN */
293 
294  pSystemState->timer = SYS_FSM_SHORT_TIME;
296  pSystemState->substate = SYS_ENTRY;
297  break;
298 
299  /****************************INITIALIZE INTERLOCK*************************************/
301  SYS_SAVELASTSTATES(pSystemState);
303  pSystemState->timer = SYS_FSM_SHORT_TIME;
305  pSystemState->substate = SYS_ENTRY;
306  pSystemState->initializationTimeout = 0;
307  break;
308 
309  /****************************INITIALIZE CONTACTORS*************************************/
310  /* TODO: check if necessary and add */
311 
312  /****************************INITIALIZE BALANCING*************************************/
314  SYS_SAVELASTSTATES(pSystemState);
315  if (pSystemState->substate == SYS_ENTRY) {
317  pSystemState->timer = SYS_FSM_SHORT_TIME;
318  pSystemState->substate = SYS_WAIT_INITIALIZATION_BAL;
319  pSystemState->initializationTimeout = 0;
320  break;
321  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BAL) {
322  balancingInitializationState = BAL_GetInitializationState();
323  if (balancingInitializationState == STD_OK) {
324  pSystemState->timer = SYS_FSM_SHORT_TIME;
326  break;
327  } else {
328  if (pSystemState->initializationTimeout >
330  pSystemState->timer = SYS_FSM_SHORT_TIME;
331  pSystemState->state = SYS_STATEMACH_ERROR;
332  pSystemState->substate = SYS_BAL_INIT_ERROR;
333  break;
334  }
335  pSystemState->timer = SYS_FSM_SHORT_TIME;
336  pSystemState->initializationTimeout++;
337  break;
338  }
339  } else if (pSystemState->substate == SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE) {
340  if (BALANCING_DEFAULT_INACTIVE == true) {
341  balancingGlobalEnableState = BAL_SetStateRequest(BAL_STATE_GLOBAL_DISABLE_REQUEST);
342  } else {
343  balancingGlobalEnableState = BAL_SetStateRequest(BAL_STATE_GLOBAL_ENABLE_REQUEST);
344  }
345  if (balancingGlobalEnableState == BAL_OK) {
346  pSystemState->timer = SYS_FSM_SHORT_TIME;
348  pSystemState->substate = SYS_ENTRY;
349  break;
350  } else {
351  if (pSystemState->initializationTimeout >
353  pSystemState->timer = SYS_FSM_SHORT_TIME;
354  pSystemState->state = SYS_STATEMACH_ERROR;
355  pSystemState->substate = SYS_BAL_INIT_ERROR;
356  break;
357  }
358  pSystemState->timer = SYS_FSM_SHORT_TIME;
359  pSystemState->initializationTimeout++;
360  break;
361  }
362  }
363  break;
364 
365  /****************************START FIRST MEAS CYCLE**************************/
367  SYS_SAVELASTSTATES(pSystemState);
368  if (pSystemState->substate == SYS_ENTRY) {
370  pSystemState->initializationTimeout = 0;
372  } else if (pSystemState->substate == SYS_WAIT_FIRST_MEASUREMENT_CYCLE) {
373  if (MEAS_IsFirstMeasurementCycleFinished() == true) {
374  /* allow initialization of algorithm module */
376  /* MEAS_RequestOpenWireCheck(); */ /*TODO: check with strings */
377  pSystemState->timer = SYS_FSM_SHORT_TIME;
378  if (CURRENT_SENSOR_PRESENT == true) {
380  } else {
381  pSystemState->state = SYS_STATEMACH_INITIALIZE_MISC;
382  }
383  pSystemState->substate = SYS_ENTRY;
384  break;
385  } else {
386  if (pSystemState->initializationTimeout >
388  pSystemState->timer = SYS_FSM_SHORT_TIME;
389  pSystemState->state = SYS_STATEMACH_ERROR;
390  pSystemState->substate = SYS_MEAS_INIT_ERROR;
391  break;
392  } else {
393  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
394  pSystemState->initializationTimeout++;
395  break;
396  }
397  }
398  }
399  break;
400 
401  /****************************CHECK CURRENT SENSOR PRESENCE*************************************/
403  SYS_SAVELASTSTATES(pSystemState);
404 
405  if (pSystemState->substate == SYS_ENTRY) {
406  pSystemState->initializationTimeout = 0;
407  CAN_EnablePeriodic(true);
408 #if CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED
409  /* If triggered mode is used, CAN trigger message needs to
410  * be transmitted and current sensor response has to be
411  * received afterwards. This may take some time, therefore
412  * delay has to be increased.
413  */
414  pSystemState->timer = SYS_FSM_LONG_TIME_MS;
415 #else /* CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
416  pSystemState->timer = SYS_FSM_LONG_TIME;
417 #endif /* CURRENT_SENSOR_ISABELLENHUETTE_TRIGGERED */
419  } else if (pSystemState->substate == SYS_WAIT_CURRENT_SENSOR_PRESENCE) {
420  bool allSensorsPresent = true;
421  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
422  if (CAN_IsCurrentSensorPresent(stringNumber) == true) {
423  if (CAN_IsCurrentSensorCcPresent(stringNumber) == true) {
424  SE_SocInit(true, stringNumber);
425  } else {
426  SE_SocInit(false, stringNumber);
427  }
428  if (CAN_IsCurrentSensorEcPresent(stringNumber) == true) {
429  SE_SoeInit(true, stringNumber);
430  } else {
431  SE_SoeInit(false, stringNumber);
432  }
433  } else {
434  allSensorsPresent = false;
435  }
436  }
437 
438  if (allSensorsPresent == true) {
439  SOF_Init();
440 
441  pSystemState->timer = SYS_FSM_SHORT_TIME;
442  pSystemState->state = SYS_STATEMACH_INITIALIZE_MISC;
443  pSystemState->substate = SYS_ENTRY;
444  break;
445  } else {
446  if (pSystemState->initializationTimeout >
448  pSystemState->timer = SYS_FSM_SHORT_TIME;
449  pSystemState->state = SYS_STATEMACH_ERROR;
451  break;
452  } else {
453  pSystemState->timer = SYS_FSM_MEDIUM_TIME;
454  pSystemState->initializationTimeout++;
455  break;
456  }
457  }
458  }
459  break;
460 
461  /****************************INITIALIZED_MISC*************************************/
463  SYS_SAVELASTSTATES(pSystemState);
464 
465  if (CURRENT_SENSOR_PRESENT == false) {
466  CAN_EnablePeriodic(true);
467  for (uint8_t stringNumber = 0u; stringNumber < BS_NR_OF_STRINGS; stringNumber++) {
468  SE_SocInit(false, stringNumber);
469  SE_SoeInit(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 
599 extern void SYS_GeneralMacroBist(void) {
600  const uint8_t dummy[REPEAT_MAXIMUM_REPETITIONS] = {
602  for (uint8_t i = 0u; i < REPEAT_MAXIMUM_REPETITIONS; i++) {
604  }
605 }
606 
608  FAS_ASSERT(pSystemState != NULL_PTR);
609  bool earlyExit = false;
610  STD_RETURN_TYPE_e returnValue = STD_OK;
611 
612  /* Check multiple calls of function */
613  if (SYS_MULTIPLE_CALLS_YES == SYS_CheckMultipleCalls(pSystemState)) {
614  returnValue = STD_NOT_OK;
615  earlyExit = true;
616  }
617 
618  if (earlyExit == false) {
619  if (pSystemState->timer > 0u) {
620  if ((--pSystemState->timer) > 0u) {
621  pSystemState->triggerEntry--;
622  returnValue = STD_OK;
623  earlyExit = true;
624  }
625  }
626  }
627 
628  if (earlyExit == false) {
629  SYS_RunStateMachine(pSystemState);
630  pSystemState->triggerEntry--;
631  }
632  return returnValue;
633 }
634 
635 /*========== 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:154
bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber)
get flag if CC message from current sensor is received.
Definition: can.c:418
bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber)
get flag if EC message from current sensor is received
Definition: can.c:423
bool CAN_IsCurrentSensorPresent(uint8_t stringNumber)
set flag for presence of current sensor.
Definition: can.c:413
void CAN_Initialize(void)
Enables the CAN transceiver.. This function sets th pins to enable the CAN transceiver....
Definition: can.c:201
void CAN_EnablePeriodic(bool command)
enable/disable the periodic transmit/receive.
Definition: can.c:367
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:292
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:249
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:236
@ 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:235
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:110
STD_RETURN_TYPE_e FRAM_Read(FRAM_BLOCK_ID_e blockId)
Reads a variable from the FRAM.
Definition: fram.c:163
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:82
@ STD_OK
Definition: fstd_types.h:81
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:75
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
#define STRIP(x)
Definition: general.h:274
#define REPEAT_MAXIMUM_REPETITIONS
Definition: general.h:237
#define REPEAT_U(x, n)
Macro that helps to generate a series of literals (for array initializers).
Definition: general.h:262
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:250
Headers for the driver for the interlock.
@ ILCK_STATE_INITIALIZATION_REQUEST
Definition: interlock.h:83
STD_RETURN_TYPE_e MEAS_StartMeasurement(void)
Makes the initialization request to the AFE state machine.
Definition: meas.c:111
bool MEAS_IsFirstMeasurementCycleFinished(void)
Checks if the first AFE measurement cycle was made.
Definition: meas.c:107
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:125
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:121
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:163
uint32_t illegalRequestsCounter
Definition: sys.h:170
SYS_STATE_REQUEST_e stateRequest
Definition: sys.h:165
uint8_t triggerEntry
Definition: sys.h:172
uint16_t timer
Definition: sys.h:164
uint16_t initializationTimeout
Definition: sys.h:171
SYS_STATEMACH_SUB_e substate
Definition: sys.h:167
SYS_STATEMACH_e state
Definition: sys.h:166
static SYS_STATE_REQUEST_e SYS_TransferStateRequest(void)
transfers the current state request to the state machine.
Definition: sys.c:539
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:550
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:574
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:607
void SYS_GeneralMacroBist(void)
Definition: sys.c:599
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_INITIALIZE_CAN
Definition: sys.h:107
@ 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:110
@ SYS_STATEMACH_INITIALIZATION
Definition: sys.h:103
@ SYS_STATEMACH_INITIALIZE_MISC
Definition: sys.h:114
@ SYS_STATEMACH_INITIALIZED
Definition: sys.h:105
@ SYS_STATEMACH_RUNNING
Definition: sys.h:112
@ SYS_STATEMACH_ERROR
Definition: sys.h:117
@ SYS_STATEMACH_FIRST_MEASUREMENT_CYCLE
Definition: sys.h:113
@ SYS_STATEMACH_INITIALIZE_BMS
Definition: sys.h:111
@ SYS_STATEMACH_CHECK_CURRENT_SENSOR_PRESENCE
Definition: sys.h:115
@ SYS_STATEMACH_INITIALIZE_INTERLOCK
Definition: sys.h:108
@ SYS_OK
Definition: sys.h:151
@ SYS_REQUEST_PENDING
Definition: sys.h:153
@ SYS_ALREADY_INITIALIZED
Definition: sys.h:155
@ SYS_ILLEGAL_REQUEST
Definition: sys.h:154
enum SYS_FSM_SUBSTATES SYS_FSM_SUBSTATES_e
enum SYS_RETURN_TYPE SYS_RETURN_TYPE_e
@ SYS_STATE_NO_REQUEST
Definition: sys.h:146
@ SYS_STATE_INIT_REQUEST
Definition: sys.h:144
@ SYS_STATE_ERROR_REQUEST
Definition: sys.h:145
@ SYS_WAIT_FIRST_MEASUREMENT_CYCLE
Definition: sys.h:131
@ SYS_WAIT_INITIALIZATION_BAL_GLOBAL_ENABLE
Definition: sys.h:129
@ SYS_BAL_INIT_ERROR
Definition: sys.h:135
@ SYS_WAIT_INITIALIZATION_BMS
Definition: sys.h:130
@ SYS_SBC_INIT_ERROR
Definition: sys.h:133
@ SYS_WAIT_INITIALIZATION_SBC
Definition: sys.h:125
@ SYS_WAIT_INITIALIZATION_BAL
Definition: sys.h:128
@ SYS_CURRENT_SENSOR_PRESENCE_ERROR
Definition: sys.h:139
@ SYS_MEAS_INIT_ERROR
Definition: sys.h:138
@ SYS_WAIT_CURRENT_SENSOR_PRESENCE
Definition: sys.h:132
@ SYS_BMS_INIT_ERROR
Definition: sys.h:137
@ SYS_ENTRY
Definition: sys.h:122
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