foxBMS  1.0.0
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
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 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_ */
ILCK_ILLEGAL_TASK_TYPE
@ ILCK_ILLEGAL_TASK_TYPE
Definition: interlock.h:106
ILCK_Init
STD_RETURN_TYPE_e ILCK_Init(void)
Checks the configuration of the interlock-module.
ILCK_STATE_s::timer
uint16_t timer
Definition: interlock.h:114
ILCK_STATEMACH_OPEN
@ ILCK_STATEMACH_OPEN
Definition: interlock.h:71
STD_RETURN_TYPE_e
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
ILCK_STATE_s::ErrRequestCounter
uint32_t ErrRequestCounter
Definition: interlock.h:125
ILCK_STATE_s
Definition: interlock.h:113
ILCK_STATE_s::substate
ILCK_STATEMACH_SUB_e substate
Definition: interlock.h:120
ILCK_ERROR
@ ILCK_ERROR
Definition: interlock.h:104
ILCK_STATEMACH_UNINITIALIZED
@ ILCK_STATEMACH_UNINITIALIZED
Definition: interlock.h:67
ILCK_STATE_ERROR_REQUEST
@ ILCK_STATE_ERROR_REQUEST
Definition: interlock.h:91
ILCK_GetInterlockFeedback
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_s::state
ILCK_STATEMACH_e state
Definition: interlock.h:118
ILCK_STATE_INIT_REQUEST
@ ILCK_STATE_INIT_REQUEST
Definition: interlock.h:88
ILCK_STATEMACH_ERROR
@ ILCK_STATEMACH_ERROR
Definition: interlock.h:74
ILCK_STATEMACH_e
ILCK_STATEMACH_e
Definition: interlock.h:65
ILCK_Trigger
void ILCK_Trigger(void)
trigger function for the ILCK driver state machine.
Definition: interlock.c:320
ILCK_STATEMACH_CLOSED
@ ILCK_STATEMACH_CLOSED
Definition: interlock.h:72
ILCK_GetState
ILCK_STATEMACH_e ILCK_GetState(void)
gets the current state.
Definition: interlock.c:302
ILCK_SetStateRequest
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_STATE_s::statereq
ILCK_STATE_REQUEST_e statereq
Definition: interlock.h:116
ILCK_ENTRY
@ ILCK_ENTRY
Definition: interlock.h:81
ILCK_STATEMACH_UNDEFINED
@ ILCK_STATEMACH_UNDEFINED
Definition: interlock.h:73
ILCK_STATE_s::laststate
ILCK_STATEMACH_e laststate
Definition: interlock.h:122
ILCK_STATEMACH_SUB_e
ILCK_STATEMACH_SUB_e
Definition: interlock.h:80
ILCK_STATE_s::counter
uint8_t counter
Definition: interlock.h:127
ILCK_STATEMACH_WAIT_FIRST_REQUEST
@ ILCK_STATEMACH_WAIT_FIRST_REQUEST
Definition: interlock.h:70
ILCK_ELECTRICAL_STATE_TYPE_e
enum ILCK_ELECTRICAL_STATE_TYPE ILCK_ELECTRICAL_STATE_TYPE_e
ILCK_INIT_ERROR
@ ILCK_INIT_ERROR
Definition: interlock.h:103
interlock_cfg.h
Header for the configuration for the driver for the interlock.
ILCK_STATE_s::lastsubstate
ILCK_STATEMACH_SUB_e lastsubstate
Definition: interlock.h:124
ILCK_STATE_s::triggerentry
uint8_t triggerentry
Definition: interlock.h:126
ILCK_RETURN_TYPE_e
ILCK_RETURN_TYPE_e
Definition: interlock.h:98
ILCK_STATEMACH_INITIALIZED
@ ILCK_STATEMACH_INITIALIZED
Definition: interlock.h:69
ILCK_REQUEST_PENDING
@ ILCK_REQUEST_PENDING
Definition: interlock.h:101
ILCK_STATE_CLOSE_REQUEST
@ ILCK_STATE_CLOSE_REQUEST
Definition: interlock.h:90
ILCK_OK
@ ILCK_OK
Definition: interlock.h:99
ILCK_STATE_NO_REQUEST
@ ILCK_STATE_NO_REQUEST
Definition: interlock.h:92
ILCK_STATE_OPEN_REQUEST
@ ILCK_STATE_OPEN_REQUEST
Definition: interlock.h:89
ILCK_BUSY_OK
@ ILCK_BUSY_OK
Definition: interlock.h:100
ILCK_STATEMACH_INITIALIZATION
@ ILCK_STATEMACH_INITIALIZATION
Definition: interlock.h:68
ILCK_ALREADY_INITIALIZED
@ ILCK_ALREADY_INITIALIZED
Definition: interlock.h:105
ILCK_ILLEGAL_REQUEST
@ ILCK_ILLEGAL_REQUEST
Definition: interlock.h:102
ILCK_STATE_REQUEST_e
ILCK_STATE_REQUEST_e
Definition: interlock.h:87