1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2023 Carl Zeiss Meditec AG
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 #include <zephyr/devicetree.h>
7 #include <zephyr/drivers/emul.h>
8 #include <zephyr/drivers/sensor.h>
9 #include <zephyr/ztest.h>
10
11 #include "adltc2990.h"
12 #include "adltc2990_emul.h"
13 #include "adltc2990_reg.h"
14
15 /* Colllection of common assertion macros */
16 #define CHECK_SINGLE_ENDED_VOLTAGE(sensor_val, index, pin_voltage, r1, r2) \
17 zassert_ok(sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_VOLTAGE)); \
18 zassert_ok(sensor_channel_get(fixture->dev, SENSOR_CHAN_VOLTAGE, sensor_val)); \
19 zassert_between_inclusive( \
20 sensor_val[index].val1 + (float)sensor_val[index].val2 / 1000000, \
21 (pin_voltage - 0.01f) * ((r1 + r2) / (float)r2), \
22 (pin_voltage + 0.01f) * ((r1 + r2) / (float)r2), \
23 "%f Out of Range [%f,%f] input %f, [%dmΩ, %dmΩ] " \
24 "\nCheck if the sensor node is configured correctly", \
25 (double)(sensor_val[index].val1 + (float)sensor_val[index].val2 / 1000000), \
26 (double)((pin_voltage - 0.01f) * ((r1 + r2) / (float)r2)), \
27 (double)((pin_voltage + 0.01f) * ((r1 + r2) / (float)r2)), (double)pin_voltage, \
28 r1, r2);
29
30 #define CHECK_CURRENT(sensor_val, index, pin_voltage, r_microohms) \
31 zassert_ok(sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_CURRENT)); \
32 zassert_ok(sensor_channel_get(fixture->dev, SENSOR_CHAN_CURRENT, sensor_val)); \
33 zassert_between_inclusive( \
34 sensor_val[index].val1 + (float)sensor_val[index].val2 / 1000000, \
35 (pin_voltage - 0.01f) * ADLTC2990_MICROOHM_CONVERSION_FACTOR / r_microohms, \
36 (pin_voltage + 0.01f) * ADLTC2990_MICROOHM_CONVERSION_FACTOR / r_microohms, \
37 "%f Out of Range [%f,%f] input %f, current-resistor: %dµΩ\nCheck if the sensor " \
38 "node is configured correctly", \
39 (double)(sensor_val[index].val1 + (float)sensor_val[index].val2 / 1000000), \
40 (double)((pin_voltage - 0.001f) * ADLTC2990_MICROOHM_CONVERSION_FACTOR / \
41 r_microohms), \
42 (double)((pin_voltage + 0.001f) * ADLTC2990_MICROOHM_CONVERSION_FACTOR / \
43 r_microohms), \
44 (double)pin_voltage, r_microohms);
45
46 #define CHECK_TEMPERATURE(sensor_val, index, expected_temperature, temperature_type) \
47 zassert_ok(sensor_sample_fetch_chan(fixture->dev, temperature_type)); \
48 zassert_ok(sensor_channel_get(fixture->dev, temperature_type, sensor_val)); \
49 zassert_equal(expected_temperature, \
50 sensor_val[index].val1 + (float)sensor_val[index].val2 / 1000000, \
51 "expected %f, got %f", (double)expected_temperature, \
52 (double)(sensor_val[index].val1 + (float)sensor_val[index].val2 / 1000000));
53
54 /*** TEST-SUITE: ADLTC2990 Measurement Mode 0 0***/
55
56 struct adltc2990_0_0_fixture {
57 const struct device *dev;
58 const struct emul *target;
59 };
60
adltc2990_0_0_setup(void)61 static void *adltc2990_0_0_setup(void)
62 {
63 static struct adltc2990_0_0_fixture fixture = {
64 .dev = DEVICE_DT_GET(DT_NODELABEL(adltc2990_0_0)),
65 .target = EMUL_DT_GET(DT_NODELABEL(adltc2990_0_0)),
66 };
67
68 zassert_not_null(fixture.dev);
69 zassert_not_null(fixture.target);
70 return &fixture;
71 }
72
adltc2990_0_0_before(void * f)73 static void adltc2990_0_0_before(void *f)
74 {
75 struct adltc2990_0_0_fixture *fixture = f;
76
77 adltc2990_emul_reset(fixture->target);
78 }
79
80 ZTEST_SUITE(adltc2990_0_0, NULL, adltc2990_0_0_setup, adltc2990_0_0_before, NULL, NULL);
81
ZTEST_F(adltc2990_0_0,test_measure_mode_internal_temperature_only)82 ZTEST_F(adltc2990_0_0, test_measure_mode_internal_temperature_only)
83 {
84 struct sensor_value value[1];
85
86 zassert_equal(-ENOTSUP, sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_MAGN_X));
87 zassert_equal(-ENOTSUP, sensor_channel_get(fixture->dev, SENSOR_CHAN_MAGN_Z, value));
88 zassert_equal(-EINVAL, sensor_channel_get(fixture->dev, SENSOR_CHAN_CURRENT, value));
89 zassert_equal(-EINVAL, sensor_channel_get(fixture->dev, SENSOR_CHAN_AMBIENT_TEMP, value));
90 }
91
92 /*** TEST-SUITE: ADLTC2990 Measurement Mode 4 3***/
93
94 struct adltc2990_4_3_fixture {
95 const struct device *dev;
96 const struct emul *target;
97 };
98
adltc2990_4_3_setup(void)99 static void *adltc2990_4_3_setup(void)
100 {
101 static struct adltc2990_4_3_fixture fixture = {
102 .dev = DEVICE_DT_GET(DT_NODELABEL(adltc2990_4_3)),
103 .target = EMUL_DT_GET(DT_NODELABEL(adltc2990_4_3)),
104 };
105
106 zassert_not_null(fixture.dev);
107 zassert_not_null(fixture.target);
108 return &fixture;
109 }
110
adltc2990_4_3_before(void * f)111 static void adltc2990_4_3_before(void *f)
112 {
113 struct adltc2990_4_3_fixture *fixture = f;
114
115 adltc2990_emul_reset(fixture->target);
116 }
117
118 ZTEST_SUITE(adltc2990_4_3, NULL, adltc2990_4_3_setup, adltc2990_4_3_before, NULL, NULL);
119
ZTEST_F(adltc2990_4_3,test_available_channels)120 ZTEST_F(adltc2990_4_3, test_available_channels)
121 {
122 struct sensor_value value[3];
123
124 zassert_equal(0, sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_VOLTAGE));
125 zassert_equal(0, sensor_channel_get(fixture->dev, SENSOR_CHAN_VOLTAGE, value));
126 zassert_equal(0, sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_AMBIENT_TEMP));
127 zassert_equal(0, sensor_channel_get(fixture->dev, SENSOR_CHAN_AMBIENT_TEMP, value));
128 zassert_equal(0, sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_CURRENT));
129 zassert_equal(0, sensor_channel_get(fixture->dev, SENSOR_CHAN_CURRENT, value));
130 }
131
132 /*** TEST-SUITE: ADLTC2990 Measurement Mode 1 3***/
133
134 struct adltc2990_1_3_fixture {
135 const struct device *dev;
136 const struct emul *target;
137 };
138
adltc2990_1_3_setup(void)139 static void *adltc2990_1_3_setup(void)
140 {
141 static struct adltc2990_1_3_fixture fixture = {
142 .dev = DEVICE_DT_GET(DT_NODELABEL(adltc2990_1_3)),
143 .target = EMUL_DT_GET(DT_NODELABEL(adltc2990_1_3)),
144 };
145
146 zassert_not_null(fixture.dev);
147 zassert_not_null(fixture.target);
148 return &fixture;
149 }
150
adltc2990_1_3_before(void * f)151 static void adltc2990_1_3_before(void *f)
152 {
153 struct adltc2990_1_3_fixture *fixture = f;
154
155 adltc2990_emul_reset(fixture->target);
156 }
157
158 ZTEST_SUITE(adltc2990_1_3, NULL, adltc2990_1_3_setup, adltc2990_1_3_before, NULL, NULL);
159
ZTEST_F(adltc2990_1_3,test_die_temperature)160 ZTEST_F(adltc2990_1_3, test_die_temperature)
161 {
162 /* The following values are taken from datasheet and should translate to 125°c */
163 uint8_t msb = 0b00000111, lsb = 0b11010000;
164
165 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_INTERNAL_TEMP_MSB, &msb);
166 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_INTERNAL_TEMP_LSB, &lsb);
167
168 struct sensor_value temp_value[1];
169
170 CHECK_TEMPERATURE(temp_value, 0, 125.00f, SENSOR_CHAN_DIE_TEMP);
171
172 /*0b00011101 0b10000000 –40.0000*/
173 msb = 0b00011101;
174 lsb = 0b10000000;
175
176 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_INTERNAL_TEMP_MSB, &msb);
177 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_INTERNAL_TEMP_LSB, &lsb);
178
179 CHECK_TEMPERATURE(temp_value, 0, -40.00f, SENSOR_CHAN_DIE_TEMP);
180 }
181
ZTEST_F(adltc2990_1_3,test_ambient_temperature)182 ZTEST_F(adltc2990_1_3, test_ambient_temperature)
183 {
184 /* 0b00000001 0b10010001 +25.0625 */
185 uint8_t msb = 0b00000001, lsb = 0b10010001;
186 struct sensor_value temp_ambient[1];
187
188 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V3_MSB, &msb);
189 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V3_LSB, &lsb);
190
191 CHECK_TEMPERATURE(temp_ambient, 0, 25.06250f, SENSOR_CHAN_AMBIENT_TEMP);
192 }
193
ZTEST_F(adltc2990_1_3,test_current)194 ZTEST_F(adltc2990_1_3, test_current)
195 {
196 /* 0b00111100 0b01011000 +0.300 */
197 uint8_t msb_reg_value = 0b00111100, lsb_reg_value = 0b01011000;
198
199 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_MSB, &msb_reg_value);
200 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_LSB, &lsb_reg_value);
201
202 struct sensor_value current_values[1];
203 const struct adltc2990_config *dev_config = fixture->target->dev->config;
204
205 CHECK_CURRENT(current_values, 0, 0.3f, dev_config->pins_v1_v2.pins_current_resistor);
206
207 /* 0b00100000 0b00000000 +0.159 */
208 msb_reg_value = 0b00100000, lsb_reg_value = 0b00000000;
209 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_MSB, &msb_reg_value);
210 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_LSB, &lsb_reg_value);
211 CHECK_CURRENT(current_values, 0, 0.159f, dev_config->pins_v1_v2.pins_current_resistor);
212 }
213
ZTEST_F(adltc2990_1_3,test_V1_MINUS_V2_VCC)214 ZTEST_F(adltc2990_1_3, test_V1_MINUS_V2_VCC)
215 {
216 uint8_t msb = 0b01100000, lsb = 0b00000000;
217
218 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_MSB, &msb);
219 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_LSB, &lsb);
220
221 msb = 0b00000010;
222 lsb = 0b10001111;
223 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_VCC_MSB, &msb);
224 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_VCC_LSB, &lsb);
225
226 zassert_ok(sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_VOLTAGE));
227
228 struct sensor_value voltage_values[2];
229
230 zassert_ok(sensor_channel_get(fixture->dev, SENSOR_CHAN_VOLTAGE, voltage_values));
231
232 float test_value = voltage_values[0].val1 + (float)voltage_values[0].val2 / 1000000;
233
234 zassert_between_inclusive(test_value, -0.16f, -0.159f, "Out of Range [-0.16,-0.159]%.6f",
235 (double)test_value);
236
237 test_value = voltage_values[1].val1 + (float)voltage_values[1].val2 / 1000000;
238 zassert_between_inclusive(test_value, 2.69f, 2.7f, "Out of Range [2.69, 2.7]%.6f",
239 (double)test_value);
240 }
241
242 /*** TEST-SUITE: ADLTC2990 Measurement Mode 5 3***/
243
244 struct adltc2990_5_3_fixture {
245 const struct device *dev;
246 const struct emul *target;
247 };
248
adltc2990_5_3_setup(void)249 static void *adltc2990_5_3_setup(void)
250 {
251 static struct adltc2990_5_3_fixture fixture = {
252 .dev = DEVICE_DT_GET(DT_NODELABEL(adltc2990_5_3)),
253 .target = EMUL_DT_GET(DT_NODELABEL(adltc2990_5_3)),
254 };
255
256 zassert_not_null(fixture.dev);
257 zassert_not_null(fixture.target);
258 return &fixture;
259 }
260
adltc2990_5_3_before(void * f)261 static void adltc2990_5_3_before(void *f)
262 {
263 struct adltc2990_5_3_fixture *fixture = f;
264
265 adltc2990_emul_reset(fixture->target);
266 }
267
268 ZTEST_SUITE(adltc2990_5_3, NULL, adltc2990_5_3_setup, adltc2990_5_3_before, NULL, NULL);
269
ZTEST_F(adltc2990_5_3,test_ambient_temperature)270 ZTEST_F(adltc2990_5_3, test_ambient_temperature)
271 {
272 /*Kelvin 0b00010001 0b00010010 273.1250*/
273 uint8_t msb = 0b00010001, lsb = 0b00010010;
274
275 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_MSB, &msb);
276 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_LSB, &lsb);
277
278 struct sensor_value temp_value[2];
279
280 CHECK_TEMPERATURE(temp_value, 0, 273.1250f, SENSOR_CHAN_AMBIENT_TEMP);
281
282 /*Kelvin 0b00001110 0b10010010 233.125*/
283 msb = 0b00001110;
284 lsb = 0b10010010;
285 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V3_MSB, &msb);
286 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V3_LSB, &lsb);
287 CHECK_TEMPERATURE(temp_value, 1, 233.1250f, SENSOR_CHAN_AMBIENT_TEMP);
288 }
289
ZTEST_F(adltc2990_5_3,test_die_temperature)290 ZTEST_F(adltc2990_5_3, test_die_temperature)
291 {
292 /*0b00011000 0b11100010 398.1250*/
293 uint8_t msb = 0b00011000, lsb = 0b11100010;
294
295 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_INTERNAL_TEMP_MSB, &msb);
296 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_INTERNAL_TEMP_LSB, &lsb);
297
298 struct sensor_value temp_value[1];
299
300 CHECK_TEMPERATURE(temp_value, 0, 398.1250f, SENSOR_CHAN_DIE_TEMP);
301 }
302
303 /*** TEST-SUITE: ADLTC2990 Measurement Mode 7 3***/
304
305 struct adltc2990_6_3_fixture {
306 const struct device *dev;
307 const struct emul *target;
308 };
309
adltc2990_6_3_setup(void)310 static void *adltc2990_6_3_setup(void)
311 {
312 static struct adltc2990_6_3_fixture fixture = {
313 .dev = DEVICE_DT_GET(DT_NODELABEL(adltc2990_6_3)),
314 .target = EMUL_DT_GET(DT_NODELABEL(adltc2990_6_3)),
315 };
316
317 zassert_not_null(fixture.dev);
318 zassert_not_null(fixture.target);
319 return &fixture;
320 }
321
adltc2990_6_3_before(void * f)322 static void adltc2990_6_3_before(void *f)
323 {
324 struct adltc2990_6_3_fixture *fixture = f;
325
326 adltc2990_emul_reset(fixture->target);
327 }
328
329 ZTEST_SUITE(adltc2990_6_3, NULL, adltc2990_6_3_setup, adltc2990_6_3_before, NULL, NULL);
330
ZTEST_F(adltc2990_6_3,test_current)331 ZTEST_F(adltc2990_6_3, test_current)
332 {
333 /* 0b00111100 0b01011000 +0.300 */
334 uint8_t msb_reg_value = 0b00111100, lsb_reg_value = 0b01011000;
335
336 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_MSB, &msb_reg_value);
337 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_LSB, &lsb_reg_value);
338
339 struct sensor_value current_values[2];
340 const struct adltc2990_config *dev_config = fixture->target->dev->config;
341
342 CHECK_CURRENT(current_values, 0, 0.3f, dev_config->pins_v1_v2.pins_current_resistor);
343
344 /* 0b00100000 0b00000000 +0.159 */
345 msb_reg_value = 0b00100000, lsb_reg_value = 0b00000000;
346 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V3_MSB, &msb_reg_value);
347 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V3_LSB, &lsb_reg_value);
348 CHECK_CURRENT(current_values, 1, 0.159f, dev_config->pins_v3_v4.pins_current_resistor);
349 }
350
351 /*** TEST-SUITE: ADLTC2990 Measurement Mode 7 3***/
352 struct adltc2990_7_3_fixture {
353 const struct device *dev;
354 const struct emul *target;
355 };
356
adltc2990_7_3_setup(void)357 static void *adltc2990_7_3_setup(void)
358 {
359 static struct adltc2990_7_3_fixture fixture = {
360 .dev = DEVICE_DT_GET(DT_NODELABEL(adltc2990_7_3)),
361 .target = EMUL_DT_GET(DT_NODELABEL(adltc2990_7_3)),
362 };
363
364 zassert_not_null(fixture.dev);
365 zassert_not_null(fixture.target);
366 return &fixture;
367 }
368
adltc2990_7_3_before(void * f)369 static void adltc2990_7_3_before(void *f)
370 {
371 struct adltc2990_7_3_fixture *fixture = f;
372
373 adltc2990_emul_reset(fixture->target);
374 }
375
376 ZTEST_SUITE(adltc2990_7_3, NULL, adltc2990_7_3_setup, adltc2990_7_3_before, NULL, NULL);
377
ZTEST_F(adltc2990_7_3,test_available_channels)378 ZTEST_F(adltc2990_7_3, test_available_channels)
379 {
380 zassert_equal(-EINVAL, sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_AMBIENT_TEMP));
381 zassert_equal(-EINVAL, sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_CURRENT));
382 }
383
ZTEST_F(adltc2990_7_3,test_is_device_busy)384 ZTEST_F(adltc2990_7_3, test_is_device_busy)
385 {
386 uint8_t is_busy = BIT(0);
387
388 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_STATUS, &is_busy);
389 zassert_equal(-EBUSY, sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_ALL));
390 is_busy = 0;
391 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_STATUS, &is_busy);
392 zassert_equal(0, sensor_sample_fetch_chan(fixture->dev, SENSOR_CHAN_ALL));
393 }
394
ZTEST_F(adltc2990_7_3,test_die_temperature)395 ZTEST_F(adltc2990_7_3, test_die_temperature)
396 {
397 /* The following values are taken from datasheet and should translate to 398.1250K */
398
399 uint8_t msb = 0b00011000, lsb = 0b11100010;
400
401 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_INTERNAL_TEMP_MSB, &msb);
402 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_INTERNAL_TEMP_LSB, &lsb);
403
404 struct sensor_value *die_temp_value_null = (struct sensor_value *)NULL;
405
406 zassert_equal(-EINVAL,
407 sensor_channel_get(fixture->dev, SENSOR_CHAN_ALL, die_temp_value_null));
408
409 struct sensor_value die_temp_value[1];
410
411 CHECK_TEMPERATURE(die_temp_value, 0, 398.1250f, SENSOR_CHAN_DIE_TEMP);
412 }
413
ZTEST_F(adltc2990_7_3,test_V1_V2_V3_V4_VCC)414 ZTEST_F(adltc2990_7_3, test_V1_V2_V3_V4_VCC)
415 {
416 /* 0b00111111 0b11111111 >5 */
417 uint8_t msb_reg_value = 0b00111111, lsb_reg_value = 0b11111111;
418
419 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_MSB, &msb_reg_value);
420 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V1_LSB, &lsb_reg_value);
421
422 /* 0b00101100 0b11001101 3.500 */
423 msb_reg_value = 0b00101100;
424 lsb_reg_value = 0b11001101;
425 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V2_MSB, &msb_reg_value);
426 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V2_LSB, &lsb_reg_value);
427
428 /* 0b00011111 0b11111111 2.500 */
429 msb_reg_value = 0b00011111;
430 lsb_reg_value = 0b11111111;
431 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V3_MSB, &msb_reg_value);
432 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V3_LSB, &lsb_reg_value);
433
434 /* 0b01111100 0b00101001 –0.300 */
435 msb_reg_value = 0b01111100;
436 lsb_reg_value = 0b00101001;
437 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V4_MSB, &msb_reg_value);
438 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_V4_LSB, &lsb_reg_value);
439
440 /* VCC = 6V */
441 msb_reg_value = 0b00101100;
442 lsb_reg_value = 0b11001101;
443 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_VCC_MSB, &msb_reg_value);
444 adltc2990_emul_set_reg(fixture->target, ADLTC2990_REG_VCC_LSB, &lsb_reg_value);
445
446 struct sensor_value voltage_values[5];
447
448 const struct adltc2990_config *dev_config = fixture->dev->config;
449
450 CHECK_SINGLE_ENDED_VOLTAGE(voltage_values, 0, 5.0f,
451 dev_config->pins_v1_v2.voltage_divider_resistors.v1_r1_r2[0],
452 dev_config->pins_v1_v2.voltage_divider_resistors.v1_r1_r2[1]);
453
454 CHECK_SINGLE_ENDED_VOLTAGE(voltage_values, 1, 3.5f,
455 dev_config->pins_v1_v2.voltage_divider_resistors.v2_r1_r2[0],
456 dev_config->pins_v1_v2.voltage_divider_resistors.v2_r1_r2[1]);
457
458 CHECK_SINGLE_ENDED_VOLTAGE(voltage_values, 2, 2.5f,
459 dev_config->pins_v3_v4.voltage_divider_resistors.v3_r1_r2[0],
460 dev_config->pins_v3_v4.voltage_divider_resistors.v3_r1_r2[1]);
461
462 CHECK_SINGLE_ENDED_VOLTAGE(voltage_values, 3, -0.3f,
463 dev_config->pins_v3_v4.voltage_divider_resistors.v4_r1_r2[0],
464 dev_config->pins_v3_v4.voltage_divider_resistors.v4_r1_r2[1]);
465
466 double test_value = voltage_values[4].val1 + (double)voltage_values[4].val2 / 1000000;
467
468 zassert_between_inclusive(test_value, 6.0, 6.1, "Out of Range [6.0,6.1] %.6f",
469 (double)test_value);
470
471 zassert_equal(6, voltage_values[4].val1);
472 }
473
474 /*** TEST-SUITE: ADLTC2990 Measurement Mode Incorrect***/
475 struct adltc2990_incorrect_fixture {
476 const struct device *dev;
477 const struct emul *target;
478 };
479
adltc2990_incorrect_setup(void)480 static void *adltc2990_incorrect_setup(void)
481 {
482 static struct adltc2990_incorrect_fixture fixture = {
483 .dev = DEVICE_DT_GET(DT_NODELABEL(adltc2990_incorrect)),
484 .target = EMUL_DT_GET(DT_NODELABEL(adltc2990_incorrect)),
485 };
486
487 zassert_not_null(fixture.dev);
488 zassert_not_null(fixture.target);
489 return &fixture;
490 }
491
adltc2990_incorrect_before(void * f)492 static void adltc2990_incorrect_before(void *f)
493 {
494 struct adltc2990_incorrect_fixture *fixture = f;
495
496 adltc2990_emul_reset(fixture->target);
497 }
498
499 ZTEST_SUITE(adltc2990_incorrect, NULL, adltc2990_incorrect_setup, adltc2990_incorrect_before, NULL,
500 NULL);
501
ZTEST_F(adltc2990_incorrect,test_current_cannot_be_measured)502 ZTEST_F(adltc2990_incorrect, test_current_cannot_be_measured)
503 {
504 struct sensor_value current[1];
505
506 zassert_equal(-EINVAL, sensor_channel_get(fixture->dev, SENSOR_CHAN_CURRENT, current));
507 }
508