Skip to content

Commit 484f07c

Browse files
jwang11Anas Nashif
authored andcommitted
tests: add zephyr adc driver api test case
the commit test below adc driver api with different resolutions and modes adc_enable() adc_read() adc_disable() move original adc test to adc_simple folder Change-Id: I016b5e67a5d89fc8d5ae76f33799e5d3eb3e1cf8 Signed-off-by: jing wang <[email protected]>
1 parent fde2b3f commit 484f07c

File tree

16 files changed

+182
-2
lines changed

16 files changed

+182
-2
lines changed

tests/drivers/adc/adc_api/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BOARD ?= quark_se_c1000_ss_devboard
2+
CONF_FILE ?= prj_resolution_6.conf
3+
4+
include ${ZEPHYR_BASE}/Makefile.test

tests/drivers/adc/adc_api/README

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This is the test app which test ADC on Quark SE processor.
2+
3+
Default ADC mode is interrupt mode.
4+
The case tests ADC working in different resolutions.
5+
6+
The analog input pin and channel number mapping
7+
for Quark Se Devboard.
8+
A0 Channel 10
9+
A1 Channel 11
10+
A2 Channel 12
11+
A3 Channel 13
12+
A4 Channel 14
13+
14+
This test uses channel 10 to sample the voltage of VCC3.3.
15+
So connect A0 to VCC3.3 and start the APP.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_ADC=y
2+
CONFIG_ZTEST=y
3+
CONFIG_ADC_QMSI_POLL=y
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_ADC=y
2+
CONFIG_ZTEST=y
3+
CONFIG_ADC_QMSI_SAMPLE_WIDTH=9
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_ADC=y
2+
CONFIG_ZTEST=y
3+
CONFIG_ADC_QMSI_SAMPLE_WIDTH=11
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_ADC=y
2+
CONFIG_ZTEST=y
3+
CONFIG_ADC_QMSI_SAMPLE_WIDTH=5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_ADC=y
2+
CONFIG_ZTEST=y
3+
CONFIG_ADC_QMSI_SAMPLE_WIDTH=7
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include $(ZEPHYR_BASE)/tests/Makefile.test
2+
3+
obj-y = main.o test_adc.o
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @addtogroup t_driver_adc
9+
* @{
10+
* @defgroup t_adc_basic test_adc_basic_operations
11+
* @}
12+
*/
13+
14+
extern void test_adc_sample(void);
15+
16+
#include <zephyr.h>
17+
#include <ztest.h>
18+
19+
void test_main(void)
20+
{
21+
ztest_test_suite(adc_basic_test,
22+
ztest_unit_test(test_adc_sample));
23+
ztest_run_test_suite(adc_basic_test);
24+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* @addtogroup test_adc_basic_operations
9+
* @{
10+
* @defgroup t_adc_basic_basic_operations test_adc_sample
11+
* @brief TestPurpose: verify ADC works well with different resolutions
12+
* and sample mode
13+
* @details
14+
* - Test Steps
15+
* -# Connect A0 to VCC3.3.
16+
* -# Prepare ADC sequence table.
17+
* -# Bind ADC device.
18+
* -# Enable ADC device.
19+
* -# Call adc_read() to fetch ADC sample.
20+
* -# Dump the sample results.
21+
* - Expected Results
22+
* -# ADC will return the sample result for VCC3.3. Different resolutions
23+
* will all return almost the biggest value in each sample width.
24+
* @}
25+
*/
26+
27+
#include <adc.h>
28+
#include <zephyr.h>
29+
#include <ztest.h>
30+
31+
#define ADC_DEV_NAME CONFIG_ADC_0_NAME
32+
#define BUFFER_SIZE 5
33+
34+
static uint16_t seq_buffer[BUFFER_SIZE];
35+
36+
static struct adc_seq_entry entry = {
37+
.sampling_delay = 30,
38+
.channel_id = 10,
39+
.buffer = (void *)seq_buffer,
40+
.buffer_length = BUFFER_SIZE * sizeof(seq_buffer[0])
41+
};
42+
43+
static struct adc_seq_table table = {
44+
.entries = &entry,
45+
.num_entries = 1,
46+
};
47+
48+
static int test_task(void)
49+
{
50+
int i;
51+
int ret;
52+
struct device *adc_dev = device_get_binding(ADC_DEV_NAME);
53+
54+
if (!adc_dev) {
55+
TC_PRINT("Cannot get ADC device\n");
56+
return TC_FAIL;
57+
}
58+
59+
/* 1. Verify adc_enable() */
60+
adc_enable(adc_dev);
61+
62+
k_sleep(500);
63+
64+
/* 2. Verify adc_read() */
65+
ret = adc_read(adc_dev, &table);
66+
if (ret != 0) {
67+
TC_PRINT("Failed to fetch sample data from ADC controller\n");
68+
return TC_FAIL;
69+
}
70+
71+
TC_PRINT("Channel 10 ADC Sample: ");
72+
for (i = 0; i < BUFFER_SIZE; i++) {
73+
TC_PRINT("%d ", seq_buffer[i]);
74+
}
75+
TC_PRINT("\n");
76+
77+
/* 3. Verify adc_disable() */
78+
adc_disable(adc_dev);
79+
80+
return TC_PASS;
81+
}
82+
83+
void test_adc_sample(void)
84+
{
85+
assert_true(test_task() == TC_PASS, NULL);
86+
}

0 commit comments

Comments
 (0)