diff options
Diffstat (limited to 'apps/system')
27 files changed, 0 insertions, 4603 deletions
diff --git a/apps/system/Kconfig b/apps/system/Kconfig deleted file mode 100644 index 6c8651088..000000000 --- a/apps/system/Kconfig +++ /dev/null @@ -1,40 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -menu "Custom Free Memory Command" -source "$APPSDIR/system/free/Kconfig" -endmenu - -menu "I2C tool" -source "$APPSDIR/system/i2c/Kconfig" -endmenu - -menu "FLASH Program Installation" -source "$APPSDIR/system/install/Kconfig" -endmenu - -menu "readline()" -source "$APPSDIR/system/readline/Kconfig" -endmenu - -menu "Power Off" -source "$APPSDIR/system/poweroff/Kconfig" -endmenu - -menu "RAMTRON" -source "$APPSDIR/system/ramtron/Kconfig" -endmenu - -menu "SD Card" -source "$APPSDIR/system/sdcard/Kconfig" -endmenu - -menu "Sysinfo" -source "$APPSDIR/system/sysinfo/Kconfig" -endmenu - -menu "USB Monitor" -source "$APPSDIR/system/usbmonitor/Kconfig" -endmenu diff --git a/apps/system/Make.defs b/apps/system/Make.defs deleted file mode 100644 index 3c679f112..000000000 --- a/apps/system/Make.defs +++ /dev/null @@ -1,71 +0,0 @@ -############################################################################ -# apps/system/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_SYSTEM_FREE),y) -CONFIGURED_APPS += system/free -endif - -ifeq ($(CONFIG_SYSTEM_I2CTOOL),y) -CONFIGURED_APPS += system/i2c -endif - -ifeq ($(CONFIG_SYSTEM_INSTALL),y) -CONFIGURED_APPS += system/install -endif - -ifeq ($(CONFIG_SYSTEM_READLINE),y) -CONFIGURED_APPS += system/readline -endif - -ifeq ($(CONFIG_SYSTEM_POWEROFF),y) -CONFIGURED_APPS += system/poweroff -endif - -ifeq ($(CONFIG_SYSTEM_RAMTRON),y) -CONFIGURED_APPS += system/ramtron -endif - -ifeq ($(CONFIG_SYSTEM_SDCARD),y) -CONFIGURED_APPS += system/sdcard -endif - -ifeq ($(CONFIG_SYSTEM_SYSINFO),y) -CONFIGURED_APPS += system/sysinfo -endif - -ifeq ($(CONFIG_SYSTEM_USBMONITOR),y) -CONFIGURED_APPS += system/usbmonitor -endif diff --git a/apps/system/Makefile b/apps/system/Makefile deleted file mode 100644 index f39eedec4..000000000 --- a/apps/system/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -############################################################################ -# apps/system/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config # Current configuration - -# Sub-directories containing system task - -SUBDIRS = free i2c install readline poweroff ramtron sdcard sysinfo usbmonitor - -# Create the list of installed runtime modules (INSTALLED_DIRS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) -define ADD_DIRECTORY - INSTALLED_DIRS += $(if $(wildcard .\$1\Makefile),$1,) -endef -else -define ADD_DIRECTORY - INSTALLED_DIRS += $(if $(wildcard ./$1/Makefile),$1,) -endef -endif - -$(foreach DIR, $(SUBDIRS), $(eval $(call ADD_DIRECTORY,$(DIR)))) - -all: nothing -.PHONY: nothing context depend clean distclean - -define SDIR_template -$(1)_$(2): - $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" -endef - -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),depend))) -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),clean))) -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) - -nothing: - -context: - -depend: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_depend) - -clean: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_clean) - -distclean: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_distclean) diff --git a/apps/system/free/Kconfig b/apps/system/free/Kconfig deleted file mode 100644 index 239559867..000000000 --- a/apps/system/free/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config SYSTEM_FREE - bool "NSH free command replacement" - default n - ---help--- - Enable support for the NSH free replacement command. - -if SYSTEM_FREE -endif - diff --git a/apps/system/free/Makefile b/apps/system/free/Makefile deleted file mode 100644 index 58ca7956c..000000000 --- a/apps/system/free/Makefile +++ /dev/null @@ -1,120 +0,0 @@ -############################################################################ -# apps/system/free/Makefile -# -# Copyright (C) 2011-2012 Uros Platise. All rights reserved. -# Author: 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. -# -############################################################################ - -# TODO, this makefile should run make under the app dirs, instead of -# sourcing the Make.defs! - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# Hello Application -# TODO: appname can be automatically extracted from the directory name - -APPNAME = free -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 768 - -ASRCS = -CSRCS = free.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -# Register application - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -# Create dependencies - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/system/free/free.c b/apps/system/free/free.c deleted file mode 100644 index c44cd5e22..000000000 --- a/apps/system/free/free.c +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - * apps/system/free/free.c - * - * 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/progmem.h> - -#include <stdio.h> -#include <stdlib.h> - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* TODO Max block size only works on uniform prog mem */ - -static void free_getprogmeminfo(struct mallinfo * mem) -{ - uint16_t page = 0, stpage = 0xFFFF; - uint16_t pagesize = 0; - int status; - - mem->arena = 0; - mem->fordblks = 0; - mem->uordblks = 0; - mem->mxordblk = 0; - - for (status=0, page=0; status >= 0; page++) - { - status = up_progmem_ispageerased(page); - pagesize = up_progmem_pagesize(page); - - mem->arena += pagesize; - - /* Is this beginning of new free space section */ - - if (status == 0) - { - if (stpage == 0xFFFF) stpage = page; - mem->fordblks += pagesize; - } - else if (status != 0) - { - mem->uordblks += pagesize; - - if (stpage != 0xFFFF && up_progmem_isuniform()) - { - stpage = page - stpage; - if (stpage > mem->mxordblk) - { - mem->mxordblk = stpage; - } - stpage = 0xFFFF; - } - } - } - - mem->mxordblk *= pagesize; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int free_main(int argc, char **argv) -{ - struct mallinfo data; - struct mallinfo prog; - -#ifdef CONFIG_CAN_PASS_STRUCTS - data = mallinfo(); -#else - (void)mallinfo(&data); -#endif - - free_getprogmeminfo(&prog); - - printf(" total used free largest\n"); - printf("Data: %11d%11d%11d%11d\n", - data.arena, data.uordblks, data.fordblks, data.mxordblk); - printf("Prog: %11d%11d%11d%11d\n", - prog.arena, prog.uordblks, prog.fordblks, prog.mxordblk); - - return OK; -} diff --git a/apps/system/i2c/Kconfig b/apps/system/i2c/Kconfig deleted file mode 100644 index 745378b37..000000000 --- a/apps/system/i2c/Kconfig +++ /dev/null @@ -1,61 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - - -config SYSTEM_I2CTOOL - bool "I2C tool" - default n - depends on I2C - ---help--- - Enable support for the I2C tool. - -config I2CTOOL_BUILTIN - bool "NSH built-in command" - default y - depends on SYSTEM_I2CTOOL && NSH_BUILTIN_APPS - ---help--- - Build the tools as an NSH built-in command - -config I2CTOOL_MINBUS - int "Minimum bus number" - default 0 - depends on SYSTEM_I2CTOOL - ---help--- - Smallest bus index supported by the hardware (default 0). - -config I2CTOOL_MAXBUS - int "Maximum bus number" - depends on SYSTEM_I2CTOOL - default 3 - ---help--- - Largest bus index supported by the hardware (default 3) - -config I2CTOOL_MINADDR - hex "Minimum I2C address" - depends on SYSTEM_I2CTOOL - default 0x03 - ---help--- - Minium 7-bit device address (default: 0x03) - -config I2CTOOL_MAXADDR - hex "Maximum I2C address" - depends on SYSTEM_I2CTOOL - default 0x77 - ---help--- - Largest 7-bit device address (default: 0x77) - -config I2CTOOL_MAXREGADDR - hex "Maximum I2C register address" - default 0xff - depends on SYSTEM_I2CTOOL - ---help--- - Largest I2C register address (default: 0xff) - -config I2CTOOL_DEFFREQ - int "Default I2C frequency" - default 4000000 - depends on SYSTEM_I2CTOOL - ---help--- - Default I2C frequency (default: 4000000) diff --git a/apps/system/i2c/Makefile b/apps/system/i2c/Makefile deleted file mode 100644 index 7f0e6005b..000000000 --- a/apps/system/i2c/Makefile +++ /dev/null @@ -1,108 +0,0 @@ -############################################################################ -# apps/system/i2c/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# I2C tool - -ASRCS = -CSRCS = i2c_bus.c i2c_common.c i2c_dev.c i2c_get.c i2c_main.c i2c_set.c i2c_verf.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . -VPATH = - -APPNAME = i2c -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 -MAXOPTIMIZATION = -Os - -# Build Targets - -all: .built -.PHONY: context .depend depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep - diff --git a/apps/system/i2c/README.txt b/apps/system/i2c/README.txt deleted file mode 100644 index 7b432533b..000000000 --- a/apps/system/i2c/README.txt +++ /dev/null @@ -1,397 +0,0 @@ -README File for the I2C Tool
-============================
-
-The I2C tool provides a way to debug I2C related problems. This README file
-will provide usage information for the I2C tools.
-
-CONTENTS
-========
-
- o System Requirements
- - I2C Driver
- - Configuration Options
- o Help
- o Common Line Form
- o Common Command Options
- - "Sticky" Options
- - Environment variables
- - Common Option Summary
- o Command summary
- - bus
- - dev
- - get
- - set
- - verf
- o I2C Build Configuration
- - NuttX Configuration Requirements
- - I2C Tool Configuration Options
-
-System Requirements
-===================
-
-I2C Driver
-----------
-In order to use the I2C driver, you system -- in particular, your I2C driver --
-must meet certain requirements:
-
-1. It support calling up_i2cinitialize() numerous times, resetting the I2C
- hardware on each (initial) time. up_i2cuninitialize() will be called after
- each call to up_i2cinitialize() to free any resources and disable the I2C.
-2. up_i2cinitialize must accept any interface number without crashing. It
- must simply return NULL if the device is not supported.
-3. The I2C driver must support the transfer method (CONFIG_I2C_TRANSFER=y).
-
-The I2C tool is designed to be implemented as a NuttShell (NSH) add-on. Read
-the apps/nshlib/README.txt file for information about add-ons.
-
-Configuration Options
----------------------
-CONFIG_I2CTOOL_BUILTIN - Build the tools as an NSH built-in command
-CONFIG_I2CTOOL_MINBUS - Smallest bus index supported by the hardware (default 0).
-CONFIG_I2CTOOL_MAXBUS - Largest bus index supported by the hardware (default 3)
-CONFIG_I2CTOOL_MINADDR - Minium device address (default: 0x03)
-CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77)
-CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff)
-CONFIG_I2CTOOL_DEFFREQ - Default frequency (default: 4000000)
-
-HELP
-====
-
-First of all, the I2C tools supports a pretty extensive help output. That
-help output can be view by entering either:
-
- nsh> i2c help
-
-or
-
- nsh> i2c ?
-
-Here is an example of the help output. I shows the general form of the
-command line, the various I2C commands supported with their unique command
-line options, and a more detailed summary of the command I2C command
-options.
-
- nsh> i2c help
- Usage: i2c <cmd> [arguments]
- Where <cmd> is one of:
-
- Show help : ?
- List buses : bus
- List devices : dev [OPTIONS] <first> <last>
- Read register : get [OPTIONS] [<repititions>]
- Show help : help
- Write register: set [OPTIONS] <value> [<repititions>]
- Verify access : verf [OPTIONS] <value> [<repititions>]
-
- Where common "sticky" OPTIONS include:
- [-a addr] is the I2C device address (hex). Default: 03 Current: 03
- [-b bus] is the I2C bus number (decimal). Default: 1 Current: 1
- [-r regaddr] is the I2C device register address (hex). Default: 00 Current: 00
- [-w width] is the data width (8 or 16 decimal). Default: 8 Current: 8
- [-s|n], send/don't send start between command and data. Default: -n Current: -n
- [-i|j], Auto increment|don't increment regaddr on repititions. Default: NO Current: NO
- [-f freq] I2C frequency. Default: 100000 Current: 100000
-
- NOTES:
- o An environment variable like $PATH may be used for any argument.
- o Arguments are "sticky". For example, once the I2C address is
- specified, that address will be re-used until it is changed.
-
- WARNING:
- o The I2C dev command may have bad side effects on your I2C devices.
- Use only at your own risk.
-
-COMMAND LINE FORM
-=================
-
-The I2C is started from NSH by invoking the 'i2c' command from the NSH
-command line. The general form of the 'i2c' command is:
-
- i2c <cmd> [arguments]
-
-Where <cmd> is a "sub-command" and identifies one I2C operations supported
-by the tool. [arguments] represents the list of arguments needed to perform
-the I2C operation. Those arguments vary from command to command as
-described below. However, there is also a core set of common OPTIONS
-supported by all commands. So perhaps a better representation of the
-general I2C command would be:
-
- i2c <cmd> [OPTIONS] [arguments]
-
-Where [OPTIONS] represents the common options and and arguments represent
-the operation-specific arguments.
-
-COMMON COMMAND OPTIONS
-======================
-
-"Sticky" Options
-----------------
-In order to interact with I2C devices, there are a number of I2C parameters
-that must be set correctly. One way to do this would be to provide to set
-the value of each separate command for each I2C parameter. The I2C tool
-takes a different approach, instead: The I2C configuration can be specified
-as a (potentially long) sequence of command line arguments.
-
-These arguments, however, are "sticky." They are sticky in the sense that
-once you set the I2C parameter, that value will remain until it is reset
-with a new value (or until you reset the board).
-
-Environment Variables
----------------------
-NOTE also that if environment variables are not disabled (by
-CONFIG_DISABLE_ENVIRON=y), then these options may also be environment
-variables. Environment variables must be preceded with the special
-character $. For example, PWD is the variable that holds the current
-working directory and so $PWD could be used as a command line argument. The
-use of environment variables on the I2C tools command is really only useful
-if you wish to write NSH scripts to execute a longer, more complex series of
-I2C commands.
-
-Common Option Summary
----------------------
-
-[-a addr] is the I2C device address (hex). Default: 03 Current: 03
-
- The [-a addr] sets the I2C device address. The valid range is 0x03
- through 0x77 (this valid range is controlled by the configuration settings
- CONFIG_I2CTOOL_MINADDR and CONFIG_I2CTOOL_MAXADDR). If you are working
- with the same device, the address needs to be set only once.
-
- All I2C address are 7-bit, hexadecimal values.
-
- NOTE 1: Notice in the "help" output above it shows both default value of
- the I2C address (03 hex) and the current address value (also 03 hex).
-
- NOTE 2: Sometimes I2C addresses are represented as 8-bit values (with
- bit zero indicating a read or write operation). The I2C tool uses a
- 7-bit representation of the address with bit 7 unused and no read/write
- indication in bit 0. Essentially, the 7-bit address is like the 8-bit
- address shifted right by 1.
-
- NOTE 3: Most I2C bus controllers will also support 10-bit addressing.
- That capability has not been integrated into the I2C tool as of this
- writing.
-
-[-b bus] is the I2C bus number (decimal). Default: 1 Current: 1
-
- Most devices support multiple I2C devices and also have unique bus
- numbering. This option identifies which bus you are working with now.
- The valid range of bus numbers is controlled by the configuration settings
- CONFIG_I2CTOOL_MINBUS and CONFIG_I2CTOOL_MAXBUS.
-
- The bus numbers are small, decimal numbers.
-
-[-r regaddr] is the I2C device register address (hex). Default: 00 Current: 00
-
- The I2C set and get commands will access registers on the I2C device. This
- option selects the device register address (sometimes called the sub-address).
- This is an 8-bit hexadecimal value. The maximum value is determined by
- the configuration setting CONFIG_I2CTOOL_MAXREGADDR.
-
-[-w width] is the data width (8 or 16 decimal). Default: 8 Current: 8
-
- Device register data may be 8-bit or 16-bit. This options selects one of
- those two data widths.
-
-[-s|n], send/don't send start between command and data. Default: -n Current: -n
-
- This determines whether or not there should be a new I2C START between
- sending of the register address and sending/receiving of the register data.
-
-[-i|j], Auto increment|don't increment regaddr on repititions. Default: NO Current: NO
-
- On commands that take a optional number of repetitions, the option can be
- used to temporarily increment the regaddr value by one on each repitition.
-
-[-f freq] I2C frequency. Default: 400000 Current: 400000
-
- The [-f freq] sets the frequency of the I2C device.
-
-COMMAND SUMMARY
-===============
-
-We have already seen the I2C help (or ?) commands above. This section will
-discuss the remaining commands.
-
-List buses: bus [OPTIONS]
---------------------------
-
-This command will simply list all of the configured I2C buses and indicate
-which are supported by the driver and which are not:
-
- BUS EXISTS?
- Bus 1: YES
- Bus 2: NO
-
-The valid range of bus numbers is controlled by the configuration settings
-CONFIG_I2CTOOL_MINBUS and CONFIG_I2CTOOL_MAXBUS.
-
-List devices: dev [OPTIONS] <first> <last>
-------------------------------------------
-
-The 'dev' command will attempt to identify all of the I2C devices on the
-selected bus. The <first> and <last> arguments are 7-bit, hexadecimal
-I2C addresses. This command will examine a range of addresses beginning
-with <first> and continuing through <last>. It will request the value
-of register zero from each device.
-
-If the device at an address responds, then this command will display the
-address of the device. If the device does not respond, this command will
-display "--". The resulting display is like:
-
-nsh> i2c dev 03 77
- 0 1 2 3 4 5 6 7 8 9 a b c d e f
-00: -- -- -- -- -- -- -- -- -- -- -- -- --
-10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-40: -- -- -- -- -- -- -- -- -- 49 -- -- -- -- -- --
-50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-70: -- -- -- -- -- -- -- --
-
-WARNINGS:
- o The I2C dev command may have bad side effects on certain I2C devices.
- For example, if could cause data loss in an EEPROM device.
- o The I2C dev command also depends upon the underlying behavior of the
- I2C driver. How does the driver respond to addressing failures?
-
-Read register: get [OPTIONS]
-----------------------------
-
- This command will read the value of the I2C register using the selected
- I2C parameters in the common options. No other arguments are required.
-
- This command with write the 8-bit address value then read an 8- or 16-bit
- data value from the device. Optionally, it may re-start the transfer
- before obtaining the data.
-
- An optional <repititions> argument can be supplied to repeat the
- read operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- read will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- READ Bus: 1 Addr: 49 Subaddr: 04 Value: 96
-
- All values (except the bus numbers) are hexadecimal.
-
-Write register: set [OPTIONS] <value>
--------------------------------------
-
- This command will write a value to an I2C register using the selected
- I2C parameters in the common options. The value to write must be provided
- as the final, hexadecimal value. This value may be an 8-bit value (in the
- range 00-ff) or a 16-bit value (in the range 0000-ffff), depending upon
- the selected data width.
-
- This command will write the 8-bit address value then write the 8- or 16-bit
- data value to the device. Optionally, it may re-start the transfer
- before writing the data.
-
- An optional <repititions> argument can be supplied to repeat the
- write operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- written will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- WROTE Bus: 1 Addr: 49 Subaddr: 04 Value: 96
-
- All values (except the bus numbers) are hexadecimal.
-
-Verify access : verf [OPTIONS] <value> [<repititions>]
-------------------------------------------------------
-
- This command combines writing and reading from an I2C device register.
- It will write a value to an will write a value to an I2C register using
- the selected I2C parameters in the common options just as described for
- tie 'set' command. Then this command will read the value back just
- as described with the 'get' command. Finally, this command will compare
- the value read and against the value written and emit an error message
- if they do not match.
-
- If no value is provided, then this command will use the register address
- itself as the data, providing for a address-in-address test.
-
- An optional <repititions> argument can be supplied to repeat the
- verify operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- written will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- VERIFY Bus: 1 Addr: 49 Subaddr: 04 Wrote: 96 Read: 92 FAILURE
-
- All values (except the bus numbers) are hexadecimal.
-
-I2C BUILD CONFIGURATION
-=======================
-
-NuttX Configuration Requirements
---------------------------------
-The I2C tools requires the following in your NuttX configuration:
-
-1. Device-specific I2C support must be enabled. The I2C tool will call the
- platform-specific function up_i2cinitialize() to get instances of the
- I2C interface and the platform-specific function up_i2cuninitialize()
- to discard instances of the I2C interface.
-
- NOTE 1: The I2C interface is defined in include/nuttx/i2c.h.
-
- NOTE 2: This I2C tool uses direct I2C device interfaces. As such, it
- relies on internal OS interfaces that are not normally available to a
- user-space program. As a result, the I2C tool cannot be used if a
- NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL).
-
-2. I2C driver configuration
-
- The CONFIG_I2C_TRANSFER option must also be set in your NuttX
- configuration. This configuration is the defconfig file in your
- configuration directory that is copied to the NuttX top-level
- directory as .config when NuttX is configured.
-
- CONFIG_I2C_TRANSFER=y
-
- NOTE: CONFIG_I2C_TRANSFER adds extra methods to the I2C interface.
- Not all I2C interfaces support these extra methods. If your platform's
- I2C driver does not support these extra methods, then you cannot use
- the I2C tool unless you extend the support in your platform I2C
- driver.
-
-3. Application configuration.
-
- The path to the I2C tool directory must also be set in your NuttX
- application configuration. This application configuration is the
- appconfig file in your configuration directory that is copied to the
- NuttX application directory as .config when NuttX is configured.
-
- CONFIGURE_APPS += system/i2c
-
-I2C Tool Configuration Options
-------------------------------
-
-The default behavior of the I2C tool can be modified by the setting the
-options in the NuttX configuration. This configuration is the defconfig
-file in your configuration directory that is copied to the NuttX top-level
-directory as .config when NuttX is configured.
-
- CONFIG_I2CTOOL_BUILTIN: Build the tools as an NSH built-in command
- CONFIG_I2CTOOL_MINBUS: Smallest bus index supported by the hardware (default 0).
- CONFIG_I2CTOOL_MAXBUS: Largest bus index supported by the hardware (default 3)
- CONFIG_I2CTOOL_MINADDR: Minium device address (default: 0x03)
- CONFIG_I2CTOOL_MAXADDR: Largest device address (default: 0x77)
- CONFIG_I2CTOOL_MAXREGADDR: Largest register address (default: 0xff)
- CONFIG_I2CTOOL_DEFFREQ: Default frequency (default: 4000000)
diff --git a/apps/system/i2c/i2c_bus.c b/apps/system/i2c/i2c_bus.c deleted file mode 100644 index a684166ff..000000000 --- a/apps/system/i2c/i2c_bus.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_bus.c - * - * 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_bus - ****************************************************************************/ - -int i2ccmd_bus(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - FAR struct i2c_dev_s *dev; - int i; - - i2ctool_printf(i2ctool, " BUS EXISTS?\n"); - for (i = CONFIG_I2CTOOL_MINBUS; i <= CONFIG_I2CTOOL_MAXBUS; i++) - { - dev = up_i2cinitialize(i); - if (dev) - { - i2ctool_printf(i2ctool, "Bus %d: YES\n", i); - (void)up_i2cuninitialize(dev); - } - else - { - i2ctool_printf(i2ctool, "Bus %d: NO\n", i); - } - } - - return OK; -} diff --git a/apps/system/i2c/i2c_common.c b/apps/system/i2c/i2c_common.c deleted file mode 100644 index 4af648c7d..000000000 --- a/apps/system/i2c/i2c_common.c +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_common.c - * - * 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: common_args - ****************************************************************************/ - -int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) -{ - FAR char *ptr = *arg; - long value; - int ret; - - if (ptr[0] != '-') - { - goto invalid_argument; - } - - switch (ptr[1]) - { - case 'a': - ret = arg_hex(arg, &value); - if (value < CONFIG_I2CTOOL_MINADDR || value > CONFIG_I2CTOOL_MAXADDR) - { - goto out_of_range; - } - - i2ctool->addr = (uint8_t) value; - return ret; - - case 'b': - ret = arg_decimal(arg, &value); - if (value < CONFIG_I2CTOOL_MINBUS || value > CONFIG_I2CTOOL_MAXBUS) - { - goto out_of_range; - } - - i2ctool->bus = (uint8_t) value; - return ret; - - case 'f': - ret = arg_decimal(arg, &value); - if (value == 0) - { - goto out_of_range; - } - - i2ctool->freq = value; - return ret; - - case 'i': - i2ctool->autoincr = true; - return 1; - - case 'j': - i2ctool->autoincr = false; - return 1; - - case 'n': - i2ctool->start = false; - return 1; - - case 'r': - ret = arg_hex(arg, &value); - if (value < 0 || value > CONFIG_I2CTOOL_MAXREGADDR) - { - goto out_of_range; - } - - i2ctool->regaddr = (uint8_t) value; - return ret; - - case 's': - i2ctool->start = true; - return 1; - - case 'w': - ret = arg_decimal(arg, &value); - if (value != 8 && value != 16) - { - goto out_of_range; - } - - i2ctool->width = (uint8_t) value; - return ret; - - default: - goto invalid_argument; - } - -invalid_argument: - i2ctool_printf(i2ctool, g_i2carginvalid, ptr); - return ERROR; - -out_of_range: - i2ctool_printf(i2ctool, g_i2cargrange, ptr); - return ERROR; -} - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -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 - ****************************************************************************/ - -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: arg_hex - ****************************************************************************/ - -int arg_hex(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 16); - return ret; -} diff --git a/apps/system/i2c/i2c_dev.c b/apps/system/i2c/i2c_dev.c deleted file mode 100644 index 3d0480a15..000000000 --- a/apps/system/i2c/i2c_dev.c +++ /dev/null @@ -1,235 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_dev.c - * - * 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_dev - ****************************************************************************/ - -int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - FAR struct i2c_dev_s *dev; - struct i2c_msg_s msg[2]; - FAR char *ptr; - union - { - uint16_t data16; - uint8_t data8; - } u; - - uint8_t regaddr; - long first; - long last; - int addr; - int nargs; - int argndx; - int ret; - int i; - int j; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There should be exactly two more things on the command line: The first and - * last addresses to be probed. - */ - - if (argndx+1 < argc) - { - first = strtol(argv[argndx], NULL, 16); - last = strtol(argv[argndx+1], NULL, 16); - if (first < 0 || first > 0x7f || last < 0 || last > 0x7f || first > last) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx += 2; - } - else - { - i2ctool_printf(i2ctool, g_i2cargrequired, argv[0]); - return ERROR; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - - /* Probe each address */ - - i2ctool_printf(i2ctool, " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); - for (i = 0; i < 128; i += 16) - { - i2ctool_printf(i2ctool, "%02x: ", i); - for (j = 0; j < 16; j++) - { - /* Skip addresses that are out of the selected range */ - - addr = i+j; - if (addr < first || addr > last) - { - i2ctool_printf(i2ctool, " "); - continue; - } - - /* Set the I2C address */ - - I2C_SETADDRESS(dev, addr, 7); - - /* Set up data structures */ - - regaddr = 0; - - msg[0].addr = addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = addr; - msg[1].flags = I2C_M_READ; - if (i2ctool->width == 8) - { - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret == OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - if (ret == OK) - { - i2ctool_printf(i2ctool, "%02x ", addr); - } - else - { - i2ctool_printf(i2ctool, "-- "); - } - } - i2ctool_printf(i2ctool, "\n"); - i2ctool_flush(i2ctool); - } - - (void)up_i2cuninitialize(dev); - return OK; -} diff --git a/apps/system/i2c/i2c_get.c b/apps/system/i2c/i2c_get.c deleted file mode 100644 index 08510af4b..000000000 --- a/apps/system/i2c/i2c_get.c +++ /dev/null @@ -1,257 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_get.c - * - * 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_get - ****************************************************************************/ - -int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint16_t result; - uint8_t regaddr; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* Read from the I2C bus */ - - ret = i2ctool_get(i2ctool, dev, regaddr, &result); - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "READ Bus: %d Addr: %02x Subaddr: %02x Value: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x\n", result); - } - else - { - i2ctool_printf(i2ctool, "%04x\n", result); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} - -/**************************************************************************** - * Name: i2ctool_get - ****************************************************************************/ - -int i2ctool_get(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t *result) -{ - struct i2c_msg_s msg[2]; - union - { - uint16_t data16; - uint8_t data8; - } u; - int ret; - - /* Set up data structures */ - - msg[0].addr = i2ctool->addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = i2ctool->addr; - msg[1].flags = I2C_M_READ; - if (i2ctool->width == 8) - { - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret== OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - /* Return the result of the read operation */ - - if (ret == OK) - { - if (i2ctool->width == 8) - { - *result = (uint16_t)u.data8; - } - else - { - *result = u.data16; - } - } - return ret; -} diff --git a/apps/system/i2c/i2c_main.c b/apps/system/i2c/i2c_main.c deleted file mode 100644 index 0cf6786cb..000000000 --- a/apps/system/i2c/i2c_main.c +++ /dev/null @@ -1,446 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_main.c - * - * 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 Gregory Nutt 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 <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <stdarg.h> -#include <assert.h> -#include <errno.h> -#include <debug.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv); -static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **argv); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -struct i2ctool_s g_i2ctool; - -static const struct cmdmap_s g_i2ccmds[] = -{ - { "?", i2ccmd_help, "Show help ", NULL }, - { "bus", i2ccmd_bus, "List busses ", NULL }, - { "dev", i2ccmd_dev, "List devices ", "[OPTIONS] <first> <last>" }, - { "get", i2ccmd_get, "Read register ", "[OPTIONS] [<repititions>]" }, - { "help", i2ccmd_help, "Show help ", NULL }, - { "set", i2ccmd_set, "Write register", "[OPTIONS] <value> [<repititions>]" }, - { "verf", i2ccmd_verf, "Verify access ", "[OPTIONS] [<value>] [<repititions>]" }, - { NULL, NULL, NULL, NULL } -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Common, message formats */ - -const char g_i2cargrequired[] = "i2ctool: %s: missing required argument(s)\n"; -const char g_i2carginvalid[] = "i2ctool: %s: argument invalid\n"; -const char g_i2cargrange[] = "i2ctool: %s: value out of range\n"; -const char g_i2ccmdnotfound[] = "i2ctool: %s: command not found\n"; -const char g_i2ctoomanyargs[] = "i2ctool: %s: too many arguments\n"; -const char g_i2ccmdfailed[] = "i2ctool: %s: %s failed: %d\n"; -const char g_i2cxfrerror[] = "i2ctool: %s: Transfer failed: %d\n"; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_help - ****************************************************************************/ - -static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - const struct cmdmap_s *ptr; - - i2ctool_printf(i2ctool, "Usage: i2c <cmd> [arguments]\n"); - i2ctool_printf(i2ctool, "Where <cmd> is one of:\n\n"); - for (ptr = g_i2ccmds; ptr->cmd; ptr++) - { - if (ptr->usage) - { - i2ctool_printf(i2ctool, " %s: %s %s\n", ptr->desc, ptr->cmd, ptr->usage); - } - else - { - i2ctool_printf(i2ctool, " %s: %s\n", ptr->desc, ptr->cmd); - } - } - - i2ctool_printf(i2ctool, "\nWhere common \"sticky\" OPTIONS include:\n"); - i2ctool_printf(i2ctool, " [-a addr] is the I2C device address (hex). " - "Default: %02x Current: %02x\n", - CONFIG_I2CTOOL_MINADDR, i2ctool->addr); - i2ctool_printf(i2ctool, " [-b bus] is the I2C bus number (decimal). " - "Default: %d Current: %d\n", - CONFIG_I2CTOOL_MINBUS, i2ctool->bus); - i2ctool_printf(i2ctool, " [-r regaddr] is the I2C device register address (hex). " - "Default: 00 Current: %02x\n", - i2ctool->regaddr); - i2ctool_printf(i2ctool, " [-w width] is the data width (8 or 16 decimal). " - "Default: 8 Current: %d\n", - i2ctool->width); - i2ctool_printf(i2ctool, " [-s|n], send/don't send start between command and data. " - "Default: -n Current: %s\n", - i2ctool->start ? "-s" : "-n"); - i2ctool_printf(i2ctool, " [-i|j], Auto increment|don't increment regaddr on repititions. " - "Default: NO Current: %s\n", - i2ctool->autoincr ? "YES" : "NO"); - i2ctool_printf(i2ctool, " [-f freq] I2C frequency. " - "Default: %d Current: %d\n", - CONFIG_I2CTOOL_DEFFREQ, i2ctool->freq); - i2ctool_printf(i2ctool, "\nNOTES:\n"); -#ifndef CONFIG_DISABLE_ENVIRON - i2ctool_printf(i2ctool, "o An environment variable like $PATH may be used for any argument.\n"); -#endif - i2ctool_printf(i2ctool, "o Arguments are \"sticky\". For example, once the I2C address is\n"); - i2ctool_printf(i2ctool, " specified, that address will be re-used until it is changed.\n"); - i2ctool_printf(i2ctool, "\nWARNING:\n"); - i2ctool_printf(i2ctool, "o The I2C dev command may have bad side effects on your I2C devices.\n"); - i2ctool_printf(i2ctool, " Use only at your own risk.\n"); - return OK; -} - -/**************************************************************************** - * Name: i2ccmd_unrecognized - ****************************************************************************/ - -static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - i2ctool_printf(i2ctool, g_i2ccmdnotfound, argv[0]); - return ERROR; -} - -/**************************************************************************** - * Name: i2c_execute - ****************************************************************************/ - -static int i2c_execute(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) -{ - const struct cmdmap_s *cmdmap; - const char *cmd; - cmd_t handler; - int ret; - - /* The form of argv is: - * - * argv[0]: The command name. This is argv[0] when the arguments - * are, finally, received by the command vtblr - * argv[1]: The beginning of argument (up to MAX_ARGUMENTS) - * argv[argc]: NULL terminating pointer - */ - - /* See if the command is one that we understand */ - - cmd = argv[0]; - handler = i2ccmd_unrecognized; - - for (cmdmap = g_i2ccmds; cmdmap->cmd; cmdmap++) - { - if (strcmp(cmdmap->cmd, cmd) == 0) - { - handler = cmdmap->handler; - break; - } - } - - ret = handler(i2ctool, argc, argv); - return ret; -} - -/**************************************************************************** - * Name: i2c_argument - ****************************************************************************/ - -FAR char *i2c_argument(FAR struct i2ctool_s *i2ctool, int argc, char *argv[], int *pindex) -{ - FAR char *arg; - int index = *pindex; - - /* If we are at the end of the arguments with nothing, then return NULL */ - - if (index >= argc) - { - return NULL; - } - - /* Get the return parameter */ - - arg = argv[index]; - *pindex = index + 1; - -#ifndef CONFIG_DISABLE_ENVIRON - /* Check for references to environment variables */ - - if (arg[0] == '$') - { - /* Return the value of the environment variable with this name */ - - FAR char *value = getenv(arg+1); - if (value) - { - return value; - } - else - { - return (FAR char*)""; - } - } -#endif - - /* Return the next argument. */ - - return arg; -} - -/**************************************************************************** - * Name: i2c_parse - ****************************************************************************/ - -int i2c_parse(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) -{ - FAR char *newargs[MAX_ARGUMENTS+2]; - FAR char *cmd; - int nargs; - int index; - - /* Parse out the command, skipping the first argument (the program name)*/ - - index = 1; - cmd = i2c_argument(i2ctool, argc, argv, &index); - - /* Check if any command was provided */ - - if (!cmd) - { - /* An empty line is not an error and an unprocessed command cannot - * generate an error, but neither should they change the last - * command status. - */ - - return i2ccmd_help(i2ctool, 0, NULL); - } - - /* Parse all of the arguments following the command name. */ - - newargs[0] = cmd; - for (nargs = 1; nargs <= MAX_ARGUMENTS; nargs++) - { - newargs[nargs] = i2c_argument(i2ctool, argc, argv, &index); - if (!newargs[nargs]) - { - break; - } - } - newargs[nargs] = NULL; - - /* Then execute the command */ - - return i2c_execute(i2ctool, nargs, newargs); -} - -/**************************************************************************** - * Name: i2c_setup - ****************************************************************************/ - -static inline int i2c_setup(FAR struct i2ctool_s *i2ctool) -{ - /* Initialize the output stream */ - -#ifdef CONFIG_I2CTOOL_OUTDEV - i2ctool->ss_outfd = open(CONFIG_I2CTOOL_OUTDEV, O_WRONLY); - if (i2ctool->ss_outfd < 0) - { - fprintf(stderr, g_i2ccmdfailed, "open", errno); - return ERROR; - } - - /* Create a standard C stream on the console device */ - - i2ctool->ss_outstream = fdopen(i2ctool->ss_outfd, "w"); - if (!i2ctool->ss_outstream) - { - fprintf(stderr, g_i2ccmdfailed, "fdopen", errno); - return ERROR; - } -#endif - - return OK; -} - -/**************************************************************************** - * Name: i2c_teardown - * - * Description: - * Close the output stream if it is not the standard output stream. - * - ****************************************************************************/ - -static void i2c_teardown(FAR struct i2ctool_s *i2ctool) -{ - fflush(OUTSTREAM(&g_i2ctool)); - -#ifdef CONFIG_I2CTOOL_OUTDEV - fclose(i2ctool->ss_outstream); -#endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2c_main - ****************************************************************************/ - -int i2c_main(int argc, char *argv[]) -{ - /* Verify settings */ - - if (g_i2ctool.bus < CONFIG_I2CTOOL_MINBUS || g_i2ctool.bus > CONFIG_I2CTOOL_MAXBUS) - { - g_i2ctool.bus = CONFIG_I2CTOOL_MINBUS; - } - - if (g_i2ctool.addr < CONFIG_I2CTOOL_MINADDR || g_i2ctool.addr > CONFIG_I2CTOOL_MAXADDR) - { - g_i2ctool.addr = CONFIG_I2CTOOL_MINADDR; - } - - if (g_i2ctool.regaddr < CONFIG_I2CTOOL_MAXREGADDR) - { - g_i2ctool.regaddr = 0; - } - - if (g_i2ctool.width != 8 && g_i2ctool.width != 16) - { - g_i2ctool.width = 8; - } - - if (g_i2ctool.freq == 0) - { - g_i2ctool.freq = CONFIG_I2CTOOL_DEFFREQ; - } - - /* Parse process the command line */ - - i2c_setup(&g_i2ctool); - (void)i2c_parse(&g_i2ctool, argc, argv); - - i2ctool_flush(&g_i2ctool); - i2c_teardown(&g_i2ctool); - return OK; -} - -/**************************************************************************** - * Name: i2ctool_printf - * - * Description: - * Print a string to the currently selected stream. - * - ****************************************************************************/ - -int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = vfprintf(OUTSTREAM(i2ctool), fmt, ap); - va_end(ap); - - return ret; -} - -/**************************************************************************** - * Name: i2ctool_write - * - * Description: - * write a buffer to the currently selected stream. - * - ****************************************************************************/ - -ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes) -{ - ssize_t ret; - - /* Write the data to the output stream */ - - ret = fwrite(buffer, 1, nbytes, OUTSTREAM(i2ctool)); - if (ret < 0) - { - dbg("[%d] Failed to send buffer: %d\n", OUTFD(i2ctool), errno); - } - return ret; -} - -/**************************************************************************** - * Name: i2ctool_flush - * - * Description: - * Flush buffered I/O to the currently selected stream. - * - ****************************************************************************/ - -void i2ctool_flush(FAR struct i2ctool_s *i2ctool) -{ - fflush(OUTSTREAM(i2ctool)); -} diff --git a/apps/system/i2c/i2c_set.c b/apps/system/i2c/i2c_set.c deleted file mode 100644 index 5baf7f835..000000000 --- a/apps/system/i2c/i2c_set.c +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_set.c - * - * 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_set - ****************************************************************************/ - -int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint8_t regaddr; - long value; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There must be at least one more thing on the command line: The value - * to be written. - */ - - if (argndx < argc) - { - value = strtol(argv[argndx], NULL, 16); - if (i2ctool->width == 8) - { - if (value < 0 || value > 255) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - } - else if (value < 0 || value > 65535) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - else - { - i2ctool_printf(i2ctool, g_i2cargrequired, argv[0]); - return ERROR; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* Write to the I2C bus */ - - ret = i2ctool_set(i2ctool, dev, regaddr, (uint16_t)value); - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "WROTE Bus: %d Addr: %02x Subaddr: %02x Value: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x\n", (int)value); - } - else - { - i2ctool_printf(i2ctool, "%04x\n", (int)value); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} - -/**************************************************************************** - * Name: i2ctool_set - ****************************************************************************/ - -int i2ctool_set(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t value) -{ - struct i2c_msg_s msg[2]; - union - { - uint16_t data16; - uint8_t data8; - } u; - int ret; - - /* Set up data structures */ - - msg[0].addr = i2ctool->addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = i2ctool->addr; - msg[1].flags = 0; - if (i2ctool->width == 8) - { - u.data8 = (uint8_t)value; - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - u.data16 = value; - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret == OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - return ret; -} diff --git a/apps/system/i2c/i2c_verf.c b/apps/system/i2c/i2c_verf.c deleted file mode 100644 index 109e9c4ce..000000000 --- a/apps/system/i2c/i2c_verf.c +++ /dev/null @@ -1,249 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_verf.c - * - * 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_verf - ****************************************************************************/ - -int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint16_t rdvalue; - uint8_t regaddr; - bool addrinaddr; - long wrvalue; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* The options may be followed by the optional wrvalue to be written. If omitted, then - * the register address will be used as the wrvalue, providing an address-in-address - * test. - */ - - addrinaddr = true; - wrvalue = 0; - - if (argndx < argc) - { - wrvalue = strtol(argv[argndx], NULL, 16); - if (i2ctool->width == 8) - { - if (wrvalue < 0 || wrvalue > 255) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - } - else if (wrvalue < 0 || wrvalue > 65535) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - addrinaddr = false; - argndx++; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* If we are performing an address-in-address test, then use the register - * address as the value to write. - */ - - if (addrinaddr) - { - wrvalue = regaddr; - } - - /* Write to the I2C bus */ - - ret = i2ctool_set(i2ctool, dev, regaddr, (uint16_t)wrvalue); - if (ret == OK) - { - /* Read the value back from the I2C bus */ - - ret = i2ctool_get(i2ctool, dev, regaddr, &rdvalue); - } - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "VERIFY Bus: %d Addr: %02x Subaddr: %02x Wrote: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x Read: %02x", (int)wrvalue, (int)rdvalue); - } - else - { - i2ctool_printf(i2ctool, "%04x Read: %04x", (int)wrvalue, (int)rdvalue); - } - - if (wrvalue != rdvalue) - { - i2ctool_printf(i2ctool, " <<< FAILURE\n"); - } - else - { - i2ctool_printf(i2ctool, "\n"); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} diff --git a/apps/system/i2c/i2ctool.h b/apps/system/i2c/i2ctool.h deleted file mode 100644 index 4ff26d03e..000000000 --- a/apps/system/i2c/i2ctool.h +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2ctool.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_SYSTEM_I2C_I2CTOOLS_H -#define __APPS_SYSTEM_I2C_I2CTOOLS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/compiler.h> - -#include <sys/types.h> -#include <stdio.h> -#include <stdint.h> -#include <stdbool.h> -#include <errno.h> - -#include <nuttx/i2c.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* CONFIG_I2CTOOL_BUILTIN - Build the tools as an NSH built-in command - * CONFIG_I2CTOOL_MINBUS - Smallest bus index supported by the hardware (default 0). - * CONFIG_I2CTOOL_MAXBUS - Largest bus index supported by the hardware (default 3) - * CONFIG_I2CTOOL_MINADDR - Minium device address (default: 0x03) - * CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77) - * CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff) - * CONFIG_I2CTOOL_DEFFREQ - Default frequency (default: 4000000) - */ - -#ifndef CONFIG_I2C_TRANSFER -# error "CONFIG_I2C_TRANSFER is required in the configuration" -#endif - -#ifndef CONFIG_I2CTOOL_MINBUS -# define CONFIG_I2CTOOL_MINBUS 0 -#endif - -#ifndef CONFIG_I2CTOOL_MAXBUS -# define CONFIG_I2CTOOL_MAXBUS 3 -#endif - -#ifndef CONFIG_I2CTOOL_MINADDR -# define CONFIG_I2CTOOL_MINADDR 0x03 -#endif - -#ifndef CONFIG_I2CTOOL_MAXADDR -# define CONFIG_I2CTOOL_MAXADDR 0x77 -#endif - -#ifndef CONFIG_I2CTOOL_MAXREGADDR -# define CONFIG_I2CTOOL_MAXREGADDR 0xff -#endif - -#ifndef CONFIG_I2CTOOL_DEFFREQ -# define CONFIG_I2CTOOL_DEFFREQ 100000 -#endif - -/* This is the maximum number of arguments that will be accepted for a - * command. The only real limit is in the OS configuration that limits - * the number of parameters passed to a task. - */ - -#define MAX_ARGUMENTS (CONFIG_MAX_TASK_ARGS-1) - -/* Maximum size of one command line */ - -#define MAX_LINELEN 80 - -/* Are we using the NuttX console for I/O? Or some other character device? */ - -#ifdef CONFIG_I2CTOOL_INDEV -# define INFD(p) ((p)->ss_infd) -# define INSTREAM(p) ((p)->ss_instream) -#else -# define INFD(p) 0 -# define INSTREAM(p) stdin -#endif - -#ifdef CONFIG_I2CTOOL_OUTDEV -# define OUTFD(p) ((p)->ss_outfd) -# define OUTSTREAM(p) ((p)->ss_outstream) -#else -# define OUTFD(p) 1 -# define OUTSTREAM(p) stdout -#endif - -/* Output is via printf but can be changed using this macro */ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# define i2c_output(v, fmt...) printf(v, ##fmt) -#else -# define i2c_output printf -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct i2ctool_s -{ - /* Sticky options */ - - uint8_t addr; /* [-a addr] is the I2C device address */ - uint8_t bus; /* [-b bus] is the I2C bus number */ - uint8_t regaddr; /* [-r regaddr] is the I2C device register address */ - uint8_t width; /* [-w width] is the data width (8 or 16) */ - bool start; /* [-s|n], send|don't send start between command and data */ - bool autoincr; /* [-i|j], Auto increment|don't increment regaddr on repititions */ - uint32_t freq; /* [-f freq] I2C frequency */ - - /* Output streams */ - -#ifdef CONFIG_I2CTOOL_OUTDEV - int ss_outfd; /* Output file descriptor */ - FILE *ss_outstream; /* Output stream */ -#endif -}; - -typedef int (*cmd_t)(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); - -struct cmdmap_s -{ - FAR const char *cmd; /* Name of the command */ - cmd_t handler; /* Function that handles the command */ - FAR const char *desc; /* Short description */ - FAR const char *usage; /* Usage instructions for 'help' command */ -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern const char g_i2cargrequired[]; -extern const char g_i2carginvalid[]; -extern const char g_i2cargrange[]; -extern const char g_i2ccmdnotfound[]; -extern const char g_i2ctoomanyargs[]; -extern const char g_i2ccmdfailed[]; -extern const char g_i2cxfrerror[]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Message handler */ - -ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes); -int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...); -void i2ctool_flush(FAR struct i2ctool_s *i2ctool); - -/* Command handlers */ - -int i2ccmd_bus(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); - -/* I2C access functions */ - -int i2ctool_get(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t addr, uint16_t *result); -int i2ctool_set(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t value); - -/* Common logic */ - -int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg); -int arg_string(FAR char **arg, FAR char **value); -int arg_decimal(FAR char **arg, FAR long *value); -int arg_hex(FAR char **arg, FAR long *value); - -#endif /* __APPS_SYSTEM_I2C_I2CTOOLS_H */ diff --git a/apps/system/install/Kconfig b/apps/system/install/Kconfig deleted file mode 100644 index a48f67f20..000000000 --- a/apps/system/install/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config SYSTEM_INSTALL - bool "FLASH installation tool" - default n - ---help--- - Enable support for the FLASH installation tool. - -if SYSTEM_INSTALL -endif - diff --git a/apps/system/install/Makefile b/apps/system/install/Makefile deleted file mode 100644 index 07d42887a..000000000 --- a/apps/system/install/Makefile +++ /dev/null @@ -1,121 +0,0 @@ -############################################################################ -# apps/system/install/Makefile -# -# Copyright (C) 2011 Uros Platise. All rights reserved. -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: 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. -# -############################################################################ - -# TODO, this makefile should run make under the app dirs, instead of -# sourcing the Make.defs! - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# Hello Application -# TODO: appname can be automatically extracted from the directory name - -APPNAME = install -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 1024 - -ASRCS = -CSRCS = install.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -# Register application - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -# Create dependencies - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/system/install/README.txt b/apps/system/install/README.txt deleted file mode 100644 index 66e9b0939..000000000 --- a/apps/system/install/README.txt +++ /dev/null @@ -1,26 +0,0 @@ - -Install Program -=============== - - Source: NuttX - Author: Uros Platise - Date: 7. May 2011 - -This application installs XIP application by placing it directly into -the program memory (flash) area into free area and creates a start-up -script into selected directory (i.e. /usr/bin/progname). - -Usage: - install [--stack RequiredStackSpace] [--priority Priority] - source-file destination-directory - -If stackspace is not given default stack space of 4096 Bytes is used. -If priority is not given system default is used. - -Additional options: - - --remove destination-file i.e. install --remove /usr/bin/myapp - --force to replace existing installation - --start <page> install app at or after <page> - --margin <pages> leave some free space after the kernel - Default is 16 pages so kernel may grow. diff --git a/apps/system/install/install.c b/apps/system/install/install.c deleted file mode 100644 index fd14b7a6f..000000000 --- a/apps/system/install/install.c +++ /dev/null @@ -1,470 +0,0 @@ -/**************************************************************************** - * apps/system/install/install.c - * - * Copyright (C) 2011 Uros Platise. All rights reserved. - * Author: Uros Platise <uros.platise@isotel.eu> - * - * 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/progmem.h> -#include <sys/stat.h> - -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ACTION_INSTALL 0x01 -#define ACTION_REMOVE 0x00 -#define ACTION_REINSTALL 0x03 -#define ACTION_INSUFPARAM 0x80 - -#define INSTALL_PROGRAMBLOCKSIZE 1024 - -/**************************************************************************** - * Private data - ****************************************************************************/ - -static const char *install_help = - "Installs XIP program into flash and creates a start-up script in the\n" - "destination directory.\n\n" - "Usage:\t%s [options] source-file.xip destination-directory\n\n" - "Example:\n\t%s --stack 1024 /sdcard/demo.xip /usr/bin\n\n" - "Options:\n" - "\t--stack <required_stack_space>\n" - "\t--priority <priority>\n" - "\t--remove <dest-file>\tRemoves installed application\n" - "\t--force\t\t\tReplaces existing installation\n" - "\t--start <page>\t\tInstalls application at or after <page>\n" - "\t--margin <pages>\tLeave some free space after the kernel (default 16)\n"; - -static const char *install_script_text = - "# XIP stacksize=%x priority=%x size=%x\n"; - -static const char *install_script_exec = - "exec 0x%x\n"; - -/**************************************************************************** - * Private functions - ****************************************************************************/ - -static int install_getstartpage(int startpage, int pagemargin, int desiredsize) -{ - uint16_t page = 0, stpage = 0xffff; - uint16_t pagesize = 0; - int maxlen = -1; - int maxlen_start = 0xffff; - int status; - - for (status=0, page=0; status >= 0; page++) - { - status = up_progmem_ispageerased(page); - pagesize = up_progmem_pagesize(page); - - /* Is this beginning of new free space section */ - - if (status == 0) - { - if (stpage == 0xffff) stpage = page; - } - else if (status != 0) - { - if (stpage != 0xffff) - { - if ((page - stpage) > maxlen) - { - if (maxlen==-1) - { - /* First time found sth? */ - - stpage += pagemargin; - maxlen = 0; - } - - if(stpage < startpage) - { - stpage = startpage; - } - - if (page > stpage) - { - maxlen = page - stpage; - maxlen_start = stpage; - } - - if (maxlen*pagesize >= desiredsize) - { - /* printf("Found page at %d ... %d\n", stpage, page); */ - return maxlen_start*pagesize; - } - } - - stpage = 0xffff; - } - } - } - - /* Requested space is not available */ - - return -1; -} - -static int install_programflash(int startaddr, const char *source) -{ - int status; - int count; - int totalsize = 0; - char *buf; - FILE *fp; - - if ((buf = malloc(INSTALL_PROGRAMBLOCKSIZE)) == NULL) - { - return -ENOMEM; - } - - if ((fp = fopen(source, "r"))) - { - do - { - count = fread(buf, 1, INSTALL_PROGRAMBLOCKSIZE, fp); - - if ((status = up_progmem_write(startaddr, buf, count)) < 0) - { - totalsize = status; - break; - } - - startaddr += count; - totalsize += count; - } - while(count); - } - else - { - totalsize = -errno; - } - - fclose(fp); - free(buf); - - return totalsize; -} - -static void install_getscriptname(char *scriptname, const char *progname, const char *destdir) -{ - const char * progonly; - - /* I.e. as /usr/bin */ - - strcpy(scriptname, destdir); - - /* extract from i.e. /sdcard/demo -> /demo, together with / */ - - progonly = strrchr(progname, '/'); - strcat(scriptname, progonly); -} - -static int install_getprogsize(const char *progname) -{ - struct stat fileinfo; - - if (stat(progname, &fileinfo) < 0) - { - return -1; - } - - return fileinfo.st_size; -} - -static int install_alreadyexists(const char *scriptname) -{ - FILE *fp; - - if ((fp = fopen(scriptname, "r")) == NULL) - { - return 0; - } - - fclose(fp); - return 1; -} - -static int install_createscript(int addr, int stacksize, int progsize, - int priority, const char *scriptname) -{ - FILE *fp; - - if ((fp = fopen(scriptname, "w+")) == NULL) - { - return -errno; - } - - fprintf(fp, install_script_text, stacksize, priority, progsize); - fprintf(fp, install_script_exec, addr); - - fflush(fp); - fclose(fp); - - return 0; -} - -static int install_getlasthexvalue(FILE *fp, char delimiter) -{ - char buf[128]; - char *p; - - if (fgets(buf, 127, fp)) - { - if ((p = strrchr(buf, delimiter))) - { - return strtol(p+1, NULL, 16); - } - } - - return -1; -} - -static int install_remove(const char *scriptname) -{ - FILE *fp; - int progsize, addr, freedsize; - uint16_t page; - int status = 0; - - /* Parse script */ - - if ((fp = fopen(scriptname, "r"))) - { - progsize = install_getlasthexvalue(fp,'='); - addr = install_getlasthexvalue(fp,' '); - freedsize = progsize; - } - else - { - return -errno; - } - - fclose(fp); - - /* Remove pages */ - - if (progsize <= 0 || addr <= 0) - { - return -EIO; - } - - do - { - if ((page = up_progmem_getpage(addr)) < 0) - { - status = -page; - break; - } - - if (up_progmem_erasepage(page) < 0) - { - status = -page; - break; - } - - addr += up_progmem_pagesize(page); - progsize -= up_progmem_pagesize(page); - - } - while(progsize > 0); - - if (status < 0) - { - return status; - } - - /* Remove script file */ - - if (unlink(scriptname) < 0) - { - return -errno; - } - - return freedsize; -} - - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int install_main(int argc, char *argv[]) -{ - int i; - int progsize; - int scrsta; - int stacksize = 4096; - int priority = SCHED_PRIORITY_DEFAULT; - int pagemargin = 16; - int startpage = 0; - int startaddr = 0; - int action = ACTION_INSTALL; - char scriptname[128]; - - /* Supported? */ - - if (!up_progmem_isuniform()) - { - fprintf(stderr, "Error: install supports uniform organization only.\n"); - return -1; - } - - /* Parse arguments */ - - for (i=1; i<argc; i++) - { - if (argv[i][0]=='-' && argv[i][1]=='-' && i<=argc) - { - if (strcmp(argv[i]+2, "stack")==0) - { - stacksize = atoi(argv[++i]); - } - else if (strcmp(argv[i]+2, "priority")==0) - { - priority = atoi(argv[++i]); - } - else if (strcmp(argv[i]+2, "start")==0) - { - startpage = atoi(argv[++i]); - } - else if (strcmp(argv[i]+2, "margin")==0) - { - pagemargin = atoi(argv[++i]); - } - else if (strcmp(argv[i]+2, "remove")==0) - { - action = ACTION_REMOVE; - } - else if (strcmp(argv[i]+2, "force")==0) - { - action = ACTION_REINSTALL; - } - else fprintf(stderr, "Unknown option: %s\n", argv[i]); - } - else - { - break; - } - } - - /* Do the job */ - - switch(action & 1) - { - case ACTION_REMOVE: - if (i > argc-1) - { - action = ACTION_INSUFPARAM; - break; /* are there sufficient parameters */ - } - - if ((scrsta=install_remove(argv[i])) < 0) - { - fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta)); - return -1; - } - - printf("Removed %s and freed %d bytes\n", argv[i], scrsta); - return 0; - - case ACTION_INSTALL: - if (i > argc-2) - { - action = ACTION_INSUFPARAM; - break; /* are there sufficient parameters */ - } - - install_getscriptname(scriptname, argv[i], argv[i+1]); - - /* script-exists? */ - - if (install_alreadyexists(scriptname) == 1) - { - if (action != ACTION_REINSTALL) - { - fprintf(stderr, "Program with that name already exists.\n"); - return -EEXIST; - } - - if ((scrsta = install_remove(scriptname)) < 0) - { - fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta)); - return -1; - } - - printf("Replacing %s\n", scriptname); - } - - startaddr = install_getstartpage(startpage, pagemargin, install_getprogsize(argv[i])); - if (startpage < 0) - { - fprintf(stderr, "Not enough memory\n"); - return -ENOMEM; - } - - if ((progsize = install_programflash(startaddr, argv[i])) <= 0) - { - fprintf(stderr, "Error writing program memory: %s\n" - "Note: Flash pages are not released, so you may try again and program will be\n" - " written in other pages.\n", strerror(-progsize)); - return -EIO; - } - - if ((scrsta = install_createscript(startaddr, stacksize, progsize, - priority, scriptname)) < 0) - { - fprintf(stderr, "Error writing program script at %s: %s\n", - argv[i+1], strerror(-scrsta)); - return -EIO; - } - - printf("Installed application of size %d bytes to program memory [%xh - %xh].\n", - progsize, startaddr, startaddr + progsize); - return 0; - } - - fprintf(stderr, install_help, argv[0], argv[0]); - return -1; -} diff --git a/apps/system/readline/Kconfig b/apps/system/readline/Kconfig deleted file mode 100644 index 6482b1204..000000000 --- a/apps/system/readline/Kconfig +++ /dev/null @@ -1,22 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config SYSTEM_READLINE - bool "readline() support" - default n - ---help--- - Enable support for the readline() function. - -if SYSTEM_READLINE -config READLINE_ECHO - bool "Echo character input" - default y - ---help--- - Echo received character input back via stdout. This is normal - behavior and should be selected unless the source of stdin input - already has local echo support or you need to suppress the back-channel - responses for any other reason. - -endif diff --git a/apps/system/readline/Makefile b/apps/system/readline/Makefile deleted file mode 100644 index 040fd2e28..000000000 --- a/apps/system/readline/Makefile +++ /dev/null @@ -1,106 +0,0 @@ -############################################################################ -# apps/system/readline/Makefile -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# The Readline Library - -ASRCS = -CSRCS = readline.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -# Context build phase target - -context: - -# Dependency build phase target - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -# Housekeeping targets - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c deleted file mode 100644 index a8240a62a..000000000 --- a/apps/system/readline/readline.c +++ /dev/null @@ -1,432 +0,0 @@ -/**************************************************************************** - * apps/system/readline/readline.c - * - * Copyright (C) 2007-2008, 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/ascii.h> -#include <nuttx/vt100.h> - -#include <apps/readline.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* In some systems, the underlying serial logic may automatically echo - * characters back to the console. We will assume that that is not the case - & here - */ - -#define CONFIG_READLINE_ECHO 1 - -/* Some environments may return CR as end-of-line, others LF, and others - * both. If not specified, the logic here assumes either (but not both) as - * the default. - */ - -#if defined(CONFIG_EOL_IS_CR) -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_LF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_EITHER_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -#else -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# define CONFIG_EOL_IS_EITHER_CRLF 1 -#endif - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ -/* <esc>[K is the VT100 command erases to the end of the line. */ - -static const char g_erasetoeol[] = VT100_CLEAREOL; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: readline_rawgetc - ****************************************************************************/ - -static inline int readline_rawgetc(int infd) -{ - char buffer; - ssize_t nread; - - /* Loop until we successfully read a character (or until an unexpected - * error occurs). - */ - - for (;;) - { - /* Read one character from the incoming stream */ - - nread = read(infd, &buffer, 1); - - /* Check for end-of-file. */ - - if (nread == 0) - { - /* Return zero on end-of-file */ - - return 0; - } - - /* Check if an error occurred */ - - else if (nread < 0) - { - /* EINTR is not really an error; it simply means that a signal we - * received while watiing for intput. - */ - - int errcode = errno; - if (errcode != EINTR) - { - return -errcode; - } - - continue; - } - - else if (buffer == '\0') - { - /* Ignore NUL characters, since they look like EOF to our caller */ - - continue; - } - - /* Success, return the character that was read */ - - return (int)buffer; - } -} - -/**************************************************************************** - * Name: readline_consoleputc - ****************************************************************************/ - -#ifdef CONFIG_READLINE_ECHO -static inline void readline_consoleputc(int ch, int outfd) -{ - char buffer = ch; - ssize_t nwritten; - - /* Loop until we successfully write a character (or until an unexpected - * error occurs). - */ - - do - { - /* Write the character to the outgoing stream */ - - nwritten = write(outfd, &buffer, 1); - - /* Check for irrecoverable write errors. */ - - if (nwritten < 0 && errno != EINTR) - { - break; - } - } - while (nwritten < 1); -} -#endif - -/**************************************************************************** - * Name: readline_consolewrite - ****************************************************************************/ - -#ifdef CONFIG_READLINE_ECHO -static inline void readline_consolewrite(int outfd, FAR const char *buffer, size_t buflen) -{ - (void)write(outfd, buffer, buflen); -} -#endif - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: readline - * - * readline() reads in at most one less than 'buflen' characters from - * 'instream' and stores them into the buffer pointed to by 'buf'. - * Characters are echoed on 'outstream'. Reading stops after an EOF or a - * newline. If a newline is read, it is stored into the buffer. A null - * terminator is stored after the last character in the buffer. - * - * This version of realine assumes that we are reading and writing to - * a VT100 console. This will not work well if 'instream' or 'outstream' - * corresponds to a raw byte steam. - * - * This function is inspired by the GNU readline but is an entirely - * different creature. - * - * Input Parameters: - * buf - The user allocated buffer to be filled. - * buflen - the size of the buffer. - * instream - The stream to read characters from - * outstream - The stream to each characters to. - * - * Returned values: - * On success, the (positive) number of bytes transferred is returned. - * A length of zero would indicate an end of file condition. On failure, - * a negated errno value is returned. - * - **************************************************************************/ - -ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) -{ - int infd; - int outfd; - int escape; - int nch; - - /* Sanity checks */ - - if (!instream || !outstream || !buf || buflen < 1) - { - return -EINVAL; - } - - if (buflen < 2) - { - *buf = '\0'; - return 0; - } - - /* Extract the file descriptions. This is cheating (and horribly non- - * standard) - */ - - infd = instream->fs_filedes; - outfd = outstream->fs_filedes; - - /* <esc>[K is the VT100 command that erases to the end of the line. */ - -#ifdef CONFIG_READLINE_ECHO - readline_consolewrite(outfd, g_erasetoeol, sizeof(g_erasetoeol)); -#endif - - /* Read characters until we have a full line. On each the loop we must - * be assured that there are two free bytes in the line buffer: One for - * the next character and one for the null terminator. - */ - - escape = 0; - nch = 0; - - for(;;) - { - /* Get the next character */ - - int ch = readline_rawgetc(infd); - - /* Check for end-of-file or read error */ - - if (ch <= 0) - { - /* Did we already received some data? */ - - if (nch > 0) - { - /* Yes.. Terminate the line (which might be zero length) - * and return the data that was received. The end-of-file - * or error condition will be reported next time. - */ - - buf[nch] = '\0'; - return nch; - } - - return ch; - } - - /* Are we processing a VT100 escape sequence */ - - else if (escape) - { - /* Yes, is it an <esc>[, 3 byte sequence */ - - if (ch != ASCII_LBRACKET || escape == 2) - { - /* We are finished with the escape sequence */ - - escape = 0; - ch = 'a'; - } - else - { - /* The next character is the end of a 3-byte sequence. - * NOTE: Some of the <esc>[ sequences are longer than - * 3-bytes, but I have not encountered any in normal use - * yet and, so, have not provided the decoding logic. - */ - - escape = 2; - } - } - - /* Check for backspace - * - * There are several notions of backspace, for an elaborate summary see - * http://www.ibb.net/~anne/keyboard.html. There is no clean solution. - * Here both DEL and backspace are treated like backspace here. The - * Unix/Linux screen terminal by default outputs DEL (0x7f) when the - * backspace key is pressed. - */ - - else if (ch == ASCII_BS || ch == ASCII_DEL) - { - /* Eliminate that last character in the buffer. */ - - if (nch > 0) - { - nch--; - -#ifdef CONFIG_READLINE_ECHO - /* Echo the backspace character on the console. Always output - * the backspace character because the VT100 terminal doesn't - * understand DEL properly. - */ - - readline_consoleputc(ASCII_BS, outfd); - readline_consolewrite(outfd, g_erasetoeol, sizeof(g_erasetoeol)); -#endif - } - } - - /* Check for the beginning of a VT100 escape sequence */ - - else if (ch == ASCII_ESC) - { - /* The next character is escaped */ - - escape = 1; - } - - /* Check for end-of-line. This is tricky only in that some - * environments may return CR as end-of-line, others LF, and - * others both. - */ - -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) - else if (ch == '\n') -#elif defined(CONFIG_EOL_IS_CR) - else if (ch == '\r') -#elif CONFIG_EOL_IS_EITHER_CRLF - else if (ch == '\n' || ch == '\r') -#endif - { - /* The newline is stored in the buffer along with the null - * terminator. - */ - - buf[nch++] = '\n'; - buf[nch] = '\0'; - -#ifdef CONFIG_READLINE_ECHO - /* Echo the newline to the console */ - - readline_consoleputc('\n', outfd); -#endif - return nch; - } - - /* Otherwise, check if the character is printable and, if so, put the - * character in the line buffer - */ - - else if (isprint(ch)) - { - buf[nch++] = ch; - -#ifdef CONFIG_READLINE_ECHO - /* Echo the character to the console */ - - readline_consoleputc(ch, outfd); -#endif - /* Check if there is room for another character and the line's - * null terminator. If not then we have to end the line now. - */ - - if (nch + 1 >= buflen) - { - buf[nch] = '\0'; - return nch; - } - } - } -} - diff --git a/apps/system/usbmonitor/Kconfig b/apps/system/usbmonitor/Kconfig deleted file mode 100644 index bde97de15..000000000 --- a/apps/system/usbmonitor/Kconfig +++ /dev/null @@ -1,67 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config SYSTEM_USBMONITOR - bool "USB Monitor" - default n - depends on USBDEV && USBDEV_TRACE && SYSLOG - ---help--- - If USB device tracing is enabled (USBDEV_TRACE), then this option - will select the USB monitor. The USB monitor is a daemon that will - periodically collect the buffered USB trace data and dump it to the - SYSLOG device. - -if SYSTEM_USBMONITOR - -config SYSTEM_USBMONITOR_STACKSIZE - int "USB Monitor daemon stack size" - default 2048 - ---help--- - The stack size to use the the USB monitor daemon. Default: 2048 - -config SYSTEM_USBMONITOR_PRIORITY - int "USB Monitor daemon priority" - default 50 - ---help--- - The priority to use the the USB monitor daemon. Default: 50 - -config SYSTEM_USBMONITOR_INTERVAL - int "USB Monitor dump frequency" - default 2 - ---help--- - The rate in seconds that the USB monitor will wait before dumping - the next set of buffered USB trace data. Default: 2 seconds. - -config SYSTEM_USBMONITOR_TRACEINIT - bool "Show initialization events" - default n - ---help--- - Show initialization events - -config SYSTEM_USBMONITOR_TRACECLASS - bool "Show class driver events" - default n - ---help--- - Show class driver events - -config SYSTEM_USBMONITOR_TRACETRANSFERS - bool "Show data transfer events" - default n - ---help--- - Show data transfer events - -config SYSTEM_USBMONITOR_TRACECONTROLLER - bool "Show controller events" - default n - ---help--- - Show controller events - -config SYSTEM_USBMONITOR_TRACEINTERRUPTS - bool "Show interrupt-related events" - default n - ---help--- - Show interrupt-related events -endif - diff --git a/apps/system/usbmonitor/Makefile b/apps/system/usbmonitor/Makefile deleted file mode 100644 index 56b6ccee1..000000000 --- a/apps/system/usbmonitor/Makefile +++ /dev/null @@ -1,117 +0,0 @@ -############################################################################ -# apps/system/usbmonitor/Makefile -# -# Copyright (C) 2013 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# USB Monitor Application - -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 768 - -ASRCS = -CSRCS = usbmonitor.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -# Register application - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)usbmonitor_start.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,"usbmon_start",$(PRIORITY),$(STACKSIZE),usbmonitor_start) - -$(BUILTIN_REGISTRY)$(DELIM)usbmonitor_stop.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,"usbmon_stop",$(PRIORITY),$(STACKSIZE),usbmonitor_stop) - -context: $(BUILTIN_REGISTRY)$(DELIM)usbmonitor_start.bdat $(BUILTIN_REGISTRY)$(DELIM)usbmonitor_stop.bdat -else -context: -endif - -# Create dependencies - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/system/usbmonitor/usbmonitor.c b/apps/system/usbmonitor/usbmonitor.c deleted file mode 100644 index cde945b43..000000000 --- a/apps/system/usbmonitor/usbmonitor.c +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** - * apps/system/usbmonitor/usbmonitor.c - * - * Copyright (C) 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 <nuttx/progmem.h> - -#include <sys/types.h> -#include <stdbool.h> -#include <unistd.h> -#include <sched.h> -#include <syslog.h> -#include <errno.h> - -#include <nuttx/usb/usbdev_trace.h> - -#ifdef CONFIG_SYSTEM_USBMONITOR - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define USBMON_PREFIX "USB Monitor: " - -/* Configuration ************************************************************/ - -#ifndef CONFIG_SYSTEM_USBMONITOR_STACKSIZE -# define CONFIG_SYSTEM_USBMONITOR_STACKSIZE 2048 -#endif - -#ifndef CONFIG_SYSTEM_USBMONITOR_PRIORITY -# define CONFIG_SYSTEM_USBMONITOR_PRIORITY 50 -#endif - -#ifndef CONFIG_SYSTEM_USBMONITOR_INTERVAL -# define CONFIG_SYSTEM_USBMONITOR_INTERVAL 2 -#endif - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACEINIT -# define TRACE_INIT_BITS (TRACE_INIT_BIT) -#else -# define TRACE_INIT_BITS (0) -#endif - -#define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACECLASS -# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|\ - TRACE_CLASSSTATE_BIT) -#else -# define TRACE_CLASS_BITS (0) -#endif - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACETRANSFERS -# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|\ - TRACE_READ_BIT|TRACE_WRITE_BIT|\ - TRACE_COMPLETE_BIT) -#else -# define TRACE_TRANSFER_BITS (0) -#endif - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACECONTROLLER -# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) -#else -# define TRACE_CONTROLLER_BITS (0) -#endif - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACEINTERRUPTS -# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|\ - TRACE_INTEXIT_BIT) -#else -# define TRACE_INTERRUPT_BITS (0) -#endif - -#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|\ - TRACE_CLASS_BITS|TRACE_TRANSFER_BITS|\ - TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct usbmon_state_s -{ - volatile bool started; - volatile bool stop; - pid_t pid; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct usbmon_state_s g_usbmonitor; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int usbmonitor_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf((trprintf_t)syslog, trace->event, trace->value); - return 0; -} - -static int usbmonitor_daemon(int argc, char **argv) -{ - syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid); - - /* Loop until we detect that there is a request to stop. */ - - while (!g_usbmonitor.stop) - { - sleep(CONFIG_SYSTEM_USBMONITOR_INTERVAL); - (void)usbtrace_enumerate(usbmonitor_tracecallback, NULL); - } - - /* Stopped */ - - g_usbmonitor.stop = false; - g_usbmonitor.started = false; - syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int usbmonitor_start(int argc, char **argv) -{ - /* Has the monitor already started? */ - - sched_lock(); - if (!g_usbmonitor.started) - { - int ret; - - /* No.. start it now */ - - /* First, initialize any USB tracing options that were requested */ - - usbtrace_enable(TRACE_BITSET); - - /* Then start the USB monitoring daemon */ - - g_usbmonitor.started = true; - g_usbmonitor.stop = false; - - ret = TASK_CREATE("USB Monitor", CONFIG_SYSTEM_USBMONITOR_PRIORITY, - CONFIG_SYSTEM_USBMONITOR_STACKSIZE, - (main_t)usbmonitor_daemon, (const char **)NULL); - if (ret < 0) - { - int errcode = errno; - syslog(USBMON_PREFIX - "ERROR: Failed to start the USB monitor: %d\n", - errcode); - } - else - { - g_usbmonitor.pid = ret; - syslog(USBMON_PREFIX "Started: %d\n", g_usbmonitor.pid); - } - - sched_unlock(); - return 0; - } - - sched_unlock(); - syslog(USBMON_PREFIX "%s: %d\n", - g_usbmonitor.stop ? "Stopping" : "Running", g_usbmonitor.pid); - return 0; -} - -int usbmonitor_stop(int argc, char **argv) -{ - /* Has the monitor already started? */ - - if (g_usbmonitor.started) - { - /* Stop the USB monitor. The next time the monitor wakes up, - * it will see the the stop indication and will exist. - */ - - syslog(USBMON_PREFIX "Stopping: %d\n", g_usbmonitor.pid); - g_usbmonitor.stop = true; - - /* We may as well disable tracing since there is no listener */ - - usbtrace_enable(0); - } - - syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); - return 0; -} - -#endif /* CONFIG_SYSTEM_USBMONITOR */ |