Skip to content

Commit f4970da

Browse files
committed
tests: drivers: adc_dma: fix sampling interval failing NXP tests
In 6e21ebf the sampling interval was changed, which caused the issue #56070. This is fixed by allowing different boards to specify a sampling period. Also changed the test_task_with_interval to verify that the supplied interval was used. Signed-off-by: Hein Wessels <[email protected]>
1 parent d4ed0d7 commit f4970da

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/drivers/adc/adc_dma/src/test_adc.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2018 Nordic Semiconductor ASA
33
* Copyright (c) 2016 Intel Corporation
44
* Copyright (c) 2020, NXP
5+
* Copyright (c) 2023, Nobleo Technology
56
*
67
* SPDX-License-Identifier: Apache-2.0
78
*/
@@ -23,6 +24,7 @@
2324
#define ADC_1ST_CHANNEL_ID 26
2425
#define COUNTER_NODE_NAME pit0
2526
#define HW_TRIGGER_INTERVAL (2U)
27+
#define SAMPLE_INTERVAL_US HW_TRIGGER_INTERVAL
2628

2729
#elif defined(CONFIG_BOARD_FRDM_K82F)
2830

@@ -34,6 +36,7 @@
3436
#define ADC_1ST_CHANNEL_ID 26
3537
#define COUNTER_NODE_NAME pit0
3638
#define HW_TRIGGER_INTERVAL (2U)
39+
#define SAMPLE_INTERVAL_US HW_TRIGGER_INTERVAL
3740

3841
#elif defined(CONFIG_BOARD_NUCLEO_H743ZI)
3942

@@ -64,8 +67,12 @@
6467
#define BUFFER_MEM_REGION EMPTY
6568
#endif
6669

67-
/* for DMA HW trigger interval need large than HW trigger interval*/
68-
#define SAMPLE_INTERVAL_US (10000U)
70+
/* The sample interval between consecutive samplings. Some drivers require
71+
* specific values to function.
72+
*/
73+
#if !defined(SAMPLE_INTERVAL_US)
74+
#define SAMPLE_INTERVAL_US 0
75+
#endif
6976

7077
#define BUFFER_SIZE 24
7178
#ifndef ALIGNMENT
@@ -284,7 +291,7 @@ static int test_task_asynchronous_call(void)
284291
const struct adc_sequence_options options = {
285292
.extra_samplings = 4,
286293
/* Start consecutive samplings as fast as possible. */
287-
.interval_us = 0,
294+
.interval_us = SAMPLE_INTERVAL_US,
288295
};
289296
const struct adc_sequence sequence = {
290297
.options = &options,
@@ -348,7 +355,7 @@ static int test_task_with_interval(void)
348355
int64_t milliseconds_spent;
349356

350357
const struct adc_sequence_options options = {
351-
.interval_us = 500UL, /*make this double to sample time*/
358+
.interval_us = 100 * 1000, /* 10 ms - much larger than expected sampling time */
352359
.callback = sample_with_interval_callback,
353360
.extra_samplings = 1,
354361
};
@@ -372,7 +379,7 @@ static int test_task_with_interval(void)
372379
time_stamp = k_uptime_get();
373380
ret = adc_read(adc_dev, &sequence);
374381
milliseconds_spent = k_uptime_delta(&time_stamp);
375-
printk("now spend = %lldms\n", milliseconds_spent);
382+
zassert_true(milliseconds_spent >= (options.interval_us / 1000UL));
376383
zassert_equal(ret, 0, "adc_read() failed with code %d", ret);
377384
}
378385
check_samples2(1 + options.extra_samplings);
@@ -438,7 +445,6 @@ static int test_task_repeated_samplings(void)
438445
*/
439446
.extra_samplings = 2,
440447
/* Start consecutive samplings as fast as possible. */
441-
/* but the interval shall be larger than the HW trigger*/
442448
.interval_us = SAMPLE_INTERVAL_US,
443449
};
444450
const struct adc_sequence sequence = {

0 commit comments

Comments
 (0)