foxBMS - Unit Tests  1.3.0
The foxBMS Unit Tests API Documentation
bender_iso165c_cfg.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 bender_iso165c_cfg.h
44  * @author foxBMS Team
45  * @date 2021-03-17 (date of creation)
46  * @updated 2022-05-30 (date of last update)
47  * @version v1.3.0
48  * @ingroup DRIVERS_CONFIGURATION
49  * @prefix I165C
50  *
51  * @brief Headers for the configuration for the insulation monitoring
52  *
53  * Please see the manual and data sheet for detailed information about the
54  * specifications and defines used within this file.
55  *
56  * docref: iso165C_C1_D00154_06_M_XXEN - 03/2021 - Manual
57  * docref: iso165Cx_D00154_04_D_XXEN - 03/2021 - Data sheet
58  */
59 
60 #ifndef FOXBMS__BENDER_ISO165C_CFG_H_
61 #define FOXBMS__BENDER_ISO165C_CFG_H_
62 
63 /*========== Includes =======================================================*/
64 #include "general.h"
65 
66 /* clang-format off */
67 #include "imd.h"
68 /* clang-format on */
69 
70 #include "can_cfg.h"
71 
72 /*========== Macros and Definitions =========================================*/
73 /** CAN Node the IMD device is connected to */
74 #define I165C_CAN_NODE (CAN1_NODE)
75 
76 /** Switch if bender iso165C or iso165C-1 is used
77  * true: iso165C
78  * false: iso165C-1
79  */
80 #define I165C_IS_165C_USED (false)
81 
82 /** Select if self-test scenario overall (I165C_SELF_TEST_LONG) or ParameterConfig
83  * self-test scenario (I165C_SELF_TEST_SHORT) shall be executed */
84 #define I165C_SELF_TEST_LONG
85 
86 /** Measured resistance threshold under which a warning is issued by i165c */
87 #define I165C_WARNING_THRESHOLD_kOhm IMD_WARNING_THRESHOLD_INSULATION_RESISTANCE_kOhm
88 
89 /** Measured resistance threshold under which an error is issued by i165c */
90 #define I165C_ERROR_THRESHOLD_kOhm IMD_ERROR_THRESHOLD_INSULATION_RESISTANCE_kOhm
91 
92 #if ((I165C_WARNING_THRESHOLD_kOhm > 2000u) || (I165C_WARNING_THRESHOLD_kOhm < 40u))
93 #error "Warning threshold outside of possible measurement 40-2000 kOhm"
94 #endif
95 #if ((I165C_ERROR_THRESHOLD_kOhm > 1000u) || (I165C_ERROR_THRESHOLD_kOhm < 30u))
96 #error "Warning threshold outside of possible measurement 40-2000 kOhm"
97 #endif
98 
99 /** Measurement averaging factor */
100 #define I165C_MEASUREMENT_AVERAGING_FACTOR (10u) /* Recommended value for EVs according to data sheet: 10 */
101 
102 /** Number of attempts to get acknowledgement of message reception by i165c */
103 #define I165C_TRANSMISSION_ATTEMPTS (3u)
104 
105 /** Number of attempts to receive the IMD_Info message from iso165c */
106 #define I165C_IMD_INFO_RECEIVE_ATTEMPTS (50u)
107 
108 /** Max number of attempts to read CAN queue */
109 #define I165C_MAX_QUEUE_READS (5u)
110 
111 /** Maximum queue timeout time in milliseconds */
112 #define I165C_QUEUE_TIMEOUT_ms ((TickType_t)0u)
113 
114 /** datsheet version: iso165C_D00154_03_M_XXEN/01.2019 */
115 
116 /**
117  * frames have up to two data words
118  * (1 data word length = 16 bits)
119  * or up to 4 data bytes
120  * (1 data byte length = 8 bits)
121  *
122  * CAUTION: data word order is reversed !!!!!!!!!
123  * (see data sheet page 15)
124  */
125 
126 /** data word 1 is in first position */
127 #define I165C_DW1 (0u)
128 /** data word 2 is in second position */
129 #define I165C_DW2 (1u)
130 /** data word 3 is in third position */
131 #define I165C_DW3 (2u)
132 /** data byte 1 is in first position */
133 #define I165C_DB1 (3u)
134 /** data byte 2 is in second position */
135 #define I165C_DB2 (4u)
136 /** data byte 3 is in third position */
137 #define I165C_DB3 (5u)
138 /** data byte 4 is in fourth position */
139 #define I165C_DB4 (6u)
140 
141 /** type of messages to communicate with I165C */
142 
143 /** cyclic message, transmitted every second */
144 #define I165C_MESSAGETYPE_IMD_INFO (CAN_ID_IMD_INFO)
145 /** message for requests (self test, reset, set values...) */
146 #define I165C_MESSAGETYPE_IMD_REQUEST (CAN_ID_IMD_REQUEST)
147 /** answer message, always send by I165C when it received a request*/
148 #define I165C_MESSAGETYPE_IMD_RESPONSE (CAN_ID_IMD_RESPONSE)
149 
150 /** control commands (CTL) */
151 
152 /** trigger self test */
153 #define I165C_CMD_S_IMC_CTL_SELFTEST (0x21u)
154 #define I165C_D_IMC_SELFTEST_SCR_CTL_REQUEST (I165C_DW1)
155 #define I165C_D_IMC_SELFTEST_SCR_CTL_RESPONSE (I165C_DW1)
156 #define I165C_SELFTEST_SCENARIO_NO_ACTION (0u)
157 #define I165C_SELFTEST_SCENARIO_OVERALL (1u)
158 #define I165C_SELFTEST_SCENARIO_PARAMETERCONFIG (2u)
159 /** reset I165C */
160 #define I165C_CMD_S_VIFC_CTL_IMC_RESET (0xC8u)
161 
162 /** lock and unlock possibility to make changes to I165C */
163 #define I165C_CMD_S_VIFC_CTL_LOCK (0xCAu)
164 #define I165C_D_VIFC_LOCK_MODE_CTL_REQUEST (I165C_DW1)
165 #define I165C_D_VIFC_LOCK_MODE_CTL_RESPONSE (I165C_DW1)
166 #define I165C_D_VIFC_LOCK_PWD_CTL_REQUEST (I165C_DW2)
167 #define I165C_LOCKMODE_UNLOCKED (0u)
168 #define I165C_LOCKMODE_LOCKED (1u)
169 #define I165C_LOCKMODE_UNKNOWN (100u)
170 #define I165C_UNLOCK_PASSWORD (0u)
171 #define I165C_LOCK_PASSWORD (0xFFFFu)
172 
173 /** change measurement mode */
174 #define I165C_CMD_S_VIFC_CTL_MEASUREMENT (0xCBu)
175 #define I165C_DW_VIFC_CTL_MEASUREMENT_REQUEST (I165C_DW1)
176 #define I165C_DISABLE_MEASUREMENT (0u)
177 #define I165C_ENABLE_MEASUREMENT (1u)
178 #define I165C_MEASUREMENT_MODE_UNKNOWN (100u)
179 
180 /**
181  * set commands (SET)
182  * for each command, 0,1 or 2 data words are defined
183  * they are defined for the request and the response
184  * a response is always sent when the I165C receives
185  * a command
186  */
187 
188 /** set error threshold */
189 #define I165C_CMD_S_IMC_SET_R_ISO_ERR_THR (0x28u)
190 #define I165C_D_IMC_R_ISO_ERR_THR_SET_REQUEST (I165C_DW1)
191 #define I165C_D_IMC_R_ISO_ERR_THR_SET_RESPONSE (I165C_DW1)
192 /** set warning threshold */
193 #define I165C_CMD_S_IMC_SET_R_ISO_ERR_WRN (0x29u)
194 #define I165C_D_IMC_R_ISO_ERR_WRN_SET_REQUEST (I165C_DW1)
195 #define I165C_D_IMC_R_ISO_ERR_WRN_SET_RESPONSE (I165C_DW1)
196 /** set the mean factor of the insulation resistance averaging algorithm */
197 #define I165C_CMD_S_IMC_SET_MEAN_FACTOR (0x2Bu)
198 #define I165C_D_IMC_MEAN_FACTOR_SET_REQUEST (I165C_DW1)
199 #define I165C_D_IMC_MEAN_FACTOR_SET_RESPONSE (I165C_DW1)
200 /** change the state of the HV relays in the HV coupling network */
201 #define I165C_CMD_S_VIFC_SET_HV_RELAIS (0xD2u)
202 #define I165C_D_VIFC_HV_RELAIS_SET_REQUEST (I165C_DW1)
203 #define I165C_D_VIFC_HV_RELAIS_STATE_SET_REQUEST (I165C_DW2)
204 #define I165C_D_VIFC_HV_RELAIS_NEGATIVE (0u)
205 #define I165C_D_VIFC_HV_RELAIS_POSITIVE (1u)
206 #define I165C_D_VIFC_HV_RELAIS_SET_RESPONSE (I165C_DW1)
207 #define I165C_D_VIFC_HV_RELAIS_STATE_SET_RESPONSE (I165C_DW2)
208 #define I165C_RELAY_STATE_OPEN (0u)
209 #define I165C_RELAY_STATE_CLOSED (1u)
210 
211 /**
212  * get commands (GET)
213  * for each command, 0,1 or 2 data words are defined
214  * they are defined for the request and the response
215  * a response is always sent when the I165C receives
216  * a command
217  */
218 
219 /** dummy command (ping the I165C) */
220 #define I165C_CMD_S_VIFC_DUMMY (0x00u)
221 
222 /** get the D_IMC_STATUS internal status of the I165C */
223 #define I165C_CMD_S_IMC_GET_STATUS (0x37u)
224 #define I165C_D_IMC_STATUS_GET_RESPONSE (I165C_DW1)
225 #define I165C_INSULATION_FAULT_SHIFT (0u)
226 #define I165C_CHASSIS_FAULT_SHIFT (1u)
227 #define I165C_SYSTEM_FAILURE_SHIFT (2u)
228 #define I165C_CALIBRATION_RUNNING_SHIFT (3u)
229 #define I165C_SELFTEST_RUNNING_SHIFT (4u)
230 #define I165C_INSULATION_WARNING_SHIFT (5u)
231 
232 /** get the D_IMC_STATUS_EXT device-internal IMC self-test results */
233 #define I165C_D_IMC_STATUS_EXT_GET_RESPONSE (I165C_DW2)
234 #define I165C_CALIBRATION_PARAMETER_SHIFT (0u)
235 #define I165C_HARDWARE_FAILURE_SHIFT (1u)
236 #define I165C_EEPROM_PARAMETER_SHIFT (2u)
237 #define I165C_FLASH_PARAMETER_SHIFT (3u)
238 #define I165C_RAM_PARAMETER_SHIFT (4u)
239 #define I165C_STACK_OVERFLOW_SHIFT (5u)
240 #define I165C_PARAMETER_VALUE_SHIFT (7u)
241 #define I165C_TEST_PULSE_VOLTAGE_A_REF_SHIFT (8u)
242 #define I165C_VOLTAGE_LEVEL_PLUS12V_SHIFT (9u)
243 #define I165C_VOLTAGE_LEVEL_MINUS12V_SHIFT (10u)
244 #define I165C_FUSE_BIT_VALID_INVALID_SHIFT (11u)
245 #define I165C_HV1_VOLTAGE_SHIFT (12u)
246 #define I165C_HV2_VOLTAGE_SHIFT (13u)
247 #define I165C_MANUFACTURER_STRING_VALID_INVALID_SHIFT (14u)
248 
249 /** get the insulation resistance */
250 #define I165C_CMD_S_IMC_GET_R_ISO (0x35u)
251 #define I165C_D_IMC_R_ISO_GET_RESPONSE (I165C_DW1)
252 #define I165C_D_IMC_R_ISO_BIAS_GET_RESPONSE (I165C_DB1)
253 #define I165C_BIAS_TO_HV_MINUS (1u)
254 #define I165C_BIAS_TO_HV_PLUS (2u)
255 #define I165C_D_IMC_R_ISO_CNT_GET_RESPONSE (I165C_DB2)
256 
257 /** get error threshold */
258 #define I165C_CMD_S_IMC_GET_R_ISO_ERR_THR (0x32u)
259 #define I165C_D_IMC_R_ISO_ERR_THR_GET_RESPONSE (I165C_DW1)
260 
261 /** get warning threshold */
262 #define I165C_CMD_S_IMC_GET_R_ISO_WRN_THR (0x39u)
263 #define I165C_D_IMC_R_ISO_WRN_THR_GET_RESPONSE (I165C_DW1)
264 
265 /** get mean factor */
266 #define I165C_CMD_S_IMC_GET_MEAN_FACTOR (0x3Cu)
267 #define I165C_D_IMC_MEAN_FACTOR_GET_RESPONSE (I165C_DW1)
268 
269 /** get HV1, HV value between HV1_POS and HV1_NEG */
270 #define I165C_CMD_S_IMC_GET_HV_1 (0x36u)
271 #define I165C_D_IMC_HV_1_GET_RESPONSE (I165C_DW1)
272 
273 /** get HV2, HV value between HV2_POS and HV2_NEG */
274 #define I165C_CMD_S_IMC_GET_HV_2 (0x3Au)
275 #define I165C_D_IMC_HV_2_GET_RESPONSE (I165C_DW1)
276 
277 /** get software version of the IMC */
278 #define I165C_CMD_S_IMC_GET_VERSION (0x33u)
279 #define I165C_D_IMC_VERSION_INDEX_GET_REQUEST (I165C_DW1)
280 #define I165C_IMC_BOOTLOADER (0u)
281 #define I165C_IMC_FIRMWARE (1u)
282 #define I165C_IMC_FIRMWARE_ID (2u)
283 #define I165C_IMC_FIRMWARE_HASH (3u)
284 #define I165C_D_IMC_VERSION_INDEX_GET_RESPONSE (I165C_DW1)
285 #define I165C_D_IMC_VERSION_GET_RESPONSE (I165C_DW2)
286 
287 /** get insulation monitoring counter value */
288 #define I165C_CMD_S_IMC_GET_TEST_CNT (0x5Au)
289 #define I165C_D_IMC_TEST_CNT_GET_RESPONSE (I165C_DW1)
290 
291 /** get manufacturer information */
292 #define I165C_CMD_S_IMC_GET_MANUFACTURER (0x3Du)
293 #define I165C_D_IMC_MANUFACT_INDEX_GET_REQUEST (I165C_DW1)
294 #define I165C_D_IMC_MANUFACT_INDEX_GET_RESPONSE (I165C_DW1)
295 #define I165C_D_IMC_MANUFACT_DATA_GET_RESPONSE (I165C_DW2)
296 
297 /** get internal status of the D_VIFC_STATUS */
298 #define I165C_CMD_S_VIFC_GET_STATUS (0xDCu)
299 #define I165C_D_VIFC_STATUS_GET_RESPONSE (I165C_DW1)
300 #define I165C_INSULATION_MEASUREMENT_STATUS_SHIFT (0u)
301 #define I165C_IMC_CONNECTIVITY_SHIFT (1u)
302 #define I165C_IMC_ALIVE_STATUS_DETECTION_SHIFT (2u)
303 #define I165C_VIFC_COMMAND_SHIFT (4u)
304 #define I165C_RESISTANCE_VALUE_OUTDATED_SHIFT (8u)
305 #define I165C_IMC_SELFTEST_OVERALL_SCENARIO_SHIFT (12u)
306 #define I165C_IMC_SELFTEST_PARAMETERCONFIG_SCENARIO_SHIFT (13u)
307 
308 /** get state of the HV relays in the HV coupling network */
309 #define I165C_CMD_S_VIFC_GET_HV_RELAIS (0xDDu)
310 #define I165C_D_VIFC_HV_RELAIS_GET_REQUEST (I165C_DW1)
311 #define I165C_D_VIFC_HV_RELAIS_GET_RESPONSE (I165C_DW1)
312 #define I165C_D_VIFC_HV_RELAIS_STATE_GET_RESPONSE (I165C_DW2)
313 
314 /** get "Alive" state of the IMC */
315 #define I165C_CMD_S_VIFC_GET_IMC_ALIVE (0xE2u)
316 #define I165C_D_VIFC_IMC_ALIVE_GET_RESPONSE (I165C_DW1)
317 
318 /** get software version of the VIFC */
319 #define I165C_CMD_S_VIFC_GET_VERSION (0xDEu)
320 #define I165C_D_IMC_VERSION_INDEX_GET_REQUEST (I165C_DW1)
321 #define I165C_D_VIFC_VERSION_INDEX_GET_RESPONSE (I165C_DW1)
322 #define I165C_D_VIFC_VERSION_GET_RESPONSE (I165C_DW2)
323 
324 /** get locking state of the iso165C */
325 #define I165C_CMD_S_VIFC_GET_LOCK (0xE0u)
326 #define I165C_D_VIFC_LOCK_MODE_GET_RESPONSE (I165C_DW1)
327 
328 /*========== Extern Constant and Variable Declarations ======================*/
329 
330 /*========== Extern Function Prototypes =====================================*/
331 
332 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
333 
334 #endif /* FOXBMS__BENDER_ISO165C_CFG_H_ */
Headers for the configuration for the CAN module.
General macros and definitions for the whole platform.
API header for the insulation monitoring device.