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