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 <jing.j.wang@intel.com>
This commit is contained in:
jing wang 2017-01-10 17:00:08 +08:00 committed by Anas Nashif
commit 484f07cec7
16 changed files with 182 additions and 2 deletions

View file

@ -0,0 +1,4 @@
BOARD ?= quark_se_c1000_ss_devboard
CONF_FILE ?= prj_resolution_6.conf
include ${ZEPHYR_BASE}/Makefile.test

View file

@ -0,0 +1,15 @@
This is the test app which test ADC on Quark SE processor.
Default ADC mode is interrupt mode.
The case tests ADC working in different resolutions.
The analog input pin and channel number mapping
for Quark Se Devboard.
A0 Channel 10
A1 Channel 11
A2 Channel 12
A3 Channel 13
A4 Channel 14
This test uses channel 10 to sample the voltage of VCC3.3.
So connect A0 to VCC3.3 and start the APP.

View file

@ -0,0 +1,3 @@
CONFIG_ADC=y
CONFIG_ZTEST=y
CONFIG_ADC_QMSI_POLL=y

View file

@ -0,0 +1,3 @@
CONFIG_ADC=y
CONFIG_ZTEST=y
CONFIG_ADC_QMSI_SAMPLE_WIDTH=9

View file

@ -0,0 +1,3 @@
CONFIG_ADC=y
CONFIG_ZTEST=y
CONFIG_ADC_QMSI_SAMPLE_WIDTH=11

View file

@ -0,0 +1,3 @@
CONFIG_ADC=y
CONFIG_ZTEST=y
CONFIG_ADC_QMSI_SAMPLE_WIDTH=5

View file

@ -0,0 +1,3 @@
CONFIG_ADC=y
CONFIG_ZTEST=y
CONFIG_ADC_QMSI_SAMPLE_WIDTH=7

View file

@ -0,0 +1,3 @@
include $(ZEPHYR_BASE)/tests/Makefile.test
obj-y = main.o test_adc.o

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @addtogroup t_driver_adc
* @{
* @defgroup t_adc_basic test_adc_basic_operations
* @}
*/
extern void test_adc_sample(void);
#include <zephyr.h>
#include <ztest.h>
void test_main(void)
{
ztest_test_suite(adc_basic_test,
ztest_unit_test(test_adc_sample));
ztest_run_test_suite(adc_basic_test);
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* @addtogroup test_adc_basic_operations
* @{
* @defgroup t_adc_basic_basic_operations test_adc_sample
* @brief TestPurpose: verify ADC works well with different resolutions
* and sample mode
* @details
* - Test Steps
* -# Connect A0 to VCC3.3.
* -# Prepare ADC sequence table.
* -# Bind ADC device.
* -# Enable ADC device.
* -# Call adc_read() to fetch ADC sample.
* -# Dump the sample results.
* - Expected Results
* -# ADC will return the sample result for VCC3.3. Different resolutions
* will all return almost the biggest value in each sample width.
* @}
*/
#include <adc.h>
#include <zephyr.h>
#include <ztest.h>
#define ADC_DEV_NAME CONFIG_ADC_0_NAME
#define BUFFER_SIZE 5
static uint16_t seq_buffer[BUFFER_SIZE];
static struct adc_seq_entry entry = {
.sampling_delay = 30,
.channel_id = 10,
.buffer = (void *)seq_buffer,
.buffer_length = BUFFER_SIZE * sizeof(seq_buffer[0])
};
static struct adc_seq_table table = {
.entries = &entry,
.num_entries = 1,
};
static int test_task(void)
{
int i;
int ret;
struct device *adc_dev = device_get_binding(ADC_DEV_NAME);
if (!adc_dev) {
TC_PRINT("Cannot get ADC device\n");
return TC_FAIL;
}
/* 1. Verify adc_enable() */
adc_enable(adc_dev);
k_sleep(500);
/* 2. Verify adc_read() */
ret = adc_read(adc_dev, &table);
if (ret != 0) {
TC_PRINT("Failed to fetch sample data from ADC controller\n");
return TC_FAIL;
}
TC_PRINT("Channel 10 ADC Sample: ");
for (i = 0; i < BUFFER_SIZE; i++) {
TC_PRINT("%d ", seq_buffer[i]);
}
TC_PRINT("\n");
/* 3. Verify adc_disable() */
adc_disable(adc_dev);
return TC_PASS;
}
void test_adc_sample(void)
{
assert_true(test_task() == TC_PASS, NULL);
}

View file

@ -0,0 +1,29 @@
[test_adc_arc_resolution_6]
tags = drivers
arch_whitelist = arc
extra_args = CONF_FILE=prj_resolution_6.conf
platform_whitelist = quark_se_c1000_devboard arduino_101
[test_adc_arc_resolution_8]
tags = drivers
arch_whitelist = arc
extra_args = CONF_FILE=prj_resolution_8.conf
platform_whitelist = quark_se_c1000_devboard arduino_101
[test_adc_arc_resolution_10]
tags = drivers
arch_whitelist = arc
extra_args = CONF_FILE=prj_resolution_10.conf
platform_whitelist = quark_se_c1000_devboard arduino_101
[test_adc_arc_resolution_12]
tags = drivers
arch_whitelist = arc
extra_args = CONF_FILE=prj_resolution_12.conf
platform_whitelist = quark_se_c1000_devboard arduino_101
[test_adc_arc_poll_mode]
tags = drivers
arch_whitelist = arc
extra_args = CONF_FILE=prj_poll_mode.conf
platform_whitelist = quark_se_c1000_devboard arduino_101

View file

@ -1,10 +1,14 @@
/* adc.c - ADC test source file */
/*
* Copyright (c) 2015 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ztest.h>
#include <device.h>