samples: Add a tiny test application for ADC API
Currently useful only for Galileo. Change-Id: I8d4fafd530e11a50f91cedd0de1691393f270b9c Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
5fbf815419
commit
27e8c5beb2
5 changed files with 137 additions and 0 deletions
5
samples/nanokernel/apps/adc/Makefile
Normal file
5
samples/nanokernel/apps/adc/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
PLATFORM_CONFIG = galileo
|
||||
KERNEL_TYPE = nano
|
||||
CONF_FILE = prj_$(ARCH).conf
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
4
samples/nanokernel/apps/adc/prj_x86.conf
Normal file
4
samples/nanokernel/apps/adc/prj_x86.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
CONFIG_PCI_DEBUG=y
|
||||
|
||||
CONFIG_ADC=y
|
||||
CONFIG_ADC_DEBUG=y
|
3
samples/nanokernel/apps/adc/src/Makefile
Normal file
3
samples/nanokernel/apps/adc/src/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
ccflags-y += -I${ZEPHYR_BASE}/include/drivers
|
||||
|
||||
obj-y = adc.o
|
119
samples/nanokernel/apps/adc/src/adc.c
Normal file
119
samples/nanokernel/apps/adc/src/adc.c
Normal file
|
@ -0,0 +1,119 @@
|
|||
/* adc.c - ADC test source file */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1) Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2) Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3) Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <nanokernel.h>
|
||||
#include <arch/cpu.h>
|
||||
|
||||
#include <device.h>
|
||||
#include <misc/byteorder.h>
|
||||
#include <adc.h>
|
||||
|
||||
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||
#include <stdio.h>
|
||||
#define DBG printf
|
||||
#else
|
||||
#include <misc/printk.h>
|
||||
#define DBG printk
|
||||
#endif
|
||||
|
||||
#define SLEEPTIME 10
|
||||
#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec)
|
||||
|
||||
static int cb_count;
|
||||
|
||||
static uint8_t seq_buffer[100];
|
||||
static struct adc_seq_entry sample = {
|
||||
.sampling_delay = 1,
|
||||
.channel_id = 0,
|
||||
.buffer = seq_buffer,
|
||||
.buffer_length = 100,
|
||||
};
|
||||
|
||||
static struct adc_seq_table table = {
|
||||
.entries = &sample,
|
||||
.num_entries = 1,
|
||||
};
|
||||
|
||||
static void _print_sample_in_hex(uint8_t *buf, uint32_t length)
|
||||
{
|
||||
DBG("Buffer content:\n");
|
||||
for (; length > 0; length -= 2, buf += 2) {
|
||||
DBG("0x%x ", *((uint16_t *)buf));
|
||||
}
|
||||
}
|
||||
|
||||
static void callback(struct device *dev, enum adc_callback_type cb_type)
|
||||
{
|
||||
DBG("ADC callback %d - type %d\n", cb_count++, cb_type);
|
||||
|
||||
if (cb_type == ADC_CB_DONE) {
|
||||
DBG("Sampling is done\n");
|
||||
_print_sample_in_hex(seq_buffer, 100);
|
||||
} else {
|
||||
DBG("Sampling could not proceed, an error occurred\n");
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
struct device *adc;
|
||||
struct nano_timer timer;
|
||||
uint32_t data[2] = {0, 0};
|
||||
|
||||
cb_count = 0;
|
||||
|
||||
nano_timer_init(&timer, data);
|
||||
|
||||
adc = device_get_binding(CONFIG_ADC_TI_ADC108S102_0_DRV_NAME);
|
||||
if (!adc) {
|
||||
DBG("Cannot get adc controller\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
adc_set_callback(adc, callback);
|
||||
|
||||
adc_enable(adc);
|
||||
|
||||
adc_disable(adc);
|
||||
|
||||
if (adc_read(adc, &table) != DEV_OK) {
|
||||
DBG("Could not call adc_read\n");
|
||||
}
|
||||
|
||||
done:
|
||||
while (1) {
|
||||
DBG("Waiting...");
|
||||
|
||||
nano_task_timer_start(&timer, SLEEPTICKS);
|
||||
nano_task_timer_wait(&timer);
|
||||
}
|
||||
}
|
6
samples/nanokernel/apps/adc/testcase.ini
Normal file
6
samples/nanokernel/apps/adc/testcase.ini
Normal file
|
@ -0,0 +1,6 @@
|
|||
[test]
|
||||
build_only = true
|
||||
tags = apps
|
||||
|
||||
arch_whitelist = x86
|
||||
platform_whitelist = galileo
|
Loading…
Add table
Add a link
Reference in a new issue