samples: A test app for quark Always-on counter and timer

Test application to test quark Always-on counter and timer.

This app requires QMSI lib which is not in the repo yet.
See the instruction in readme.txt.

Origin: Original

Change-Id: If75b2714f9b609abc6f7b51c1c0d99d15152399f
Signed-off-by: Baohong Liu <baohong.liu@intel.com>
This commit is contained in:
Baohong Liu 2016-03-14 15:01:42 -07:00 committed by Anas Nashif
commit 61064f0c5e
6 changed files with 284 additions and 0 deletions

View file

@ -0,0 +1,5 @@
KERNEL_TYPE = nano
BOARD ?= quark_d2000_crb
CONF_FILE = aon.config
include ${ZEPHYR_BASE}/Makefile.inc

View file

@ -0,0 +1,6 @@
CONFIG_PRINTK=y
CONFIG_COUNTER=y
CONFIG_QMSI_DRIVERS=y
CONFIG_AON_COUNTER_QMSI=y
CONFIG_AON_TIMER_QMSI=y
CONFIG_QMSI_INSTALL_PATH="${ZEPHYR_BASE}/libqmsi/"

View file

@ -0,0 +1,101 @@
Title: Quark Always-on counter and timer test app
Description:
A simple test app to test the AON counter and timer for quark d2000.
--------------------------------------------------------------------------------
Building and Running Project:
make BOARD=quark_d2000_crb
--------------------------------------------------------------------------------
Important note:
This sample app requires QMSI lib which is not in the repo yet.
User needs to get the QMSI source code and compile it with command
like the following.
make SOC=quark_d2000 libqmsi
Then, copy the directory "libqmsi" to the ZEPHYR base directory.
Sample Output:
Always-on counter example app
Always-on counter started
Always-on counter value: 125
Always-on counter value: 218
Always-on counter value: 310
Always-on counter value: 401
Always-on counter value: 493
Always-on counter value: 586
Always-on counter value: 678
Always-on counter value: 769
Always-on counter value: 862
Always-on counter value: 952
Always-on counter value: 1045
Always-on counter value: 1139
Always-on counter value: 1233
Always-on counter value: 1329
Always-on counter value: 1422
Always-on counter value: 1518
Always-on counter value: 1612
Always-on counter value: 1708
Always-on counter value: 1802
Always-on counter value: 1898
Always-on counter does not support alarm!
Always-on counter stopped
Periodic timer example app
Periodic timer started
Periodic timer value: ffffff92
Periodic timer value: ffffff2f
Periodic timer value: fffffecd
Periodic timer value: fffffe6a
Periodic timer value: fffffe09
Periodic timer value: fffffda6
Periodic timer value: fffffd45
Periodic timer value: fffffce4
Periodic timer value: fffffc83
Periodic timer value: fffffc22
Periodic timer value: fffffbc1
Periodic timer value: fffffb5f
Periodic timer value: fffffafc
Periodic timer value: fffffa9a
Periodic timer value: fffffa37
Periodic timer value: fffff9d6
Periodic timer value: fffff973
Periodic timer value: fffff910
Periodic timer value: fffff8ae
Periodic timer value: fffff84d
Periodic Timer alarm on
Periodic timer callback data 30
Periodic timer callback value 9905
Periodic timer callback data 30
Periodic timer callback value 9905
Periodic timer callback data 30
Periodic timer callback value 9903
Periodic timer callback data 30
Periodic timer callback value 9903
Periodic timer alarm off
Periodic timer value: 000026c4
Periodic timer value: 00002661
Periodic timer value: 000025fe
Periodic timer value: 0000259b
Periodic timer value: 00002538
Periodic timer value: 000024d5
Periodic timer value: 00002472
Periodic timer value: 0000240f
Periodic timer value: 000023ac
Periodic timer value: 00002348
Periodic timer value: 000022e5
Periodic timer value: 00002282
Periodic timer value: 0000221f
Periodic timer value: 000021bd
Periodic timer value: 0000215a
Periodic timer value: 000020f7
Periodic timer value: 00002094
Periodic timer value: 00002032
Periodic timer value: 00001fcf
Periodic timer value: 00001f6c
Periodic timer stopped

