Merged nuttx/apps into master
This commit is contained in:
commit
486967227e
51
COPYING
51
COPYING
@ -80,6 +80,17 @@ 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.
|
||||
|
||||
Mini Basic
|
||||
^^^^^^^^^^
|
||||
|
||||
The Mini Basic implementation at apps/interpreters derives from version 1.0
|
||||
by Malcolm McLean, Leeds University, and was released under the Creative
|
||||
Commons Attibution license. I am not legal expert, but this license
|
||||
appears to be compatible with the NuttX BSD license see:
|
||||
https://creativecommons.org/licenses/ . I, however, cannot take
|
||||
responsibility for any actions that you might take based on my
|
||||
understanding. Please use your own legal judgement.
|
||||
|
||||
THTTPD
|
||||
^^^^^^
|
||||
|
||||
@ -135,3 +146,43 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
apps/netutils/pppd
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This implementation of PPPD has a license that is mostly compatible the
|
||||
NuttX 3-clause BSD license, but includes a fourth clause that required
|
||||
acknowledgement of Mike Johnson/Mycal Labs if it is built into your
|
||||
product:
|
||||
|
||||
Copyright (C) 2000, Mycal Labs www.mycal.com
|
||||
Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
All rights reserved.
|
||||
|
||||
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. All advertising materials mentioning features or use of this software
|
||||
must display the following acknowledgement:
|
||||
This product includes software developed by Mike Johnson/Mycal Labs
|
||||
www.mycal.net.
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
|
@ -1338,7 +1338,7 @@
|
||||
replaced with the NSH uname command (2015-07-04).
|
||||
* apps/syste/netdb: Add a command to access the network database
|
||||
(2015-07-08).
|
||||
* apps/netuils/dnsclient and include/netutils/dnsclient.h: Move the
|
||||
* apps/netutils/dnsclient and include/netutils/dnsclient.h: Move the
|
||||
DNS client logic into the NuttX C library. It is a necessary part
|
||||
for the full implementation of the netdb logic and provides more
|
||||
flexibility in that location (2015-07-10).
|
||||
@ -1605,7 +1605,7 @@
|
||||
path by providing an alternal path on the command line. From Sébastien
|
||||
Lorquet (2016-06-01).
|
||||
|
||||
7.17 2016-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||
7.17 2016-07-25 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/alarm: ioctl call was clobbering file descriptor
|
||||
(2016-06-02).
|
||||
@ -1631,11 +1631,11 @@
|
||||
in NSH network startup logic. From David S. Alessio (2016-06-09) .
|
||||
* Rearrange make to eliminate Kmenu files From Sebastien Lorquet
|
||||
(2016-06-09).
|
||||
* apps/nshlib: ake NSH net-initialization be a configuration option.
|
||||
* apps/nshlib: Make NSH net-initialization be a configuration option.
|
||||
From Marten Svanfeldt (2016-06-09).
|
||||
* Make sure that APPNAME is defined in all Makefiles that generate
|
||||
applications. From Sebastien Lorquet (2016-06-09).
|
||||
* apps/netutils/esp8266/: Add logic to set the BAUD rate. From Pierr-
|
||||
* apps/netutils/esp8266/: Add logic to set the BAUD rate. From Pierre-
|
||||
noel Bouteville (2016-06-11).
|
||||
* apps/netutils/esp8266/: CONFIG_SERIAL_TERMIOS must be defined in
|
||||
order to set BAUD (2016-06-11).
|
||||
@ -1653,5 +1653,92 @@
|
||||
apps/. From Alan Carvalho de Assis (2016-06-23).
|
||||
* apps/canutils/canlib: Basic CAN utility library. From Sebastien Lorquet
|
||||
(2016-06-24).
|
||||
* apps/nshlib/Kconfig: Move NSH stuff out of nuttx/configs/Kconfig to
|
||||
here. Why was it in the NuttX tree in the first place? (2016-06-24).
|
||||
* apps/nshlib/Kconfig: Move some NSH settings out of nuttx/configs/Kconfig
|
||||
to here. Why was it in the NuttX tree (2016-06-24).
|
||||
* apps/platform/olimex-stm32-e407: Add platform files for Olimex STM32
|
||||
E407. From Mateusz Szafoni (2016-06-27).
|
||||
* apps/system/hex2bin: Move the portable library portion of hex2bin to
|
||||
nuttx/libc/hex2bin where it can be shared with the OS internals
|
||||
(2016-06-27).
|
||||
* apps/nshlib: 'ps' command now prints out the stack usage if stack
|
||||
coloration is enabled. From Frank Benkert (2016-06-30).
|
||||
* All inclusion of apps/ header files were removed from the nuttx/
|
||||
repository. This caused a lot of reshuffling of logic: binfmt pcode
|
||||
support, usbmonitor is now a kernel thread, TZ/Olson database moved to
|
||||
libc/zoneinfo (2016-06-29).
|
||||
* apps/include directory structure reorganized. There are no longer any
|
||||
header files in the apps/include/. directory. Rather, sub-directories
|
||||
were added to match the partitioning of apps/ sub-directories and the
|
||||
header files were moved into the appropriate sub-directory. This
|
||||
change is intended to help with some changes be considered by
|
||||
Sébastien Lorquet (2016-07-01).
|
||||
* apps/nshlib: Allow stack usage to be disabled on constrained systems.
|
||||
From David Sidrane (2016-07-01).
|
||||
* apps/examples/canard: Add canard example application. From Matthias
|
||||
Renner (2016-07-08).
|
||||
* apps/builtins: exec_builtin was not using the provided open flags. As
|
||||
a result >> redirection was not working (2016-07-10).
|
||||
* apps/netutils/ntpclient: The NTP client will now optionally use
|
||||
pool.ntp.org as the NTP server; and reset the retry count upon success
|
||||
-- more robust. From David Alessio (2016-07-10).
|
||||
* apps/nshlib/nsh_proccmds.c: Recent enhancements to cmd_ps trips a
|
||||
floating point exception if LIBC_FLOATINGPOINT is not defined (at
|
||||
least on Cortex M4 w/ hardfloat). I’m using a buildroot gcc
|
||||
configured to support Cortex-M4F and the hard float ABI, target files
|
||||
are compiles with: -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16
|
||||
-mfloat-abi=hard. I’m not sure the best way to address this, but the
|
||||
this chage is the first that comes to mind. Note, I added the float
|
||||
qualifier ‘F’ after a few constants to prevent the compiler from
|
||||
promoting the multiplication and division to double (expensive on
|
||||
M4F) then demoting to single float for the store. From David
|
||||
Alessio (2016-07-10).
|
||||
* Call all includes fronm <apps/bla/bla.h> to "bla/bla.h". From
|
||||
Sebastien Lorquet (2016-07-11).
|
||||
* Build System: Add apps/include to include path in top-level
|
||||
Make.defs file. Remove multiple definitions of INCDIR opt
|
||||
(2016-07-11).
|
||||
* apps/netutils, uIP webserver: Fix a data declaration in a header file
|
||||
(2016-07-11).
|
||||
* apps/nshlib: In ps command, don't show stack usage if
|
||||
CONFIG_STACK_COLORATION is not enabled (2016-07-13).
|
||||
* apps/netutils/esp8266: In Kconfig, select ARCH_HAVE_NET when
|
||||
NETUTILS_ESP8266 is selected. This allows, among other things,
|
||||
support for network debug output. From Pierre-noel Bouteville
|
||||
(2016-07-14).
|
||||
* apps/nshlib: PS Command: When Priority Inheritance is enabled, the
|
||||
format of /proc/<PID>/status changes to show both the current priority
|
||||
and the thread’s base priority. This messes up the format of cmd_ps.
|
||||
From David Alessio (2016-07-15).
|
||||
* apps/examples/pty_test: PTY test program. From Alan Carvalho de Assis
|
||||
(2016-07-15).
|
||||
* apps/examples/media: media example was intended to take either a
|
||||
command line argument, or a compiled-in default value from config.
|
||||
However, the default was ignored, leading to confusing error messages.
|
||||
From ziggurat29 (2016-07-17).
|
||||
|
||||
7.18 2016-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/canutils/libuavcan: Under certain circumstances, DELIM make not
|
||||
be defined in Makefile (2016-07-28).
|
||||
* Add the dirlinks target to some Makefiles. This plugs some holes
|
||||
opened by last chicken-and-egg build fix (2016-07-28).
|
||||
* apps/examples/gpio: Add a simple test of the GPIO driver (2016-08-01).
|
||||
* Add definition for APPNAME in apps/canutils/canlib. From Sebastien
|
||||
Lorquet (2016-08-01).
|
||||
* Add DIRLINK and DIRUNLOBK tool definitions to Make.defs (2016-08-02).
|
||||
* apps/exmples/gpio: Should not claim an error if we are only asked to
|
||||
read an output pin (2016-08-03).
|
||||
* apps/nshlib/: Fix FIFO_SIZE vs PIPE_SIZE (2016-08-04).
|
||||
* apps/examples/rfid-readuid: Add RFID_READUID sample application. From
|
||||
Alan Carvalho de Assis (2016-08-06).
|
||||
* apps/interpreters/minibasic: Add a port of Mini Basic, version 1.0,
|
||||
written by Malcom McLean and released under the Creative Commons
|
||||
Attribution license (2016-08-11).
|
||||
* apps/examples: Add Oneshot timer example (2016-08-12).
|
||||
* apps/system/tee: Port tee command from NetBSD (2016-08-12).
|
||||
* apps/examples/oneshot: If the requested delay is > max_delay, then
|
||||
break the delay up into several pieces (2016-08-15).
|
||||
* apps/examples/oneshot: A thought about how we might improve accuracy
|
||||
of long delays (2016-08-15).
|
||||
* nshlib/Kconfigt: Fix hex representation of IP address. Noted by
|
||||
Michal Lyszczek (2016-08-19).
|
||||
|
18
Make.defs
18
Make.defs
@ -2,7 +2,7 @@
|
||||
# apps/Make.defs
|
||||
# Common make definitions provided to all applications
|
||||
#
|
||||
# Copyright (C) 2011, 2014 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2011, 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -34,6 +34,8 @@
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Builtin Registration
|
||||
|
||||
BUILTIN_REGISTRY = $(APPDIR)$(DELIM)builtin$(DELIM)registry
|
||||
|
||||
DEPCONFIG = $(TOPDIR)$(DELIM).config
|
||||
@ -58,6 +60,20 @@ endif
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
MKKCONFIG = $(APPDIR)\tools\mkkconfig.bat
|
||||
DIRLINK = $(TOPDIR)\tools\link.bat
|
||||
DIRUNLINK = $(TOPDIR)\tools\unlink.bat
|
||||
else
|
||||
MKKCONFIG = $(APPDIR)/tools/mkkconfig.sh
|
||||
DIRLINK = $(TOPDIR)/tools/link.sh
|
||||
DIRUNLINK = $(TOPDIR)/tools/unlink.sh
|
||||
endif
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
INCDIROPT = -w
|
||||
endif
|
||||
|
||||
# Standard include path
|
||||
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(APPDIR)$(DELIM)include"}
|
||||
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(APPDIR)$(DELIM)include"}
|
||||
|
||||
|
5
Makefile
5
Makefile
@ -76,7 +76,7 @@ BIN = libapps$(LIBEXT)
|
||||
# Build targets
|
||||
|
||||
all: $(BIN)
|
||||
.PHONY: import install context context_serialize context_rest .depdirs preconfig depend clean distclean
|
||||
.PHONY: import install dirlinks context context_serialize context_rest .depdirs preconfig depend clean distclean
|
||||
|
||||
define MAKE_template
|
||||
$(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" BIN_DIR="$(BIN_DIR)"
|
||||
@ -110,6 +110,9 @@ install: $(BIN_DIR) .install
|
||||
import:
|
||||
$(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
|
||||
dirlinks:
|
||||
$(Q) $(MAKE) -C platform dirlinks TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
|
||||
context_rest: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_context)
|
||||
|
||||
context_serialize:
|
||||
|
@ -61,7 +61,7 @@ collected during the make context build phase.
|
||||
|
||||
To execute an application function:
|
||||
|
||||
exec_builtin() is defined in the nuttx/include/apps/builtin.h
|
||||
exec_builtin() is defined in the nuttx/include/apps/builtin/builtin.h
|
||||
|
||||
NuttShell (NSH) Built-In Commands
|
||||
---------------------------------
|
||||
|
@ -51,36 +51,7 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#if 0
|
||||
#include <sys/wait.h>
|
||||
#include <sched.h>
|
||||
#include <string.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/binfmt/builtin.h>
|
||||
#endif
|
||||
|
||||
#include <apps/builtin.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
#include "builtin/builtin.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@ -202,7 +173,7 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
|
||||
/* Set up to close open redirfile and set to stdout (1) */
|
||||
|
||||
ret = posix_spawn_file_actions_addopen(&file_actions, 1,
|
||||
redirfile, O_WRONLY, 0644);
|
||||
redirfile, oflags, 0644);
|
||||
if (ret != 0)
|
||||
{
|
||||
serr("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret);
|
||||
|
@ -37,9 +37,11 @@
|
||||
|
||||
# CAN utility library
|
||||
|
||||
ASRCS =
|
||||
CSRCS = canlib_getbaud.c canlib_setbaud.c
|
||||
CSRCS+= canlib_getloopback.c canlib_setloopback.c
|
||||
CSRCS+= canlib_getsilent.c canlib_setsilent.c
|
||||
ASRCS =
|
||||
CSRCS = canlib_getbaud.c canlib_setbaud.c
|
||||
CSRCS += canlib_getloopback.c canlib_setloopback.c
|
||||
CSRCS += canlib_getsilent.c canlib_setsilent.c
|
||||
|
||||
APPNAME = canlib
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/drivers/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getbaud
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/drivers/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getloopback
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/drivers/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getsilent
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/drivers/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setbaud
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/drivers/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setloopback
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/drivers/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setsilent
|
||||
|
@ -20,7 +20,7 @@ config LIBCANARD_URL
|
||||
|
||||
config LIBCANARD_VERSION
|
||||
string "libcanard Version"
|
||||
default "a7a6d4c6b105976cccac36e05c42abee566b70c4"
|
||||
default "e4a1d52be862b03e5872add75890e67bf1d9187c"
|
||||
---help---
|
||||
libcanard version.
|
||||
|
||||
|
@ -49,9 +49,9 @@ LIBCANARD_DRVDIR = $(LIBCANARD_SRCDIR)$(DELIM)drivers$(DELIM)nuttx
|
||||
|
||||
APPS_INCDIR = $(APPDIR)$(DELIM)include$(DELIM)canutils
|
||||
|
||||
CFLAGS += -I$(APPS_INCDIR)
|
||||
CFLAGS += -std=c99 -I$(APPS_INCDIR) -DCANARD_ASSERT=DEBUGASSERT
|
||||
|
||||
CSRCS = $(LIBCANARD_SRCDIR)$(DELIM)canard.c $(LIBCANARD_DRVDIR)$(DELIM)nuttx.c
|
||||
CSRCS = $(LIBCANARD_SRCDIR)$(DELIM)canard.c $(LIBCANARD_DRVDIR)$(DELIM)canard_nuttx.c
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(CSRCS)
|
||||
|
@ -35,7 +35,9 @@
|
||||
|
||||
-include $(TOPDIR)/.config
|
||||
-include $(TOPDIR)/Make.defs
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
DELIM ?= $(strip /)
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
WGET = wget
|
||||
UNPACK = unzip
|
||||
@ -59,14 +61,16 @@ PYUAVCAN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBUAVCAN_PYUAVCAN_VERSION)
|
||||
PYUAVCAN_UNPACKNAME = pyuavcan-$(PYUAVCAN_VERSION)
|
||||
PYUAVCAN_PACKNAME = $(PYUAVCAN_UNPACKNAME)$(PACKEXT)
|
||||
|
||||
-include libuavcan/libuavcan/include.mk
|
||||
-include libuavcan/libuavcan_drivers/stm32/driver/include.mk
|
||||
-include libuavcan$(DELIM)libuavcan$(DELIM)include.mk
|
||||
-include libuavcan$(DELIM)libuavcan_drivers$(DELIM)stm32$(DELIM)driver$(DELIM)include.mk
|
||||
|
||||
CXXSRCS = platform_stm32.cpp $(LIBUAVCAN_SRC) $(LIBUAVCAN_STM32_SRC)
|
||||
|
||||
CXXFLAGS += -I$(LIBUAVCAN_INC) -I$(LIBUAVCAN_STM32_INC) -Idsdlc_generated
|
||||
CXXFLAGS += -I$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common
|
||||
CXXFLAGS += -I$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)stm32
|
||||
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(LIBUAVCAN_INC)"}
|
||||
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(LIBUAVCAN_STM32_INC)"}
|
||||
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" dsdlc_generated}
|
||||
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common"}
|
||||
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)stm32"}
|
||||
|
||||
CXXFLAGS += -D__KERNEL__
|
||||
CXXFLAGS += -DUAVCAN_STM32_NUTTX=1
|
||||
|
@ -208,6 +208,11 @@ examples/can
|
||||
CONFIG_EXAMPLES_CAN_READONLY - Only receive messages
|
||||
CONFIG_EXAMPLES_CAN_WRITEONLY - Only send messages
|
||||
|
||||
examples/canard
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
Example application for canutils/libcarnard.
|
||||
|
||||
examples/cc3000
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
@ -548,6 +553,11 @@ examples/ftpd
|
||||
CONFIG_NETUTILS_NETLIB=y
|
||||
CONFIG_NETUTILS_TELNED=y
|
||||
|
||||
examples/gpio
|
||||
^^^^^^^^^^^^
|
||||
|
||||
A simple test/example of the NuttX GPIO driver.
|
||||
|
||||
examples/hello
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
@ -643,8 +653,8 @@ examples/igmp
|
||||
* CONFIG_EXAMPLES_NETLIB
|
||||
The networking library is needed
|
||||
|
||||
examples/adc
|
||||
^^^^^^^^^^^^
|
||||
examples/i2cchar
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
A mindlessly simple test of an I2C driver. It reads an write garbage data to the
|
||||
I2C transmitter and/or received as fast possible.
|
||||
@ -736,7 +746,7 @@ examples/lcdrw
|
||||
NuttX is built as a protected, supervisor kernel (CONFIG_BUILD_PROTECTED
|
||||
or CONFIG_BUILD_KERNEL).
|
||||
|
||||
examples/adc
|
||||
examples/leds
|
||||
^^^^^^^^^^^^
|
||||
This is a simple test of the board LED driver at nuttx/drivers/leds/userled_*.c.
|
||||
|
||||
@ -1431,6 +1441,11 @@ examples/null
|
||||
This is the do nothing application. It is only used for bringing
|
||||
up new NuttX architectures in the most minimal of environments.
|
||||
|
||||
examples/oneshot
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
Simple test of a oneshot driver.
|
||||
|
||||
examples/ostest
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
@ -1484,7 +1499,7 @@ examples/pca9635
|
||||
examples/pipe
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
A test of the mkfifo() and pipe() APIs.
|
||||
A test of the mkfifo() and pipe() APIs. Requires CONFIG_PIPES
|
||||
|
||||
* CONFIG_EXAMPLES_PIPE_STACKSIZE
|
||||
Sets the size of the stack to use when creating the child tasks.
|
||||
@ -1622,6 +1637,11 @@ examples/posix_spawn
|
||||
|
||||
LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld
|
||||
|
||||
examples/pty_test
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
A test of NuttX pseudo-terminals. Provided by Alan Carvalho de Assis.
|
||||
|
||||
examples/pwm
|
||||
^^^^^^^^^^^^
|
||||
|
||||
@ -1716,6 +1736,11 @@ examples/relays
|
||||
NuttX is built as a protected, supervisor kernel (CONFIG_BUILD_PROTECTED
|
||||
or CONFIG_BUILD_KERNEL).
|
||||
|
||||
examples/rfid_readuid
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
RFID READUID example
|
||||
|
||||
examples/rgbled
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
|
||||
#include "romfs.h"
|
||||
|
||||
|
@ -50,12 +50,12 @@
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/net/arp.h>
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_BRIDGE_NET1_DHCPC) || \
|
||||
defined(CONFIG_EXAMPLES_BRIDGE_NET2_DHCPC)
|
||||
# include <arpa/inet.h>
|
||||
# include <apps/netutils/dhcpc.h>
|
||||
# include "netutils/dhcpc.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -51,7 +51,7 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/drivers/can.h>
|
||||
|
||||
#include "can.h"
|
||||
|
||||
|
@ -1,17 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/.tzbuilt
|
||||
/.tzunpack
|
||||
/tzbin
|
||||
/tzcode
|
||||
/tz*-latest.tar.gz
|
||||
/romfs_zoneinfo.*
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
||||
/*.obj
|
48
examples/canard/Kconfig
Normal file
48
examples/canard/Kconfig
Normal file
@ -0,0 +1,48 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_LIBCANARD
|
||||
bool "libcandard example"
|
||||
default n
|
||||
depends on CANUTILS_LIBCANARD && CLOCK_MONOTONIC && SYSTEM_TIME64
|
||||
---help---
|
||||
Enable the LIBCANARD example
|
||||
|
||||
if EXAMPLES_LIBCANARD
|
||||
|
||||
config EXAMPLES_LIBCANARD_DEVPATH
|
||||
string "Device Path"
|
||||
default "/dev/can0"
|
||||
---help---
|
||||
The device path
|
||||
|
||||
config EXAMPLES_LIBCANARD_NODE_ID
|
||||
int "Node ID"
|
||||
default 1
|
||||
range 1 127
|
||||
---help---
|
||||
Specifies the node's ID
|
||||
|
||||
config EXAMPLES_LIBCANARD_APP_NODE_NAME
|
||||
string "Node name"
|
||||
default "org.uavcan.libcanard.nuttx.demo"
|
||||
---help---
|
||||
app node name
|
||||
|
||||
config EXAMPLES_LIBCANARD_NODE_MEM_POOL_SIZE
|
||||
int "Node Memory Pool Size"
|
||||
default 1024
|
||||
---help---
|
||||
Specifies the node's memory pool size
|
||||
|
||||
config EXAMPLES_LIBCANARD_DAEMON_PRIORITY
|
||||
int "daemon task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_LIBCANARD_STACKSIZE
|
||||
int "canard stack size"
|
||||
default 2048
|
||||
|
||||
endif
|
39
examples/canard/Make.defs
Normal file
39
examples/canard/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/canard/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||
# Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||
#
|
||||
# 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_LIBCANARD),y)
|
||||
CONFIGURED_APPS += examples/canard
|
||||
endif
|
52
examples/canard/Makefile
Normal file
52
examples/canard/Makefile
Normal file
@ -0,0 +1,52 @@
|
||||
############################################################################
|
||||
# apps/examples/canard/Makefile
|
||||
#
|
||||
# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||
# Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||
#
|
||||
# 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
|
||||
|
||||
CONFIG_EXAMPLES_LIBCANARD_STACKSIZE ?= 2048
|
||||
|
||||
CONFIG_XYZ_PROGNAME ?= canard$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_XYZ_PROGNAME)
|
||||
|
||||
APPNAME = canard
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_LIBCANARD_STACKSIZE)
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
CFLAGS += -I$(APPDIR)/include/canutils
|
||||
MAINSRC = canard_main.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
554
examples/canard/canard_main.c
Normal file
554
examples/canard/canard_main.c
Normal file
@ -0,0 +1,554 @@
|
||||
/****************************************************************************
|
||||
* examples/canard/canard_main.c
|
||||
*
|
||||
* Copyright (C) 2016 ETH Zuerich. All rights reserved.
|
||||
* Author: Matthias Renner <rennerm@ethz.ch>
|
||||
*
|
||||
* 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/drivers/can.h>
|
||||
#include <canard.h>
|
||||
#include <canard_nuttx.h> /* CAN backend driver for nuttx, distributed
|
||||
* with Libcanard */
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/boardctl.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Application constants */
|
||||
|
||||
#define APP_VERSION_MAJOR 1
|
||||
#define APP_VERSION_MINOR 0
|
||||
#define APP_NODE_NAME CONFIG_EXAMPLES_LIBCANARD_APP_NODE_NAME
|
||||
#define GIT_HASH 0xb28bf6ac
|
||||
|
||||
/* Some useful constants defined by the UAVCAN specification.
|
||||
* Data type signature values can be easily obtained with the script
|
||||
* show_data_type_info.py
|
||||
*/
|
||||
|
||||
#define UAVCAN_NODE_STATUS_MESSAGE_SIZE 7
|
||||
#define UAVCAN_NODE_STATUS_DATA_TYPE_ID 341
|
||||
#define UAVCAN_NODE_STATUS_DATA_TYPE_SIGNATURE 0x0f0868d0c1a7c6f1
|
||||
|
||||
#define UAVCAN_NODE_HEALTH_OK 0
|
||||
#define UAVCAN_NODE_HEALTH_WARNING 1
|
||||
#define UAVCAN_NODE_HEALTH_ERROR 2
|
||||
#define UAVCAN_NODE_HEALTH_CRITICAL 3
|
||||
|
||||
#define UAVCAN_NODE_MODE_OPERATIONAL 0
|
||||
#define UAVCAN_NODE_MODE_INITIALIZATION 1
|
||||
|
||||
#define UAVCAN_GET_NODE_INFO_RESPONSE_MAX_SIZE ((3015 + 7) / 8)
|
||||
#define UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE 0xee468a8121c46a9e
|
||||
#define UAVCAN_GET_NODE_INFO_DATA_TYPE_ID 1
|
||||
|
||||
#define UNIQUE_ID_LENGTH_BYTES 16
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Library instance.
|
||||
* In simple applications it makes sense to make it static, but it is not
|
||||
* necessary.
|
||||
*/
|
||||
|
||||
static CanardInstance canard;
|
||||
|
||||
/* Arena for memory allocation, used by the library */
|
||||
|
||||
static uint8_t canard_memory_pool[CONFIG_EXAMPLES_LIBCANARD_NODE_MEM_POOL_SIZE];
|
||||
|
||||
static uint8_t unique_id[UNIQUE_ID_LENGTH_BYTES] =
|
||||
{ 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01
|
||||
};
|
||||
|
||||
/* Node status variables */
|
||||
|
||||
static uint8_t node_health = UAVCAN_NODE_HEALTH_OK;
|
||||
static uint8_t node_mode = UAVCAN_NODE_MODE_INITIALIZATION;
|
||||
static bool g_canard_daemon_started;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: getMonotonicTimestampUSec
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t getMonotonicTimestampUSec(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
memset(&ts, 0, sizeof(ts));
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
|
||||
return ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000ULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: makeNodeStatusMessage
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void makeNodeStatusMessage(uint8_t buffer[UAVCAN_NODE_STATUS_MESSAGE_SIZE])
|
||||
{
|
||||
static uint32_t started_at_sec = 0;
|
||||
|
||||
memset(buffer, 0, UAVCAN_NODE_STATUS_MESSAGE_SIZE);
|
||||
|
||||
if (started_at_sec == 0)
|
||||
{
|
||||
started_at_sec = (uint32_t) (getMonotonicTimestampUSec() / 1000000U);
|
||||
}
|
||||
|
||||
const uint32_t uptime_sec =
|
||||
(uint32_t) ((getMonotonicTimestampUSec() / 1000000U) - started_at_sec);
|
||||
|
||||
/* Here we're using the helper for demonstrational purposes; in this
|
||||
* simple case it could be preferred to encode the values manually.
|
||||
*/
|
||||
|
||||
canardEncodeScalar(buffer, 0, 32, &uptime_sec);
|
||||
canardEncodeScalar(buffer, 32, 2, &node_health);
|
||||
canardEncodeScalar(buffer, 34, 3, &node_mode);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: onTransferReceived
|
||||
*
|
||||
* Description:
|
||||
* This callback is invoked by the library when a new message or request
|
||||
* or response is received.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void onTransferReceived(CanardInstance *ins,
|
||||
CanardRxTransfer *transfer)
|
||||
{
|
||||
if ((transfer->transfer_type == CanardTransferTypeRequest) &&
|
||||
(transfer->data_type_id == UAVCAN_GET_NODE_INFO_DATA_TYPE_ID))
|
||||
{
|
||||
printf("GetNodeInfo request from %d\n", transfer->source_node_id);
|
||||
|
||||
uint8_t buffer[UAVCAN_GET_NODE_INFO_RESPONSE_MAX_SIZE];
|
||||
memset(buffer, 0, UAVCAN_GET_NODE_INFO_RESPONSE_MAX_SIZE);
|
||||
|
||||
/* NodeStatus */
|
||||
|
||||
makeNodeStatusMessage(buffer);
|
||||
|
||||
/* SoftwareVersion */
|
||||
|
||||
buffer[7] = APP_VERSION_MAJOR;
|
||||
buffer[8] = APP_VERSION_MINOR;
|
||||
buffer[9] = 1; /* Optional field flags, VCS commit is set */
|
||||
|
||||
/* uint32_t u32 = GIT_HASH;
|
||||
* canardEncodeScalar(buffer, 80, 32, &u32);
|
||||
*/
|
||||
|
||||
/* Image CRC skipped */
|
||||
/* HardwareVersion */
|
||||
/* Major skipped */
|
||||
/* Minor skipped */
|
||||
|
||||
memcpy(&buffer[24], unique_id, UNIQUE_ID_LENGTH_BYTES);
|
||||
|
||||
/* Certificate of authenticity skipped */
|
||||
/* Name */
|
||||
|
||||
const size_t name_len = strlen(APP_NODE_NAME);
|
||||
memcpy(&buffer[41], APP_NODE_NAME, name_len);
|
||||
|
||||
const size_t total_size = 41 + name_len;
|
||||
|
||||
/* Transmitting; in this case we don't have to release the payload
|
||||
* because it's empty anyway.
|
||||
*/
|
||||
|
||||
const int resp_res =
|
||||
canardRequestOrRespond(ins,
|
||||
transfer->source_node_id,
|
||||
UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE,
|
||||
UAVCAN_GET_NODE_INFO_DATA_TYPE_ID,
|
||||
&transfer->transfer_id,
|
||||
transfer->priority,
|
||||
CanardResponse,
|
||||
&buffer[0],
|
||||
(uint16_t) total_size);
|
||||
if (resp_res <= 0)
|
||||
{
|
||||
(void)fprintf(stderr, "Could not respond to GetNodeInfo; error %d\n",
|
||||
resp_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: shouldAcceptTransfer
|
||||
*
|
||||
* Description:
|
||||
* This callback is invoked by the library when it detects beginning of a
|
||||
* new transfer on the bus that can be received by the local node.
|
||||
* If the callback returns true, the library will receive the transfer.
|
||||
* If the callback returns false, the library will ignore the transfer.
|
||||
* All transfers that are addressed to other nodes are always ignored.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static bool shouldAcceptTransfer(const CanardInstance * ins,
|
||||
uint64_t * out_data_type_signature,
|
||||
uint16_t data_type_id,
|
||||
CanardTransferType transfer_type,
|
||||
uint8_t source_node_id)
|
||||
{
|
||||
(void)source_node_id;
|
||||
|
||||
if (canardGetLocalNodeID(ins) == CANARD_BROADCAST_NODE_ID)
|
||||
{
|
||||
/* If we're in the process of allocation of dynamic node ID, accept
|
||||
* only relevant transfers.
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((transfer_type == CanardTransferTypeRequest) &&
|
||||
(data_type_id == UAVCAN_GET_NODE_INFO_DATA_TYPE_ID))
|
||||
{
|
||||
*out_data_type_signature = UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: process1HzTasks
|
||||
*
|
||||
* Description:
|
||||
* This function is called at 1 Hz rate from the main loop.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void process1HzTasks(uint64_t timestamp_usec)
|
||||
{
|
||||
/* Purging transfers that are no longer transmitted. This will occasionally
|
||||
* free up some memory.
|
||||
*/
|
||||
|
||||
canardCleanupStaleTransfers(&canard, timestamp_usec);
|
||||
|
||||
/* Printing the memory usage statistics. */
|
||||
|
||||
{
|
||||
const CanardPoolAllocatorStatistics stats =
|
||||
canardGetPoolAllocatorStatistics(&canard);
|
||||
const unsigned peak_percent =
|
||||
100U * stats.peak_usage_blocks / stats.capacity_blocks;
|
||||
|
||||
#ifdef CONFIG_DEBUG_CAN
|
||||
printf
|
||||
("Memory pool stats: capacity %u blocks, usage %u blocks, peak usage %u blocks (%u%%)\n",
|
||||
stats.capacity_blocks, stats.current_usage_blocks,
|
||||
stats.peak_usage_blocks, peak_percent);
|
||||
#endif
|
||||
|
||||
/* The recommended way to establish the minimal size of the memory pool
|
||||
* is to stress-test the application and record the worst case memory
|
||||
* usage.
|
||||
*/
|
||||
|
||||
if (peak_percent > 70)
|
||||
{
|
||||
puts("WARNING: ENLARGE MEMORY POOL");
|
||||
}
|
||||
}
|
||||
|
||||
/* Transmitting the node status message periodically. */
|
||||
|
||||
{
|
||||
uint8_t buffer[UAVCAN_NODE_STATUS_MESSAGE_SIZE];
|
||||
makeNodeStatusMessage(buffer);
|
||||
|
||||
static uint8_t transfer_id;
|
||||
|
||||
const int bc_res =
|
||||
canardBroadcast(&canard, UAVCAN_NODE_STATUS_DATA_TYPE_SIGNATURE,
|
||||
UAVCAN_NODE_STATUS_DATA_TYPE_ID, &transfer_id,
|
||||
CANARD_TRANSFER_PRIORITY_LOW,
|
||||
buffer, UAVCAN_NODE_STATUS_MESSAGE_SIZE);
|
||||
if (bc_res <= 0)
|
||||
{
|
||||
(void)fprintf(stderr, "Could not broadcast node status; error %d\n",
|
||||
bc_res);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
static uint8_t transfer_id;
|
||||
uint8_t payload[1];
|
||||
uint8_t dest_id = 2;
|
||||
const int resp_res =
|
||||
canardRequestOrRespond(&canard, dest_id,
|
||||
UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE,
|
||||
UAVCAN_GET_NODE_INFO_DATA_TYPE_ID, &transfer_id,
|
||||
CANARD_TRANSFER_PRIORITY_LOW, CanardRequest,
|
||||
payload, 0);
|
||||
if (resp_res <= 0)
|
||||
{
|
||||
(void)fprintf(stderr, "Could not request GetNodeInfo; error %d\n",
|
||||
resp_res);
|
||||
}
|
||||
}
|
||||
|
||||
node_mode = UAVCAN_NODE_MODE_OPERATIONAL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: processTxRxOnce
|
||||
*
|
||||
* Description:
|
||||
* Transmits all frames from the TX queue, receives up to one frame.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void processTxRxOnce(CanardNuttXInstance * nuttxcan, int timeout_msec)
|
||||
{
|
||||
const CanardCANFrame *txf;
|
||||
|
||||
/* Transmitting */
|
||||
|
||||
for (txf = NULL; (txf = canardPeekTxQueue(&canard)) != NULL;)
|
||||
{
|
||||
const int tx_res = canardNuttXTransmit(nuttxcan, txf, 0);
|
||||
if (tx_res < 0) /* Failure - drop the frame and report */
|
||||
{
|
||||
canardPopTxQueue(&canard);
|
||||
(void)fprintf(stderr,
|
||||
"Transmit error %d, frame dropped, errno '%s'\n",
|
||||
tx_res, strerror(errno));
|
||||
}
|
||||
else if (tx_res > 0) /* Success - just drop the frame */
|
||||
{
|
||||
canardPopTxQueue(&canard);
|
||||
}
|
||||
else /* Timeout - just exit and try again later */
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Receiving */
|
||||
|
||||
CanardCANFrame rx_frame;
|
||||
const uint64_t timestamp = getMonotonicTimestampUSec();
|
||||
const int rx_res = canardNuttXReceive(nuttxcan, &rx_frame, timeout_msec);
|
||||
|
||||
if (rx_res < 0) /* Failure - report */
|
||||
{
|
||||
(void)fprintf(stderr, "Receive error %d, errno '%s'\n", rx_res,
|
||||
strerror(errno));
|
||||
}
|
||||
else if (rx_res > 0) /* Success - process the frame */
|
||||
{
|
||||
canardHandleRxFrame(&canard, &rx_frame, timestamp);
|
||||
}
|
||||
else
|
||||
{
|
||||
; /* Timeout - nothing to do */
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canard_daemon
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int canard_daemon(int argc, char *argv[])
|
||||
{
|
||||
static CanardNuttXInstance canardnuttx_instance;
|
||||
#ifdef CONFIG_DEBUG_CAN
|
||||
struct canioc_bittiming_s bt;
|
||||
#endif
|
||||
int errval = 0;
|
||||
int ret;
|
||||
|
||||
/* Initialization of the CAN hardware is performed by logic external to
|
||||
* this test.
|
||||
*/
|
||||
|
||||
ret = boardctl(BOARDIOC_CAN_INITIALIZE, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("canard_daemon: ERROR: BOARDIOC_CAN_INITIALIZE failed: %d\n",
|
||||
ret);
|
||||
errval = 1;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Open the CAN device for reading */
|
||||
|
||||
ret = canardNuttXInit(&canardnuttx_instance,
|
||||
CONFIG_EXAMPLES_LIBCANARD_DEVPATH);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("canard_daemon: ERROR: open %s failed: %d\n",
|
||||
CONFIG_EXAMPLES_LIBCANARD_DEVPATH, errno);
|
||||
errval = 2;
|
||||
goto errout_with_dev;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_CAN
|
||||
/* Show bit timing information if provided by the driver. Not all CAN
|
||||
* drivers will support this IOCTL.
|
||||
*/
|
||||
|
||||
ret =
|
||||
ioctl(canardNuttXGetDeviceFileDescriptor(&canardnuttx_instance),
|
||||
CANIOC_GET_BITTIMING, (unsigned long)((uintptr_t)&bt));
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("canard_daemon: Bit timing not available: %d\n", errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("canard_daemon: Bit timing:\n");
|
||||
printf("canard_daemon: Baud: %lu\n", (unsigned long)bt.bt_baud);
|
||||
printf("canard_daemon: TSEG1: %u\n", bt.bt_tseg1);
|
||||
printf("canard_daemon: TSEG2: %u\n", bt.bt_tseg2);
|
||||
printf("canard_daemon: SJW: %u\n", bt.bt_sjw);
|
||||
}
|
||||
#endif
|
||||
|
||||
canardInit(&canard, canard_memory_pool, sizeof(canard_memory_pool),
|
||||
onTransferReceived, shouldAcceptTransfer);
|
||||
canardSetLocalNodeID(&canard, CONFIG_EXAMPLES_LIBCANARD_NODE_ID);
|
||||
printf("canard_daemon: canard initialized\n");
|
||||
printf("start node (ID: %d Name: %s)\n", CONFIG_EXAMPLES_LIBCANARD_NODE_ID,
|
||||
APP_NODE_NAME);
|
||||
|
||||
g_canard_daemon_started = true;
|
||||
uint64_t next_1hz_service_at = getMonotonicTimestampUSec();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
processTxRxOnce(&canardnuttx_instance, 10);
|
||||
|
||||
const uint64_t ts = getMonotonicTimestampUSec();
|
||||
|
||||
if (ts >= next_1hz_service_at)
|
||||
{
|
||||
next_1hz_service_at += 1000000;
|
||||
process1HzTasks(ts);
|
||||
}
|
||||
}
|
||||
|
||||
errout_with_dev:
|
||||
canardNuttXClose(&canardnuttx_instance);
|
||||
|
||||
errout:
|
||||
g_canard_daemon_started = false;
|
||||
printf("canard_daemon: Terminating!\n");
|
||||
fflush(stdout);
|
||||
return errval;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canard_main
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int canard_main(int argc, FAR char *argv[])
|
||||
#endif
|
||||
{
|
||||
FAR char *canardargv[2];
|
||||
int ret;
|
||||
|
||||
printf("canard_main: Starting canard_daemon\n");
|
||||
if (g_canard_daemon_started)
|
||||
{
|
||||
printf("canard_main: receive and send task already running\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
canardargv[0] = "canard_daemon";
|
||||
canardargv[1] = NULL;
|
||||
|
||||
ret = task_create("canard_daemon", CONFIG_EXAMPLES_LIBCANARD_DAEMON_PRIORITY,
|
||||
CONFIG_EXAMPLES_LIBCANARD_STACKSIZE, canard_daemon,
|
||||
(FAR char *const *)canardargv);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
printf("canard_main: ERROR: Failed to start canard_daemon: %d\n",
|
||||
errcode);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("canard_main: canard_daemon started\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -47,11 +47,11 @@
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <apps/netutils/telnetd.h>
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/telnetd.h"
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include <apps/nsh.h>
|
||||
#include "nshlib/nshlib.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
@ -53,8 +53,8 @@
|
||||
#include <debug.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/telnetd.h>
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/telnetd.h"
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "telnetd.h"
|
||||
|
||||
|
@ -61,7 +61,7 @@
|
||||
|
||||
#include <nuttx/net/net.h>
|
||||
|
||||
#include <apps/netutils/telnetd.h>
|
||||
#include "netutils/telnetd.h"
|
||||
|
||||
#include "telnetd.h"
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <apps/netutils/chat.h>
|
||||
#include "netutils/chat.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
@ -50,7 +50,7 @@
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/configdata.h>
|
||||
#include <nuttx/mtd/configdata.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
@ -4,10 +4,11 @@
|
||||
#
|
||||
|
||||
config EXAMPLES_CPUHOG
|
||||
bool "CPU hog"
|
||||
default n
|
||||
---help---
|
||||
Enable the cpuhog example
|
||||
bool "CPU hog"
|
||||
default n
|
||||
depends on PIPES
|
||||
---help---
|
||||
Enable the cpuhog example
|
||||
|
||||
if EXAMPLES_CPUHOG
|
||||
|
||||
|
@ -44,8 +44,8 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/dhcpd.h>
|
||||
#include "netutils/netlib.h"
|
||||
#include "netutils/dhcpd.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Preprocessor Definitions
|
||||
|
@ -51,8 +51,8 @@
|
||||
#include <netinet/in.h>
|
||||
#include <nuttx/net/arp.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/discover.h>
|
||||
#include "netutils/netlib.h"
|
||||
#include "netutils/discover.h"
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_DISCOVER_DHCPC
|
||||
# include <arpa/inet.h>
|
||||
@ -65,7 +65,7 @@
|
||||
/* DHCPC may be used in conjunction with any other feature (or not) */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_DISCOVER_DHCPC
|
||||
# include <apps/netutils/dhcpc.h>
|
||||
# include "netutils/dhcpc.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -50,7 +50,7 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
@ -49,7 +49,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <apps/ftpc.h>
|
||||
#include "netutils/ftpc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <apps/ftpc.h>
|
||||
#include "netutils/ftpc.h"
|
||||
|
||||
#include "ftpc.h"
|
||||
|
||||
|
@ -44,9 +44,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <apps/ftpc.h>
|
||||
#include "netutils/ftpc.h"
|
||||
|
||||
#include <apps/readline.h>
|
||||
#include "system/readline.h"
|
||||
|
||||
#include "ftpc.h"
|
||||
|
||||
|
@ -46,8 +46,8 @@
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/ftpd.h>
|
||||
#include "netutils/netlib.h"
|
||||
#include "netutils/ftpd.h"
|
||||
|
||||
#include "ftpd.h"
|
||||
|
||||
|
11
examples/gpio/.gitignore
vendored
Normal file
11
examples/gpio/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
31
examples/gpio/Kconfig
Normal file
31
examples/gpio/Kconfig
Normal file
@ -0,0 +1,31 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_GPIO
|
||||
bool "GPIO driver example"
|
||||
default n
|
||||
depends on DEV_GPIO
|
||||
---help---
|
||||
Enable the GPIO driver example
|
||||
|
||||
if EXAMPLES_GPIO
|
||||
|
||||
config EXAMPLES_GPIO_PROGNAME
|
||||
string "Program name"
|
||||
default "gpio"
|
||||
depends on BUILD_KERNEL
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_GPIO_PRIORITY
|
||||
int "GPIO task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_GPIO_STACKSIZE
|
||||
int "GPIO stack size"
|
||||
default 2048
|
||||
|
||||
endif
|
39
examples/gpio/Make.defs
Normal file
39
examples/gpio/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/gpio/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_GPIO),y)
|
||||
CONFIGURED_APPS += examples/gpio
|
||||
endif
|
56
examples/gpio/Makefile
Normal file
56
examples/gpio/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
############################################################################
|
||||
# apps/examples/gpio/Makefile
|
||||
#
|
||||
# Copyright (C) 2008, 2010-2013 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
|
||||
|
||||
# GPIO, World! built-in application info
|
||||
|
||||
CONFIG_EXAMPLES_GPIO_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_GPIO_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = gpio
|
||||
PRIORITY = $(CONFIG_EXAMPLES_GPIO_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_GPIO_STACKSIZE)
|
||||
|
||||
# GPIO, World! Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = gpio_main.c
|
||||
|
||||
CONFIG_EXAMPLES_GPIO_PROGNAME ?= gpio$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_GPIO_PROGNAME)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
322
examples/gpio/gpio_main.c
Normal file
322
examples/gpio/gpio_main.c
Normal file
@ -0,0 +1,322 @@
|
||||
/****************************************************************************
|
||||
* examples/gpio/gpio_main.c
|
||||
*
|
||||
* Copyright (C) 2016 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 <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/ioexpander/gpio.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void show_usage(FAR const char *progname)
|
||||
{
|
||||
fprintf(stderr, "USAGE: %s [-w <signo>] [-o <value>] <driver-path>\n", progname);
|
||||
fprintf(stderr, " %s -h\n", progname);
|
||||
fprintf(stderr, "Where:\n");
|
||||
fprintf(stderr, "\t<driver-path>: The full path to the GPIO pin driver.\n");
|
||||
fprintf(stderr, "\t-w <signo>: Wait for an signal if this is an interrupt pin.\n");
|
||||
fprintf(stderr, "\t-o <value>: Write this value (0 or 1) if this is an output pin.\n");
|
||||
fprintf(stderr, "\t-h: Print this usage information and exit.\n");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* gpio_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int gpio_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
FAR char *devpath = NULL;
|
||||
enum gpio_pintype_e pintype;
|
||||
bool havesigno = false;
|
||||
bool invalue;
|
||||
bool outvalue = false;
|
||||
bool haveout = false;
|
||||
int signo = 0;
|
||||
int ndx;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
/* Parse command line */
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Missing required arguments\n");
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ndx = 1;
|
||||
if (strcmp(argv[ndx], "-h") == 0)
|
||||
{
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(argv[ndx], "-w") == 0)
|
||||
{
|
||||
havesigno = true;
|
||||
|
||||
if (++ndx >= argc)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Missing argument to -o\n");
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
signo = atoi(argv[ndx]);
|
||||
|
||||
if (++ndx >= argc)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Missing required <driver-path>\n");
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (ndx < argc && strcmp(argv[ndx], "-o") == 0)
|
||||
{
|
||||
if (++ndx >= argc)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Missing argument to -o\n");
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(argv[ndx], "0") == 0)
|
||||
{
|
||||
outvalue = false;
|
||||
haveout = true;
|
||||
}
|
||||
else if (strcmp(argv[ndx], "1") == 0)
|
||||
{
|
||||
outvalue = true;
|
||||
haveout = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ERROR: Invalid argument to -o\n");
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (++ndx >= argc)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Missing required <driver-path>\n");
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
devpath = argv[ndx];
|
||||
printf("Driver: %s\n", devpath);
|
||||
|
||||
/* Open the pin driver */
|
||||
|
||||
fd = open(devpath, O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to open %s: %d\n", devpath, errcode);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Get the pin type */
|
||||
|
||||
ret = ioctl(fd, GPIOC_PINTYPE, (unsigned long)((uintptr_t)&pintype));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to read pintype from %s: %d\n", devpath, errcode);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Read the pin value */
|
||||
|
||||
ret = ioctl(fd, GPIOC_READ, (unsigned long)((uintptr_t)&invalue));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to read value from %s: %d\n", devpath, errcode);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Perform the test based on the pintype and on command line options */
|
||||
|
||||
switch (pintype)
|
||||
{
|
||||
case GPIO_INPUT_PIN:
|
||||
{
|
||||
printf(" Input pin: Value=%u\n", (unsigned int)invalue);
|
||||
}
|
||||
break;
|
||||
|
||||
case GPIO_OUTPUT_PIN:
|
||||
{
|
||||
printf(" Output pin: Value=%u\n", (unsigned int)invalue);
|
||||
|
||||
if (haveout)
|
||||
{
|
||||
printf(" Writing: Value=%u\n", (unsigned int)outvalue);
|
||||
|
||||
/* Write the pin value */
|
||||
|
||||
ret = ioctl(fd, GPIOC_WRITE, (unsigned long)outvalue);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to write value %u from %s: %d\n",
|
||||
devpath, (unsigned int)outvalue, errcode);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Re-read the pin value */
|
||||
|
||||
ret = ioctl(fd, GPIOC_READ, (unsigned long)((uintptr_t)&invalue));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to re-read value from %s: %d\n",
|
||||
devpath, errcode);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf(" Verify: Value=%u\n", (unsigned int)invalue);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GPIO_INTERRUPT_PIN:
|
||||
{
|
||||
printf(" Interrupt pin: Value=%u\n", invalue);
|
||||
|
||||
if (havesigno)
|
||||
{
|
||||
struct timespec ts;
|
||||
struct siginfo info;
|
||||
sigset_t set;
|
||||
|
||||
/* Set up to receive signal */
|
||||
|
||||
ret = ioctl(fd, GPIOC_REGISTER, (unsigned long)signo);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to setup for signal from %s: %d\n",
|
||||
devpath, errcode);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Wait up to 5 seconds for the signal */
|
||||
|
||||
(void)sigemptyset(&set);
|
||||
(void)sigaddset(&set, signo);
|
||||
|
||||
ts.tv_sec = 5;
|
||||
ts.tv_nsec = 0;
|
||||
|
||||
ret = sigtimedwait(&set, &info, &ts);
|
||||
(void)ioctl(fd, GPIOC_UNREGISTER, 0);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
if (errcode == EAGAIN)
|
||||
{
|
||||
printf(" [Five second timeout with no signal]\n");
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to wait signal %d from %s: %d\n",
|
||||
signo, devpath, errcode);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Re-read the pin value */
|
||||
|
||||
ret = ioctl(fd, GPIOC_READ, (unsigned long)((uintptr_t)&invalue));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to re-read value from %s: %d\n",
|
||||
devpath, errcode);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf(" Verify: Value=%u\n", (unsigned int)invalue);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "ERROR: Unrecognized pintype: %d\n", (int)pintype);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -48,8 +48,8 @@
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/ipmsfilter.h>
|
||||
#include "netutils/netlib.h"
|
||||
#include "netutils/ipmsfilter.h"
|
||||
|
||||
#include "igmp.h"
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <apps/netutils/cJSON.h>
|
||||
#include "netutils/cJSON.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
|
@ -155,7 +155,7 @@ int media_main(int argc, FAR char *argv[])
|
||||
devpath = argv[1];
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDWR);
|
||||
fd = open(devpath, O_RDWR);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
|
@ -68,8 +68,8 @@
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <apps/modbus/mb.h>
|
||||
#include <apps/modbus/mbport.h>
|
||||
#include "modbus/mb.h"
|
||||
#include "modbus/mbport.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
@ -52,7 +52,7 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include <nuttx/module.h>
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include <nuttx/fs/mkfatfs.h>
|
||||
|
||||
#include "mount.h"
|
||||
|
@ -47,12 +47,13 @@
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/drivers/drivers.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* Make sure that support for MTD partitions is enabled */
|
||||
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/drivers/drivers.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_MTDRWB
|
||||
@ -124,10 +124,6 @@ static uint8_t g_simflash[MTDRWB_BUFSIZE];
|
||||
extern FAR struct mtd_dev_s *mtdrwb_archinitialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -58,7 +58,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "netloop.h"
|
||||
|
||||
|
@ -52,7 +52,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "nettest.h"
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
||||
|
||||
#include <nuttx/wireless/nrf24l01.h>
|
||||
|
||||
#include <apps/readline.h>
|
||||
#include "system/readline.h"
|
||||
|
||||
#ifdef CONFIG_DISABLE_POLL
|
||||
# error The poll interface is required for the nRF24L01 terminal example. You must disable config option DISABLE_POLL.
|
||||
|
@ -55,7 +55,7 @@
|
||||
# include <nuttx/binfmt/symtab.h>
|
||||
#endif
|
||||
|
||||
#include <apps/nsh.h>
|
||||
#include "nshlib/nshlib.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
@ -49,7 +49,7 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
#include <nuttx/binfmt/nxflat.h>
|
||||
|
||||
|
@ -66,7 +66,7 @@
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
#include <nuttx/nx/nxterm.h>
|
||||
|
||||
#include <apps/nsh.h>
|
||||
#include "nshlib/nshlib.h"
|
||||
|
||||
#include "nxterm_internal.h"
|
||||
|
||||
|
11
examples/oneshot/.gitignore
vendored
Normal file
11
examples/oneshot/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
65
examples/oneshot/Kconfig
Normal file
65
examples/oneshot/Kconfig
Normal file
@ -0,0 +1,65 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_ONESHOT
|
||||
bool "Oneshot timer example"
|
||||
default n
|
||||
depends on ONESHOT
|
||||
---help---
|
||||
Enable the oneshot timer driver example
|
||||
|
||||
if EXAMPLES_ONESHOT
|
||||
|
||||
config EXAMPLE_ONESHOT_DEVNAME
|
||||
string "Oneshot time device name"
|
||||
default "/dev/oneshot"
|
||||
---help---
|
||||
This is the default name of the timer device that will be tested if
|
||||
one is not specified on the command line.
|
||||
|
||||
config EXAMPLE_ONESHOT_DELAY
|
||||
int "Sample delay (microseconds)"
|
||||
default 100000
|
||||
---help---
|
||||
This is the default delay samples in microseconds if one is not
|
||||
specified on the command line
|
||||
|
||||
config EXAMPLE_ONESHOT_SIGNO
|
||||
int "Signal number"
|
||||
default 13
|
||||
---help---
|
||||
This is the number of the signal that will be used in the oneshot
|
||||
notification.
|
||||
|
||||
config EXAMPLES_ONESHOT_APPNAME
|
||||
string "Oneshot timer executable name"
|
||||
default "oneshot"
|
||||
depends on NSH_BUILTIN_APPS
|
||||
---help---
|
||||
This is the name of the built-in application
|
||||
|
||||
config EXAMPLES_ONESHOT_STACKSIZE
|
||||
int "Oneshot timer stack size"
|
||||
default 2048
|
||||
depends on NSH_BUILTIN_APPS
|
||||
---help---
|
||||
This is the stack size allocated when the oneshot timer task runs
|
||||
|
||||
config EXAMPLES_ONESHOT_PRIORITY
|
||||
int "Oneshot timer task priority"
|
||||
default 100
|
||||
depends on NSH_BUILTIN_APPS
|
||||
---help---
|
||||
This is the priority of the oneshot timer task
|
||||
|
||||
config EXAMPLES_ONESHOT_PROGNAME
|
||||
string "Oneshot timer program name"
|
||||
default "oneshot"
|
||||
depends on BUILD_KERNEL
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
endif
|
@ -1,5 +1,5 @@
|
||||
############################################################################
|
||||
# apps/system/usbmonitor/Make.defs
|
||||
# apps/examples/oneshot/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
@ -34,7 +34,6 @@
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_SYSTEM_USBMONITOR),y)
|
||||
CONFIGURED_APPS += system/usbmonitor
|
||||
ifeq ($(CONFIG_EXAMPLES_ONESHOT),y)
|
||||
CONFIGURED_APPS += examples/oneshot
|
||||
endif
|
||||
|
56
examples/oneshot/Makefile
Normal file
56
examples/oneshot/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
############################################################################
|
||||
# apps/examples/oneshot/Makefile
|
||||
#
|
||||
# Copyright (C) 2016 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
|
||||
|
||||
# Oneshot timer built-in application info
|
||||
|
||||
CONFIG_EXAMPLES_ONESHOT_APPNAME ?= "oneshot"
|
||||
CONFIG_EXAMPLES_ONESHOT_STACKSIZE ?= 2048
|
||||
CONFIG_EXAMPLES_ONESHOT_PRIORITY ?= 100
|
||||
CONFIG_EXAMPLES_ONESHOT_PROGNAME ?= "oneshot"
|
||||
|
||||
APPNAME = $(CONFIG_EXAMPLES_ONESHOT_APPNAME)
|
||||
PRIORITY = $(CONFIG_EXAMPLES_ONESHOT_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_ONESHOT_STACKSIZE)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_ONESHOT_PROGNAME)
|
||||
|
||||
# Oneshot timer example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = oneshot_main.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
270
examples/oneshot/oneshot_main.c
Normal file
270
examples/oneshot/oneshot_main.c
Normal file
@ -0,0 +1,270 @@
|
||||
/****************************************************************************
|
||||
* examples/oneshot/oneshot_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 <string.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/timers/oneshot.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLE_ONESHOT_DEVNAME
|
||||
# define CONFIG_EXAMPLE_ONESHOT_DEVNAME "/dev/oneshot"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLE_ONESHOT_DELAY
|
||||
# define CONFIG_EXAMPLE_ONESHOT_DELAY 100000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLE_ONESHOT_SIGNO
|
||||
# define CONFIG_EXAMPLE_ONESHOT_SIGNO 13
|
||||
#endif
|
||||
|
||||
/* For long delays that have to be broken into segments, some loss of
|
||||
* precision is expected due to interrupt and context switching overhead.
|
||||
* This inaccuracy will cause somewhat longer times than the time requested
|
||||
* due to this overhead. It might be possible to reduce this inaccuracy
|
||||
* some by (1) making this task very high priority so that it runs in a more
|
||||
* deterministic way, and (2) by subtracting a "fudge factor" to account for
|
||||
* time lost due to the overhead.
|
||||
*/
|
||||
|
||||
#define FUDGE_FACTOR 10
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: oneshot_main
|
||||
****************************************************************************/
|
||||
|
||||
static void show_usage(FAR const char *progname)
|
||||
{
|
||||
fprintf(stderr, "USAGE: %s [-d <usecs>] [<devname>]\n", progname);
|
||||
fprintf(stderr, "Where:\n");
|
||||
fprintf(stderr, "\t-d <usecs>:\n");
|
||||
fprintf(stderr, "\tSpecifies the oneshot delay in microseconds. Default %ld\n",
|
||||
(unsigned long)CONFIG_EXAMPLE_ONESHOT_DELAY);
|
||||
fprintf(stderr, "\t<devname>:\n");
|
||||
fprintf(stderr, "\tSpecifies the path to the oneshot driver. Default %s\n",
|
||||
CONFIG_EXAMPLE_ONESHOT_DEVNAME);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: oneshot_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int oneshot_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
FAR const char *devname = CONFIG_EXAMPLE_ONESHOT_DEVNAME;
|
||||
unsigned long usecs = CONFIG_EXAMPLE_ONESHOT_DELAY;
|
||||
unsigned long secs;
|
||||
struct oneshot_start_s start;
|
||||
struct siginfo info;
|
||||
struct timespec ts;
|
||||
uint64_t maxus;
|
||||
sigset_t set;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
/* USAGE: nsh> oneshot [-d <usecs>] [<devname>] */
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
if (argc == 2)
|
||||
{
|
||||
/* FORM: nsh> oneshot [<devname>] */
|
||||
|
||||
devname = argv[1];
|
||||
}
|
||||
else if (argc < 5)
|
||||
{
|
||||
/* FORM: nsh> oneshot [-d <usecs>] */
|
||||
|
||||
if (strcmp(argv[1], "-d") != 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[1]);
|
||||
show_usage(argv[0]);
|
||||
}
|
||||
|
||||
usecs = strtoul(argv[2], NULL, 10);
|
||||
|
||||
if (argc == 4)
|
||||
{
|
||||
/* FORM: nsh> oneshot [-d <usecs>] [<devname>] */
|
||||
|
||||
devname = argv[3];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unsupported number of arguments: %d\n", argc);
|
||||
show_usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Open the oneshot device */
|
||||
|
||||
printf("Opening %s\n", devname);
|
||||
|
||||
fd = open(devname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to open %s: %d\n",
|
||||
devname, errno);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Get the maximum delay */
|
||||
|
||||
ret = ioctl(fd, OSIOC_MAXDELAY, (unsigned long)((uintptr_t)&ts));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to get the maximum delayl: %d\n",
|
||||
errno);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
maxus = (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000;
|
||||
|
||||
printf("Maximum delay is %llu\n", maxus);
|
||||
|
||||
/* Loop waiting until the full delay expires */
|
||||
|
||||
while (usecs > 0)
|
||||
{
|
||||
/* Start the oneshot timer */
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, CONFIG_EXAMPLE_ONESHOT_SIGNO);
|
||||
|
||||
if (usecs < maxus)
|
||||
{
|
||||
/* Wait for the remaining time */
|
||||
|
||||
printf("Starting oneshot timer with delay %lu microseconds\n",
|
||||
usecs);
|
||||
|
||||
start.pid = 0;
|
||||
start.signo = CONFIG_EXAMPLE_ONESHOT_SIGNO;
|
||||
start.arg = NULL;
|
||||
|
||||
secs = usecs / 1000000;
|
||||
usecs -= 1000000 * secs;
|
||||
|
||||
start.ts.tv_sec = secs;
|
||||
start.ts.tv_nsec = usecs * 1000;
|
||||
|
||||
/* Zero usecs to terminate the loop */
|
||||
|
||||
usecs = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Wait for the maximum */
|
||||
|
||||
printf("Starting oneshot timer with delay %llu microseconds\n",
|
||||
maxus);
|
||||
|
||||
start.ts.tv_sec = ts.tv_sec;
|
||||
start.ts.tv_nsec = ts.tv_nsec;
|
||||
|
||||
usecs -= maxus;
|
||||
|
||||
#if FUDGE_FACTOR > 0
|
||||
if (usecs > FUDGE_FACTOR)
|
||||
{
|
||||
usecs -= FUDGE_FACTOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
usecs = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ret = ioctl(fd, OSIOC_START, (unsigned long)((uintptr_t)&start));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to start the oneshot interval: %d\n",
|
||||
errno);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Wait for the oneshot to fire */
|
||||
|
||||
printf("Waiting...\n");
|
||||
ret = sigwaitinfo(&set, &info);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: sigwaitinfo failed: %d\n",
|
||||
errno);
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the oneshot driver */
|
||||
|
||||
printf("Finished\n");
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -43,7 +43,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <apps/interpreters/prun.h>
|
||||
#include "interpreters/prun.h"
|
||||
|
||||
#include "pashello.h"
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
config EXAMPLES_PIPE
|
||||
bool "Pipe example"
|
||||
default n
|
||||
depends on PIPES
|
||||
---help---
|
||||
Enable the pipe example
|
||||
|
||||
|
@ -48,22 +48,6 @@
|
||||
|
||||
#include "pipe.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -78,12 +62,16 @@ int main(int argc, FAR char *argv[])
|
||||
int pipe_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
#if CONFIG_DEV_FIFO_SIZE > 0 || CONFIG_DEV_PIPE_SIZE > 0
|
||||
int fd[2];
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
#if CONFIG_DEV_FIFO_SIZE > 0
|
||||
/* Test FIFO logic */
|
||||
|
||||
printf("\npipe_main: Performing FIFO test\n");
|
||||
|
||||
ret = mkfifo(FIFO_PATH1, 0666);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -91,16 +79,17 @@ int pipe_main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Open one end of the FIFO for reading and the other end for writing. NOTE:
|
||||
* the following might not work on most FIFO implementations because the attempt
|
||||
* to open just one end of the FIFO for writing might block. The NuttX FIFOs block
|
||||
* only on open for read-only (see interlock_test()).
|
||||
/* Open one end of the FIFO for reading and the other end for writing.
|
||||
* NOTE: The following might not work on most FIFO implementations because
|
||||
* the attempt to open just one end of the FIFO for writing might block.
|
||||
* The NuttX FIFOs block only on open for read-only (see interlock_test()).
|
||||
*/
|
||||
|
||||
fd[1] = open(FIFO_PATH1, O_WRONLY);
|
||||
if (fd[1] < 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: Failed to open FIFO %s for writing, errno=%d\n",
|
||||
fprintf(stderr,
|
||||
"pipe_main: Failed to open FIFO %s for writing, errno=%d\n",
|
||||
FIFO_PATH1, errno);
|
||||
return 2;
|
||||
}
|
||||
@ -108,12 +97,14 @@ int pipe_main(int argc, char *argv[])
|
||||
fd[0] = open(FIFO_PATH1, O_RDONLY);
|
||||
if (fd[0] < 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: Failed to open FIFO %s for reading, errno=%d\n",
|
||||
fprintf(stderr,
|
||||
"pipe_main: Failed to open FIFO %s for reading, errno=%d\n",
|
||||
FIFO_PATH1, errno);
|
||||
if (close(fd[1]) != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
||||
}
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
@ -124,10 +115,12 @@ int pipe_main(int argc, char *argv[])
|
||||
{
|
||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
||||
}
|
||||
|
||||
if (close(fd[1]) != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
||||
}
|
||||
|
||||
/* unlink(FIFO_PATH1); fails */
|
||||
|
||||
if (ret != 0)
|
||||
@ -135,11 +128,19 @@ int pipe_main(int argc, char *argv[])
|
||||
fprintf(stderr, "pipe_main: FIFO test FAILED (%d)\n", ret);
|
||||
return 4;
|
||||
}
|
||||
|
||||
printf("pipe_main: FIFO test PASSED\n");
|
||||
|
||||
#else
|
||||
printf("\npipe_main: Skipping FIFO test\n");
|
||||
|
||||
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
|
||||
|
||||
#if CONFIG_DEV_PIPE_SIZE > 0
|
||||
/* Test PIPE logic */
|
||||
|
||||
printf("\npipe_main: Performing pipe test\n");
|
||||
|
||||
ret = pipe(fd);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -164,6 +165,7 @@ int pipe_main(int argc, char *argv[])
|
||||
fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret);
|
||||
return 6;
|
||||
}
|
||||
|
||||
printf("pipe_main: PIPE test PASSED\n");
|
||||
|
||||
/* Perform the FIFO interlock test */
|
||||
@ -175,6 +177,7 @@ int pipe_main(int argc, char *argv[])
|
||||
fprintf(stderr, "pipe_main: FIFO interlock test FAILED (%d)\n", ret);
|
||||
return 7;
|
||||
}
|
||||
|
||||
printf("pipe_main: PIPE interlock test PASSED\n");
|
||||
|
||||
/* Perform the pipe redirection test */
|
||||
@ -186,8 +189,14 @@ int pipe_main(int argc, char *argv[])
|
||||
fprintf(stderr, "pipe_main: FIFO redirection test FAILED (%d)\n", ret);
|
||||
return 7;
|
||||
}
|
||||
|
||||
printf("pipe_main: PIPE redirection test PASSED\n");
|
||||
|
||||
#else
|
||||
printf("\npipe_main: Skipping pipe test\n");
|
||||
|
||||
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */
|
||||
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
config EXAMPLES_POLL
|
||||
bool "Poll example"
|
||||
default n
|
||||
depends on !NSH_BUILTIN_APPS
|
||||
depends on !NSH_BUILTIN_APPS && PIPES
|
||||
---help---
|
||||
Enable the poll example
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "poll_internal.h"
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "poll_internal.h"
|
||||
|
||||
|
@ -148,7 +148,7 @@ spawn_main.o: spawn_main.c \
|
||||
$(TOPDIR)/include/spawn.h \
|
||||
$(TOPDIR)/include/debug.h \
|
||||
$(TOPDIR)/include/errno.h \
|
||||
$(TOPDIR)/include/nuttx/fs/ramdisk.h \
|
||||
$(TOPDIR)/include/nuttx/drivers/ramdisk.h \
|
||||
$(TOPDIR)/include/nuttx/binfmt/elf.h \
|
||||
$(TOPDIR)/include/nuttx/binfmt/symtab.h \
|
||||
filesystem/romfs.h
|
||||
|
@ -51,7 +51,7 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <apps/netutils/pppd.h>
|
||||
#include "netutils/pppd.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
11
examples/pty_test/.gitignore
vendored
Normal file
11
examples/pty_test/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
48
examples/pty_test/Kconfig
Normal file
48
examples/pty_test/Kconfig
Normal file
@ -0,0 +1,48 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_PTYTEST
|
||||
bool "Pseudo Terminal test example"
|
||||
default n
|
||||
depends on PSEUDOTERM
|
||||
select PSEUDOTERM_SUSV1
|
||||
---help---
|
||||
Enable the PTY example
|
||||
|
||||
if EXAMPLES_PTYTEST
|
||||
|
||||
config EXAMPLES_PTYTEST_PROGNAME
|
||||
string "Program name"
|
||||
default "pts"
|
||||
depends on BUILD_KERNEL
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_PTYTEST_POLL
|
||||
bool "Test poll() with data transfers"
|
||||
default n
|
||||
|
||||
config EXAMPLES_PTYTEST_SERIALDEV
|
||||
string "Test serial device"
|
||||
default "/dev/ttyS1"
|
||||
|
||||
config EXAMPLES_PTYTEST_PRIORITY
|
||||
int "PTY_Test task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_PTYTEST_STACKSIZE
|
||||
int "PTYTest stack size"
|
||||
default 2048
|
||||
|
||||
config EXAMPLES_PTYTEST_DAEMONPRIO,
|
||||
int "PTY_Test daemon task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_PTYTEST_STACKSIZE
|
||||
int "PTY_Test daemon stack size"
|
||||
default 2048
|
||||
|
||||
endif
|
39
examples/pty_test/Make.defs
Normal file
39
examples/pty_test/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/pty_test/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2016 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_PTYTEST),y)
|
||||
CONFIGURED_APPS += examples/pty_test
|
||||
endif
|
57
examples/pty_test/Makefile
Normal file
57
examples/pty_test/Makefile
Normal file
@ -0,0 +1,57 @@
|
||||
############################################################################
|
||||
# apps/examples/pty_test/Makefile
|
||||
#
|
||||
# Copyright (C) 2016 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
|
||||
|
||||
# Hello, World! built-in application info
|
||||
|
||||
CONFIG_EXAMPLES_PTYTEST_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_PTYTEST_STACKSIZE ?= 8192
|
||||
|
||||
APPNAME = pty_test
|
||||
PRIORITY = $(CONFIG_EXAMPLES_PTYTEST_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_PTYTEST_STACKSIZE)
|
||||
|
||||
# PTY Test! Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
CFLAGS += -I$(APPDIR)/include
|
||||
MAINSRC = pty_test.c
|
||||
|
||||
CONFIG_EXAMPLES_PTYTEST_PROGNAME ?= pty_test$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_PTYTEST_PROGNAME)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
416
examples/pty_test/pty_test.c
Normal file
416
examples/pty_test/pty_test.c
Normal file
@ -0,0 +1,416 @@
|
||||
/****************************************************************************
|
||||
* examples/pty_test/pty_test.c
|
||||
*
|
||||
* Copyright (C) 2016, Gregory Nutt. All rights reserved.
|
||||
* Author: Alan Carvalho de Assisi <acassis@gmail.com>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <termios.h>
|
||||
#include <poll.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <nuttx/serial/pty.h>
|
||||
|
||||
#include "nshlib/nshlib.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_PTYTEST_SERIALDEV
|
||||
# define CONFIG_EXAMPLES_PTYTEST_SERIALDEV "/dev/ttyS1"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_PTYTEST_DAEMONPRIO
|
||||
# define CONFIG_EXAMPLES_PTYTEST_DAEMONPRIO SCHED_PRIORITY_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_PTYTEST_STACKSIZE
|
||||
# define CONFIG_EXAMPLES_PTYTEST_STACKSIZE 2048
|
||||
#endif
|
||||
|
||||
#define POLL_TIMEOUT 200
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
struct term_pair_s
|
||||
{
|
||||
int fd_uart;
|
||||
int fd_pty;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: serial_in
|
||||
*
|
||||
* Description:
|
||||
* Read data from serial and write to pts
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void serial_in(struct term_pair_s *tp)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
struct pollfd fdp;
|
||||
#endif
|
||||
char buffer[16];
|
||||
int ret;
|
||||
|
||||
if (!tp)
|
||||
{
|
||||
fprintf(stderr, "ERROR: terminal pair struct is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
fdp.fd = tp->fd_uart;
|
||||
fdp.events = POLLIN;
|
||||
#endif
|
||||
|
||||
/* Run forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
ret = poll((struct pollfd *)&fdp, 1, POLL_TIMEOUT);
|
||||
if (ret > 0)
|
||||
{
|
||||
if ((fdp.revents & POLLIN) != 0)
|
||||
#endif
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
len = read(tp->fd_uart, buffer, 16);
|
||||
if (len < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR Failed to read from serial: %d\n",
|
||||
errno);
|
||||
}
|
||||
else if (len > 0)
|
||||
{
|
||||
ret = write(tp->fd_pty, buffer, len);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Failed to write to serial: %d\n",
|
||||
errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
}
|
||||
|
||||
/* Timeout */
|
||||
|
||||
else if (ret == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Poll error */
|
||||
|
||||
else if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: poll failed: %d\n", errno);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: serial_out
|
||||
*
|
||||
* Description:
|
||||
* Read data from pts and write to serial
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void serial_out(struct term_pair_s *tp)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
struct pollfd fdp;
|
||||
#endif
|
||||
char buffer[16];
|
||||
int ret;
|
||||
|
||||
if (!tp)
|
||||
{
|
||||
fprintf(stderr, "Error: terminal pair struct is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
fdp.fd = tp->fd_pty;
|
||||
fdp.events = POLLIN;
|
||||
#endif
|
||||
|
||||
/* Run forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
ret = poll((struct pollfd *)&fdp, 1, POLL_TIMEOUT);
|
||||
if (ret > 0)
|
||||
{
|
||||
if ((fdp.revents & POLLIN) != 0)
|
||||
#endif
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
len = read(tp->fd_pty, buffer, 16);
|
||||
if (len < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR: Failed to read from pseudo-terminal: %d\n",
|
||||
errno);
|
||||
}
|
||||
else if (len > 0)
|
||||
{
|
||||
ret = write(tp->fd_uart, buffer, len);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR: Failed to write to serial: %d\n",
|
||||
errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
}
|
||||
|
||||
/* Timeout */
|
||||
|
||||
else if (ret == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* poll error */
|
||||
|
||||
else if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: poll failed: %d\n", errno);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pty_test_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int pty_test_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
struct term_pair_s termpair;
|
||||
struct termios tio;
|
||||
pthread_t si_thread;
|
||||
pthread_t so_thread;
|
||||
char buffer[16];
|
||||
pid_t pid;
|
||||
int fd_pts;
|
||||
int ret;
|
||||
|
||||
printf("Create pseudo-terminal\n");
|
||||
|
||||
/* Open pseudo-terminal master (pts factory) */
|
||||
|
||||
termpair.fd_pty = open("/dev/ptmx", O_RDWR | O_NOCTTY);
|
||||
if (termpair.fd_pty < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to opening /dev/ptmx: %d\n",
|
||||
errno);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Grant access and unlock the slave PTY */
|
||||
|
||||
ret = grantpt(termpair.fd_pty);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: grantpt() failed: %d\n", errno);
|
||||
goto error_pts;
|
||||
}
|
||||
|
||||
ret = unlockpt(termpair.fd_pty);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: unlockpt() failed: %d\n", errno);
|
||||
goto error_pts;
|
||||
}
|
||||
|
||||
/* Get the create pts file-name */
|
||||
|
||||
ret = ptsname_r(termpair.fd_pty, buffer, 16);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ptsname_r() failed: %d\n", errno);
|
||||
goto error_pts;
|
||||
}
|
||||
|
||||
/* Open the created pts */
|
||||
|
||||
fd_pts = open(buffer, O_RDWR | O_NONBLOCK);
|
||||
if (fd_pts < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to open %s: %d\n", buffer, errno);
|
||||
goto error_pts;
|
||||
}
|
||||
|
||||
/* Open the second serial port to create a new console there */
|
||||
|
||||
termpair.fd_uart = open(CONFIG_EXAMPLES_PTYTEST_SERIALDEV,
|
||||
O_RDWR | O_NONBLOCK);
|
||||
if (termpair.fd_uart < 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to open %s: %\n",
|
||||
CONFIG_EXAMPLES_PTYTEST_SERIALDEV, errno);
|
||||
goto error_serial;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SERIAL_TERMIOS
|
||||
/* Enable \n -> \r\n conversion during write */
|
||||
|
||||
ret = tcgetattr(termpair.fd_uart, &tio);
|
||||
if (ret)
|
||||
{
|
||||
fprintf(stderr, "ERROR: tcgetattr() failed: %d\n", errno);
|
||||
goto error_serial;
|
||||
}
|
||||
|
||||
tio.c_oflag = OPOST | ONLCR;
|
||||
ret = tcsetattr(termpair.fd_uart, TCSANOW, &tio);
|
||||
if (ret)
|
||||
{
|
||||
fprintf(stderr, "ERROR: tcsetattr() failed: %d\n", errno);
|
||||
goto error_serial;
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("Starting a new NSH Session using %s\n", buffer);
|
||||
|
||||
/* Close default stdin, stdout and stderr */
|
||||
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
|
||||
/* Use this pts file as stdin, stdout, and stderr */
|
||||
|
||||
(void)dup2(fd_pts, 0);
|
||||
(void)dup2(fd_pts, 1);
|
||||
(void)dup2(fd_pts, 2);
|
||||
|
||||
/* Create a new console using this /dev/pts/N */
|
||||
|
||||
pid = task_create("NSH Console", CONFIG_EXAMPLES_PTYTEST_DAEMONPRIO,
|
||||
CONFIG_EXAMPLES_PTYTEST_STACKSIZE, nsh_consolemain, NULL);
|
||||
if (pid < 0)
|
||||
{
|
||||
/* Can't do output because stdout and stderr are redirected */
|
||||
|
||||
goto error_console;
|
||||
}
|
||||
|
||||
/* Start a thread to read from serial */
|
||||
|
||||
ret = pthread_create(&si_thread, NULL,
|
||||
(pthread_startroutine_t)serial_in,
|
||||
(pthread_addr_t)&termpair);
|
||||
if (ret != 0)
|
||||
{
|
||||
/* Can't do output because stdout and stderr are redirected */
|
||||
|
||||
goto error_thread1;
|
||||
}
|
||||
|
||||
/* Start a thread to write to serial */
|
||||
|
||||
ret = pthread_create(&so_thread, NULL,
|
||||
(pthread_startroutine_t)serial_out,
|
||||
(pthread_addr_t)&termpair);
|
||||
if (ret != 0)
|
||||
{
|
||||
/* Can't do output because stdout and stderr are redirected */
|
||||
|
||||
goto error_thread2;
|
||||
}
|
||||
|
||||
/* Stay here to keep the threads running */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Nothing to do, then sleep to avoid eating all cpu time */
|
||||
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
error_thread2:
|
||||
error_thread1:
|
||||
error_console:
|
||||
close(termpair.fd_uart);
|
||||
error_serial:
|
||||
close(fd_pts);
|
||||
error_pts:
|
||||
close(termpair.fd_pty);
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
@ -51,7 +51,7 @@
|
||||
#include <debug.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/pwm.h>
|
||||
#include <nuttx/drivers/pwm.h>
|
||||
|
||||
#include "pwm.h"
|
||||
|
||||
|
11
examples/rfid_readuid/.gitignore
vendored
Normal file
11
examples/rfid_readuid/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
30
examples/rfid_readuid/Kconfig
Normal file
30
examples/rfid_readuid/Kconfig
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_RFID_READUID
|
||||
bool "RFID Read UID example"
|
||||
default n
|
||||
---help---
|
||||
Enable the RFID READUID example
|
||||
|
||||
if EXAMPLES_RFID_READUID
|
||||
|
||||
config EXAMPLES_RFID_READUID_PROGNAME
|
||||
string "Program name"
|
||||
default "rfid_readuid"
|
||||
depends on BUILD_KERNEL
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_RFID_READUID_PRIORITY
|
||||
int "RFID Read UID task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_RFID_READUID_STACKSIZE
|
||||
int "RFID Read UID stack size"
|
||||
default 2048
|
||||
|
||||
endif
|
39
examples/rfid_readuid/Make.defs
Normal file
39
examples/rfid_readuid/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/rfid_readuid/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2016 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_RFID_READUID),y)
|
||||
CONFIGURED_APPS += examples/rfid_readuid
|
||||
endif
|
56
examples/rfid_readuid/Makefile
Normal file
56
examples/rfid_readuid/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
############################################################################
|
||||
# apps/examples/rfid_readuid/Makefile
|
||||
#
|
||||
# Copyright (C) 2016 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
|
||||
|
||||
# RFID Read UID built-in application info
|
||||
|
||||
CONFIG_EXAMPLES_RFID_READUID_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_RFID_READUID_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = rfid_readuid
|
||||
PRIORITY = $(CONFIG_EXAMPLES_RFID_READUID_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_RFID_READUID_STACKSIZE)
|
||||
|
||||
# RFID Read UID Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = rfid_readuid.c
|
||||
|
||||
CONFIG_EXAMPLES_RFID_READUID_PROGNAME ?= rfid_readuid$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_RFID_READUID_PROGNAME)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* apps/include/usbmonitor.h
|
||||
* examples/rfid_readuid/rfid_readuid.c
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -33,64 +33,87 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_INCLUDE_USBMONITOR_H
|
||||
#define __APPS_INCLUDE_USBMONITOR_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef CONFIG_SYSTEM_USBMONITOR
|
||||
#include <nuttx/wireless/mfrc522.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_WL_MFRC522
|
||||
# error "CONFIG_WL_MFRC522 is not defined in the configuration"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_RFID_READUID_DEVNAME
|
||||
# define CONFIG_EXAMPLES_RFID_READUID_DEVNAME "/dev/rfid0"
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
/****************************************************************************
|
||||
* rfid_readuid_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
#define EXTERN extern
|
||||
int rfid_readuid_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
int count = 0;
|
||||
char buffer[10];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
fd = open(CONFIG_EXAMPLES_RFID_READUID_DEVNAME, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("Failed to open %s\n", CONFIG_EXAMPLES_RFID_READUID_DEVNAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbmon_start and usbmon_stop
|
||||
*
|
||||
* Start and top the USB monitor daemon. These are normally controlled
|
||||
* from the USB command line, but the ability to control these
|
||||
* programmatically is also helpful (for example, so that the daemon is
|
||||
* running before NSH starts).
|
||||
*
|
||||
* Input Parameters:
|
||||
* Standard task parameters. These can be called or spawned. Since the
|
||||
* return almost immediately, it is fine to just call the functions. The
|
||||
* parameters are not used so you can pass 0 and NULL, respectivley; this
|
||||
* is done this way so that these functions can be NSH builtin
|
||||
* applications.
|
||||
*
|
||||
* Returned values:
|
||||
* Standard task return values (zero meaning success).
|
||||
*
|
||||
****************************************************************************/
|
||||
/* Try to read a card up to 3 times */
|
||||
|
||||
int usbmonitor_start(int argc, char **argv);
|
||||
int usbmonitor_stop(int argc, char **argv);
|
||||
while (count < 3)
|
||||
{
|
||||
printf("Trying to READ: ");
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
/* 11 bytes = 0x12345678\0 */
|
||||
|
||||
ret = read(fd, buffer, 11);
|
||||
if (ret == 11)
|
||||
{
|
||||
printf("RFID CARD UID = %s\n", buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == -EAGAIN || ret == -EPERM)
|
||||
{
|
||||
printf("Card is not present!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown error!\n");
|
||||
}
|
||||
|
||||
/* Wait 500ms before trying again */
|
||||
|
||||
usleep(500000);
|
||||
count++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SYSTEM_USBMONITOR */
|
||||
#endif /* __APPS_INCLUDE_USBMONITOR_H */
|
@ -69,7 +69,7 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
|
||||
#include "romfs_testdir.h"
|
||||
|
||||
|
@ -49,8 +49,8 @@
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/smtp.h>
|
||||
#include "netutils/netlib.h"
|
||||
#include "netutils/smtp.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Defintitions
|
||||
|
@ -58,7 +58,7 @@
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <nuttx/net/arp.h>
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_TCPECHO_DHCPC
|
||||
# include <arpa/inet.h>
|
||||
@ -71,7 +71,7 @@
|
||||
/* DHCPC may be used in conjunction with any other feature (or not) */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_TCPECHO_DHCPC
|
||||
# include <apps/netutils/dhcpc.h>
|
||||
# include "netutils/dhcpc.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -48,8 +48,8 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/telnetd.h>
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/telnetd.h"
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "telnetd.h"
|
||||
|
||||
|
@ -54,10 +54,10 @@
|
||||
#include <netinet/ether.h>
|
||||
|
||||
#include <nuttx/net/arp.h>
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/thttpd.h>
|
||||
#include "netutils/netlib.h"
|
||||
#include "netutils/thttpd.h"
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
#ifdef CONFIG_THTTPD_NXFLAT
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <apps/tiff.h>
|
||||
#include "graphics/tiff.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
|
@ -8,7 +8,7 @@ config EXAMPLES_TIMER
|
||||
default n
|
||||
depends on TIMER && BUILD_FLAT
|
||||
---help---
|
||||
Enable the \"Timer, World!\" example
|
||||
Enable the timer example
|
||||
|
||||
if EXAMPLES_TIMER
|
||||
|
||||
|
@ -47,7 +47,7 @@ PRIORITY = $(CONFIG_EXAMPLES_TIMER_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_TIMER_STACKSIZE)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_TIMER_PROGNAME)
|
||||
|
||||
# Timer, World! Example
|
||||
# Timer example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
|
@ -68,7 +68,7 @@
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "udp-internal.h"
|
||||
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#include "udpblaster.h"
|
||||
|
||||
|
@ -52,7 +52,7 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/ramdisk.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include <nuttx/fs/unionfs.h>
|
||||
|
||||
#include "romfs_atestdir.h"
|
||||
|
@ -51,7 +51,7 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <apps/readline.h>
|
||||
#include "system/readline.h"
|
||||
|
||||
#include <nuttx/usb/usbdev.h>
|
||||
#include <nuttx/usb/usbdev_trace.h>
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <apps/netutils/httpd.h>
|
||||
#include "netutils/httpd.h"
|
||||
|
||||
#include "cgi.h"
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/net/arp.h>
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC
|
||||
#include <arpa/inet.h>
|
||||
@ -70,12 +70,12 @@
|
||||
/* DHCPC may be used in conjunction with any other feature (or not) */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC
|
||||
# include <apps/netutils/dhcpc.h>
|
||||
# include "netutils/dhcpc.h"
|
||||
#endif
|
||||
|
||||
/* Include uIP webserver definitions */
|
||||
|
||||
#include <apps/netutils/httpd.h>
|
||||
#include "netutils/httpd.h"
|
||||
|
||||
#include "cgi.h"
|
||||
|
||||
|
@ -46,8 +46,8 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/webclient.h>
|
||||
#include "netutils/netlib.h"
|
||||
#include "netutils/webclient.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Preprocessor Definitions
|
||||
|
@ -49,9 +49,9 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/webclient.h>
|
||||
#include <apps/netutils/cJSON.h>
|
||||
#include "netutils/netlib.h"
|
||||
#include "netutils/webclient.h"
|
||||
#include "netutils/cJSON.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
@ -45,7 +45,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <apps/netutils/xmlrpc.h>
|
||||
#include "netutils/xmlrpc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user