foxBMS - Unit Tests  1.4.1
The foxBMS Unit Tests API Documentation
interlock.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2022, 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 2022-10-27 (date of last update)
47  * @version v1.4.1
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 /*========== Macros and Definitions =========================================*/
62 
63 /**
64  * States of the ILCK state machine
65  */
66 typedef enum {
67  /* Init-Sequence */
68  ILCK_STATEMACHINE_UNINITIALIZED, /*!< Uninitialized state */
69  ILCK_STATEMACHINE_INITIALIZED, /*!< statemachine initialized */
70  ILCK_STATEMACHINE_UNDEFINED, /*!< undefined state */
72 
73 /**
74  * Substates of the ILCK state machine
75  */
76 typedef enum {
77  ILCK_ENTRY, /*!< Substate entry state */
79 
80 /**
81  * State requests for the ILCK statemachine
82  */
83 typedef enum {
87 
88 /**
89  * Possible return values when state requests are made to the ILCK statemachine
90  */
91 typedef enum {
92  ILCK_OK, /*!< ILCK --> ok */
93  ILCK_REQUEST_PENDING, /*!< requested to be executed */
94  ILCK_ALREADY_INITIALIZED, /*!< Initialization of ilck already finished */
95  ILCK_ILLEGAL_REQUEST, /*!< Request can not be executed */
97 
98 /**
99  * This structure contains all the variables relevant for the ILCK state machine.
100  * The user can get the current state of the ILCK state machine with this variable
101  */
102 typedef struct {
103  uint16_t timer; /*!< time in ms before the state machine processes the next state, e.g. in counts of 1ms */
105  statereq; /*!< current state request made to the state machine */
107  state; /*!< state of Driver State Machine */
109  substate; /*!< current substate of the state machine */
111  laststate; /*!< previous state of the state machine */
113  lastsubstate; /*!< previous substate of the state machine */
114  uint32_t ErrRequestCounter; /*!< counts the number of illegal requests to the LTC state machine */
115  uint8_t triggerentry; /*!< counter for re-entrance protection (function running flag) */
116  uint8_t counter; /*!< general purpose counter */
117 } ILCK_STATE_s;
118 
119 /*========== Extern Constant and Variable Declarations ======================*/
120 
121 /*========== Extern Function Prototypes =====================================*/
122 
123 /**
124  * @brief sets the current state request of the state variable ilck_state.
125  *
126  * This function is used to make a state request to the state machine,e.g, start voltage measurement,
127  * read result of voltage measurement, re-initialization
128  * It calls ILCK_CheckStateRequest() to check if the request is valid.
129  * The state request is rejected if is not valid.
130  * The result of the check is returned immediately, so that the requester can act in case
131  * it made a non-valid state request.
132  *
133  * @param statereq state request to set
134  *
135  * @return retVal current state request, taken from ILCK_STATE_REQUEST_e
136  */
138 
139 /**
140  * @brief gets the current state.
141  *
142  * This function is used in the functioning of the ILCK state machine.
143  *
144  * @return current state, taken from ILCK_STATEMACH_e
145  */
146 extern ILCK_STATEMACH_e ILCK_GetState(void);
147 
148 /**
149  * @brief trigger function for the ILCK driver state machine.
150  *
151  * This function contains the sequence of events in the ILCK state machine.
152  * It must be called time-triggered, every 1ms.
153  */
154 extern void ILCK_Trigger(void);
155 
156 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
157 #ifdef UNITY_UNIT_TEST
158 extern void TEST_ILCK_SetStateStruct(ILCK_STATE_s state);
160 #endif
161 
162 #endif /* FOXBMS__INTERLOCK_H_ */
ILCK_STATEMACH_e
Definition: interlock.h:66
@ ILCK_STATEMACHINE_UNINITIALIZED
Definition: interlock.h:68
@ ILCK_STATEMACHINE_INITIALIZED
Definition: interlock.h:69
@ ILCK_STATEMACHINE_UNDEFINED
Definition: interlock.h:70
ILCK_RETURN_TYPE_e
Definition: interlock.h:91
@ ILCK_ALREADY_INITIALIZED
Definition: interlock.h:94
@ ILCK_ILLEGAL_REQUEST
Definition: interlock.h:95
@ ILCK_OK
Definition: interlock.h:92
@ ILCK_REQUEST_PENDING
Definition: interlock.h:93
ILCK_STATEMACH_SUB_e
Definition: interlock.h:76
@ ILCK_ENTRY
Definition: interlock.h:77
void TEST_ILCK_SetStateStruct(ILCK_STATE_s state)
Definition: interlock.c:322
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:251
void ILCK_Trigger(void)
trigger function for the ILCK driver state machine.
Definition: interlock.c:265
ILCK_ELECTRICAL_STATE_TYPE_e TEST_ILCK_GetInterlockFeedback(void)
Definition: interlock.c:325
ILCK_STATE_REQUEST_e
Definition: interlock.h:83
@ ILCK_STATE_NO_REQUEST
Definition: interlock.h:85
@ ILCK_STATE_INITIALIZATION_REQUEST
Definition: interlock.h:84
ILCK_STATEMACH_e ILCK_GetState(void)
gets the current state.
Definition: interlock.c:247
Header for the configuration for the driver for the interlock.
ILCK_ELECTRICAL_STATE_TYPE_e
uint32_t ErrRequestCounter
Definition: interlock.h:114
uint8_t triggerentry
Definition: interlock.h:115
ILCK_STATE_REQUEST_e statereq
Definition: interlock.h:105
ILCK_STATEMACH_e state
Definition: interlock.h:107
ILCK_STATEMACH_SUB_e lastsubstate
Definition: interlock.h:113
ILCK_STATEMACH_e laststate
Definition: interlock.h:111
uint16_t timer
Definition: interlock.h:103
ILCK_STATEMACH_SUB_e substate
Definition: interlock.h:109
uint8_t counter
Definition: interlock.h:116