foxBMS  1.1.1
The foxBMS Battery Management System API Documentation
interlock.h
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 interlock.h
44  * @author foxBMS Team
45  * @date 2020-02-24 (date of creation)
46  * @updated 2020-02-24 (date of last update)
47  * @ingroup DRIVERS
48  * @prefix ILCK
49  *
50  * @brief Headers for the driver for the interlock.
51  *
52  */
53 
54 #ifndef FOXBMS__INTERLOCK_H_
55 #define FOXBMS__INTERLOCK_H_
56 
57 /*========== Includes =======================================================*/
58 #include "interlock_cfg.h"
59 
60 /*========== Macros and Definitions =========================================*/
61 
62 /**
63  * States of the ILCK state machine
64  */
65 typedef enum {
66  /* Init-Sequence */
67  ILCK_STATEMACH_UNINITIALIZED, /*!< Uninitialized state */
68  ILCK_STATEMACH_INITIALIZATION, /*!< Initialization state */
69  ILCK_STATEMACH_INITIALIZED, /*!< statemachine initialized */
70  ILCK_STATEMACH_WAIT_FIRST_REQUEST, /*!< wait for open/close request */
71  ILCK_STATEMACH_OPEN, /*!< state to open interlock */
72  ILCK_STATEMACH_CLOSED, /*!< state to close interlock */
73  ILCK_STATEMACH_UNDEFINED, /*!< undefined state */
74  ILCK_STATEMACH_ERROR, /*!< Error-State: */
76 
77 /**
78  * Substates of the ILCK state machine
79  */
80 typedef enum {
81  ILCK_ENTRY, /*!< Substate entry state */
83 
84 /**
85  * State requests for the ILCK statemachine
86  */
87 typedef enum {
94 
95 /**
96  * Possible return values when state requests are made to the ILCK statemachine
97  */
98 typedef enum {
99  ILCK_OK, /*!< ILCK --> ok */
100  ILCK_BUSY_OK, /*!< ILCK under load --> ok */
101  ILCK_REQUEST_PENDING, /*!< requested to be executed */
102  ILCK_ILLEGAL_REQUEST, /*!< Request can not be executed */
103  ILCK_INIT_ERROR, /*!< Error state: Source: Initialization */
104  ILCK_ERROR, /*!< General error state */
105  ILCK_ALREADY_INITIALIZED, /*!< Initialization of ilck already finished */
106  ILCK_ILLEGAL_TASK_TYPE, /*!< Illegal */
108 
109 /**
110  * This structure contains all the variables relevant for the ILCK state machine.
111  * The user can get the current state of the ILCK state machine with this variable
112  */
113 typedef struct {
114  uint16_t timer; /*!< time in ms before the state machine processes the next state, e.g. in counts of 1ms */
116  statereq; /*!< current state request made to the state machine */
118  state; /*!< state of Driver State Machine */
120  substate; /*!< current substate of the state machine */
122  laststate; /*!< previous state of the state machine */
124  lastsubstate; /*!< previous substate of the state machine */
125  uint32_t ErrRequestCounter; /*!< counts the number of illegal requests to the LTC state machine */
126  uint8_t triggerentry; /*!< counter for re-entrance protection (function running flag) */
127  uint8_t counter; /*!< general purpose counter */
128 } ILCK_STATE_s;
129 
130 /*========== Extern Constant and Variable Declarations ======================*/
131 
132 /*========== Extern Function Prototypes =====================================*/
133 /**
134  * @brief Checks the configuration of the interlock-module
135  * @return retVal (type: STD_RETURN_TYPE_e)
136  */
138 
139 /**
140  * @brief Reads the feedback pin of the interlock and returns its current value
141  * (ILCK_SWITCH_OFF/ILCK_SWITCH_ON)
142  * @return measuredInterlockState (type: ILCK_ELECTRICAL_STATE_TYPE_e)
143  */
145 
146 /**
147  * @brief sets the current state request of the state variable ilck_state.
148  *
149  * This function is used to make a state request to the state machine,e.g, start voltage measurement,
150  * read result of voltage measurement, re-initialization
151  * It calls ILCK_CheckStateRequest() to check if the request is valid.
152  * The state request is rejected if is not valid.
153  * The result of the check is returned immediately, so that the requester can act in case
154  * it made a non-valid state request.
155  *
156  * @param statereq state request to set
157  *
158  * @return retVal current state request, taken from ILCK_STATE_REQUEST_e
159  */
161 
162 /**
163  * @brief gets the current state.
164  *
165  * This function is used in the functioning of the ILCK state machine.
166  *
167  * @return current state, taken from ILCK_STATEMACH_e
168  */
169 extern ILCK_STATEMACH_e ILCK_GetState(void);
170 
171 /**
172  * @brief trigger function for the ILCK driver state machine.
173  *
174  * This function contains the sequence of events in the ILCK state machine.
175  * It must be called time-triggered, every 1ms.
176  */
177 extern void ILCK_Trigger(void);
178 
179 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
180 #ifdef UNITY_UNIT_TEST
181 extern void TEST_ILCK_SetStateStruct(ILCK_STATE_s state);
182 #endif
183 
184 #endif /* FOXBMS__INTERLOCK_H_ */
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
ILCK_STATEMACH_e
Definition: interlock.h:65
@ ILCK_STATEMACH_UNINITIALIZED
Definition: interlock.h:67
@ ILCK_STATEMACH_OPEN
Definition: interlock.h:71
@ ILCK_STATEMACH_CLOSED
Definition: interlock.h:72
@ ILCK_STATEMACH_INITIALIZED
Definition: interlock.h:69
@ ILCK_STATEMACH_WAIT_FIRST_REQUEST
Definition: interlock.h:70
@ ILCK_STATEMACH_INITIALIZATION
Definition: interlock.h:68
@ ILCK_STATEMACH_UNDEFINED
Definition: interlock.h:73
@ ILCK_STATEMACH_ERROR
Definition: interlock.h:74
STD_RETURN_TYPE_e ILCK_Init(void)
Checks the configuration of the interlock-module.
ILCK_RETURN_TYPE_e
Definition: interlock.h:98
@ ILCK_INIT_ERROR
Definition: interlock.h:103
@ ILCK_BUSY_OK
Definition: interlock.h:100
@ ILCK_ALREADY_INITIALIZED
Definition: interlock.h:105
@ ILCK_ILLEGAL_TASK_TYPE
Definition: interlock.h:106
@ ILCK_ERROR
Definition: interlock.h:104
@ ILCK_ILLEGAL_REQUEST
Definition: interlock.h:102
@ ILCK_OK
Definition: interlock.h:99
@ ILCK_REQUEST_PENDING
Definition: interlock.h:101
ILCK_STATEMACH_SUB_e
Definition: interlock.h:80
@ ILCK_ENTRY
Definition: interlock.h:81
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
void ILCK_Trigger(void)
trigger function for the ILCK driver state machine.
Definition: interlock.c:320
ILCK_ELECTRICAL_STATE_TYPE_e ILCK_GetInterlockFeedback(void)
Reads the feedback pin of the interlock and returns its current value (ILCK_SWITCH_OFF/ILCK_SWITCH_ON...
Definition: interlock.c:287
ILCK_STATE_REQUEST_e
Definition: interlock.h:87
@ ILCK_STATE_NO_REQUEST
Definition: interlock.h:92
@ ILCK_STATE_OPEN_REQUEST
Definition: interlock.h:89
@ ILCK_STATE_INIT_REQUEST
Definition: interlock.h:88
@ ILCK_STATE_ERROR_REQUEST
Definition: interlock.h:91
@ ILCK_STATE_CLOSE_REQUEST
Definition: interlock.h:90
ILCK_STATEMACH_e ILCK_GetState(void)
gets the current state.
Definition: interlock.c:302
Header for the configuration for the driver for the interlock.
enum ILCK_ELECTRICAL_STATE_TYPE ILCK_ELECTRICAL_STATE_TYPE_e
uint32_t ErrRequestCounter
Definition: interlock.h:125
uint8_t triggerentry
Definition: interlock.h:126
ILCK_STATE_REQUEST_e statereq
Definition: interlock.h:116
ILCK_STATEMACH_e state
Definition: interlock.h:118
ILCK_STATEMACH_SUB_e lastsubstate
Definition: interlock.h:124
ILCK_STATEMACH_e laststate
Definition: interlock.h:122
uint16_t timer
Definition: interlock.h:114
ILCK_STATEMACH_SUB_e substate
Definition: interlock.h:120
uint8_t counter
Definition: interlock.h:127