Resync new repository with old repo r5166

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-09-17 18:18:44 +00:00
commit 57623d42eb
5691 changed files with 1361853 additions and 0 deletions
+208
View File
@@ -0,0 +1,208 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
menu "ADC Example"
source "$APPSDIR/examples/adc/Kconfig"
endmenu
menu "Buttons Example"
source "$APPSDIR/examples/buttons/Kconfig"
endmenu
menu "CAN Example"
source "$APPSDIR/examples/can/Kconfig"
endmenu
menu "USB CDC/ACM Class Driver Example"
source "$APPSDIR/examples/cdcacm/Kconfig"
endmenu
menu "USB composite Class Driver Example"
source "$APPSDIR/examples/composite/Kconfig"
endmenu
menu "DHCP Server Example"
source "$APPSDIR/examples/dhcpd/Kconfig"
endmenu
menu "FTP Client Example"
source "$APPSDIR/examples/ftpc/Kconfig"
endmenu
menu "FTP Server Example"
source "$APPSDIR/examples/ftpd/Kconfig"
endmenu
menu "\"Hello, World!\" Example"
source "$APPSDIR/examples/hello/Kconfig"
endmenu
menu "\"Hello, World!\" C++ Example"
source "$APPSDIR/examples/helloxx/Kconfig"
endmenu
menu "USB HID Keyboard Example"
source "$APPSDIR/examples/hidkbd/Kconfig"
endmenu
menu "IGMP Example"
source "$APPSDIR/examples/igmp/Kconfig"
endmenu
menu "LCD Read/Write Example"
source "$APPSDIR/examples/lcdrw/Kconfig"
endmenu
menu "Memory Management Example"
source "$APPSDIR/examples/mm/Kconfig"
endmenu
menu "File System Mount Example"
source "$APPSDIR/examples/mount/Kconfig"
endmenu
menu "FreeModBus Example"
source "$APPSDIR/examples/modbus/Kconfig"
endmenu
menu "Network Test Example"
source "$APPSDIR/examples/nettest/Kconfig"
endmenu
menu "NuttShell (NSH) Example"
source "$APPSDIR/examples/nsh/Kconfig"
endmenu
menu "NULL Example"
source "$APPSDIR/examples/null/Kconfig"
endmenu
menu "NX Graphics Example"
source "$APPSDIR/examples/nx/Kconfig"
endmenu
menu "NxConsole Example"
source "$APPSDIR/examples/nxconsole/Kconfig"
endmenu
menu "NXFFS File System Example"
source "$APPSDIR/examples/nxffs/Kconfig"
endmenu
menu "NXFLAT Example"
source "$APPSDIR/examples/nxflat/Kconfig"
endmenu
menu "NX Graphics \"Hello, World!\" Example"
source "$APPSDIR/examples/nxhello/Kconfig"
endmenu
menu "NX Graphics image Example"
source "$APPSDIR/examples/nximage/Kconfig"
endmenu
menu "NX Graphics lines Example"
source "$APPSDIR/examples/nxlines/Kconfig"
endmenu
menu "NX Graphics Text Example"
source "$APPSDIR/examples/nxtext/Kconfig"
endmenu
menu "OS Test Example"
source "$APPSDIR/examples/ostest/Kconfig"
endmenu
menu "Pascal \"Hello, World!\"example"
source "$APPSDIR/examples/pashello/Kconfig"
endmenu
menu "Pipe Example"
source "$APPSDIR/examples/pipe/Kconfig"
endmenu
menu "Poll Example"
source "$APPSDIR/examples/poll/Kconfig"
endmenu
menu "Pulse Width Modulation (PWM) Example"
source "$APPSDIR/examples/pwm/Kconfig"
endmenu
menu "Quadrature Encoder Example"
source "$APPSDIR/examples/qencoder/Kconfig"
endmenu
menu "RGMP Example"
source "$APPSDIR/examples/rgmp/Kconfig"
endmenu
menu "ROMFS Example"
source "$APPSDIR/examples/romfs/Kconfig"
endmenu
menu "sendmail Example"
source "$APPSDIR/examples/sendmail/Kconfig"
endmenu
menu "Serial Loopback Example"
source "$APPSDIR/examples/serloop/Kconfig"
endmenu
menu "Telnet Daemon Example"
source "$APPSDIR/examples/telnetd/Kconfig"
endmenu
menu "THTTPD Web Server Example"
source "$APPSDIR/examples/thttpd/Kconfig"
endmenu
menu "TIFF Generation Example"
source "$APPSDIR/examples/tiff/Kconfig"
endmenu
menu "Touchscreen Example"
source "$APPSDIR/examples/touchscreen/Kconfig"
endmenu
menu "UDP Example"
source "$APPSDIR/examples/udp/Kconfig"
endmenu
menu "UDP Discovery Daemon Example"
source "$APPSDIR/examples/discover/Kconfig"
endmenu
menu "uIP Web Server Example"
source "$APPSDIR/examples/uip/Kconfig"
endmenu
menu "USB Serial Test Example"
source "$APPSDIR/examples/usbserial/Kconfig"
endmenu
menu "USB Mass Storage Class Example"
source "$APPSDIR/examples/usbstorage/Kconfig"
endmenu
menu "USB Serial Terminal Example"
source "$APPSDIR/examples/usbterm/Kconfig"
endmenu
menu "Watchdog timer Example"
source "$APPSDIR/examples/watchdog/Kconfig"
endmenu
menu "wget Example"
source "$APPSDIR/examples/wget/Kconfig"
endmenu
menu "WLAN Example"
source "$APPSDIR/examples/wlan/Kconfig"
endmenu
menu "XML RPC Example"
source "$APPSDIR/examples/xmlrpc/Kconfig"
endmenu
+231
View File
@@ -0,0 +1,231 @@
############################################################################
# apps/examples/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_EXAMPLES_ADC),y)
CONFIGURED_APPS += examples/adc
endif
ifeq ($(CONFIG_EXAMPLES_BUTTONS),y)
CONFIGURED_APPS += examples/buttons
endif
ifeq ($(CONFIG_EXAMPLES_CAN),y)
CONFIGURED_APPS += examples/can
endif
ifeq ($(CONFIG_EXAMPLES_CDCACM),y)
CONFIGURED_APPS += examples/cdcacm
endif
ifeq ($(CONFIG_EXAMPLES_COMPOSITE),y)
CONFIGURED_APPS += examples/composite
endif
ifeq ($(CONFIG_EXAMPLES_DHCPD),y)
CONFIGURED_APPS += examples/dhcpd
endif
ifeq ($(CONFIG_EXAMPLE_DISCOVER),y)
CONFIGURED_APPS += examples/discover
endif
ifeq ($(CONFIG_EXAMPLES_FTPC),y)
CONFIGURED_APPS += examples/ftpc
endif
ifeq ($(CONFIG_EXAMPLES_FTPD),y)
CONFIGURED_APPS += examples/ftpd
endif
ifeq ($(CONFIG_EXAMPLES_HELLO),y)
CONFIGURED_APPS += examples/hello
endif
ifeq ($(CONFIG_EXAMPLES_HELLOXX),y)
CONFIGURED_APPS += examples/helloxx
endif
ifeq ($(CONFIG_EXAMPLES_HIDKBD),y)
CONFIGURED_APPS += examples/hidkbd
endif
ifeq ($(CONFIG_EXAMPLES_IGMP),y)
CONFIGURED_APPS += examples/igmp
endif
ifeq ($(CONFIG_EXAMPLES_LCDRW),y)
CONFIGURED_APPS += examples/lcdrw
endif
ifeq ($(CONFIG_EXAMPLES_MM),y)
CONFIGURED_APPS += examples/mm
endif
ifeq ($(CONFIG_EXAMPLES_MOUNT),y)
CONFIGURED_APPS += examples/mount
endif
ifeq ($(CONFIG_EXAMPLES_NETTEST),y)
CONFIGURED_APPS += examples/nettest
endif
ifeq ($(CONFIG_EXAMPLES_NSH),y)
CONFIGURED_APPS += examples/nsh
endif
ifeq ($(CONFIG_EXAMPLES_NULL),y)
CONFIGURED_APPS += examples/null
endif
ifeq ($(CONFIG_EXAMPLES_NX),y)
CONFIGURED_APPS += examples/nx
endif
ifeq ($(CONFIG_EXAMPLES_NXCONSOLE),y)
CONFIGURED_APPS += examples/nxconsole
endif
ifeq ($(CONFIG_EXAMPLES_NXFFS),y)
CONFIGURED_APPS += examples/nxffs
endif
ifeq ($(CONFIG_EXAMPLES_NXFLAT),y)
CONFIGURED_APPS += examples/nxflat
endif
ifeq ($(CONFIG_EXAMPLES_NXHELLO),y)
CONFIGURED_APPS += examples/nxhello
endif
ifeq ($(CONFIG_EXAMPLES_NXIMAGE),y)
CONFIGURED_APPS += examples/nximage
endif
ifeq ($(CONFIG_EXAMPLES_NXLINES),y)
CONFIGURED_APPS += examples/nxlines
endif
ifeq ($(CONFIG_EXAMPLES_NXTEXT),y)
CONFIGURED_APPS += examples/nxtext
endif
ifeq ($(CONFIG_EXAMPLES_OSTEST),y)
CONFIGURED_APPS += examples/ostest
endif
ifeq ($(CONFIG_EXAMPLES_PASHELLO),y)
CONFIGURED_APPS += examples/pashello
endif
ifeq ($(CONFIG_EXAMPLES_PIPE),y)
CONFIGURED_APPS += examples/pipe
endif
ifeq ($(CONFIG_EXAMPLES_POLL),y)
CONFIGURED_APPS += examples/poll
endif
ifeq ($(CONFIG_EXAMPLES_PWM),y)
CONFIGURED_APPS += examples/pwm
endif
ifeq ($(CONFIG_EXAMPLES_QENCODER),y)
CONFIGURED_APPS += examples/qencoder
endif
ifeq ($(CONFIG_EXAMPLES_RGMP),y)
CONFIGURED_APPS += examples/rgmp
endif
ifeq ($(CONFIG_EXAMPLES_ROMFS),y)
CONFIGURED_APPS += examples/romfs
endif
ifeq ($(CONFIG_EXAMPLES_SENDMAIL),y)
CONFIGURED_APPS += examples/sendmail
endif
ifeq ($(CONFIG_EXAMPLES_SERLOOP),y)
CONFIGURED_APPS += examples/serloop
endif
ifeq ($(CONFIG_EXAMPLES_TELNETD),y)
CONFIGURED_APPS += examples/telnetd
endif
ifeq ($(CONFIG_EXAMPLES_THTTPD),y)
CONFIGURED_APPS += examples/thttpd
endif
ifeq ($(CONFIG_EXAMPLES_TIFF),y)
CONFIGURED_APPS += examples/tiff
endif
ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN),y)
CONFIGURED_APPS += examples/touchscreen
endif
ifeq ($(CONFIG_EXAMPLES_UDP),y)
CONFIGURED_APPS += examples/udp
endif
ifeq ($(CONFIG_EXAMPLES_UIP),y)
CONFIGURED_APPS += examples/uip
endif
ifeq ($(CONFIG_EXAMPLES_USBSERIAL),y)
CONFIGURED_APPS += examples/usbserial
endif
ifeq ($(CONFIG_EXAMPLES_USBMSC),y)
CONFIGURED_APPS += examples/usbmsc
endif
ifeq ($(CONFIG_EXAMPLES_USBTERM),y)
CONFIGURED_APPS += examples/usbterm
endif
ifeq ($(CONFIG_EXAMPLES_WGET),y)
CONFIGURED_APPS += examples/wget
endif
ifeq ($(CONFIG_EXAMPLES_WLAN),y)
CONFIGURED_APPS += examples/wlan
endif
ifeq ($(CONFIG_EXAMPLES_XMLRPC),y)
CONFIGURED_APPS += examples/xmlrpc
endif
+131
View File
@@ -0,0 +1,131 @@
############################################################################
# apps/examples/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
SUBDIRS = adc buttons can cdcacm composite dhcpd discover ftpc ftpd hello
SUBDIRS += helloxx hidkbd igmp lcdrw mm modbus mount nettest nsh null nx
SUBDIRS += nxconsole nxffs nxflat nxhello nximage nxlines nxtext ostest
SUBDIRS += pashello pipe poll pwm qencoder rgmp romfs serloop telnetd
SUBDIRS += thttpd tiff touchscreen udp uip usbserial sendmail usbstorage
SUBDIRS += usbterm watchdog wget wlan
# Sub-directories that might need context setup. Directories may need
# context setup for a variety of reasons, but the most common is because
# the example may be built as an NSH built-in function.
#
# Directories that may be built as NSH built-in functions may have their
# own configuration setting (like CONFIG_EXAMPLES_HELLOXX_BUILTIN), but
# many only depend on the generic CONFIG_NSH_BUILTIN_APPS setting. And
# there a few which an ONLY be built as NSH built-in applications; these
# are included in the list unconditionally.
CNTXTDIRS = pwm
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
CNTXTDIRS += adc can cdcacm composite discover ftpd dhcpd modbus nettest
CNTXTDIRS += qencoder telnetd watchdog
endif
ifeq ($(CONFIG_EXAMPLES_HELLO_BUILTIN),y)
CNTXTDIRS += hello
endif
ifeq ($(CONFIG_EXAMPLES_HELLOXX_BUILTIN),y)
CNTXTDIRS += helloxx
endif
ifeq ($(CONFIG_EXAMPLES_LCDRW_BUILTIN),y)
CNTXTDIRS += lcdrw
endif
ifeq ($(CONFIG_EXAMPLES_NX_BUILTIN),y)
CNTXTDIRS += nx
endif
ifeq ($(CONFIG_EXAMPLES_NXHELLO_BUILTIN),y)
CNTXTDIRS += nxhello
endif
ifeq ($(CONFIG_EXAMPLES_NXIMAGE_BUILTIN),y)
CNTXTDIRS += nximage
endif
ifeq ($(CONFIG_EXAMPLES_LINES_BUILTIN),y)
CNTXTDIRS += nxlines
endif
ifeq ($(CONFIG_EXAMPLES_NXTEXT_BUILTIN),y)
CNTXTDIRS += nxtext
endif
ifeq ($(CONFIG_EXAMPLES_OSTEST_BUILTIN),y)
CNTXTDIRS += ostest
endif
ifeq ($(CONFIG_EXAMPLES_TIFF_BUILTIN),y)
CNTXTDIRS += tiff
endif
ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN),y)
CNTXTDIRS += touchscreen
endif
ifeq ($(CONFIG_EXAMPLES_USBMSC_BUILTIN),y)
CNTXTDIRS += usbstorage
endif
ifeq ($(CONFIG_EXAMPLES_USBTERM_BUILTIN),y)
CNTXTDIRS += usbterm
endif
all: nothing
.PHONY: nothing context depend clean distclean
nothing:
context:
@for dir in $(CNTXTDIRS) ; do \
$(MAKE) -C $$dir context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
done
depend:
@for dir in $(SUBDIRS) ; do \
$(MAKE) -C $$dir depend TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
done
clean:
@for dir in $(SUBDIRS) ; do \
$(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
done
distclean: clean
@for dir in $(SUBDIRS) ; do \
$(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
done
-include Make.dep
File diff suppressed because it is too large Load Diff
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_ADC
bool "ADC example"
default n
---help---
Enable the ADC example
if EXAMPLES_ADC
endif
+105
View File
@@ -0,0 +1,105 @@
############################################################################
# apps/examples/adc/Makefile
#
# 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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# NuttX NX Graphics Example.
ASRCS =
CSRCS = adc_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Touchscreen built-in application info
APPNAME = adc
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: context clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+125
View File
@@ -0,0 +1,125 @@
/****************************************************************************
* examples/examples/adc/adc.h
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __APPS_EXAMPLES_ADC_ADC_H
#define __APPS_EXAMPLES_ADC_ADC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* CONFIG_NSH_BUILTIN_APPS - Build the ADC test as an NSH built-in function.
* Default: Built as a standalone problem
* CONFIG_EXAMPLES_ADC_DEVPATH - The default path to the ADC device. Default: /dev/adc0
* CONFIG_EXAMPLES_ADC_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS
* is defined, then the number of samples is provided on the command line
* and this value is ignored. Otherwise, this number of samples is
* collected and the program terminates. Default: Samples are collected
* indefinitely.
* CONFIG_EXAMPLES_ADC_GROUPSIZE - The number of samples to read at once.
* Default: 4
*/
#ifndef CONFIG_ADC
# error "ADC device support is not enabled (CONFIG_ADC)"
#endif
#ifndef CONFIG_EXAMPLES_ADC_DEVPATH
# define CONFIG_EXAMPLES_ADC_DEVPATH "/dev/adc0"
#endif
#ifndef CONFIG_EXAMPLES_ADC_GROUPSIZE
# define CONFIG_EXAMPLES_ADC_GROUPSIZE 4
#endif
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lib_rawprintf(__VA_ARGS__)
# define msgflush()
# else
# define message(...) printf(__VA_ARGS__)
# define msgflush() fflush(stdout)
# endif
#else
# ifdef CONFIG_DEBUG
# define message lib_rawprintf
# define msgflush()
# else
# define message printf
# define msgflush() fflush(stdout)
# endif
#endif
/****************************************************************************
* Public Types
****************************************************************************/
struct adc_state_s
{
bool initialized;
FAR char *devpath;
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
int count;
#endif
};
/****************************************************************************
* Public Variables
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: adc_devinit()
*
* Description:
* Perform architecuture-specific initialization of the ADC hardware. This
* interface must be provided by all configurations using apps/examples/adc
*
****************************************************************************/
int adc_devinit(void);
#endif /* __APPS_EXAMPLES_ADC_ADC_H */
+359
View File
@@ -0,0 +1,359 @@
/****************************************************************************
* examples/adc/adc_main.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/analog/adc.h>
#include "adc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static struct adc_state_s g_adcstate;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: adc_devpath
****************************************************************************/
static void adc_devpath(FAR struct adc_state_s *adc, FAR const char *devpath)
{
/* Get rid of any old device path */
if (adc->devpath)
{
free(adc->devpath);
}
/* Then set-up the new device path by copying the string */
adc->devpath = strdup(devpath);
}
/****************************************************************************
* Name: adc_help
****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
static void adc_help(FAR struct adc_state_s *adc)
{
message("Usage: adc [OPTIONS]\n");
message("\nArguments are \"sticky\". For example, once the ADC device is\n");
message("specified, that device will be re-used until it is changed.\n");
message("\n\"sticky\" OPTIONS include:\n");
message(" [-p devpath] selects the ADC device. "
"Default: %s Current: %s\n",
CONFIG_EXAMPLES_ADC_DEVPATH, g_adcstate.devpath ? g_adcstate.devpath : "NONE");
message(" [-n count] selects the samples to collect. "
"Default: 1 Current: %d\n", adc->count);
message(" [-h] shows this message and exits\n");
}
#endif
/****************************************************************************
* Name: arg_string
****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
static int arg_string(FAR char **arg, FAR char **value)
{
FAR char *ptr = *arg;
if (ptr[2] == '\0')
{
*value = arg[1];
return 2;
}
else
{
*value = &ptr[2];
return 1;
}
}
#endif
/****************************************************************************
* Name: arg_decimal
****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
static int arg_decimal(FAR char **arg, FAR long *value)
{
FAR char *string;
int ret;
ret = arg_string(arg, &string);
*value = strtol(string, NULL, 10);
return ret;
}
#endif
/****************************************************************************
* Name: parse_args
****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
static void parse_args(FAR struct adc_state_s *adc, int argc, FAR char **argv)
{
FAR char *ptr;
FAR char *str;
long value;
int index;
int nargs;
for (index = 1; index < argc; )
{
ptr = argv[index];
if (ptr[0] != '-')
{
message("Invalid options format: %s\n", ptr);
exit(0);
}
switch (ptr[1])
{
case 'n':
nargs = arg_decimal(&argv[index], &value);
if (value < 0)
{
message("Count must be non-negative: %ld\n", value);
exit(1);
}
adc->count = (uint32_t)value;
index += nargs;
break;
case 'p':
nargs = arg_string(&argv[index], &str);
adc_devpath(adc, str);
index += nargs;
break;
case 'h':
adc_help(adc);
exit(0);
default:
message("Unsupported option: %s\n", ptr);
adc_help(adc);
exit(1);
}
}
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: adc_main
****************************************************************************/
int adc_main(int argc, char *argv[])
{
struct adc_msg_s sample[CONFIG_EXAMPLES_ADC_GROUPSIZE];
size_t readsize;
ssize_t nbytes;
int fd;
int errval = 0;
int ret;
int i;
/* Check if we have initialized */
if (!g_adcstate.initialized)
{
/* Initialization of the ADC hardware is performed by logic external to
* this test.
*/
message("adc_main: Initializing external ADC device\n");
ret = adc_devinit();
if (ret != OK)
{
message("adc_main: adc_devinit failed: %d\n", ret);
errval = 1;
goto errout;
}
/* Set the default values */
adc_devpath(&g_adcstate, CONFIG_EXAMPLES_ADC_DEVPATH);
#ifdef CONFIG_EXAMPLES_ADC_NSAMPLES
g_adcstate.count = CONFIG_EXAMPLES_ADC_NSAMPLES;
#else
g_adcstate.count = 1;
#endif
g_adcstate.initialized = true;
}
/* Parse the command line */
#ifdef CONFIG_NSH_BUILTIN_APPS
parse_args(&g_adcstate, argc, argv);
#endif
/* If this example is configured as an NX add-on, then limit the number of
* samples that we collect before returning. Otherwise, we never return
*/
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
message("adc_main: g_adcstate.count: %d\n", g_adcstate.count);
#endif
/* Open the ADC device for reading */
message("adc_main: Hardware initialized. Opening the ADC device: %s\n",
g_adcstate.devpath);
fd = open(g_adcstate.devpath, O_RDONLY);
if (fd < 0)
{
message("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno);
errval = 2;
goto errout_with_dev;
}
/* Now loop the appropriate number of times, displaying the collected
* ADC samples.
*/
#if defined(CONFIG_NSH_BUILTIN_APPS)
for (; g_adcstate.count > 0; g_adcstate.count--)
#elif defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
for (g_adcstate.count = 0; g_adcstate.count < CONFIG_EXAMPLES_ADC_NSAMPLES; g_adcstate.count++)
#else
for (;;)
#endif
{
/* Flush any output before the loop entered or from the previous pass
* through the loop.
*/
msgflush();
/* Read CONFIG_EXAMPLES_ADC_GROUPSIZE samples */
readsize = CONFIG_EXAMPLES_ADC_GROUPSIZE * sizeof(struct adc_msg_s);
nbytes = read(fd, sample, readsize);
/* Handle unexpected return values */
if (nbytes < 0)
{
errval = errno;
if (errval != EINTR)
{
message("adc_main: read %s failed: %d\n",
g_adcstate.devpath, errval);
errval = 3;
goto errout_with_dev;
}
message("adc_main: Interrupted read...\n");
}
else if (nbytes == 0)
{
message("adc_main: No data read, Ignoring\n");
}
/* Print the sample data on successful return */
else
{
int nsamples = nbytes / sizeof(struct adc_msg_s);
if (nsamples * sizeof(struct adc_msg_s) != nbytes)
{
message("adc_main: read size=%d is not a multiple of sample size=%d, Ignoring\n",
nbytes, sizeof(struct adc_msg_s));
}
else
{
message("Sample:\n");
for (i = 0; i < nsamples ; i++)
{
message("%d: channel: %d value: %d\n",
i, sample[i].am_channel, sample[i].am_data);
}
}
}
}
errout_with_dev:
close(fd);
errout:
message("Terminating!\n");
msgflush();
return errval;
}
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_BUTTONS
bool "Buttons example"
default n
---help---
Enable the buttons example
if EXAMPLES_BUTTONS
endif
+105
View File
@@ -0,0 +1,105 @@
############################################################################
# apps/examples/buttons/Makefile
#
# 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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Hello, World! Example
ASRCS =
CSRCS = buttons_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Buttons built-in application info
APPNAME = buttons
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: context clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+499
View File
@@ -0,0 +1,499 @@
/****************************************************************************
* examples/buttons/buttons_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 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.
*
****************************************************************************/
/****************************************************************************
* NOTE: This test exercises internal button driver interfaces. As such, it
* it relies on internal OS interfaces that are not normally available to a
* user-space program. As a result, this example cannot be used if a
* NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL).
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <debug.h>
/****************************************************************************
* Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_ARCH_BUTTONS
# error "CONFIG_ARCH_BUTTONS is not defined in the configuration"
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_NAME0
# define CONFIG_EXAMPLE_BUTTONS_NAME0 "BUTTON0"
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_NAME1
# define CONFIG_EXAMPLE_BUTTONS_NAME1 "BUTTON1"
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_NAME2
# define CONFIG_EXAMPLE_BUTTONS_NAME2 "BUTTON2"
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_NAME3
# define CONFIG_EXAMPLE_BUTTONS_NAME3 "BUTTON3"
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_NAME4
# define CONFIG_EXAMPLE_BUTTONS_NAME4 "BUTTON4"
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_NAME5
# define CONFIG_EXAMPLE_BUTTONS_NAME5 "BUTTON5"
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_NAME6
# define CONFIG_EXAMPLE_BUTTONS_NAME6 "BUTTON6"
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_NAME7
# define CONFIG_EXAMPLE_BUTTONS_NAME7 "BUTTON7"
#endif
#define BUTTON_MIN 0
#define BUTTON_MAX 7
#ifndef CONFIG_EXAMPLE_BUTTONS_MIN
# define CONFIG_EXAMPLE_BUTTONS_MIN BUTTON_MIN
#endif
#ifndef CONFIG_EXAMPLE_BUTTONS_MAX
# define CONFIG_EXAMPLE_BUTTONS_MAX BUTTON_MAX
#endif
#if CONFIG_EXAMPLE_BUTTONS_MIN > CONFIG_EXAMPLE_BUTTONS_MAX
# error "CONFIG_EXAMPLE_BUTTONS_MIN > CONFIG_EXAMPLE_BUTTONS_MAX"
#endif
#if CONFIG_EXAMPLE_BUTTONS_MAX > 7
# error "CONFIG_EXAMPLE_BUTTONS_MAX > 7"
#endif
#ifndef CONFIG_EXAMPLE_IRQBUTTONS_MIN
# define CONFIG_EXAMPLE_IRQBUTTONS_MIN CONFIG_EXAMPLE_BUTTONS_MIN
#endif
#ifndef CONFIG_EXAMPLE_IRQBUTTONS_MAX
# define CONFIG_EXAMPLE_IRQBUTTONS_MAX CONFIG_EXAMPLE_BUTTONS_MAX
#endif
#if CONFIG_EXAMPLE_IRQBUTTONS_MIN > CONFIG_EXAMPLE_IRQBUTTONS_MAX
# error "CONFIG_EXAMPLE_IRQBUTTONS_MIN > CONFIG_EXAMPLE_IRQBUTTONS_MAX"
#endif
#if CONFIG_EXAMPLE_IRQBUTTONS_MAX > 7
# error "CONFIG_EXAMPLE_IRQBUTTONS_MAX > 7"
#endif
#ifndef MIN
# define MIN(a,b) (a < b ? a : b)
#endif
#ifndef MAX
# define MAX(a,b) (a > b ? a : b)
#endif
#define MIN_BUTTON MIN(CONFIG_EXAMPLE_BUTTONS_MIN, CONFIG_EXAMPLE_IRQBUTTONS_MIN)
#define MAX_BUTTON MAX(CONFIG_EXAMPLE_BUTTONS_MAX, CONFIG_EXAMPLE_IRQBUTTONS_MAX)
#define NUM_BUTTONS (MAX_BUTTON - MIN_BUTTON + 1)
#define BUTTON_INDEX(b) ((b)-MIN_BUTTON)
/****************************************************************************
* Private Types
****************************************************************************/
struct button_info_s
{
FAR const char *name; /* Name for the button */
#ifdef CONFIG_ARCH_IRQBUTTONS
xcpt_t handler; /* Button interrupt handler */
#endif
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static void show_buttons(uint8_t oldset, uint8_t newset);
#ifdef CONFIG_ARCH_IRQBUTTONS
static void button_handler(int id, int irq);
#if MIN_BUTTON < 1
static int button0_handler(int irq, FAR void *context);
#endif
#if MIN_BUTTON < 2 && MAX_BUTTON > 0
static int button1_handler(int irq, FAR void *context);
#endif
#if MIN_BUTTON < 3 && MAX_BUTTON > 1
static int button2_handler(int irq, FAR void *context);
#endif
#if MIN_BUTTON < 4 && MAX_BUTTON > 2
static int button3_handler(int irq, FAR void *context);
#endif
#if MIN_BUTTON < 5 && MAX_BUTTON > 3
static int button4_handler(int irq, FAR void *context);
#endif
#if MIN_BUTTON < 6 && MAX_BUTTON > 4
static int button5_handler(int irq, FAR void *context);
#endif
#if MIN_BUTTON < 7 && MAX_BUTTON > 5
static int button6_handler(int irq, FAR void *context);
#endif
#if MAX_BUTTON > 6
static int button7_handler(int irq, FAR void *context);
#endif
#endif /* CONFIG_ARCH_IRQBUTTONS */
/****************************************************************************
* Private Data
****************************************************************************/
/* Button Names */
static const struct button_info_s g_buttoninfo[NUM_BUTTONS] =
{
#if MIN_BUTTON < 1
{
CONFIG_EXAMPLE_BUTTONS_NAME0,
#ifdef CONFIG_ARCH_IRQBUTTONS
button0_handler
#endif
},
#endif
#if MIN_BUTTON < 2 && MAX_BUTTON > 0
{
CONFIG_EXAMPLE_BUTTONS_NAME1,
#ifdef CONFIG_ARCH_IRQBUTTONS
button1_handler
#endif
},
#endif
#if MIN_BUTTON < 3 && MAX_BUTTON > 1
{
CONFIG_EXAMPLE_BUTTONS_NAME2,
#ifdef CONFIG_ARCH_IRQBUTTONS
button2_handler
#endif
},
#endif
#if MIN_BUTTON < 4 && MAX_BUTTON > 2
{
CONFIG_EXAMPLE_BUTTONS_NAME3,
#ifdef CONFIG_ARCH_IRQBUTTONS
button3_handler
#endif
},
#endif
#if MIN_BUTTON < 5 && MAX_BUTTON > 3
{
CONFIG_EXAMPLE_BUTTONS_NAME4,
#ifdef CONFIG_ARCH_IRQBUTTONS
button4_handler
#endif
},
#endif
#if MIN_BUTTON < 6 && MAX_BUTTON > 4
{
CONFIG_EXAMPLE_BUTTONS_NAME5,
#ifdef CONFIG_ARCH_IRQBUTTONS
button5_handler
#endif
},
#endif
#if MIN_BUTTON < 7 && MAX_BUTTON > 5
{
CONFIG_EXAMPLE_BUTTONS_NAME6,
#ifdef CONFIG_ARCH_IRQBUTTONS
button6_handler
#endif
},
#endif
#if MAX_BUTTON > 6
{
CONFIG_EXAMPLE_BUTTONS_NAME7,
#ifdef CONFIG_ARCH_IRQBUTTONS
button7_handler
#endif
}
#endif
};
/* Last sampled button set */
static uint8_t g_oldset;
/* Used to limit the number of button presses */
#ifdef CONFIG_NSH_BUILTIN_APPS
static volatile long g_nbuttons;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
static void show_buttons(uint8_t oldset, uint8_t newset)
{
uint8_t chgset = oldset ^ newset;
int i;
/* Update the count of button presses shown */
#ifdef CONFIG_NSH_BUILTIN_APPS
if ((chgset & newset) != 0)
{
g_nbuttons++;
}
#endif
/* Show each button state change */
for (i = MIN_BUTTON; i <= MAX_BUTTON; i++)
{
uint8_t mask = (1 << i);
if ((chgset & mask) != 0)
{
FAR const char *state;
/* Get the button state */
if ((newset & mask) != 0)
{
state = "depressed";
}
else
{
state = "released";
}
/* Use lib_lowprintf() because we make be executing from an
* interrupt handler.
*/
lib_lowprintf(" %s %s\n", g_buttoninfo[BUTTON_INDEX(i)].name, state);
}
}
}
#ifdef CONFIG_ARCH_IRQBUTTONS
static void button_handler(int id, int irq)
{
uint8_t newset = up_buttons();
lib_lowprintf("IRQ:%d Button %d:%s SET:%02x:\n",
irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset);
show_buttons(g_oldset, newset);
g_oldset = newset;
}
#if MIN_BUTTON < 1
static int button0_handler(int irq, FAR void *context)
{
button_handler(0, irq);
return OK;
}
#endif
#if MIN_BUTTON < 2 && MAX_BUTTON > 0
static int button1_handler(int irq, FAR void *context)
{
button_handler(1, irq);
return OK;
}
#endif
#if MIN_BUTTON < 3 && MAX_BUTTON > 1
static int button2_handler(int irq, FAR void *context)
{
button_handler(2, irq);
return OK;
}
#endif
#if MIN_BUTTON < 4 && MAX_BUTTON > 2
static int button3_handler(int irq, FAR void *context)
{
button_handler(3, irq);
return OK;
}
#endif
#if MIN_BUTTON < 5 && MAX_BUTTON > 3
static int button4_handler(int irq, FAR void *context)
{
button_handler(4, irq);
return OK;
}
#endif
#if MIN_BUTTON < 6 && MAX_BUTTON > 4
static int button5_handler(int irq, FAR void *context)
{
button_handler(5, irq);
return OK;
}
#endif
#if MIN_BUTTON < 7 && MAX_BUTTON > 5
static int button6_handler(int irq, FAR void *context)
{
button_handler(6, irq);
return OK;
}
#endif
#if MAX_BUTTON > 6
static int button7_handler(int irq, FAR void *context)
{
button_handler(7, irq);
return OK;
}
#endif
#endif /* CONFIG_ARCH_IRQBUTTONS */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* buttons_main
****************************************************************************/
int buttons_main(int argc, char *argv[])
{
uint8_t newset;
irqstate_t flags;
int i;
/* If this example is configured as an NX add-on, then limit the number of
* samples that we collect before returning. Otherwise, we never return
*/
#ifdef CONFIG_NSH_BUILTIN_APPS
long maxbuttons = 1;
g_nbuttons = 0;
if (argc > 1)
{
maxbuttons = strtol(argv[1], NULL, 10);
}
lib_lowprintf("maxbuttons: %d\n", maxbuttons);
#endif
/* Initialize the button GPIOs */
up_buttoninit();
/* Register to recieve button interrupts */
#ifdef CONFIG_ARCH_IRQBUTTONS
for (i = CONFIG_EXAMPLE_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLE_IRQBUTTONS_MAX; i++)
{
xcpt_t oldhandler = up_irqbutton(i, g_buttoninfo[BUTTON_INDEX(i)].handler);
/* Use lib_lowprintf() for compatibility with interrrupt handler output. */
lib_lowprintf("Attached handler at %p to button %d [%s], oldhandler:%p\n",
g_buttoninfo[BUTTON_INDEX(i)].handler, i,
g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler);
/* Some hardware multiplexes different GPIO button sources to the same
* physical interrupt. If we register multiple such multiplexed button
* interrupts, then the second registration will overwrite the first. In
* this case, the first button interrupts may be aliased to the second
* interrupt handler (or worse, could be lost).
*/
if (oldhandler != NULL)
{
lib_lowprintf("WARNING: oldhandler:%p is not NULL! "
"Button events may be lost or aliased!\n",
oldhandler);
}
}
#endif
/* Poll button state */
g_oldset = up_buttons();
#ifdef CONFIG_NSH_BUILTIN_APPS
while (g_nbuttons < maxbuttons)
#else
for (;;)
#endif
{
/* Get the set of pressed and release buttons. */
newset = up_buttons();
/* Any changes from the last sample? */
if (newset != g_oldset)
{
/* Disable interrupts so that output here will not collide with
* output from an interrupt handler.
*/
flags = irqsave();
/* Use lib_lowprintf() for compatibility with interrrupt handler
* output.
*/
lib_lowprintf("POLL SET:%02x:\n", newset);
show_buttons(g_oldset, newset);
g_oldset = newset;
irqrestore(flags);
}
/* Sleep a little... but not long. This will determine how fast we
* poll for button changes.
*/
usleep(150000); /* 150 Milliseconds */
}
/* Un-register button handlers */
#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NSH_BUILTIN_APPS)
for (i = CONFIG_EXAMPLE_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLE_IRQBUTTONS_MAX; i++)
{
(void)up_irqbutton(i, NULL);
}
#endif
return 0;
}
+14
View File
@@ -0,0 +1,14 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_CAN
bool "CAN example"
default n
---help---
Enable the CAN example
if EXAMPLES_CAN
endif
+105
View File
@@ -0,0 +1,105 @@
############################################################################
# apps/examples/can/Makefile
#
# 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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# NuttX NX Graphics Example.
ASRCS =
CSRCS = can_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Touchscreen built-in application info
APPNAME = can
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: context clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+131
View File
@@ -0,0 +1,131 @@
/****************************************************************************
* examples/examples/can/can.h
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __APPS_EXAMPLES_CAN_CAN_H
#define __APPS_EXAMPLES_CAN_CAN_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* This test depends on these specific CAN configurations settings (your
* specific CAN settings might require additional settings).
*
* CONFIG_CAN - Enables CAN support.
* CONFIG_CAN_LOOPBACK - A CAN driver may or may not support a loopback
* mode for testing. The STM32 CAN driver does support loopback mode.
*
* Specific configuration options for this example include:
*
* CONFIG_NSH_BUILTIN_APPS - Build the CAN test as an NSH built-in function.
* Default: Built as a standalone problem
* CONFIG_CAN_LOOPBACK
* CONFIG_EXAMPLES_CAN_DEVPATH - The path to the CAN device. Default: /dev/can0
* CONFIG_EXAMPLES_CAN_NMSGS - If CONFIG_NSH_BUILTIN_APPS
* is defined, then the number of loops is provided on the command line
* and this value is ignored. Otherwise, this number of CAN message is
* collected and the program terminates. Default: If built as an NSH
* built-in, the default is 32. Otherwise messages are sent and received
* indefinitely.
* CONFIG_EXAMPLES_CAN_READONLY - Only receive messages
* CONFIG_EXAMPLES_CAN_WRITEONLY - Only send messages
*/
#ifndef CONFIG_CAN
# error "CAN device support is not enabled (CONFIG_CAN)"
#endif
#ifndef CONFIG_CAN_LOOPBACK
# warning "CAN loopback is not enabled (CONFIG_CAN_LOOPBACK)"
#endif
#ifndef CONFIG_EXAMPLES_CAN_DEVPATH
# define CONFIG_EXAMPLES_CAN_DEVPATH "/dev/can0"
#endif
#if defined(CONFIG_NSH_BUILTIN_APPS) && !defined(CONFIG_EXAMPLES_CAN_NMSGS)
# define CONFIG_EXAMPLES_CAN_NMSGS 32
#endif
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lib_rawprintf(__VA_ARGS__)
# define msgflush()
# else
# define message(...) printf(__VA_ARGS__)
# define msgflush() fflush(stdout)
# endif
#else
# ifdef CONFIG_DEBUG
# define message lib_rawprintf
# define msgflush()
# else
# define message printf
# define msgflush() fflush(stdout)
# endif
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Variables
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: can_devinit()
*
* Description:
* Perform architecuture-specific initialization of the CAN hardware. This
* interface must be provided by all configurations using apps/examples/can
*
****************************************************************************/
int can_devinit(void);
#endif /* __APPS_EXAMPLES_CAN_CAN_H */
+301
View File
@@ -0,0 +1,301 @@
/****************************************************************************
* examples/can/can_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 NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/can.h>
#include "can.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_EXAMPLES_CAN_READONLY)
# undef CONFIG_EXAMPLES_CAN_WRITEONLY
# undef CONFIG_EXAMPLES_CAN_READWRITE
# define CAN_OFLAGS O_RDONLY
#elif defined(CONFIG_EXAMPLES_CAN_WRITEONLY)
# undef CONFIG_EXAMPLES_CAN_READWRITE
# define CAN_OFLAGS O_WRONLY
#else
# undef CONFIG_EXAMPLES_CAN_READWRITE
# define CONFIG_EXAMPLES_CAN_READWRITE 1
# define CAN_OFLAGS O_RDWR
#endif
#ifdef CONFIG_CAN_EXTID
# define MAX_ID (1 << 29)
#else
# define MAX_ID (1 << 11)
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: can_main
****************************************************************************/
int can_main(int argc, char *argv[])
{
#ifndef CONFIG_EXAMPLES_CAN_READONLY
struct can_msg_s txmsg;
#ifdef CONFIG_CAN_EXTID
uint32_t msgid;
#else
uint16_t msgid;
#endif
int msgdlc;
uint8_t msgdata;
#endif
#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY
struct can_msg_s rxmsg;
#endif
size_t msgsize;
ssize_t nbytes;
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_CAN_NMSGS)
long nmsgs;
#endif
int fd;
int errval = 0;
int ret;
int i;
/* If this example is configured as an NX add-on, then limit the number of
* samples that we collect before returning. Otherwise, we never return
*/
#if defined(CONFIG_NSH_BUILTIN_APPS)
nmsgs = CONFIG_EXAMPLES_CAN_NMSGS;
if (argc > 1)
{
nmsgs = strtol(argv[1], NULL, 10);
}
message("can_main: nmsgs: %d\n", nmsgs);
#elif defined(CONFIG_EXAMPLES_CAN_NMSGS)
message("can_main: nmsgs: %d\n", CONFIG_EXAMPLES_CAN_NMSGS);
#endif
/* Initialization of the CAN hardware is performed by logic external to
* this test.
*/
message("can_main: Initializing external CAN device\n");
ret = can_devinit();
if (ret != OK)
{
message("can_main: can_devinit failed: %d\n", ret);
errval = 1;
goto errout;
}
/* Open the CAN device for reading */
message("can_main: Hardware initialized. Opening the CAN device\n");
fd = open(CONFIG_EXAMPLES_CAN_DEVPATH, CAN_OFLAGS);
if (fd < 0)
{
message("can_main: open %s failed: %d\n",
CONFIG_EXAMPLES_CAN_DEVPATH, errno);
errval = 2;
goto errout_with_dev;
}
/* Now loop the appropriate number of times, performing one loopback test
* on each pass.
*/
#ifndef CONFIG_EXAMPLES_CAN_READONLY
msgdlc = 1;
msgid = 1;
msgdata = 0;
#endif
#if defined(CONFIG_NSH_BUILTIN_APPS)
for (; nmsgs > 0; nmsgs--)
#elif defined(CONFIG_EXAMPLES_CAN_NMSGS)
for (nmsgs = 0; nmsgs < CONFIG_EXAMPLES_CAN_NMSGS; nmsgs++)
#else
for (;;)
#endif
{
/* Flush any output before the loop entered or from the previous pass
* through the loop.
*/
msgflush();
/* Construct the next TX message */
#ifndef CONFIG_EXAMPLES_CAN_READONLY
txmsg.cm_hdr.ch_id = msgid;
txmsg.cm_hdr.ch_rtr = false;
txmsg.cm_hdr.ch_dlc = msgdlc;
#ifdef CONFIG_CAN_EXTID
txmsg.cm_hdr.ch_extid = true;
#endif
for (i = 0; i < msgdlc; i++)
{
txmsg.cm_data[i] = msgdata + i;
}
/* Send the TX message */
msgsize = CAN_MSGLEN(msgdlc);
nbytes = write(fd, &txmsg, msgsize);
if (nbytes != msgsize)
{
message("ERROR: write(%d) returned %d\n", msgsize, nbytes);
errval = 3;
goto errout_with_dev;
}
#endif
#ifdef CONFIG_EXAMPLES_CAN_WRITEONLY
message(" ID: %4d DLC: %d\n", msgid, msgdlc);
#endif
/* Read the RX message */
#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY
msgsize = sizeof(struct can_msg_s);
nbytes = read(fd, &rxmsg, msgsize);
if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize)
{
message("ERROR: read(%d) returned %d\n", msgsize, nbytes);
errval = 4;
goto errout_with_dev;
}
#endif
#ifndef CONFIG_EXAMPLES_CAN_READONLY
message(" ID: %4d DLC: %d\n", rxmsg.cm_hdr.id, rxmsg.cm_hdr.dlc);
#endif
/* Verify that the received messages are the same */
#ifdef CONFIG_EXAMPLES_CAN_READWRITE
if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0)
{
message("ERROR: Sent header does not match received header:\n");
lib_dumpbuffer("Sent header", (FAR const uint8_t*)&txmsg.cm_hdr,
sizeof(struct can_hdr_s));
lib_dumpbuffer("Received header", (FAR const uint8_t*)&rxmsg.cm_hdr,
sizeof(struct can_hdr_s));
errval = 4;
goto errout_with_dev;
}
if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0)
{
message("ERROR: Data does not match. DLC=%d\n", msgdlc);
for (i = 0; i < msgdlc; i++)
{
message(" %d: TX %02x RX %02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]);
errval = 5;
goto errout_with_dev;
}
}
/* Report success */
message(" ID: %4d DLC: %d -- OK\n", msgid, msgdlc);
#endif
/* Set up for the next pass */
#ifndef CONFIG_EXAMPLES_CAN_READONLY
msgdata += msgdlc;
if (++msgid >= MAX_ID)
{
msgid = 1;
}
if (++msgdlc > CAN_MAXDATALEN)
{
msgdlc = 1;
}
#endif
}
errout_with_dev:
close(fd);
errout:
message("Terminating!\n");
msgflush();
return errval;
}
+14
View File
@@ -0,0 +1,14 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_CDCACM
bool "CAN example"
default n
---help---
Enable the USB CDC/ACM class driver example
if EXAMPLES_CDCACM
endif
+109
View File
@@ -0,0 +1,109 @@
############################################################################
# apps/examples/cdcacm/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
# USB CDC/ACM serial mass storage example
ASRCS =
CSRCS = cdcacm_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# USB CDC/ACM built-in application info
APPNAME1 = sercon
PRIORITY1 = SCHED_PRIORITY_DEFAULT
STACKSIZE1 = 2048
APPNAME2 = serdis
PRIORITY2 = SCHED_PRIORITY_DEFAULT
STACKSIZE2 = 2048
# Common build
VPATH =
all: .built
.PHONY: context clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
$(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(APPNAME1)_main)
$(call REGISTER,$(APPNAME2),$(PRIORITY2),$(STACKSIZE2),$(APPNAME2)_main)
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+165
View File
@@ -0,0 +1,165 @@
/****************************************************************************
* examples/cdcacm/cdcacm.h
*
* 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.
*
****************************************************************************/
#ifndef __EXAMPLES_CDCACM_CDCACM_H
#define __EXAMPLES_CDCACM_CDCACM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <nuttx/usb/usbdev_trace.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Prerequisites */
#ifndef CONFIG_USBDEV
# error "CONFIG_USBDEV is not defined"
#endif
#ifndef CONFIG_CDCACM
# error "CONFIG_CDCACM is not defined"
#endif
#ifndef CONFIG_NSH_BUILTIN_APPS
# error "This example can only be built as an NSH built-in application"
#endif
/* Default configuration values */
#ifndef CONFIG_EXAMPLES_CDCACM_DEVMINOR
# define CONFIG_EXAMPLES_CDCACM_DEVMINOR 0
#endif
/* Trace Configuration ******************************************************/
#ifdef CONFIG_EXAMPLES_CDCACM_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_EXAMPLES_CDCACM_TRACECLASS
# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT)
#else
# define TRACE_CLASS_BITS (0)
#endif
#ifdef CONFIG_EXAMPLES_CDCACM_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_EXAMPLES_CDCACM_TRACECONTROLLER
# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT)
#else
# define TRACE_CONTROLLER_BITS (0)
#endif
#ifdef CONFIG_EXAMPLES_CDCACM_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)
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lib_lowprintf(__VA_ARGS__)
# define msgflush()
# else
# define message(...) printf(__VA_ARGS__)
# define msgflush() fflush(stdout)
# endif
#else
# ifdef CONFIG_DEBUG
# define message lib_lowprintf
# define msgflush()
# else
# define message printf
# define msgflush() fflush(stdout)
# endif
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/* All global variables used by this example are packed into a structure in
* order to avoid name collisions.
*/
struct cdcacm_state_s
{
/* This is the handle that references to this particular USB storage driver
* instance. It is only needed if the USB mass storage device example is
* built using CONFIG_NSH_BUILTIN_APPS. In this case, the value
* of the driver handle must be remembered between the 'sercon' and 'msdis'
* commands.
*/
FAR void *handle;
};
/****************************************************************************
* Public Data
****************************************************************************/
/* All global variables used by this example are packed into a structure in
* order to avoid name collisions.
*/
extern struct cdcacm_state_s g_cdcacm;
/****************************************************************************
* Public Functions
****************************************************************************/
#endif /* __EXAMPLES_CDCACM_CDCACM_H */
+147
View File
@@ -0,0 +1,147 @@
/****************************************************************************
* examples/cdcacm/cdcacm_main.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
#include <debug.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/cdcacm.h>
#include "cdcacm.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/* All global variables used by this example are packed into a structure in
* order to avoid name collisions.
*/
struct cdcacm_state_s g_cdcacm;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* sercon_main
*
* Description:
* This is the main program that configures the CDC/ACM serial device.
*
****************************************************************************/
int sercon_main(int argc, char *argv[])
{
int ret;
/* Check if there is a non-NULL USB mass storage device handle (meaning that the
* USB mass storage device is already configured).
*/
if (g_cdcacm.handle)
{
message("sercon:: ERROR: Already connected\n");
return EXIT_FAILURE;
}
/* Then, in any event, enable trace data collection as configured BEFORE
* enabling the CDC/ACM device.
*/
usbtrace_enable(TRACE_BITSET);
/* Initialize the USB CDC/ACM serial driver */
message("sercon: Registering CDC/ACM serial driver\n");
ret = cdcacm_initialize(CONFIG_EXAMPLES_CDCACM_DEVMINOR, &g_cdcacm.handle);
if (ret < 0)
{
message("sercon: ERROR: Failed to create the CDC/ACM serial device: %d\n", -ret);
return EXIT_FAILURE;
}
message("sercon: Successfully registered the CDC/ACM serial driver\n");
return EXIT_SUCCESS;
}
/****************************************************************************
* serdis_main
*
* Description:
* This is a program entry point that will disconnect the CDC/ACM serial
* device.
*
****************************************************************************/
int serdis_main(int argc, char *argv[])
{
/* First check if the USB mass storage device is already connected */
if (!g_cdcacm.handle)
{
message("serdis: ERROR: Not connected\n");
return EXIT_FAILURE;
}
/* Then, in any event, disable trace data collection as configured BEFORE
* enabling the CDC/ACM device.
*/
usbtrace_enable(0);
/* Then disconnect the device and uninitialize the USB mass storage driver */
cdcacm_uninitialize(g_cdcacm.handle);
g_cdcacm.handle = NULL;
message("serdis: Disconnected\n");
return EXIT_SUCCESS;
}
+14
View File
@@ -0,0 +1,14 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_COMPOSITE
bool "USB composite class driver example"
default n
---help---
Enable the USB compsite class driver example
if EXAMPLES_COMPOSITE
endif
+111
View File
@@ -0,0 +1,111 @@
############################################################################
# apps/examples/composite/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
# USB device mass storage example
ASRCS =
CSRCS = composite_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# USB storage built-in application info
APPNAME1 = conn
PRIORITY1 = SCHED_PRIORITY_DEFAULT
STACKSIZE1 = 2048
APPNAME2 = disconn
PRIORITY2 = SCHED_PRIORITY_DEFAULT
STACKSIZE2 = 2048
# Common build
VPATH =
all: .built
.PHONY: context clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(APPNAME1)_main)
$(call REGISTER,$(APPNAME2),$(PRIORITY2),$(STACKSIZE2),$(APPNAME2)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+259
View File
@@ -0,0 +1,259 @@
/****************************************************************************
* examples/composite/composite.h
*
* 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.
*
****************************************************************************/
#ifndef __EXAMPLES_COMPOSITE_COMPOSITE_H
#define __EXAMPLES_COMPOSITE_COMPOSITE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* OS/Driver configuration checkes */
#ifndef CONFIG_USBDEV
# error "USB device support is not enabled (CONFIG_USBDEV)"
#endif
#ifndef CONFIG_USBDEV_COMPOSITE
# error "USB composite device support is not enabled (CONFIG_USBDEV_COMPOSITE)"
#endif
#ifndef CONFIG_CDCACM
# error "USB CDC/ACM serial device support is not enabled (CONFIG_CDCACM)"
#endif
#ifndef CONFIG_CDCACM_COMPOSITE
# error "USB CDC/ACM serial composite device support is not enabled (CONFIG_CDCACM_COMPOSITE)"
#endif
#ifndef CONFIG_USBMSC
# error "USB mass storage device support is not enabled (CONFIG_USBMSC)"
#endif
#ifndef CONFIG_USBMSC_COMPOSITE
# error "USB mass storage composite device support is not enabled (CONFIG_USBMSC_COMPOSITE)"
#endif
/* Example MSC default values */
#ifndef CONFIG_EXAMPLES_COMPOSITE_NLUNS
# define CONFIG_EXAMPLES_COMPOSITE_NLUNS 1
#endif
#ifndef CONFIG_EXAMPLES_COMPOSITE_DEVMINOR1
# define CONFIG_EXAMPLES_COMPOSITE_DEVMINOR1 0
#endif
#ifndef CONFIG_EXAMPLES_COMPOSITE_DEVPATH1
# define CONFIG_EXAMPLES_COMPOSITE_DEVPATH1 "/dev/mmcsd0"
#endif
#if CONFIG_EXAMPLES_COMPOSITE_NLUNS > 1
# ifndef CONFIG_EXAMPLES_COMPOSITE_DEVMINOR2
# error "CONFIG_EXAMPLES_COMPOSITE_DEVMINOR2 for LUN=2"
# endif
# ifndef CONFIG_EXAMPLES_COMPOSITE_DEVPATH2
# error "CONFIG_EXAMPLES_COMPOSITE_DEVPATH2 for LUN=2"
# endif
# if CONFIG_EXAMPLES_COMPOSITE_NLUNS > 2
# ifndef CONFIG_EXAMPLES_COMPOSITE_DEVMINOR3
# error "CONFIG_EXAMPLES_COMPOSITE_DEVMINOR2 for LUN=3"
# endif
# ifndef CONFIG_EXAMPLES_COMPOSITE_DEVPATH2
# error "CONFIG_EXAMPLES_COMPOSITE_DEVPATH2 for LUN=3"
# endif
# if CONFIG_EXAMPLES_COMPOSITE_NLUNS > 3
# error "CONFIG_EXAMPLES_COMPOSITE_NLUNS must be {1,2,3}"
# endif
# endif
#endif
#ifndef CONFIG_EXAMPLES_COMPOSITE_BUFLEN
# define CONFIG_EXAMPLES_COMPOSITE_BUFLEN 256
#endif
/* Example MSC default values */
#ifndef CONFIG_EXAMPLES_COMPOSITE_TTYUSB
# define CONFIG_EXAMPLES_COMPOSITE_TTYUSB 0
#endif
#ifndef CONFIG_EXAMPLES_COMPOSITE_SERDEV
# if CONFIG_EXAMPLES_COMPOSITE_TTYUSB != 0
# error "Serial device unknown (CONFIG_EXAMPLES_COMPOSITE_SERDEV)"
# elif defined(CONFIG_CDCACM)
# define CONFIG_EXAMPLES_COMPOSITE_SERDEV "/dev/ttyACM0"
# else
# define CONFIG_EXAMPLES_COMPOSITE_SERDEV "/dev/ttyUSB0"
# endif
#endif
#ifndef CONFIG_EXAMPLES_COMPOSITE_BUFSIZE
# define CONFIG_EXAMPLES_COMPOSITE_BUFSIZE 256
#endif
/* Trace initialization *****************************************************/
#ifdef CONFIG_EXAMPLES_COMPOSITE_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_EXAMPLES_COMPOSITE_TRACECLASS
# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT)
#else
# define TRACE_CLASS_BITS (0)
#endif
#ifdef CONFIG_EXAMPLES_COMPOSITE_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_EXAMPLES_COMPOSITE_TRACECONTROLLER
# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT)
#else
# define TRACE_CONTROLLER_BITS (0)
#endif
#ifdef CONFIG_EXAMPLES_COMPOSITE_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)
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lib_lowprintf(__VA_ARGS__)
# define msgflush()
# else
# define message(...) printf(__VA_ARGS__)
# define msgflush() fflush(stdout)
# endif
#else
# ifdef CONFIG_DEBUG
# define message lib_lowprintf
# define msgflush()
# else
# define message printf
# define msgflush() fflush(stdout)
# endif
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/* All global variables used by this example are packed into a structure in
* order to avoid name collisions.
*/
struct composite_state_s
{
/* This is the handle that references to this particular USB composite driver
* instance. It is only needed if the example is built using
* CONFIG_NSH_BUILTIN_APPS. In this case, the value of the driver handle
* must be remembered between the 'conn' and 'disconn' commands.
*/
FAR void *cmphandle; /* Composite device handle */
FAR void *mschandle; /* Mass storage device handle */
/* Serial file descriptors */
#if !defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_DISABLE_SIGNALS)
int outfd; /* Blocking write-only */
int infd; /* Non-blockig read-only */
#endif
/* Heap usage samples. These are useful for checking USB storage memory
* usage and for tracking down memoryh leaks.
*/
#ifdef CONFIG_EXAMPLES_COMPOSITE_DEBUGMM
struct mallinfo mmstart; /* Memory usage before the connection */
struct mallinfo mmprevious; /* The last memory usage sample */
struct mallinfo mmcurrent; /* The current memory usage sample */
#endif
/* Serial I/O buffer */
#if !defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_DISABLE_SIGNALS)
uint8_t serbuf[CONFIG_EXAMPLES_COMPOSITE_BUFSIZE];
#endif
};
/****************************************************************************
* Public Data
****************************************************************************/
/* All global variables used by this example are packed into a structure in
* order to avoid name collisions.
*/
extern struct composite_state_s g_composite;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: composite_archinitialize
*
* Description:
* Perform architecture specific initialization.
*
****************************************************************************/
extern int composite_archinitialize(void);
#endif /* __EXAMPLES_COMPOSITE_COMPOSITE_H */
File diff suppressed because it is too large Load Diff
+14
View File
@@ -0,0 +1,14 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_DHCPD
bool "DHCP server example"
default n
---help---
Enable the DHCP server example
if EXAMPLES_DHCPD
endif
+106
View File
@@ -0,0 +1,106 @@
############################################################################
# apps/examples/dhcpd/Makefile
#
# Copyright (C) 2009-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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# DHCP Daemon Example
ASRCS =
CSRCS = target.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# DHCPD built-in application info
APPNAME = dhcpd
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+62
View File
@@ -0,0 +1,62 @@
############################################################################
# apps/examples/dhcpd/Makefile.host
#
# Copyright (C) 2007, 2009, 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.
#
############################################################################
# TOPDIR must be defined on the make command line
include $(TOPDIR)/Make.defs
OBJS = host.o1 dhcpd.o1
BIN = dhcpd
HOSTCFLAGS += -DCONFIG_NETUTILS_DHCPD_HOST=1
HOSTCFLAGS += -DCONFIG_NETUTILS_DHCPD_INTERFACE=\"eth1\"
HOSTCFLAGS += -DHAVE_SO_REUSEADDR=1
HOSTCFLAGS += -DHAVE_SO_BROADCAST=1
VPATH = $(TOPDIR)/netutils/dhcpd:.
all: $(BIN)
.PHONY: clean context clean_context distclean
$(OBJS): %.o1: %.c
$(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
$(BIN): $(OBJS)
$(HOSTCC) $(HOSTLDFLAGS) $^ -o $@
clean:
@rm -f $(BIN).* *.o1 *~
+58
View File
@@ -0,0 +1,58 @@
/****************************************************************************
* examples/dhcpd/host.c
*
* Copyright (C) 2007, 2009, 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
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
extern int dhcpd_run(void);
/****************************************************************************
* main
****************************************************************************/
int main(int argc, char **argv, char **envp)
{
dhcpd_run();
return 0;
}
+130
View File
@@ -0,0 +1,130 @@
/****************************************************************************
* examples/dhcpd/target.c
*
* Copyright (C) 2009, 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 <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <apps/netutils/uiplib.h>
#include <apps/netutils/dhcpd.h>
/****************************************************************************
* Preprocessor Definitions
****************************************************************************/
/* Configuation Checkes *****************************************************/
/* BEWARE:
* There are other configuration settings needed in netutils/dhcpd/dhcpdc.c,
* but there are default values for those so we cannot check them here.
*/
#ifndef CONFIG_EXAMPLE_DHCPD_IPADDR
# error "You must define CONFIG_EXAMPLE_DHCPD_IPADDR"
#endif
#ifndef CONFIG_EXAMPLE_DHCPD_DRIPADDR
# error "You must define CONFIG_EXAMPLE_DHCPD_DRIPADDR"
#endif
#ifndef CONFIG_EXAMPLE_DHCPD_NETMASK
# error "You must define CONFIG_EXAMPLE_DHCPD_NETMASK"
#endif
#ifndef CONFIG_NET
# error "You must define CONFIG_NET"
#endif
#ifndef CONFIG_NET_UDP
# error "You must define CONFIG_NET_UDP"
#endif
#ifndef CONFIG_NET_BROADCAST
# error "You must define CONFIG_NET_BROADCAST"
#endif
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Name: dhcpd_main
****************************************************************************/
int dhcpd_main(int argc, char *argv[])
{
struct in_addr addr;
#if defined(CONFIG_EXAMPLE_DHCPD_NOMAC)
uint8_t mac[IFHWADDRLEN];
#endif
/* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_EXAMPLE_DHCPD_NOMAC
mac[0] = 0x00;
mac[1] = 0xe0;
mac[2] = 0xde;
mac[3] = 0xad;
mac[4] = 0xbe;
mac[5] = 0xef;
uip_setmacaddr("eth0", mac);
#endif
/* Set up our host address */
addr.s_addr = HTONL(CONFIG_EXAMPLE_DHCPD_IPADDR);
uip_sethostaddr("eth0", &addr);
/* Set up the default router address */
addr.s_addr = HTONL(CONFIG_EXAMPLE_DHCPD_DRIPADDR);
uip_setdraddr("eth0", &addr);
/* Setup the subnet mask */
addr.s_addr = HTONL(CONFIG_EXAMPLE_DHCPD_NETMASK);
uip_setnetmask("eth0", &addr);
/* Then start the server */
dhcpd_run();
return 0;
}
+45
View File
@@ -0,0 +1,45 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLE_DISCOVER
bool "UDP Discovery Example"
default n
depends on NET_UDP
select NETUTILS_DISCOVER
---help---
Enable the netutils/discover utility. This example initializes and
starts the UDP discover daemon. This daemon is useful for
discovering devices in local networks, especially with DHCP
configured devices. It listens for UDP broadcasts which also can
include a device class so that groups of devices can be discovered.
It is also possible to address all classes with a kind of broadcast
discover.
config EXAMPLE_DISCOVER_DHCPC
bool "DHCP Client"
default n
depends on EXAMPLE_DISCOVER && !NSH_BUILTIN_APPS
select NETUTILS_DHCPC
select NETUTILS_RESOLV
config EXAMPLE_DISCOVER_NOMAC
bool "Use Canned MAC Address"
default n
depends on EXAMPLE_DISCOVER && !NSH_BUILTIN_APPS
config EXAMPLE_DISCOVER_IPADDR
hex "Target IP address"
default 0x0a000002
depends on EXAMPLE_DISCOVER && !NSH_BUILTIN_APPS && !EXAMPLE_DISCOVER_DHCPC
config EXAMPLE_DISCOVER_DRIPADDR
hex "Default Router IP address (Gateway)"
default 0x0a000001
depends on EXAMPLE_DISCOVER && !NSH_BUILTIN_APPS
config EXAMPLE_DISCOVER_NETMASK
hex "Network Mask"
default 0xffffff00
depends on EXAMPLE_DISCOVER && !NSH_BUILTIN_APPS
+106
View File
@@ -0,0 +1,106 @@
############################################################################
# apps/examples/discover/Makefile
#
# Copyright (C) 2012 Max Holtzberg. All rights reserved.
# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved.
#
# Authors: Max Holtzberg <mh@uvc.de>
# 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
# Discover built-in application info
APPNAME = discover
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
ASRCS =
CSRCS = discover_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+188
View File
@@ -0,0 +1,188 @@
/****************************************************************************
* examples/discover/discover_main.c
*
* Copyright (C) 2012 Max Holtzberg. All rights reserved.
* Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved.
*
* Authors: Max Holtzberg <mh@uvc.de>
* 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 <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <debug.h>
#include <net/if.h>
#include <nuttx/net/uip/uip.h>
#include <nuttx/net/uip/uip-arp.h>
#include <apps/netutils/uiplib.h>
#include <apps/netutils/discover.h>
#ifdef CONFIG_EXAMPLE_DISCOVER_DHCPC
# include <arpa/inet.h>
#endif
/* Here we include the header file for the application(s) we use in
* our project as defined in the config/<board-name>/defconfig file
*/
/* DHCPC may be used in conjunction with any other feature (or not) */
#ifdef CONFIG_EXAMPLE_DISCOVER_DHCPC
# include <apps/netutils/resolv.h>
# include <apps/netutils/dhcpc.h>
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* discover_main
****************************************************************************/
int discover_main(int argc, char *argv[])
{
/* If this task is excecutated as an NSH built-in function, then the
* network has already been configured by NSH's start-up logic.
*/
#ifndef CONFIG_NSH_BUILTIN_APPS
struct in_addr addr;
#if defined(CONFIG_EXAMPLE_DISCOVER_DHCPC) || defined(CONFIG_EXAMPLE_DISCOVER_NOMAC)
uint8_t mac[IFHWADDRLEN];
#endif
#ifdef CONFIG_EXAMPLE_DISCOVER_DHCPC
void *handle;
#endif
/* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_EXAMPLE_DISCOVER_NOMAC
mac[0] = 0x00;
mac[1] = 0xe0;
mac[2] = 0xde;
mac[3] = 0xad;
mac[4] = 0xbe;
mac[5] = 0xef;
uip_setmacaddr("eth0", mac);
#endif
/* Set up our host address */
#ifdef CONFIG_EXAMPLE_DISCOVER_DHCPC
addr.s_addr = 0;
#else
addr.s_addr = HTONL(CONFIG_EXAMPLE_DISCOVER_IPADDR);
#endif
uip_sethostaddr("eth0", &addr);
/* Set up the default router address */
addr.s_addr = HTONL(CONFIG_EXAMPLE_DISCOVER_DRIPADDR);
uip_setdraddr("eth0", &addr);
/* Setup the subnet mask */
addr.s_addr = HTONL(CONFIG_EXAMPLE_DISCOVER_NETMASK);
uip_setnetmask("eth0", &addr);
#ifdef CONFIG_EXAMPLE_DISCOVER_DHCPC
/* Set up the resolver */
resolv_init();
/* Get the MAC address of the NIC */
uip_getmacaddr("eth0", mac);
/* Set up the DHCPC modules */
handle = dhcpc_open(&mac, IFHWADDRLEN);
/* Get an IP address. Note: there is no logic here for renewing the address in this
* example. The address should be renewed in ds.lease_time/2 seconds.
*/
printf("Getting IP address\n");
if (handle)
{
struct dhcpc_state ds;
(void)dhcpc_request(handle, &ds);
uip_sethostaddr("eth1", &ds.ipaddr);
if (ds.netmask.s_addr != 0)
{
uip_setnetmask("eth0", &ds.netmask);
}
if (ds.default_router.s_addr != 0)
{
uip_setdraddr("eth0", &ds.default_router);
}
if (ds.dnsaddr.s_addr != 0)
{
resolv_conf(&ds.dnsaddr);
}
dhcpc_close(handle);
printf("IP: %s\n", inet_ntoa(ds.ipaddr));
}
#endif /* CONFIG_EXAMPLE_DISCOVER_DHCPC */
#endif /* CONFIG_NSH_BUILTIN_APPS */
if (discover_start() < 0)
{
ndbg("Could not start discover daemon.\n");
return ERROR;
}
return OK;
}
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_FTPC
bool "FTP client example"
default n
---help---
Enable the FTP client example
if EXAMPLES_FTPC
endif
+105
View File
@@ -0,0 +1,105 @@
############################################################################
# apps/examples/ftpc/Makefile
#
# 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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# FTPC Client Application
APPNAME = ftpc
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 4096
ASRCS =
CSRCS = ftpc_main.c ftpc_cmds.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
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)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
# Register application
.context:
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
context: .context
# Create dependencies
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f .context Make.dep .depend
-include Make.dep
+112
View File
@@ -0,0 +1,112 @@
/****************************************************************************
* apps/examples/ftpc/ftpc.h
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __APPS_EXAMPLES_FTPC_FTPC_H
#define __APPS_EXAMPLES_FTPC_FTPC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <apps/ftpc.h>
/****************************************************************************
* Definitions
****************************************************************************/
/* Maximum size of one command line */
#ifndef CONFIG_FTPC_LINELEN
# define CONFIG_FTPC_LINELEN 80
#endif
/* If CONFIG_STDIO_LINEBUFFER is defined, the STDIO buffer will be flushed
* on each new line. Otherwise, STDIO needs to be explicitly flushed to
* see the output in context.
*/
#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && \
CONFIG_STDIO_BUFFER_SIZE > 0 && !defined(CONFIG_STDIO_LINEBUFFER)
# define FFLUSH() fflush(stdout)
#else
# define FFLUSH()
#endif
/****************************************************************************
* Public Types
****************************************************************************/
typedef int (*cmd_t)(SESSION handle, int argc, char **argv);
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* FTP command handlers */
extern int cmd_rlogin(SESSION handle, int argc, char **argv);
extern int cmd_rquit(SESSION handle, int argc, char **argv);
extern int cmd_rchdir(SESSION handle, int argc, char **argv);
extern int cmd_rpwd(SESSION handle, int argc, char **argv);
extern int cmd_rcdup(SESSION handle, int argc, char **argv);
extern int cmd_rmkdir(SESSION handle, int argc, char **argv);
extern int cmd_rrmdir(SESSION handle, int argc, char **argv);
extern int cmd_runlink(SESSION handle, int argc, char **argv);
extern int cmd_rchmod(SESSION handle, int argc, char **argv);
extern int cmd_rrename(SESSION handle, int argc, char **argv);
extern int cmd_rsize(SESSION handle, int argc, char **argv);
extern int cmd_rtime(SESSION handle, int argc, char **argv);
extern int cmd_ridle(SESSION handle, int argc, char **argv);
extern int cmd_rnoop(SESSION handle, int argc, char **argv);
extern int cmd_rhelp(SESSION handle, int argc, char **argv);
extern int cmd_rls(SESSION handle, int argc, char **argv);
extern int cmd_rget(SESSION handle, int argc, char **argv);
extern int cmd_rput(SESSION handle, int argc, char **argv);
#endif /* __APPS_EXAMPLES_FTPC_FTPC_H */
+398
View File
@@ -0,0 +1,398 @@
/****************************************************************************
* examples/ftpc/ftpc_cmds.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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <apps/ftpc.h>
#include "ftpc.h"
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: cmd_rlogin
****************************************************************************/
int cmd_rlogin(SESSION handle, int argc, char **argv)
{
struct ftpc_login_s login = {NULL, NULL, NULL, true};
login.uname = argv[1];
if (argc > 2)
{
login.pwd = argv[2];
}
return ftpc_login(handle, &login);
}
/****************************************************************************
* Name: cmd_rquit
****************************************************************************/
int cmd_rquit(SESSION handle, int argc, char **argv)
{
int ret = ftpc_quit(handle);
if (ret < 0)
{
printf("quit failed: %d\n", errno);
}
printf("Exitting...\n");
exit(0);
return ERROR;
}
/****************************************************************************
* Name: cmd_rchdir
****************************************************************************/
int cmd_rchdir(SESSION handle, int argc, char **argv)
{
return ftpc_chdir(handle, argv[1]);
}
/****************************************************************************
* Name: cmd_rpwd
****************************************************************************/
int cmd_rpwd(SESSION handle, int argc, char **argv)
{
FAR char *pwd = ftpc_rpwd(handle);
if (pwd)
{
printf("PWD: %s\n", pwd);
free(pwd);
return OK;
}
return ERROR;
}
/****************************************************************************
* Name: cmd_rcdup
****************************************************************************/
int cmd_rcdup(SESSION handle, int argc, char **argv)
{
return ftpc_cdup(handle);
}
/****************************************************************************
* Name: cmd_rmkdir
****************************************************************************/
int cmd_rmkdir(SESSION handle, int argc, char **argv)
{
return ftpc_mkdir(handle, argv[1]);
}
/****************************************************************************
* Name: cmd_rrmdir
****************************************************************************/
int cmd_rrmdir(SESSION handle, int argc, char **argv)
{
return ftpc_rmdir(handle, argv[1]);
}
/****************************************************************************
* Name: cmd_runlink
****************************************************************************/
int cmd_runlink(SESSION handle, int argc, char **argv)
{
return ftpc_unlink(handle, argv[1]);
}
/****************************************************************************
* Name: cmd_rchmod
****************************************************************************/
int cmd_rchmod(SESSION handle, int argc, char **argv)
{
return ftpc_chmod(handle, argv[1], argv[2]);
}
/****************************************************************************
* Name: cmd_rrename
****************************************************************************/
int cmd_rrename(SESSION handle, int argc, char **argv)
{
return ftpc_rename(handle, argv[1], argv[2]);
}
/****************************************************************************
* Name: cmd_rsize
****************************************************************************/
int cmd_rsize(SESSION handle, int argc, char **argv)
{
off_t size = ftpc_filesize(handle, argv[1]);
printf("SIZE: %lu\n", size);
return OK;
}
/****************************************************************************
* Name: cmd_rtime
****************************************************************************/
int cmd_rtime(SESSION handle, int argc, char **argv)
{
time_t filetime = ftpc_filetime(handle, argv[1]);
printf("TIME: %lu\n", (long)filetime);
return OK;
}
/****************************************************************************
* Name: cmd_ridle
****************************************************************************/
int cmd_ridle(SESSION handle, int argc, char **argv)
{
unsigned int idletime = 0;
if (argc > 1)
{
idletime = atoi(argv[1]);
}
return ftpc_idle(handle, idletime);
}
/****************************************************************************
* Name: cmd_rnoop
****************************************************************************/
int cmd_rnoop(SESSION handle, int argc, char **argv)
{
return ftpc_noop(handle);
}
/****************************************************************************
* Name: cmd_rhelp
****************************************************************************/
int cmd_rhelp(SESSION handle, int argc, char **argv)
{
FAR const char *cmd = NULL;
int ret;
if (argc > 1)
{
cmd = argv[1];
}
ret = ftpc_help(handle, cmd);
if (ret == OK)
{
FAR char *msg = ftpc_response(handle);
puts(msg);
free(msg);
}
return ret;
}
/****************************************************************************
* Name: cmd_rls
****************************************************************************/
int cmd_rls(SESSION handle, int argc, char **argv)
{
FAR struct ftpc_dirlist_s *dirlist;
FAR char *dirname = NULL;
int i;
/* Get the directory listing */
if (argc > 1)
{
dirname = argv[1];
}
dirlist = ftpc_listdir(handle, dirname);
if (!dirlist)
{
return ERROR;
}
/* Print the directory listing */
printf("%s/\n", dirname ? dirname : ".");
for (i = 0; i < dirlist->nnames; i++)
{
printf(" %s\n", dirlist->name[i]);
}
FFLUSH();
/* We are responsible for freeing the directory structure allocated by
* ftpc_listdir().
*/
ftpc_dirfree(dirlist);
return OK;
}
/****************************************************************************
* Name: cmd_rget
****************************************************************************/
int cmd_rget(SESSION handle, int argc, char **argv)
{
FAR const char *rname;
FAR const char *lname = NULL;
int xfrmode = FTPC_XFRMODE_ASCII;
int option;
while ((option = getopt(argc, argv, "ab")) != ERROR)
{
if (option == 'a')
{
xfrmode = FTPC_XFRMODE_ASCII;
}
else if (option == 'b')
{
xfrmode = FTPC_XFRMODE_BINARY;
}
else
{
printf("%s: Unrecognized option: '%c'\n", "put", option);
return ERROR;
}
}
/* There should be one or two parameters remaining on the command line */
if (optind >= argc)
{
printf("%s: Missing required arguments\n", "get");
return ERROR;
}
rname = argv[optind];
optind++;
if (optind < argc)
{
lname = argv[optind];
optind++;
}
if (optind != argc)
{
printf("%s: Too many arguments\n", "get");
return ERROR;
}
/* Perform the transfer */
return ftpc_getfile(handle, rname, lname, FTPC_GET_NORMAL, xfrmode);
}
/****************************************************************************
* Name: cmd_rput
****************************************************************************/
int cmd_rput(SESSION handle, int argc, char **argv)
{
FAR const char *lname;
FAR const char *rname = NULL;
int xfrmode = FTPC_XFRMODE_ASCII;
int option;
while ((option = getopt(argc, argv, "ab")) != ERROR)
{
if (option == 'a')
{
xfrmode = FTPC_XFRMODE_ASCII;
}
else if (option == 'b')
{
xfrmode = FTPC_XFRMODE_BINARY;
}
else
{
printf("%s: Unrecognized option: '%c'\n", "put", option);
return ERROR;
}
}
/* There should be one or two parameters remaining on the command line */
if (optind >= argc)
{
printf("%s: Missing required arguments\n", "get");
return ERROR;
}
lname = argv[optind];
optind++;
if (optind < argc)
{
rname = argv[optind];
optind++;
}
if (optind != argc)
{
printf("%s: Too many arguments\n ");
return ERROR;
}
/* Perform the transfer */
return ftp_putfile(handle, lname, rname, FTPC_PUT_NORMAL, xfrmode);
}
+455
View File
@@ -0,0 +1,455 @@
/****************************************************************************
* examples/ftpc/ftpc_main.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <apps/ftpc.h>
#include <apps/readline.h>
#include "ftpc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define FTPC_MAX_ARGUMENTS 4
/****************************************************************************
* Public Types
****************************************************************************/
struct cmdmap_s
{
const char *cmd; /* Name of the command */
cmd_t handler; /* Function that handles the command */
uint8_t minargs; /* Minimum number of arguments (including command) */
uint8_t maxargs; /* Maximum number of arguments (including command) */
const char *usage; /* Usage instructions for 'help' command */
};
/****************************************************************************
* Private Data
****************************************************************************/
static const char g_delim[] = " \t\n";
static int cmd_lhelp(SESSION handle, int argc, char **argv);
static int cmd_lunrecognized(SESSION handle, int argc, char **argv);
static const struct cmdmap_s g_cmdmap[] =
{
{ "cd", cmd_rchdir, 2, 2, "<directory>" },
{ "chmod", cmd_rchmod, 3, 3, "<permissions> <path>" },
{ "get", cmd_rget, 2, 4, "[-a|b] <rname> [<lname>]" },
{ "help", cmd_lhelp, 1, 2, "" },
{ "idle", cmd_ridle, 1, 2, "[<idletime>]" },
{ "login", cmd_rlogin, 2, 3, "<uname> [<password>]" },
{ "ls", cmd_rls, 1, 2, "[<dirpath>]" },
{ "quit", cmd_rquit, 1, 1, "" },
{ "mkdir", cmd_rmkdir, 2, 2, "<directory>" },
{ "noop", cmd_rnoop, 1, 1, "" },
{ "put", cmd_rput, 2, 4, "[-a|b] <lname> [<rname>]" },
{ "pwd", cmd_rpwd, 1, 1, "" },
{ "rename", cmd_rrename, 3, 3, "<oldname> <newname>" },
{ "rhelp", cmd_rhelp, 1, 2, "[<command>]" },
{ "rm", cmd_runlink, 2, 2, "" },
{ "rmdir", cmd_rrmdir, 2, 2, "<directory>" },
{ "size", cmd_rsize, 2, 2, "<filepath>" },
{ "time", cmd_rtime, 2, 2, "<filepath>" },
{ "up", cmd_rcdup, 1, 1, "" },
{ NULL, NULL, 1, 1, NULL }
};
static char g_line[CONFIG_FTPC_LINELEN];
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: cmd_lhelp
****************************************************************************/
static int cmd_lhelp(SESSION handle, int argc, char **argv)
{
const struct cmdmap_s *ptr;
printf("Local FTPC commands:\n");
for (ptr = g_cmdmap; ptr->cmd; ptr++)
{
if (ptr->usage)
{
printf(" %s %s\n", ptr->cmd, ptr->usage);
}
else
{
printf(" %s\n", ptr->cmd);
}
}
return OK;
}
/****************************************************************************
* Name: cmd_lunrecognized
****************************************************************************/
static int cmd_lunrecognized(SESSION handle, int argc, char **argv)
{
printf("Command %s unrecognized\n", argv[0]);
return ERROR;
}
/****************************************************************************
* Name: ftpc_argument
****************************************************************************/
char *ftpc_argument(char **saveptr)
{
char *pbegin = *saveptr;
char *pend = NULL;
const char *term;
/* Find the beginning of the next token */
for (;
*pbegin && strchr(g_delim, *pbegin) != NULL;
pbegin++);
/* If we are at the end of the string with nothing
* but delimiters found, then return NULL.
*/
if (!*pbegin)
{
return NULL;
}
/* Does the token begin with '#' -- comment */
else if (*pbegin == '#')
{
/* Return NULL meaning that we are at the end of the line */
*saveptr = pbegin;
pbegin = NULL;
}
else
{
/* Otherwise, we are going to have to parse to find the end of
* the token. Does the token begin with '"'?
*/
if (*pbegin == '"')
{
/* Yes.. then only another '"' can terminate the string */
pbegin++;
term = "\"";
}
else
{
/* No, then any of the usual terminators will terminate the argument */
term = g_delim;
}
/* Find the end of the string */
for (pend = pbegin + 1;
*pend && strchr(term, *pend) == NULL;
pend++);
/* pend either points to the end of the string or to
* the first delimiter after the string.
*/
if (*pend)
{
/* Turn the delimiter into a null terminator */
*pend++ = '\0';
}
/* Save the pointer where we left off */
*saveptr = pend;
}
/* Return the beginning of the token. */
return pbegin;
}
/****************************************************************************
* Name: ftpc_execute
****************************************************************************/
static int ftpc_execute(SESSION handle, int argc, char *argv[])
{
const struct cmdmap_s *cmdmap;
const char *cmd;
cmd_t handler = cmd_lunrecognized;
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 handler
* argv[1]: The beginning of argument (up to FTPC_MAX_ARGUMENTS)
* argv[argc]: NULL terminating pointer
*/
cmd = argv[0];
/* See if the command is one that we understand */
for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++)
{
if (strcmp(cmdmap->cmd, cmd) == 0)
{
/* Check if a valid number of arguments was provided. We
* do this simple, imperfect checking here so that it does
* not have to be performed in each command.
*/
if (argc < cmdmap->minargs)
{
/* Fewer than the minimum number were provided */
printf("Too few arguments for '%s'\n", cmd);
return ERROR;
}
else if (argc > cmdmap->maxargs)
{
/* More than the maximum number were provided */
printf("Too many arguments for '%s'\n", cmd);
return ERROR;
}
else
{
/* A valid number of arguments were provided (this does
* not mean they are right).
*/
handler = cmdmap->handler;
break;
}
}
}
ret = handler(handle, argc, argv);
if (ret < 0)
{
printf("%s failed: %d\n", cmd, errno);
}
return ret;
}
/****************************************************************************
* Name: ftpc_parse
****************************************************************************/
int ftpc_parse(SESSION handle, char *cmdline)
{
FAR char *argv[FTPC_MAX_ARGUMENTS+1];
FAR char *saveptr;
FAR char *cmd;
int argc;
int ret;
/* Initialize parser state */
memset(argv, 0, FTPC_MAX_ARGUMENTS*sizeof(FAR char *));
/* Parse out the command at the beginning of the line */
saveptr = cmdline;
cmd = ftpc_argument(&saveptr);
/* Check if any command was provided -OR- if command processing is
* currently disabled.
*/
if (!cmd)
{
/* An empty line is not an error */
return OK;
}
/* Parse all of the arguments following the command name. */
argv[0] = cmd;
for (argc = 1; argc < FTPC_MAX_ARGUMENTS; argc++)
{
argv[argc] = ftpc_argument(&saveptr);
if (!argv[argc])
{
break;
}
}
argv[argc] = NULL;
/* Check if the maximum number of arguments was exceeded */
if (argc > FTPC_MAX_ARGUMENTS)
{
printf("Too many arguments\n");
ret = -EINVAL;
}
else
{
/* Then execute the command */
ret = ftpc_execute(handle, argc, argv);
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
int ftpc_main(int argc, char **argv, char **envp)
{
struct ftpc_connect_s connect = {{0}, 0};
SESSION handle;
FAR char *ptr;
#ifndef CONFIG_EXAMPLES_FTPC_FGETS
int ret;
#endif
if (argc != 2)
{
printf("Usage:\n");
printf(" %s xx.xx.xx.xx[:pp]\n", argv[0]);
printf("Where\n");
printf(" xx.xx.xx.xx is the IP address of the FTP server\n");
printf(" pp is option port to use with the FTP server\n");
exit(1);
}
/* Check if the argument includes a port number */
ptr = strchr(argv[1], ':');
if (ptr)
{
*ptr = '\0';
connect.port = atoi(ptr+1);
}
/* In any event, we can now extract the IP address from the comman-line */
connect.addr.s_addr = inet_addr(argv[1]);
/* Connect to the FTP server */
handle = ftpc_connect(&connect);
if (!handle)
{
printf("Failed to connect to the server: %d\n", errno);
exit(1);
}
/* Present a greeting */
printf("NuttX FTP Client:\n");
FFLUSH();
/* Setting optind to -1 is a non-standard, backdoor way to reinitialize
* getopt(). getopt() is not thread safe and we have no idea what state
* it is in now!
*/
optind = -1;
/* Then enter the command line parsing loop */
for (;;)
{
/* Display the prompt string */
fputs("nfc> ", stdout);
FFLUSH();
/* Get the next line of input */
#ifdef CONFIG_EXAMPLES_FTPC_FGETS
/* fgets returns NULL on end-of-file or any I/O error */
if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin) == NULL)
{
printf("ERROR: fgets failed: %d\n", errno);
return 1;
}
#else
ret = readline(g_line, CONFIG_FTPC_LINELEN, stdin, stdout);
/* Readline normally returns the number of characters read,
* but will return 0 on end of file or a negative value
* if an error occurs. Either will cause the session to
* terminate.
*/
if (ret <= 0)
{
printf("ERROR: readline failed: %d\n", ret);
return 1;
}
#endif
else
{
/* Parse and process the command */
(void)ftpc_parse(handle, g_line);
FFLUSH();
}
}
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_FTPD
bool "FTP server example"
default n
---help---
Enable the FTP server example
if EXAMPLES_FTPD
endif
+101
View File
@@ -0,0 +1,101 @@
############################################################################
# apps/examples/ftpd/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
# Hello, World! Example
ASRCS =
CSRCS = ftpd_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: context clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,ftpd_start,SCHED_PRIORITY_DEFAULT,2048,ftpd_start)
$(call REGISTER,ftpd_stop,SCHED_PRIORITY_DEFAULT,2048,ftpd_stop)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+157
View File
@@ -0,0 +1,157 @@
/****************************************************************************
* apps/examples/ftpd/ftpd.h
* Interface for the Contiki ftpd.
*
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __APPS_EXAMPLES_FTPD_FTPD_H
#define __APPS_EXAMPLES_FTPD_FTPD_H
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* CONFIG_EXAMPLES_FTPD_PRIO - Priority of the FTP daemon.
* Default: SCHED_PRIORITY_DEFAULT
* CONFIG_EXAMPLES_FTPD_STACKSIZE - Stack size allocated for the
* FTP daemon. Default: 2048
* CONFIG_EXAMPLES_FTPD_NONETINIT - Define to suppress configuration of the
* network by apps/examples/ftpd. You would need to suppress network
* configuration if the network is configuration prior to running the
* example.
*
* If CONFIG_EXAMPLES_FTPD_NONETINIT is not defined, then the following may
* be specified to customized the network configuration:
*
* CONFIG_EXAMPLE_FTPD_NOMAC - If the hardware has no MAC address of its
* own, define this =y to provide a bogus address for testing.
* CONFIG_EXAMPLE_FTPD_IPADDR - The target IP address. Default 10.0.0.2
* CONFIG_EXAMPLE_FTPD_DRIPADDR - The default router address. Default
* 10.0.0.1
* CONFIG_EXAMPLE_FTPD_NETMASK - The network mask. Default: 255.255.255.0
*/
#ifndef CONFIG_EXAMPLES_FTPD_PRIO
# define CONFIG_EXAMPLES_FTPD_PRIO SCHED_PRIORITY_DEFAULT
#endif
#ifndef CONFIG_EXAMPLES_FTPD_STACKSIZE
# define CONFIG_EXAMPLES_FTPD_STACKSIZE 2048
#endif
#ifndef CONFIG_EXAMPLES_FTPD_CLIENTPRIO
# define CONFIG_EXAMPLES_FTPD_CLIENTPRIO SCHED_PRIORITY_DEFAULT
#endif
#ifndef CONFIG_EXAMPLES_FTPD_CLIENTSTACKSIZE
# define CONFIG_EXAMPLES_FTPD_CLIENTSTACKSIZE 2048
#endif
/* NSH always initializes the network */
#if defined(CONFIG_NSH_BUILTIN_APPS) && !defined(CONFIG_EXAMPLES_FTPD_NONETINIT)
# define CONFIG_EXAMPLES_FTPD_NONETINIT 1
#endif
#ifdef CONFIG_EXAMPLES_FTPD_NONETINIT
# undef CONFIG_EXAMPLE_FTPD_IPADDR
# undef CONFIG_EXAMPLE_FTPD_DRIPADDR
# undef CONFIG_EXAMPLE_FTPD_NETMASK
#else
# ifndef CONFIG_EXAMPLE_FTPD_IPADDR
# define CONFIG_EXAMPLE_FTPD_IPADDR 0x0a000002
# endif
# ifndef CONFIG_EXAMPLE_FTPD_DRIPADDR
# define CONFIG_EXAMPLE_FTPD_DRIPADDR 0x0a000001
# endif
# ifndef CONFIG_EXAMPLE_FTPD_NETMASK
# define CONFIG_EXAMPLE_FTPD_NETMASK 0xffffff00
# endif
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/* This structure describes one entry in a table of accounts */
struct fptd_account_s
{
uint8_t flags;
FAR const char *user;
FAR const char *password;
FAR const char *home;
};
/* To minimize the probability of name collisitions, all FTPD example
* global data is maintained in single structure.
*/
struct ftpd_globals_s
{
bool initialized; /* True: Networking is initialized. The
* network must be initialized only once.
*/
#ifdef CONFIG_NSH_BUILTIN_APPS
volatile bool stop; /* True: Request daemon to exit */
volatile bool running; /* True: The daemon is running */
#endif
pid_t pid; /* Task ID of the FTPD daemon. The value
* -1 is a redundant indication that the
* daemon is not running.
*/
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* To minimize the probability of name collisitions, all FTPD example
* global data is maintained in a single instance of a structure.
*/
extern struct ftpd_globals_s g_ftpdglob;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* __APPS_EXAMPLES_FTPD_FTPD_H */
+292
View File
@@ -0,0 +1,292 @@
/****************************************************************************
* examples/telnetd/shell.c
*
* 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 of the Institute 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 INSTITUTE 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 INSTITUTE 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 <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>
#include <debug.h>
#include <netinet/in.h>
#include <apps/netutils/uiplib.h>
#include <apps/netutils/ftpd.h>
#include "ftpd.h"
/****************************************************************************
* Private Data
****************************************************************************/
static const struct fptd_account_s g_ftpdaccounts[] =
{
{ FTPD_ACCOUNTFLAG_SYSTEM, "root", "abc123", NULL },
{ FTPD_ACCOUNTFLAG_GUEST, "ftp", NULL, NULL },
{ FTPD_ACCOUNTFLAG_GUEST, "anonymous", NULL, NULL },
};
#define NACCOUNTS (sizeof(g_ftpdaccounts) / sizeof(struct fptd_account_s))
/****************************************************************************
* Public Data
****************************************************************************/
/* To minimize the probability of name collisitions, all FTPD example
* global data is maintained in a single instance of a structure.
*/
struct ftpd_globals_s g_ftpdglob;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: fptd_netinit
****************************************************************************/
static void fptd_netinit(void)
{
#ifndef CONFIG_EXAMPLES_FTPD_NONETINIT
struct in_addr addr;
#ifdef CONFIG_EXAMPLE_FTPD_NOMAC
uint8_t mac[IFHWADDRLEN];
#endif
/* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_EXAMPLE_FTPD_NOMAC
mac[0] = 0x00;
mac[1] = 0xe0;
mac[2] = 0xde;
mac[3] = 0xad;
mac[4] = 0xbe;
mac[5] = 0xef;
uip_setmacaddr("eth0", mac);
#endif
/* Set up our host address */
addr.s_addr = HTONL(CONFIG_EXAMPLE_FTPD_IPADDR);
uip_sethostaddr("eth0", &addr);
/* Set up the default router address */
addr.s_addr = HTONL(CONFIG_EXAMPLE_FTPD_DRIPADDR);
uip_setdraddr("eth0", &addr);
/* Setup the subnet mask */
addr.s_addr = HTONL(CONFIG_EXAMPLE_FTPD_NETMASK);
uip_setnetmask("eth0", &addr);
#endif /* CONFIG_EXAMPLES_FTPD_NONETINIT */
}
/****************************************************************************
* Name: ftpd_accounts
****************************************************************************/
static void ftpd_accounts(FTPD_SESSION handle)
{
FAR const struct fptd_account_s *account;
int i;
printf("Adding accounts:\n");
for (i = 0; i < NACCOUNTS; i++)
{
account = &g_ftpdaccounts[i];
printf("%d. %s account: USER=%s PASSWORD=%s HOME=%s\n", i+1,
(account->flags & FTPD_ACCOUNTFLAG_SYSTEM) != 0 ? "Root" : "User",
(!account->user) ? "(none)" : account->user,
(!account->password) ? "(none)" : account->password,
(!account->home) ? "(none)" : account->home);
ftpd_adduser(handle, account->flags, account->user,
account->password, account->home);
}
}
/****************************************************************************
* Name: ftpd_daemon
****************************************************************************/
int ftpd_daemon(int s_argc, char **s_argv)
{
FTPD_SESSION handle;
int ret;
/* The FTPD daemon has been started */
#ifdef CONFIG_NSH_BUILTIN_APPS
g_ftpdglob.running = true;
#endif
printf("FTP daemon [%d] started\n", g_ftpdglob.pid);
/* Open FTPD */
handle = ftpd_open();
if (!handle)
{
printf("FTP daemon [%d] failed to open FTPD\n", g_ftpdglob.pid);
#ifdef CONFIG_NSH_BUILTIN_APPS
g_ftpdglob.running = false;
g_ftpdglob.stop = false;
#endif
g_ftpdglob.pid = -1;
return EXIT_FAILURE;
}
/* Configure acounts */
(void)ftpd_accounts(handle);
/* Then drive the FTPD server. */
#ifdef CONFIG_NSH_BUILTIN_APPS
while (g_ftpdglob.stop == 0)
#else
for (;;)
#endif
{
/* If ftpd_session returns success, it means that a new FTP session
* has been started.
*/
ret = ftpd_session(handle, 5000);
/* If any interesting happened (i.e., any thing other than a timeout),
* then report the interesting event.
*/
if (ret != -ETIMEDOUT)
{
printf("FTP daemon [%d] ftpd_session returned %d\n", g_ftpdglob.pid, ret);
}
}
/* Close the FTPD server and exit (we can get here only if
* CONFIG_NSH_BUILTIN_APPS is defined).
*/
#ifdef CONFIG_NSH_BUILTIN_APPS
printf("FTP daemon [%d] stopping\n", g_ftpdglob.pid);
g_ftpdglob.running = false;
g_ftpdglob.stop = false;
g_ftpdglob.pid = -1;
ftpd_close(handle);
#endif
return EXIT_SUCCESS;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ftpd_main
****************************************************************************/
int ftpd_main(int s_argc, char **s_argv)
{
/* Check if we have already initialized the network */
if (!g_ftpdglob.initialized)
{
/* Bring up the network */
printf("Initializing the network\n");
fptd_netinit();
/* Initialize daemon state */
g_ftpdglob.initialized = true;
g_ftpdglob.pid = -1;
#ifdef CONFIG_NSH_BUILTIN_APPS
g_ftpdglob.stop = false;
g_ftpdglob.running = false;
#endif
}
/* Then start the new daemon (if it is not already running) */
#ifdef CONFIG_NSH_BUILTIN_APPS
if (g_ftpdglob.stop && g_ftpdglob.running)
{
printf("Waiting for FTP daemon [%d] to stop\n", g_ftpdglob.pid);
return EXIT_FAILURE;
}
else
#endif
if (!g_ftpdglob.running)
{
printf("Starting the FTP daemon\n");
g_ftpdglob.pid = TASK_CREATE("FTP daemon", CONFIG_EXAMPLES_FTPD_PRIO,
CONFIG_EXAMPLES_FTPD_STACKSIZE,
ftpd_daemon, NULL);
if (g_ftpdglob.pid < 0)
{
printf("Failed to start the FTP daemon: %d\n", errno);
return EXIT_FAILURE;
}
}
else
{
printf("FTP daemon [%d] is running\n", g_ftpdglob.pid);
}
return EXIT_SUCCESS;
}
/****************************************************************************
* Name: ftpd_stop
****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
int ftpd_stop(int s_argc, char **s_argv)
{
if (!g_ftpdglob.initialized || !g_ftpdglob.running)
{
printf("The FTP daemon not running\n");
return EXIT_FAILURE;
}
printf("Stopping the FTP daemon, pid=%d\n", g_ftpdglob.pid);
g_ftpdglob.stop = true;
return EXIT_SUCCESS;
}
#endif
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_HELLO
bool "\"Hello, World!\" example"
default n
---help---
Enable the \"Hello, World!\" example
if EXAMPLES_HELLO
endif
+105
View File
@@ -0,0 +1,105 @@
############################################################################
# apps/examples/hello/Makefile
#
# Copyright (C) 2008, 2010-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
# Hello, World! built-in application info
APPNAME = hello
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Hello, World! Example
ASRCS =
CSRCS = hello_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_EXAMPLES_HELLO_BUILTIN),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+64
View File
@@ -0,0 +1,64 @@
/****************************************************************************
* examples/hello/hello_main.c
*
* Copyright (C) 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 <stdio.h>
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* hello_main
****************************************************************************/
int hello_main(int argc, char *argv[])
{
printf("Hello, World!!\n");
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_HELLOXX
bool "\"Hello, World!\" C++ example"
default n
---help---
Enable the \"Hello, World!\" C++ example
if EXAMPLES_HELLOXX
endif
+122
View File
@@ -0,0 +1,122 @@
############################################################################
# apps/examples/helloxx/Makefile
#
# Copyright (C) 2009-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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = helloxx_main.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = helloxx
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend disclean chkcxx
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
.built: chkcxx $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_EXAMPLES_HELLOXX_BUILTIN),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+165
View File
@@ -0,0 +1,165 @@
//***************************************************************************
// examples/helloxx/helloxx_main.cxx
//
// Copyright (C) 2009, 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 <cstdio>
#include <debug.h>
#include <nuttx/init.h>
#include <nuttx/arch.h>
//***************************************************************************
// Definitions
//***************************************************************************
// Debug ********************************************************************
// Non-standard debug that may be enabled just for testing the constructors
#ifndef CONFIG_DEBUG
# undef CONFIG_DEBUG_CXX
#endif
#ifdef CONFIG_DEBUG_CXX
# define cxxdbg dbg
# define cxxlldbg lldbg
# ifdef CONFIG_DEBUG_VERBOSE
# define cxxvdbg vdbg
# define cxxllvdbg llvdbg
# else
# define cxxvdbg(x...)
# define cxxllvdbg(x...)
# endif
#else
# define cxxdbg(x...)
# define cxxlldbg(x...)
# define cxxvdbg(x...)
# define cxxllvdbg(x...)
#endif
//***************************************************************************
// Private Classes
//***************************************************************************
class CHelloWorld
{
public:
CHelloWorld(void) : mSecret(42)
{
cxxdbg("Constructor: mSecret=%d\n", mSecret);
}
~CHelloWorld(void)
{
cxxdbg("Destructor\n");
}
bool HelloWorld(void)
{
cxxdbg("HelloWorld: mSecret=%d\n", mSecret);
if (mSecret != 42)
{
printf("CHelloWorld::HelloWorld: CONSTRUCTION FAILED!\n");
return false;
}
else
{
printf("CHelloWorld::HelloWorld: Hello, World!!\n");
return true;
}
}
private:
int mSecret;
};
//***************************************************************************
// Private Data
//***************************************************************************
// Define a statically constructed CHellowWorld instance if C++ static
// initializers are supported by the platform
#ifdef CONFIG_HAVE_CXXINITIALIZE
static CHelloWorld g_HelloWorld;
#endif
//***************************************************************************
// Public Functions
//***************************************************************************
/****************************************************************************
* Name: helloxx_main
****************************************************************************/
int helloxx_main(int argc, char *argv[])
{
// If C++ initialization for static constructors is supported, then do
// that first
#ifdef CONFIG_HAVE_CXXINITIALIZE
up_cxxinitialize();
#endif
// Exercise an explictly instantiated C++ object
CHelloWorld *pHelloWorld = new CHelloWorld;
printf("helloxx_main: Saying hello from the dynamically constructed instance\n");
pHelloWorld->HelloWorld();
// Exercise an C++ object instantiated on the stack
#ifndef CONFIG_EXAMPLES_HELLOXX_NOSTACKCONST
CHelloWorld HelloWorld;
printf("helloxx_main: Saying hello from the instance constructed on the stack\n");
HelloWorld.HelloWorld();
#endif
// Exercise an statically constructed C++ object
#ifdef CONFIG_HAVE_CXXINITIALIZE
printf("helloxx_main: Saying hello from the statically constructed instance\n");
g_HelloWorld.HelloWorld();
#endif
delete pHelloWorld;
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_HIDKBD
bool "USB HID keyboard example"
default n
---help---
Enable the USB HID keyboard example
if EXAMPLES_HIDKBD
endif
+93
View File
@@ -0,0 +1,93 @@
############################################################################
# apps/examples/hidkbd/Makefile
#
# 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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# USB Host HID keyboard Example
ASRCS =
CSRCS = hidkbd_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
context:
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+231
View File
@@ -0,0 +1,231 @@
/****************************************************************************
* examples/hidkbd/null_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 <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sched.h>
#include <errno.h>
#include <nuttx/usb/usbhost.h>
/****************************************************************************
* Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Sanity checking */
#ifndef CONFIG_USBHOST
# error "CONFIG_USBHOST is not defined"
#endif
#ifdef CONFIG_USBHOST_INT_DISABLE
# error "Interrupt endpoints are disabled (CONFIG_USBHOST_INT_DISABLE)"
#endif
#ifndef CONFIG_NFILE_DESCRIPTORS
# error "CONFIG_NFILE_DESCRIPTORS > 0 needed"
#endif
/* Provide some default values for other configuration settings */
#ifndef CONFIG_EXAMPLES_HIDKBD_DEFPRIO
# define CONFIG_EXAMPLES_HIDKBD_DEFPRIO 50
#endif
#ifndef CONFIG_EXAMPLES_HIDKBD_STACKSIZE
# define CONFIG_EXAMPLES_HIDKBD_STACKSIZE 1024
#endif
#ifndef CONFIG_EXAMPLES_HIDKBD_DEVNAME
# define CONFIG_EXAMPLES_HIDKBD_DEVNAME "/dev/kbda"
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static struct usbhost_driver_s *g_drvr;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: hidkbd_waiter
*
* Description:
* Wait for USB devices to be connected.
*
****************************************************************************/
static int hidkbd_waiter(int argc, char *argv[])
{
bool connected = false;
int ret;
printf("hidkbd_waiter: Running\n");
for (;;)
{
/* Wait for the device to change state */
ret = DRVR_WAIT(g_drvr, connected);
DEBUGASSERT(ret == OK);
connected = !connected;
printf("hidkbd_waiter: %s\n", connected ? "connected" : "disconnected");
/* Did we just become connected? */
if (connected)
{
/* Yes.. enumerate the newly connected device */
(void)DRVR_ENUMERATE(g_drvr);
}
}
/* Keep the compiler from complaining */
return 0;
}
/****************************************************************************
* Name: hidkbd_main
****************************************************************************/
int hidkbd_main(int argc, char *argv[])
{
char buffer[256];
pid_t pid;
ssize_t nbytes;
int fd;
int ret;
/* First, register all of the USB host HID keyboard class driver */
printf("hidkbd_main: Register class drivers\n");
ret = usbhost_kbdinit();
if (ret != OK)
{
printf("hidkbd_main: Failed to register the KBD class\n");
}
/* Then get an instance of the USB host interface */
printf("hidkbd_main: Initialize USB host keyboard driver\n");
g_drvr = usbhost_initialize(0);
if (g_drvr)
{
/* Start a thread to handle device connection. */
printf("hidkbd_main: Start hidkbd_waiter\n");
#ifndef CONFIG_CUSTOM_STACK
pid = task_create("usbhost", CONFIG_EXAMPLES_HIDKBD_DEFPRIO,
CONFIG_EXAMPLES_HIDKBD_STACKSIZE,
(main_t)hidkbd_waiter, (const char **)NULL);
#else
pid = task_create("usbhost", CONFIG_EXAMPLES_HIDKBD_DEFPRIO,
(main_t)hidkbd_waiter, (const char **)NULL);
#endif
/* Now just sleep. Eventually logic here will open the kbd device and
* perform the HID keyboard test.
*/
for (;;)
{
/* Open the keyboard device. Loop until the device is successfully
* opened.
*/
do
{
printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY);
if (fd < 0)
{
printf("Failed: %d\n", errno);
fflush(stdout);
sleep(3);
}
}
while (fd < 0);
printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
fflush(stdout);
/* Loop until there is a read failure */
do
{
/* Read a buffer of data */
nbytes = read(fd, buffer, 256);
if (nbytes > 0)
{
/* On success, echo the buffer to stdout */
(void)write(1, buffer, nbytes);
}
}
while (nbytes >= 0);
printf("Closing device %s: %d\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME, (int)nbytes);
fflush(stdout);
close(fd);
}
}
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_IGMP
bool "IGMP example"
default n
---help---
Enable the IGMP example
if EXAMPLES_IGMP
endif

Some files were not shown because too many files have changed in this diff Show More