View file

@ -0,0 +1 @@
obj-y = main.o

View file

@ -0,0 +1,166 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <zephyr.h>
#include <misc/printk.h>
#include <device.h>
#include <counter.h>
static void aonpt_example_callback(struct device *dev, void *user_data);
static void free_running_counter_example(void);
static void periodic_timer_example(void);
void main(void)
{
/* test quark Always-on free running counter */
free_running_counter_example();
/* test quark Always-on periodic timer */
periodic_timer_example();
}
static void free_running_counter_example(void)
{
volatile uint32_t delay = 0;
uint32_t c_val = 0, i = 0;
uint32_t dummy_data = 30;
uint32_t counter_initial_value = 10000;
struct device *aon_counter_dev;
aon_counter_dev = device_get_binding("AON_COUNTER");
if (!aon_counter_dev) {
printk("Counter device not found\n");
return;
}
printk("Always-on free running counter example app\n");
if (counter_start(aon_counter_dev) != DEV_OK) {
printk("Counter device enabling fail!\n");
return;
}
printk("Always-on counter started\n");
/* The AON counter runs from the RTC clock at 32KHz (rather than
* the system clock which is 32MHz) so we need to spin for a few cycles
* allow the register change to propagate.
*/
for (delay = 5000; delay--;) {
}
for (i = 0; i < 20; i++) {
for (delay = 500; delay--;) {
}
c_val = counter_read(aon_counter_dev);
printk("Always-on counter value: %d\n", c_val);
}
if (counter_set_alarm(aon_counter_dev, NULL, counter_initial_value,
(void *)&dummy_data) != DEV_OK) {
printk("Always-on counter does not support alarm!\n");
}
counter_stop(aon_counter_dev);
printk("Always-on counter stopped\n");
}
static void periodic_timer_example(void)
{
volatile uint32_t delay = 0;
uint32_t pt_val = 0, i = 0;
uint32_t dummy_data = 30;
uint32_t timer_initial_value = 10000;
struct device *aon_periodic_timer_dev = NULL;
aon_periodic_timer_dev = device_get_binding("AON_TIMER");
if (!aon_periodic_timer_dev) {
printk("Timer device not found\n");
return;
}
printk("Periodic timer example app\n");
counter_start(aon_periodic_timer_dev);
printk("Periodic timer started\n");
/* The AON timer runs from the RTC clock at 32KHz (rather than
* the system clock which is 32MHz) so we need to spin for a few cycles
* allow the register change to propagate.
*/
for (delay = 5000; delay--;) {
}
for (i = 0; i < 20; i++) {
for (delay = 500; delay--;) {
}
pt_val = counter_read(aon_periodic_timer_dev);
printk("Periodic timer value: %x\n", pt_val);
}
if (counter_set_alarm(aon_periodic_timer_dev, aonpt_example_callback,
timer_initial_value, (void *)&dummy_data)
!= DEV_OK) {
printk("Periodic Timer was not started yet\n");
return;
}
printk("Periodic Timer alarm on\n");
/* long delay for the alarm and callback to happen */
for (delay = 5000000; delay--;) {
}
/* callback is turned off */
if (counter_set_alarm(aon_periodic_timer_dev, NULL,
timer_initial_value, (void *)&dummy_data)
!= DEV_OK) {
printk("Periodic timer was not started yet\n");
return;
}
printk("Periodic timer alarm off\n");
for (i = 0; i < 20; i++) {
for (delay = 500; delay--;) {
}
pt_val = counter_read(aon_periodic_timer_dev);
printk("Periodic timer value: %x\n", pt_val);
}
counter_stop(aon_periodic_timer_dev);
printk("Periodic timer stopped\n");
}
static void aonpt_example_callback(struct device *dev, void *user_data)
{
printk("Periodic timer callback data %d\n", *((uint32_t *)user_data));
printk("Periodic timer callback value %d\n", counter_read(dev));
}

View file

@ -0,0 +1,5 @@
[test]
skip = true
tags = apps
build_only = true
platform_whitelist = quark_d2000_crb