mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-07 01:04:19 +08:00
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:
@@ -0,0 +1,335 @@
|
||||
5.19 2011-03-12 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Initial version of the apps/ directory was released as contributed by
|
||||
Uros Platise.
|
||||
|
||||
6.0 2011-03-21 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* README.txt -- README cosmetics
|
||||
* hello/ -- hello world minor changes
|
||||
* Makefile -- Makefile cosmetics (I am slowly adding the Darjeeling JVM)
|
||||
* Make.defs -- New file adds common make definitions for applications.
|
||||
* hello/Makefile -- Now uses new Make.defs definitions. Added README.txt.
|
||||
* apps/poweroff -- New application to turn off board power.
|
||||
* Moved NSH library, netutils, and examples from the nuttx/ directory to
|
||||
the apps/ directory
|
||||
* Moved exec_nuttapp machinery into the nuttapp/ directory.
|
||||
|
||||
6.1 2011-04-10 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Creation of auto-generated header files now occurs during the context
|
||||
build phase.
|
||||
* Added sdcard insert and eject, nsh command '?' and some code remarks
|
||||
* Renamed nuttapp to namedapp
|
||||
* namedapp/binfs.c -- Create a tiny filesystem that can be used
|
||||
to show the internal named apps under /bin.
|
||||
* Numerous fixes to build system required to support building with native
|
||||
Windows toolchain.
|
||||
|
||||
6.2 2011-05-06 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/nxffs: Add a test a a configuration that will be used to
|
||||
verify NXFFS.
|
||||
|
||||
6.3 2011-05-15 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/interpreter: Add a directory to hold interpreters. The Pascal add-
|
||||
on module now installs and builds under this directory.
|
||||
* apps/interpreter/ficl: Added logic to build Ficl (the "Forth Inspired
|
||||
Command Language"). See http://ficl.sourceforge.net/.
|
||||
* apps/netutils/dhcpc, dhcpcd, and tftp. If these directories are included
|
||||
in the configuration but CONFIG_NET_UDP is disable (which is not very wise),
|
||||
then a make error occurs because tools/mkdep.sh is called with no files.
|
||||
* system/free: Move Uros' custom free command from vsn/free
|
||||
* system/install: Add a new install command submitted by Uros Platise.
|
||||
* examples/rgmp. Add a placeholder for an RGMP build example.
|
||||
RGMP is a project for running GPOS and RTOS simultaneously on
|
||||
multi-processor platforms. See http://rgmp.sourceforge.net/wiki/index.php/Main_Page
|
||||
for further information about RGMP. NOTE: This is an empty example
|
||||
on initial check-in.
|
||||
|
||||
6.4 2011-06-06 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* nshlib/nsh_netcmds.c: If a network device name and IP address are provided
|
||||
with the ifconfig command, then this command will now set the network address.
|
||||
(Contributed by Yu Qiang).
|
||||
* netutils/ftpc: A library to support client-side FTP.
|
||||
* examples/ftpc: A simple add-on to the NSH. From NSH, you can start
|
||||
this simple FTP shell to transfer files to/from a remote FTP server.
|
||||
|
||||
6.5 2011-06-21 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* netutils/ftpc: Simpflication and size reduction.
|
||||
|
||||
6.6 2011-07-11 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Make.defs, namedapp/namedapp.c: Several structural changes made to get a
|
||||
clean compile under the ez80 ZDS-II toolchain (no design changes).
|
||||
* apps/examples/buttons: Add a test for the new standardized button interfaces
|
||||
* apps/examples/nxtext: Add another NX graphics test. This one focus on
|
||||
placing text on the background while pop-up windows occur. Text should
|
||||
continue to update normally with or without the popup windows present.
|
||||
|
||||
6.7 2011-08-02 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/nx and nxtext: These examples can now be built as NSH
|
||||
"built-in" commands.
|
||||
* apps/examples/nxhello: The simplest graphics example: It just says
|
||||
"Hello, World!" in the center of the display. This example can also be
|
||||
built as an NSH "built-in" command.
|
||||
* apps/examples/nx, ntext, and nxhello: All updated to use the new
|
||||
NuttX font interfaces.
|
||||
* apps/examples/nximage: Another super simple graphics example: It just puts
|
||||
the NuttX logo in the center of the display. This example can also be
|
||||
built as an NSH "built-in" command.
|
||||
* apps/examples/usbstorage: Can now be built as two NSH "built-in" commands:
|
||||
'msconn' will connect the USB mass storage device; 'msdis' will disconnect
|
||||
the USB storage device.
|
||||
* apps/examples/nx*: All NX header files moved from nuttx/include/nuttx to
|
||||
nuttx/include/nuttx/nx.
|
||||
* apps/examples/usbstorage: Added instrumentation to monitor memory usage
|
||||
to check for memory leaks in the USB storage driver.
|
||||
* apps/examples/nxhello/nxhello_bkgd.c: Fix handling of allocated glyph
|
||||
memory.
|
||||
|
||||
6.8 2011-08-11 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/nxlines: Added a test for NX line drawing capabilities.
|
||||
|
||||
6.9 2011-09-11 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/nxlines: Extend the line drawing text to include drawing
|
||||
of circles.
|
||||
* apps/system/i2c: Add an I2C test tool that should help to bring up I2C
|
||||
devices (when it is fully functional).
|
||||
* apps/nshlib/nsh_timcmds.c: Add the date command that can be used to
|
||||
show or set the time (only if CONFIG_RTC is set).
|
||||
|
||||
6.10 2011-10-06 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/system/i2c: Add repitition and address auto-incrementing so that
|
||||
and command can be executed numerous times. Add a new verify command
|
||||
that will write to a register, read from register, and verify that
|
||||
returned value.
|
||||
* apps/graphics/tiff: Add a library that can be used to create TIFF files.
|
||||
* apps/examples/tiff: Add a unit test for the TIFF file creation logic
|
||||
* apps/examples/lcdrw: Add a test to verify if you can or can or read
|
||||
data from an LCD correctly.
|
||||
* apps/examples/usbterm: A USB terminal example.. more of a USB chat or
|
||||
serial bridge: Data received on local console echoed via USB serial;
|
||||
data received on USB serial is echoed on the local console.
|
||||
* apps/examples/touchscreen: Add a simple, generic test for any
|
||||
touschscreen driver.
|
||||
* Makefile: The apps/ Makefile now checks for an apps/external directory
|
||||
or symbolic link. If such a directory/link exists (and has a Makefile),
|
||||
it will be added to the apps/ build. This allows external directories
|
||||
to be included into the apps/ build by simply creating a symbolic link.
|
||||
|
||||
6.11 2011-11-12 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
(No major changes from 6.10)
|
||||
|
||||
6.12 2011-12-06 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/buttons: The button test can now be executed as an NSH
|
||||
built in command.
|
||||
|
||||
6.13 2012-12-26 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/dhcpd: May now be built as an NSH built-in application
|
||||
by setting CONFIG_NSH_BUILTIN_APPS.
|
||||
* apps/netutils/dhcpd/dhcpd.c: Fix several problems using host order address
|
||||
where network addresses expected (and vice versa).
|
||||
* apps/examples/nettest: May now be built as an NSH built-in application
|
||||
by setting CONFIG_NSH_BUILTIN_APPS.
|
||||
* apps/examples/nettest: Correct some build issues with the nettest is
|
||||
built for performance evaluation.
|
||||
* apps/examples/adc: Add a very simple test to drive and test an ADC
|
||||
driver.
|
||||
* apps/examples/pwm: Add an NSH PWM command to drive and test a PWM
|
||||
driver.
|
||||
* apps/examples/can: Add an NSH CAN command to drive and test a CAN
|
||||
driver in loopback mode.
|
||||
|
||||
6.14 2012-01-15 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/buttons/main.c: The test needs to call up_buttoninit() to
|
||||
properly configure the button interrupt GPIOs.
|
||||
* apps/examples/pwm: Add support to test the pulse count option recently
|
||||
added to the PWM interface.
|
||||
|
||||
6.15 2012-02-12 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/nshlib/nsh_serial.c and nsh_usbdev.c: If NuttX is configured to use
|
||||
a USB serial console, then NSH needs to wait until the USB console is
|
||||
connected and available.
|
||||
* apps/examples/composite: Add a test of the USB composite device.
|
||||
* apps/examples/Telnetd: Move the tiny uIP shell example from
|
||||
netutils/Telnetd to examples/Telnetd. Enhanced the Telnetd daemon so that
|
||||
it supports Telnetd via a TTY device driver: A new TTY device driver is
|
||||
created when each new Telnet connection is created. The shell thread
|
||||
is started with stdin, stdout, and stderr mapped to the TTY device.
|
||||
* netutils/Telnetd: The old uIP Telnet demo is gone. In its place is a new
|
||||
Telnet infrastructure. The new Telnet daemon creates sessions that are
|
||||
"wrapped" as character devices and mapped to stdin, stdout, and stderr.
|
||||
Now the Telnet session can be inherited by spawned tasks.
|
||||
* examples/Telnetd: Add a test for the new Telnet daemon.
|
||||
* examples/Telnetd/telnetd_driver.c: Move the internal socket structure from
|
||||
the daemon's socket array into the driver's state data so that it will be
|
||||
independent from the the Telnetd daemon.
|
||||
* apps/system/readline: Moved the old nuttx/lib/stdio/lib_fgets.c here
|
||||
and renamed it as readline(). The old fgets was simplied and the overloaded
|
||||
readline functionality was removed.
|
||||
* apps/netutils/ftpd: Add an FTPD server (does not even compile on initial
|
||||
checkin).
|
||||
* apps/examples/ftpd: Add a test for the FTPD server (untest on initial
|
||||
check-in).
|
||||
* apps/nshlib/nsh_fscmds.c: Add support for a 'dmesg' command that will
|
||||
dump the system log if CONFIG_SYSLOG is selected.
|
||||
|
||||
6.16 2012-03-10 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/qencoder: Add a quadrature driver test.
|
||||
* apps/examples/ostest/fpu.c: Add a test to verify that FPU registers
|
||||
are properly saved and restored on context switches.
|
||||
* apps/system/readline/readline.c: readline() will now treat either a
|
||||
backspace or a DEL character as a backspace (i.e., deleting the character
|
||||
to the left of the cursor). This makes NSH less dependent on particular
|
||||
keyboard mappings of the Backspace key. Submitted by Mike Smith.
|
||||
* apps/examples/cdcacm: An example that illustrates how the CDC/ACM driver
|
||||
may to connected and disconnected through software control.
|
||||
* apps/examples/nsh/nsh_main.c: If available, call up_cxxinitialize() to
|
||||
initialize all statically defined C++ classes.
|
||||
* apps/nshlib: Now supports a USB serial device for NSH console I/O. This
|
||||
allows NSH to be used on boards that have USB but no serial connectors.
|
||||
|
||||
6.17 2012-04-14 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/can: Add conditional compilation so that the test can be
|
||||
configured to only send messages or to only receive messages. This will
|
||||
let the test work in other modes than simple loopback testing.
|
||||
* apps/examples/hello and apps/examples/ostest: Can now be built as NSH
|
||||
built-int functions.
|
||||
* vsn/hello: Removed. The modified apps/examples/hello is enough "Hello,
|
||||
World!"
|
||||
* apps/examples/nxconsole: Add a test of the NX console device.
|
||||
* apps/examples/nxconsole: The NX console example now supports running
|
||||
the NuttShell (NSH) within an NX window.
|
||||
* apps/system/readline: Now uses standard definitions from
|
||||
include/nuttx/ascii.h and vt100.h
|
||||
* Kconfig, */Kconfig: Added skeleton Kconfig files to all directories that
|
||||
may need them.
|
||||
|
||||
6.18 2012-05-19 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Kconfig: Continued Kconfig file updates (no longer tracking on a per-file
|
||||
basis in the ChangeLog)
|
||||
* apps/examples/watchdog: Add a watchdog timer example.
|
||||
* apps/examples/tiff: Fix wrong path used for temporary file.
|
||||
* apps/examples/touchscreen: Standardize the board-specific, touchscreen
|
||||
initialization interfaces.
|
||||
|
||||
6.19 2012-06-15 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/nshlib/nsh_usbdev.c: Add the capability to use an arbitrary USB
|
||||
device as the console (not necessarily /dev/console). This is a useful
|
||||
option because then you can still use the serial console to debug with.
|
||||
* apps/nshlib/nsh_usbdev.c: User now has to press ENTER 3 times before
|
||||
USB console will start. Otherwise, the USB console starts before there
|
||||
is anyone at the other end to listen.
|
||||
* apps/nshlib/nsh_usbdev.c and nsh_consolemain.c: Add support for the USB
|
||||
capability when a USB console is used.
|
||||
* apps/nshlib/nsh_fscmds.c: Add the 'mv' command
|
||||
|
||||
6.20 2012-07-12 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* namedapp/exec_namedapp.c - Correct an error when round robin scheduling
|
||||
is enabled. The priority of the new, named application was erroneously
|
||||
being set to the priority of the parent thread; losing its configured
|
||||
priority. Reported by Mike Smith.
|
||||
|
||||
6.21 2012-08-25 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/include/: Stylistic clean-up of all header files.
|
||||
* apps/modbus and apps/include/modbus: A port of freemodbus-v1.5.0
|
||||
has been added to the NuttX apps/ source tree.
|
||||
* apps/examples/modbus: A port of the freemodbus-v1.5.0 "demo"
|
||||
program that will be used to verify the FreeModBus port
|
||||
* apps/modbus: Don't use strerror(). It is just too big.
|
||||
* apps/modbus: Add CONFIG_MB_TERMIOS. If the driver doesn't support
|
||||
termios ioctls, then don't bother trying to configure the baud, parity
|
||||
etc.
|
||||
* apps/nshlib: If waitpid() is supported, then NSH now catches the
|
||||
return value from spawned applications (provided by Mike Smith)
|
||||
* apps/nshlib: Lock the scheduler while starting built-in applications
|
||||
in order to eliminate race conditions (also from Mike Smith).
|
||||
* apps/examples/adc, pwm, and qencoder: Add support for testing
|
||||
devices with multiple ADC, PWM, and QE devices.
|
||||
* apps/nshlib/nsh_mntcmds.c: Separated mount-related commands out of
|
||||
nsh_fscmds.c. Extended to the mount command so that if no arguments
|
||||
are provided, then the current mountpoints are enumerated.
|
||||
* apps/nshlib/nsh_mntcmds.c: Add an NSH df command to list the
|
||||
properties of mounted file systems.
|
||||
* apps/nshlib/nsh_parse.c: Extend help command options. 'help' with
|
||||
no arguments outputs a short list of commands. With -v lists all
|
||||
command line details. A command name can be added to just get
|
||||
help on one command.
|
||||
* system/readline.c: If character input/output is interrupted by a
|
||||
signal, then readline() will try the read/write again.
|
||||
* apps/*/Make.defs: Numerous fixes needed to use the automated
|
||||
configuration (from Richard Cochran).
|
||||
|
||||
6.22 2012-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/netutils/thttpd/thttpd_cgi.c: Missing NULL in argv[]
|
||||
list (contributed by Kate).
|
||||
* apps/nshlib/nsh_parse.c: CONFIG_NSH_DISABLE_WGET not CONFIG_NSH_DISABLE_GET
|
||||
in one location (found by Kate).
|
||||
* apps/examples/ostest/prioinherit.c: Limit the number of test
|
||||
threds to no more than 3 of each priority. Bad things happen
|
||||
when the existing logic tried to created several hundred test
|
||||
treads!
|
||||
* apps/nshlib/nsh.h: Both CONFIG_LIBC_STRERROR and CONFIG_NSH_STRERROR
|
||||
must be defined to use strerror() with NSH.
|
||||
* apps/examples/*/*_main.c, system/i2c/i2c_main.c, and others: Added
|
||||
configuration variable CONFIG_USER_ENTRYPOINT that may be used to change
|
||||
the default entry from user_start to some other symbol. Contributed by
|
||||
Kate.
|
||||
* apps/netutils/webserver/httpd/c: Fix a typo that as introduced in
|
||||
version r4402: 'lese' instead of 'else' (Noted by Max Holtzberg).
|
||||
* tools/mkfsdata.pl: The uIP web server CGI image making perl script was
|
||||
moved from apps/netutils/webserver/makefsdata to nuttx/tools/mkfsdata.pl
|
||||
(Part of a larger change submitted by Max Holtzberg).
|
||||
* apps/netutils/webserver, apps/examples/uip, and apps/include/netutils/httpd.h:
|
||||
The "canned" version of the uIP web servers content that was at
|
||||
netutils/webserver/httpd_fsdata.c has been replaced with a dynamically
|
||||
built configuration located at apps/examples/uip (Contributed by
|
||||
Max Holtzberg).
|
||||
* apps/netutils/webserver: Several inenhancements from Kate including the
|
||||
ability to elide scripting and SERVER headers and the ability to map
|
||||
files into memory before transferring them.
|
||||
* apps/netutils/webserver: Add ability to map a URL to CGI function.
|
||||
Contributed by Kate.
|
||||
* apps/nshlib/nsh_mntcmds.c: The changes of 6.21 introduced holes in the
|
||||
error handling: Now the number of arguments to mount can be 0 or 4.
|
||||
Additional parameter checking is required to prevent mysterious errors
|
||||
(submiteed by Kate).
|
||||
* apps/netutils/webserver/httpd_mmap.c: Fix errors when the mmap()
|
||||
length is zero (submitted by Kate).
|
||||
* apps/netutils/webserver/httpd_sendfile.c: Add and option,
|
||||
CONFIG_NETUTILS_HTTPD_SENDFILE to transfer files using the NuttX
|
||||
sendfile() interface.
|
||||
* apps/netutils/discover: A UDP network discovery utility contributed
|
||||
by Max Holtzberg.
|
||||
* apps/examples/discover: A test example for the UDP network discovery
|
||||
utility (also contribed by Max Holtzberg).
|
||||
* apps/examples/*/main.c: Too many files called main.c. Each renamed
|
||||
to something unique so that they will not collide in the archive.
|
||||
* apps/netutils/xmlrpc: The Embeddable Lightweight XML-RPC Server
|
||||
discussed at http://www.drdobbs.com/web-development/\
|
||||
an-embeddable-lightweight-xml-rpc-server/184405364. Contributed by
|
||||
Max Holtzberg.
|
||||
* apps/netutils/uip_listenon.c: Logic in uip_server.c that creates
|
||||
the listening socket was moved to this new file to support re-use.
|
||||
Contributed by Kate.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
menu "Named Applications"
|
||||
source "$APPSDIR/namedapp/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Examples"
|
||||
source "$APPSDIR/examples/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Interpreters"
|
||||
source "$APPSDIR/interpreters/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Network Utilities"
|
||||
source "$APPSDIR/netutils/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "ModBus"
|
||||
source "$APPSDIR/modbus/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NSH Library"
|
||||
source "$APPSDIR/nshlib/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "System NSH Add-Ons"
|
||||
source "$APPSDIR/system/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "VSN board Add-Ons"
|
||||
source "$APPSDIR/vsn/Kconfig"
|
||||
endmenu
|
||||
@@ -0,0 +1,41 @@
|
||||
############################################################################
|
||||
# apps/Make.defs
|
||||
# Common make definitions provided to all applications
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
define REGISTER
|
||||
@echo "Register: $1"
|
||||
@echo "{ \"$1\", $2, $3, $4 }," >> "$(APPDIR)/namedapp/namedapp_list.h"
|
||||
@echo "EXTERN int $4(int argc, char *argv[]);" >> "$(APPDIR)/namedapp/namedapp_proto.h"
|
||||
endef
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
############################################################################
|
||||
# apps/Makefile
|
||||
#
|
||||
# Copyright (C) 2011-2012 Uros Platise. All rights reserved.
|
||||
# Authors: Uros Platise <uros.platise@isotel.eu>
|
||||
# Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
-include $(TOPDIR)/.config
|
||||
|
||||
APPDIR = ${shell pwd}
|
||||
|
||||
# Application Directories
|
||||
|
||||
# CONFIGURED_APPS is the list of all configured built-in directories/built
|
||||
# action. It is created by the configured appconfig file (a copy of which
|
||||
# appears in this directory as .config)
|
||||
# SUBDIRS is the list of all directories containing Makefiles. It is used
|
||||
# only for cleaning. namedapp must always be the first in the list. This
|
||||
# list can be extended by the .config file as well
|
||||
|
||||
CONFIGURED_APPS =
|
||||
SUBDIRS = examples graphics interpreters modbus namedapp nshlib netutils system vsn
|
||||
|
||||
# There are two different mechanisms for obtaining the list of configured
|
||||
# directories:
|
||||
#
|
||||
# (1) In the legacy method, these paths are all provided in the appconfig
|
||||
# file that is copied to the top-level apps/ directory as .config
|
||||
# (2) With the development of the NuttX configuration tool, however, the
|
||||
# selected applications are now enabled by the configuration tool.
|
||||
# The apps/.config file is no longer used. Instead, the set of
|
||||
# configured build directories can be found by including a Make.defs
|
||||
# file contained in each of the apps/subdirectories.
|
||||
#
|
||||
# When the NuttX configuration tools executes, it will always define the
|
||||
# configure CONFIG_NUTTX_NEWCONFIG to select between these two cases. Then
|
||||
# legacy appconfig files will still work but newly configuration files will
|
||||
# also work. Eventually the CONFIG_NUTTX_NEWCONFIG option will be phased
|
||||
# out.
|
||||
|
||||
ifeq ($(CONFIG_NUTTX_NEWCONFIG),y)
|
||||
|
||||
include examples/Make.defs
|
||||
include graphics/Make.defs
|
||||
include interpreters/Make.defs
|
||||
include modbus/Make.defs
|
||||
include namedapp/Make.defs
|
||||
include netutils/Make.defs
|
||||
include nshlib/Make.defs
|
||||
include system/Make.defs
|
||||
include vsn/Make.defs
|
||||
|
||||
# INSTALLED_APPS is the list of currently available application directories. It
|
||||
# is the same as CONFIGURED_APPS, but filtered to exclude any non-existent
|
||||
# application directory. namedapp is always in the list of applications to be
|
||||
# built.
|
||||
|
||||
INSTALLED_APPS =
|
||||
|
||||
# The legacy case:
|
||||
|
||||
else
|
||||
-include .config
|
||||
|
||||
# INSTALLED_APPS is the list of currently available application directories. It
|
||||
# is the same as CONFIGURED_APPS, but filtered to exclude any non-existent
|
||||
# application directory. namedapp is always in the list of applications to be
|
||||
# built.
|
||||
|
||||
INSTALLED_APPS = namedapp
|
||||
endif
|
||||
|
||||
# Create the list of available applications (INSTALLED_APPS)
|
||||
|
||||
define ADD_BUILTIN
|
||||
INSTALLED_APPS += ${shell if [ -r $1/Makefile ]; then echo "$1"; fi}
|
||||
endef
|
||||
|
||||
$(foreach BUILTIN, $(CONFIGURED_APPS), $(eval $(call ADD_BUILTIN,$(BUILTIN))))
|
||||
|
||||
# The external/ directory may also be added to the INSTALLED_APPS. But there
|
||||
# is no external/ directory in the repository. Rather, this directory may be
|
||||
# provided by the user (possibly as a symbolic link) to add libraries and
|
||||
# applications to the standard build from the repository.
|
||||
|
||||
INSTALLED_APPS += ${shell if [ -r external/Makefile ]; then echo "external"; fi}
|
||||
SUBDIRS += ${shell if [ -r external/Makefile ]; then echo "external"; fi}
|
||||
|
||||
# The final build target
|
||||
|
||||
BIN = libapps$(LIBEXT)
|
||||
|
||||
# Build targets
|
||||
|
||||
all: $(BIN)
|
||||
.PHONY: $(INSTALLED_APPS) context depend clean distclean
|
||||
|
||||
$(INSTALLED_APPS):
|
||||
@$(MAKE) -C $@ TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)";
|
||||
|
||||
$(BIN): $(INSTALLED_APPS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $@, $${obj}); \
|
||||
done ; )
|
||||
|
||||
.context:
|
||||
@for dir in $(INSTALLED_APPS) ; do \
|
||||
rm -f $$dir/.context ; \
|
||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" context ; \
|
||||
done
|
||||
@touch $@
|
||||
|
||||
context: .context
|
||||
|
||||
.depend: context Makefile $(SRCS)
|
||||
@for dir in $(INSTALLED_APPS) ; do \
|
||||
rm -f $$dir/.depend ; \
|
||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" depend ; \
|
||||
done
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@for dir in $(SUBDIRS) ; do \
|
||||
$(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
|
||||
done
|
||||
@rm -f $(BIN) *~ .*.swp *.o
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: # clean
|
||||
@for dir in $(SUBDIRS) ; do \
|
||||
$(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
|
||||
done
|
||||
@rm -f .config .context .depend
|
||||
@( if [ -e external ]; then \
|
||||
echo "********************************************************"; \
|
||||
echo "* The external directory/link must be removed manually *"; \
|
||||
echo "********************************************************"; \
|
||||
fi; \
|
||||
)
|
||||
|
||||
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
Application Folder
|
||||
==================
|
||||
|
||||
Contents
|
||||
--------
|
||||
|
||||
General
|
||||
Directory Location
|
||||
Named Applications
|
||||
Named Startup main() function
|
||||
NuttShell (NSH) Built-In Commands
|
||||
Synchronous Built-In Commands
|
||||
Application Configuration File
|
||||
Example Named Application
|
||||
Building NuttX with Board-Specific Pieces Outside the Source Tree
|
||||
|
||||
General
|
||||
-------
|
||||
This folder provides various applications found in sub-directories. These
|
||||
applications are not inherently a part of NuttX but are provided you help
|
||||
you develop your own applications. The apps/ directory is a "break away"
|
||||
part of the configuration that you may chose to use or not.
|
||||
|
||||
Directory Location
|
||||
------------------
|
||||
The default application directory used by the NuttX build should be named
|
||||
apps/ (or apps-x.y/ where x.y is the NuttX version number). This apps/
|
||||
directoy should appear in the directory tree at the same level as the
|
||||
NuttX directory. Like:
|
||||
|
||||
.
|
||||
|- nuttx
|
||||
|
|
||||
`- apps
|
||||
|
||||
If all of the above conditions are TRUE, then NuttX will be able to
|
||||
find the application directory. If your application directory has a
|
||||
different name or is location at a different position, then you will
|
||||
have to inform the NuttX build system of that location. There are several
|
||||
ways to do that:
|
||||
|
||||
1) You can define CONFIG_APPS_DIR to be the full path to your application
|
||||
directory in the NuttX configuration file.
|
||||
2) You can provide the path to the application directory on the command line
|
||||
like: make APPDIR=<path> or make CONFIG_APPS_DIR=<path>
|
||||
3) When you configure NuttX using tools/configure.sh, you can provide that
|
||||
path to the application directory on the configuration command line
|
||||
like: ./configure.sh -a <app-dir> <board-name>/<config-name>
|
||||
|
||||
Named Applications
|
||||
------------------
|
||||
NuttX also supports applications that can be started using a name string.
|
||||
In this case, application entry points with their requirements are gathered
|
||||
together in two files:
|
||||
|
||||
- namedapp/namedapp_proto.h Entry points, prototype function
|
||||
- namedapp/namedapp_list.h Application specific information and requirements
|
||||
|
||||
The build occurs in several phases as different build targets are executed:
|
||||
(1) context, (2) depend, and (3) default (all). Application information is
|
||||
collected during the make context build phase.
|
||||
|
||||
To execute an application function:
|
||||
|
||||
exec_namedapp() is defined in the nuttx/include/apps/apps.h
|
||||
|
||||
NuttShell (NSH) Built-In Commands
|
||||
---------------------------------
|
||||
One use of named applications is to provide a way of invoking your custom
|
||||
application through the NuttShell (NSH) command line. NSH will support
|
||||
a seamless method invoking the applications, when the following option is
|
||||
enabled in the NuttX configuration file:
|
||||
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
|
||||
Applications registered in the apps/namedapp/namedapp_list.h file will then
|
||||
be accessible from the NSH command line. If you type 'help' at the NSH
|
||||
prompt, you will see a list of the registered commands.
|
||||
|
||||
Synchronous Built-In Commands
|
||||
-----------------------------
|
||||
By default, built-in commands started from the NSH command line will run
|
||||
asynchronously with NSH. If you want to force NSH to execute commands
|
||||
then wait for the command to execute, you can enable that feature by
|
||||
adding the following to the NuttX configuration file:
|
||||
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
|
||||
The configuration option enables support for the waitpid() RTOS interface.
|
||||
When that interface is enabled, NSH will use it to wait, sleeping until
|
||||
the built-in command executes to completion.
|
||||
|
||||
Of course, even with CONFIG_SCHED_WAITPID=y defined, specific commands
|
||||
can still be forced to run asynchronously by adding the ampersand (&)
|
||||
after the NSH command.
|
||||
|
||||
Application Configuration File
|
||||
------------------------------
|
||||
A special configuration file is used to configure which applications
|
||||
are to be included in the build. The source for this file is
|
||||
configs/<board>/<configuration>/appconfig. The existence of the appconfig
|
||||
file in the board configuration directory is sufficient to enable building
|
||||
of applications.
|
||||
|
||||
The appconfig file is copied into the apps/ directory as .config when
|
||||
NuttX is configured. .config is included in the toplevel apps/Makefile.
|
||||
As a minimum, this configuration file must define files to add to the
|
||||
CONFIGURED_APPS list like:
|
||||
|
||||
CONFIGURED_APPS += examples/hello vsn/poweroff
|
||||
|
||||
Named Start-Up main() function
|
||||
------------------------------
|
||||
A named application can even be used as the main, start-up entry point
|
||||
into your embedded software. When the user defines this option in
|
||||
the NuttX configuration file:
|
||||
|
||||
CONFIG_BUILTIN_APP_START=<application name>
|
||||
|
||||
that application shall be invoked immediately after system starts
|
||||
*instead* of the default "user_start" entry point.
|
||||
Note that <application name> must be provided as: "hello",
|
||||
will call:
|
||||
|
||||
int hello_main(int argc, char *argv[])
|
||||
|
||||
Example Named Application
|
||||
-------------------------
|
||||
An example application skeleton can be found under the examples/hello
|
||||
sub-directory. This example shows how a named application can be added
|
||||
to the project. One must define:
|
||||
|
||||
1. create sub-directory as: appname
|
||||
2. provide entry point: appname_main()
|
||||
3. set the requirements in the file: Makefile, specially the lines:
|
||||
|
||||
APPNAME = appname
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 768
|
||||
ASRCS = asm source file list as a.asm b.asm ...
|
||||
CSRCS = C source file list as foo1.c foo2.c ..
|
||||
|
||||
4. add application in the apps/.config
|
||||
|
||||
Building NuttX with Board-Specific Pieces Outside the Source Tree
|
||||
-----------------------------------------------------------------
|
||||
|
||||
Q: Has anyone come up with a tidy way to build NuttX with board-
|
||||
specific pieces outside the source tree?
|
||||
A: Here are four:
|
||||
|
||||
1) There is a make target called 'make export'. It will build
|
||||
NuttX, then bundle all of the header files, libaries, startup
|
||||
objects, and other build components into a .zip file. You
|
||||
can can move that .zip file into any build environment you
|
||||
want. You even build NuttX under a DOS CMD window.
|
||||
|
||||
This make target is documented in the top level nuttx/README.txt.
|
||||
|
||||
2) You can replace the entire apps/ directory. If there is
|
||||
nothing in the apps/ directory that you need, you can define
|
||||
CONFIG_APPS_DIR in your .config file so that it points to a
|
||||
different, custom application directory.
|
||||
|
||||
You can copy any pieces that you like from the old apps/directory
|
||||
to your custom apps directory as necessary.
|
||||
|
||||
This is documented in NuttX/configs/README.txt and
|
||||
nuttx/Documentation/NuttxPortingGuide.html (Online at
|
||||
http://nuttx.sourceforge.net/NuttxPortingGuide.html#apndxconfigs
|
||||
under Build options). And in the apps/README.txt file.
|
||||
|
||||
3) If you like the random collection of stuff in the apps/ directory
|
||||
but just want to expand the existing components with your own,
|
||||
external sub-directory then there is an easy way to that too:
|
||||
You just create the sympolic link at apps/external that
|
||||
redirects to your application sub-directory. The apps/Makefile
|
||||
will always automatically check for the existence of an
|
||||
apps/external directory and if it exists, it will automatically
|
||||
incorporate it into the build.
|
||||
|
||||
This feature of the apps/Makefile is documented only here.
|
||||
|
||||
You can, for example, create a script called install.sh that
|
||||
installs a custom application, configuration, and board specific
|
||||
directory:
|
||||
|
||||
a) Copy 'MyBoard' directory to configs/MyBoard.
|
||||
b) Add a symbolic link to MyApplication at apps/external
|
||||
c) Configure NuttX (usually by:
|
||||
|
||||
tools/configure.sh MyBoard/MyConfiguration
|
||||
|
||||
or simply by copying defconfig->nutt/.config,
|
||||
setenv.sh->nuttx/setenv.sh, Make.defs->nuttx/Make.defs,
|
||||
appconfig->apps/.config
|
||||
|
||||
Using the 'external' link makes it especially easy to add a
|
||||
'built-in' application an existing configuration.
|
||||
|
||||
4) Add any link to apps/
|
||||
|
||||
a) Add symbolic links apps/ to as many other directories as you
|
||||
want.
|
||||
b) Then just add the (relative) paths to the links in your
|
||||
appconfig file (that becomes the apps/.config file).
|
||||
|
||||
That is basically the same as my option #3 but doesn't use the
|
||||
magic 'external' link. The toplevel apps/Makefile will always
|
||||
to build whatever in finds in the apps/.config file (plus the
|
||||
external link if present).
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
@@ -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
|
||||
@@ -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
|
||||
@@ -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 */
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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 */
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 *~
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 */
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 */
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user