apps/examples/zerocross: Add a Zero Cross application example. From Alan Carvalho de Assis
This commit is contained in:
parent
d538f48797
commit
825b721dfa
@ -1441,4 +1441,5 @@
|
||||
essentially the same as examples/smart, but has all of the SmartFS
|
||||
specific logic ripped out. This was created for testing the new
|
||||
tmpfs (2015-10-10).
|
||||
|
||||
* apps/examples/zerocross: Add a Zero Cross application example.
|
||||
From Alan Carvalho de Assis (2015-10-13).
|
||||
|
@ -89,5 +89,6 @@ source "$APPSDIR/examples/watchdog/Kconfig"
|
||||
source "$APPSDIR/examples/wget/Kconfig"
|
||||
source "$APPSDIR/examples/wgetjson/Kconfig"
|
||||
source "$APPSDIR/examples/xmlrpc/Kconfig"
|
||||
source "$APPSDIR/examples/zerocross/Kconfig"
|
||||
|
||||
endmenu # Examples
|
||||
|
@ -2250,3 +2250,8 @@ examples/xmlrpc
|
||||
Default 0x0a000001. Ignored if CONFIG_NSH_BUILTIN_APPS is selected.
|
||||
CONFIG_EXAMPLES_XMLRPC_NETMASK - Network Mask. Default 0xffffff00
|
||||
Ignored if CONFIG_NSH_BUILTIN_APPS is selected.
|
||||
|
||||
examples/zerocross
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
A simple test of the Zero Crossing device driver.
|
||||
|
11
examples/zerocross/.gitignore
vendored
Normal file
11
examples/zerocross/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.context
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
23
examples/zerocross/Kconfig
Normal file
23
examples/zerocross/Kconfig
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_ZEROCROSS
|
||||
bool "Zero Cross Detection example"
|
||||
default n
|
||||
depends on ZEROCROSS && !DISABLE_SIGNALS
|
||||
---help---
|
||||
Enable the zero cross detection example
|
||||
|
||||
if EXAMPLES_ZEROCROSS
|
||||
|
||||
config EXAMPLES_ZEROCROSS_DEVNAME
|
||||
string "Zero Cross device name"
|
||||
default "/dev/zc0"
|
||||
|
||||
config EXAMPLES_ZEROCROSS_SIGNO
|
||||
int "Zero Cross signal"
|
||||
default 13
|
||||
|
||||
endif
|
39
examples/zerocross/Make.defs
Normal file
39
examples/zerocross/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/zerocross/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_ZEROCROSS),y)
|
||||
CONFIGURED_APPS += examples/zerocross
|
||||
endif
|
53
examples/zerocross/Makefile
Normal file
53
examples/zerocross/Makefile
Normal file
@ -0,0 +1,53 @@
|
||||
############################################################################
|
||||
# apps/examples/zerocross/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)/Make.defs
|
||||
|
||||
# Zero Cross Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = zerocross_main.c
|
||||
|
||||
CONFIG_ZEROCROSS_PROGNAME ?= zerocross$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_ZEROCROSS_PROGNAME)
|
||||
|
||||
# Buttons built-in application info
|
||||
|
||||
APPNAME = zerocross
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
include $(APPDIR)/Application.mk
|
148
examples/zerocross/zerocross_main.c
Normal file
148
examples/zerocross/zerocross_main.c
Normal file
@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
* examplex/zerocross/zerocross_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 <debug.h>
|
||||
|
||||
#include <nuttx/sensors/zerocross.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_ZEROCROSS
|
||||
# error "CONFIG_ZEROCROSS is not defined in the configuration"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_ZEROCROSS_DEVNAME
|
||||
# define CONFIG_EXAMPLES_ZEROCROSS_DEVNAME "/dev/zc0"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_ZEROCROSS_SIGNO
|
||||
# define CONFIG_EXAMPLES_ZEROCROSS_SIGNO 13
|
||||
#endif
|
||||
|
||||
/* Helpers ******************************************************************/
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) (a < b ? a : b)
|
||||
#endif
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) (a > b ? a : b)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* zerocross_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int zerocross_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
struct zc_notify_s notify;
|
||||
int fd;
|
||||
int tmp;
|
||||
int ret;
|
||||
int err = EXIT_FAILURE;
|
||||
|
||||
/* Open the zerocross device */
|
||||
|
||||
fd = open(CONFIG_EXAMPLES_ZEROCROSS_DEVNAME, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to open %s: %d\n",
|
||||
CONFIG_EXAMPLES_ZEROCROSS_DEVNAME, errno);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Register to receive a signal on every zero cross event */
|
||||
|
||||
notify.zc_signo = CONFIG_EXAMPLES_ZEROCROSS_SIGNO;
|
||||
|
||||
ret = ioctl(fd, ZCIOC_REGISTER, (unsigned long)((uintptr_t)¬ify));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ioctl(ZCIOC_REGISTER) failed: %d\n", errno);
|
||||
goto errout_with_fd;
|
||||
}
|
||||
|
||||
/* Then loop, receiving signals indicating zero cross events. */
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
struct siginfo value;
|
||||
sigset_t set;
|
||||
ssize_t nread;
|
||||
|
||||
/* Wait for a signal */
|
||||
|
||||
(void)sigemptyset(&set);
|
||||
(void)sigaddset(&set, CONFIG_EXAMPLES_ZEROCROSS_SIGNO);
|
||||
ret = sigwaitinfo(&set, &value);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errno);
|
||||
goto errout_with_fd;
|
||||
}
|
||||
|
||||
/* Show the value accompanying the signal */
|
||||
|
||||
printf("Signal received!\n");
|
||||
printf("Sample = %d\n", value.si_value.sival_int);
|
||||
}
|
||||
|
||||
err = EXIT_SUCCESS;
|
||||
|
||||
errout_with_fd:
|
||||
close(fd);
|
||||
return err;
|
||||
}
|
Loading…
Reference in New Issue
Block a user