foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
imd.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 imd.h
44  * @author foxBMS Team
45  * @date 2020-11-20 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup DRIVERS
49  * @prefix IMD
50  *
51  * @brief API header for the insulation monitoring device
52  *
53  */
54 
55 #ifndef FOXBMS__IMD_H_
56 #define FOXBMS__IMD_H_
57 
58 /*========== Includes =======================================================*/
59 
60 #include "can_cfg.h"
61 #include "ftask_cfg.h"
62 
63 #include "database.h"
64 
65 #include <stdint.h>
66 
67 /*========== Macros and Definitions =========================================*/
68 #define IMD_PERIODIC_CALL_TIME_ms (FTSK_TASK_CYCLIC_100MS_CYCLE_TIME)
69 
70 /** Minimum required insulation resistance - Error threshold */
71 #define IMD_ERROR_THRESHOLD_INSULATION_RESISTANCE_kOhm (500u)
72 
73 /** Minimum required insulation resistance - Warning threshold */
74 #define IMD_WARNING_THRESHOLD_INSULATION_RESISTANCE_kOhm (750u)
75 
76 /** Possible return values when state requests are made to the IMD state machine */
77 typedef enum {
78  IMD_REQUEST_OK, /*!< request was successful */
79  IMD_REQUEST_PENDING, /*!< requested to be executed */
80  IMD_ILLEGAL_REQUEST, /*!< Request can not be executed */
81  IMD_ALREADY_INITIALIZED, /*!< IMD state machine already initialized */
83 
84 /** State requests for the IMD state machine */
85 typedef enum {
86  IMD_STATE_INITIALIZE_REQUEST, /*!< request for initialization */
87  IMD_STATE_SWITCH_ON_REQUEST, /*!< request to switch on IMD device */
88  IMD_STATE_SHUTDOWN_REQUEST, /*!< request for shut down */
89  IMD_STATE_NO_REQUEST, /*!< dummy request for no request */
91 
92 /** States of the state machine */
93 typedef enum {
94  IMD_FSM_STATE_DUMMY, /*!< dummy state - always the first state */
95  IMD_FSM_STATE_HAS_NEVER_RUN, /*!< never run state - always the second state */
96  IMD_FSM_STATE_UNINITIALIZED, /*!< uninitialized state */
97  IMD_FSM_STATE_INITIALIZATION, /*!< initializing the state machine */
98  IMD_FSM_STATE_IMD_ENABLE, /*!< switch on IMD */
99  IMD_FSM_STATE_SHUTDOWN, /*!< shut down state of IMD state machine */
100  IMD_FSM_STATE_RUNNING, /*!< operational mode of the state machine */
101  IMD_FSM_STATE_ERROR, /*!< state for error processing */
103 
104 /*========== Extern Constant and Variable Declarations ======================*/
105 
106 /*========== Extern Function Prototypes =====================================*/
107 /**
108  * @brief Request initialization of IMD state machine
109  * @return Always #IMD_REQUEST_OK
110  */
112 
113 /**
114  * @brief Request to activate the actual IMD measurement
115  * @return Always #IMD_REQUEST_OK
116  */
118 
119 /**
120  * @brief Request to deactivate the actual IMD measurement
121  * @return Always #IMD_REQUEST_OK
122  */
124 
125 /**
126  * @brief Gets the initialization state.
127  * @details This function is used for getting the IMD initialization state.
128  * @return true if state machine initialized, otherwise false
129  */
130 extern bool IMD_GetInitializationState(void);
131 
132 /**
133  * @brief trigger function for the IMD driver state machine.
134  * @details This function contains the sequence of events in the IMD state
135  * machine. It must be called time-triggered, every 100ms.
136  * @returns returns #STD_OK if trigger called successfully
137  */
138 extern STD_RETURN_TYPE_e IMD_Trigger(void);
139 
140 /**************************************************** FOLLOWING FUNCTIONS NEED TO BE IMPLEMENTED BY THE IMD DRIVER */
141 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE imd-documentation */
142 /**
143  * @brief Processes the initialization state
144  * @details This function needs to be implemented in the dedicated driver. This
145  * function initializes the required SW modules and peripherals but
146  * does not start the actual IMD measurement.
147  * @return #IMD_FSM_STATE_INITIALIZATION if initialization not finished and
148  * another call is required. #IMD_FSM_STATE_IMD_ENABLE if
149  * initialization is finished and #IMD_FSM_STATE_ERROR if an error is
150  * detected that prohibits a working IMD driver.
151  */
153 
154 /**
155  * @brief Processes the IMD enable state
156  * @details This function needs to be implemented in the dedicated driver. This
157  * function enables the actual IMD device to start the insulation
158  * measurement. Functionality need to be fulfilled after one call.
159  * @return #IMD_FSM_STATE_RUNNING if startup has been completed. Returns #IMD_FSM_STATE_ERROR if an error is
160  * detected that prohibits a working IMD driver.
161  */
163 
164 /**
165  * @brief Processes the running state
166  * @details This function needs to be implemented in the dedicated driver
167  * @param pTableInsulationMonitoring pointer to insulation monitoring
168  * database entry
169  * @return #IMD_FSM_STATE_RUNNING if measurement works as expected, otherwise
170  * #IMD_FSM_STATE_ERROR if an error is detected that prohibits a
171  * further execution of the IMD driver.
172  */
174 
175 /**
176  * @brief Processes the shutdown state
177  * @details This function needs to be implemented in the dedicated driver. This
178  * function disables the actual IMD device to stop the insulation
179  * measurement.
180  * @return #IMD_FSM_STATE_SHUTDOWN if shutdown state is not finished and
181  * another call is required. #IMD_FSM_STATE_IMD_ENABLE if shut down
182  * has been completed and #IMD_FSM_STATE_ERROR if an error is detected
183  * that prohibits a working IMD driver.
184  */
186 
187 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE imd-documentation */
188 /*******************************************************************************************************************/
189 
190 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
191 #ifdef UNITY_UNIT_TEST
192 #endif
193 
194 #endif /* FOXBMS__IMD_H_ */
Headers for the configuration for the CAN module.
Database module header.
STD_RETURN_TYPE_e
Definition: fstd_types.h:82
Task configuration header.
IMD_RETURN_TYPE_e IMD_RequestInsulationMeasurement(void)
Request to activate the actual IMD measurement.
Definition: imd.c:516
IMD_FSM_STATES_e IMD_ProcessInitializationState(void)
Processes the initialization state.
Definition: bender_ir155.c:210
bool IMD_GetInitializationState(void)
Gets the initialization state.
Definition: imd.c:524
STD_RETURN_TYPE_e IMD_Trigger(void)
trigger function for the IMD driver state machine.
Definition: imd.c:528
IMD_FSM_STATES_e IMD_ProcessShutdownState(void)
Processes the shutdown state.
Definition: bender_ir155.c:225
IMD_FSM_STATES_e IMD_ProcessEnableState(void)
Processes the IMD enable state.
Definition: bender_ir155.c:214
IMD_RETURN_TYPE_e IMD_RequestMeasurementStop(void)
Request to deactivate the actual IMD measurement.
Definition: imd.c:520
IMD_FSM_STATES_e
Definition: imd.h:93
@ IMD_FSM_STATE_RUNNING
Definition: imd.h:100
@ IMD_FSM_STATE_SHUTDOWN
Definition: imd.h:99
@ IMD_FSM_STATE_INITIALIZATION
Definition: imd.h:97
@ IMD_FSM_STATE_HAS_NEVER_RUN
Definition: imd.h:95
@ IMD_FSM_STATE_IMD_ENABLE
Definition: imd.h:98
@ IMD_FSM_STATE_DUMMY
Definition: imd.h:94
@ IMD_FSM_STATE_UNINITIALIZED
Definition: imd.h:96
@ IMD_FSM_STATE_ERROR
Definition: imd.h:101
IMD_STATE_REQUEST_e
Definition: imd.h:85
@ IMD_STATE_SWITCH_ON_REQUEST
Definition: imd.h:87
@ IMD_STATE_SHUTDOWN_REQUEST
Definition: imd.h:88
@ IMD_STATE_INITIALIZE_REQUEST
Definition: imd.h:86
@ IMD_STATE_NO_REQUEST
Definition: imd.h:89
IMD_RETURN_TYPE_e
Definition: imd.h:77
@ IMD_ALREADY_INITIALIZED
Definition: imd.h:81
@ IMD_ILLEGAL_REQUEST
Definition: imd.h:80
@ IMD_REQUEST_PENDING
Definition: imd.h:79
@ IMD_REQUEST_OK
Definition: imd.h:78
IMD_RETURN_TYPE_e IMD_RequestInitialization(void)
Request initialization of IMD state machine.
Definition: imd.c:512
IMD_FSM_STATES_e IMD_ProcessRunningState(DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulationMonitoring)
Processes the running state.
Definition: bender_ir155.c:220