summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-13 12:57:26 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-13 12:57:26 -0600
commit6ac92b4ccedc22e87d31db846c8ea16fc5f96ae9 (patch)
tree3c52ab9a6ad48864b9609ee768782aa13e289a33
parent539679ea1af06dfa26c117023807bf4cb46eb8bf (diff)
downloadpx4-nuttx-6ac92b4ccedc22e87d31db846c8ea16fc5f96ae9.tar.gz
px4-nuttx-6ac92b4ccedc22e87d31db846c8ea16fc5f96ae9.tar.bz2
px4-nuttx-6ac92b4ccedc22e87d31db846c8ea16fc5f96ae9.zip
apps/exemples/timer: Add a trivial test of the timer driver
-rw-r--r--apps/examples/Kconfig1
-rw-r--r--apps/examples/Make.defs4
-rw-r--r--apps/examples/Makefile6
-rw-r--r--apps/examples/README.txt25
-rw-r--r--apps/examples/timer/.gitignore11
-rw-r--r--apps/examples/timer/Kconfig68
-rw-r--r--apps/examples/timer/Makefile140
-rw-r--r--apps/examples/timer/timer_main.c192
8 files changed, 444 insertions, 3 deletions
diff --git a/apps/examples/Kconfig b/apps/examples/Kconfig
index 9acffdfd8..6714e6351 100644
--- a/apps/examples/Kconfig
+++ b/apps/examples/Kconfig
@@ -67,6 +67,7 @@ source "$APPSDIR/examples/smart/Kconfig"
source "$APPSDIR/examples/tcpecho/Kconfig"
source "$APPSDIR/examples/telnetd/Kconfig"
source "$APPSDIR/examples/thttpd/Kconfig"
+source "$APPSDIR/examples/timer/Kconfig"
source "$APPSDIR/examples/tiff/Kconfig"
source "$APPSDIR/examples/touchscreen/Kconfig"
source "$APPSDIR/examples/udp/Kconfig"
diff --git a/apps/examples/Make.defs b/apps/examples/Make.defs
index b7a73da15..2c23a68e6 100644
--- a/apps/examples/Make.defs
+++ b/apps/examples/Make.defs
@@ -298,6 +298,10 @@ ifeq ($(CONFIG_EXAMPLES_TIFF),y)
CONFIGURED_APPS += examples/tiff
endif
+ifeq ($(CONFIG_EXAMPLES_TIMER),y)
+CONFIGURED_APPS += examples/timer
+endif
+
ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN),y)
CONFIGURED_APPS += examples/touchscreen
endif
diff --git a/apps/examples/Makefile b/apps/examples/Makefile
index 9b1445716..8d39c1a5f 100644
--- a/apps/examples/Makefile
+++ b/apps/examples/Makefile
@@ -44,8 +44,8 @@ SUBDIRS += mtdpart mtdrwb netpkt nettest nrf24l01_term nsh null nx nxterm
SUBDIRS += nxffs nxflat nxhello nximage nxlines nxtext ostest pashello pipe
SUBDIRS += poll posix_spawn pwm qencoder random relays rgmp romfs sendmail
SUBDIRS += serialblaster serloop serialrx slcd smart smart_test tcpecho
-SUBDIRS += telnetd thttpd tiff touchscreen udp usbserial usbterm watchdog
-SUBDIRS += webserver wget wgetjson xmlrpc
+SUBDIRS += telnetd thttpd tiff timer touchscreen udp usbserial usbterm
+SUBDIRS += watchdog webserver wget wgetjson xmlrpc
# Sub-directories that might need context setup. Directories may need
# context setup for a variety of reasons, but the most common is because
@@ -59,7 +59,7 @@ CNTXTDIRS += djoystick flash_test ftpd hello helloxx i2schar json keypadtest
CNTXTDIRS += ltdc modbus lcdrw mtdpart mtdrwb netpkt nettest nx nxhello
CNTXTDIRS += nximage nxlines nxtext nrf24l01_term ostest random relays
CNTXTDIRS += qencoder serialblasters lcd serialrx smart_test tcpecho telnetd
-CNTXTDIRS += tiff touchscreen usbterm watchdog wgetjson
+CNTXTDIRS += tiff timer touchscreen usbterm watchdog wgetjson
endif
all: nothing
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index 05c51e25b..13586419b 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -1750,6 +1750,31 @@ examples/tiff
CONFIG_EXAMPLES_TIFF=y
CONFIG_GRAPHICS_TIFF=y
+examples/timer
+^^^^^^^^^^^^^^
+
+ This is a simple test of the timer driver (see include/nuttx/timer.h).
+
+ Dependencies:
+ CONFIG_TIMER - The timer driver must be selected
+
+ Example configuration:
+
+ CONFIG_EXAMPLE_TIMER_DEVNAME - This is the name of the timer device that
+ will be tested. Default: "/dev/timer0"
+ CONFIG_EXAMPLE_TIMER_INTERVAL - This is the timer interval in
+ microseconds. Default: 1000000
+ CONFIG_EXAMPLE_TIMER_DELAY - This is the delay between timer samples in
+ microseconds. Default: 10000
+ CONFIG_EXAMPLES_TIMER_APPNAME - This is the name of the built-in
+ application: Default: "timer"
+ CONFIG_EXAMPLES_TIMER_STACKSIZE - This is the stack size allocated when
+ the timer task runs. Default: 2048
+ CONFIG_EXAMPLES_TIMER_PRIORITY - This is the priority of the timer task:
+ Default: 100
+ CONFIG_EXAMPLES_TIMER_PROGNAME - This is the name of the program that
+ will be use when the NSH ELF program is installed. Default: "timer"
+
examples/touchscreen
^^^^^^^^^^^^^^^^^^^^
diff --git a/apps/examples/timer/.gitignore b/apps/examples/timer/.gitignore
new file mode 100644
index 000000000..fa1ec7579
--- /dev/null
+++ b/apps/examples/timer/.gitignore
@@ -0,0 +1,11 @@
+/Make.dep
+/.depend
+/.built
+/*.asm
+/*.obj
+/*.rel
+/*.lst
+/*.sym
+/*.adb
+/*.lib
+/*.src
diff --git a/apps/examples/timer/Kconfig b/apps/examples/timer/Kconfig
new file mode 100644
index 000000000..9c3ae7ce3
--- /dev/null
+++ b/apps/examples/timer/Kconfig
@@ -0,0 +1,68 @@
+#
+# For a description of the syntax of this configuration file,
+# see misc/tools/kconfig-language.txt.
+#
+
+config EXAMPLES_TIMER
+ bool "Timer example"
+ default n
+ depends on TIMER
+ ---help---
+ Enable the \"Timer, World!\" example
+
+if EXAMPLES_TIMER
+
+config EXAMPLE_TIMER_DEVNAME
+ string "Timer device name"
+ default "/dev/timer0"
+ ---help---
+ This is the name of the timer device that will be tested.
+
+config EXAMPLE_TIMER_INTERVAL
+ int "Timer interval (microseconds)"
+ default 1000000
+ ---help---
+ This is the timer interval in microseconds.
+
+config EXAMPLE_TIMER_DELAY
+ int "Sample delay (microseconds)"
+ default 100000
+ ---help---
+ This is the delay between timer samples in microseconds
+
+config EXAMPLE_TIMER_NSAMPLES
+ int "Number of samples"
+ default 20
+ ---help---
+ This is the number of timer samples that will be collected
+
+config EXAMPLES_TIMER_APPNAME
+ string "Timer executable name"
+ default "timer"
+ depends on NSH_BUILTIN_APPS
+ ---help---
+ This is the name of the built-in application
+
+config EXAMPLES_TIMER_STACKSIZE
+ int "Timer stack size"
+ default 2048
+ depends on NSH_BUILTIN_APPS
+ ---help---
+ This is the stack size allocated when the timer task runs
+
+config EXAMPLES_TIMER_PRIORITY
+ int "Timer task priority"
+ default 100
+ depends on NSH_BUILTIN_APPS
+ ---help---
+ This is the priority of the timer task
+
+config EXAMPLES_TIMER_PROGNAME
+ string "Timer program name"
+ default "timer"
+ depends on BUILD_KERNEL
+ ---help---
+ This is the name of the program that will be use when the NSH ELF
+ program is installed.
+
+endif
diff --git a/apps/examples/timer/Makefile b/apps/examples/timer/Makefile
new file mode 100644
index 000000000..dfbca4635
--- /dev/null
+++ b/apps/examples/timer/Makefile
@@ -0,0 +1,140 @@
+############################################################################
+# apps/examples/timer/Makefile
+#
+# Copyright (C) 2015 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# 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 NuttX 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 OWNER 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 $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+# Timer built-in application info
+
+CONFIG_EXAMPLES_TIMER_APPNAME ?= "timer"
+CONFIG_EXAMPLES_TIMER_STACKSIZE ?= 2048
+CONFIG_EXAMPLES_TIMER_PRIORITY ?= 100
+CONFIG_EXAMPLES_TIMER_PROGNAME ?= "timer"
+
+APPNAME = $(CONFIG_EXAMPLES_TIMER_APPNAME)
+PRIORITY = $(CONFIG_EXAMPLES_TIMER_PRIORITY)
+STACKSIZE = $(CONFIG_EXAMPLES_TIMER_STACKSIZE)
+PROGNAME = $(CONFIG_EXAMPLES_TIMER_PROGNAME)
+
+# Timer, World! Example
+
+ASRCS =
+CSRCS =
+MAINSRC = timer_main.c
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
+OBJS = $(AOBJS) $(COBJS)
+
+ifneq ($(CONFIG_BUILD_KERNEL),y)
+ OBJS += $(MAINOBJ)
+endif
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
+ifeq ($(WINTOOL),y)
+ BIN = ..\\..\\libapps$(LIBEXT)
+else
+ BIN = ../../libapps$(LIBEXT)
+endif
+endif
+
+ifeq ($(WINTOOL),y)
+ INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
+else
+ INSTALL_DIR = $(BIN_DIR)
+endif
+
+ROOTDEPPATH = --dep-path .
+
+# Common build
+
+VPATH =
+
+all: .built
+.PHONY: clean depend distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+.built: $(OBJS)
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ @touch .built
+
+ifeq ($(CONFIG_BUILD_KERNEL),y)
+$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
+ @echo "LD: $(PROGNAME)"
+ $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
+ $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
+
+install: $(BIN_DIR)$(DELIM)$(PROGNAME)
+
+else
+install:
+
+endif
+
+ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
+$(BUILTIN_REGISTRY)$(DELIM)timer_main.bdat: $(DEPCONFIG) Makefile
+ $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),timer_main)
+
+context: $(BUILTIN_REGISTRY)$(DELIM)timer_main.bdat
+else
+context:
+endif
+
+.depend: Makefile $(SRCS)
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @touch $@
+
+depend: .depend
+
+clean:
+ $(call DELFILE, .built)
+ $(call CLEAN)
+
+distclean: clean
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+
+-include Make.dep
diff --git a/apps/examples/timer/timer_main.c b/apps/examples/timer/timer_main.c
new file mode 100644
index 000000000..ed1219447
--- /dev/null
+++ b/apps/examples/timer/timer_main.c
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * examples/timer/timer_main.c
+ *
+ * Copyright (C) 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 NuttX 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 OWNER 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <nuttx/timer.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLE_TIMER_DEVNAME
+# define CONFIG_EXAMPLE_TIMER_DEVNAME "/dev/timer0"
+#endif
+
+#ifndef CONFIG_EXAMPLE_TIMER_INTERVAL
+# define CONFIG_EXAMPLE_TIMER_INTERVAL 1000000
+#endif
+
+#ifndef CONFIG_EXAMPLE_TIMER_DELAY
+# define CONFIG_EXAMPLE_TIMER_DELAY 100000
+#endif
+
+#ifndef CONFIG_EXAMPLE_TIMER_NSAMPLES
+# define CONFIG_EXAMPLE_TIMER_NSAMPLES 20
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * timer_status
+ ****************************************************************************/
+
+static void timer_status(int fd)
+{
+ struct timer_status_s status;
+ int ret;
+
+ /* Get timer status */
+
+ ret = ioctl(fd, TCIOC_GETSTATUS, (unsigned long)((uintptr_t)&status));
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: Failed to get timer status: %d\n", errno);
+ close(fd);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Print the timer status */
+
+ printf(" flags: %08lx timeout: %lu timeleft: %lu\n",
+ (unsigned long)status.flags, (unsigned long)status.timeout,
+ (unsigned long)status.timeleft);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * timer_main
+ ****************************************************************************/
+
+#ifdef CONFIG_BUILD_KERNEL
+int main(int argc, FAR char *argv[])
+#else
+int timer_main(int argc, char *argv[])
+#endif
+{
+ int ret;
+ int fd;
+ int i;
+
+ /* Open the timer device */
+
+ printf("Open %s\n", CONFIG_EXAMPLE_TIMER_DEVNAME);
+
+ fd = open(CONFIG_EXAMPLE_TIMER_DEVNAME, O_RDONLY);
+ if (fd < 0)
+ {
+ fprintf(stderr, "ERROR: Failed to open %s: %d\n",
+ CONFIG_EXAMPLE_TIMER_DEVNAME, errno);
+ return EXIT_FAILURE;
+ }
+
+ /* Show the timer status before setting the timer interval */
+
+ timer_status(fd);
+
+ /* Set the timer interval */
+
+ printf("Set timer interval to %lu\n",
+ (unsigned long)CONFIG_EXAMPLE_TIMER_INTERVAL);
+
+ ret = ioctl(fd, TCIOC_SETTIMEOUT, CONFIG_EXAMPLE_TIMER_INTERVAL);
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: Failed to set the timer interval: %d\n", errno);
+ close(fd);
+ return EXIT_FAILURE;
+ }
+
+ /* Show the timer status before starting */
+
+ timer_status(fd);
+
+ /* Start the timer */
+
+ printf("Start the timer\n");
+
+ ret = ioctl(fd, TCIOC_START, 0);
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: Failed to start the timer: %d\n", errno);
+ close(fd);
+ return EXIT_FAILURE;
+ }
+
+ /* Wait a bit showing timer status */
+
+ for (i = 0; i < CONFIG_EXAMPLE_TIMER_NSAMPLES; i++)
+ {
+ usleep(CONFIG_EXAMPLE_TIMER_DELAY);
+ timer_status(fd);
+ }
+
+ /* Stop the timer */
+
+ printf("Stop the timer\n");
+
+ ret = ioctl(fd, TCIOC_STOP, 0);
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: Failed to stop the timer: %d\n", errno);
+ close(fd);
+ return EXIT_FAILURE;
+ }
+
+ /* Show the timer status before starting */
+
+ timer_status(fd);
+
+ /* Close the timer driver */
+
+ printf("Finished\n");
+ close(fd);
+ return EXIT_SUCCESS;
+}