foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
interlock.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file interlock.h
44  * @author foxBMS Team
45  * @date 2020-02-24 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup DRIVERS
49  * @prefix ILCK
50  *
51  * @brief Headers for the driver for the interlock.
52  *
53  */
54 
55 #ifndef FOXBMS__INTERLOCK_H_
56 #define FOXBMS__INTERLOCK_H_
57 
58 /*========== Includes =======================================================*/
59 #include "interlock_cfg.h"
60 
61 #include <stdint.h>
62 
63 /*========== Macros and Definitions =========================================*/
64 
65 /**
66  * States of the ILCK state machine
67  */
68 typedef enum {
69  /* Init-Sequence */
70  ILCK_STATEMACHINE_UNINITIALIZED, /*!< Uninitialized state */
71  ILCK_STATEMACHINE_INITIALIZED, /*!< state machine initialized */
72  ILCK_STATEMACHINE_UNDEFINED, /*!< undefined state */
74 
75 /**
76  * Substates of the ILCK state machine
77  */
78 typedef enum {
79  ILCK_ENTRY, /*!< Substate entry state */
81 
82 /**
83  * State requests for the ILCK state machine
84  */
85 typedef enum {
89 
90 /**
91  * Possible return values when state requests are made to the ILCK state machine
92  */
93 typedef enum {
94  ILCK_OK, /*!< ILCK --> ok */
95  ILCK_REQUEST_PENDING, /*!< requested to be executed */
96  ILCK_ALREADY_INITIALIZED, /*!< Initialization of ilck already finished */
97  ILCK_ILLEGAL_REQUEST, /*!< Request can not be executed */
99 
100 /**
101  * This structure contains all the variables relevant for the ILCK state machine.
102  * The user can get the current state of the ILCK state machine with this variable
103  */
104 typedef struct {
105  uint16_t timer; /*!< time in ms before the state machine processes the next state, e.g. in counts of 1ms */
106  ILCK_STATE_REQUEST_e statereq; /*!< current state request made to the state machine */
107  ILCK_STATEMACH_e state; /*!< state of Driver State Machine */
108  ILCK_STATEMACH_SUB_e substate; /*!< current substate of the state machine */
109  ILCK_STATEMACH_e laststate; /*!< previous state of the state machine */
110  ILCK_STATEMACH_SUB_e lastsubstate; /*!< previous substate of the state machine */
111  uint32_t ErrRequestCounter; /*!< counts the number of illegal requests to the LTC state machine */
112  uint8_t triggerentry; /*!< counter for re-entrance protection (function running flag) */
113  uint8_t counter; /*!< general purpose counter */
114 } ILCK_STATE_s;
115 
116 /*========== Extern Constant and Variable Declarations ======================*/
117 
118 /*========== Extern Function Prototypes =====================================*/
119 
120 /**
121  * @brief sets the current state request of the state variable ilck_state.
122  *
123  * This function is used to make a state request to the state machine,e.g, start voltage measurement,
124  * read result of voltage measurement, re-initialization
125  * It calls ILCK_CheckStateRequest() to check if the request is valid.
126  * The state request is rejected if is not valid.
127  * The result of the check is returned immediately, so that the requester can act in case
128  * it made a non-valid state request.
129  *
130  * @param statereq state request to set
131  *
132  * @return retVal current state request, taken from ILCK_STATE_REQUEST_e
133  */
135 
136 /**
137  * @brief gets the current state.
138  *
139  * This function is used in the functioning of the ILCK state machine.
140  *
141  * @return current state, taken from ILCK_STATEMACH_e
142  */
143 extern ILCK_STATEMACH_e ILCK_GetState(void);
144 
145 /**
146  * @brief trigger function for the ILCK driver state machine.
147  *
148  * This function contains the sequence of events in the ILCK state machine.
149  * It must be called time-triggered, every 1ms.
150  */
151 extern void ILCK_Trigger(void);
152 
153 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
154 #ifdef UNITY_UNIT_TEST
155 extern void TEST_ILCK_SetStateStruct(ILCK_STATE_s state);
156 extern ILCK_ELECTRICAL_STATE_TYPE_e TEST_ILCK_GetInterlockFeedback(void);
157 #endif
158 
159 #endif /* FOXBMS__INTERLOCK_H_ */
ILCK_STATEMACH_e
Definition: interlock.h:68
@ ILCK_STATEMACHINE_UNINITIALIZED
Definition: interlock.h:70
@ ILCK_STATEMACHINE_INITIALIZED
Definition: interlock.h:71
@ ILCK_STATEMACHINE_UNDEFINED
Definition: interlock.h:72
ILCK_RETURN_TYPE_e
Definition: interlock.h:93
@ ILCK_ALREADY_INITIALIZED
Definition: interlock.h:96
@ ILCK_ILLEGAL_REQUEST
Definition: interlock.h:97
@ ILCK_OK
Definition: interlock.h:94
@ ILCK_REQUEST_PENDING
Definition: interlock.h:95
ILCK_STATEMACH_SUB_e
Definition: interlock.h:78
@ ILCK_ENTRY
Definition: interlock.h:79
ILCK_RETURN_TYPE_e ILCK_SetStateRequest(ILCK_STATE_REQUEST_e statereq)
sets the current state request of the state variable ilck_state.
Definition: interlock.c:254
void ILCK_Trigger(void)
trigger function for the ILCK driver state machine.
Definition: interlock.c:268
ILCK_STATE_REQUEST_e
Definition: interlock.h:85
@ ILCK_STATE_NO_REQUEST
Definition: interlock.h:87
@ ILCK_STATE_INITIALIZATION_REQUEST
Definition: interlock.h:86
ILCK_STATEMACH_e ILCK_GetState(void)
gets the current state.
Definition: interlock.c:250
Header for the configuration for the driver for the interlock.
ILCK_ELECTRICAL_STATE_TYPE_e
uint32_t ErrRequestCounter
Definition: interlock.h:111
uint8_t triggerentry
Definition: interlock.h:112
ILCK_STATE_REQUEST_e statereq
Definition: interlock.h:106
ILCK_STATEMACH_e state
Definition: interlock.h:107
ILCK_STATEMACH_SUB_e lastsubstate
Definition: interlock.h:110
ILCK_STATEMACH_e laststate
Definition: interlock.h:109
uint16_t timer
Definition: interlock.h:105
ILCK_STATEMACH_SUB_e substate
Definition: interlock.h:108
uint8_t counter
Definition: interlock.h:113