Add nuttx to the system framework, which is 10.1.0
This commit is contained in:
parent
06c351e27c
commit
804bd57aa0
|
@ -0,0 +1,235 @@
|
|||
############################################################################
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# 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
|
||||
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
BUILD_MODULE = y
|
||||
endif
|
||||
endif
|
||||
|
||||
# The GNU make CURDIR will always be a POSIX-like path with forward slashes
|
||||
# as path segment separators. If we know that this is a native build, then
|
||||
# we need to fix up the path so the DELIM will match the actual delimiter.
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
CWD = $(strip ${shell echo %CD% | cut -d: -f2})
|
||||
else
|
||||
CWD = $(CURDIR)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
|
||||
LDLIBS += "${shell cygpath -w $(BIN)}"
|
||||
else
|
||||
LDLIBS += $(BIN)
|
||||
endif
|
||||
|
||||
SUFFIX = $(subst $(DELIM),.,$(CWD))
|
||||
PROGNAME := $(shell echo $(PROGNAME))
|
||||
|
||||
# Object files
|
||||
|
||||
RASRCS = $(filter %.s,$(ASRCS))
|
||||
CASRCS = $(filter %.S,$(ASRCS))
|
||||
|
||||
RAOBJS = $(RASRCS:.s=$(SUFFIX)$(OBJEXT))
|
||||
CAOBJS = $(CASRCS:.S=$(SUFFIX)$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(SUFFIX)$(OBJEXT))
|
||||
CXXOBJS = $(CXXSRCS:$(CXXEXT)=$(SUFFIX)$(OBJEXT))
|
||||
|
||||
MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC))
|
||||
MAINCSRCS = $(filter %.c,$(MAINSRC))
|
||||
MAINCXXOBJ = $(MAINCXXSRCS:$(CXXEXT)=$(SUFFIX)$(OBJEXT))
|
||||
MAINCOBJ = $(MAINCSRCS:.c=$(SUFFIX)$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
|
||||
OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS)
|
||||
|
||||
ifneq ($(BUILD_MODULE),y)
|
||||
OBJS += $(MAINCOBJ) $(MAINCXXOBJ)
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path .
|
||||
DEPPATH += --obj-path .
|
||||
DEPPATH += --obj-suffix $(SUFFIX)$(OBJEXT)
|
||||
|
||||
VPATH += :.
|
||||
|
||||
# Targets follow
|
||||
|
||||
all:: $(OBJS)
|
||||
.PHONY: clean depend distclean
|
||||
.PRECIOUS: $(BIN)
|
||||
|
||||
define ELFASSEMBLE
|
||||
@echo "AS: $1"
|
||||
$(Q) $(CC) -c $(AELFFLAGS) $($(strip $1)_AELFFLAGS) $1 -o $2
|
||||
endef
|
||||
|
||||
define ELFCOMPILE
|
||||
@echo "CC: $1"
|
||||
$(Q) $(CC) -c $(CELFFLAGS) $($(strip $1)_CELFFLAGS) $1 -o $2
|
||||
endef
|
||||
|
||||
define ELFCOMPILEXX
|
||||
@echo "CXX: $1"
|
||||
$(Q) $(CXX) -c $(CXXELFFLAGS) $($(strip $1)_CXXELFFLAGS) $1 -o $2
|
||||
endef
|
||||
|
||||
define ELFLD
|
||||
@echo "LD: $2"
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDLIBS) -o $2
|
||||
endef
|
||||
|
||||
$(RAOBJS): %$(SUFFIX)$(OBJEXT): %.s
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(AELFFLAGS)), \
|
||||
$(call ELFASSEMBLE, $<, $@), $(call ASSEMBLE, $<, $@))
|
||||
|
||||
$(CAOBJS): %$(SUFFIX)$(OBJEXT): %.S
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(AELFFLAGS)), \
|
||||
$(call ELFASSEMBLE, $<, $@), $(call ASSEMBLE, $<, $@))
|
||||
|
||||
$(COBJS): %$(SUFFIX)$(OBJEXT): %.c
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
|
||||
$(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
|
||||
|
||||
$(CXXOBJS): %$(SUFFIX)$(OBJEXT): %$(CXXEXT)
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
|
||||
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
|
||||
|
||||
archive:
|
||||
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
|
||||
$(call ARCHIVE_ADD, "${shell cygpath -w $(BIN)}", $(OBJS))
|
||||
else
|
||||
$(call ARCHIVE_ADD, $(BIN), $(OBJS))
|
||||
endif
|
||||
|
||||
ifeq ($(BUILD_MODULE),y)
|
||||
|
||||
$(MAINCXXOBJ): %$(SUFFIX)$(OBJEXT): %$(CXXEXT)
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
|
||||
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
|
||||
|
||||
$(MAINCOBJ): %$(SUFFIX)$(OBJEXT): %.c
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
|
||||
$(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
|
||||
|
||||
PROGLIST := $(wordlist 1,$(words $(MAINCOBJ) $(MAINCXXOBJ)),$(PROGNAME))
|
||||
PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGLIST))
|
||||
PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ)
|
||||
|
||||
$(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ)
|
||||
$(Q) mkdir -p $(BINDIR)
|
||||
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
|
||||
$(call ELFLD,$(firstword $(PROGOBJ)),"${shell cygpath -w $(firstword $(PROGLIST))}")
|
||||
else
|
||||
$(call ELFLD,$(firstword $(PROGOBJ)),$(firstword $(PROGLIST)))
|
||||
endif
|
||||
$(Q) chmod +x $(firstword $(PROGLIST))
|
||||
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
|
||||
$(Q) $(STRIP) $(firstword $(PROGLIST))
|
||||
endif
|
||||
$(eval PROGLIST=$(filter-out $(firstword $(PROGLIST)),$(PROGLIST)))
|
||||
$(eval PROGOBJ=$(filter-out $(firstword $(PROGOBJ)),$(PROGOBJ)))
|
||||
|
||||
install:: $(PROGLIST)
|
||||
|
||||
else
|
||||
|
||||
MAINNAME := $(addsuffix _main,$(PROGNAME))
|
||||
|
||||
$(MAINCXXOBJ): %$(SUFFIX)$(OBJEXT): %$(CXXEXT)
|
||||
$(eval $<_CXXFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))})
|
||||
$(eval $<_CXXELFFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))})
|
||||
$(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME)))
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
|
||||
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
|
||||
|
||||
$(MAINCOBJ): %$(SUFFIX)$(OBJEXT): %.c
|
||||
$(eval $<_CFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))})
|
||||
$(eval $<_CELFFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))})
|
||||
$(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME)))
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
|
||||
$(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
|
||||
|
||||
install::
|
||||
|
||||
endif # BUILD_MODULE
|
||||
|
||||
context::
|
||||
|
||||
ifneq ($(PROGNAME),)
|
||||
|
||||
REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME)))
|
||||
APPLIST := $(PROGNAME)
|
||||
|
||||
$(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))))
|
||||
|
||||
register:: $(REGLIST)
|
||||
else
|
||||
register::
|
||||
endif
|
||||
|
||||
.depend: Makefile $(wildcard $(foreach SRC, $(SRCS), $(addsuffix /$(SRC), $(subst :, ,$(VPATH))))) $(DEPCONFIG)
|
||||
ifeq ($(filter %$(CXXEXT),$(SRCS)),)
|
||||
$(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(filter-out Makefile,$(filter-out $(DEPCONFIG),$^)) >Make.dep
|
||||
else
|
||||
$(Q) $(MKDEP) $(DEPPATH) "$(CXX)" -- $(CXXFLAGS) -- $(filter-out Makefile,$(filter-out $(DEPCONFIG),$^)) >Make.dep
|
||||
endif
|
||||
$(Q) touch $@
|
||||
|
||||
depend:: .depend
|
||||
|
||||
clean::
|
||||
$(call CLEAN)
|
||||
|
||||
distclean:: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
|
@ -0,0 +1,20 @@
|
|||
Apache NuttX is an effort undergoing incubation at The Apache Software Foundation (ASF),
|
||||
sponsored by the Apache Incubator. Incubation is required of all newly accepted projects
|
||||
until a further review indicates that the infrastructure, communications, and decision
|
||||
making process have stabilized in a manner consistent with other successful ASF projects.
|
||||
While incubation status is not necessarily a reflection of the completeness or stability
|
||||
of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
|
||||
|
||||
Some of the incubating project's releases may not be fully compliant with ASF policy. For
|
||||
example, releases may have incomplete or un-reviewed licensing conditions. What follows is
|
||||
a list of known issues the project is currently aware of (note that this list, by definition,
|
||||
is likely to be incomplete):
|
||||
|
||||
* Releases may have incomplete licensing conditions.
|
||||
* Some ASF files still have BSD headers. Most of the top contributors have signed an ICLA and
|
||||
we are working on updating the headers and getting approvals from other copyright holders.
|
||||
|
||||
If you are planning to incorporate this work into your product/project, please be aware that
|
||||
you will need to conduct a thorough licensing review to determine the overall implications of
|
||||
including this work. For the current status of this project through the Apache Incubator
|
||||
visit: https://incubator.apache.org/projects/nuttx.html
|
|
@ -0,0 +1,72 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# Sub-directories that have been built or configured.
|
||||
|
||||
SUBDIRS := $(dir $(wildcard *$(DELIM)Makefile))
|
||||
CONFIGSUBDIRS := $(filter-out $(dir $(wildcard *$(DELIM)Kconfig)),$(SUBDIRS))
|
||||
CLEANSUBDIRS += $(dir $(wildcard *$(DELIM).depend))
|
||||
CLEANSUBDIRS += $(dir $(wildcard *$(DELIM).kconfig))
|
||||
CLEANSUBDIRS := $(sort $(CLEANSUBDIRS))
|
||||
|
||||
all: nothing
|
||||
|
||||
.PHONY: nothing clean distclean
|
||||
|
||||
$(foreach SDIR, $(CONFIGSUBDIRS), $(eval $(call SDIR_template,$(SDIR),preconfig)))
|
||||
$(foreach SDIR, $(CLEANSUBDIRS), $(eval $(call SDIR_template,$(SDIR),clean)))
|
||||
$(foreach SDIR, $(CLEANSUBDIRS), $(eval $(call SDIR_template,$(SDIR),distclean)))
|
||||
|
||||
nothing:
|
||||
|
||||
install:
|
||||
|
||||
preconfig: $(foreach SDIR, $(CONFIGSUBDIRS), $(SDIR)_preconfig)
|
||||
ifneq ($(MENUDESC),)
|
||||
$(Q) $(MKKCONFIG) -m $(MENUDESC)
|
||||
$(Q) touch .kconfig
|
||||
endif
|
||||
|
||||
clean: $(foreach SDIR, $(CLEANSUBDIRS), $(SDIR)_clean)
|
||||
|
||||
distclean: $(foreach SDIR, $(CLEANSUBDIRS), $(SDIR)_distclean)
|
||||
ifneq ($(MENUDESC),)
|
||||
$(call DELFILE, Kconfig)
|
||||
$(call DELFILE, .kconfig)
|
||||
endif
|
||||
|
||||
-include Make.dep
|
|
@ -0,0 +1,489 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
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 Library: 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.
|
||||
|
||||
apps/testing/scanftest/scanftest_main.c
|
||||
=======================================
|
||||
Derives from the cc65 Project which has a zlib license:
|
||||
|
||||
Copyright (C) 2005-01-26, Greg King (https://github.com/cc65)
|
||||
|
||||
Original License:
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from
|
||||
the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software in
|
||||
a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not
|
||||
be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
apps/webserver
|
||||
==============
|
||||
|
||||
This has a license that is mostly compatible the NuttX 3-clause BSD license,
|
||||
but includes a fourth clause that required acknowledgement of Adam Dunkels
|
||||
if it is built into your product:
|
||||
|
||||
Copyright (c) 2001, Adam Dunkels.
|
||||
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 Adam Dunkels.
|
||||
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.
|
||||
|
||||
apps/examples/lvgldemo
|
||||
======================
|
||||
|
||||
Derives from the lvgl Project which has an MIT license:
|
||||
|
||||
Copyright (C) 2019 Gábor Kiss-Vámosi. All rights reserved.
|
||||
Author: Gábor Kiss-Vámosi <kisvegabor@gmail.com>
|
||||
|
||||
Released under the following BSD-compatible MIT license:
|
||||
|
||||
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.
|
||||
|
||||
canutils/candump
|
||||
================
|
||||
|
||||
Includes five dual licensed third part files from Volkswagon with
|
||||
licensing as follows (Copyright dates vary from file-to-file):
|
||||
|
||||
SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
|
||||
|
||||
Copyright (c) 2002-2009 Volkswagen Group Electronic Research
|
||||
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. Neither the name of Volkswagen nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
Alternatively, provided that this notice is retained in full, this
|
||||
software may be distributed under the terms of the GNU General
|
||||
Public License ("GPL") version 2, in which case the provisions of the
|
||||
GPL apply INSTEAD OF those given above.
|
||||
|
||||
The provided data structures and external interfaces from this code
|
||||
are not restricted to be used by modules with a GPL compatible license.
|
||||
|
||||
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.
|
||||
|
||||
Send feedback to <linux-can@vger.kernel.org>
|
|
@ -0,0 +1,120 @@
|
|||
############################################################################
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
TOPDIR ?= $(APPDIR)/import
|
||||
include $(TOPDIR)/Make.defs
|
||||
|
||||
# The GNU make CURDIR will always be a POSIX-like path with forward slashes
|
||||
# as path segment separators. This is fine for the above inclusions but
|
||||
# will cause problems later for the native build. If we know that this is
|
||||
# a native build, then we need to fix up the APPDIR path for subsequent
|
||||
# use
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
APPDIR := ${shell echo %CD%}
|
||||
endif
|
||||
|
||||
# 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 $(wildcard $(APPDIR)$(DELIM)*$(DELIM)Make.defs))
|
||||
BUILDIRS := $(filter-out $(APPDIR)$(DELIM)import$(DELIM),$(BUILDIRS))
|
||||
CONFIGDIRS := $(filter-out $(APPDIR)$(DELIM)builtin$(DELIM),$(BUILDIRS))
|
||||
CONFIGDIRS := $(filter-out $(dir $(wildcard $(APPDIR)$(DELIM)*$(DELIM)Kconfig)),$(CONFIGDIRS))
|
||||
CLEANDIRS := $(dir $(wildcard $(APPDIR)$(DELIM)*$(DELIM)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))))
|
||||
|
||||
# File extensions
|
||||
|
||||
CXXEXT ?= .cxx
|
||||
|
||||
# Library path
|
||||
|
||||
LIBPATH ?= $(TOPDIR)$(DELIM)staging
|
||||
|
||||
# The install path
|
||||
|
||||
BINDIR ?= $(APPDIR)$(DELIM)bin
|
||||
|
||||
# The final build target
|
||||
|
||||
BIN ?= $(APPDIR)$(DELIM)libapps$(LIBEXT)
|
||||
|
||||
# Tools
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
MKKCONFIG ?= $(APPDIR)$(DELIM)tools$(DELIM)mkkconfig.bat
|
||||
else
|
||||
MKKCONFIG ?= $(APPDIR)$(DELIM)tools$(DELIM)mkkconfig.sh
|
||||
endif
|
||||
|
||||
# Builtin Registration
|
||||
|
||||
BUILTIN_REGISTRY = $(APPDIR)$(DELIM)builtin$(DELIM)registry
|
||||
DEPCONFIG = $(TOPDIR)$(DELIM).config
|
||||
|
||||
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
|
||||
|
||||
# Standard include path
|
||||
|
||||
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(APPDIR)$(DELIM)include"}
|
||||
CXXFLAGS += ${shell $(INCDIR) "$(CC)" "$(APPDIR)$(DELIM)include"}
|
||||
|
||||
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
|
||||
NUTTXLIB ?= "${shell cygpath -w $(TOPDIR)$(DELIM)staging}"
|
||||
else
|
||||
NUTTXLIB ?= "$(TOPDIR)$(DELIM)staging"
|
||||
endif
|
|
@ -0,0 +1,222 @@
|
|||
############################################################################
|
||||
# apps/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
# Copyright (C) 2011-2014, 2018-2019 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
export APPDIR = $(CURDIR)
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# Symbol table for loadable apps.
|
||||
|
||||
SYMTABSRC = symtab_apps.c
|
||||
SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT))
|
||||
|
||||
# Build targets
|
||||
|
||||
# We first remove libapps.a before letting the other rules add objects to it
|
||||
# so that we ensure libapps.a does not contain objects from prior build
|
||||
|
||||
all:
|
||||
$(RM) $(BIN)
|
||||
$(MAKE) $(BIN)
|
||||
|
||||
.PHONY: import install dirlinks export .depdirs preconfig depend clean distclean
|
||||
.PHONY: context clean_context context_all register register_all
|
||||
.PRECIOUS: $(BIN)
|
||||
|
||||
$(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),register)))
|
||||
$(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)))
|
||||
|
||||
$(MKDEP): $(TOPDIR)/tools/mkdeps.c
|
||||
$(HOSTCC) $(HOSTINCLUDES) $(HOSTCFLAGS) $< -o $@
|
||||
|
||||
$(INCDIR): $(TOPDIR)/tools/incdir.c
|
||||
$(HOSTCC) $(HOSTINCLUDES) $(HOSTCFLAGS) $< -o $@
|
||||
|
||||
IMPORT_TOOLS = $(MKDEP) $(INCDIR)
|
||||
|
||||
# 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)
|
||||
|
||||
.import: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
|
||||
$(Q) $(MAKE) install
|
||||
|
||||
import: $(IMPORT_TOOLS)
|
||||
$(Q) $(MAKE) context TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
$(Q) $(MAKE) register TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
$(Q) $(MAKE) depend TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
$(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)
|
||||
$(Q) for app in ${CONFIGURED_APPS}; do \
|
||||
$(MAKE) -C "$${app}" archive ; \
|
||||
done
|
||||
|
||||
else
|
||||
|
||||
$(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
|
||||
$(Q) for app in ${CONFIGURED_APPS}; do \
|
||||
$(MAKE) -C "$${app}" archive ; \
|
||||
done
|
||||
$(Q) $(MAKE) install
|
||||
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) >$@.tmp
|
||||
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
|
||||
|
||||
$(SYMTABOBJ): %$(OBJEXT): %.c
|
||||
$(call COMPILE, -fno-lto $<, $@)
|
||||
|
||||
$(BIN): $(SYMTABOBJ)
|
||||
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
|
||||
$(call ARCHIVE_ADD, "${shell cygpath -w $(BIN)}", $^)
|
||||
else
|
||||
$(call ARCHIVE_ADD, $(BIN), $^)
|
||||
endif
|
||||
|
||||
endif # !CONFIG_BUILD_LOADABLE
|
||||
|
||||
install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install)
|
||||
|
||||
# Link nuttx
|
||||
|
||||
HEAD_OBJ += $(wildcard $(APPDIR)$(DELIM)import$(DELIM)startup$(DELIM)*$(OBJEXT))
|
||||
HEAD_OBJ += $(wildcard $(APPDIR)$(DELIM)builtin$(DELIM)*$(OBJEXT))
|
||||
|
||||
.import: $(BIN) install
|
||||
$(Q) echo "LD: nuttx"
|
||||
$(Q) $(LD) --entry=__start $(LDFLAGS) $(LDLIBPATH) $(EXTRA_LIBPATHS) \
|
||||
-L$(APPDIR)$(DELIM)import$(DELIM)scripts -T$(LDNAME) \
|
||||
-o nuttx$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) $(LDSTARTGROUP) \
|
||||
$(BIN) $(LDLIBS) $(EXTRA_LIBS) $(LDENDGROUP)
|
||||
ifeq ($(CONFIG_INTELHEX_BINARY),y)
|
||||
$(Q) echo "CP: nuttx.hex"
|
||||
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex nuttx$(EXEEXT) nuttx.hex
|
||||
endif
|
||||
ifeq ($(CONFIG_RAW_BINARY),y)
|
||||
$(Q) echo "CP: nuttx.bin"
|
||||
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary nuttx$(EXEEXT) nuttx.bin
|
||||
endif
|
||||
$(call POSTBUILD, $(APPDIR))
|
||||
|
||||
import: $(IMPORT_TOOLS)
|
||||
$(Q) $(MAKE) context TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
$(Q) $(MAKE) register TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
$(Q) $(MAKE) depend TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
$(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import"
|
||||
|
||||
endif # CONFIG_BUILD_KERNEL
|
||||
|
||||
dirlinks:
|
||||
$(Q) $(MAKE) -C platform dirlinks
|
||||
|
||||
context_all: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_context)
|
||||
register_all: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_register)
|
||||
|
||||
context:
|
||||
$(Q) $(MAKE) context_all
|
||||
$(Q) $(MAKE) register_all
|
||||
|
||||
Kconfig:
|
||||
$(foreach SDIR, $(CONFIGDIRS), $(call MAKE_template,$(SDIR),preconfig))
|
||||
$(Q) $(MKKCONFIG)
|
||||
|
||||
preconfig: Kconfig
|
||||
|
||||
export:
|
||||
ifneq ($(EXPORTDIR),)
|
||||
ifneq ($(BUILTIN_REGISTRY),)
|
||||
$(Q) mkdir -p "${EXPORTDIR}"/registry || exit 1; \
|
||||
for f in "${BUILTIN_REGISTRY}"/*.bdat "${BUILTIN_REGISTRY}"/*.pdat ; do \
|
||||
[ -f "$${f}" ] && cp -f "$${f}" "${EXPORTDIR}"/registry ; \
|
||||
done
|
||||
endif
|
||||
endif
|
||||
|
||||
.depdirs: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_depend)
|
||||
|
||||
.depend: Makefile .depdirs
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean_context:
|
||||
$(Q) $(MAKE) -C platform clean_context
|
||||
$(Q) $(MAKE) -C builtin clean_context
|
||||
|
||||
clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean)
|
||||
$(call DELFILE, $(SYMTABSRC))
|
||||
$(call DELFILE, $(SYMTABOBJ))
|
||||
$(call DELFILE, $(BIN))
|
||||
$(call DELFILE, Kconfig)
|
||||
$(call DELDIR, $(BINDIR))
|
||||
$(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, $(BINDIR))
|
||||
$(call CLEAN)
|
|
@ -0,0 +1,5 @@
|
|||
Apache NuttX
|
||||
Copyright 2020 The Apache Software Foundation
|
||||
|
||||
This product includes software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
|
@ -0,0 +1,239 @@
|
|||
# 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.z/` where `x.y.z` 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:
|
||||
|
||||
```conf
|
||||
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:
|
||||
|
||||
```conf
|
||||
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:
|
||||
|
||||
```conf
|
||||
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 += $(APPDIR)/examples/hello`
|
||||
like this:
|
||||
|
||||
```makefile
|
||||
ifneq ($(CONFIG_EXAMPLES_HELLO),)
|
||||
CONFIGURED_APPS += $(APPDIR)/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: progname
|
||||
|
||||
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:
|
||||
|
||||
```c
|
||||
main()
|
||||
```
|
||||
|
||||
4. Set the requirements in the file: `Makefile`, specially the lines:
|
||||
|
||||
```makefile
|
||||
PROGNAME = progname
|
||||
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 ..
|
||||
```
|
||||
|
||||
5. The `Make.defs` file should include a line like:
|
||||
|
||||
```makefile
|
||||
ifneq ($(CONFIG_PROGNAME),)
|
||||
CONFIGURED_APPS += progname
|
||||
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, libraries, startup objects, and other
|
||||
build components into a `.zip` file. You can move that `.zip` file into
|
||||
any build environment you want. You can 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/boards/README.txt` and
|
||||
`nuttx/Documentation/NuttXPortingGuide.html` (Online at
|
||||
https://bitbucket.org/nuttx/nuttx/src/master/Documentation/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
|
||||
symbolic 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 `Makefile`s for examples),
|
||||
and (2) a tiny `Make.defs` file that simply adds the custom build
|
||||
directories to the variable `CONFIGURED_APPS` like:
|
||||
|
||||
```makefile
|
||||
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
|
||||
`Makefile`s 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 `boards/MyBoard`.
|
||||
b) Add a symbolic link to `MyApplication` at `apps/external`.
|
||||
c) Configure NuttX, usually by:
|
||||
|
||||
```bash
|
||||
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.
|
|
@ -0,0 +1,39 @@
|
|||
############################################################################
|
||||
# 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 += $(APPDIR)/builtin
|
||||
endif
|
|
@ -0,0 +1,81 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# Source and object files
|
||||
|
||||
CSRCS = builtin_list.c exec_builtin.c
|
||||
|
||||
# Registry entry lists
|
||||
|
||||
PDATLIST = $(strip $(call RWILDCARD, registry, *.pdat))
|
||||
BDATLIST = $(strip $(call RWILDCARD, registry, *.bdat))
|
||||
|
||||
builtin_list.c: builtin_list.h builtin_proto.h
|
||||
|
||||
registry$(DELIM).updated:
|
||||
$(Q) touch registry$(DELIM).updated
|
||||
|
||||
builtin_list.h: registry$(DELIM).updated
|
||||
ifeq ($(BDATLIST),)
|
||||
$(call DELFILE, builtin_list.h)
|
||||
$(Q) touch builtin_list.h
|
||||
else
|
||||
$(call CATFILE, builtin_list.h, $(BDATLIST))
|
||||
endif
|
||||
|
||||
builtin_proto.h: registry$(DELIM).updated
|
||||
ifeq ($(PDATLIST),)
|
||||
$(call DELFILE, builtin_proto.h)
|
||||
$(Q) touch builtin_proto.h
|
||||
else
|
||||
$(call CATFILE, builtin_proto.h, $(PDATLIST))
|
||||
endif
|
||||
|
||||
depend:: builtin_list.h builtin_proto.h
|
||||
|
||||
clean::
|
||||
$(call DELFILE, builtin_list.h)
|
||||
$(call DELFILE, builtin_proto.h)
|
||||
|
||||
clean_context::
|
||||
$(call DELFILE, $(PDATLIST))
|
||||
$(call DELFILE, $(BDATLIST))
|
||||
|
||||
distclean:: clean_context clean
|
||||
$(call DELFILE, registry$(DELIM).updated)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,78 @@
|
|||
/****************************************************************************
|
||||
* apps/builtin/builtin_list.c
|
||||
*
|
||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
* Copyright (C) 2011, 2019 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/lib/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
|
||||
****************************************************************************/
|
|
@ -0,0 +1,228 @@
|
|||
/****************************************************************************
|
||||
* 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
|
||||
/* Load and execute the application. */
|
||||
|
||||
ret = posix_spawn(&pid, builtin->name, &file_actions, &attr,
|
||||
(argv) ? &argv[1] : (FAR char * const *)NULL, NULL);
|
||||
|
||||
if (ret != 0 && builtin->main != NULL)
|
||||
#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).
|
||||
*/
|
||||
|
||||
posix_spawn_file_actions_destroy(&file_actions);
|
||||
posix_spawnattr_destroy(&attr);
|
||||
return pid;
|
||||
|
||||
errout_with_actions:
|
||||
posix_spawn_file_actions_destroy(&file_actions);
|
||||
|
||||
errout_with_attrs:
|
||||
posix_spawnattr_destroy(&attr);
|
||||
|
||||
errout_with_errno:
|
||||
errno = ret;
|
||||
return ERROR;
|
||||
}
|
|
@ -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 $(APPDIR)/canutils/*/Make.defs)
|
|
@ -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
|
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config CANUTILS_CANDUMP
|
||||
tristate "SocketCAN candump tool"
|
||||
default n
|
||||
depends on NET_CAN
|
||||
select CANUTILS_LIBCANUTILS
|
||||
---help---
|
||||
Enable the SocketCAN candump tool ported from
|
||||
https://github.com/linux-can/can-utils
|
||||
|
||||
if CANUTILS_CANDUMP
|
||||
endif
|
|
@ -0,0 +1,24 @@
|
|||
############################################################################
|
||||
# apps/canutils/candump/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################/
|
||||
|
||||
ifneq ($(CONFIG_CANUTILS_CANDUMP),)
|
||||
CONFIGURED_APPS += $(APPDIR)/canutils/candump
|
||||
endif
|
|
@ -0,0 +1,34 @@
|
|||
############################################################################
|
||||
# apps/canutils/candump/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################/
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# SocketCAN userspace utilities and tools candump tool
|
||||
# https://github.com/linux-can/can-utils/blob/master/candump.c
|
||||
|
||||
PROGNAME = candump
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 3072
|
||||
MODULE = $(CONFIG_CANUTILS_CANDUMP)
|
||||
|
||||
CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/canutils/libcanutils}
|
||||
MAINSRC = candump.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,810 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
|
||||
/*
|
||||
* candump.c
|
||||
*
|
||||
* Copyright (c) 2002-2009 Volkswagen Group Electronic Research
|
||||
* 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. Neither the name of Volkswagen nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* Alternatively, provided that this notice is retained in full, this
|
||||
* software may be distributed under the terms of the GNU General
|
||||
* Public License ("GPL") version 2, in which case the provisions of the
|
||||
* GPL apply INSTEAD OF those given above.
|
||||
*
|
||||
* The provided data structures and external interfaces from this code
|
||||
* are not restricted to be used by modules with a GPL compatible license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Send feedback to <linux-can@vger.kernel.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <libgen.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/uio.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <nuttx/can.h>
|
||||
#include <netpacket/can.h>
|
||||
|
||||
#include "terminal.h"
|
||||
#include "lib.h"
|
||||
|
||||
/* for hardware timestamps - since Linux 2.6.30 */
|
||||
#ifndef SO_TIMESTAMPING
|
||||
#define SO_TIMESTAMPING 37
|
||||
#endif
|
||||
|
||||
/* from #include <linux/net_tstamp.h> - since Linux 2.6.30 */
|
||||
#define SOF_TIMESTAMPING_SOFTWARE (1<<4)
|
||||
#define SOF_TIMESTAMPING_RX_SOFTWARE (1<<3)
|
||||
#define SOF_TIMESTAMPING_RAW_HARDWARE (1<<6)
|
||||
|
||||
#define MAXSOCK 16 /* max. number of CAN interfaces given on the cmdline */
|
||||
#define MAXIFNAMES 30 /* size of receive name index to omit ioctls */
|
||||
#define MAXCOL 6 /* number of different colors for colorized output */
|
||||
#define ANYDEV "any" /* name of interface to receive from any CAN interface */
|
||||
#define ANL "\r\n" /* newline in ASC mode */
|
||||
|
||||
#define SILENT_INI 42 /* detect user setting on commandline */
|
||||
#define SILENT_OFF 0 /* no silent mode */
|
||||
#define SILENT_ANI 1 /* silent mode with animation */
|
||||
#define SILENT_ON 2 /* silent mode (completely silent) */
|
||||
|
||||
#define BOLD ATTBOLD
|
||||
#define RED ATTBOLD FGRED
|
||||
#define GREEN ATTBOLD FGGREEN
|
||||
#define YELLOW ATTBOLD FGYELLOW
|
||||
#define BLUE ATTBOLD FGBLUE
|
||||
#define MAGENTA ATTBOLD FGMAGENTA
|
||||
#define CYAN ATTBOLD FGCYAN
|
||||
|
||||
const char col_on [MAXCOL][19] = {BLUE, RED, GREEN, BOLD, MAGENTA, CYAN};
|
||||
const char col_off [] = ATTRESET;
|
||||
|
||||
static char *cmdlinename[MAXSOCK];
|
||||
static __u32 dropcnt[MAXSOCK];
|
||||
static __u32 last_dropcnt[MAXSOCK];
|
||||
static char devname[MAXIFNAMES][IFNAMSIZ+1];
|
||||
static int dindex[MAXIFNAMES];
|
||||
static int max_devname_len; /* to prevent frazzled device name output */
|
||||
const int canfd_on = 1;
|
||||
|
||||
#define MAXANI 4
|
||||
const char anichar[MAXANI] = {'|', '/', '-', '\\'};
|
||||
const char extra_m_info[4][4] = {"- -", "B -", "- E", "B E"};
|
||||
|
||||
static volatile int running = 1;
|
||||
|
||||
static void print_usage(char *prg)
|
||||
{
|
||||
fprintf(stderr, "%s - dump CAN bus traffic.\n", prg);
|
||||
fprintf(stderr, "\nUsage: %s [options] <CAN interface>+\n", prg);
|
||||
fprintf(stderr, " (use CTRL-C to terminate %s)\n\n", prg);
|
||||
fprintf(stderr, "Options:\n");
|
||||
fprintf(stderr, " -t <type> (timestamp: (a)bsolute/(d)elta/(z)ero/(A)bsolute w date)\n");
|
||||
fprintf(stderr, " -H (read hardware timestamps instead of system timestamps)\n");
|
||||
fprintf(stderr, " -c (increment color mode level)\n");
|
||||
fprintf(stderr, " -i (binary output - may exceed 80 chars/line)\n");
|
||||
fprintf(stderr, " -a (enable additional ASCII output)\n");
|
||||
fprintf(stderr, " -S (swap byte order in printed CAN data[] - marked with '%c' )\n", SWAP_DELIMITER);
|
||||
fprintf(stderr, " -s <level> (silent mode - %d: off (default) %d: animation %d: silent)\n", SILENT_OFF, SILENT_ANI, SILENT_ON);
|
||||
fprintf(stderr, " -l (log CAN-frames into file. Sets '-s %d' by default)\n", SILENT_ON);
|
||||
fprintf(stderr, " -L (use log file format on stdout)\n");
|
||||
fprintf(stderr, " -n <count> (terminate after reception of <count> CAN frames)\n");
|
||||
fprintf(stderr, " -r <size> (set socket receive buffer to <size>)\n");
|
||||
fprintf(stderr, " -D (Don't exit if a \"detected\" can device goes down.\n");
|
||||
fprintf(stderr, " -d (monitor dropped CAN frames)\n");
|
||||
fprintf(stderr, " -e (dump CAN error frames in human-readable format)\n");
|
||||
fprintf(stderr, " -x (print extra message infos, rx/tx brs esi)\n");
|
||||
fprintf(stderr, " -T <msecs> (terminate after <msecs> without any reception)\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "Up to %d CAN interfaces with optional filter sets can be specified\n", MAXSOCK);
|
||||
fprintf(stderr, "on the commandline in the form: <ifname>[,filter]*\n");
|
||||
fprintf(stderr, "\nFilters:\n");
|
||||
fprintf(stderr, " Comma separated filters can be specified for each given CAN interface:\n");
|
||||
fprintf(stderr, " <can_id>:<can_mask>\n (matches when <received_can_id> & mask == can_id & mask)\n");
|
||||
fprintf(stderr, " <can_id>~<can_mask>\n (matches when <received_can_id> & mask != can_id & mask)\n");
|
||||
fprintf(stderr, " #<error_mask>\n (set error frame filter, see include/linux/can/error.h)\n");
|
||||
fprintf(stderr, " [j|J]\n (join the given CAN filters - logical AND semantic)\n");
|
||||
fprintf(stderr, "\nCAN IDs, masks and data content are given and expected in hexadecimal values.\n");
|
||||
fprintf(stderr, "When the can_id is 8 digits long the CAN_EFF_FLAG is set for 29 bit EFF format.\n");
|
||||
fprintf(stderr, "Without any given filter all data frames are received ('0:0' default filter).\n");
|
||||
fprintf(stderr, "\nUse interface name '%s' to receive from all CAN interfaces.\n", ANYDEV);
|
||||
fprintf(stderr, "\nExamples:\n");
|
||||
fprintf(stderr, "%s -c -c -ta can0,123:7FF,400:700,#000000FF can2,400~7F0 can3 can8\n\n", prg);
|
||||
fprintf(stderr, "%s -l any,0~0,#FFFFFFFF\n (log only error frames but no(!) data frames)\n", prg);
|
||||
fprintf(stderr, "%s -l any,0:0,#FFFFFFFF\n (log error frames and also all data frames)\n", prg);
|
||||
fprintf(stderr, "%s vcan2,12345678:DFFFFFFF\n (match only for extended CAN ID 12345678)\n", prg);
|
||||
fprintf(stderr, "%s vcan2,123:7FF\n (matches CAN ID 123 - including EFF and RTR frames)\n", prg);
|
||||
fprintf(stderr, "%s vcan2,123:C00007FF\n (matches CAN ID 123 - only SFF and non-RTR frames)\n", prg);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void sigterm(int signo)
|
||||
{
|
||||
running = 0;
|
||||
}
|
||||
|
||||
int idx2dindex(int ifidx, int socket) {
|
||||
|
||||
int i;
|
||||
struct ifreq ifr;
|
||||
|
||||
for (i=0; i < MAXIFNAMES; i++) {
|
||||
if (dindex[i] == ifidx)
|
||||
return i;
|
||||
}
|
||||
|
||||
/* create new interface index cache entry */
|
||||
|
||||
/* remove index cache zombies first */
|
||||
for (i=0; i < MAXIFNAMES; i++) {
|
||||
if (dindex[i]) {
|
||||
ifr.ifr_ifindex = dindex[i];
|
||||
if (ioctl(socket, SIOCGIFNAME, &ifr) < 0)
|
||||
dindex[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i < MAXIFNAMES; i++)
|
||||
if (!dindex[i]) /* free entry */
|
||||
break;
|
||||
|
||||
if (i == MAXIFNAMES) {
|
||||
fprintf(stderr, "Interface index cache only supports %d interfaces.\n",
|
||||
MAXIFNAMES);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dindex[i] = ifidx;
|
||||
|
||||
ifr.ifr_ifindex = ifidx;
|
||||
if (ioctl(socket, SIOCGIFNAME, &ifr) < 0)
|
||||
perror("SIOCGIFNAME");
|
||||
|
||||
if (max_devname_len < (int)strlen(ifr.ifr_name))
|
||||
max_devname_len = strlen(ifr.ifr_name);
|
||||
|
||||
strcpy(devname[i], ifr.ifr_name);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("new index %d (%s)\n", i, devname[i]);
|
||||
#endif
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
fd_set rdfs;
|
||||
int s[MAXSOCK];
|
||||
unsigned char timestamp = 0;
|
||||
unsigned char hwtimestamp = 0;
|
||||
unsigned char down_causes_exit = 1;
|
||||
unsigned char dropmonitor = 0;
|
||||
unsigned char extra_msg_info = 0;
|
||||
unsigned char silent = SILENT_INI;
|
||||
unsigned char silentani = 0;
|
||||
unsigned char color = 0;
|
||||
unsigned char view = 0;
|
||||
unsigned char log = 0;
|
||||
unsigned char logfrmt = 0;
|
||||
int count = 0;
|
||||
int rcvbuf_size = 0;
|
||||
int opt, ret;
|
||||
int currmax, numfilter;
|
||||
int join_filter;
|
||||
char *ptr, *nptr;
|
||||
struct sockaddr_can addr;
|
||||
char ctrlmsg[CMSG_SPACE(sizeof(struct timeval) + 3*sizeof(struct timespec) + sizeof(__u32))];
|
||||
struct iovec iov;
|
||||
struct msghdr msg;
|
||||
struct cmsghdr *cmsg;
|
||||
struct can_filter *rfilter;
|
||||
can_err_mask_t err_mask;
|
||||
struct canfd_frame frame;
|
||||
int nbytes, i, maxdlen;
|
||||
struct ifreq ifr;
|
||||
struct timeval tv, last_tv;
|
||||
struct timeval timeout, timeout_config = { 0, 0 }, *timeout_current = NULL;
|
||||
FILE *logfile = NULL;
|
||||
|
||||
#if 0 /* NuttX doesn't support these signals */
|
||||
signal(SIGTERM, sigterm);
|
||||
signal(SIGHUP, sigterm);
|
||||
#endif
|
||||
signal(SIGINT, sigterm);
|
||||
|
||||
last_tv.tv_sec = 0;
|
||||
last_tv.tv_usec = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "t:HciaSs:lDdxLn:r:heT:?")) != -1) {
|
||||
switch (opt) {
|
||||
case 't':
|
||||
timestamp = optarg[0];
|
||||
if ((timestamp != 'a') && (timestamp != 'A') &&
|
||||
(timestamp != 'd') && (timestamp != 'z')) {
|
||||
fprintf(stderr, "%s: unknown timestamp mode '%c' - ignored\n",
|
||||
basename(argv[0]), optarg[0]);
|
||||
timestamp = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
hwtimestamp = 1;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
color++;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
view |= CANLIB_VIEW_BINARY;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
view |= CANLIB_VIEW_ASCII;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
view |= CANLIB_VIEW_SWAP;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
view |= CANLIB_VIEW_ERROR;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
silent = atoi(optarg);
|
||||
if (silent > SILENT_ON) {
|
||||
print_usage(basename(argv[0]));
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
log = 1;
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
down_causes_exit = 0;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
dropmonitor = 1;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
extra_msg_info = 1;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
logfrmt = 1;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
count = atoi(optarg);
|
||||
if (count < 1) {
|
||||
print_usage(basename(argv[0]));
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
rcvbuf_size = atoi(optarg);
|
||||
if (rcvbuf_size < 1) {
|
||||
print_usage(basename(argv[0]));
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
errno = 0;
|
||||
timeout_config.tv_usec = strtol(optarg, NULL, 0);
|
||||
if (errno != 0) {
|
||||
print_usage(basename(argv[0]));
|
||||
exit(1);
|
||||
}
|
||||
timeout_config.tv_sec = timeout_config.tv_usec / 1000;
|
||||
timeout_config.tv_usec = (timeout_config.tv_usec % 1000) * 1000;
|
||||
timeout_current = &timeout;
|
||||
break;
|
||||
default:
|
||||
print_usage(basename(argv[0]));
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc) {
|
||||
print_usage(basename(argv[0]));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (logfrmt && view) {
|
||||
fprintf(stderr, "Log file format selected: Please disable ASCII/BINARY/SWAP options!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (silent == SILENT_INI) {
|
||||
if (log) {
|
||||
fprintf(stderr, "Disabled standard output while logging.\n");
|
||||
silent = SILENT_ON; /* disable output on stdout */
|
||||
} else
|
||||
silent = SILENT_OFF; /* default output */
|
||||
}
|
||||
|
||||
currmax = argc - optind; /* find real number of CAN devices */
|
||||
|
||||
if (currmax > MAXSOCK) {
|
||||
fprintf(stderr, "More than %d CAN devices given on commandline!\n", MAXSOCK);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i=0; i < currmax; i++) {
|
||||
|
||||
ptr = argv[optind+i];
|
||||
nptr = strchr(ptr, ',');
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open %d '%s'.\n", i, ptr);
|
||||
#endif
|
||||
|
||||
s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
if (s[i] < 0) {
|
||||
perror("socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cmdlinename[i] = ptr; /* save pointer to cmdline name of this socket */
|
||||
|
||||
if (nptr)
|
||||
nbytes = nptr - ptr; /* interface name is up the first ',' */
|
||||
else
|
||||
nbytes = strlen(ptr); /* no ',' found => no filter definitions */
|
||||
|
||||
if (nbytes >= IFNAMSIZ) {
|
||||
fprintf(stderr, "name of CAN device '%s' is too long!\n", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (nbytes > max_devname_len)
|
||||
max_devname_len = nbytes; /* for nice printing */
|
||||
|
||||
addr.can_family = AF_CAN;
|
||||
|
||||
memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name));
|
||||
strncpy(ifr.ifr_name, ptr, nbytes);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("using interface name '%s'.\n", ifr.ifr_name);
|
||||
#endif
|
||||
|
||||
if (strcmp(ANYDEV, ifr.ifr_name)) {
|
||||
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
|
||||
perror("SIOCGIFINDEX");
|
||||
exit(1);
|
||||
}
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
} else
|
||||
addr.can_ifindex = 0; /* any can interface */
|
||||
|
||||
if (nptr) {
|
||||
|
||||
/* found a ',' after the interface name => check for filters */
|
||||
|
||||
/* determine number of filters to alloc the filter space */
|
||||
numfilter = 0;
|
||||
ptr = nptr;
|
||||
while (ptr) {
|
||||
numfilter++;
|
||||
ptr++; /* hop behind the ',' */
|
||||
ptr = strchr(ptr, ','); /* exit condition */
|
||||
}
|
||||
|
||||
rfilter = malloc(sizeof(struct can_filter) * numfilter);
|
||||
if (!rfilter) {
|
||||
fprintf(stderr, "Failed to create filter space!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
numfilter = 0;
|
||||
err_mask = 0;
|
||||
join_filter = 0;
|
||||
|
||||
while (nptr) {
|
||||
|
||||
ptr = nptr+1; /* hop behind the ',' */
|
||||
nptr = strchr(ptr, ','); /* update exit condition */
|
||||
|
||||
if (sscanf(ptr, "%" SCNx32 ":%" SCNx32,
|
||||
&rfilter[numfilter].can_id,
|
||||
&rfilter[numfilter].can_mask) == 2) {
|
||||
rfilter[numfilter].can_mask &= ~CAN_ERR_FLAG;
|
||||
if (*(ptr+8) == ':')
|
||||
rfilter[numfilter].can_id |= CAN_EFF_FLAG;
|
||||
numfilter++;
|
||||
} else if (sscanf(ptr, "%" SCNx32 "~%" SCNx32,
|
||||
&rfilter[numfilter].can_id,
|
||||
&rfilter[numfilter].can_mask) == 2) {
|
||||
rfilter[numfilter].can_id |= CAN_INV_FILTER;
|
||||
rfilter[numfilter].can_mask &= ~CAN_ERR_FLAG;
|
||||
if (*(ptr+8) == '~')
|
||||
rfilter[numfilter].can_id |= CAN_EFF_FLAG;
|
||||
numfilter++;
|
||||
} else if (*ptr == 'j' || *ptr == 'J') {
|
||||
join_filter = 1;
|
||||
} else if (sscanf(ptr, "#%" SCNx32, &err_mask) != 1) {
|
||||
fprintf(stderr, "Error in filter option parsing: '%s'\n", ptr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (err_mask)
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
|
||||
&err_mask, sizeof(err_mask));
|
||||
|
||||
if (join_filter && setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_JOIN_FILTERS,
|
||||
&join_filter, sizeof(join_filter)) < 0) {
|
||||
perror("setsockopt CAN_RAW_JOIN_FILTERS not supported by your Linux Kernel");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (numfilter)
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FILTER,
|
||||
rfilter, numfilter * sizeof(struct can_filter));
|
||||
|
||||
free(rfilter);
|
||||
|
||||
} /* if (nptr) */
|
||||
|
||||
/* try to switch the socket into CAN FD mode */
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
|
||||
|
||||
if (rcvbuf_size) {
|
||||
|
||||
int curr_rcvbuf_size;
|
||||
socklen_t curr_rcvbuf_size_len = sizeof(curr_rcvbuf_size);
|
||||
|
||||
/* try SO_RCVBUFFORCE first, if we run with CAP_NET_ADMIN */
|
||||
if (setsockopt(s[i], SOL_SOCKET, SO_RCVBUFFORCE,
|
||||
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
||||
#ifdef DEBUG
|
||||
printf("SO_RCVBUFFORCE failed so try SO_RCVBUF ...\n");
|
||||
#endif
|
||||
if (setsockopt(s[i], SOL_SOCKET, SO_RCVBUF,
|
||||
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
||||
perror("setsockopt SO_RCVBUF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (getsockopt(s[i], SOL_SOCKET, SO_RCVBUF,
|
||||
&curr_rcvbuf_size, &curr_rcvbuf_size_len) < 0) {
|
||||
perror("getsockopt SO_RCVBUF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Only print a warning the first time we detect the adjustment */
|
||||
/* n.b.: The wanted size is doubled in Linux in net/sore/sock.c */
|
||||
if (!i && curr_rcvbuf_size < rcvbuf_size*2)
|
||||
fprintf(stderr, "The socket receive buffer size was "
|
||||
"adjusted due to /proc/sys/net/core/rmem_max.\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (timestamp || log || logfrmt) {
|
||||
|
||||
if (hwtimestamp) {
|
||||
const int timestamping_flags = (SOF_TIMESTAMPING_SOFTWARE | \
|
||||
SOF_TIMESTAMPING_RX_SOFTWARE | \
|
||||
SOF_TIMESTAMPING_RAW_HARDWARE);
|
||||
|
||||
if (setsockopt(s[i], SOL_SOCKET, SO_TIMESTAMPING,
|
||||
×tamping_flags, sizeof(timestamping_flags)) < 0) {
|
||||
perror("setsockopt SO_TIMESTAMPING is not supported by your Linux kernel");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
const int timestamp_on = 1;
|
||||
|
||||
if (setsockopt(s[i], SOL_SOCKET, SO_TIMESTAMP,
|
||||
×tamp_on, sizeof(timestamp_on)) < 0) {
|
||||
perror("setsockopt SO_TIMESTAMP");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dropmonitor) {
|
||||
|
||||
const int dropmonitor_on = 1;
|
||||
|
||||
if (setsockopt(s[i], SOL_SOCKET, SO_RXQ_OVFL,
|
||||
&dropmonitor_on, sizeof(dropmonitor_on)) < 0) {
|
||||
perror("setsockopt SO_RXQ_OVFL not supported by your Linux Kernel");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (bind(s[i], (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
perror("bind");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (log) {
|
||||
time_t currtime;
|
||||
struct tm now;
|
||||
char fname[83]; /* suggested by -Wformat-overflow= */
|
||||
|
||||
if (time(&currtime) == (time_t)-1) {
|
||||
perror("time");
|
||||
return 1;
|
||||
}
|
||||
|
||||
localtime_r(&currtime, &now);
|
||||
|
||||
sprintf(fname, "candump-%04d-%02d-%02d_%02d%02d%02d.log",
|
||||
now.tm_year + 1900,
|
||||
now.tm_mon + 1,
|
||||
now.tm_mday,
|
||||
now.tm_hour,
|
||||
now.tm_min,
|
||||
now.tm_sec);
|
||||
|
||||
if (silent != SILENT_ON)
|
||||
fprintf(stderr, "Warning: Console output active while logging!\n");
|
||||
|
||||
fprintf(stderr, "Enabling Logfile '%s'\n", fname);
|
||||
|
||||
logfile = fopen(fname, "w");
|
||||
if (!logfile) {
|
||||
perror("logfile");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* these settings are static and can be held out of the hot path */
|
||||
iov.iov_base = &frame;
|
||||
msg.msg_name = &addr;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = &ctrlmsg;
|
||||
|
||||
while (running) {
|
||||
|
||||
FD_ZERO(&rdfs);
|
||||
for (i=0; i<currmax; i++)
|
||||
FD_SET(s[i], &rdfs);
|
||||
|
||||
if (timeout_current)
|
||||
*timeout_current = timeout_config;
|
||||
|
||||
if ((ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, timeout_current)) <= 0) {
|
||||
//perror("select");
|
||||
running = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i=0; i<currmax; i++) { /* check all CAN RAW sockets */
|
||||
|
||||
if (FD_ISSET(s[i], &rdfs)) {
|
||||
|
||||
int idx;
|
||||
|
||||
/* these settings may be modified by recvmsg() */
|
||||
iov.iov_len = sizeof(frame);
|
||||
msg.msg_namelen = sizeof(addr);
|
||||
msg.msg_controllen = sizeof(ctrlmsg);
|
||||
msg.msg_flags = 0;
|
||||
|
||||
nbytes = recvmsg(s[i], &msg, 0);
|
||||
idx = idx2dindex(addr.can_ifindex, s[i]);
|
||||
|
||||
if (nbytes < 0) {
|
||||
if ((errno == ENETDOWN) && !down_causes_exit) {
|
||||
fprintf(stderr, "%s: interface down\n", devname[idx]);
|
||||
continue;
|
||||
}
|
||||
perror("read");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((size_t)nbytes == CAN_MTU)
|
||||
maxdlen = CAN_MAX_DLEN;
|
||||
else if ((size_t)nbytes == CANFD_MTU)
|
||||
maxdlen = CANFD_MAX_DLEN;
|
||||
else {
|
||||
fprintf(stderr, "read: incomplete CAN frame\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (count && (--count == 0))
|
||||
running = 0;
|
||||
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg);
|
||||
cmsg && (cmsg->cmsg_level == SOL_SOCKET);
|
||||
cmsg = CMSG_NXTHDR(&msg,cmsg)) {
|
||||
if (cmsg->cmsg_type == SO_TIMESTAMP) {
|
||||
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
|
||||
} else if (cmsg->cmsg_type == SO_TIMESTAMPING) {
|
||||
|
||||
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
|
||||
|
||||
/*
|
||||
* stamp[0] is the software timestamp
|
||||
* stamp[1] is deprecated
|
||||
* stamp[2] is the raw hardware timestamp
|
||||
* See chapter 2.1.2 Receive timestamps in
|
||||
* linux/Documentation/networking/timestamping.txt
|
||||
*/
|
||||
tv.tv_sec = stamp[2].tv_sec;
|
||||
tv.tv_usec = stamp[2].tv_nsec/1000;
|
||||
} else if (cmsg->cmsg_type == SO_RXQ_OVFL)
|
||||
memcpy(&dropcnt[i], CMSG_DATA(cmsg), sizeof(__u32));
|
||||
}
|
||||
|
||||
/* check for (unlikely) dropped frames on this specific socket */
|
||||
if (dropcnt[i] != last_dropcnt[i]) {
|
||||
|
||||
__u32 frames = dropcnt[i] - last_dropcnt[i];
|
||||
|
||||
if (silent != SILENT_ON)
|
||||
printf("DROPCOUNT: dropped %" PRId32 " CAN frame%s on '%s' socket (total drops %" PRId32 ")\n",
|
||||
(uint32_t)frames, (frames > 1)?"s":"", devname[idx], (uint32_t)dropcnt[i]);
|
||||
|
||||
if (log)
|
||||
fprintf(logfile, "DROPCOUNT: dropped %" PRId32 " CAN frame%s on '%s' socket (total drops %" PRId32 ")\n",
|
||||
(uint32_t)frames, (frames > 1)?"s":"", devname[idx], (uint32_t)dropcnt[i]);
|
||||
|
||||
last_dropcnt[i] = dropcnt[i];
|
||||
}
|
||||
|
||||
/* once we detected a EFF frame indent SFF frames accordingly */
|
||||
if (frame.can_id & CAN_EFF_FLAG)
|
||||
view |= CANLIB_VIEW_INDENT_SFF;
|
||||
|
||||
if (log) {
|
||||
char buf[CL_CFSZ]; /* max length */
|
||||
|
||||
/* log CAN frame with absolute timestamp & device */
|
||||
sprint_canframe(buf, &frame, 0, maxdlen);
|
||||
fprintf(logfile, "(%010ju.%06ld) %*s %s\n",
|
||||
(uintmax_t)tv.tv_sec, tv.tv_usec,
|
||||
max_devname_len, devname[idx], buf);
|
||||
}
|
||||
|
||||
if ((logfrmt) && (silent == SILENT_OFF)){
|
||||
char buf[CL_CFSZ]; /* max length */
|
||||
|
||||
/* print CAN frame in log file style to stdout */
|
||||
sprint_canframe(buf, &frame, 0, maxdlen);
|
||||
printf("(%010ju.%06ld) %*s %s\n",
|
||||
(uintmax_t)tv.tv_sec, tv.tv_usec,
|
||||
max_devname_len, devname[idx], buf);
|
||||
goto out_fflush; /* no other output to stdout */
|
||||
}
|
||||
|
||||
if (silent != SILENT_OFF){
|
||||
if (silent == SILENT_ANI) {
|
||||
printf("%c\b", anichar[silentani%=MAXANI]);
|
||||
silentani++;
|
||||
}
|
||||
goto out_fflush; /* no other output to stdout */
|
||||
}
|
||||
|
||||
printf(" %s", (color>2)?col_on[idx%MAXCOL]:"");
|
||||
|
||||
switch (timestamp) {
|
||||
|
||||
case 'a': /* absolute with timestamp */
|
||||
printf("(%010ju.%06ld) ",
|
||||
(uintmax_t)tv.tv_sec, tv.tv_usec);
|
||||
break;
|
||||
|
||||
case 'A': /* absolute with date */
|
||||
{
|
||||
struct tm tm;
|
||||
char timestring[25];
|
||||
|
||||
tm = *localtime(&tv.tv_sec);
|
||||
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
printf("(%s.%06ld) ", timestring, tv.tv_usec);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd': /* delta */
|
||||
case 'z': /* starting with zero */
|
||||
{
|
||||
struct timeval diff;
|
||||
|
||||
if (last_tv.tv_sec == 0) /* first init */
|
||||
last_tv = tv;
|
||||
diff.tv_sec = tv.tv_sec - last_tv.tv_sec;
|
||||
diff.tv_usec = tv.tv_usec - last_tv.tv_usec;
|
||||
if (diff.tv_usec < 0)
|
||||
diff.tv_sec--, diff.tv_usec += 1000000;
|
||||
if (diff.tv_sec < 0)
|
||||
diff.tv_sec = diff.tv_usec = 0;
|
||||
printf("(%03ju.%06ld) ",
|
||||
(uintmax_t)diff.tv_sec, diff.tv_usec);
|
||||
|
||||
if (timestamp == 'd')
|
||||
last_tv = tv; /* update for delta calculation */
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* no timestamp output */
|
||||
break;
|
||||
}
|
||||
|
||||
printf(" %s", (color && (color<3))?col_on[idx%MAXCOL]:"");
|
||||
printf("%*s", max_devname_len, devname[idx]);
|
||||
|
||||
if (extra_msg_info) {
|
||||
|
||||
if (msg.msg_flags & MSG_DONTROUTE)
|
||||
printf (" TX %s", extra_m_info[frame.flags & 3]);
|
||||
else
|
||||
printf (" RX %s", extra_m_info[frame.flags & 3]);
|
||||
}
|
||||
|
||||
printf("%s ", (color==1)?col_off:"");
|
||||
|
||||
fprint_long_canframe(stdout, &frame, NULL, view, maxdlen);
|
||||
|
||||
printf("%s", (color>1)?col_off:"");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
out_fflush:
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<currmax; i++)
|
||||
close(s[i]);
|
||||
|
||||
if (log)
|
||||
fclose(logfile);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -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
|
|
@ -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 += $(APPDIR)/canutils/canlib
|
||||
endif
|
|
@ -0,0 +1,44 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# CAN utility library
|
||||
|
||||
CSRCS = canlib_getbaud.c canlib_setbaud.c
|
||||
CSRCS += canlib_getloopback.c canlib_setloopback.c
|
||||
CSRCS += canlib_getsilent.c canlib_setsilent.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/****************************************************************************
|
||||
* 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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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 - whether 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;
|
||||
}
|
|
@ -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 - whether 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;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config CANUTILS_CANSEND
|
||||
tristate "SocketCAN cansend tool"
|
||||
default n
|
||||
depends on NET_CAN
|
||||
select CANUTILS_LIBCANUTILS
|
||||
---help---
|
||||
Enable the SocketCAN cansend tool ported from
|
||||
https://github.com/linux-can/can-utils
|
||||
|
||||
if CANUTILS_CANSEND
|
||||
endif
|
|
@ -0,0 +1,24 @@
|
|||
############################################################################
|
||||
# apps/canutils/cansend/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################/
|
||||
|
||||
ifneq ($(CONFIG_CANUTILS_CANSEND),)
|
||||
CONFIGURED_APPS += $(APPDIR)/canutils/cansend
|
||||
endif
|
|
@ -0,0 +1,34 @@
|
|||
############################################################################
|
||||
# apps/canutils/cansend/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################/
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# SocketCAN userspace utilities and tools cansend tool
|
||||
# https://github.com/linux-can/can-utils/blob/master/cansend.c
|
||||
|
||||
PROGNAME = cansend
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
MODULE = $(CONFIG_CANUTILS_CANSEND)
|
||||
|
||||
CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/canutils/libcanutils}
|
||||
MAINSRC = cansend.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,169 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
|
||||
/*
|
||||
* cansend.c - send CAN-frames via CAN_RAW sockets
|
||||
*
|
||||
* Copyright (c) 2002-2007 Volkswagen Group Electronic Research
|
||||
* 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. Neither the name of Volkswagen nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* Alternatively, provided that this notice is retained in full, this
|
||||
* software may be distributed under the terms of the GNU General
|
||||
* Public License ("GPL") version 2, in which case the provisions of the
|
||||
* GPL apply INSTEAD OF those given above.
|
||||
*
|
||||
* The provided data structures and external interfaces from this code
|
||||
* are not restricted to be used by modules with a GPL compatible license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Send feedback to <linux-can@vger.kernel.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <nuttx/can.h>
|
||||
#include <netpacket/can.h>
|
||||
|
||||
#include "lib.h"
|
||||
|
||||
static void print_usage_send(char *prg)
|
||||
{
|
||||
fprintf(stderr, "%s - send CAN-frames via CAN_RAW sockets.\n", prg);
|
||||
fprintf(stderr, "\nUsage: %s <device> <can_frame>.\n", prg);
|
||||
fprintf(stderr, "\n<can_frame>:\n");
|
||||
fprintf(stderr, " <can_id>#{data} for 'classic' CAN 2.0 data frames\n");
|
||||
fprintf(stderr, " <can_id>#R{len} for 'classic' CAN 2.0 data frames\n");
|
||||
fprintf(stderr, " <can_id>##<flags>{data} for CAN FD frames\n\n");
|
||||
fprintf(stderr, "<can_id>:\n"
|
||||
" 3 (SFF) or 8 (EFF) hex chars\n");
|
||||
fprintf(stderr, "{data}:\n"
|
||||
" 0..8 (0..64 CAN FD) ASCII hex-values (optionally separated by '.')\n");
|
||||
fprintf(stderr, "{len}:\n"
|
||||
" an optional 0..8 value as RTR frames can contain a valid dlc field\n");
|
||||
fprintf(stderr, "<flags>:\n"
|
||||
" a single ASCII Hex value (0 .. F) which defines canfd_frame.flags\n\n");
|
||||
fprintf(stderr, "Examples:\n");
|
||||
fprintf(stderr, " 5A1#11.2233.44556677.88 / 123#DEADBEEF / 5AA# / 123##1 / 213##311223344 /\n"
|
||||
" 1F334455#1122334455667788 / 123#R / 00000123#R3\n\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int s; /* can raw socket */
|
||||
int required_mtu;
|
||||
int mtu;
|
||||
int enable_canfd = 1;
|
||||
struct sockaddr_can addr;
|
||||
struct canfd_frame frame;
|
||||
struct ifreq ifr;
|
||||
|
||||
/* check command line options */
|
||||
if (argc != 3) {
|
||||
print_usage_send(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* parse CAN frame */
|
||||
required_mtu = parse_canframe(argv[2], &frame);
|
||||
if (!required_mtu){
|
||||
fprintf(stderr, "\nWrong CAN-frame format!\n\n");
|
||||
print_usage_send(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* open socket */
|
||||
if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
|
||||
perror("socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1);
|
||||
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
|
||||
ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
|
||||
if (!ifr.ifr_ifindex) {
|
||||
perror("if_nametoindex");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.can_family = AF_CAN;
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
|
||||
if (required_mtu > (int)CAN_MTU) {
|
||||
|
||||
/* check if the frame fits into the CAN netdevice */
|
||||
if (ioctl(s, SIOCGIFMTU, &ifr) < 0) {
|
||||
perror("SIOCGIFMTU");
|
||||
return 1;
|
||||
}
|
||||
mtu = ifr.ifr_mtu;
|
||||
|
||||
if (mtu != CANFD_MTU) {
|
||||
printf("CAN interface is not CAN FD capable - sorry.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* interface is ok - try to switch the socket into CAN FD mode */
|
||||
if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES,
|
||||
&enable_canfd, sizeof(enable_canfd))){
|
||||
printf("error when enabling CAN FD support\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 */
|
||||
frame.len = can_dlc2len(can_len2dlc(frame.len));
|
||||
}
|
||||
|
||||
/* disable default receive filter on this RAW socket */
|
||||
/* This is obsolete as we do not read from the socket at all, but for */
|
||||
/* this reason we can remove the receive list in the Kernel to save a */
|
||||
/* little (really a very little!) CPU usage. */
|
||||
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
|
||||
|
||||
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
perror("bind");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* send frame */
|
||||
if (write(s, &frame, required_mtu) != required_mtu) {
|
||||
perror("write");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close(s);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -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
|
||||
---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
|
|
@ -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 += $(APPDIR)/canutils/libcanard
|
||||
endif
|
|
@ -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 $(APPDIR)/Make.defs
|
||||
|
||||
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 -DCANARD_ASSERT=DEBUGASSERT
|
||||
CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPS_INCDIR)}
|
||||
|
||||
CSRCS = $(LIBCANARD_SRCDIR)$(DELIM)canard.c $(LIBCANARD_DRVDIR)$(DELIM)canard_nuttx.c
|
||||
|
||||
$(LIBCANARD_PACKNAME):
|
||||
@echo "Downloading: $@"
|
||||
$(Q) curl -o $@ -L $(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
|
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config CANUTILS_LIBCANUTILS
|
||||
bool "CAN-utils support library"
|
||||
default n
|
||||
depends on NET_CAN
|
||||
---help---
|
||||
Enable the CAN-utils support library ported from
|
||||
https://github.com/linux-can/can-utils
|
||||
|
||||
if CANUTILS_LIBCANUTILS
|
||||
|
||||
endif
|
|
@ -0,0 +1,23 @@
|
|||
############################################################################
|
||||
# apps/canutils/libcanutils/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################/
|
||||
|
||||
ifeq ($(CONFIG_CANUTILS_LIBCANUTILS),y)
|
||||
CONFIGURED_APPS += $(APPDIR)/canutils/libcanutils
|
||||
endif
|
|
@ -0,0 +1,28 @@
|
|||
############################################################################
|
||||
# apps/canutils/libcanutils/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################/
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# SocketCAN userspace utilities and tools library
|
||||
# https://github.com/linux-can/can-utils
|
||||
|
||||
CSRCS = lib.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,609 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
|
||||
/*
|
||||
* lib.c - library for command line tools
|
||||
*
|
||||
* Copyright (c) 2002-2007 Volkswagen Group Electronic Research
|
||||
* 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. Neither the name of Volkswagen nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* Alternatively, provided that this notice is retained in full, this
|
||||
* software may be distributed under the terms of the GNU General
|
||||
* Public License ("GPL") version 2, in which case the provisions of the
|
||||
* GPL apply INSTEAD OF those given above.
|
||||
*
|
||||
* The provided data structures and external interfaces from this code
|
||||
* are not restricted to be used by modules with a GPL compatible license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Send feedback to <linux-can@vger.kernel.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sys/socket.h> /* for sa_family_t */
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/can/error.h>
|
||||
#include <netpacket/can.h>
|
||||
|
||||
#include "lib.h"
|
||||
|
||||
#define CANID_DELIM '#'
|
||||
#define DATA_SEPERATOR '.'
|
||||
|
||||
const char hex_asc_upper[] = "0123456789ABCDEF";
|
||||
|
||||
#define hex_asc_upper_lo(x) hex_asc_upper[((x) & 0x0F)]
|
||||
#define hex_asc_upper_hi(x) hex_asc_upper[((x) & 0xF0) >> 4]
|
||||
|
||||
static inline void put_hex_byte(char *buf, __u8 byte)
|
||||
{
|
||||
buf[0] = hex_asc_upper_hi(byte);
|
||||
buf[1] = hex_asc_upper_lo(byte);
|
||||
}
|
||||
|
||||
static inline void _put_id(char *buf, int end_offset, canid_t id)
|
||||
{
|
||||
/* build 3 (SFF) or 8 (EFF) digit CAN identifier */
|
||||
while (end_offset >= 0) {
|
||||
buf[end_offset--] = hex_asc_upper_lo(id);
|
||||
id >>= 4;
|
||||
}
|
||||
}
|
||||
|
||||
#define put_sff_id(buf, id) _put_id(buf, 2, id)
|
||||
#define put_eff_id(buf, id) _put_id(buf, 7, id)
|
||||
|
||||
/* CAN DLC to real data length conversion helpers */
|
||||
|
||||
static const unsigned char dlc2len[] = {0, 1, 2, 3, 4, 5, 6, 7,
|
||||
8, 12, 16, 20, 24, 32, 48, 64};
|
||||
|
||||
/* get data length from can_dlc with sanitized can_dlc */
|
||||
unsigned char can_dlc2len(unsigned char can_dlc)
|
||||
{
|
||||
return dlc2len[can_dlc & 0x0F];
|
||||
}
|
||||
|
||||
static const unsigned char len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */
|
||||
9, 9, 9, 9, /* 9 - 12 */
|
||||
10, 10, 10, 10, /* 13 - 16 */
|
||||
11, 11, 11, 11, /* 17 - 20 */
|
||||
12, 12, 12, 12, /* 21 - 24 */
|
||||
13, 13, 13, 13, 13, 13, 13, 13, /* 25 - 32 */
|
||||
14, 14, 14, 14, 14, 14, 14, 14, /* 33 - 40 */
|
||||
14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */
|
||||
15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */
|
||||
15, 15, 15, 15, 15, 15, 15, 15}; /* 57 - 64 */
|
||||
|
||||
/* map the sanitized data length to an appropriate data length code */
|
||||
unsigned char can_len2dlc(unsigned char len)
|
||||
{
|
||||
if (len > 64)
|
||||
return 0xF;
|
||||
|
||||
return len2dlc[len];
|
||||
}
|
||||
|
||||
unsigned char asc2nibble(char c) {
|
||||
|
||||
if ((c >= '0') && (c <= '9'))
|
||||
return c - '0';
|
||||
|
||||
if ((c >= 'A') && (c <= 'F'))
|
||||
return c - 'A' + 10;
|
||||
|
||||
if ((c >= 'a') && (c <= 'f'))
|
||||
return c - 'a' + 10;
|
||||
|
||||
return 16; /* error */
|
||||
}
|
||||
|
||||
int hexstring2data(char *arg, unsigned char *data, int maxdlen) {
|
||||
|
||||
int len = strlen(arg);
|
||||
int i;
|
||||
unsigned char tmp;
|
||||
|
||||
if (!len || len%2 || len > maxdlen*2)
|
||||
return 1;
|
||||
|
||||
memset(data, 0, maxdlen);
|
||||
|
||||
for (i=0; i < len/2; i++) {
|
||||
|
||||
tmp = asc2nibble(*(arg+(2*i)));
|
||||
if (tmp > 0x0F)
|
||||
return 1;
|
||||
|
||||
data[i] = (tmp << 4);
|
||||
|
||||
tmp = asc2nibble(*(arg+(2*i)+1));
|
||||
if (tmp > 0x0F)
|
||||
return 1;
|
||||
|
||||
data[i] |= tmp;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_canframe(char *cs, struct canfd_frame *cf) {
|
||||
/* documentation see lib.h */
|
||||
|
||||
int i, idx, dlen, len;
|
||||
int maxdlen = CAN_MAX_DLEN;
|
||||
int ret = CAN_MTU;
|
||||
unsigned char tmp;
|
||||
|
||||
len = strlen(cs);
|
||||
//printf("'%s' len %d\n", cs, len);
|
||||
|
||||
memset(cf, 0, sizeof(*cf)); /* init CAN FD frame, e.g. LEN = 0 */
|
||||
|
||||
if (len < 4)
|
||||
return 0;
|
||||
|
||||
if (cs[3] == CANID_DELIM) { /* 3 digits */
|
||||
|
||||
idx = 4;
|
||||
for (i=0; i<3; i++){
|
||||
if ((tmp = asc2nibble(cs[i])) > 0x0F)
|
||||
return 0;
|
||||
cf->can_id |= (tmp << (2-i)*4);
|
||||
}
|
||||
|
||||
} else if (cs[8] == CANID_DELIM) { /* 8 digits */
|
||||
|
||||
idx = 9;
|
||||
for (i=0; i<8; i++){
|
||||
if ((tmp = asc2nibble(cs[i])) > 0x0F)
|
||||
return 0;
|
||||
cf->can_id |= (tmp << (7-i)*4);
|
||||
}
|
||||
if (!(cf->can_id & CAN_ERR_FLAG)) /* 8 digits but no errorframe? */
|
||||
cf->can_id |= CAN_EFF_FLAG; /* then it is an extended frame */
|
||||
|
||||
} else
|
||||
return 0;
|
||||
|
||||
if((cs[idx] == 'R') || (cs[idx] == 'r')){ /* RTR frame */
|
||||
cf->can_id |= CAN_RTR_FLAG;
|
||||
|
||||
/* check for optional DLC value for CAN 2.0B frames */
|
||||
if(cs[++idx] && (tmp = asc2nibble(cs[idx])) <= CAN_MAX_DLC)
|
||||
cf->len = tmp;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (cs[idx] == CANID_DELIM) { /* CAN FD frame escape char '##' */
|
||||
|
||||
maxdlen = CANFD_MAX_DLEN;
|
||||
ret = CANFD_MTU;
|
||||
|
||||
/* CAN FD frame <canid>##<flags><data>* */
|
||||
if ((tmp = asc2nibble(cs[idx+1])) > 0x0F)
|
||||
return 0;
|
||||
|
||||
cf->flags = tmp;
|
||||
idx += 2;
|
||||
}
|
||||
|
||||
for (i=0, dlen=0; i < maxdlen; i++){
|
||||
|
||||
if(cs[idx] == DATA_SEPERATOR) /* skip (optional) separator */
|
||||
idx++;
|
||||
|
||||
if(idx >= len) /* end of string => end of data */
|
||||
break;
|
||||
|
||||
if ((tmp = asc2nibble(cs[idx++])) > 0x0F)
|
||||
return 0;
|
||||
cf->data[i] = (tmp << 4);
|
||||
if ((tmp = asc2nibble(cs[idx++])) > 0x0F)
|
||||
return 0;
|
||||
cf->data[i] |= tmp;
|
||||
dlen++;
|
||||
}
|
||||
cf->len = dlen;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fprint_canframe(FILE *stream , struct canfd_frame *cf, char *eol, int sep, int maxdlen) {
|
||||
/* documentation see lib.h */
|
||||
|
||||
char buf[CL_CFSZ]; /* max length */
|
||||
|
||||
sprint_canframe(buf, cf, sep, maxdlen);
|
||||
fprintf(stream, "%s", buf);
|
||||
if (eol)
|
||||
fprintf(stream, "%s", eol);
|
||||
}
|
||||
|
||||
void sprint_canframe(char *buf , struct canfd_frame *cf, int sep, int maxdlen) {
|
||||
/* documentation see lib.h */
|
||||
|
||||
int i,offset;
|
||||
int len = (cf->len > maxdlen) ? maxdlen : cf->len;
|
||||
|
||||
if (cf->can_id & CAN_ERR_FLAG) {
|
||||
put_eff_id(buf, cf->can_id & (CAN_ERR_MASK|CAN_ERR_FLAG));
|
||||
buf[8] = '#';
|
||||
offset = 9;
|
||||
} else if (cf->can_id & CAN_EFF_FLAG) {
|
||||
put_eff_id(buf, cf->can_id & CAN_EFF_MASK);
|
||||
buf[8] = '#';
|
||||
offset = 9;
|
||||
} else {
|
||||
put_sff_id(buf, cf->can_id & CAN_SFF_MASK);
|
||||
buf[3] = '#';
|
||||
offset = 4;
|
||||
}
|
||||
|
||||
/* standard CAN frames may have RTR enabled. There are no ERR frames with RTR */
|
||||
if (maxdlen == CAN_MAX_DLEN && cf->can_id & CAN_RTR_FLAG) {
|
||||
buf[offset++] = 'R';
|
||||
/* print a given CAN 2.0B DLC if it's not zero */
|
||||
if (cf->len && cf->len <= CAN_MAX_DLC)
|
||||
buf[offset++] = hex_asc_upper_lo(cf->len);
|
||||
|
||||
buf[offset] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (maxdlen == CANFD_MAX_DLEN) {
|
||||
/* add CAN FD specific escape char and flags */
|
||||
buf[offset++] = '#';
|
||||
buf[offset++] = hex_asc_upper_lo(cf->flags);
|
||||
if (sep && len)
|
||||
buf[offset++] = '.';
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
put_hex_byte(buf + offset, cf->data[i]);
|
||||
offset += 2;
|
||||
if (sep && (i+1 < len))
|
||||
buf[offset++] = '.';
|
||||
}
|
||||
|
||||
buf[offset] = 0;
|
||||
}
|
||||
|
||||
void fprint_long_canframe(FILE *stream , struct canfd_frame *cf, char *eol, int view, int maxdlen) {
|
||||
/* documentation see lib.h */
|
||||
|
||||
char buf[CL_LONGCFSZ];
|
||||
|
||||
sprint_long_canframe(buf, cf, view, maxdlen);
|
||||
fprintf(stream, "%s", buf);
|
||||
if ((view & CANLIB_VIEW_ERROR) && (cf->can_id & CAN_ERR_FLAG)) {
|
||||
snprintf_can_error_frame(buf, sizeof(buf), cf, "\n\t");
|
||||
fprintf(stream, "\n\t%s", buf);
|
||||
}
|
||||
if (eol)
|
||||
fprintf(stream, "%s", eol);
|
||||
}
|
||||
|
||||
void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxdlen) {
|
||||
/* documentation see lib.h */
|
||||
|
||||
int i, j, dlen, offset;
|
||||
int len = (cf->len > maxdlen)? maxdlen : cf->len;
|
||||
|
||||
/* initialize space for CAN-ID and length information */
|
||||
memset(buf, ' ', 15);
|
||||
|
||||
if (cf->can_id & CAN_ERR_FLAG) {
|
||||
put_eff_id(buf, cf->can_id & (CAN_ERR_MASK|CAN_ERR_FLAG));
|
||||
offset = 10;
|
||||
} else if (cf->can_id & CAN_EFF_FLAG) {
|
||||
put_eff_id(buf, cf->can_id & CAN_EFF_MASK);
|
||||
offset = 10;
|
||||
} else {
|
||||
if (view & CANLIB_VIEW_INDENT_SFF) {
|
||||
put_sff_id(buf + 5, cf->can_id & CAN_SFF_MASK);
|
||||
offset = 10;
|
||||
} else {
|
||||
put_sff_id(buf, cf->can_id & CAN_SFF_MASK);
|
||||
offset = 5;
|
||||
}
|
||||
}
|
||||
|
||||
/* The len value is sanitized by maxdlen (see above) */
|
||||
if (maxdlen == CAN_MAX_DLEN) {
|
||||
buf[offset + 1] = '[';
|
||||
buf[offset + 2] = len + '0';
|
||||
buf[offset + 3] = ']';
|
||||
|
||||
/* standard CAN frames may have RTR enabled */
|
||||
if (cf->can_id & CAN_RTR_FLAG) {
|
||||
sprintf(buf+offset+5, " remote request");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
buf[offset] = '[';
|
||||
buf[offset + 1] = (len/10) + '0';
|
||||
buf[offset + 2] = (len%10) + '0';
|
||||
buf[offset + 3] = ']';
|
||||
}
|
||||
offset += 5;
|
||||
|
||||
if (view & CANLIB_VIEW_BINARY) {
|
||||
dlen = 9; /* _10101010 */
|
||||
if (view & CANLIB_VIEW_SWAP) {
|
||||
for (i = len - 1; i >= 0; i--) {
|
||||
buf[offset++] = (i == len-1)?' ':SWAP_DELIMITER;
|
||||
for (j = 7; j >= 0; j--)
|
||||
buf[offset++] = (1<<j & cf->data[i])?'1':'0';
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < len; i++) {
|
||||
buf[offset++] = ' ';
|
||||
for (j = 7; j >= 0; j--)
|
||||
buf[offset++] = (1<<j & cf->data[i])?'1':'0';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dlen = 3; /* _AA */
|
||||
if (view & CANLIB_VIEW_SWAP) {
|
||||
for (i = len - 1; i >= 0; i--) {
|
||||
if (i == len-1)
|
||||
buf[offset++] = ' ';
|
||||
else
|
||||
buf[offset++] = SWAP_DELIMITER;
|
||||
|
||||
put_hex_byte(buf + offset, cf->data[i]);
|
||||
offset += 2;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < len; i++) {
|
||||
buf[offset++] = ' ';
|
||||
put_hex_byte(buf + offset, cf->data[i]);
|
||||
offset += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf[offset] = 0; /* terminate string */
|
||||
|
||||
/*
|
||||
* The ASCII & ERRORFRAME output is put at a fixed len behind the data.
|
||||
* For now we support ASCII output only for payload length up to 8 bytes.
|
||||
* Does it make sense to write 64 ASCII byte behind 64 ASCII HEX data on the console?
|
||||
*/
|
||||
if (len > CAN_MAX_DLEN)
|
||||
return;
|
||||
|
||||
if (cf->can_id & CAN_ERR_FLAG)
|
||||
sprintf(buf+offset, "%*s", dlen*(8-len)+13, "ERRORFRAME");
|
||||
else if (view & CANLIB_VIEW_ASCII) {
|
||||
j = dlen*(8-len)+4;
|
||||
if (view & CANLIB_VIEW_SWAP) {
|
||||
sprintf(buf+offset, "%*s", j, "`");
|
||||
offset += j;
|
||||
for (i = len - 1; i >= 0; i--)
|
||||
if ((cf->data[i] > 0x1F) && (cf->data[i] < 0x7F))
|
||||
buf[offset++] = cf->data[i];
|
||||
else
|
||||
buf[offset++] = '.';
|
||||
|
||||
sprintf(buf+offset, "`");
|
||||
} else {
|
||||
sprintf(buf+offset, "%*s", j, "'");
|
||||
offset += j;
|
||||
for (i = 0; i < len; i++)
|
||||
if ((cf->data[i] > 0x1F) && (cf->data[i] < 0x7F))
|
||||
buf[offset++] = cf->data[i];
|
||||
else
|
||||
buf[offset++] = '.';
|
||||
|
||||
sprintf(buf+offset, "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char *error_classes[] = {
|
||||
"tx-timeout",
|
||||
"lost-arbitration",
|
||||
"controller-problem",
|
||||
"protocol-violation",
|
||||
"transceiver-status",
|
||||
"no-acknowledgement-on-tx",
|
||||
"bus-off",
|
||||
"bus-error",
|
||||
"restarted-after-bus-off",
|
||||
};
|
||||
|
||||
static const char *controller_problems[] = {
|
||||
"rx-overflow",
|
||||
"tx-overflow",
|
||||
"rx-error-warning",
|
||||
"tx-error-warning",
|
||||
"rx-error-passive",
|
||||
"tx-error-passive",
|
||||
"back-to-error-active",
|
||||
};
|
||||
|
||||
static const char *protocol_violation_types[] = {
|
||||
"single-bit-error",
|
||||
"frame-format-error",
|
||||
"bit-stuffing-error",
|
||||
"tx-dominant-bit-error",
|
||||
"tx-recessive-bit-error",
|
||||
"bus-overload",
|
||||
"active-error",
|
||||
"error-on-tx",
|
||||
};
|
||||
|
||||
static const char *protocol_violation_locations[] = {
|
||||
"unspecified",
|
||||
"unspecified",
|
||||
"id.28-to-id.21",
|
||||
"start-of-frame",
|
||||
"bit-srtr",
|
||||
"bit-ide",
|
||||
"id.20-to-id.18",
|
||||
"id.17-to-id.13",
|
||||
"crc-sequence",
|
||||
"reserved-bit-0",
|
||||
"data-field",
|
||||
"data-length-code",
|
||||
"bit-rtr",
|
||||
"reserved-bit-1",
|
||||
"id.4-to-id.0",
|
||||
"id.12-to-id.5",
|
||||
"unspecified",
|
||||
"active-error-flag",
|
||||
"intermission",
|
||||
"tolerate-dominant-bits",
|
||||
"unspecified",
|
||||
"unspecified",
|
||||
"passive-error-flag",
|
||||
"error-delimiter",
|
||||
"crc-delimiter",
|
||||
"acknowledge-slot",
|
||||
"end-of-frame",
|
||||
"acknowledge-delimiter",
|
||||
"overload-flag",
|
||||
"unspecified",
|
||||
"unspecified",
|
||||
"unspecified",
|
||||
};
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
static int snprintf_error_data(char *buf, size_t len, uint8_t err,
|
||||
const char **arr, int arr_len)
|
||||
{
|
||||
int i, n = 0, count = 0;
|
||||
|
||||
if (!err || len <= 0)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < arr_len; i++) {
|
||||
if (err & (1 << i)) {
|
||||
if (count)
|
||||
n += snprintf(buf + n, len - n, ",");
|
||||
n += snprintf(buf + n, len - n, "%s", arr[i]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int snprintf_error_lostarb(char *buf, size_t len, const struct canfd_frame *cf)
|
||||
{
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
return snprintf(buf, len, "{at bit %d}", cf->data[0]);
|
||||
}
|
||||
|
||||
static int snprintf_error_ctrl(char *buf, size_t len, const struct canfd_frame *cf)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
n += snprintf(buf + n, len - n, "{");
|
||||
n += snprintf_error_data(buf + n, len - n, cf->data[1],
|
||||
controller_problems,
|
||||
ARRAY_SIZE(controller_problems));
|
||||
n += snprintf(buf + n, len - n, "}");
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int snprintf_error_prot(char *buf, size_t len, const struct canfd_frame *cf)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
n += snprintf(buf + n, len - n, "{{");
|
||||
n += snprintf_error_data(buf + n, len - n, cf->data[2],
|
||||
protocol_violation_types,
|
||||
ARRAY_SIZE(protocol_violation_types));
|
||||
n += snprintf(buf + n, len - n, "}{");
|
||||
if (cf->data[3] > 0 &&
|
||||
cf->data[3] < ARRAY_SIZE(protocol_violation_locations))
|
||||
n += snprintf(buf + n, len - n, "%s",
|
||||
protocol_violation_locations[cf->data[3]]);
|
||||
n += snprintf(buf + n, len - n, "}}");
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *cf,
|
||||
const char* sep)
|
||||
{
|
||||
canid_t class, mask;
|
||||
int i, n = 0, classes = 0;
|
||||
char *defsep = ",";
|
||||
|
||||
if (!(cf->can_id & CAN_ERR_FLAG))
|
||||
return;
|
||||
|
||||
class = cf->can_id & CAN_EFF_MASK;
|
||||
if (class > (1 << ARRAY_SIZE(error_classes))) {
|
||||
fprintf(stderr, "Error class %#jx is invalid\n", (uintmax_t)class);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sep)
|
||||
sep = defsep;
|
||||
|
||||
for (i = 0; i < (int)ARRAY_SIZE(error_classes); i++) {
|
||||
mask = 1 << i;
|
||||
if (class & mask) {
|
||||
if (classes)
|
||||
n += snprintf(buf + n, len - n, "%s", sep);
|
||||
n += snprintf(buf + n, len - n, "%s", error_classes[i]);
|
||||
if (mask == CAN_ERR_LOSTARB)
|
||||
n += snprintf_error_lostarb(buf + n, len - n,
|
||||
cf);
|
||||
if (mask == CAN_ERR_CRTL)
|
||||
n += snprintf_error_ctrl(buf + n, len - n, cf);
|
||||
if (mask == CAN_ERR_PROT)
|
||||
n += snprintf_error_prot(buf + n, len - n, cf);
|
||||
classes++;
|
||||
}
|
||||
}
|
||||
|
||||
if (cf->data[6] || cf->data[7]) {
|
||||
n += snprintf(buf + n, len - n, "%s", sep);
|
||||
n += snprintf(buf + n, len - n, "error-counter-tx-rx{{%d}{%d}}",
|
||||
cf->data[6], cf->data[7]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
|
||||
/*
|
||||
* lib.h - library include for command line tools
|
||||
*
|
||||
* Copyright (c) 2002-2007 Volkswagen Group Electronic Research
|
||||
* 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. Neither the name of Volkswagen nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* Alternatively, provided that this notice is retained in full, this
|
||||
* software may be distributed under the terms of the GNU General
|
||||
* Public License ("GPL") version 2, in which case the provisions of the
|
||||
* GPL apply INSTEAD OF those given above.
|
||||
*
|
||||
* The provided data structures and external interfaces from this code
|
||||
* are not restricted to be used by modules with a GPL compatible license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Send feedback to <linux-can@vger.kernel.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CAN_UTILS_LIB_H
|
||||
#define CAN_UTILS_LIB_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Compatibility for NuttX */
|
||||
typedef uint8_t __u8;
|
||||
typedef uint32_t __u32;
|
||||
|
||||
/* buffer sizes for CAN frame string representations */
|
||||
|
||||
#define CL_ID (sizeof("12345678##1"))
|
||||
#define CL_DATA sizeof(".AA")
|
||||
#define CL_BINDATA sizeof(".10101010")
|
||||
|
||||
/* CAN FD ASCII hex short representation with DATA_SEPERATORs */
|
||||
#define CL_CFSZ (2*CL_ID + 64*CL_DATA)
|
||||
|
||||
/* CAN FD ASCII hex long representation with binary output */
|
||||
#define CL_LONGCFSZ (2*CL_ID + sizeof(" [255] ") + (64*CL_BINDATA))
|
||||
|
||||
/* CAN DLC to real data length conversion helpers especially for CAN FD */
|
||||
|
||||
/* get data length from can_dlc with sanitized can_dlc */
|
||||
unsigned char can_dlc2len(unsigned char can_dlc);
|
||||
|
||||
/* map the sanitized data length to an appropriate data length code */
|
||||
unsigned char can_len2dlc(unsigned char len);
|
||||
|
||||
unsigned char asc2nibble(char c);
|
||||
/*
|
||||
* Returns the decimal value of a given ASCII hex character.
|
||||
*
|
||||
* While 0..9, a..f, A..F are valid ASCII hex characters.
|
||||
* On invalid characters the value 16 is returned for error handling.
|
||||
*/
|
||||
|
||||
int hexstring2data(char *arg, unsigned char *data, int maxdlen);
|
||||
/*
|
||||
* Converts a given ASCII hex string to a (binary) byte string.
|
||||
*
|
||||
* A valid ASCII hex string consists of an even number of up to 16 chars.
|
||||
* Leading zeros '00' in the ASCII hex string are interpreted.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* "1234" => data[0] = 0x12, data[1] = 0x34
|
||||
* "001234" => data[0] = 0x00, data[1] = 0x12, data[2] = 0x34
|
||||
*
|
||||
* Return values:
|
||||
* 0 = success
|
||||
* 1 = error (in length or the given characters are no ASCII hex characters)
|
||||
*
|
||||
* Remark: The not written data[] elements are initialized with zero.
|
||||
*
|
||||
*/
|
||||
|
||||
int parse_canframe(char *cs, struct canfd_frame *cf);
|
||||
/*
|
||||
* Transfers a valid ASCII string describing a CAN frame into struct canfd_frame.
|
||||
*
|
||||
* CAN 2.0 frames
|
||||
* - string layout <can_id>#{R{len}|data}
|
||||
* - {data} has 0 to 8 hex-values that can (optionally) be separated by '.'
|
||||
* - {len} can take values from 0 to 8 and can be omitted if zero
|
||||
* - return value on successful parsing: CAN_MTU
|
||||
*
|
||||
* CAN FD frames
|
||||
* - string layout <can_id>##<flags>{data}
|
||||
* - <flags> a single ASCII Hex value (0 .. F) which defines canfd_frame.flags
|
||||
* - {data} has 0 to 64 hex-values that can (optionally) be separated by '.'
|
||||
* - return value on successful parsing: CANFD_MTU
|
||||
*
|
||||
* Return value on detected problems: 0
|
||||
*
|
||||
* <can_id> can have 3 (standard frame format) or 8 (extended frame format)
|
||||
* hexadecimal chars
|
||||
*
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* 123# -> standard CAN-Id = 0x123, len = 0
|
||||
* 12345678# -> extended CAN-Id = 0x12345678, len = 0
|
||||
* 123#R -> standard CAN-Id = 0x123, len = 0, RTR-frame
|
||||
* 123#R0 -> standard CAN-Id = 0x123, len = 0, RTR-frame
|
||||
* 123#R7 -> standard CAN-Id = 0x123, len = 7, RTR-frame
|
||||
* 7A1#r -> standard CAN-Id = 0x7A1, len = 0, RTR-frame
|
||||
*
|
||||
* 123#00 -> standard CAN-Id = 0x123, len = 1, data[0] = 0x00
|
||||
* 123#1122334455667788 -> standard CAN-Id = 0x123, len = 8
|
||||
* 123#11.22.33.44.55.66.77.88 -> standard CAN-Id = 0x123, len = 8
|
||||
* 123#11.2233.44556677.88 -> standard CAN-Id = 0x123, len = 8
|
||||
* 32345678#112233 -> error frame with CAN_ERR_FLAG (0x2000000) set
|
||||
*
|
||||
* 123##0112233 -> CAN FD frame standard CAN-Id = 0x123, flags = 0, len = 3
|
||||
* 123##1112233 -> CAN FD frame, flags = CANFD_BRS, len = 3
|
||||
* 123##2112233 -> CAN FD frame, flags = CANFD_ESI, len = 3
|
||||
* 123##3 -> CAN FD frame, flags = (CANFD_ESI | CANFD_BRS), len = 0
|
||||
* ^^
|
||||
* CAN FD extension to handle the canfd_frame.flags content
|
||||
*
|
||||
* Simple facts on this compact ASCII CAN frame representation:
|
||||
*
|
||||
* - 3 digits: standard frame format
|
||||
* - 8 digits: extendend frame format OR error frame
|
||||
* - 8 digits with CAN_ERR_FLAG (0x2000000) set: error frame
|
||||
* - an error frame is never a RTR frame
|
||||
* - CAN FD frames do not have a RTR bit
|
||||
*/
|
||||
|
||||
void fprint_canframe(FILE *stream , struct canfd_frame *cf, char *eol, int sep, int maxdlen);
|
||||
void sprint_canframe(char *buf , struct canfd_frame *cf, int sep, int maxdlen);
|
||||
/*
|
||||
* Creates a CAN frame hexadecimal output in compact format.
|
||||
* The CAN data[] is separated by '.' when sep != 0.
|
||||
*
|
||||
* The type of the CAN frame (CAN 2.0 / CAN FD) is specified by maxdlen:
|
||||
* maxdlen = 8 -> CAN2.0 frame
|
||||
* maxdlen = 64 -> CAN FD frame
|
||||
*
|
||||
* 12345678#112233 -> extended CAN-Id = 0x12345678, len = 3, data, sep = 0
|
||||
* 12345678#R -> extended CAN-Id = 0x12345678, RTR, len = 0
|
||||
* 12345678#R5 -> extended CAN-Id = 0x12345678, RTR, len = 5
|
||||
* 123#11.22.33.44.55.66.77.88 -> standard CAN-Id = 0x123, dlc = 8, sep = 1
|
||||
* 32345678#112233 -> error frame with CAN_ERR_FLAG (0x2000000) set
|
||||
* 123##0112233 -> CAN FD frame standard CAN-Id = 0x123, flags = 0, len = 3
|
||||
* 123##2112233 -> CAN FD frame, flags = CANFD_ESI, len = 3
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* fprint_canframe(stdout, &frame, "\n", 0); // with eol to STDOUT
|
||||
* fprint_canframe(stderr, &frame, NULL, 0); // no eol to STDERR
|
||||
*
|
||||
*/
|
||||
|
||||
#define CANLIB_VIEW_ASCII 0x1
|
||||
#define CANLIB_VIEW_BINARY 0x2
|
||||
#define CANLIB_VIEW_SWAP 0x4
|
||||
#define CANLIB_VIEW_ERROR 0x8
|
||||
#define CANLIB_VIEW_INDENT_SFF 0x10
|
||||
|
||||
#define SWAP_DELIMITER '`'
|
||||
|
||||
void fprint_long_canframe(FILE *stream , struct canfd_frame *cf, char *eol, int view, int maxdlen);
|
||||
void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxdlen);
|
||||
/*
|
||||
* Creates a CAN frame hexadecimal output in user readable format.
|
||||
*
|
||||
* The type of the CAN frame (CAN 2.0 / CAN FD) is specified by maxdlen:
|
||||
* maxdlen = 8 -> CAN2.0 frame
|
||||
* maxdlen = 64 -> CAN FD frame
|
||||
*
|
||||
* 12345678 [3] 11 22 33 -> extended CAN-Id = 0x12345678, dlc = 3, data
|
||||
* 12345678 [0] remote request -> extended CAN-Id = 0x12345678, RTR
|
||||
* 14B0DC51 [8] 4A 94 E8 2A EC 58 55 62 'J..*.XUb' -> (with ASCII output)
|
||||
* 20001111 [7] C6 23 7B 32 69 98 3C ERRORFRAME -> (CAN_ERR_FLAG set)
|
||||
* 12345678 [03] 11 22 33 -> CAN FD with extended CAN-Id = 0x12345678, dlc = 3
|
||||
*
|
||||
* 123 [3] 11 22 33 -> CANLIB_VIEW_INDENT_SFF == 0
|
||||
* 123 [3] 11 22 33 -> CANLIB_VIEW_INDENT_SFF == set
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // CAN FD frame with eol to STDOUT
|
||||
* fprint_long_canframe(stdout, &frame, "\n", 0, CANFD_MAX_DLEN);
|
||||
*
|
||||
* // CAN 2.0 frame without eol to STDERR
|
||||
* fprint_long_canframe(stderr, &frame, NULL, 0, CAN_MAX_DLEN);
|
||||
*
|
||||
*/
|
||||
|
||||
void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *cf,
|
||||
const char *sep);
|
||||
/*
|
||||
* Creates a CAN error frame output in user readable format.
|
||||
*/
|
||||
|
||||
#endif
|
|
@ -0,0 +1,95 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
|
||||
/*
|
||||
* Copyright (c) 2002-2007 Volkswagen Group Electronic Research
|
||||
* 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. Neither the name of Volkswagen nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* Alternatively, provided that this notice is retained in full, this
|
||||
* software may be distributed under the terms of the GNU General
|
||||
* Public License ("GPL") version 2, in which case the provisions of the
|
||||
* GPL apply INSTEAD OF those given above.
|
||||
*
|
||||
* The provided data structures and external interfaces from this code
|
||||
* are not restricted to be used by modules with a GPL compatible license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Send feedback to <linux-can@vger.kernel.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TERMINAL_H
|
||||
#define TERMINAL_H
|
||||
|
||||
/* reset to default */
|
||||
|
||||
#define ATTRESET "\33[0m"
|
||||
|
||||
/* attributes */
|
||||
|
||||
#define ATTBOLD "\33[1m"
|
||||
#define ATTUNDERLINE "\33[4m"
|
||||
#define ATTBLINK "\33[5m"
|
||||
#define ATTINVERSE "\33[7m"
|
||||
#define ATTINVISIBLE "\33[8m"
|
||||
|
||||
/* foreground colors */
|
||||
|
||||
#define FGBLACK "\33[30m"
|
||||
#define FGRED "\33[31m"
|
||||
#define FGGREEN "\33[32m"
|
||||
#define FGYELLOW "\33[33m"
|
||||
#define FGBLUE "\33[34m"
|
||||
#define FGMAGENTA "\33[35m"
|
||||
#define FGCYAN "\33[36m"
|
||||
#define FGWHITE "\33[37m"
|
||||
|
||||
/* background colors */
|
||||
|
||||
#define BGBLACK "\33[40m"
|
||||
#define BGRED "\33[41m"
|
||||
#define BGGREEN "\33[42m"
|
||||
#define BGYELLOW "\33[43m"
|
||||
#define BGBLUE "\33[44m"
|
||||
#define BGMAGENTA "\33[45m"
|
||||
#define BGCYAN "\33[46m"
|
||||
#define BGWHITE "\33[47m"
|
||||
|
||||
/* cursor */
|
||||
|
||||
#define CSR_HOME "\33[H"
|
||||
#define CSR_UP "\33[A"
|
||||
#define CSR_DOWN "\33[B"
|
||||
#define CSR_RIGHT "\33[C"
|
||||
#define CSR_LEFT "\33[D"
|
||||
|
||||
#define CSR_HIDE "\33[?25l"
|
||||
#define CSR_SHOW "\33[?25h"
|
||||
|
||||
/* clear screen */
|
||||
|
||||
#define CLR_SCREEN "\33[2J"
|
||||
|
||||
#endif /* TERMINAL_H */
|
|
@ -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
|
|
@ -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 += $(APPDIR)/canutils/libobd2
|
||||
endif
|
|
@ -0,0 +1,42 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# CAN utility library
|
||||
|
||||
CSRCS = obd2.c obd_sendrequest.c obd_waitresponse.c obd_decodepid.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config CANUTILS_SLCAN
|
||||
tristate "SocketCAN slcan tool"
|
||||
default n
|
||||
depends on NET_CAN
|
||||
---help---
|
||||
Enable the SocketCAN slcan tool
|
||||
|
||||
if CANUTILS_SLCAN
|
||||
|
||||
config SLCAN_TRACE
|
||||
bool "Print trace output"
|
||||
default y
|
||||
---help---
|
||||
Debug trace output
|
||||
|
||||
endif
|
|
@ -0,0 +1,24 @@
|
|||
############################################################################
|
||||
# apps/canutils/slcan/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_CANUTILS_SLCAN),)
|
||||
CONFIGURED_APPS += $(APPDIR)/canutils/slcan
|
||||
endif
|
|
@ -0,0 +1,34 @@
|
|||
############################################################################
|
||||
# apps/canutils/slcan/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(APPDIR)/Make.defs
|
||||
|
||||
# Network packet socket example
|
||||
|
||||
PROGNAME = slcan
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 3048
|
||||
MODULE = $(CONFIG_CANUTILS_SLCAN)
|
||||
|
||||
CSRCS =
|
||||
|
||||
MAINSRC = slcan.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,504 @@
|
|||
/****************************************************************************
|
||||
* apps/canutils/slcan/slcan.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <sched.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/uio.h>
|
||||
#include <net/if.h>
|
||||
#include <termios.h>
|
||||
#include <nuttx/can.h>
|
||||
#include <netpacket/can.h>
|
||||
|
||||
#include "slcan.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Defines
|
||||
****************************************************************************/
|
||||
|
||||
#define DEFAULT_PRIORITY 100
|
||||
#define DEFAULT_STACK_SIZE 2048
|
||||
|
||||
#ifdef CONFIG_SLCAN_TRACE
|
||||
# define DEBUG 1
|
||||
#else
|
||||
# define DEBUG 0
|
||||
#endif
|
||||
|
||||
#define debug_print(fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (DEBUG) \
|
||||
syslog(LOG_DEBUG, fmt, ##__VA_ARGS__); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/****************************************************************************
|
||||
* private data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SLCAN_TRACE
|
||||
static char opening[] = "starting slcan\n";
|
||||
#else
|
||||
static char opening[] = "";
|
||||
#endif
|
||||
|
||||
static void ok_return(int fd)
|
||||
{
|
||||
write(fd, "\r", 1);
|
||||
}
|
||||
|
||||
static void fail_return(int fd)
|
||||
{
|
||||
write(fd, "\a", 1); /* BELL return for error */
|
||||
}
|
||||
|
||||
static int readlinebuffer(int fd, char *buf, int maxlen)
|
||||
{
|
||||
size_t n;
|
||||
int meslen = 0;
|
||||
int noeol = 1;
|
||||
uint8_t ch;
|
||||
|
||||
while ((meslen < maxlen) && noeol)
|
||||
{
|
||||
n = read(fd, &ch, 1);
|
||||
if (n > 0)
|
||||
{
|
||||
/* valid input */
|
||||
|
||||
if (ch == '\r')
|
||||
{
|
||||
noeol = 0;
|
||||
*buf = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
*buf++ = ch;
|
||||
meslen++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (meslen);
|
||||
}
|
||||
}
|
||||
return (meslen);
|
||||
}
|
||||
|
||||
static int caninit(char *candev, int *s, struct sockaddr_can *addr,
|
||||
char *ctrlmsg, struct canfd_frame *frame,
|
||||
struct msghdr *msg, struct iovec *iov)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
debug_print("slcanBus\n");
|
||||
if ((*s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Error opening CAN socket\n");
|
||||
return -1;
|
||||
}
|
||||
strncpy(ifr.ifr_name, candev, 4);
|
||||
ifr.ifr_name[4] = '\0';
|
||||
ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
|
||||
if (!ifr.ifr_ifindex)
|
||||
{
|
||||
syslog(LOG_ERR, "error finding index %s\n", candev);
|
||||
return -1;
|
||||
}
|
||||
memset(addr, 0, sizeof(struct sockaddr));
|
||||
addr->can_family = AF_CAN;
|
||||
addr->can_ifindex = ifr.ifr_ifindex;
|
||||
setsockopt(*s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
|
||||
|
||||
if (bind(*s, (struct sockaddr *)addr, sizeof(struct sockaddr)) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "bind error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
iov->iov_base = frame;
|
||||
msg->msg_name = addr;
|
||||
msg->msg_iov = iov;
|
||||
msg->msg_iovlen = 1;
|
||||
msg->msg_control = ctrlmsg;
|
||||
|
||||
/* CAN interface ready to be used */
|
||||
|
||||
debug_print("CAN socket open\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: slcan_main
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* UART */
|
||||
|
||||
char buf[31];
|
||||
int mode = 0;
|
||||
size_t n;
|
||||
int canspeed = 1000000; /* default to 1MBps */
|
||||
int fd; /* UART slcan channel */
|
||||
|
||||
/* CAN */
|
||||
|
||||
int s, nbytes, i, ret, reccount;
|
||||
struct sockaddr_can addr;
|
||||
struct canfd_frame frame;
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
fd_set rdfs;
|
||||
char ctrlmsg[CMSG_SPACE(sizeof(struct timeval) +
|
||||
3 * sizeof(struct timespec) + sizeof(int))];
|
||||
char sbuf[40], *sbp;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
fprintf(stderr, "Usage: slcan <can device> <uart device>\n");
|
||||
fflush(stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *chrdev = argv[2];
|
||||
char *candev = argv[1];
|
||||
|
||||
debug_print("Starting slcan on NuttX\n");
|
||||
fd = open(chrdev, O_RDWR | O_BINARY);
|
||||
if (fd < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to open serial channel %s\n", chrdev);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Create CAN socket */
|
||||
|
||||
if (caninit(candev, &s, &addr, &ctrlmsg[0], &frame, &msg, &iov) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to open CAN socket %s\n", candev);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* serial interface active */
|
||||
|
||||
debug_print("Serial interface open %s\n", chrdev);
|
||||
write(fd, opening, (sizeof(opening) - 1));
|
||||
|
||||
while (mode < 100)
|
||||
{
|
||||
/* Setup ooll */
|
||||
|
||||
FD_ZERO(&rdfs);
|
||||
FD_SET(s, &rdfs); /* CAN Socket */
|
||||
FD_SET(fd, &rdfs); /* UART */
|
||||
|
||||
if ((ret = select(s + 1, &rdfs, NULL, NULL, NULL)) <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FD_ISSET(s, &rdfs))
|
||||
{
|
||||
/* CAN received new message in socketCAN input */
|
||||
|
||||
iov.iov_len = sizeof(frame);
|
||||
msg.msg_namelen = sizeof(addr);
|
||||
msg.msg_controllen = sizeof(ctrlmsg);
|
||||
msg.msg_flags = 0;
|
||||
nbytes = recvmsg(s, &msg, 0);
|
||||
|
||||
if (nbytes == CAN_MTU)
|
||||
{
|
||||
reccount++;
|
||||
debug_print("R%d, Id:0x%X\n", reccount, frame.can_id);
|
||||
if (frame.can_id & CAN_EFF_FLAG)
|
||||
{
|
||||
/* 29 bit address */
|
||||
|
||||
frame.can_id = frame.can_id & ~CAN_EFF_FLAG;
|
||||
sprintf(sbuf, "T%08X%d", frame.can_id, frame.len);
|
||||
sbp = &sbuf[10];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 11 bit address */
|
||||
|
||||
sprintf(sbuf, "t%03X%d", frame.can_id, frame.len);
|
||||
sbp = &sbuf[5];
|
||||
}
|
||||
|
||||
for (i = 0; i < frame.len; i++)
|
||||
{
|
||||
sprintf(sbp, "%02X", frame.data[i]);
|
||||
sbp += 2;
|
||||
}
|
||||
|
||||
*sbp++ = '\r';
|
||||
*sbp = '\0';
|
||||
write(fd, sbuf, strlen(sbuf));
|
||||
}
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd, &rdfs))
|
||||
{
|
||||
/* UART receive */
|
||||
|
||||
n = readlinebuffer(fd, buf, 30);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 0: /* CAN channel not open */
|
||||
if (n > 0)
|
||||
{
|
||||
if (buf[0] == 'F')
|
||||
{
|
||||
/* return clear flags */
|
||||
|
||||
write(fd, "F00\r", 4);
|
||||
}
|
||||
else if (buf[0] == 'O')
|
||||
{
|
||||
/* open CAN interface */
|
||||
|
||||
mode = 1;
|
||||
debug_print("Open interface\n");
|
||||
ok_return(fd);
|
||||
}
|
||||
else if (buf[0] == 'S')
|
||||
{
|
||||
/* set CAN interface speed */
|
||||
|
||||
switch (buf[1])
|
||||
{
|
||||
case '0':
|
||||
canspeed = 10000;
|
||||
break;
|
||||
case '1':
|
||||
canspeed = 20000;
|
||||
break;
|
||||
case '2':
|
||||
canspeed = 50000;
|
||||
break;
|
||||
case '3':
|
||||
canspeed = 100000;
|
||||
break;
|
||||
case '4':
|
||||
canspeed = 125000;
|
||||
break;
|
||||
case '5':
|
||||
canspeed = 250000;
|
||||
break;
|
||||
case '6':
|
||||
canspeed = 500000;
|
||||
break;
|
||||
case '7':
|
||||
canspeed = 800000;
|
||||
break;
|
||||
case '8': /* set speed to 1Mbps */
|
||||
canspeed = 1000000;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
struct ifreq ifr;
|
||||
|
||||
/* set the device name */
|
||||
|
||||
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1);
|
||||
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
|
||||
|
||||
ifr.ifr_ifru.ifru_can_data.arbi_bitrate =
|
||||
canspeed / 1000; /* Convert bit/s to kbit/s */
|
||||
ifr.ifr_ifru.ifru_can_data.arbi_samplep = 80;
|
||||
|
||||
if (ioctl(s, SIOCSCANBITRATE, &ifr) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "set speed %d failed\n",
|
||||
canspeed);
|
||||
fail_return(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug_print("set speed %d\n", canspeed);
|
||||
ok_return(fd);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* whatever */
|
||||
|
||||
ok_return(fd);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1: /* CAN task running open interface */
|
||||
if (n > 0)
|
||||
{
|
||||
if (buf[0] == 'C')
|
||||
{
|
||||
/* close interface */
|
||||
|
||||
mode = 0;
|
||||
debug_print("Close interface\n");
|
||||
ok_return(fd);
|
||||
}
|
||||
else if (buf[0] == 'T')
|
||||
{
|
||||
/* Transmit an extended 29 bit CAN frame */
|
||||
|
||||
char tbuf[9];
|
||||
int idval, val;
|
||||
|
||||
/* get 29bit CAN ID */
|
||||
|
||||
strncpy(tbuf, &buf[1], 8);
|
||||
tbuf[8] = '\0';
|
||||
sscanf(tbuf, "%x", &idval);
|
||||
|
||||
frame.len = buf[9] - '0'; /* get byte count */
|
||||
|
||||
/* get canmessage */
|
||||
|
||||
for (i = 0; i < frame.len; i++)
|
||||
{
|
||||
tbuf[0] = buf[10 + (2 * i)];
|
||||
tbuf[1] = buf[11 + (2 * i)];
|
||||
tbuf[2] = '\0';
|
||||
sscanf(tbuf, "%x", &val);
|
||||
frame.data[i] = val & 0xff;
|
||||
}
|
||||
|
||||
debug_print("Transmitt: 0x%X ", idval);
|
||||
for (i = 0; i < frame.len; i++)
|
||||
{
|
||||
debug_print("0x%02X ", frame.data[i]);
|
||||
}
|
||||
|
||||
debug_print("\n");
|
||||
|
||||
frame.can_id = idval | CAN_EFF_FLAG; /* 29 bit */
|
||||
|
||||
if (write(s, &frame, CAN_MTU) != CAN_MTU)
|
||||
{
|
||||
syslog(LOG_ERR, "transmitt error\n");
|
||||
|
||||
/* TODO update error flags */
|
||||
}
|
||||
|
||||
ok_return(fd);
|
||||
}
|
||||
else if (buf[0] == 't')
|
||||
{
|
||||
/* Transmit an 11 bit CAN frame */
|
||||
|
||||
char tbuf[9];
|
||||
int idval, val;
|
||||
|
||||
/* get 11bit CAN ID */
|
||||
|
||||
strncpy(tbuf, &buf[1], 3);
|
||||
tbuf[3] = '\0';
|
||||
sscanf(tbuf, "%x", &idval);
|
||||
|
||||
frame.len = buf[4] - '0'; /* get byte count */
|
||||
|
||||
/* get canmessage */
|
||||
|
||||
for (i = 0; i < frame.len; i++)
|
||||
{
|
||||
tbuf[0] = buf[5 + (2 * i)];
|
||||
tbuf[1] = buf[6 + (2 * i)];
|
||||
tbuf[2] = '\0';
|
||||
sscanf(tbuf, "%x", &val);
|
||||
frame.data[i] = val & 0xff;
|
||||
}
|
||||
|
||||
debug_print("Transmitt: 0x%X ", idval);
|
||||
for (i = 0; i < frame.len; i++)
|
||||
{
|
||||
debug_print("0x%02X ", frame.data[i]);
|
||||
}
|
||||
|
||||
debug_print("\n");
|
||||
|
||||
frame.can_id = idval; /* 11 bit address command */
|
||||
|
||||
if (write(s, &frame, CAN_MTU) != CAN_MTU)
|
||||
{
|
||||
syslog(LOG_ERR, "transmitt error\n");
|
||||
|
||||
/* TODO update error flags */
|
||||
}
|
||||
|
||||
ok_return(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* whatever */
|
||||
|
||||
ok_return(fd);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: /* should not happen */
|
||||
mode = 100;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
close(s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/****************************************************************************
|
||||
* apps/canutils/slcan/slcan.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef SLCAN_H
|
||||
#define SLCAN_H
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* S6 - CAN speed 500 kBit/s
|
||||
* S8 - CAN speed 1 Mbit/s
|
||||
* O - open channel
|
||||
* C - close channel
|
||||
* C
|
||||
* S8
|
||||
* O
|
||||
* F -> return status flags
|
||||
*/
|
||||
#define SLCAN_REC_FIFO_FULL (1 << 0)
|
||||
#define SLCAN_SND_FIFO_FULL (1 << 1)
|
||||
#define SLCAN_ERROR_WARN (1 << 2)
|
||||
#define SLCAN_DATA_OVERRUN (1 << 3)
|
||||
#define SLCAN_ERROR_PASSIVE (1 << 5)
|
||||
#define SLCAN_ARBITRATION_LOST (1 << 6)
|
||||
#define SLCAN_BUS_ERROR (1 << 7)
|
||||
|
||||
#endif /* SLCAN_H */
|
|
@ -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 $(APPDIR)/examples/*/Make.defs)
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -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_ABNTCODI
|
||||
tristate "ABNT CODI example"
|
||||
default n
|
||||
select INDUSTRY_ABNT_CODI_LIB
|
||||
---help---
|
||||
Enable the ABNT CODI test example
|
||||
|
||||
if EXAMPLES_ABNTCODI
|
||||
|
||||
config EXAMPLES_ABNTCODI_PROGNAME
|
||||
string "Program name"
|
||||
default "abntcodi"
|
||||
---help---
|
||||
This is the name of the program that will be used when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_ABNTCODI_PRIORITY
|
||||
int "ABNTCODI task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_ABNTCODI_STACKSIZE
|
||||
int "ABNTCODI stack size"
|
||||
default DEFAULT_TASK_STACKSIZE
|
||||
|
||||
endif
|
|
@ -0,0 +1,39 @@
|
|||
############################################################################
|
||||
# apps/examples/abntcodi/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2019 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_ABNTCODI),)
|
||||
CONFIGURED_APPS += $(APPDIR)/examples/abntcodi
|
||||
endif
|
|
@ -0,0 +1,49 @@
|
|||
############################################################################
|
||||
# apps/examples/abntcodi/Makefile
|
||||
#
|
||||
# Copyright (C) 2019 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 $(APPDIR)/Make.defs
|
||||
|
||||
# ABNTCODI built-in application info
|
||||
|
||||
PROGNAME = $(CONFIG_EXAMPLES_ABNTCODI_PROGNAME)
|
||||
PRIORITY = $(CONFIG_EXAMPLES_ABNTCODI_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_ABNTCODI_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_ABNTCODI)
|
||||
|
||||
# ABNTCODI Example
|
||||
|
||||
MAINSRC = abntcodi_main.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,144 @@
|
|||
/****************************************************************************
|
||||
* examples/hello/abntcodi_main.c
|
||||
*
|
||||
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
|
||||
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* 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 <fcntl.h>
|
||||
#include <syslog.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "industry/abnt_codi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
void print_abnt_codi(FAR struct abnt_codi_proto_s *proto)
|
||||
{
|
||||
printf("Seconds missing to end of the active demand: %d\n",
|
||||
proto->end_act_dem);
|
||||
printf("Current Bill Indicator: %d\n", proto->bill_indicator);
|
||||
printf("Reactive Interval Indicator: %d\n", proto->react_interval);
|
||||
printf("Capacitive Reactive Pulses are used to calculate consumption: %s\n",
|
||||
boolstr(proto->react_cap_pulse));
|
||||
printf("Inductive Reactive Pulses are used to calculate consumption: %s\n",
|
||||
boolstr(proto->react_ind_pulse));
|
||||
printf("Segment type: %s\n",
|
||||
proto->segment_type == SEGMENT_PEEK ? "PEEK" :
|
||||
proto->segment_type == SEGMENT_OUT_PEEK ? "OUT OF PEEK" :
|
||||
proto->segment_type == SEGMENT_RESERVED ? "RESERVED" : "UNKNOWN");
|
||||
printf("Charges type: %s\n",
|
||||
proto->charge_type == CHARGES_BLUE ? "BLUE" :
|
||||
proto->charge_type == CHARGES_GREEN ? "GREEN" :
|
||||
proto->charge_type == CHARGES_IRRIGATORS ? "IRRIGATORS" : "OTHERS");
|
||||
printf("Number of Active pulses since the beginning of current demand: %d\n",
|
||||
proto->pulses_act_dem);
|
||||
printf("Number of Reactive pulses since beginning of current demand: %d\n",
|
||||
proto->pulses_react_dem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* abntcodi_main
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
FAR struct abnt_codi_proto_s *proto;
|
||||
int fd;
|
||||
int cnt;
|
||||
int ret;
|
||||
uint8_t byte;
|
||||
uint8_t data[8];
|
||||
|
||||
/* Allocate memory to protocol struct */
|
||||
|
||||
proto = malloc(sizeof(struct abnt_codi_proto_s));
|
||||
if (!proto)
|
||||
{
|
||||
printf("Failed to allocate memory to abnt_codi_proto_s!\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Open the serial port used to read ABNT CODI (Baudrate: 110bps) */
|
||||
|
||||
fd = open("/dev/ttyS1", O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("Unable to open file /dev/ttyS1\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Run forever */
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
/* Read until we complete a sequence of 8 bytes */
|
||||
|
||||
cnt = 0;
|
||||
do
|
||||
{
|
||||
ret = read(fd, &byte, 1);
|
||||
if (ret != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
data[cnt++] = byte;
|
||||
}
|
||||
while (cnt < 8);
|
||||
|
||||
/* Parse the received data */
|
||||
|
||||
if (abnt_codi_parse(data, proto))
|
||||
{
|
||||
print_abnt_codi(proto);
|
||||
}
|
||||
|
||||
/* Avoid busy wait using 100% CPU cycles */
|
||||
|
||||
usleep(5000000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# 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
|
||||
---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
|
||||
---help---
|
||||
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
|
|
@ -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 += $(APPDIR)/examples/adc
|
||||
endif
|
|
@ -0,0 +1,49 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# ADC example
|
||||
|
||||
MAINSRC = adc_main.c
|
||||
|
||||
# application info
|
||||
|
||||
PROGNAME = adc
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_ADC)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,90 @@
|
|||
/****************************************************************************
|
||||
* 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 - 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;
|
||||
int count;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __APPS_EXAMPLES_ADC_ADC_H */
|
|
@ -0,0 +1,358 @@
|
|||
/****************************************************************************
|
||||
* 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
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
****************************************************************************/
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arg_string
|
||||
****************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arg_decimal
|
||||
****************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: parse_args
|
||||
****************************************************************************/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: adc_main
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
g_adcstate.count = CONFIG_EXAMPLES_ADC_NSAMPLES;
|
||||
|
||||
/* Parse the command line */
|
||||
|
||||
parse_args(&g_adcstate, argc, argv);
|
||||
|
||||
/* 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
|
||||
*/
|
||||
|
||||
printf("adc_main: g_adcstate.count: %d\n", g_adcstate.count);
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
/* 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: %" PRId32 "\n",
|
||||
i + 1, sample[i].am_channel, sample[i].am_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (g_adcstate.count && --g_adcstate.count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return OK;
|
||||
|
||||
/* Error exits */
|
||||
|
||||
errout_with_dev:
|
||||
close(fd);
|
||||
|
||||
errout:
|
||||
printf("Terminating!\n");
|
||||
fflush(stdout);
|
||||
return errval;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#
|
||||
# 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"
|
||||
---help---
|
||||
This is the name of the program that will be used 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 DEFAULT_TASK_STACKSIZE
|
||||
|
||||
endif
|
|
@ -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 += $(APPDIR)/examples/adxl372_test
|
||||
endif
|
|
@ -0,0 +1,47 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
PROGNAME = $(CONFIG_EXAMPLES_ADXL372_TEST_PROGNAME)
|
||||
PRIORITY = $(CONFIG_EXAMPLES_ADXL372_TEST_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_ADXL372_TEST_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_ADXL372_TEST)
|
||||
|
||||
# ADXL372 sensor test Example
|
||||
|
||||
MAINSRC = adxl372_test_main.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,560 @@
|
|||
/****************************************************************************
|
||||
* 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>
|
||||
#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
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
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[ARRAYSIZE(test_ptr_array)];
|
||||
|
||||
if (argc < 1 || *argv[1] == 0 || *(argv[1] + 1) == 0)
|
||||
{
|
||||
goto print_help;
|
||||
}
|
||||
|
||||
/* We have at least 1 parameter which 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 >= ARRAYSIZE(test_ptr_array))
|
||||
{
|
||||
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 < ARRAYSIZE(test_ptr_array); 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 for the ADXL372 accelerometer\n");
|
||||
printf(" Example:\n");
|
||||
printf(" adxl372_test -b /dev/adxl372_0\n");
|
||||
return RC_INVALPARM;
|
||||
}
|
|
@ -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 INPUT_AJOYSTICK
|
||||
---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
|
|
@ -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 += $(APPDIR)/examples/ajoystick
|
||||
endif
|
|
@ -0,0 +1,49 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# Hello, World! Example
|
||||
|
||||
MAINSRC = ajoy_main.c
|
||||
|
||||
# Buttons built-in application info
|
||||
|
||||
PROGNAME = ajoy
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_AJOYSTICK)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,458 @@
|
|||
/****************************************************************************
|
||||
* 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 */
|
||||
|
||||
sigemptyset(&set);
|
||||
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
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
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_event.sigev_notify = SIGEV_SIGNAL;
|
||||
notify.an_event.sigev_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. */
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_nsec = 600*1000*1000;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# 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"
|
||||
---help---
|
||||
This is the name of the program that will be used 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 DEFAULT_TASK_STACKSIZE
|
||||
|
||||
config EXAMPLES_ALARM_DEVPATH
|
||||
string "RTC device path"
|
||||
default "/dev/rtc0"
|
||||
|
||||
config EXAMPLES_ALARM_SIGNO
|
||||
int "Alarm signal"
|
||||
default 1
|
||||
|
||||
endif # EXAMPLES_ALARM
|
|
@ -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 += $(APPDIR)/examples/alarm
|
||||
endif
|
|
@ -0,0 +1,49 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# RTC driver alarm test built-in application info
|
||||
|
||||
PROGNAME = $(CONFIG_EXAMPLES_ALARM_PROGNAME)
|
||||
PRIORITY = $(CONFIG_EXAMPLES_ALARM_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_ALARM_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_ALARM)
|
||||
|
||||
# RTC driver alarm test
|
||||
|
||||
MAINSRC = alarm_main.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,421 @@
|
|||
/****************************************************************************
|
||||
* 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 */
|
||||
|
||||
sigemptyset(&set);
|
||||
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;
|
||||
|
||||
sigfillset(&act.sa_mask);
|
||||
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 cause 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
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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.pid = g_alarm_daemon_pid;
|
||||
setrel.reltime = (time_t)seconds;
|
||||
|
||||
setrel.event.sigev_notify = SIGEV_SIGNAL;
|
||||
setrel.event.sigev_signo = CONFIG_EXAMPLES_ALARM_SIGNO;
|
||||
setrel.event.sigev_value.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);
|
||||
|
||||
close(fd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Alarm %d set in %lu seconds\n", alarmid, seconds);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# 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"
|
||||
---help---
|
||||
This is the name of the program that will be used when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
endif
|
|
@ -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 += $(APPDIR)/examples/apa102
|
||||
endif
|
|
@ -0,0 +1,49 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# APA102 built-in application info
|
||||
|
||||
PROGNAME = $(CONFIG_EXAMPLES_APA102_PROGNAME)
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_APA102)
|
||||
|
||||
# APA102 Test
|
||||
|
||||
MAINSRC = apa102_main.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,192 @@
|
|||
/****************************************************************************
|
||||
* 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
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
#
|
||||
# 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"
|
||||
---help---
|
||||
This is the name of the program that will be used 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 DEFAULT_TASK_STACKSIZE
|
||||
|
||||
endif
|
|
@ -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 += $(APPDIR)/examples/apds9960
|
||||
endif
|
|
@ -0,0 +1,49 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# Hello, World! built-in application info
|
||||
|
||||
PROGNAME = $(CONFIG_EXAMPLES_APDS9960_PROGNAME)
|
||||
PRIORITY = $(CONFIG_EXAMPLES_APDS9960_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_APDS9960_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_APDS9960)
|
||||
|
||||
# Hello, World! Example
|
||||
|
||||
MAINSRC = apds9960_main.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,116 @@
|
|||
/****************************************************************************
|
||||
* 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
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_AUDIO_SOUND
|
||||
bool "Audio tone generator example (RTTL player)"
|
||||
default n
|
||||
---help---
|
||||
Enable the audio RTTL player example
|
||||
|
||||
if EXAMPLES_AUDIO_SOUND
|
||||
|
||||
config EXAMPLES_AUDIO_SOUND_PROGNAME
|
||||
string "Program name"
|
||||
default "audio_rttl"
|
||||
|
||||
config EXAMPLES_AUDIO_SOUND_PRIORITY
|
||||
int "Audio sound task priority"
|
||||
default 150
|
||||
|
||||
config EXAMPLES_AUDIO_SOUND_STACKSIZE
|
||||
int "Audio sound stack size"
|
||||
default DEFAULT_TASK_STACKSIZE
|
||||
|
||||
endif
|
|
@ -0,0 +1,38 @@
|
|||
############################################################################
|
||||
# audio_player/Make.defs
|
||||
#
|
||||
# Copyright 2018 Sony Semiconductor Solutions Corporation
|
||||
#
|
||||
# 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 of Sony Semiconductor Solutions Corporation nor
|
||||
# the names of its contributors may be used to endorse or promote
|
||||
# products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_AUDIO_SOUND),y)
|
||||
CONFIGURED_APPS += examples/audio_rttl
|
||||
endif
|
|
@ -0,0 +1,58 @@
|
|||
############################################################################
|
||||
# audio_beep/Makefile
|
||||
#
|
||||
# Copyright 2018 Sony Semiconductor Solutions Corporation
|
||||
#
|
||||
# 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 of Sony Semiconductor Solutions Corporation 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
|
||||
-include $(SDKDIR)/Make.defs
|
||||
|
||||
# Audio application info
|
||||
|
||||
PROGNAME = $(CONFIG_EXAMPLES_AUDIO_SOUND_PROGNAME)
|
||||
PRIORITY = $(CONFIG_EXAMPLES_AUDIO_SOUND_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_AUDIO_SOUND_STACKSIZE)
|
||||
|
||||
# Audio Example
|
||||
|
||||
MAINSRC = audio_rttl.cxx
|
||||
|
||||
# Audio Example paths
|
||||
|
||||
AUDIODIR = $(SDKDIR)$(DELIM)modules$(DELIM)audio
|
||||
|
||||
# Audio Example flags
|
||||
|
||||
CXXFLAGS += ${shell $(INCDIR) "$(CC)" "$(AUDIODIR)"}
|
||||
CXXFLAGS += -D_POSIX
|
||||
|
||||
include $(APPDIR)/Application.mk
|
|
@ -0,0 +1,374 @@
|
|||
/****************************************************************************
|
||||
* audio_rttl/audio_rttl.cxx
|
||||
*
|
||||
* Copyright 2019 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* 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 of Sony Semiconductor Solutions Corporation 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 <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <arch/board/board.h>
|
||||
#include <arch/chip/audio.h>
|
||||
|
||||
#include "audio_rttl.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Note - note freq on octave 1 */
|
||||
|
||||
#define C 16.35
|
||||
#define CD 17.32
|
||||
#define D 18.35
|
||||
#define DE 19.45
|
||||
#define E 20.60
|
||||
#define F 21.83
|
||||
#define FG 23.12
|
||||
#define G 24.50
|
||||
#define A 27.50
|
||||
#define AB 29.14
|
||||
#define B 30.84
|
||||
|
||||
/* Octave - base freq multiplier for the base freq */
|
||||
|
||||
#define OCT2 4
|
||||
#define OCT3 8
|
||||
#define OCT4 16
|
||||
#define OCT5 32
|
||||
#define OCT6 64
|
||||
#define OCT7 128
|
||||
#define OCT8 256
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
int freq;
|
||||
float base_freq;
|
||||
char temp_note;
|
||||
int octave;
|
||||
int duration;
|
||||
int note_duration;
|
||||
int base_duration;
|
||||
int bpm;
|
||||
int cnt;
|
||||
|
||||
/* Set I/O parameters for power on. */
|
||||
|
||||
if (!board_audio_power_control(true))
|
||||
{
|
||||
printf("Error: board_audio_power_control() failure.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Start Audio RTTL player\n");
|
||||
|
||||
bpm = 0;
|
||||
octave = 0;
|
||||
base_duration = 0;
|
||||
note_duration = 0;
|
||||
|
||||
while (*g_song != ':')
|
||||
{
|
||||
g_song++;
|
||||
}
|
||||
|
||||
g_song++;
|
||||
|
||||
if (*g_song == 'd')
|
||||
{
|
||||
g_song = g_song + 2;
|
||||
base_duration = *g_song - '0';
|
||||
g_song++;
|
||||
if ((*g_song >= '0') && (*g_song <= '9'))
|
||||
{
|
||||
base_duration = (base_duration * 10) + (*g_song - '0');
|
||||
g_song++;
|
||||
}
|
||||
|
||||
g_song++;
|
||||
}
|
||||
|
||||
if (*g_song == 'o')
|
||||
{
|
||||
g_song = g_song + 2;
|
||||
octave = *g_song - '0';
|
||||
g_song = g_song + 2;
|
||||
}
|
||||
|
||||
if (octave == 2)
|
||||
{
|
||||
octave = OCT2;
|
||||
}
|
||||
else if (octave == 3)
|
||||
{
|
||||
octave = OCT3;
|
||||
}
|
||||
else if (octave == 4)
|
||||
{
|
||||
octave = OCT4;
|
||||
}
|
||||
else if (octave == 5)
|
||||
{
|
||||
octave = OCT5;
|
||||
}
|
||||
else if (octave == 6)
|
||||
{
|
||||
octave = OCT6;
|
||||
}
|
||||
else if (octave == 7)
|
||||
{
|
||||
octave = OCT7;
|
||||
}
|
||||
else if (octave == 8)
|
||||
{
|
||||
octave = OCT8;
|
||||
}
|
||||
|
||||
if (*g_song == 'b')
|
||||
{
|
||||
g_song = g_song + 2;
|
||||
bpm = 0;
|
||||
for (cnt = 1; cnt <= 3; cnt++)
|
||||
{
|
||||
if (*g_song != ':')
|
||||
{
|
||||
bpm = bpm * 10 + (*g_song - '0');
|
||||
g_song++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
g_song++;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if ((*g_song >= '0') && (*g_song <= '9'))
|
||||
{
|
||||
note_duration = *g_song - '0';
|
||||
g_song++;
|
||||
}
|
||||
|
||||
if ((*g_song >= '0') && (*g_song <= '9'))
|
||||
{
|
||||
note_duration = (note_duration * 10) + (*g_song - '0');
|
||||
g_song++;
|
||||
}
|
||||
|
||||
if (note_duration > 0)
|
||||
{
|
||||
duration = ((60 * 1000L / bpm) * 4) / note_duration;
|
||||
}
|
||||
else
|
||||
{
|
||||
duration = ((60 * 1000L / bpm) * 4) / base_duration;
|
||||
}
|
||||
|
||||
base_freq = 0;
|
||||
temp_note = ' ';
|
||||
switch (*g_song)
|
||||
{
|
||||
case 'c':
|
||||
{
|
||||
temp_note = 'c';
|
||||
base_freq = C;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'd':
|
||||
{
|
||||
temp_note = 'd';
|
||||
base_freq = D;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'e':
|
||||
{
|
||||
temp_note = 'e';
|
||||
base_freq = E;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'f':
|
||||
{
|
||||
temp_note = 'f';
|
||||
base_freq = F;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'g':
|
||||
{
|
||||
temp_note = 'g';
|
||||
base_freq = G;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'a':
|
||||
{
|
||||
temp_note = 'a';
|
||||
base_freq = A;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'b':
|
||||
{
|
||||
temp_note = 'b';
|
||||
base_freq = B;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'p':
|
||||
{
|
||||
temp_note = 'p';
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_song++;
|
||||
|
||||
if (*g_song == '.')
|
||||
{
|
||||
duration += duration / 2;
|
||||
g_song++;
|
||||
}
|
||||
|
||||
if (*g_song == '#')
|
||||
{
|
||||
if (temp_note == 'c')
|
||||
{
|
||||
base_freq = CD;
|
||||
}
|
||||
|
||||
if (temp_note == 'd')
|
||||
{
|
||||
base_freq = DE;
|
||||
}
|
||||
|
||||
if (temp_note == 'f')
|
||||
{
|
||||
base_freq = FG;
|
||||
}
|
||||
|
||||
if (temp_note == 'a')
|
||||
{
|
||||
base_freq = AB;
|
||||
}
|
||||
|
||||
g_song++;
|
||||
}
|
||||
|
||||
if ((*g_song - '0') == '2')
|
||||
{
|
||||
octave = OCT2;
|
||||
}
|
||||
|
||||
if ((*g_song - '0') == '3')
|
||||
{
|
||||
octave = OCT3;
|
||||
}
|
||||
|
||||
if ((*g_song - '0') == '4')
|
||||
{
|
||||
octave = OCT4;
|
||||
}
|
||||
|
||||
if ((*g_song - '0') == '5')
|
||||
{
|
||||
octave = OCT5;
|
||||
}
|
||||
|
||||
if ((*g_song - '0') == '6')
|
||||
{
|
||||
octave = OCT6;
|
||||
}
|
||||
|
||||
if ((*g_song - '0') == '7')
|
||||
{
|
||||
octave = OCT7;
|
||||
}
|
||||
|
||||
if ((*g_song - '0') == '8')
|
||||
{
|
||||
octave = OCT8;
|
||||
}
|
||||
|
||||
g_song++;
|
||||
|
||||
if (*g_song == ',')
|
||||
{
|
||||
g_song++;
|
||||
}
|
||||
|
||||
/* play the sound */
|
||||
|
||||
freq = ceil(base_freq * octave);
|
||||
|
||||
if (!board_audio_tone_generator(1, -40, freq))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(duration * 1000L);
|
||||
}
|
||||
while (*g_song);
|
||||
|
||||
/* Sound off. */
|
||||
|
||||
if (!board_audio_tone_generator(0, 0, 0))
|
||||
{
|
||||
printf("Error: board_audio_tone_generator() failure.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set I/O parameters for power off. */
|
||||
|
||||
if (!board_audio_power_control(false))
|
||||
{
|
||||
printf("Error: board_audio_power_control() failure.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Done.\n");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/****************************************************************************
|
||||
* audio_sound/audio_sound.h
|
||||
*
|
||||
* Copyright 2019 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* 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 of Sony Semiconductor Solutions Corporation 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *g_song = (FAR char *)
|
||||
"Test:d=4,o=6,b=90:c,c#,d,d#,e,f,f#,g,a,a#,b,p,b,a#,a,g,f#,f,e,d#,d,c#,c";
|
|
@ -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
|
|
@ -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 += $(APPDIR)/examples/bastest
|
||||
endif
|
|
@ -0,0 +1,72 @@
|
|||
############################################################################
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# BAS test volume mounter
|
||||
|
||||
PROGNAME = bastest
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_BASTEST)
|
||||
|
||||
# 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
|
||||
|
||||
# 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))
|
||||
|
||||
include $(APPDIR)/Application.mk
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,121 @@
|
|||
/****************************************************************************
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
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;
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,7 @@
|
|||
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
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
|||
10 a=1
|
||||
20 repeat
|
||||
30 print a
|
||||
40 a=a+1
|
||||
50 until a=10
|
|
@ -0,0 +1,7 @@
|
|||
10 gosub 100
|
||||
20 gosub 100
|
||||
30 end
|
||||
100 gosub 200
|
||||
110 gosub 200
|
||||
120 return
|
||||
200 print "hello, world":return
|
|
@ -0,0 +1,11 @@
|
|||
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
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue