foxBMS  1.0.0
The foxBMS Battery Management System API Documentation
state-machine.h
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 state-machine.h
44  * @author foxBMS Team
45  * @date 2020-10-29 (date of creation)
46  * @updated 2020-11-09 (date of last update)
47  * @ingroup STATE_MACHINE
48  * @prefix EG
49  *
50  * @brief Header file of some software
51  *
52  */
53 
54 #ifndef FOXBMS__STATE_MACHINE_H_
55 #define FOXBMS__STATE_MACHINE_H_
56 
57 /*========== Includes =======================================================*/
58 #include "general.h"
59 
60 /*========== Macros and Definitions =========================================*/
61 /** States of the state machine */
62 typedef enum EG_FSM_STATES {
63  EG_FSM_STATE_DUMMY, /*!< dummy state - always the first state */
64  EG_FSM_STATE_HAS_NEVER_RUN, /*!< never run state - always the second state */
65  EG_FSM_STATE_UNINITIALIZED, /*!< uninitialized state */
66  EG_FSM_STATE_INITIALIZATION, /*!< initializing the state machine */
67  EG_FSM_STATE_RUNNING, /*!< operational mode of the state machine */
68  EG_FSM_STATE_ERROR, /*!< state for error processing */
70 
71 /** Substates of the state machine */
72 typedef enum EG_FSM_SUBSTATES {
73  EG_FSM_SUBSTATE_DUMMY, /*!< dummy state - always the first substate */
74  EG_FSM_SUBSTATE_ENTRY, /*!< entry state - always the second substate */
75  EG_FSM_SUBSTATE_INITIALIZATION_0, /*!< fist initialization substate */
76  EG_FSM_SUBSTATE_INITIALIZATION_1, /*!< second initialization substate */
77  EG_FSM_SUBSTATE_INITIALIZATION_EXIT, /*!< last initialization substate */
78  EG_FSM_SUBSTATE_RUNNING_0, /*!< fist running substate */
79  EG_FSM_SUBSTATE_RUNNING_1, /*!< second running substate */
80  EG_FSM_SUBSTATE_RUNNING_2, /*!< third running substate */
82 
83 /** some struct with some information */
84 typedef struct EG_INFORMATION {
85  uint8_t r0; /*!< some info 0 */
86  uint8_t r1; /*!< some info 0 */
87  uint8_t r2; /*!< some info 0 */
89 
90 /** This struct describes the state of the monitoring instance */
91 typedef struct EG_STATE {
92  uint16_t timer; /*!< timer of the state */
93  uint8_t triggerEntry; /*!< trigger entry of the state */
94  EG_FSM_STATES_e nextState; /*!< next state of the FSM */
95  EG_FSM_STATES_e currentState; /*!< current state of the FSM */
96  EG_FSM_STATES_e previousState; /*!< previous state of the FSM */
97  EG_FSM_SUBSTATES_e nextSubstate; /*!< next substate of the FSM */
98  EG_FSM_SUBSTATES_e currentSubstate; /*!< current substate of the FSM */
99  EG_FSM_SUBSTATES_e previousSubstate; /*!< previous substate of the FSM */
100  EG_INFORMATION_s information; /*!< Some information to be stored */
102 
103 /*========== Extern Constant and Variable Declarations ======================*/
104 
105 /** state of the example state machine */
106 extern EG_STATE_s eg_state;
107 
108 /*========== Extern Function Prototypes =====================================*/
109 /**
110  * @brief tick function, call this to advance the state machine
111  * @param pEgState current state of the state machine
112  * @returns returns always #STD_OK
113  */
114 extern STD_RETURN_TYPE_e EG_Trigger(EG_STATE_s *pEgState);
115 
116 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
117 
118 #endif /* FOXBMS__STATE_MACHINE_H_ */
EG_STATE
Definition: state-machine.h:91
EG_FSM_SUBSTATES_e
enum EG_FSM_SUBSTATES EG_FSM_SUBSTATES_e
general.h
TODO.
EG_FSM_SUBSTATE_DUMMY
@ EG_FSM_SUBSTATE_DUMMY
Definition: state-machine.h:73
EG_FSM_STATE_UNINITIALIZED
@ EG_FSM_STATE_UNINITIALIZED
Definition: state-machine.h:65
EG_FSM_STATE_ERROR
@ EG_FSM_STATE_ERROR
Definition: state-machine.h:68
EG_INFORMATION::r0
uint8_t r0
Definition: state-machine.h:85
EG_FSM_STATE_RUNNING
@ EG_FSM_STATE_RUNNING
Definition: state-machine.h:67
EG_INFORMATION_s
struct EG_INFORMATION EG_INFORMATION_s
EG_FSM_SUBSTATE_RUNNING_1
@ EG_FSM_SUBSTATE_RUNNING_1
Definition: state-machine.h:79
STD_RETURN_TYPE_e
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
EG_FSM_STATES_e
enum EG_FSM_STATES EG_FSM_STATES_e
EG_STATE::nextSubstate
EG_FSM_SUBSTATES_e nextSubstate
Definition: state-machine.h:97
EG_STATE_s
struct EG_STATE EG_STATE_s
EG_FSM_SUBSTATE_RUNNING_2
@ EG_FSM_SUBSTATE_RUNNING_2
Definition: state-machine.h:80
EG_FSM_STATE_DUMMY
@ EG_FSM_STATE_DUMMY
Definition: state-machine.h:63
EG_FSM_STATE_INITIALIZATION
@ EG_FSM_STATE_INITIALIZATION
Definition: state-machine.h:66
EG_INFORMATION::r1
uint8_t r1
Definition: state-machine.h:86
EG_STATE::previousSubstate
EG_FSM_SUBSTATES_e previousSubstate
Definition: state-machine.h:99
EG_INFORMATION::r2
uint8_t r2
Definition: state-machine.h:87
EG_FSM_SUBSTATE_INITIALIZATION_0
@ EG_FSM_SUBSTATE_INITIALIZATION_0
Definition: state-machine.h:75
EG_STATE::timer
uint16_t timer
Definition: state-machine.h:92
eg_state
EG_STATE_s eg_state
Definition: state-machine.c:87
EG_STATE::currentState
EG_FSM_STATES_e currentState
Definition: state-machine.h:95
EG_FSM_STATE_HAS_NEVER_RUN
@ EG_FSM_STATE_HAS_NEVER_RUN
Definition: state-machine.h:64
EG_FSM_SUBSTATE_ENTRY
@ EG_FSM_SUBSTATE_ENTRY
Definition: state-machine.h:74
EG_Trigger
STD_RETURN_TYPE_e EG_Trigger(EG_STATE_s *pEgState)
tick function, call this to advance the state machine
Definition: state-machine.c:435
EG_STATE::nextState
EG_FSM_STATES_e nextState
Definition: state-machine.h:94
EG_FSM_SUBSTATES
EG_FSM_SUBSTATES
Definition: state-machine.h:72
EG_FSM_SUBSTATE_RUNNING_0
@ EG_FSM_SUBSTATE_RUNNING_0
Definition: state-machine.h:78
EG_FSM_SUBSTATE_INITIALIZATION_EXIT
@ EG_FSM_SUBSTATE_INITIALIZATION_EXIT
Definition: state-machine.h:77
EG_INFORMATION
Definition: state-machine.h:84
EG_FSM_STATES
EG_FSM_STATES
Definition: state-machine.h:62
EG_STATE::previousState
EG_FSM_STATES_e previousState
Definition: state-machine.h:96
EG_STATE::triggerEntry
uint8_t triggerEntry
Definition: state-machine.h:93
EG_STATE::information
EG_INFORMATION_s information
Definition: state-machine.h:100
EG_FSM_SUBSTATE_INITIALIZATION_1
@ EG_FSM_SUBSTATE_INITIALIZATION_1
Definition: state-machine.h:76
EG_STATE::currentSubstate
EG_FSM_SUBSTATES_e currentSubstate
Definition: state-machine.h:98