Merge remote-tracking branch 'apps/NxWidgets'
This commit is contained in:
commit
68877ca48c
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
.depend
|
||||
Make.dep
|
||||
*.o
|
||||
*.a
|
||||
*.d
|
||||
@ -8,3 +10,15 @@
|
||||
core
|
||||
.gdbinit
|
||||
cscope.out
|
||||
/Kconfig
|
||||
/bin
|
||||
/exe
|
||||
/external
|
||||
/.context
|
||||
/.config
|
||||
/.depend
|
||||
/*.lib
|
||||
/romfs.img
|
||||
/boot_romfsimg.h
|
||||
/*/*/.built
|
||||
|
||||
|
258
Application.mk
Normal file
258
Application.mk
Normal file
@ -0,0 +1,258 @@
|
||||
############################################################################
|
||||
# apps/Application.mk
|
||||
#
|
||||
# Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||
# Authors: Gregory Nutt <gnutt@nuttx.org>
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# If this is an executable program (with MAINSRC), we must build it as a
|
||||
# loadable module for the KERNEL build (always) or if the tristate module
|
||||
# has the value "m"
|
||||
|
||||
ifneq ($(MAINSRC),)
|
||||
ifeq ($($(MODULE)),m)
|
||||
BUILD_MODULE = y
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
BUILD_MODULE = y
|
||||
endif
|
||||
|
||||
# Pass the definition to the C/C++ code via the CFLAGS/CXXFLAGS
|
||||
|
||||
ifeq ($(BUILD_MODULE),y)
|
||||
CFLAGS += ${shell $(DEFINE) "$(CC)" BUILD_MODULE}
|
||||
CXXFLAGS += ${shell $(DEFINE) "$(CC)" BUILD_MODULE}
|
||||
endif
|
||||
|
||||
# File extensions
|
||||
|
||||
CXXEXT ?= .cxx
|
||||
|
||||
# Object files
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
CXXOBJS = $(CXXSRCS:$(CXXEXT)=$(OBJEXT))
|
||||
|
||||
ifeq ($(suffix $(MAINSRC)),$(CXXEXT))
|
||||
MAINOBJ = $(MAINSRC:$(CXXEXT)=$(OBJEXT))
|
||||
else
|
||||
MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
|
||||
endif
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
|
||||
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
|
||||
|
||||
ifneq ($(BUILD_MODULE),y)
|
||||
OBJS += $(MAINOBJ)
|
||||
endif
|
||||
|
||||
# Module install directory
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)$(DELIM)libapps$(LIBEXT)}"
|
||||
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
|
||||
else
|
||||
BIN = $(APPDIR)$(DELIM)libapps$(LIBEXT)
|
||||
INSTALL_DIR = $(BIN_DIR)
|
||||
endif
|
||||
|
||||
ROOTDEPPATH += --dep-path .
|
||||
|
||||
VPATH += :.
|
||||
|
||||
# Targets follow
|
||||
|
||||
all:: .built
|
||||
.PHONY: clean preconfig depend distclean
|
||||
.PRECIOUS: $(APPDIR)/libapps$(LIBEXT)
|
||||
|
||||
ifneq ($(CONFIG_BUILD_LOADABLE),y)
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
$(CXXOBJS): %$(OBJEXT): %$(CXXEXT)
|
||||
$(call COMPILEXX, $<, $@)
|
||||
|
||||
ifeq ($(suffix $(MAINSRC)),$(CXXEXT))
|
||||
$(MAINOBJ): %$(OBJEXT): %$(CXXEXT)
|
||||
$(call COMPILEXX, $<, $@)
|
||||
else
|
||||
$(MAINOBJ): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
define ELFASSEMBLE
|
||||
@echo "AS: $1"
|
||||
$(Q) $(CC) -c $(AELFFLAGS) $1 -o $2
|
||||
endef
|
||||
|
||||
define ELFCOMPILE
|
||||
@echo "CC: $1"
|
||||
$(Q) $(CC) -c $(CELFFLAGS) $1 -o $2
|
||||
endef
|
||||
|
||||
define ELFCOMPILEXX
|
||||
@echo "CXX: $1"
|
||||
$(Q) $(CXX) -c $(CXXELFFLAGS) $1 -o $2
|
||||
endef
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(if $(AELFFLAGS), \
|
||||
$(call ELFASSEMBLE, $<, $@), \
|
||||
$(call ASSEMBLE, $<, $@) \
|
||||
)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(if $(CELFFLAGS), \
|
||||
$(call ELFCOMPILE, $<, $@), \
|
||||
$(call COMPILE, $<, $@) \
|
||||
)
|
||||
|
||||
$(CXXOBJS): %$(OBJEXT): %$(CXXEXT)
|
||||
$(if $(CXXELFFLAGS), \
|
||||
$(call ELFCOMPILEXX, $<, $@), \
|
||||
$(call COMPILEXX, $<, $@) \
|
||||
)
|
||||
|
||||
ifeq ($(suffix $(MAINSRC)),$(CXXEXT))
|
||||
$(MAINOBJ): %$(OBJEXT): %$(CXXEXT)
|
||||
$(if $(CXXELFFLAGS), \
|
||||
$(call ELFCOMPILEXX, $<, $@), \
|
||||
$(call COMPILEXX, $<, $@) \
|
||||
)
|
||||
else
|
||||
$(MAINOBJ): %$(OBJEXT): %.c
|
||||
$(if $(CELFFLAGS), \
|
||||
$(call ELFCOMPILE, $<, $@), \
|
||||
$(call COMPILE, $<, $@) \
|
||||
)
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
.built: $(OBJS)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
$(Q) touch $@
|
||||
|
||||
ifeq ($(BUILD_MODULE), y)
|
||||
|
||||
ifeq ($(WINTOOL), y)
|
||||
PROGPRFX = ${cygpath -u $(INSTALL_DIR)$(DELIM)}
|
||||
else
|
||||
PROGPRFX = $(INSTALL_DIR)$(DELIM)
|
||||
endif
|
||||
|
||||
PROGLIST := $(addprefix $(PROGPRFX),$(PROGNAME))
|
||||
PROGOBJ := $(MAINOBJ)
|
||||
|
||||
$(PROGLIST): $(MAINOBJ) $(OBJS)
|
||||
ifneq ($(PROGOBJ),)
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) $(ARCHCRT0OBJ) $(firstword $(PROGOBJ)) $(LDLIBS) -o $(strip $(firstword $(PROGLIST)))_
|
||||
$(Q) $(NM) -u $(strip $(firstword $(PROGLIST)))_
|
||||
$(Q) install -m 0755 -D $(strip $(firstword $(PROGLIST)))_ $(firstword $(PROGLIST))
|
||||
$(call DELFILE, $(strip $(firstword $(PROGLIST)))_)
|
||||
# $(Q) $(STRIP) $(firstword $(PROGLIST))
|
||||
$(eval PROGLIST=$(filter-out $(firstword $(PROGLIST)),$(PROGLIST)))
|
||||
$(eval PROGOBJ=$(filter-out $(firstword $(PROGOBJ)),$(PROGOBJ)))
|
||||
endif
|
||||
|
||||
install:: $(PROGLIST)
|
||||
|
||||
else
|
||||
install::
|
||||
|
||||
endif # BUILD_MODULE
|
||||
|
||||
preconfig::
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
ifneq ($(BUILD_MODULE),y)
|
||||
REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(APPNAME)_main.bdat)
|
||||
APPLIST := $(APPNAME)
|
||||
|
||||
ifneq ($(APPNAME),)
|
||||
ifneq ($(PRIORITY),)
|
||||
ifneq ($(STACKSIZE),)
|
||||
$(REGLIST): $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(firstword $(APPLIST)),$(firstword $(PRIORITY)),$(firstword $(STACKSIZE)),$(if $(BUILD_MODULE),,$(firstword $(APPLIST))_main))
|
||||
$(eval APPLIST=$(filter-out $(firstword $(APPLIST)),$(APPLIST)))
|
||||
$(if $(filter-out $(firstword $(PRIORITY)),$(PRIORITY)),$(eval PRIORITY=$(filter-out $(firstword $(PRIORITY)),$(PRIORITY))))
|
||||
$(if $(filter-out $(firstword $(STACKSIZE)),$(STACKSIZE)),$(eval STACKSIZE=$(filter-out $(firstword $(STACKSIZE)),$(STACKSIZE))))
|
||||
|
||||
context:: $(REGLIST)
|
||||
else
|
||||
context::
|
||||
endif
|
||||
else
|
||||
context::
|
||||
endif
|
||||
else
|
||||
context::
|
||||
endif
|
||||
else
|
||||
context::
|
||||
endif
|
||||
else
|
||||
context::
|
||||
endif
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
ifeq ($(filter %$(CXXEXT),$(SRCS)),)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(filter-out Makefile,$^) >Make.dep
|
||||
else
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CXX)" -- $(CXXFLAGS) -- $(filter-out Makefile,$^) >Make.dep
|
||||
endif
|
||||
$(Q) touch $@
|
||||
|
||||
depend:: .depend
|
||||
|
||||
clean::
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean:: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
188
COPYING
Normal file
188
COPYING
Normal file
@ -0,0 +1,188 @@
|
||||
COPYING -- Describes the terms under which Nuttx is distributed. A
|
||||
copy of the BSD-style licensing is included in this file. In my
|
||||
words -- I believe that you should free to use NuttX in any
|
||||
environment, private, private, commercial, open, closed, etc.
|
||||
provided only that you repect the modest copyright notices as
|
||||
described in license (below). Please feel free to contact me if you
|
||||
have any licensing concerns.
|
||||
|
||||
NuttX
|
||||
^^^^^^
|
||||
|
||||
License for NuttX in general (authorship of individual files may vary):
|
||||
|
||||
Copyright (C) 2007-2012 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.
|
||||
|
||||
uIP
|
||||
^^^
|
||||
|
||||
Some lower-level networking middle-ware components of NuttX
|
||||
derive from uIP which has a similar BSD style license:
|
||||
|
||||
Copyright (c) 2001-2003, Adam Dunkels.
|
||||
All rights reserved.
|
||||
|
||||
FreeModbus
|
||||
^^^^^^^^^
|
||||
|
||||
FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
|
||||
Copyright (c) 2006 Christian Walter <wolti@sil.at>
|
||||
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. 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.
|
||||
|
||||
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
|
||||
^^^^^^
|
||||
|
||||
Derived from the original THTTPD package:
|
||||
|
||||
Copyright © 1995,1998,1999,2000,2001 by Jef Poskanzer <jef@mail.acme.com>.
|
||||
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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
|
||||
cJSON
|
||||
^^^^^
|
||||
|
||||
Derives from the cJSON Project which has an MIT license:
|
||||
|
||||
Copyright (c) 2009 Dave Gamble
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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.
|
3072
ChangeLog.txt
Normal file
3072
ChangeLog.txt
Normal file
File diff suppressed because it is too large
Load Diff
76
Directory.mk
Normal file
76
Directory.mk
Normal file
@ -0,0 +1,76 @@
|
||||
############################################################################
|
||||
# apps/Directory.mk
|
||||
#
|
||||
# Copyright (C) 2011-2015, 2018 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
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# Sub-directories
|
||||
|
||||
SUBDIRS = $(dir $(wildcard */Makefile))
|
||||
|
||||
all: nothing
|
||||
|
||||
.PHONY: nothing context depend clean distclean
|
||||
|
||||
define SDIR_template
|
||||
$(1)_$(2):
|
||||
$(Q) cd $(1) && $(MAKE) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
endef
|
||||
|
||||
$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),preconfig)))
|
||||
$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),context)))
|
||||
$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),depend)))
|
||||
$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),clean)))
|
||||
$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),distclean)))
|
||||
|
||||
nothing:
|
||||
|
||||
install:
|
||||
|
||||
preconfig: $(foreach SDIR, $(SUBDIRS), $(SDIR)_preconfig)
|
||||
$(Q) $(MKKCONFIG) -m $(MENUDESC)
|
||||
|
||||
context: $(foreach SDIR, $(SUBDIRS), $(SDIR)_context)
|
||||
|
||||
depend: $(foreach SDIR, $(SUBDIRS), $(SDIR)_depend)
|
||||
|
||||
clean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_clean)
|
||||
|
||||
distclean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_distclean)
|
||||
ifneq ($(MENUDESC),)
|
||||
$(call DELFILE, Kconfig)
|
||||
endif
|
||||
|
||||
-include Make.dep
|
128
Make.defs
Normal file
128
Make.defs
Normal file
@ -0,0 +1,128 @@
|
||||
############################################################################
|
||||
# apps/Make.defs
|
||||
# Common make definitions provided to all applications
|
||||
#
|
||||
# Copyright (C) 2011, 2014, 2016, 2018 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Builtin Registration
|
||||
|
||||
BUILTIN_REGISTRY = $(APPDIR)$(DELIM)builtin$(DELIM)registry
|
||||
|
||||
DEPCONFIG = $(TOPDIR)$(DELIM).config
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
define REGISTER
|
||||
$(Q) echo Register: $1
|
||||
$(Q) echo { "$1", $2, $3, $4 }, > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat"
|
||||
$(Q) if [ ! -z $4 ]; then \
|
||||
echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat"; \
|
||||
fi;
|
||||
$(Q) touch $(BUILTIN_REGISTRY)$(DELIM).updated"
|
||||
endef
|
||||
else
|
||||
define REGISTER
|
||||
$(Q) echo "Register: $1 $4"
|
||||
$(Q) echo "{ \"$1\", $2, $3, $4 }," > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat"
|
||||
$(Q) if [ ! -z $4 ]; then \
|
||||
echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat"; \
|
||||
fi;
|
||||
$(Q) touch "$(BUILTIN_REGISTRY)$(DELIM).updated"
|
||||
endef
|
||||
endif
|
||||
|
||||
# Tools
|
||||
#
|
||||
# In a normal build, tools will reside in the nuttx/tools sub-directory and
|
||||
# TOPDIR will refer to that nuttx/ directory. This, however, is not the
|
||||
# case when building apps/ with a NuttX export directory; there is no
|
||||
# apps/import/tools directory. In that case copies of the NuttX tools in
|
||||
# the apps/tools directory are used.
|
||||
|
||||
DELIM ?= $(strip /)
|
||||
ifneq (,$(wildcard $(TOPDIR)$(DELIM)tools))
|
||||
TOOLDIR = $(TOPDIR)$(DELIM)tools
|
||||
else
|
||||
TOOLDIR = $(APPDIR)$(DELIM)tools
|
||||
endif
|
||||
|
||||
ifeq ($(DIRLINK),)
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
DIRLINK = $(TOOLDIR)$(DELIM)link.bat
|
||||
DIRUNLINK = $(TOOLDIR)$(DELIM)unlink.bat
|
||||
else ifeq ($(CONFIG_WINDOWS_MSYS),y)
|
||||
DIRLINK = $(TOOLDIR)$(DELIM)copydir.sh
|
||||
DIRUNLINK = $(TOOLDIR)$(DELIM)unlink.sh
|
||||
else
|
||||
DIRUNLINK = $(TOOLDIR)$(DELIM)unlink.sh
|
||||
ifeq ($(WINTOOL),y)
|
||||
DIRLINK = $(TOOLDIR)$(DELIM)copydir.sh
|
||||
else
|
||||
DIRLINK = $(TOOLDIR)$(DELIM)link.sh
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
MKKCONFIG = $(APPDIR)$(DELIM)tools$(DELIM)mkkconfig.bat
|
||||
else
|
||||
MKKCONFIG = $(APPDIR)$(DELIM)tools$(DELIM)mkkconfig.sh
|
||||
endif
|
||||
|
||||
ifeq ($(INCDIR),)
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
INCDIR = $(TOOLDIR)$(DELIM)incdir.bat
|
||||
else
|
||||
INCDIR = $(TOOLDIR)$(DELIM)incdir.sh
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(DEFINE),)
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
DEFINE = $(APPDIR)$(DELIM)tools$(DELIM)define.bat
|
||||
else
|
||||
DEFINE = $(APPDIR)$(DELIM)tools$(DELIM)define.sh
|
||||
endif
|
||||
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"}
|
||||
|
||||
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
||||
LDLIBS = $(APPDIR)/libapps.a
|
||||
endif
|
226
Makefile
Normal file
226
Makefile
Normal file
@ -0,0 +1,226 @@
|
||||
############################################################################
|
||||
# apps/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
# Copyright (C) 2011-2014, 2018 Gregory Nutt. All rights reserved.
|
||||
# Authors: Uros Platise <uros.platise@isotel.eu>
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
APPDIR = ${shell pwd}
|
||||
TOPDIR ?= $(APPDIR)/import
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
-include $(APPDIR)/Make.defs
|
||||
|
||||
# Application Directories
|
||||
|
||||
# BUILDIRS is the list of top-level directories containing Make.defs files
|
||||
# CLEANDIRS is the list of all top-level directories containing Makefiles.
|
||||
# It is used only for cleaning.
|
||||
|
||||
BUILDIRS := $(dir $(filter-out import/Make.defs,$(wildcard */Make.defs)))
|
||||
CLEANDIRS := $(dir $(wildcard */Makefile))
|
||||
|
||||
# CONFIGURED_APPS is the application directories that should be built in
|
||||
# the current configuration.
|
||||
|
||||
CONFIGURED_APPS =
|
||||
|
||||
define Add_Application
|
||||
include $(1)Make.defs
|
||||
endef
|
||||
|
||||
$(foreach BDIR, $(BUILDIRS), $(eval $(call Add_Application,$(BDIR))))
|
||||
|
||||
# Library path
|
||||
|
||||
LIBPATH ?= $(TOPDIR)$(DELIM)staging
|
||||
|
||||
# The install path
|
||||
|
||||
EXE_DIR = $(APPDIR)$(DELIM)exe
|
||||
BIN_DIR = $(EXE_DIR)$(DELIM)system$(DELIM)bin
|
||||
|
||||
# The final build target
|
||||
|
||||
BIN = libapps$(LIBEXT)
|
||||
|
||||
# Symbol table for loadable apps.
|
||||
|
||||
SYMTABSRC = $(EXE_DIR)$(DELIM)symtab_apps.c
|
||||
SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT))
|
||||
|
||||
# Build targets
|
||||
|
||||
all: $(BIN)
|
||||
.PHONY: import install dirlinks context context_serialize clean_context context_rest .depdirs preconfig depend clean distclean
|
||||
.PRECIOUS: libapps$(LIBEXT)
|
||||
|
||||
define MAKE_template
|
||||
$(Q) cd $(1) && $(MAKE) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" BIN_DIR="$(BIN_DIR)"
|
||||
|
||||
endef
|
||||
|
||||
define SDIR_template
|
||||
$(1)_$(2):
|
||||
$(Q) cd $(1) && $(MAKE) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" BIN_DIR="$(BIN_DIR)"
|
||||
|
||||
endef
|
||||
|
||||
$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),all)))
|
||||
$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),install)))
|
||||
$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),context)))
|
||||
$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),depend)))
|
||||
$(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),clean)))
|
||||
$(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),distclean)))
|
||||
|
||||
# In the KERNEL build, we must build and install all of the modules. No
|
||||
# symbol table is needed
|
||||
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
|
||||
.install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install)
|
||||
|
||||
install: $(BIN_DIR) .install
|
||||
|
||||
$(BIN_DIR):
|
||||
$(Q) mkdir -p $(BIN_DIR)
|
||||
|
||||
.import: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
|
||||
$(Q) $(MAKE) install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
|
||||
import: $(BIN_DIR)
|
||||
$(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
|
||||
else
|
||||
|
||||
# In FLAT and protected modes, the modules have already been created. A
|
||||
# symbol table is required.
|
||||
|
||||
ifeq ($(CONFIG_BUILD_LOADABLE),)
|
||||
|
||||
$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
|
||||
|
||||
else
|
||||
|
||||
$(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
|
||||
$(Q) $(MAKE) install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(EXE_DIR)$(DELIM)system $(SYMTABSRC)
|
||||
|
||||
$(SYMTABOBJ): %$(OBJEXT): %.c
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(call COMPILE, -fno-lto "${shell cygpath -w $<}", "${shell cygpath -w $@}")
|
||||
else
|
||||
$(call COMPILE, -fno-lto $<, $@)
|
||||
endif
|
||||
|
||||
$(BIN): $(SYMTABOBJ)
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(call ARCHIVE, $(BIN), "${shell cygpath -w $^}")
|
||||
else
|
||||
$(call ARCHIVE, $(BIN), $^)
|
||||
endif
|
||||
endif # !CONFIG_BUILD_KERNEL && CONFIG_BUILD_LOADABLE
|
||||
|
||||
.install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install)
|
||||
|
||||
$(BIN_DIR):
|
||||
$(Q) mkdir -p $(BIN_DIR)
|
||||
|
||||
install: $(BIN_DIR) .install
|
||||
|
||||
.import: $(BIN) install
|
||||
|
||||
import:
|
||||
$(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
|
||||
endif # CONFIG_BUILD_KERNEL
|
||||
|
||||
dirlinks:
|
||||
$(Q) $(MAKE) -C platform dirlinks TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" BIN_DIR="$(BIN_DIR)"
|
||||
|
||||
context_rest: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_context)
|
||||
|
||||
context_serialize:
|
||||
$(Q) $(MAKE) -C builtin context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
$(Q) $(MAKE) context_rest
|
||||
|
||||
context: context_serialize
|
||||
|
||||
Kconfig:
|
||||
$(foreach SDIR, $(BUILDIRS), $(call MAKE_template,$(SDIR),preconfig))
|
||||
$(Q) $(MKKCONFIG)
|
||||
|
||||
preconfig: Kconfig
|
||||
|
||||
.depdirs: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_depend)
|
||||
|
||||
.depend: context Makefile .depdirs
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean_context:
|
||||
$(Q) $(MAKE) -C platform clean_context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" BIN_DIR="$(BIN_DIR)"
|
||||
|
||||
clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean)
|
||||
$(call DELFILE, $(SYMTABSRC))
|
||||
$(call DELFILE, $(SYMTABOBJ))
|
||||
$(call DELFILE, $(BIN))
|
||||
$(call DELFILE, Kconfig)
|
||||
$(call DELDIR, $(BIN_DIR))
|
||||
$(call DELDIR, $(EXE_DIR))
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_distclean)
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
$(Q) ( if exist external ( \
|
||||
echo ********************************************************" \
|
||||
echo * The external directory/link must be removed manually *" \
|
||||
echo ********************************************************" \
|
||||
)
|
||||
else
|
||||
$(Q) ( if [ -e external ]; then \
|
||||
echo "********************************************************"; \
|
||||
echo "* The external directory/link must be removed manually *"; \
|
||||
echo "********************************************************"; \
|
||||
fi; \
|
||||
)
|
||||
endif
|
||||
$(call DELFILE, .depend)
|
||||
$(call DELFILE, $(SYMTABSRC))
|
||||
$(call DELFILE, $(SYMTABOBJ))
|
||||
$(call DELFILE, $(BIN))
|
||||
$(call DELFILE, Kconfig)
|
||||
$(call DELDIR, $(BIN_DIR))
|
||||
$(call DELDIR, $(EXE_DIR))
|
||||
$(call CLEAN)
|
223
README.txt
Normal file
223
README.txt
Normal file
@ -0,0 +1,223 @@
|
||||
Application Folder
|
||||
==================
|
||||
|
||||
Contents
|
||||
--------
|
||||
|
||||
General
|
||||
Directory Location
|
||||
Built-In Applications
|
||||
NuttShell (NSH) Built-In Commands
|
||||
Synchronous Built-In Commands
|
||||
Application Configuration File
|
||||
Example Built-In Application
|
||||
Building NuttX with Board-Specific Pieces Outside the Source Tree
|
||||
|
||||
General
|
||||
-------
|
||||
This folder provides various applications found in sub-directories. These
|
||||
applications are not inherently a part of NuttX but are provided to help
|
||||
you develop your own applications. The apps/ directory is a "break away"
|
||||
part of the configuration that you may choose to use or not.
|
||||
|
||||
Directory Location
|
||||
------------------
|
||||
The default application directory used by the NuttX build should be named
|
||||
apps/ (or apps-x.y/ where x.y is the NuttX version number). This apps/
|
||||
directory should appear in the directory tree at the same level as the
|
||||
NuttX directory. Like:
|
||||
|
||||
.
|
||||
|- nuttx
|
||||
|
|
||||
`- apps
|
||||
|
||||
If all of the above conditions are TRUE, then NuttX will be able to
|
||||
find the application directory. If your application directory has a
|
||||
different name or is location at a different position, then you will
|
||||
have to inform the NuttX build system of that location. There are several
|
||||
ways to do that:
|
||||
|
||||
1) You can define CONFIG_APPS_DIR to be the full path to your application
|
||||
directory in the NuttX configuration file.
|
||||
2) You can provide the path to the application directory on the command line
|
||||
like: make APPDIR=<path> or make CONFIG_APPS_DIR=<path>
|
||||
3) When you configure NuttX using tools/configure.sh, you can provide that
|
||||
path to the application directory on the configuration command line
|
||||
like: ./configure.sh -a <app-dir> <board-name>/<config-name>
|
||||
|
||||
Built-In Applications
|
||||
---------------------
|
||||
NuttX also supports applications that can be started using a name string.
|
||||
In this case, application entry points with their requirements are gathered
|
||||
together in two files:
|
||||
|
||||
- builtin/builtin_proto.h Entry points, prototype function
|
||||
- builtin/builtin_list.h Application specific information and requirements
|
||||
|
||||
The build occurs in several phases as different build targets are executed:
|
||||
(1) context, (2) depend, and (3) default (all). Application information is
|
||||
collected during the make context build phase.
|
||||
|
||||
To execute an application function:
|
||||
|
||||
exec_builtin() is defined in the nuttx/include/apps/builtin/builtin.h
|
||||
|
||||
NuttShell (NSH) Built-In Commands
|
||||
---------------------------------
|
||||
One use of builtin applications is to provide a way of invoking your custom
|
||||
application through the NuttShell (NSH) command line. NSH will support
|
||||
a seamless method invoking the applications, when the following option is
|
||||
enabled in the NuttX configuration file:
|
||||
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
|
||||
Applications registered in the apps/builtin/builtin_list.h file will then
|
||||
be accessible from the NSH command line. If you type 'help' at the NSH
|
||||
prompt, you will see a list of the registered commands.
|
||||
|
||||
Synchronous Built-In Commands
|
||||
-----------------------------
|
||||
By default, built-in commands started from the NSH command line will run
|
||||
asynchronously with NSH. If you want to force NSH to execute commands
|
||||
then wait for the command to execute, you can enable that feature by
|
||||
adding the following to the NuttX configuration file:
|
||||
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
|
||||
The configuration option enables support for the waitpid() RTOS interface.
|
||||
When that interface is enabled, NSH will use it to wait, sleeping until
|
||||
the built-in command executes to completion.
|
||||
|
||||
Of course, even with CONFIG_SCHED_WAITPID=y defined, specific commands
|
||||
can still be forced to run asynchronously by adding the ampersand (&)
|
||||
after the NSH command.
|
||||
|
||||
Application Configuration File
|
||||
------------------------------
|
||||
The NuttX configuration uses kconfig-frontends tools and the NuttX
|
||||
configuration file (.config) file. For example, the NuttX .config
|
||||
may have:
|
||||
|
||||
CONFIG_EXAMPLES_HELLO=y
|
||||
|
||||
This will select the apps/examples/hello in the following way:
|
||||
|
||||
- The top-level make will include examples/Make.defs
|
||||
- examples/Make.defs will set CONFIGURED_APPS += examples/hello
|
||||
like this:
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_HELLO),y)
|
||||
CONFIGURED_APPS += examples/hello
|
||||
endif
|
||||
|
||||
Example Built-In Application
|
||||
----------------------------
|
||||
An example application skeleton can be found under the examples/hello
|
||||
sub-directory. This example shows how a builtin application can be added
|
||||
to the project. One must:
|
||||
|
||||
1. Create sub-directory as: appname
|
||||
|
||||
2. In this directory there should be:
|
||||
|
||||
- A Make.defs file that would be included by the apps/Makefile
|
||||
- A Kconfig file that would be used by the configuration tool (see the
|
||||
file kconfig-language.txt in the NuttX tools repository). This
|
||||
Kconfig file should be included by the apps/Kconfig file
|
||||
- A Makefile, and
|
||||
- The application source code.
|
||||
|
||||
3. The application source code should provide the entry point:
|
||||
appname_main()
|
||||
|
||||
4. Set the requirements in the file: Makefile, specially the lines:
|
||||
|
||||
APPNAME = appname
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 768
|
||||
ASRCS = asm source file list as a.asm b.asm ...
|
||||
CSRCS = C source file list as foo1.c foo2.c ..
|
||||
|
||||
4b. The Make.defs file should include a line like:
|
||||
|
||||
ifeq ($(CONFIG_APPNAME),y)
|
||||
CONFIGURED_APPS += appname
|
||||
endif
|
||||
|
||||
Building NuttX with Board-Specific Pieces Outside the Source Tree
|
||||
-----------------------------------------------------------------
|
||||
|
||||
Q: Has anyone come up with a tidy way to build NuttX with board-
|
||||
specific pieces outside the source tree?
|
||||
A: Here are three:
|
||||
|
||||
1) There is a make target called 'make export'. It will build
|
||||
NuttX, then bundle all of the header files, libaries, startup
|
||||
objects, and other build components into a .zip file. You
|
||||
can can move that .zip file into any build environment you
|
||||
want. You even build NuttX under a DOS CMD window.
|
||||
|
||||
This make target is documented in the top level nuttx/README.txt.
|
||||
|
||||
2) You can replace the entire apps/ directory. If there is
|
||||
nothing in the apps/ directory that you need, you can define
|
||||
CONFIG_APPS_DIR in your .config file so that it points to a
|
||||
different, custom application directory.
|
||||
|
||||
You can copy any pieces that you like from the old apps/directory
|
||||
to your custom apps directory as necessary.
|
||||
|
||||
This is documented in NuttX/configs/README.txt and
|
||||
nuttx/Documentation/NuttxPortingGuide.html (Online at
|
||||
https://bitbucket.org/nuttx/documentation/src/master/NuttxPortingGuide.html#apndxconfigs
|
||||
under Build options). And in the apps/README.txt file.
|
||||
|
||||
3) If you like the random collection of stuff in the apps/ directory
|
||||
but just want to expand the existing components with your own,
|
||||
external sub-directory then there is an easy way to that too:
|
||||
You just create a sympolic link in the apps/ directory that
|
||||
redirects to your application sub-directory.
|
||||
|
||||
In order to be incorporated into the build, the directory that
|
||||
you link under the apps/ directory should contain (1) a Makefile
|
||||
that supports the clean and distclean targets (see other Makefiles
|
||||
for examples), and (2) a tiny Make.defs file that simply adds the
|
||||
custon build directories to the variable CONFIGURED_APPS like:
|
||||
|
||||
CONFIGURED_APPS += my_directory1 my_directory2
|
||||
|
||||
The apps/Makefile will always automatically check for the
|
||||
existence of subdirectories containing a Makefile and a Make.defs
|
||||
file. The Makefile will be used only to support cleaning operations.
|
||||
The Make.defs file provides the set of directories to be built; these
|
||||
directories must also contain a Makefile. That Makefile must be able
|
||||
to build the sources and add the objects to the apps/libapps.a archive.
|
||||
(see other Makefiles for examples). It should support the all,
|
||||
install, context, and depend targets.
|
||||
|
||||
apps/Makefile does not depend on any hardcoded lists of directories.
|
||||
Instead, it does a wildcard search to find all appropriate
|
||||
directories. This means that to install a new application, you
|
||||
simply have to copy the directory (or link it) into the apps/
|
||||
directory. If the new directory includes a Makefile and Make.defs
|
||||
file, then it will automatically be included in the build.
|
||||
|
||||
If the directory that you add also includes a Kconfig file, then it
|
||||
will automatically be included in the NuttX configuration system as
|
||||
well. apps/Makefile uses a tool at apps/tools/mkkconfig.sh that
|
||||
dynamically builds the apps/Kconfig file at pre-configuration time.
|
||||
|
||||
You could, for example, create a script called install.sh that
|
||||
installs a custom application, configuration, and board specific
|
||||
directory:
|
||||
|
||||
a) Copy 'MyBoard' directory to configs/MyBoard.
|
||||
b) Add a symbolic link to MyApplication at apps/external
|
||||
c) Configure NuttX (usually by:
|
||||
|
||||
tools/configure.sh MyBoard/MyConfiguration
|
||||
|
||||
Use of the name ''apps/external'' is suggested because that name
|
||||
is included in the .gitignore file and will save you some nuisance
|
||||
when working with GIT.
|
11
builtin/.gitignore
vendored
Normal file
11
builtin/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/.context
|
||||
/.depend
|
||||
/.built
|
||||
/Make.dep
|
||||
/builtin_list.h
|
||||
/builtin_proto.h
|
||||
/*.src
|
||||
/*.obj
|
||||
/*.lst
|
||||
/*.asm
|
||||
/*.sym
|
18
builtin/Kconfig
Normal file
18
builtin/Kconfig
Normal file
@ -0,0 +1,18 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
menu "Built-In Applications"
|
||||
depends on BUILTIN
|
||||
|
||||
config BUILTIN_PROXY_STACKSIZE
|
||||
int "Builtin Proxy Stack Size"
|
||||
default 1024
|
||||
---help---
|
||||
If exec_builtin uses I/O redirection options, then it will require
|
||||
an intermediary/proxy task to muck with the file descriptors. This
|
||||
configuration item specifies the stack size used for the proxy. Default:
|
||||
1024 bytes.
|
||||
|
||||
endmenu # Built-In Applications
|
40
builtin/Make.defs
Normal file
40
builtin/Make.defs
Normal file
@ -0,0 +1,40 @@
|
||||
############################################################################
|
||||
# apps/builtin/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2012 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_BUILTIN),y)
|
||||
CONFIGURED_APPS += builtin
|
||||
endif
|
||||
|
83
builtin/Makefile
Normal file
83
builtin/Makefile
Normal file
@ -0,0 +1,83 @@
|
||||
############################################################################
|
||||
# apps/builtin/Makefile
|
||||
#
|
||||
# Copyright (C) 2011-2012, 2018 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
|
||||
|
||||
# Source and object files
|
||||
|
||||
CSRCS = builtin_forindex.c builtin_list.c exec_builtin.c
|
||||
|
||||
# Registry entry lists
|
||||
|
||||
PDATLIST = $(strip $(call RWILDCARD, registry, *.pdat))
|
||||
BDATLIST = $(strip $(call RWILDCARD, registry, *.bdat))
|
||||
|
||||
registry$(DELIM).updated:
|
||||
$(Q) $(MAKE) -C registry .updated TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
|
||||
builtin_list$(OBJEXT): builtin_list.h builtin_proto.h
|
||||
|
||||
builtin_list.h: registry$(DELIM).updated
|
||||
$(call DELFILE, .xx_builtin_list.h)
|
||||
$(Q) touch .xx_builtin_list.h
|
||||
ifneq ($(BDATLIST),)
|
||||
$(call CATFILE, .xx_builtin_list.h, $(BDATLIST))
|
||||
endif
|
||||
$(Q) mv .xx_builtin_list.h builtin_list.h
|
||||
|
||||
builtin_proto.h: registry$(DELIM).updated
|
||||
$(call DELFILE, .xx_builtin_proto.h)
|
||||
$(Q) touch .xx_builtin_proto.h
|
||||
ifneq ($(PDATLIST),)
|
||||
$(call CATFILE, .xx_builtin_proto.h, $(PDATLIST))
|
||||
endif
|
||||
$(Q) mv .xx_builtin_proto.h builtin_proto.h
|
||||
|
||||
context::
|
||||
$(Q) $(MAKE) -C registry context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
|
||||
depend:: builtin_list.h builtin_proto.h
|
||||
|
||||
clean::
|
||||
$(Q) $(MAKE) -C registry clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
$(call DELFILE, .xx_builtin_list.h)
|
||||
$(call DELFILE, .xx_builtin_proto.h)
|
||||
|
||||
distclean::
|
||||
$(Q) $(MAKE) -C registry distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
$(call DELFILE, builtin_list.h)
|
||||
$(call DELFILE, builtin_proto.h)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
65
builtin/builtin_forindex.c
Normal file
65
builtin/builtin_forindex.c
Normal file
@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
* apps/builtin/builtin_forindex.c
|
||||
*
|
||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
* Copyright (C) 2011, 2016 Gregory Nutt. All rights reserved.
|
||||
* Authors: Uros Platise <uros.platise@isotel.eu>
|
||||
* 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 <nuttx/binfmt/builtin.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
extern const struct builtin_s g_builtins[];
|
||||
extern const int g_builtin_count;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct builtin_s *builtin_for_index(int index)
|
||||
{
|
||||
if (index < g_builtin_count)
|
||||
{
|
||||
return &g_builtins[index];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
79
builtin/builtin_list.c
Normal file
79
builtin/builtin_list.c
Normal file
@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
* apps/builtin/builtin_list.c
|
||||
*
|
||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Authors: Uros Platise <uros.platise@isotel.eu>
|
||||
* 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 <nuttx/binfmt/builtin.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#include "builtin_proto.h"
|
||||
|
||||
const struct builtin_s g_builtins[] =
|
||||
{
|
||||
# include "builtin_list.h"
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
|
||||
const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
233
builtin/exec_builtin.c
Normal file
233
builtin/exec_builtin.c
Normal file
@ -0,0 +1,233 @@
|
||||
/****************************************************************************
|
||||
* apps/builtin/exec_builtin.c
|
||||
*
|
||||
* Originally by:
|
||||
*
|
||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
* Author: Uros Platise <uros.platise@isotel.eu>
|
||||
*
|
||||
* With subsequent updates, modifications, and general maintenance by:
|
||||
*
|
||||
* Copyright (C) 2012-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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <spawn.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "builtin/builtin.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec_builtin
|
||||
*
|
||||
* Description:
|
||||
* Executes builtin applications registered during 'make context' time.
|
||||
* New application is run in a separate task context (and thread).
|
||||
*
|
||||
* Input Parameter:
|
||||
* filename - Name of the linked-in binary to be started.
|
||||
* argv - Argument list
|
||||
* redirfile - If output if redirected, this parameter will be non-NULL
|
||||
* and will provide the full path to the file.
|
||||
* oflags - If output is redirected, this parameter will provide the
|
||||
* open flags to use. This will support file replacement
|
||||
* of appending to an existing file.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is an end-user function, so it follows the normal convention:
|
||||
* Returns the PID of the exec'ed module. On failure, it.returns
|
||||
* -1 (ERROR) and sets errno appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int exec_builtin(FAR const char *appname, FAR char * const *argv,
|
||||
FAR const char *redirfile, int oflags)
|
||||
{
|
||||
FAR const struct builtin_s *builtin;
|
||||
posix_spawnattr_t attr;
|
||||
posix_spawn_file_actions_t file_actions;
|
||||
struct sched_param param;
|
||||
pid_t pid;
|
||||
int index;
|
||||
int ret;
|
||||
|
||||
/* Verify that an application with this name exists */
|
||||
|
||||
index = builtin_isavail(appname);
|
||||
if (index < 0)
|
||||
{
|
||||
ret = ENOENT;
|
||||
goto errout_with_errno;
|
||||
}
|
||||
|
||||
/* Get information about the builtin */
|
||||
|
||||
builtin = builtin_for_index(index);
|
||||
if (builtin == NULL)
|
||||
{
|
||||
ret = ENOENT;
|
||||
goto errout_with_errno;
|
||||
}
|
||||
|
||||
/* Initialize attributes for task_spawn(). */
|
||||
|
||||
ret = posix_spawnattr_init(&attr);
|
||||
if (ret != 0)
|
||||
{
|
||||
goto errout_with_errno;
|
||||
}
|
||||
|
||||
ret = posix_spawn_file_actions_init(&file_actions);
|
||||
if (ret != 0)
|
||||
{
|
||||
goto errout_with_attrs;
|
||||
}
|
||||
|
||||
/* Set the correct task size and priority */
|
||||
|
||||
param.sched_priority = builtin->priority;
|
||||
ret = posix_spawnattr_setschedparam(&attr, ¶m);
|
||||
if (ret != 0)
|
||||
{
|
||||
goto errout_with_actions;
|
||||
}
|
||||
|
||||
ret = task_spawnattr_setstacksize(&attr, builtin->stacksize);
|
||||
if (ret != 0)
|
||||
{
|
||||
goto errout_with_actions;
|
||||
}
|
||||
|
||||
/* If robin robin scheduling is enabled, then set the scheduling policy
|
||||
* of the new task to SCHED_RR before it has a chance to run.
|
||||
*/
|
||||
|
||||
#if CONFIG_RR_INTERVAL > 0
|
||||
ret = posix_spawnattr_setschedpolicy(&attr, SCHED_RR);
|
||||
if (ret != 0)
|
||||
{
|
||||
goto errout_with_actions;
|
||||
}
|
||||
|
||||
ret = posix_spawnattr_setflags(&attr,
|
||||
POSIX_SPAWN_SETSCHEDPARAM |
|
||||
POSIX_SPAWN_SETSCHEDULER);
|
||||
if (ret != 0)
|
||||
{
|
||||
goto errout_with_actions;
|
||||
}
|
||||
|
||||
#else
|
||||
ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM);
|
||||
if (ret != 0)
|
||||
{
|
||||
goto errout_with_actions;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Is output being redirected? */
|
||||
|
||||
if (redirfile)
|
||||
{
|
||||
/* Set up to close open redirfile and set to stdout (1) */
|
||||
|
||||
ret = posix_spawn_file_actions_addopen(&file_actions, 1,
|
||||
redirfile, oflags, 0644);
|
||||
if (ret != 0)
|
||||
{
|
||||
serr("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret);
|
||||
goto errout_with_actions;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LIBC_EXECFUNCS
|
||||
/* A NULL entry point implies that the task is a loadable application */
|
||||
|
||||
if (builtin->main == NULL)
|
||||
{
|
||||
/* Load and execute the application. */
|
||||
|
||||
ret = posix_spawn(&pid, builtin->name, &file_actions,
|
||||
&attr, (argv) ? &argv[1] : (FAR char * const *)NULL,
|
||||
NULL);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Start the built-in */
|
||||
|
||||
ret = task_spawn(&pid, builtin->name, builtin->main, &file_actions,
|
||||
&attr, (argv) ? &argv[1] : (FAR char * const *)NULL,
|
||||
(FAR char * const *)NULL);
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
serr("ERROR: task_spawn failed: %d\n", ret);
|
||||
goto errout_with_actions;
|
||||
}
|
||||
|
||||
/* Free attributes and file actions. Ignoring return values in the case
|
||||
* of an error.
|
||||
*/
|
||||
|
||||
/* Return the task ID of the new task if the task was successfully
|
||||
* started. Otherwise, ret will be ERROR (and the errno value will
|
||||
* be set appropriately).
|
||||
*/
|
||||
|
||||
(void)posix_spawn_file_actions_destroy(&file_actions);
|
||||
(void)posix_spawnattr_destroy(&attr);
|
||||
return pid;
|
||||
|
||||
errout_with_actions:
|
||||
(void)posix_spawn_file_actions_destroy(&file_actions);
|
||||
|
||||
errout_with_attrs:
|
||||
(void)posix_spawnattr_destroy(&attr);
|
||||
|
||||
errout_with_errno:
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
5
builtin/registry/.gitignore
vendored
Normal file
5
builtin/registry/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.updated
|
||||
*.pdat
|
||||
*.bdat
|
||||
|
||||
|
64
builtin/registry/Makefile
Normal file
64
builtin/registry/Makefile
Normal file
@ -0,0 +1,64 @@
|
||||
############################################################################
|
||||
# apps/builtin/registry/Makefile
|
||||
#
|
||||
# Copyright (C) 2012 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
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# NSH Library
|
||||
|
||||
all:
|
||||
.PHONY: context depend clean distclean
|
||||
.PRECIOUS: ../../libapps$(LIBEXT)
|
||||
|
||||
.updated: $(DEPCONFIG)
|
||||
$(call DELFILE, *.bdat)
|
||||
$(call DELFILE, *.pdat)
|
||||
$(Q) touch .updated
|
||||
|
||||
# This must run before any other context target
|
||||
|
||||
install:
|
||||
|
||||
context: .updated
|
||||
|
||||
depend:
|
||||
|
||||
clean:
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, *.bdat)
|
||||
$(call DELFILE, *.pdat)
|
||||
$(call DELFILE, .updated)
|
2
canutils/.gitignore
vendored
Normal file
2
canutils/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/Kconfig
|
||||
|
37
canutils/Make.defs
Normal file
37
canutils/Make.defs
Normal file
@ -0,0 +1,37 @@
|
||||
############################################################################
|
||||
# apps/canutils/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(wildcard canutils/*/Make.defs)
|
38
canutils/Makefile
Normal file
38
canutils/Makefile
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# apps/canutils/Makefile
|
||||
#
|
||||
# Copyright (C) 2011-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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
MENUDESC = "CAN Utilities"
|
||||
|
||||
include $(APPDIR)/Directory.mk
|
15
canutils/canlib/Kconfig
Normal file
15
canutils/canlib/Kconfig
Normal file
@ -0,0 +1,15 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config CANUTILS_CANLIB
|
||||
bool "CAN utility library"
|
||||
default n
|
||||
depends on CAN
|
||||
---help---
|
||||
Enable the CAN utility library
|
||||
|
||||
if CANUTILS_CANLIB
|
||||
|
||||
endif
|
39
canutils/canlib/Make.defs
Normal file
39
canutils/canlib/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/canutils/canlib/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
# Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
#
|
||||
# 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_CANUTILS_CANLIB),y)
|
||||
CONFIGURED_APPS += canutils/canlib
|
||||
endif
|
47
canutils/canlib/Makefile
Normal file
47
canutils/canlib/Makefile
Normal file
@ -0,0 +1,47 @@
|
||||
############################################################################
|
||||
# apps/canutils/canlib/Makefile
|
||||
#
|
||||
# Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
# Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
#
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
APPNAME = canlib
|
||||
|
||||
include $(APPDIR)/Application.mk
|
82
canutils/canlib/canlib_getbaud.c
Normal file
82
canutils/canlib/canlib_getbaud.c
Normal file
@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_getbaud.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getbaud
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_BITTIMING
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* baud - pointer to a buffer to store the current baud rate
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_getbaud(int fd, FAR int *bauds)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_bittiming_s timings;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_BITTIMING, (unsigned long)&timings);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_GET_BITTIMING failed, errno=%d\n", errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*bauds = timings.bt_baud;
|
||||
|
||||
return ret;
|
||||
}
|
83
canutils/canlib/canlib_getloopback.c
Normal file
83
canutils/canlib/canlib_getloopback.c
Normal file
@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_getloopback.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getloopback
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_CONNMODES.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - pointer to a buffer to store the current loopback mode state.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_getloopback(int fd, FAR bool *loopback)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_connmodes_s connmodes;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*loopback = (bool)connmodes.bm_loopback;
|
||||
|
||||
return ret;
|
||||
}
|
84
canutils/canlib/canlib_getsilent.c
Normal file
84
canutils/canlib/canlib_getsilent.c
Normal file
@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_getsilent.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getsilent
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_CONNMODES.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - pointer to a buffer to store the current silent mode state.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_getsilent(int fd, FAR bool *silent)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_connmodes_s connmodes;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*silent = (bool)connmodes.bm_silent;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
88
canutils/canlib/canlib_setbaud.c
Normal file
88
canutils/canlib/canlib_setbaud.c
Normal file
@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_setbaud.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setbaud
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_BITTIMING
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* baud - baud rate to use on the CAN bus
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setbaud(int fd, int bauds)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_bittiming_s timings;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_BITTIMING, (unsigned long)&timings);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_GET_BITTIMING failed, errno=%d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
timings.bt_baud = bauds;
|
||||
|
||||
ret = ioctl(fd, CANIOC_SET_BITTIMING, (unsigned long)&timings);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_SET_BITTIMING failed, errno=%d\n", errno);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
90
canutils/canlib/canlib_setloopback.c
Normal file
90
canutils/canlib/canlib_setloopback.c
Normal file
@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_setloopback.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setloopback
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_CONNMODES. When loopback mode is enabled, the CAN
|
||||
* peripheral transmits on the bus, but only receives its own sent messages.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - wether to use loopback mode.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setloopback(int fd, bool loopback)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_connmodes_s connmodes;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
connmodes.bm_loopback = !!loopback;
|
||||
|
||||
ret = ioctl(fd, CANIOC_SET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_SET_CONNMODES failed, errno=%d\n", errno);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
90
canutils/canlib/canlib_setsilent.c
Normal file
90
canutils/canlib/canlib_setsilent.c
Normal file
@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_setsilent.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setsilent
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_CONNMODES. When silent mode is enabled, the CAN
|
||||
* peripheral never transmits on the bus, but receives all bus traffic.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - wether to use loopback mode.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setsilent(int fd, bool silent)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_connmodes_s connmodes;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
connmodes.bm_silent = !!silent;
|
||||
|
||||
ret = ioctl(fd, CANIOC_SET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret != OK)
|
||||
{
|
||||
canerr("CANIOC_SET_CONNMODES failed, errno=%d\n", errno);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
2
canutils/libcanard/.gitignore
vendored
Normal file
2
canutils/libcanard/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/.built
|
||||
/libcanard-*
|
27
canutils/libcanard/Kconfig
Normal file
27
canutils/libcanard/Kconfig
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config CANUTILS_LIBCANARD
|
||||
bool "libcanard UAVCAN Library"
|
||||
default n
|
||||
depends on CAN && CAN_EXTID && !DISABLE_POLL
|
||||
---help---
|
||||
Enable the libcanard UAVCAN library.
|
||||
|
||||
if CANUTILS_LIBCANARD
|
||||
|
||||
config LIBCANARD_URL
|
||||
string "libcanard URL"
|
||||
default "https://github.com/UAVCAN/libcanard/archive"
|
||||
---help---
|
||||
libcanard URL.
|
||||
|
||||
config LIBCANARD_VERSION
|
||||
string "libcanard Version"
|
||||
default "5ad65c6a4efda60cda7a8f0512da0f465822bbb8"
|
||||
---help---
|
||||
libcanard version.
|
||||
|
||||
endif
|
39
canutils/libcanard/Make.defs
Normal file
39
canutils/libcanard/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/canutils/libcanard/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2016 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_CANUTILS_LIBCANARD),y)
|
||||
CONFIGURED_APPS += canutils/libcanard
|
||||
endif
|
86
canutils/libcanard/Makefile
Normal file
86
canutils/libcanard/Makefile
Normal file
@ -0,0 +1,86 @@
|
||||
############################################################################
|
||||
# apps/canutils/libcanard/Makefile
|
||||
#
|
||||
# Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved.
|
||||
# Authors: 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
|
||||
|
||||
WGET = wget
|
||||
UNPACK = unzip
|
||||
PACKEXT = .zip
|
||||
|
||||
LIBCANARD_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARD_URL)))
|
||||
LIBCANARD_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARD_VERSION)))
|
||||
LIBCANARD_UNPACKNAME = libcanard-$(LIBCANARD_VERSION)
|
||||
LIBCANARD_PACKNAME = $(LIBCANARD_UNPACKNAME)$(PACKEXT)
|
||||
LIBCANARD_SRCDIR = $(LIBCANARD_UNPACKNAME)
|
||||
LIBCANARD_DRVDIR = $(LIBCANARD_SRCDIR)$(DELIM)drivers$(DELIM)nuttx
|
||||
|
||||
APPS_INCDIR = $(APPDIR)$(DELIM)include$(DELIM)canutils
|
||||
|
||||
CFLAGS += -std=c99 -I$(APPS_INCDIR) -DCANARD_ASSERT=DEBUGASSERT
|
||||
|
||||
CSRCS = $(LIBCANARD_SRCDIR)$(DELIM)canard.c $(LIBCANARD_DRVDIR)$(DELIM)canard_nuttx.c
|
||||
|
||||
$(LIBCANARD_PACKNAME):
|
||||
@echo "Downloading: $@"
|
||||
$(Q) $(WGET) -O $@ $(LIBCANARD_URL)$(DELIM)$(LIBCANARD_VERSION)$(PACKEXT)
|
||||
|
||||
$(LIBCANARD_UNPACKNAME): $(LIBCANARD_PACKNAME)
|
||||
@echo "Unpacking: $< -> $@"
|
||||
$(call DELDIR, $@)
|
||||
$(Q) $(UNPACK) $<
|
||||
$(Q) touch $@
|
||||
|
||||
$(LIBCANARD_SRCDIR)$(DELIM)canard.h: $(LIBCANARD_UNPACKNAME)
|
||||
|
||||
$(LIBCANARD_DRVDIR)$(DELIM)canard_nuttx.h: $(LIBCANARD_UNPACKNAME)
|
||||
|
||||
$(APPS_INCDIR)$(DELIM)canard.h: $(LIBCANARD_SRCDIR)$(DELIM)canard.h
|
||||
$(Q) cp $< $@
|
||||
|
||||
$(APPS_INCDIR)$(DELIM)canard_nuttx.h: $(LIBCANARD_DRVDIR)$(DELIM)canard_nuttx.h
|
||||
$(Q) cp $< $@
|
||||
|
||||
context:: $(APPS_INCDIR)$(DELIM)canard.h $(APPS_INCDIR)$(DELIM)canard_nuttx.h
|
||||
|
||||
clean::
|
||||
$(foreach OBJ, $(OBJS), $(call DELFILE, $(OBJ)))
|
||||
|
||||
distclean::
|
||||
$(call DELFILE, $(APPS_INCDIR)$(DELIM)canard.h)
|
||||
$(call DELFILE, $(APPS_INCDIR)$(DELIM)canard_nuttx.h)
|
||||
$(call DELDIR, $(LIBCANARD_UNPACKNAME))
|
||||
$(call DELFILE, $(LIBCANARD_PACKNAME))
|
||||
|
||||
include $(APPDIR)/Application.mk
|
2
canutils/libobd2/.gitignore
vendored
Normal file
2
canutils/libobd2/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/.built
|
||||
/libcanard-*
|
22
canutils/libobd2/Kconfig
Normal file
22
canutils/libobd2/Kconfig
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config CANUTILS_LIBOBD2
|
||||
bool "OBD-II Library"
|
||||
default n
|
||||
depends on CAN
|
||||
---help---
|
||||
Enable the OBD-II Library
|
||||
|
||||
if CANUTILS_LIBOBD2
|
||||
|
||||
config LIBOBD2_MULTIFRAME
|
||||
bool "Enable to Multi-Frame support (increases 4KB RAM)"
|
||||
default n
|
||||
---help---
|
||||
Enable the support for multi-frames of the OBD-II protocol.
|
||||
In the multi-frame mode the ECU can send frame up to 4096 bytes.
|
||||
|
||||
endif
|
39
canutils/libobd2/Make.defs
Normal file
39
canutils/libobd2/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/canutils/libobd2/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2017 Alan Carvalho de Assis. 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
|
||||
# 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_CANUTILS_LIBOBD2),y)
|
||||
CONFIGURED_APPS += canutils/libobd2
|
||||
endif
|
45
canutils/libobd2/Makefile
Normal file
45
canutils/libobd2/Makefile
Normal file
@ -0,0 +1,45 @@
|
||||
############################################################################
|
||||
# apps/canutils/libobd2/Makefile
|
||||
#
|
||||
# Copyright (C) 2017 Alan Carvalho de Assis. 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
|
||||
# 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
|
||||
|
||||
# CAN utility library
|
||||
|
||||
ASRCS =
|
||||
CSRCS = obd2.c obd_sendrequest.c obd_waitresponse.c obd_decodepid.c
|
||||
|
||||
APPNAME = libobd2
|
||||
|
||||
include $(APPDIR)/Application.mk
|
126
canutils/libobd2/obd2.c
Normal file
126
canutils/libobd2/obd2.c
Normal file
@ -0,0 +1,126 @@
|
||||
/****************************************************************************
|
||||
* canutils/libobd2/obd2.c
|
||||
*
|
||||
* Copyright (C) 2017 Alan Carvalho de Assis. 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
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
#include "canutils/obd.h"
|
||||
#include "canutils/obd_pid.h"
|
||||
#include "canutils/obd_frame.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: obd_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize the OBD-II with initial baudrate
|
||||
*
|
||||
* Returns a obd_dev_s with initial values or NULL if error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct obd_dev_s *obd_init(char *devfile, int baudate, int mode)
|
||||
{
|
||||
struct obd_dev_s *dev;
|
||||
int ret;
|
||||
|
||||
/* Alloc memory for this device */
|
||||
|
||||
dev = malloc(sizeof(struct obd_dev_s));
|
||||
if (!dev)
|
||||
{
|
||||
printf("ERROR: Failed to alloc memory for obd_dev!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Open the CAN device for reading/writing */
|
||||
|
||||
dev->can_fd = open(devfile, O_RDWR);
|
||||
if (dev->can_fd < 0)
|
||||
{
|
||||
printf("ERROR: open %s failed: %d\n", devfile, errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Show bit timing information if provided by the driver. Not all CAN
|
||||
* drivers will support this IOCTL.
|
||||
*/
|
||||
|
||||
ret = ioctl(dev->can_fd, CANIOC_GET_BITTIMING,
|
||||
(unsigned long)((uintptr_t)&dev->can_bt));
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Bit timing not available: %d\n", errno);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Bit timing:\n");
|
||||
printf(" Baud: %lu\n", (unsigned long)dev->can_bt.bt_baud);
|
||||
printf(" TSEG1: %u\n", dev->can_bt.bt_tseg1);
|
||||
printf(" TSEG2: %u\n", dev->can_bt.bt_tseg2);
|
||||
printf(" SJW: %u\n", dev->can_bt.bt_sjw);
|
||||
}
|
||||
|
||||
/* FIXME: Setup the baudrate */
|
||||
|
||||
/* Setup the initial mode */
|
||||
|
||||
if (mode != CAN_STD && mode != CAN_EXT)
|
||||
{
|
||||
printf("ERROR: Invalid mode, it needs to be CAN_STD or CAN_EXT!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->can_mode = mode;
|
||||
|
||||
printf("OBD-II device initialized!\n");
|
||||
|
||||
return dev;
|
||||
}
|
135
canutils/libobd2/obd_decodepid.c
Normal file
135
canutils/libobd2/obd_decodepid.c
Normal file
@ -0,0 +1,135 @@
|
||||
/****************************************************************************
|
||||
* canutils/libobd2/obd_decodepid.c
|
||||
*
|
||||
* Copyright (C) 2017 Alan Carvalho de Assis. 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
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
#include "canutils/obd.h"
|
||||
#include "canutils/obd_pid.h"
|
||||
#include "canutils/obd_frame.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define MAXDATA 16
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static char g_data[MAXDATA];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: obd_decode_pid
|
||||
*
|
||||
* Description:
|
||||
* Decode the value returned for a determined PID.
|
||||
*
|
||||
* It will return the data decode as text string or NULL if error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *obd_decode_pid(FAR struct obd_dev_s *dev, uint8_t pid)
|
||||
{
|
||||
uint32_t pids;
|
||||
int rpm;
|
||||
|
||||
/* Verify if received data is valid */
|
||||
|
||||
if (dev->data[2] != pid)
|
||||
{
|
||||
printf("Expecting PID %02x but received %02x!\n", pid, dev->data[2]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (dev->data[2])
|
||||
{
|
||||
case OBD_PID_SUPPORTED:
|
||||
pids = (dev->data[3] << 24) | (dev->data[4] << 16) | \
|
||||
(dev->data[5] << 8) | dev->data[6];
|
||||
snprintf(g_data, MAXDATA, "%08X", pids);
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("Supported PIDs: %08X\n");
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OBD_PID_ENGINE_TEMPERATURE:
|
||||
snprintf(g_data, MAXDATA, "%d", dev->data[3] - 40);
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("Engine Temperature = %d\n", dev->data[3] - 40);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OBD_PID_RPM:
|
||||
rpm = ((256 * dev->data[3]) + dev->data[4])/4;
|
||||
snprintf(g_data, MAXDATA, "%d", rpm);
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("RPM = %d\n", rpm);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OBD_PID_SPEED:
|
||||
snprintf(g_data, MAXDATA, "%d", dev->data[3]);
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("SPEED = %d Km/h\n", dev->data[3]);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OBD_PID_THROTTLE_POSITION:
|
||||
snprintf(g_data, MAXDATA, "%d", (100 * dev->data[3])/255);
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("Throttle position = %d\% \n", (100 * dev->data[3])/255);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
return g_data;
|
||||
}
|
151
canutils/libobd2/obd_sendrequest.c
Normal file
151
canutils/libobd2/obd_sendrequest.c
Normal file
@ -0,0 +1,151 @@
|
||||
/****************************************************************************
|
||||
* canutils/libobd2/obd_sendrequest.c
|
||||
*
|
||||
* Copyright (C) 2017 Alan Carvalho de Assis. 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
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
#include "canutils/obd.h"
|
||||
#include "canutils/obd_pid.h"
|
||||
#include "canutils/obd_frame.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: obd_sent_request
|
||||
*
|
||||
* Description:
|
||||
* Send a "Request Message" to ECUs with requested PID.
|
||||
*
|
||||
* It will return an error case the message fails to be sent.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int obd_send_request(FAR struct obd_dev_s *dev, uint8_t opmode, uint8_t pid)
|
||||
{
|
||||
int nbytes;
|
||||
int msgdlc;
|
||||
int msgsize;
|
||||
uint8_t extended;
|
||||
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("Going SendRequest opmode=%d pid=%d\n", opmode, pid);
|
||||
#endif
|
||||
|
||||
/* Verify what is the current mode */
|
||||
|
||||
if (dev->can_mode == CAN_EXT)
|
||||
{
|
||||
extended = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
extended = 0;
|
||||
}
|
||||
|
||||
/* Define the CAN Data Length */
|
||||
|
||||
msgdlc = 8;
|
||||
|
||||
/* Construct the TX message header */
|
||||
|
||||
if (extended)
|
||||
{
|
||||
dev->can_txmsg.cm_hdr.ch_id = OBD_PID_STD_REQUEST; /* MSG ID for PID Request */
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONFIG_CAN_EXTID
|
||||
dev->can_txmsg.cm_hdr.ch_id = OBD_PID_EXT_REQUEST; /* MSG ID for PID Request */
|
||||
#endif
|
||||
}
|
||||
|
||||
dev->can_txmsg.cm_hdr.ch_rtr = false; /* Not a Remote Frame */
|
||||
dev->can_txmsg.cm_hdr.ch_dlc = msgdlc; /* Data length is 8 bytes */
|
||||
#ifdef CONFIG_CAN_EXTID
|
||||
dev->can_txmsg.cm_hdr.ch_extid = extended; /* Standard/Extend mode */
|
||||
#endif
|
||||
dev->can_txmsg.cm_hdr.ch_unused = 0; /* Unused */
|
||||
|
||||
/* Single Frame with two bytes data */
|
||||
|
||||
dev->can_txmsg.cm_data[0] = OBD_SINGLE_FRAME | OBD_SF_DATA_LEN(2);
|
||||
|
||||
/* Setup the Operation Mode */
|
||||
|
||||
dev->can_txmsg.cm_data[1] = opmode;
|
||||
|
||||
/* Setup the PID we are requesting */
|
||||
|
||||
dev->can_txmsg.cm_data[2] = pid;
|
||||
|
||||
/* Padding */
|
||||
|
||||
dev->can_txmsg.cm_data[3] = 0;
|
||||
dev->can_txmsg.cm_data[4] = 0;
|
||||
dev->can_txmsg.cm_data[5] = 0;
|
||||
dev->can_txmsg.cm_data[6] = 0;
|
||||
dev->can_txmsg.cm_data[7] = 0;
|
||||
|
||||
/* Send the TX message */
|
||||
|
||||
msgsize = CAN_MSGLEN(msgdlc);
|
||||
nbytes = write(dev->can_fd, &dev->can_txmsg, msgsize);
|
||||
if (nbytes != msgsize)
|
||||
{
|
||||
printf("ERROR: write(%ld) returned %ld\n",
|
||||
(long)msgsize, (long)nbytes);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("PID Request sent correctly!\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
160
canutils/libobd2/obd_waitresponse.c
Normal file
160
canutils/libobd2/obd_waitresponse.c
Normal file
@ -0,0 +1,160 @@
|
||||
/****************************************************************************
|
||||
* canutils/libobd2/obd_waitresponse.c
|
||||
*
|
||||
* Copyright (C) 2017 Alan Carvalho de Assis. 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
|
||||
* 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 <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can/can.h>
|
||||
|
||||
#include "canutils/obd.h"
|
||||
#include "canutils/obd_pid.h"
|
||||
#include "canutils/obd_frame.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: obd_wait_response
|
||||
*
|
||||
* Description:
|
||||
* Wait for a message from ECUs with requested PID that was sent using
|
||||
* obd_send_request().
|
||||
*
|
||||
* It will return an error case it doesn't receive the msg after the elapsed
|
||||
* "timeout" time.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int obd_wait_response(FAR struct obd_dev_s *dev, uint8_t opmode, uint8_t pid,
|
||||
int timeout)
|
||||
{
|
||||
int i;
|
||||
int nbytes;
|
||||
int msgdlc;
|
||||
int msgsize;
|
||||
uint8_t extended;
|
||||
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("Waiting Response for pid=%d\n", pid);
|
||||
#endif
|
||||
|
||||
/* Verify what is the current mode */
|
||||
|
||||
if (dev->can_mode == CAN_EXT)
|
||||
{
|
||||
extended = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
extended = 0;
|
||||
}
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
/* Read the RX message */
|
||||
|
||||
msgsize = sizeof(struct can_msg_s);
|
||||
nbytes = read(dev->can_fd, &dev->can_rxmsg, msgsize);
|
||||
if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize)
|
||||
{
|
||||
printf("ERROR: read(%ld) returned %ld\n",
|
||||
(long)msgsize, (long)nbytes);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf(" ID: %4u DLC: %u\n",
|
||||
dev->can_rxmsg.cm_hdr.ch_id, dev->can_rxmsg.cm_hdr.ch_dlc);
|
||||
#endif
|
||||
|
||||
msgdlc = dev->can_rxmsg.cm_hdr.ch_dlc;
|
||||
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
printf("Data received:\n");
|
||||
for (i = 0; i < msgdlc; i++)
|
||||
{
|
||||
printf(" %d: 0x%02x\n", i, dev->can_rxmsg.cm_data[i]);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
/* Check if we received a Response Message */
|
||||
|
||||
if ((extended && dev->can_rxmsg.cm_hdr.ch_id == OBD_PID_EXT_RESPONSE) || \
|
||||
(!extended && dev->can_rxmsg.cm_hdr.ch_id == OBD_PID_STD_RESPONSE))
|
||||
{
|
||||
|
||||
/* Check if the Response if for the PID we are interested! */
|
||||
|
||||
if (dev->can_rxmsg.cm_data[1] == (opmode + OBD_RESP_BASE) && \
|
||||
dev->can_rxmsg.cm_data[2] == pid)
|
||||
{
|
||||
/* Save received data (important for multi-frame mode) */
|
||||
|
||||
memcpy(dev->data, dev->can_rxmsg.cm_data, msgdlc);
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify if we timed out */
|
||||
|
||||
timeout--;
|
||||
if (timeout < 0)
|
||||
{
|
||||
printf("Timeout trying to receive PID %d\n", pid);
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
/* Wait 10ms */
|
||||
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
/* Never should come here */
|
||||
|
||||
return OK;
|
||||
}
|
2
examples/.gitignore
vendored
Normal file
2
examples/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/Kconfig
|
||||
|
37
examples/Make.defs
Normal file
37
examples/Make.defs
Normal file
@ -0,0 +1,37 @@
|
||||
############################################################################
|
||||
# apps/examples/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(wildcard examples/*/Make.defs)
|
38
examples/Makefile
Normal file
38
examples/Makefile
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# apps/examples/Makefile
|
||||
#
|
||||
# Copyright (C) 2011-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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
MENUDESC = "Examples"
|
||||
|
||||
include $(APPDIR)/Directory.mk
|
2279
examples/README.txt
Normal file
2279
examples/README.txt
Normal file
File diff suppressed because it is too large
Load Diff
11
examples/adc/.gitignore
vendored
Normal file
11
examples/adc/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
49
examples/adc/Kconfig
Normal file
49
examples/adc/Kconfig
Normal file
@ -0,0 +1,49 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_ADC
|
||||
tristate "ADC example"
|
||||
default n
|
||||
depends on ADC && LIB_BOARDCTL
|
||||
select BOARDCTL_ADCTEST
|
||||
---help---
|
||||
Enable the ADC example
|
||||
|
||||
if EXAMPLES_ADC
|
||||
|
||||
config EXAMPLES_ADC_DEVPATH
|
||||
string "ADC device path"
|
||||
default "/dev/adc0"
|
||||
---help---
|
||||
The default path to the ADC device. Default: /dev/adc0
|
||||
|
||||
config EXAMPLES_ADC_NSAMPLES
|
||||
int "Number of Sample Groups"
|
||||
default 0
|
||||
depends on !NSH_BUILTIN_APPS
|
||||
---help---
|
||||
If NSH_BUILTIN_APPS is defined, then the number of samples is provided
|
||||
on the command line and this value is ignored. Otherwise, this number
|
||||
of samples is collected and the program terminates. Default: 0 (samples
|
||||
are collected indefinitely).
|
||||
|
||||
config EXAMPLES_ADC_GROUPSIZE
|
||||
int "Number of Samples per Group"
|
||||
default 4
|
||||
---help---
|
||||
The number of samples to read at once. Default: 4
|
||||
|
||||
config EXAMPLES_ADC_SWTRIG
|
||||
bool "Use software trigger"
|
||||
default n
|
||||
---help---
|
||||
Some ADCs may be configured so there is no automatic or periodic
|
||||
conversion of samples. Rather, the ADC sampling must be trigger by
|
||||
software via an ioctl command. Select this option only if
|
||||
applicable for your ADC configuration. In this case, the test will
|
||||
issue the software trigger ioctl before attempting to read from the
|
||||
ADC.
|
||||
|
||||
endif
|
39
examples/adc/Make.defs
Normal file
39
examples/adc/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/adc/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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_ADC),)
|
||||
CONFIGURED_APPS += examples/adc
|
||||
endif
|
55
examples/adc/Makefile
Normal file
55
examples/adc/Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
############################################################################
|
||||
# apps/examples/adc/Makefile
|
||||
#
|
||||
# Copyright (C) 2011-2012 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
|
||||
|
||||
# ADC example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = adc_main.c
|
||||
|
||||
CONFIG_XYZ_PROGNAME ?= adc$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_XYZ_PROGNAME)
|
||||
|
||||
# application info
|
||||
|
||||
APPNAME = adc
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_ADC
|
||||
|
||||
include $(APPDIR)/Application.mk
|
94
examples/adc/adc.h
Normal file
94
examples/adc/adc.h
Normal file
@ -0,0 +1,94 @@
|
||||
/****************************************************************************
|
||||
* examples/examples/adc/adc.h
|
||||
*
|
||||
* Copyright (C) 2011 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_ADC_ADC_H
|
||||
#define __APPS_EXAMPLES_ADC_ADC_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
/* CONFIG_NSH_BUILTIN_APPS - Build the ADC test as an NSH built-in function.
|
||||
* Default: Built as a standalone program
|
||||
* CONFIG_EXAMPLES_ADC_DEVPATH - The default path to the ADC device. Default: /dev/adc0
|
||||
* CONFIG_EXAMPLES_ADC_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS
|
||||
* is defined, then the number of samples is provided on the command line
|
||||
* and this value is ignored. Otherwise, this number of samples is
|
||||
* collected and the program terminates. Default: Samples are collected
|
||||
* indefinitely.
|
||||
* CONFIG_EXAMPLES_ADC_GROUPSIZE - The number of samples to read at once.
|
||||
* Default: 4
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_ADC
|
||||
# error "ADC device support is not enabled (CONFIG_ADC)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_ADC_DEVPATH
|
||||
# define CONFIG_EXAMPLES_ADC_DEVPATH "/dev/adc0"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_ADC_GROUPSIZE
|
||||
# define CONFIG_EXAMPLES_ADC_GROUPSIZE 4
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct adc_state_s
|
||||
{
|
||||
bool initialized;
|
||||
FAR char *devpath;
|
||||
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
|
||||
int count;
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __APPS_EXAMPLES_ADC_ADC_H */
|
385
examples/adc/adc_main.c
Normal file
385
examples/adc/adc_main.c
Normal file
@ -0,0 +1,385 @@
|
||||
/****************************************************************************
|
||||
* examples/adc/adc_main.c
|
||||
*
|
||||
* Copyright (C) 2011-2012, 2015, 2017 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/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/analog/adc.h>
|
||||
#include <nuttx/analog/ioctl.h>
|
||||
|
||||
#include "adc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Use CONFIG_EXAMPLES_ADC_NSAMPLES == 0 to mean to collect samples
|
||||
* indefinitely.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_ADC_NSAMPLES
|
||||
# define CONFIG_EXAMPLES_ADC_NSAMPLES 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct adc_state_s g_adcstate;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: adc_devpath
|
||||
****************************************************************************/
|
||||
|
||||
static void adc_devpath(FAR struct adc_state_s *adc, FAR const char *devpath)
|
||||
{
|
||||
/* Get rid of any old device path */
|
||||
|
||||
if (adc->devpath)
|
||||
{
|
||||
free(adc->devpath);
|
||||
}
|
||||
|
||||
/* Then set-up the new device path by copying the string */
|
||||
|
||||
adc->devpath = strdup(devpath);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: adc_help
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static void adc_help(FAR struct adc_state_s *adc)
|
||||
{
|
||||
printf("Usage: adc [OPTIONS]\n");
|
||||
printf("\nArguments are \"sticky\". For example, once the ADC device is\n");
|
||||
printf("specified, that device will be re-used until it is changed.\n");
|
||||
printf("\n\"sticky\" OPTIONS include:\n");
|
||||
printf(" [-p devpath] selects the ADC device. "
|
||||
"Default: %s Current: %s\n",
|
||||
CONFIG_EXAMPLES_ADC_DEVPATH, g_adcstate.devpath ? g_adcstate.devpath : "NONE");
|
||||
printf(" [-n count] selects the samples to collect. "
|
||||
"Default: 1 Current: %d\n", adc->count);
|
||||
printf(" [-h] shows this message and exits\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arg_string
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static int arg_string(FAR char **arg, FAR char **value)
|
||||
{
|
||||
FAR char *ptr = *arg;
|
||||
|
||||
if (ptr[2] == '\0')
|
||||
{
|
||||
*value = arg[1];
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*value = &ptr[2];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arg_decimal
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static int arg_decimal(FAR char **arg, FAR long *value)
|
||||
{
|
||||
FAR char *string;
|
||||
int ret;
|
||||
|
||||
ret = arg_string(arg, &string);
|
||||
*value = strtol(string, NULL, 10);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: parse_args
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static void parse_args(FAR struct adc_state_s *adc, int argc, FAR char **argv)
|
||||
{
|
||||
FAR char *ptr;
|
||||
FAR char *str;
|
||||
long value;
|
||||
int index;
|
||||
int nargs;
|
||||
|
||||
for (index = 1; index < argc; )
|
||||
{
|
||||
ptr = argv[index];
|
||||
if (ptr[0] != '-')
|
||||
{
|
||||
printf("Invalid options format: %s\n", ptr);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
switch (ptr[1])
|
||||
{
|
||||
case 'n':
|
||||
nargs = arg_decimal(&argv[index], &value);
|
||||
if (value < 0)
|
||||
{
|
||||
printf("Count must be non-negative: %ld\n", value);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
adc->count = (uint32_t)value;
|
||||
index += nargs;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
nargs = arg_string(&argv[index], &str);
|
||||
adc_devpath(adc, str);
|
||||
index += nargs;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
adc_help(adc);
|
||||
exit(0);
|
||||
|
||||
default:
|
||||
printf("Unsupported option: %s\n", ptr);
|
||||
adc_help(adc);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: adc_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int adc_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
struct adc_msg_s sample[CONFIG_EXAMPLES_ADC_GROUPSIZE];
|
||||
size_t readsize;
|
||||
ssize_t nbytes;
|
||||
int fd;
|
||||
int errval = 0;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
UNUSED(ret);
|
||||
|
||||
/* Check if we have initialized */
|
||||
|
||||
if (!g_adcstate.initialized)
|
||||
{
|
||||
/* Initialization of the ADC hardware must be performed by board-specific
|
||||
* logic prior to running this test.
|
||||
*/
|
||||
|
||||
/* Set the default values */
|
||||
|
||||
adc_devpath(&g_adcstate, CONFIG_EXAMPLES_ADC_DEVPATH);
|
||||
|
||||
g_adcstate.initialized = true;
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLES_ADC_NSAMPLES > 0
|
||||
g_adcstate.count = CONFIG_EXAMPLES_ADC_NSAMPLES;
|
||||
#else
|
||||
g_adcstate.count = 1;
|
||||
#endif
|
||||
|
||||
/* Parse the command line */
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
parse_args(&g_adcstate, argc, argv);
|
||||
#endif
|
||||
|
||||
/* If this example is configured as an NX add-on, then limit the number of
|
||||
* samples that we collect before returning. Otherwise, we never return
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_ADC_NSAMPLES > 0
|
||||
printf("adc_main: g_adcstate.count: %d\n", g_adcstate.count);
|
||||
#endif
|
||||
|
||||
/* Open the ADC device for reading */
|
||||
|
||||
printf("adc_main: Hardware initialized. Opening the ADC device: %s\n",
|
||||
g_adcstate.devpath);
|
||||
|
||||
fd = open(g_adcstate.devpath, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno);
|
||||
errval = 2;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Now loop the appropriate number of times, displaying the collected
|
||||
* ADC samples.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NSH_BUILTIN_APPS)
|
||||
for (; g_adcstate.count > 0; g_adcstate.count--)
|
||||
#elif CONFIG_EXAMPLES_ADC_NSAMPLES > 0
|
||||
for (g_adcstate.count = 0;
|
||||
g_adcstate.count < CONFIG_EXAMPLES_ADC_NSAMPLES;
|
||||
g_adcstate.count++)
|
||||
#else
|
||||
for (;;)
|
||||
#endif
|
||||
{
|
||||
/* Flush any output before the loop entered or from the previous pass
|
||||
* through the loop.
|
||||
*/
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_ADC_SWTRIG
|
||||
/* Issue the software trigger to start ADC conversion */
|
||||
|
||||
ret = ioctl(fd, ANIOC_TRIGGER, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
printf("adc_main: ANIOC_TRIGGER ioctl failed: %d\n", errcode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Read up to CONFIG_EXAMPLES_ADC_GROUPSIZE samples */
|
||||
|
||||
readsize = CONFIG_EXAMPLES_ADC_GROUPSIZE * sizeof(struct adc_msg_s);
|
||||
nbytes = read(fd, sample, readsize);
|
||||
|
||||
/* Handle unexpected return values */
|
||||
|
||||
if (nbytes < 0)
|
||||
{
|
||||
errval = errno;
|
||||
if (errval != EINTR)
|
||||
{
|
||||
printf("adc_main: read %s failed: %d\n",
|
||||
g_adcstate.devpath, errval);
|
||||
errval = 3;
|
||||
goto errout_with_dev;
|
||||
}
|
||||
|
||||
printf("adc_main: Interrupted read...\n");
|
||||
}
|
||||
else if (nbytes == 0)
|
||||
{
|
||||
printf("adc_main: No data read, Ignoring\n");
|
||||
}
|
||||
|
||||
/* Print the sample data on successful return */
|
||||
|
||||
else
|
||||
{
|
||||
int nsamples = nbytes / sizeof(struct adc_msg_s);
|
||||
if (nsamples * sizeof(struct adc_msg_s) != nbytes)
|
||||
{
|
||||
printf("adc_main: read size=%ld is not a multiple of sample size=%d, Ignoring\n",
|
||||
(long)nbytes, sizeof(struct adc_msg_s));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Sample:\n");
|
||||
for (i = 0; i < nsamples; i++)
|
||||
{
|
||||
printf("%d: channel: %d value: %d\n",
|
||||
i+1, sample[i].am_channel, sample[i].am_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return OK;
|
||||
|
||||
/* Error exits */
|
||||
|
||||
errout_with_dev:
|
||||
close(fd);
|
||||
|
||||
errout:
|
||||
printf("Terminating!\n");
|
||||
fflush(stdout);
|
||||
return errval;
|
||||
}
|
11
examples/adxl372_test/.gitignore
vendored
Normal file
11
examples/adxl372_test/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
30
examples/adxl372_test/Kconfig
Normal file
30
examples/adxl372_test/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_ADXL372_TEST
|
||||
tristate "ADXL372 test program"
|
||||
default n
|
||||
---help---
|
||||
Enable the ADXL372 sensor SPI test program.
|
||||
|
||||
if EXAMPLES_ADXL372_TEST
|
||||
|
||||
config EXAMPLES_ADXL372_TEST_PROGNAME
|
||||
string "Program name"
|
||||
default "ADXL372_test"
|
||||
depends on BUILD_LOADABLE
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_ADXL372_TEST_PRIORITY
|
||||
int "ADXL372_test task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_ADXL372_TEST_STACKSIZE
|
||||
int "ADXL372_test stack size"
|
||||
default 2048
|
||||
|
||||
endif
|
39
examples/adxl372_test/Make.defs
Normal file
39
examples/adxl372_test/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/adxl372_test/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2018 RAF Research. All rights reserved.
|
||||
# Author: Bob Feretich <bob.feretich@rafresearch/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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_ADXL372_TEST),)
|
||||
CONFIGURED_APPS += examples/adxl372_test
|
||||
endif
|
56
examples/adxl372_test/Makefile
Normal file
56
examples/adxl372_test/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
############################################################################
|
||||
# apps/examples/adxl372_test/Makefile
|
||||
#
|
||||
# Copyright (C) 2018 RAF Research. All rights reserved.
|
||||
# Author: Bob Feretich <bob.feretich@rafresearch/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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
CONFIG_EXAMPLES_ADXL372_TEST_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_ADXL372_TEST_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = adxl372_test
|
||||
PRIORITY = $(CONFIG_EXAMPLES_ADXL372_TEST_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_ADXL372_TEST_STACKSIZE)
|
||||
|
||||
# ADXL372 sensor test Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = adxl372_test_main.c
|
||||
|
||||
CONFIG_EXAMPLES_ADXL372_TEST_PROGNAME ?= adxl372_test$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_ADXL372_TEST_PROGNAME)
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_ADXL372_TEST
|
||||
|
||||
include $(APPDIR)/Application.mk
|
559
examples/adxl372_test/adxl372_test_main.c
Normal file
559
examples/adxl372_test/adxl372_test_main.c
Normal file
@ -0,0 +1,559 @@
|
||||
/****************************************************************************
|
||||
* examples/adxl372_test/adxl372_test_main.c
|
||||
*
|
||||
* Copyright (C) 2018 RAF Research. All rights reserved.
|
||||
* Author: Bob Feretich <bob.feretich@rafresearch/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 <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
#undef __KERNEL__
|
||||
#include <arch/board/board.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/sensors/adxl372.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
|
||||
#define PASSED 0
|
||||
|
||||
#define SUB_PROMPT "stst >"
|
||||
#define CRED "\x1b[31m"
|
||||
#define CGREEN "\x1b[32m"
|
||||
#define CYELLOW "\x1b[33m"
|
||||
#define CBLUE "\x1b[34m"
|
||||
#define CMAGENTA "\x1b[35m"
|
||||
#define CCYAN "\x1b[36m"
|
||||
#define CRESET "\x1b[0m"
|
||||
|
||||
/* Return codes */
|
||||
|
||||
#define RC_OPENFAIL (-1)
|
||||
#define RC_OPENRONLY (-2)
|
||||
#define RC_SEEKFAIL (-3)
|
||||
#define RC_READFAIL (-4)
|
||||
#define RC_IDFAIL (-5)
|
||||
#define RC_SEEK2FAIL (-6)
|
||||
#define RC_WRITEFAIL (-7)
|
||||
#define RC_READ2FAIL (-8)
|
||||
#define RC_WRMFAIL (-9)
|
||||
#define RC_SEEK3FAIL (-10)
|
||||
#define RC_READ3FAIL (-11)
|
||||
#define RC_INVALPATH (-41)
|
||||
#define RC_INVALPARM (-42)
|
||||
|
||||
/****************************************************************************
|
||||
* Private types
|
||||
****************************************************************************/
|
||||
|
||||
typedef CODE int (*test_ptr_t)(int, FAR char *);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: subtest_prompt()
|
||||
*
|
||||
* Description:
|
||||
* 1. Display the prompt.
|
||||
* 2. Receive a character from the console port.
|
||||
* 3. Filter the input character. Invalid characters convert to either
|
||||
* '!' (error) of '*' (invalid character).
|
||||
* 4. Echo the character.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static char subtest_prompt(FAR char *prompt)
|
||||
{
|
||||
char c;
|
||||
|
||||
printf("%s", prompt);
|
||||
fflush(stdout);
|
||||
c = getchar();
|
||||
if (c < 1)
|
||||
{
|
||||
c = '!';
|
||||
}
|
||||
else if ((c < 0x20 || c > 0x7e) && c != '\r')
|
||||
{
|
||||
c = '*';
|
||||
}
|
||||
|
||||
if (c != '\r')
|
||||
{
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
return c;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Name: adxl372_test
|
||||
*
|
||||
* Description:
|
||||
* This function is public so that it can be called by board diagnostic
|
||||
* programs that contain the ADXL372.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
static int adxl372_test(int is_interactive, FAR char *path)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
int errcode;
|
||||
int i;
|
||||
char ch1 = 0;
|
||||
struct XYZ
|
||||
{
|
||||
int16_t d[3];
|
||||
};
|
||||
unsigned char tstchars[] =
|
||||
{
|
||||
0x5e, 0xc5, 0x00
|
||||
};
|
||||
char bfr[32] __attribute__((aligned(2))); /* REVISIT: GCC dependent attribute */
|
||||
FAR struct XYZ *pxyz = (FAR struct XYZ *) bfr;
|
||||
int rc = PASSED;
|
||||
int rc_step = PASSED;
|
||||
|
||||
printf("\nADXL372 accelerometer diagnostic started...\n");
|
||||
fd = open (path, O_RDWR);
|
||||
if (fd < 0 || (errno != EROFS && errno != 0))
|
||||
{
|
||||
errcode = errno;
|
||||
printf(CRED "ERROR: Failed to open %s: %d" CRESET "\n", path, errcode);
|
||||
return RC_OPENFAIL;
|
||||
}
|
||||
else if (errno == EROFS)
|
||||
{
|
||||
printf(CRED "ERROR: Accelerometer mounted as Read Only." CRESET "\n", path, errno);
|
||||
rc = RC_OPENRONLY;
|
||||
}
|
||||
|
||||
printf("open errno=%d\n", errno);
|
||||
|
||||
do
|
||||
{
|
||||
/* read id register */
|
||||
|
||||
printf("Reading ADXL372 ID_REG...\n");
|
||||
ret = lseek(fd, ADXL372_DEVID_AD, SEEK_SET);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
||||
ADXL372_DEVID_AD, path, errcode);
|
||||
rc = RC_SEEKFAIL;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
memset(bfr, 0xAA, sizeof(bfr));
|
||||
ret = read(fd, bfr, 4); /* read the sensor id regs */
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
printf(CRED "ERROR: Failed to read sensor ID from %s: %d" CRESET "\n",
|
||||
path, errcode);
|
||||
rc = RC_READFAIL;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
if (bfr[0] != ADXL372_DEVID_AD_VALUE &&
|
||||
bfr[1] != ADXL372_DEVID_MST_VALUE &&
|
||||
bfr[2] != ADXL372_PARTID_VALUE)
|
||||
{
|
||||
printf(CRED "ERROR: Sensor ID is 0x%02X%02X%02X%02X, expected 0x%02X%02X%02Xxx." CRESET "\n",
|
||||
bfr[0], bfr[1], bfr[2], bfr[3],
|
||||
ADXL372_DEVID_AD_VALUE, ADXL372_DEVID_MST_VALUE,
|
||||
ADXL372_PARTID_VALUE);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
rc = RC_IDFAIL;
|
||||
}
|
||||
|
||||
if (!is_interactive)
|
||||
{
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Sensor ID 0x%02X%02X%02X%02X is correct!\n",
|
||||
bfr[0], bfr[1], bfr[2], bfr[3]);
|
||||
}
|
||||
|
||||
if (is_interactive)
|
||||
{
|
||||
ch1 = subtest_prompt("Press 'l' to repeat or enter to continue.\n"
|
||||
SUB_PROMPT);
|
||||
}
|
||||
|
||||
if (ch1 == 'x')
|
||||
{
|
||||
goto quick_exit;
|
||||
}
|
||||
}
|
||||
while (ch1 == 'l');
|
||||
|
||||
do
|
||||
{
|
||||
/* Write and read a scratch register */
|
||||
|
||||
printf("Writing and reading a scratch register...\n");
|
||||
ret = lseek(fd, ADXL372_SCRATCH, SEEK_SET);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
||||
ADXL372_SCRATCH, path, errcode);
|
||||
rc = RC_SEEK2FAIL;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
rc_step = PASSED;
|
||||
for (i = 0; i < sizeof(tstchars); i++)
|
||||
{
|
||||
memset(bfr, 0xAA, sizeof(bfr));
|
||||
bfr[0] = (char)tstchars[i];
|
||||
ret = write(fd, bfr, 1); /* write the scratch register */
|
||||
if (ret < 0 && rc != RC_OPENRONLY)
|
||||
{
|
||||
errcode = errno;
|
||||
printf(CRED "ERROR: Write operation failed to %s: %d" CRESET "\n",
|
||||
path, errcode);
|
||||
rc = RC_WRITEFAIL;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
memset(bfr, 0xAA, sizeof(bfr));
|
||||
ret = read(fd, bfr, 1); /* read the scratch register */
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
printf(CRED "ERROR: Read operation failed from %s: %d" CRESET "\n",
|
||||
path, errcode);
|
||||
rc = RC_READ2FAIL;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
if (bfr[0] != (char)tstchars[i])
|
||||
{
|
||||
printf(CRED "ERROR: Wrote 0x%02X, read back 0x%02X." CRESET "\n",
|
||||
tstchars[i], bfr[0]);
|
||||
rc_step = RC_WRMFAIL;
|
||||
if (rc == 0)
|
||||
{
|
||||
rc = RC_WRMFAIL;
|
||||
}
|
||||
|
||||
if (!is_interactive)
|
||||
{
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rc_step == PASSED)
|
||||
{
|
||||
printf("Read/write test passed!\n");
|
||||
}
|
||||
|
||||
if (is_interactive)
|
||||
{
|
||||
ch1 = subtest_prompt("Press 'l' to repeat or enter to continue.\n"
|
||||
SUB_PROMPT);
|
||||
}
|
||||
|
||||
if (ch1 == 'x')
|
||||
{
|
||||
goto quick_exit;
|
||||
}
|
||||
}
|
||||
while (ch1 == 'l');
|
||||
|
||||
do
|
||||
{
|
||||
/* Read live data */
|
||||
|
||||
printf("Reading Live Data...\n");
|
||||
ret = lseek(fd, 0, SEEK_END);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
||||
ADXL372_XDATA_H, path, errcode);
|
||||
rc = RC_SEEK3FAIL;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
memset(bfr, 0xAA, sizeof(bfr));
|
||||
ret = read(fd, bfr, 6); /* read live accelerometer data */
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
printf(CRED "ERROR: Read operation failed from %s: %d" CRESET "\n",
|
||||
path, errcode);
|
||||
rc = RC_READ3FAIL;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
printf("ADXL372 = ( %6d, %6d, %6d))\n",
|
||||
pxyz->d[0], pxyz->d[1], pxyz->d[2]);
|
||||
printf("ADXL372 = ( 0x%04X, 0x%04X, 0x%04X)\n",
|
||||
pxyz->d[0], pxyz->d[1], pxyz->d[2]);
|
||||
printf("ADXL372 raw = ( 0x%02X%02X, 0x%02X%02X, 0x%02X%02X)\n",
|
||||
bfr[1], bfr[0], bfr[3], bfr[2], bfr[5], bfr[4]);
|
||||
|
||||
if (is_interactive)
|
||||
{
|
||||
ch1 = subtest_prompt("Press 'l' to repeat or enter to continue.\n"
|
||||
SUB_PROMPT);
|
||||
}
|
||||
|
||||
if (ch1 == 'x')
|
||||
{
|
||||
goto quick_exit;
|
||||
}
|
||||
}
|
||||
while (ch1 == 'l');
|
||||
|
||||
error_exit:
|
||||
quick_exit:
|
||||
close(fd);
|
||||
if (rc == PASSED)
|
||||
{
|
||||
printf(CGREEN "ADXL372 accelerometer diagnostic completed successfully." CRESET "\n");
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: adxl372_test_main
|
||||
*
|
||||
* Description:
|
||||
* This program defaults to testing in interactive mode.
|
||||
* To run in batch mode use a first parameter of b. E.g. adxl372_test -b
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int adxl372_test_main(int argc, FAR char *argv[])
|
||||
#endif
|
||||
{
|
||||
int rc = 0;
|
||||
int step_rc = 0;
|
||||
uint8_t ch;
|
||||
int is_interactive = 1; /* Program defaults to interactive */
|
||||
int flag_present = 0; /* Default to no flag coded */
|
||||
uint32_t ui;
|
||||
struct stat sbuf;
|
||||
|
||||
/* The two arrays below must be synchronized */
|
||||
|
||||
test_ptr_t test_ptr_array[] = /* Array of test programs */
|
||||
{
|
||||
adxl372_test, /* ADXL372 accelerometer tests */
|
||||
};
|
||||
|
||||
FAR char *test_path[sizeof(test_ptr_array) / sizeof(test_ptr_array[0])];
|
||||
|
||||
if (argc < 1 || *argv[1] == 0 || *(argv[1] + 1) == 0)
|
||||
{
|
||||
goto print_help;
|
||||
}
|
||||
|
||||
/* We have at least 1 parameters, and the first parameter has at least two characters. */
|
||||
|
||||
if (*argv[1] == '-')
|
||||
{
|
||||
flag_present = 1;
|
||||
if (*(argv[1]+1) == 'b')
|
||||
{
|
||||
is_interactive = 0;
|
||||
}
|
||||
else if (*(argv[1]+1) == 'i')
|
||||
{
|
||||
is_interactive = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto print_help;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag_present && argc < 2)
|
||||
{
|
||||
goto print_help;
|
||||
}
|
||||
|
||||
test_path[0] = argv[1 + flag_present];
|
||||
|
||||
printf("path=%s\n", test_path[0]);
|
||||
|
||||
if (stat(test_path[0], &sbuf))
|
||||
{
|
||||
printf(CRED "Error: Accelerometer path not found. Path=%s" CRESET "\n",
|
||||
test_path[0]);
|
||||
rc = RC_INVALPATH;
|
||||
}
|
||||
|
||||
if (rc)
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (is_interactive)
|
||||
{
|
||||
printf("LSM330 diagnostic started in interactive mode... \n");
|
||||
ch = 0;
|
||||
while (ch != 'x')
|
||||
{
|
||||
printf("Enter test section...\n");
|
||||
printf(" 1 = SPI ADXL Tests.\n");
|
||||
printf(" i = Toggle interactive mode.\n");
|
||||
printf(" x = Exit. (at anytime).\n");
|
||||
printf("stst> ");
|
||||
fflush(stdout);
|
||||
|
||||
ch = getchar();
|
||||
if (ch < 1)
|
||||
{
|
||||
ch = '!';
|
||||
}
|
||||
else if ((ch < 0x20 || ch > 0x7e) && ch != '\r')
|
||||
{
|
||||
ch = '*';
|
||||
}
|
||||
|
||||
if (ch != '\r')
|
||||
{
|
||||
putchar(ch);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
if (ch == 'x')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ui = ch - 0x31; /* make index zero origin */
|
||||
|
||||
if (ch == 'i')
|
||||
{
|
||||
if (is_interactive == 0)
|
||||
{
|
||||
is_interactive = 1;
|
||||
printf("Set to interactive mode.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
is_interactive = 0;
|
||||
printf("Set to batch mode.\n");
|
||||
}
|
||||
}
|
||||
else if (ui >= (sizeof(test_ptr_array) / sizeof(test_ptr_array[0])))
|
||||
{
|
||||
printf("Huh?\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (test_ptr_array[ui] == 0)
|
||||
{
|
||||
printf ("Test not supported yet.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
test_ptr_array[ui](is_interactive, test_path[ui]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* not interactive mode */
|
||||
{
|
||||
printf("ADXL372 sensor diagnostic started in batch mode...\n");
|
||||
|
||||
for (ui = 0; ui < (sizeof(test_ptr_array) / sizeof(test_ptr_array[0])); ui++)
|
||||
{
|
||||
step_rc = 0;
|
||||
if (test_ptr_array[ui] != 0)
|
||||
{
|
||||
/* call the next test routine */
|
||||
|
||||
step_rc = test_ptr_array[ui](is_interactive, test_path[ui]);
|
||||
}
|
||||
|
||||
if (step_rc != 0 && rc == 0)
|
||||
{
|
||||
rc = step_rc;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
printf("ADXL372 sensor diagnostic completed.\n");
|
||||
return rc;
|
||||
|
||||
print_help:
|
||||
printf("Usage...\n");
|
||||
printf("adxl372_test [-b | -i] <dev_path>\n");
|
||||
printf(" -b = batch mode execution\n");
|
||||
printf(" -i = interactive mode execution (default)\n");
|
||||
printf(" <dev_path> = Device path and name for the ADXL372 accelerometer\n");
|
||||
printf(" Example:\n");
|
||||
printf(" adxl372_test -b /dev/adxl372_0\n");
|
||||
return RC_INVALPARM;
|
||||
}
|
11
examples/ajoystick/.gitignore
vendored
Normal file
11
examples/ajoystick/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.context
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
23
examples/ajoystick/Kconfig
Normal file
23
examples/ajoystick/Kconfig
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_AJOYSTICK
|
||||
tristate "Analog joystick example"
|
||||
default n
|
||||
depends on AJOYSTICK && !DISABLE_SIGNALS
|
||||
---help---
|
||||
Enable the analog joystick example
|
||||
|
||||
if EXAMPLES_AJOYSTICK
|
||||
|
||||
config EXAMPLES_AJOYSTICK_DEVNAME
|
||||
string "Joystick device name"
|
||||
default "/dev/ajoy0"
|
||||
|
||||
config EXAMPLES_AJOYSTICK_SIGNO
|
||||
int "Joystick signal"
|
||||
default 13
|
||||
|
||||
endif
|
39
examples/ajoystick/Make.defs
Normal file
39
examples/ajoystick/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/ajoystick/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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_AJOYSTICK),)
|
||||
CONFIGURED_APPS += examples/ajoystick
|
||||
endif
|
56
examples/ajoystick/Makefile
Normal file
56
examples/ajoystick/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
############################################################################
|
||||
# apps/examples/ajoystick/Makefile
|
||||
#
|
||||
# Copyright (C) 2014 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! Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = ajoy_main.c
|
||||
|
||||
CONFIG_AJOY_PROGNAME ?= ajoy$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_AJOY_PROGNAME)
|
||||
|
||||
# Buttons built-in application info
|
||||
|
||||
APPNAME = ajoy
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_AJOYSTICK
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
|
467
examples/ajoystick/ajoy_main.c
Normal file
467
examples/ajoystick/ajoy_main.c
Normal file
@ -0,0 +1,467 @@
|
||||
/****************************************************************************
|
||||
* examplex/ajoystick/ajoy_main.c
|
||||
*
|
||||
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <fixedmath.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/input/ajoystick.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_AJOYSTICK
|
||||
# error "CONFIG_AJOYSTICK is not defined in the configuration"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_AJOYSTICK_DEVNAME
|
||||
# define CONFIG_EXAMPLES_AJOYSTICK_DEVNAME "/dev/ajoy0"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_AJOYSTICK_SIGNO
|
||||
# define CONFIG_EXAMPLES_AJOYSTICK_SIGNO 13
|
||||
#endif
|
||||
|
||||
#define FULL_RANGE 16
|
||||
|
||||
/* Helpers ******************************************************************/
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) (a < b ? a : b)
|
||||
#endif
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) (a > b ? a : b)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void show_buttons(ajoy_buttonset_t oldset, ajoy_buttonset_t newset);
|
||||
static void show_joystick(FAR const struct ajoy_sample_s *sample);
|
||||
static int ajoy_wait(int fd, FAR const struct timespec *timeout);
|
||||
static int ajoy_read(int fd, FAR struct ajoy_sample_s *sample);
|
||||
static int ajoy_calibrate(int fd);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
/* The set of supported joystick buttons */
|
||||
|
||||
static ajoy_buttonset_t g_ajoysupported;
|
||||
|
||||
/* Last sampled button set */
|
||||
|
||||
static ajoy_buttonset_t g_ajoylast;
|
||||
|
||||
/* Calibration data */
|
||||
|
||||
static bool g_calibrated;
|
||||
static bool g_lispositive;
|
||||
static bool g_fispositive;
|
||||
static int16_t g_xcenter;
|
||||
static int16_t g_ycenter;
|
||||
static b16_t g_xlslope;
|
||||
static b16_t g_xrslope;
|
||||
static b16_t g_yfslope;
|
||||
static b16_t g_ybslope;
|
||||
|
||||
/* Joystick button names */
|
||||
|
||||
static const char *g_ajoynames[AJOY_NBUTTONS] =
|
||||
{
|
||||
"SELECT", "FIRE", "JUMP", "BUTTON 4",
|
||||
"BUTTON 5", "BUTTON 6", "BUTTON 7", "BUTTON 8",
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void show_buttons(ajoy_buttonset_t oldset, ajoy_buttonset_t newset)
|
||||
{
|
||||
ajoy_buttonset_t chgset = oldset ^ newset;
|
||||
int i;
|
||||
|
||||
if (chgset != 0)
|
||||
{
|
||||
/* Show each button state change */
|
||||
|
||||
for (i = 0; i <= AJOY_NBUTTONS; i++)
|
||||
{
|
||||
ajoy_buttonset_t mask = (1 << i);
|
||||
if ((chgset & mask) != 0)
|
||||
{
|
||||
FAR const char *state;
|
||||
|
||||
/* Get the button state */
|
||||
|
||||
if ((newset & mask) != 0)
|
||||
{
|
||||
state = "selected";
|
||||
}
|
||||
else
|
||||
{
|
||||
state = "released";
|
||||
}
|
||||
|
||||
printf(" %-6s: %s\n", g_ajoynames[i], state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void show_joystick(FAR const struct ajoy_sample_s *sample)
|
||||
{
|
||||
printf(" RAW: X=%d Y=%d\n", sample->as_x, sample->as_y);
|
||||
if (g_calibrated)
|
||||
{
|
||||
int tmp;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
tmp = sample->as_x - g_xcenter;
|
||||
if ((g_lispositive && tmp >= 0) ||
|
||||
(!g_lispositive && tmp < 0))
|
||||
{
|
||||
x = tmp * g_xlslope;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = tmp * g_xrslope;
|
||||
}
|
||||
|
||||
tmp = sample->as_y - g_ycenter;
|
||||
if ((g_fispositive && tmp >= 0) ||
|
||||
(!g_fispositive && tmp < 0))
|
||||
{
|
||||
y = tmp * g_yfslope;
|
||||
}
|
||||
else
|
||||
{
|
||||
y = tmp * g_ybslope;
|
||||
}
|
||||
|
||||
printf(" Calibrated: X=%d Y=%d\n", x, y);
|
||||
}
|
||||
}
|
||||
|
||||
static int ajoy_wait(int fd, FAR const struct timespec *timeout)
|
||||
{
|
||||
sigset_t set;
|
||||
struct siginfo value;
|
||||
ajoy_buttonset_t newset;
|
||||
int ret;
|
||||
|
||||
/* Wait for a signal */
|
||||
|
||||
(void)sigemptyset(&set);
|
||||
(void)sigaddset(&set, CONFIG_EXAMPLES_AJOYSTICK_SIGNO);
|
||||
ret = sigtimedwait(&set, &value, timeout);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
|
||||
if (!timeout || errcode != EAGAIN)
|
||||
{
|
||||
fprintf(stderr, "ERROR: sigtimedwait() failed: %d\n", errcode);
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
/* Timeout is not an error */
|
||||
|
||||
printf("Timeout!\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Show the set of joystick buttons accompanying the signal */
|
||||
|
||||
printf("Signalled button set\n");
|
||||
newset = (ajoy_buttonset_t)value.si_value.sival_int;
|
||||
show_buttons(g_ajoylast, newset);
|
||||
g_ajoylast = newset;
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int ajoy_read(int fd, FAR struct ajoy_sample_s *sample)
|
||||
{
|
||||
ssize_t nread;
|
||||
|
||||
/* Read the joystack sample */
|
||||
|
||||
nread = read(fd, sample, sizeof(struct ajoy_sample_s));
|
||||
if (nread < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: read() failed: %d\n", errcode);
|
||||
return -errcode;
|
||||
}
|
||||
else if (nread != sizeof(struct ajoy_sample_s))
|
||||
{
|
||||
fprintf(stderr, "ERROR: read() unexpected size: %ld vs %d\n",
|
||||
(long)nread, sizeof(struct ajoy_sample_s));
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Show the joystick position and set buttons accompanying the signal */
|
||||
/* Show the set of joystick buttons that we just read */
|
||||
|
||||
printf("Read position and button set\n");
|
||||
show_joystick(sample);
|
||||
show_buttons(g_ajoylast, sample->as_buttons);
|
||||
g_ajoylast = sample->as_buttons;
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int ajoy_waitread(int fd, FAR const struct timespec *timeout,
|
||||
FAR struct ajoy_sample_s *sample)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Wait for a signal */
|
||||
|
||||
ret = ajoy_wait(fd, timeout);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ajoy_wait() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Read the joystick sample */
|
||||
|
||||
ret = ajoy_read(fd, sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ajoy_read() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static b16_t ajoy_slope(int16_t value, int32_t full_range)
|
||||
{
|
||||
return itob16(full_range) / (int32_t)value;
|
||||
}
|
||||
|
||||
static int ajoy_calibrate(int fd)
|
||||
{
|
||||
struct ajoy_sample_s sample;
|
||||
int ret;
|
||||
|
||||
printf("Calibrating the joystick...\n");
|
||||
|
||||
/* Get the center position */
|
||||
|
||||
printf("Center the joystick and press any button\n");
|
||||
ret = ajoy_waitread(fd, NULL, &sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ajoy_waitread() failed: %d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_xcenter = sample.as_x;
|
||||
g_ycenter = sample.as_y;
|
||||
|
||||
/* Get the left/right calibration data */
|
||||
|
||||
printf("Move the joystick to the far RIGHT and press any button\n");
|
||||
ret = ajoy_waitread(fd, NULL, &sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ajoy_waitread() failed: %d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_lispositive = (sample.as_x > g_xcenter);
|
||||
g_xlslope = ajoy_slope(sample.as_x - g_xcenter, FULL_RANGE);
|
||||
|
||||
printf("Move the joystick to the far LEFT and press any button\n");
|
||||
ret = ajoy_waitread(fd, NULL, &sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ajoy_waitread() failed: %d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_xrslope = ajoy_slope(sample.as_x - g_xcenter, -FULL_RANGE);
|
||||
|
||||
/* Get the forward/backward calibration data */
|
||||
|
||||
printf("Move the joystick to the far FORWARD and press any button\n");
|
||||
ret = ajoy_waitread(fd, NULL, &sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ajoy_waitread() failed: %d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_fispositive = (sample.as_y > g_ycenter);
|
||||
g_yfslope = ajoy_slope(sample.as_y - g_ycenter, FULL_RANGE);
|
||||
|
||||
printf("Move the joystick to the far BACKWARD and press any button\n");
|
||||
ret = ajoy_waitread(fd, NULL, &sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ajoy_waitread() failed: %d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_ybslope = ajoy_slope(sample.as_y - g_ycenter, -FULL_RANGE);
|
||||
|
||||
printf("Calibrated:\n");
|
||||
g_calibrated = true;
|
||||
|
||||
printf(" X: center=%d, R-slope=%08lx L-slope=%08lx\n",
|
||||
g_xcenter, g_xrslope, g_xlslope);
|
||||
printf(" Y: center=%d, F-slope=%08lx B-slope=%08lx\n",
|
||||
g_ycenter, g_yfslope, g_ybslope);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* ajoy_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int ajoy_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
struct timespec timeout;
|
||||
struct ajoy_notify_s notify;
|
||||
int fd;
|
||||
int tmp;
|
||||
int ret;
|
||||
int errcode = EXIT_FAILURE;
|
||||
|
||||
/* Reset some globals that might been been left in a bad state */
|
||||
|
||||
g_ajoylast = 0;
|
||||
|
||||
/* Open the ajoystick device */
|
||||
|
||||
fd = open(CONFIG_EXAMPLES_AJOYSTICK_DEVNAME, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to open %s: %d\n",
|
||||
CONFIG_EXAMPLES_AJOYSTICK_DEVNAME, errno);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Get the set of supported buttons */
|
||||
|
||||
ret = ioctl(fd, AJOYIOC_SUPPORTED, (unsigned long)((uintptr_t)&tmp));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ioctl(AJOYIOC_SUPPORTED) failed: %d\n", errno);
|
||||
goto errout_with_fd;
|
||||
}
|
||||
|
||||
g_ajoysupported = (ajoy_buttonset_t)tmp;
|
||||
printf("Supported joystick buttons:\n");
|
||||
show_buttons(0, g_ajoysupported);
|
||||
|
||||
/* Register to receive a signal on any change in the joystick buttons. */
|
||||
|
||||
notify.an_press = g_ajoysupported;
|
||||
notify.an_release = g_ajoysupported;
|
||||
notify.an_signo = CONFIG_EXAMPLES_AJOYSTICK_SIGNO;
|
||||
|
||||
ret = ioctl(fd, AJOYIOC_REGISTER, (unsigned long)((uintptr_t)¬ify));
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ioctl(AJOYIOC_REGISTER) failed: %d\n", errno);
|
||||
goto errout_with_fd;
|
||||
}
|
||||
|
||||
/* Calibrate the joystick */
|
||||
|
||||
ajoy_calibrate(fd);
|
||||
|
||||
/* Then loop, receiving signals indicating joystick events. If this is an
|
||||
* NSH builtin application, we will turn as soon as the SELECT button is
|
||||
* depressed.
|
||||
*/
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_nsec = 600*1000*1000;
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
while ((g_ajoylast & AJOY_BUTTON_SELECT_BIT) == 0)
|
||||
#else
|
||||
for (;;)
|
||||
#endif
|
||||
{
|
||||
struct ajoy_sample_s sample;
|
||||
|
||||
/* Wait for a signal and read the sample */
|
||||
|
||||
ret = ajoy_waitread(fd, &timeout, &sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ajoy_waitread() failed: %d\n", errno);
|
||||
goto errout_with_fd;
|
||||
}
|
||||
}
|
||||
|
||||
errcode = EXIT_SUCCESS;
|
||||
|
||||
errout_with_fd:
|
||||
close(fd);
|
||||
return errcode;
|
||||
}
|
11
examples/alarm/.gitignore
vendored
Normal file
11
examples/alarm/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
39
examples/alarm/Kconfig
Normal file
39
examples/alarm/Kconfig
Normal file
@ -0,0 +1,39 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_ALARM
|
||||
tristate "RTC alarm driver example"
|
||||
default n
|
||||
depends on RTC_DRIVER && RTC_ALARM
|
||||
---help---
|
||||
Enable the RTC driver alarm test
|
||||
|
||||
if EXAMPLES_ALARM
|
||||
|
||||
config EXAMPLES_ALARM_PROGNAME
|
||||
string "Program name"
|
||||
default "alarm"
|
||||
depends on BUILD_LOADABLE
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_ALARM_PRIORITY
|
||||
int "Alarm task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_ALARM_STACKSIZE
|
||||
int "Alarm stack size"
|
||||
default 2048
|
||||
|
||||
config EXAMPLES_ALARM_DEVPATH
|
||||
string "RTC device path"
|
||||
default "/dev/rtc0"
|
||||
|
||||
config EXAMPLES_ALARM_SIGNO
|
||||
int "Alarm signal"
|
||||
default 1
|
||||
|
||||
endif # EXAMPLES_ALARM
|
39
examples/alarm/Make.defs
Normal file
39
examples/alarm/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/alarm/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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_ALARM),)
|
||||
CONFIGURED_APPS += examples/alarm
|
||||
endif
|
58
examples/alarm/Makefile
Normal file
58
examples/alarm/Makefile
Normal file
@ -0,0 +1,58 @@
|
||||
############################################################################
|
||||
# apps/examples/alarm/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
|
||||
|
||||
# RTC driver alarm test built-in application info
|
||||
|
||||
CONFIG_EXAMPLES_ALARM_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_ALARM_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = alarm
|
||||
PRIORITY = $(CONFIG_EXAMPLES_ALARM_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_ALARM_STACKSIZE)
|
||||
|
||||
# RTC driver alarm test
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = alarm_main.c
|
||||
|
||||
CONFIG_EXAMPLES_ALARM_PROGNAME ?= alarm$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_ALARM_PROGNAME)
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_ALARM
|
||||
|
||||
include $(APPDIR)/Application.mk
|
424
examples/alarm/alarm_main.c
Normal file
424
examples/alarm/alarm_main.c
Normal file
@ -0,0 +1,424 @@
|
||||
/****************************************************************************
|
||||
* examples/alarm/alarm_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 <sched.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/timers/rtc.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static bool g_alarm_daemon_started;
|
||||
static pid_t g_alarm_daemon_pid;
|
||||
static bool g_alarm_received[CONFIG_RTC_NALARMS];
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: alarm_handler
|
||||
****************************************************************************/
|
||||
|
||||
static void alarm_handler(int signo, FAR siginfo_t *info, FAR void *ucontext)
|
||||
{
|
||||
int almndx = info->si_value.sival_int;
|
||||
if (almndx >= 0 && almndx < CONFIG_RTC_NALARMS)
|
||||
{
|
||||
g_alarm_received[almndx] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: alarm_daemon
|
||||
****************************************************************************/
|
||||
|
||||
static int alarm_daemon(int argc, FAR char *argv[])
|
||||
{
|
||||
struct sigaction act;
|
||||
sigset_t set;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Indicate that we are running */
|
||||
|
||||
g_alarm_daemon_started = true;
|
||||
printf("alarm_daemon: Running\n");
|
||||
|
||||
/* Make sure that the alarm signal is unmasked */
|
||||
|
||||
(void)sigemptyset(&set);
|
||||
(void)sigaddset(&set, CONFIG_EXAMPLES_ALARM_SIGNO);
|
||||
ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: sigprocmask failed: %d\n",
|
||||
errcode);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Register alarm signal handler */
|
||||
|
||||
act.sa_sigaction = alarm_handler;
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
|
||||
(void)sigfillset(&act.sa_mask);
|
||||
(void)sigdelset(&act.sa_mask, CONFIG_EXAMPLES_ALARM_SIGNO);
|
||||
|
||||
ret = sigaction(CONFIG_EXAMPLES_ALARM_SIGNO, &act, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: sigaction failed: %d\n",
|
||||
errcode);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Now loop forever, waiting for alarm signals */
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
/* Check if any alarms fired.
|
||||
*
|
||||
* NOTE that there are race conditions here... if we missing an alarm,
|
||||
* we will just report it a half second late.
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_RTC_NALARMS; i++)
|
||||
{
|
||||
if (g_alarm_received[i])
|
||||
{
|
||||
printf("alarm_demon: alarm %d received\n", i) ;
|
||||
g_alarm_received[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now wait a little while and poll again. If a signal is received
|
||||
* this should cuase us to awken earlier.
|
||||
*/
|
||||
|
||||
usleep(500*1000L);
|
||||
}
|
||||
|
||||
errout:
|
||||
g_alarm_daemon_started = false;
|
||||
|
||||
printf("alarm_daemon: Terminating\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: start_daemon
|
||||
****************************************************************************/
|
||||
|
||||
static int start_daemon(void)
|
||||
{
|
||||
if (!g_alarm_daemon_started)
|
||||
{
|
||||
g_alarm_daemon_pid =
|
||||
task_create("alarm_daemon", CONFIG_EXAMPLES_ALARM_PRIORITY,
|
||||
CONFIG_EXAMPLES_ALARM_STACKSIZE, alarm_daemon,
|
||||
NULL);
|
||||
if (g_alarm_daemon_pid < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to start alarm_daemon: %d\n",
|
||||
errcode);
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
printf("alarm_daemon started\n");
|
||||
usleep(500*1000L);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: show_usage
|
||||
****************************************************************************/
|
||||
|
||||
static void show_usage(FAR const char *progname)
|
||||
{
|
||||
fprintf(stderr, "USAGE:\n");
|
||||
fprintf(stderr, "\t%s [-a <alarmid>] [-cr] [<seconds>]\n", progname);
|
||||
fprintf(stderr, "Where:\n");
|
||||
fprintf(stderr, "\t-a <alarmid>\n");
|
||||
fprintf(stderr, "\t\t<alarmid> selects the alarm: 0..%d (default: 0)\n",
|
||||
CONFIG_RTC_NALARMS - 1);
|
||||
fprintf(stderr, "\t-c\tCancel previously set alarm\n");
|
||||
fprintf(stderr, "\t-r\tRead previously set alarm\n");
|
||||
fprintf(stderr, "\t<seconds>\n");
|
||||
fprintf(stderr, "\t\tThe number of seconds until the alarm expires.\n");
|
||||
fprintf(stderr, "\t\t(only if no -c or -r option given.)\n");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* alarm_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int alarm_main(int argc, FAR char *argv[])
|
||||
#endif
|
||||
{
|
||||
unsigned long seconds = 0;
|
||||
bool badarg = false;
|
||||
bool readmode = false;
|
||||
bool cancelmode = false;
|
||||
bool setmode;
|
||||
int opt;
|
||||
int alarmid = 0;
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
/* Make sure that the alarm daemon is running */
|
||||
|
||||
ret = start_daemon();
|
||||
if (ret < 0)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Parse commandline parameters. NOTE: getopt() is not thread safe nor re-entrant.
|
||||
* To keep its state proper for the next usage, it is necessary to parse to
|
||||
* the end of the line even if an error occurs. If an error occurs, this
|
||||
* logic just sets 'badarg' and continues.
|
||||
*/
|
||||
|
||||
while ((opt = getopt(argc, argv, ":a:cr")) != ERROR)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'a': /* -a: Select alarm id */
|
||||
alarmid = strtol(optarg, NULL, 0);
|
||||
if (alarmid < 0 || alarmid >= CONFIG_RTC_NALARMS)
|
||||
{
|
||||
badarg = true;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
cancelmode = true;
|
||||
break;
|
||||
case 'r':
|
||||
readmode = true;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "<unknown parameter '-%c'>\n\n", opt);
|
||||
/* fall through */
|
||||
case '?':
|
||||
case ':':
|
||||
badarg = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Both -r and -c can be given at the same time, setting is exclusive. */
|
||||
|
||||
setmode = !readmode && !cancelmode;
|
||||
|
||||
if (setmode)
|
||||
{
|
||||
if (optind >= argc)
|
||||
{
|
||||
badarg = true;
|
||||
}
|
||||
}
|
||||
else if (optind < argc)
|
||||
{
|
||||
badarg = true;
|
||||
}
|
||||
|
||||
if (badarg)
|
||||
{
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (setmode)
|
||||
{
|
||||
/* Get the number of seconds until the alarm expiration */
|
||||
|
||||
seconds = strtoul(argv[optind], NULL, 10);
|
||||
if (seconds < 1)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Invalid number of seconds: %lu\n", seconds);
|
||||
show_usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Open the RTC driver */
|
||||
|
||||
printf("Opening %s\n", CONFIG_EXAMPLES_ALARM_DEVPATH);
|
||||
|
||||
fd = open(CONFIG_EXAMPLES_ALARM_DEVPATH, O_WRONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
fprintf(stderr, "ERROR: Failed to open %s: %d\n",
|
||||
CONFIG_EXAMPLES_ALARM_DEVPATH, errcode);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (readmode)
|
||||
{
|
||||
struct rtc_rdalarm_s rd = { 0 };
|
||||
long timeleft;
|
||||
time_t now;
|
||||
|
||||
rd.id = alarmid;
|
||||
time(&now);
|
||||
|
||||
ret = ioctl(fd, RTC_RD_ALARM, (unsigned long)((uintptr_t)&rd));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
|
||||
fprintf(stderr, "ERROR: RTC_RD_ALARM ioctl failed: %d\n",
|
||||
errcode);
|
||||
|
||||
(void)close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Some of the NuttX RTC implementations do not support alarms
|
||||
* longer than one month. There RTC_RD_ALARM can return partial
|
||||
* calendar values without month and year fields.
|
||||
* TODO: fix this in lower layers?
|
||||
*/
|
||||
|
||||
if (rd.time.tm_year > 0)
|
||||
{
|
||||
/* Normal sane case, assuming we did not actually request an
|
||||
* alarm expiring in year 1900.
|
||||
*/
|
||||
|
||||
timeleft = mktime((struct tm *)&rd.time) - now;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct tm now_tm;
|
||||
|
||||
/* Periodic extend "partial" alarms by "unfolding" months,
|
||||
* until we get alarm that is in future. Note that mktime()
|
||||
* normalizes fields that are out of their valid values,
|
||||
* so we don't have to handle carry to tm_year by ourselves.
|
||||
*/
|
||||
|
||||
gmtime_r(&now, &now_tm);
|
||||
rd.time.tm_mon = now_tm.tm_mon;
|
||||
rd.time.tm_year = now_tm.tm_year;
|
||||
|
||||
do {
|
||||
timeleft = mktime((struct tm *)&rd.time) - now;
|
||||
if (timeleft < 0)
|
||||
{
|
||||
rd.time.tm_mon++;
|
||||
}
|
||||
} while (timeleft < 0);
|
||||
}
|
||||
|
||||
printf("Alarm %d is %s with %ld seconds to expiration\n", alarmid,
|
||||
rd.active ? "active" : "inactive", timeleft);
|
||||
}
|
||||
|
||||
if (cancelmode)
|
||||
{
|
||||
ret = ioctl(fd, RTC_CANCEL_ALARM, (unsigned long)alarmid);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
|
||||
fprintf(stderr, "ERROR: RTC_CANCEL_ALARM ioctl failed: %d\n",
|
||||
errcode);
|
||||
|
||||
(void)close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Alarm %d has been canceled\n", alarmid);
|
||||
}
|
||||
|
||||
if (setmode)
|
||||
{
|
||||
struct rtc_setrelative_s setrel;
|
||||
|
||||
/* Set the alarm */
|
||||
|
||||
setrel.id = alarmid;
|
||||
setrel.signo = CONFIG_EXAMPLES_ALARM_SIGNO;
|
||||
setrel.pid = g_alarm_daemon_pid;
|
||||
setrel.reltime = (time_t)seconds;
|
||||
|
||||
setrel.sigvalue.sival_int = alarmid;
|
||||
|
||||
ret = ioctl(fd, RTC_SET_RELATIVE, (unsigned long)((uintptr_t)&setrel));
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
|
||||
fprintf(stderr, "ERROR: RTC_SET_RELATIVE ioctl failed: %d\n",
|
||||
errcode);
|
||||
|
||||
(void)close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Alarm %d set in %lu seconds\n", alarmid, seconds);
|
||||
}
|
||||
|
||||
(void)close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
11
examples/apa102/.gitignore
vendored
Normal file
11
examples/apa102/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
22
examples/apa102/Kconfig
Normal file
22
examples/apa102/Kconfig
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_APA102
|
||||
tristate "APA102 LED Strip example"
|
||||
default n
|
||||
---help---
|
||||
Enable the APA102 example
|
||||
|
||||
if EXAMPLES_APA102
|
||||
|
||||
config EXAMPLES_APA102_PROGNAME
|
||||
string "Program name"
|
||||
default "apa102"
|
||||
depends on BUILD_LOADABLE
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
endif
|
39
examples/apa102/Make.defs
Normal file
39
examples/apa102/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/apa102/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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_APA102),)
|
||||
CONFIGURED_APPS += examples/apa102
|
||||
endif
|
55
examples/apa102/Makefile
Normal file
55
examples/apa102/Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
############################################################################
|
||||
# apps/examples/apa102/Makefile
|
||||
#
|
||||
# Copyright (C) 2017 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
|
||||
|
||||
# APA102 built-in application info
|
||||
|
||||
APPNAME = apa102
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
# APA102 Test
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = apa102_main.c
|
||||
|
||||
CONFIG_EXAMPLES_APA102_PROGNAME ?= apa102$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_APA102_PROGNAME)
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_APA102
|
||||
|
||||
include $(APPDIR)/Application.mk
|
196
examples/apa102/apa102_main.c
Normal file
196
examples/apa102/apa102_main.c
Normal file
@ -0,0 +1,196 @@
|
||||
/****************************************************************************
|
||||
* examples/apa102/apa102_main.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Copyright (c) 2015-2017 Pololu Corporation.
|
||||
* 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
|
||||
* 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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/leds/apa102.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CONFIG_EXAMPLES_APA102_DEVNAME "/dev/leddrv0"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#define NUM_LEDS 30
|
||||
#define US_DELAY 1000
|
||||
|
||||
struct apa102_ledstrip_s ledstrip[NUM_LEDS];
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hsvtorgb
|
||||
*
|
||||
* Description:
|
||||
* Converts a color from HSV to RGB.
|
||||
*
|
||||
* Note: This function is based on Pololu example:
|
||||
* https://github.com/pololu/apa102-arduino/blob/master/examples/Rainbow/Rainbow.ino
|
||||
*
|
||||
* Input Parameters:
|
||||
* h is hue, as a number between 0 and 360.
|
||||
* s is the saturation, as a number between 0 and 255.
|
||||
* v is the value, as a number between 0 and 255.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static struct apa102_ledstrip_s hsvtorgb(uint16_t h, uint8_t s, uint8_t v)
|
||||
{
|
||||
struct apa102_ledstrip_s led;
|
||||
uint8_t f = (h % 60) * 255 / 60;
|
||||
uint8_t p = (255 - s) * (uint16_t)v / 255;
|
||||
uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255;
|
||||
uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255;
|
||||
uint8_t r = 0;
|
||||
uint8_t g = 0;
|
||||
uint8_t b = 0;
|
||||
|
||||
switch((h / 60) % 6)
|
||||
{
|
||||
case 0:
|
||||
r = v;
|
||||
g = t;
|
||||
b = p;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
r = q;
|
||||
g = v;
|
||||
b = p;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
r = p;
|
||||
g = v;
|
||||
b = t;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
r = p;
|
||||
g = q;
|
||||
b = v;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
r = t;
|
||||
g = p;
|
||||
b = v;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
r = v;
|
||||
g = p;
|
||||
b = q;
|
||||
break;
|
||||
}
|
||||
|
||||
led.red = r;
|
||||
led.green = g;
|
||||
led.blue = b;
|
||||
led.bright = 0;
|
||||
|
||||
return led;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* apa102_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int apa102_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
int led;
|
||||
int miles = 10000;
|
||||
|
||||
fd = open(CONFIG_EXAMPLES_APA102_DEVNAME, O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to open %s: %d\n",
|
||||
CONFIG_EXAMPLES_APA102_DEVNAME, errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
/* Fill the LED Strip */
|
||||
|
||||
for (led = 0; led < NUM_LEDS; led++)
|
||||
{
|
||||
uint8_t p = miles - led * 8;
|
||||
ledstrip[led] = hsvtorgb((uint32_t)p * 359 / 256, 255, 255);
|
||||
}
|
||||
|
||||
/* Write the new colors in all the LEDs */
|
||||
|
||||
ret = write(fd, ledstrip, 4 * NUM_LEDS);
|
||||
if (ret < 0)
|
||||
{
|
||||
_err("ERROR: write LED Strip failed: %d\n", errno);
|
||||
}
|
||||
|
||||
usleep(US_DELAY);
|
||||
miles += (US_DELAY / 1000);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
11
examples/apds9960/.gitignore
vendored
Normal file
11
examples/apds9960/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
37
examples/apds9960/Kconfig
Normal file
37
examples/apds9960/Kconfig
Normal file
@ -0,0 +1,37 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_APDS9960
|
||||
tristate "APDS-9960 Test Application"
|
||||
default n
|
||||
depends on SENSORS_APDS9960
|
||||
---help---
|
||||
Enable the APDS-9960 test application.
|
||||
|
||||
if EXAMPLES_APDS9960
|
||||
|
||||
config EXAMPLES_APDS9960_PROGNAME
|
||||
string "APDS-9960 Test Program name"
|
||||
default "apds9960"
|
||||
depends on BUILD_LOADABLE
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_APDS9960_DEVNAME
|
||||
string "APDS-9960 device file name"
|
||||
default "/dev/gest0"
|
||||
---help---
|
||||
This is the name of device file name created by APDS9960 driver.
|
||||
|
||||
config EXAMPLES_APDS9960_PRIORITY
|
||||
int "APDS-9960 Test task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_APDS9960_STACKSIZE
|
||||
int "APDS-9960 Test stack size"
|
||||
default 2048
|
||||
|
||||
endif
|
39
examples/apds9960/Make.defs
Normal file
39
examples/apds9960/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/apds9960/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2017 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_APDS9960),)
|
||||
CONFIGURED_APPS += examples/apds9960
|
||||
endif
|
58
examples/apds9960/Makefile
Normal file
58
examples/apds9960/Makefile
Normal file
@ -0,0 +1,58 @@
|
||||
############################################################################
|
||||
# apps/examples/apds9960/Makefile
|
||||
#
|
||||
# Copyright (C) 2017 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_APDS9960_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_APDS9960_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = apds9960
|
||||
PRIORITY = $(CONFIG_EXAMPLES_APDS9960_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_APDS9960_STACKSIZE)
|
||||
|
||||
# Hello, World! Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = apds9960_main.c
|
||||
|
||||
CONFIG_EXAMPLES_APDS9960_PROGNAME ?= apds9960$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_APDS9960_PROGNAME)
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_APDS9960
|
||||
|
||||
include $(APPDIR)/Application.mk
|
120
examples/apds9960/apds9960_main.c
Normal file
120
examples/apds9960/apds9960_main.c
Normal file
@ -0,0 +1,120 @@
|
||||
/****************************************************************************
|
||||
* examples/apds9960/apds9960_main.c
|
||||
*
|
||||
* Copyright (C) 2017 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <nuttx/sensors/apds9960.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_APDS9960_DEVNAME
|
||||
# define CONFIG_EXAMPLES_APDS9960_DEVNAME "/dev/gest0"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* apds9960_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int apds9960_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
int fd;
|
||||
int nbytes;
|
||||
char gest;
|
||||
|
||||
fd = open(CONFIG_EXAMPLES_APDS9960_DEVNAME, O_RDONLY|O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
printf("ERROR: Failed to open %s: %d\n",
|
||||
CONFIG_EXAMPLES_APDS9960_DEVNAME, errcode);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
nbytes = read(fd, (void *)&gest, sizeof(gest));
|
||||
if (nbytes == 1)
|
||||
{
|
||||
switch (gest)
|
||||
{
|
||||
case DIR_LEFT:
|
||||
printf("LEFT\n");
|
||||
break;
|
||||
|
||||
case DIR_RIGHT:
|
||||
printf("RIGHT\n");
|
||||
break;
|
||||
|
||||
case DIR_UP:
|
||||
printf("UP\n");
|
||||
break;
|
||||
|
||||
case DIR_DOWN:
|
||||
printf("DOWN\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
/* Wait 10ms */
|
||||
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
return EXIT_FAILURE;
|
||||
}
|
13
examples/bastest/.gitignore
vendored
Normal file
13
examples/bastest/.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/romfs.img
|
||||
/romfs.h
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
39
examples/bastest/Kconfig
Normal file
39
examples/bastest/Kconfig
Normal file
@ -0,0 +1,39 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_BASTEST
|
||||
tristate "Setup Test Files for BAS"
|
||||
default n
|
||||
depends on FS_ROMFS && INTERPRETERS_BAS
|
||||
---help---
|
||||
Mount the ROMFS file system containing the BAS test files at
|
||||
/mnt/romfs. This selection depends both on INTERPRETER_BAS to provide
|
||||
the BASIC interpreter and and upon FS_ROMFS to provide support for the
|
||||
ROMFS file system.
|
||||
|
||||
The logic in certain tests (test33.bas and test36.bas will also fail
|
||||
if there is no writable file system mount at /tmp.
|
||||
|
||||
if EXAMPLES_BASTEST
|
||||
|
||||
config EXAMPLES_BASTEST_DEVMINOR
|
||||
int "ROMFS Minor Device Number"
|
||||
default 0
|
||||
---help---
|
||||
The minor device number of the ROMFS block. For example, the N in
|
||||
/dev/ramN. Used for registering the RAM block driver that will hold
|
||||
the ROMFS file system containing the BASIC files to be tested.
|
||||
Default: 0
|
||||
|
||||
config EXAMPLES_BASTEST_DEVPATH
|
||||
string "ROMFS Device Path"
|
||||
default "/dev/ram0"
|
||||
---help---
|
||||
The path to the ROMFS block driver device. This must match
|
||||
EXAMPLES_BASTEST_DEVMINOR. Used for registering the RAM block driver
|
||||
that will hold the ROMFS file system containing the BASIC files to
|
||||
be tested. Default: "/dev/ram0"
|
||||
|
||||
endif
|
39
examples/bastest/Make.defs
Normal file
39
examples/bastest/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/bastest/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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_BASTEST),)
|
||||
CONFIGURED_APPS += examples/bastest
|
||||
endif
|
75
examples/bastest/Makefile
Normal file
75
examples/bastest/Makefile
Normal file
@ -0,0 +1,75 @@
|
||||
############################################################################
|
||||
# apps/examples/bastest/Makefile
|
||||
#
|
||||
# Copyright (C) 2014 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
|
||||
|
||||
# BAS test volume mounter
|
||||
|
||||
APPNAME = bastest
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
# Hello, World! Example
|
||||
|
||||
MAINSRC = bastest_main.c
|
||||
|
||||
BASTEST_DIR = $(APPDIR)$(DELIM)examples$(DELIM)bastest
|
||||
TESTS_DIR = $(BASTEST_DIR)$(DELIM)tests
|
||||
ROMFS_IMG = romfs.img
|
||||
ROMFS_HDR = romfs.h
|
||||
|
||||
PROGNAME = bastest$(EXEEXT)
|
||||
|
||||
# Common build
|
||||
|
||||
# Create the romfs.h header file from the tests/ directory
|
||||
|
||||
$(ROMFS_IMG) :
|
||||
$(Q) genromfs -f $@ -d $(TESTS_DIR) -V "BASTEST"
|
||||
|
||||
$(ROMFS_HDR) : $(ROMFS_IMG)
|
||||
$(Q) (xxd -i $(ROMFS_IMG) | sed -e "s/^unsigned/static const unsigned/g" >$@)
|
||||
|
||||
# Add the BASTEST object to the archive
|
||||
|
||||
context:: $(ROMFS_HDR)
|
||||
|
||||
distclean::
|
||||
$(call DELFILE, $(ROMFS_HDR))
|
||||
$(call DELFILE, $(ROMFS_IMG))
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_BASTEST
|
||||
|
||||
include $(APPDIR)/Application.mk
|
1666
examples/bastest/README.txt
Normal file
1666
examples/bastest/README.txt
Normal file
File diff suppressed because it is too large
Load Diff
128
examples/bastest/bastest_main.c
Normal file
128
examples/bastest/bastest_main.c
Normal file
@ -0,0 +1,128 @@
|
||||
/****************************************************************************
|
||||
* examples/bastest/bastest_main.c
|
||||
*
|
||||
* Copyright (C) 2014 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/mount.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
|
||||
#include "romfs.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Check configuration. This is not all of the configuration settings that
|
||||
* are required -- only the more obvious.
|
||||
*/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS < 1
|
||||
# error "You must provide file descriptors via CONFIG_NFILE_DESCRIPTORS in your configuration file"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_FS_ROMFS
|
||||
# error "You must select CONFIG_FS_ROMFS in your configuration file"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DISABLE_MOUNTPOINT
|
||||
# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file"
|
||||
#endif
|
||||
|
||||
/* Describe the ROMFS file system */
|
||||
|
||||
#define SECTORSIZE 512
|
||||
#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
|
||||
#define MOUNTPT "/mnt/romfs"
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_BASTEST_DEVMINOR
|
||||
# define CONFIG_EXAMPLES_BASTEST_DEVMINOR 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_BASTEST_DEVPATH
|
||||
# define CONFIG_EXAMPLES_BASTEST_DEVPATH "/dev/ram0"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* bastest_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int bastest_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Create a ROM disk for the ROMFS filesystem */
|
||||
|
||||
printf("Registering romdisk at /dev/ram%d\n", CONFIG_EXAMPLES_BASTEST_DEVMINOR);
|
||||
ret = romdisk_register(CONFIG_EXAMPLES_BASTEST_DEVMINOR, (FAR uint8_t *)romfs_img,
|
||||
NSECTORS(romfs_img_len), SECTORSIZE);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: romdisk_register failed: %d\n", ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Mount the file system */
|
||||
|
||||
printf("Mounting ROMFS filesystem at target=%s with source=%s\n",
|
||||
MOUNTPT, CONFIG_EXAMPLES_BASTEST_DEVPATH);
|
||||
|
||||
ret = mount(CONFIG_EXAMPLES_BASTEST_DEVPATH, MOUNTPT, "romfs", MS_RDONLY, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: mount(%s,%s,romfs) failed: %s\n",
|
||||
CONFIG_EXAMPLES_BASTEST_DEVPATH, MOUNTPT, errno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
10
examples/bastest/tests/test01.bas
Normal file
10
examples/bastest/tests/test01.bas
Normal file
@ -0,0 +1,10 @@
|
||||
10 a=1
|
||||
20 print a
|
||||
30 a$="hello"
|
||||
40 print a$
|
||||
50 a=0.0002
|
||||
60 print a
|
||||
70 a=2.e-6
|
||||
80 print a
|
||||
90 a=.2e-6
|
||||
100 print a
|
8
examples/bastest/tests/test02.bas
Normal file
8
examples/bastest/tests/test02.bas
Normal file
@ -0,0 +1,8 @@
|
||||
10 dim a(1)
|
||||
20 a(0)=10
|
||||
30 a(1)=11
|
||||
40 a=12
|
||||
50 print a(0)
|
||||
60 print a(1)
|
||||
70 print a
|
||||
|
16
examples/bastest/tests/test03.bas
Normal file
16
examples/bastest/tests/test03.bas
Normal file
@ -0,0 +1,16 @@
|
||||
10 for i=0 to 10
|
||||
20 print i
|
||||
30 if i=5 then exit for
|
||||
40 next
|
||||
50 for i=0 to 0
|
||||
60 print i
|
||||
70 next I
|
||||
80 for i=1 to 0 step -1
|
||||
90 print i
|
||||
100 next
|
||||
110 for i=1 to 0
|
||||
120 print i
|
||||
130 next
|
||||
140 for i$="" to "aaaaaaaaaa" step "a"
|
||||
150 print i$
|
||||
160 next
|
6
examples/bastest/tests/test04.bas
Normal file
6
examples/bastest/tests/test04.bas
Normal file
@ -0,0 +1,6 @@
|
||||
10 a=1
|
||||
20 repeat
|
||||
30 print a
|
||||
40 a=a+1
|
||||
50 until a=10
|
||||
|
8
examples/bastest/tests/test05.bas
Normal file
8
examples/bastest/tests/test05.bas
Normal file
@ -0,0 +1,8 @@
|
||||
10 gosub 100
|
||||
20 gosub 100
|
||||
30 end
|
||||
100 gosub 200
|
||||
110 gosub 200
|
||||
120 return
|
||||
200 print "hello, world":return
|
||||
|
12
examples/bastest/tests/test06.bas
Normal file
12
examples/bastest/tests/test06.bas
Normal file
@ -0,0 +1,12 @@
|
||||
10 def fnloop
|
||||
20 if n=0.0 then
|
||||
30 r=0.0
|
||||
40 else
|
||||
50 print n
|
||||
60 n=n-1.0
|
||||
70 r=fnloop()
|
||||
80 end if
|
||||
90 =r
|
||||
100 n=10
|
||||
110 print fnloop
|
||||
|
5
examples/bastest/tests/test07.bas
Normal file
5
examples/bastest/tests/test07.bas
Normal file
@ -0,0 +1,5 @@
|
||||
10 def fna(x)
|
||||
20 if x=0 then r=1 else r=x*fna(x-1)
|
||||
30 =r
|
||||
40 print fna(7)
|
||||
|
10
examples/bastest/tests/test08.bas
Normal file
10
examples/bastest/tests/test08.bas
Normal file
@ -0,0 +1,10 @@
|
||||
10 data "a",b
|
||||
20 data "c","d
|
||||
40 read j$
|
||||
50 print "j=";j$
|
||||
60 restore 20
|
||||
70 for i=1 to 3
|
||||
80 read j$,k$
|
||||
90 print "j=";j$;" k=";k$
|
||||
100 next
|
||||
|
9
examples/bastest/tests/test09.bas
Normal file
9
examples/bastest/tests/test09.bas
Normal file
@ -0,0 +1,9 @@
|
||||
10 def fna(a)
|
||||
20 local b
|
||||
30 b=a+1
|
||||
40 =b
|
||||
60 b=3
|
||||
70 print b
|
||||
80 print fna(4)
|
||||
90 print b
|
||||
|
31
examples/bastest/tests/test10.bas
Normal file
31
examples/bastest/tests/test10.bas
Normal file
@ -0,0 +1,31 @@
|
||||
10 print using "!";"abcdef"
|
||||
20 print using "\ \";"abcdef"
|
||||
30 print using "###-";-1
|
||||
40 print using "###-";0
|
||||
50 print using "###-";1
|
||||
60 print using "###+";-1
|
||||
70 print using "###+";0
|
||||
80 print using "###+";1
|
||||
90 print using "#####,";1000
|
||||
100 print using "**#,##.##";1000.00
|
||||
110 print using "+##.##";1
|
||||
120 print using "+##.##";1.23400
|
||||
130 print using "+##.##";123.456
|
||||
140 print using "+##.";123.456
|
||||
150 print using "+##";123.456
|
||||
160 print using "abc def ###.## efg";1.3
|
||||
170 print using "###.##^^^^^";5
|
||||
180 print using "###.##^^^^";1000
|
||||
190 print using ".##^^^^";5.0
|
||||
200 print using "##^^^^";2.3e-9
|
||||
210 print using ".##^^^^";2.3e-9
|
||||
220 print using "#.#^^^^";2.3e-9
|
||||
230 print using ".####^^^^^";-011466
|
||||
240 print using "$*,***,***,***.**";3729825.24
|
||||
250 print using "$**********.**";3729825.24
|
||||
260 print using "$$###.##";456.78
|
||||
270 print using "a!b";"S"
|
||||
280 print using "a!b";"S","T"
|
||||
290 print using "a!b!c";"S"
|
||||
300 print using "a!b!c";"S","T"
|
||||
|
6
examples/bastest/tests/test11.bas
Normal file
6
examples/bastest/tests/test11.bas
Normal file
@ -0,0 +1,6 @@
|
||||
10 open "i",1,"test.bas"
|
||||
20 while not eof(1)
|
||||
30 line input #1,a$
|
||||
40 print a$
|
||||
50 wend
|
||||
|
10
examples/bastest/tests/test12.bas
Normal file
10
examples/bastest/tests/test12.bas
Normal file
@ -0,0 +1,10 @@
|
||||
10 on error print "global handler 1 caught error in line ";erl : resume 30
|
||||
20 print mid$("",-1)
|
||||
30 on error print "global handler 2 caught error in line ";erl : end
|
||||
40 def procx
|
||||
50 on error print "local handler caught error in line";erl : goto 70
|
||||
60 print 1/0
|
||||
70 end proc
|
||||
80 procx
|
||||
90 print 1 mod 0
|
||||
|
4
examples/bastest/tests/test13.bas
Normal file
4
examples/bastest/tests/test13.bas
Normal file
@ -0,0 +1,4 @@
|
||||
print "a"
|
||||
goto 20
|
||||
print "b"
|
||||
20 print "c"
|
22
examples/bastest/tests/test14.bas
Normal file
22
examples/bastest/tests/test14.bas
Normal file
@ -0,0 +1,22 @@
|
||||
10 for i=0 to 9
|
||||
20 for j=0 to 9
|
||||
30 print i,j
|
||||
40 select case i
|
||||
50 case 0
|
||||
60 print "i after case 0"
|
||||
70 case 1
|
||||
80 print "i after case 1"
|
||||
90 select case j
|
||||
100 case 0
|
||||
110 print "j after case 0"
|
||||
120 end select
|
||||
130 case 3 to 5,7
|
||||
140 print "i after case 3 to 5, 7"
|
||||
150 case is <9
|
||||
160 print "is after case is <9"
|
||||
170 case else
|
||||
180 print "i after case else"
|
||||
190 end select
|
||||
200 next
|
||||
210 next
|
||||
|
18
examples/bastest/tests/test15.bas
Normal file
18
examples/bastest/tests/test15.bas
Normal file
@ -0,0 +1,18 @@
|
||||
a$="a"
|
||||
open "r",1,"test.dat",128
|
||||
print "before field a$=";a$
|
||||
field #1,10 as a$
|
||||
field #1,5 as b$,5 as c$
|
||||
lset b$="hi"
|
||||
rset c$="ya"
|
||||
print "a$=";a$
|
||||
put #1
|
||||
close #1
|
||||
print "after close a$=";a$
|
||||
open "r",2,"test.dat",128
|
||||
field #2,10 as b$
|
||||
get #2
|
||||
print "after get b$=";b$
|
||||
close #2
|
||||
kill "test.dat"
|
||||
|
10
examples/bastest/tests/test16.bas
Normal file
10
examples/bastest/tests/test16.bas
Normal file
@ -0,0 +1,10 @@
|
||||
a=1 : b=2
|
||||
print "a=";a;"b=";b
|
||||
swap a,b
|
||||
print "a=";a;"b=";b
|
||||
dim a$(1,1),b$(1,1)
|
||||
a$(1,0)="a" : b$(0,1)="b"
|
||||
print "a$(1,0)=";a$(1,0);"b$(0,1)=";b$(0,1)
|
||||
swap a$(1,0),b$(0,1)
|
||||
print "a$(1,0)=";a$(1,0);"b$(0,1)=";b$(0,1)
|
||||
|
9
examples/bastest/tests/test17.bas
Normal file
9
examples/bastest/tests/test17.bas
Normal file
@ -0,0 +1,9 @@
|
||||
print "loop started"
|
||||
i=1
|
||||
do
|
||||
print "i is";i
|
||||
i=i+1
|
||||
if i>10 then exit do
|
||||
loop
|
||||
print "loop ended"
|
||||
|
13
examples/bastest/tests/test18.bas
Normal file
13
examples/bastest/tests/test18.bas
Normal file
@ -0,0 +1,13 @@
|
||||
print "loop started"
|
||||
x$=""
|
||||
do while len(x$)<3
|
||||
print "x$ is ";x$
|
||||
x$=x$+"a"
|
||||
y$=""
|
||||
do while len(y$)<2
|
||||
print "y$ is ";y$
|
||||
y$=y$+"b"
|
||||
loop
|
||||
loop
|
||||
print "loop ended"
|
||||
|
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