foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests 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 2021-10-18 (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_STATEMACHINE_UNINITIALIZED, /*!< Uninitialized state */
68  ILCK_STATEMACHINE_INITIALIZED, /*!< statemachine initialized */
69  ILCK_STATEMACHINE_UNDEFINED, /*!< undefined state */
71 
72 /**
73  * Substates of the ILCK state machine
74  */
75 typedef enum {
76  ILCK_ENTRY, /*!< Substate entry state */
78 
79 /**
80  * State requests for the ILCK statemachine
81  */
82 typedef enum {
86 
87 /**
88  * Possible return values when state requests are made to the ILCK statemachine
89  */
90 typedef enum {
91  ILCK_OK, /*!< ILCK --> ok */
92  ILCK_REQUEST_PENDING, /*!< requested to be executed */
93  ILCK_ALREADY_INITIALIZED, /*!< Initialization of ilck already finished */
94  ILCK_ILLEGAL_REQUEST, /*!< Request can not be executed */
96 
97 /**
98  * This structure contains all the variables relevant for the ILCK state machine.
99  * The user can get the current state of the ILCK state machine with this variable
100  */
101 typedef struct {
102  uint16_t timer; /*!< time in ms before the state machine processes the next state, e.g. in counts of 1ms */
104  statereq; /*!< current state request made to the state machine */
106  state; /*!< state of Driver State Machine */
108  substate; /*!< current substate of the state machine */
110  laststate; /*!< previous state of the state machine */
112  lastsubstate; /*!< previous substate of the state machine */
113  uint32_t ErrRequestCounter; /*!< counts the number of illegal requests to the LTC state machine */
114  uint8_t triggerentry; /*!< counter for re-entrance protection (function running flag) */
115  uint8_t counter; /*!< general purpose counter */
116 } ILCK_STATE_s;
117 
118 /*========== Extern Constant and Variable Declarations ======================*/
119 
120 /*========== Extern Function Prototypes =====================================*/
121 /**
122  * @brief Checks the configuration of the interlock-module
123  * @return retVal (type: STD_RETURN_TYPE_e)
124  */
126 
127 /**
128  * @brief sets the current state request of the state variable ilck_state.
129  *
130  * This function is used to make a state request to the state machine,e.g, start voltage measurement,
131  * read result of voltage measurement, re-initialization
132  * It calls ILCK_CheckStateRequest() to check if the request is valid.
133  * The state request is rejected if is not valid.
134  * The result of the check is returned immediately, so that the requester can act in case
135  * it made a non-valid state request.
136  *
137  * @param statereq state request to set
138  *
139  * @return retVal current state request, taken from ILCK_STATE_REQUEST_e
140  */
142 
143 /**
144  * @brief gets the current state.
145  *
146  * This function is used in the functioning of the ILCK state machine.
147  *
148  * @return current state, taken from ILCK_STATEMACH_e
149  */
150 extern ILCK_STATEMACH_e ILCK_GetState(void);
151 
152 /**
153  * @brief trigger function for the ILCK driver state machine.
154  *
155  * This function contains the sequence of events in the ILCK state machine.
156  * It must be called time-triggered, every 1ms.
157  */
158 extern void ILCK_Trigger(void);
159 
160 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
161 #ifdef UNITY_UNIT_TEST
162 extern void TEST_ILCK_SetStateStruct(ILCK_STATE_s state);
164 #endif
165 
166 #endif /* FOXBMS__INTERLOCK_H_ */
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
ILCK_STATEMACH_e
Definition: interlock.h:65
@ ILCK_STATEMACHINE_UNINITIALIZED
Definition: interlock.h:67
@ ILCK_STATEMACHINE_INITIALIZED
Definition: interlock.h:68
@ ILCK_STATEMACHINE_UNDEFINED
Definition: interlock.h:69
STD_RETURN_TYPE_e ILCK_Init(void)
Checks the configuration of the interlock-module.
ILCK_RETURN_TYPE_e
Definition: interlock.h:90
@ ILCK_ALREADY_INITIALIZED
Definition: interlock.h:93
@ ILCK_ILLEGAL_REQUEST
Definition: interlock.h:94
@ ILCK_OK
Definition: interlock.h:91
@ ILCK_REQUEST_PENDING
Definition: interlock.h:92
ILCK_STATEMACH_SUB_e
Definition: interlock.h:75
@ ILCK_ENTRY
Definition: interlock.h:76
void TEST_ILCK_SetStateStruct(ILCK_STATE_s state)
Definition: interlock.c:321
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:250
void ILCK_Trigger(void)
trigger function for the ILCK driver state machine.
Definition: interlock.c:264
ILCK_ELECTRICAL_STATE_TYPE_e TEST_ILCK_GetInterlockFeedback(void)
Definition: interlock.c:324
ILCK_STATE_REQUEST_e
Definition: interlock.h:82
@ ILCK_STATE_NO_REQUEST
Definition: interlock.h:84
@ ILCK_STATE_INITIALIZATION_REQUEST
Definition: interlock.h:83
ILCK_STATEMACH_e ILCK_GetState(void)
gets the current state.
Definition: interlock.c:246
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:113
uint8_t triggerentry
Definition: interlock.h:114
ILCK_STATE_REQUEST_e statereq
Definition: interlock.h:104
ILCK_STATEMACH_e state
Definition: interlock.h:106
ILCK_STATEMACH_SUB_e lastsubstate
Definition: interlock.h:112
ILCK_STATEMACH_e laststate
Definition: interlock.h:110
uint16_t timer
Definition: interlock.h:102
ILCK_STATEMACH_SUB_e substate
Definition: interlock.h:108
uint8_t counter
Definition: interlock.h:115