mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-22 22:32:11 +08:00
Completes coding of the PWM module
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4200 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
Executable
+148
@@ -0,0 +1,148 @@
|
||||
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-xx-xx 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.
|
||||
Executable
+41
@@ -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 <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
############################################################################
|
||||
# apps/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
# Authors: Uros Platise <uros.platise@isotel.eu>
|
||||
# Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
|
||||
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 namedapp nshlib netutils system vsn
|
||||
|
||||
-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
|
||||
|
||||
# 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; \
|
||||
)
|
||||
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
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
|
||||
|
||||
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, zpplication 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 += vsn/hello vsn/poweroff vsn/jvm
|
||||
|
||||
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 normal, 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 vsn/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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
############################################################################
|
||||
# apps/examples/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 # Current configuration
|
||||
|
||||
# Sub-directories
|
||||
|
||||
SUBDIRS = adc buttons dhcpd ftpc hello helloxx hidkbd igmp lcdrw mm mount \
|
||||
nettest nsh null nx nxffs nxflat nxhello nximage nxlines \
|
||||
nxtext ostest pashello pipe poll rgmp romfs sendmail serloop \
|
||||
thttpd tiff touchscreen udp uip usbserial usbstorage usbterm wget wlan
|
||||
|
||||
# Sub-directories that might need context setup
|
||||
|
||||
CNTXTDIRS =
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
CNTXTDIRS += adc
|
||||
endif
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
CNTXTDIRS += dhcpd
|
||||
endif
|
||||
ifeq ($(CONFIG_EXAMPLES_HELLOXX_BUILTIN),y)
|
||||
CNTXTDIRS += helloxx
|
||||
endif
|
||||
ifeq ($(CONFIG_EXAMPLES_LCDRW_BUILTIN),y)
|
||||
CNTXTDIRS += lcdrw
|
||||
endif
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
CNTXTDIRS += nettest
|
||||
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_TIFF_BUILTIN),y)
|
||||
CNTXTDIRS += tiff
|
||||
endif
|
||||
ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN),y)
|
||||
CNTXTDIRS += touchscreen
|
||||
endif
|
||||
ifeq ($(CONFIG_EXAMPLES_USBSTRG_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,105 @@
|
||||
############################################################################
|
||||
# apps/examples/touchscreen/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
Executable
+116
@@ -0,0 +1,116 @@
|
||||
/****************************************************************************
|
||||
* examples/examples/adc.h
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 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
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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,215 @@
|
||||
/****************************************************************************
|
||||
* examples/adc/adc_main.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/analog/adc.h>
|
||||
|
||||
#include "adc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
# define MAIN_NAME adc_main
|
||||
# define MAIN_STRING "adc_main: "
|
||||
#else
|
||||
# define MAIN_NAME user_start
|
||||
# define MAIN_STRING "user_start: "
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: user_start/adc_main
|
||||
****************************************************************************/
|
||||
|
||||
int MAIN_NAME(int argc, char *argv[])
|
||||
{
|
||||
struct adc_msg_s sample[CONFIG_EXAMPLES_ADC_GROUPSIZE];
|
||||
size_t readsize;
|
||||
ssize_t nbytes;
|
||||
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
|
||||
long nsamples;
|
||||
#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)
|
||||
nsamples = 1;
|
||||
if (argc > 1)
|
||||
{
|
||||
nsamples = strtol(argv[1], NULL, 10);
|
||||
}
|
||||
message(MAIN_STRING "nsamples: %d\n", nsamples);
|
||||
#elif defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
|
||||
message(MAIN_STRING "nsamples: %d\n", CONFIG_EXAMPLES_ADC_NSAMPLES);
|
||||
#endif
|
||||
|
||||
/* Initialization of the ADC hardware is performed by logic external to
|
||||
* this test.
|
||||
*/
|
||||
|
||||
message(MAIN_STRING "Initializing external ADC device\n");
|
||||
ret = adc_devinit();
|
||||
if (ret != OK)
|
||||
{
|
||||
message(MAIN_STRING "adc_devinit failed: %d\n", ret);
|
||||
errval = 1;
|
||||
goto errout;
|
||||
}
|
||||
message(MAIN_STRING "Hardware initialized. Opening the ADC device\n");
|
||||
|
||||
/* Open the ADC device for reading */
|
||||
|
||||
fd = open(CONFIG_EXAMPLES_ADC_DEVPATH, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
message(MAIN_STRING "open %s failed: %d\n",
|
||||
CONFIG_EXAMPLES_ADC_DEVPATH, errno);
|
||||
errval = 2;
|
||||
goto errout_with_dev;
|
||||
}
|
||||
|
||||
/* Now loop the appropriate number of times, displaying the collected
|
||||
* ADC samples.
|
||||
*/
|
||||
|
||||
message(MAIN_STRING "Entering the main loop\n");
|
||||
|
||||
#if defined(CONFIG_NSH_BUILTIN_APPS)
|
||||
for (; nsamples > 0; nsamples--)
|
||||
#elif defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
|
||||
for (nsamples = 0; nsamples < CONFIG_EXAMPLES_ADC_NSAMPLES; nsamples++)
|
||||
#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);
|
||||
message("Bytes read: %d\n", nbytes);
|
||||
|
||||
/* Handle unexpected return values */
|
||||
|
||||
if (nbytes < 0)
|
||||
{
|
||||
errval = errno;
|
||||
if (errval != EINTR)
|
||||
{
|
||||
message(MAIN_STRING "read %s failed: %d\n",
|
||||
CONFIG_EXAMPLES_ADC_DEVPATH, errval);
|
||||
errval = 3;
|
||||
goto errout_with_dev;
|
||||
}
|
||||
|
||||
message(MAIN_STRING "Interrupted read...\n");
|
||||
}
|
||||
else if (nbytes != readsize)
|
||||
{
|
||||
message(MAIN_STRING "Unexpected read size=%d, expected=%d, Ignoring\n",
|
||||
nbytes, readsize);
|
||||
}
|
||||
|
||||
/* Print the sample data on successful return */
|
||||
|
||||
else
|
||||
{
|
||||
message("Sample :\n");
|
||||
for (i = 0; i < CONFIG_EXAMPLES_ADC_GROUPSIZE; 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,105 @@
|
||||
############################################################################
|
||||
# apps/examples/buttons/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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 = 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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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,142 @@
|
||||
/****************************************************************************
|
||||
* 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
|
||||
|
||||
/* If CONFIG_NSH_BUILTIN_APPS is defined, then it is assumed that you want
|
||||
* to execute the DHCPD daemon as an NSH built-in task.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
# define MAIN_NAME dhcpd_main
|
||||
# define MAIN_NAME_STRING "dhcpd_main"
|
||||
#else
|
||||
# define MAIN_NAME user_start
|
||||
# define MAIN_NAME_STRING "user_start"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: user_start/dhcpd_main
|
||||
****************************************************************************/
|
||||
|
||||
int MAIN_NAME(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] = 0xb0;
|
||||
mac[3] = 0x0b;
|
||||
mac[4] = 0xba;
|
||||
mac[5] = 0xbe;
|
||||
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,105 @@
|
||||
############################################################################
|
||||
# apps/examples/ftpc/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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 <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 */
|
||||
Executable
+398
@@ -0,0 +1,398 @@
|
||||
/****************************************************************************
|
||||
* examples/ftpc/ftpc_cmds.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
Executable
+426
@@ -0,0 +1,426 @@
|
||||
/****************************************************************************
|
||||
* examples/ftpc/ftpc_main.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 <arpa/inet.h>
|
||||
#include <apps/ftpc.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];
|
||||
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;
|
||||
|
||||
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 */
|
||||
|
||||
if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin))
|
||||
{
|
||||
/* Parse process the command */
|
||||
|
||||
(void)ftpc_parse(handle, g_line);
|
||||
FFLUSH();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
############################################################################
|
||||
# apps/examples/hello/Makefile
|
||||
#
|
||||
# Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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 = main.c
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
context:
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f *.o *~ .*.swp .built
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
* examples/hello/main.c
|
||||
*
|
||||
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* user_start
|
||||
****************************************************************************/
|
||||
|
||||
int user_start(int argc, char *argv[])
|
||||
{
|
||||
printf("Hello, World!!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
############################################################################
|
||||
# apps/examples/helloxx/Makefile
|
||||
#
|
||||
# Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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 = 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
|
||||
@@ -0,0 +1,129 @@
|
||||
//***************************************************************************
|
||||
// examples/helloxx/main.c
|
||||
//
|
||||
// Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
// Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// 3. Neither the name NuttX nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/init.h>
|
||||
#include <cstdio>
|
||||
#include <debug.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Definitions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
class CHelloWorld
|
||||
{
|
||||
public:
|
||||
CHelloWorld(void) : mSecret(42) { lldbg("Constructor\n"); };
|
||||
~CHelloWorld(void) { lldbg("Destructor\n"); };
|
||||
|
||||
bool HelloWorld(void)
|
||||
{
|
||||
if (mSecret != 42)
|
||||
{
|
||||
printf("CHelloWorld::HelloWorld: CONSTRUCTION FAILED!\n");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("CHelloWorld::HelloWorld: Hello, World!!\n");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
int mSecret;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_HELLOXX_NOSTATICCONST
|
||||
static CHelloWorld g_HelloWorld;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// user_start
|
||||
//***************************************************************************
|
||||
|
||||
/****************************************************************************
|
||||
* Name: user_start/nxhello_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_HELLOXX_BUILTIN
|
||||
extern "C" int helloxx_main(int argc, char *argv[]);
|
||||
# define MAIN_NAME helloxx_main
|
||||
# define MAIN_STRING "helloxx_main: "
|
||||
#else
|
||||
# define MAIN_NAME user_start
|
||||
# define MAIN_STRING "user_start: "
|
||||
#endif
|
||||
|
||||
int MAIN_NAME(int argc, char *argv[])
|
||||
{
|
||||
#ifndef CONFIG_EXAMPLES_HELLOXX_NOSTACKCONST
|
||||
CHelloWorld HelloWorld;
|
||||
#endif
|
||||
CHelloWorld *pHelloWorld = new CHelloWorld;
|
||||
|
||||
printf(MAIN_STRING "Saying hello from the dynamically constructed instance\n");
|
||||
pHelloWorld->HelloWorld();
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_HELLOXX_NOSTACKCONST
|
||||
printf(MAIN_STRING "Saying hello from the instance constructed on the stack\n");
|
||||
HelloWorld.HelloWorld();
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_HELLOXX_NOSTATICCONST
|
||||
printf(MAIN_STRING "Saying hello from the statically constructed instance\n");
|
||||
g_HelloWorld.HelloWorld();
|
||||
#endif
|
||||
|
||||
delete pHelloWorld;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
############################################################################
|
||||
# apps/examples/hidkbd/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/.config
|
||||
-include $(TOPDIR)/Make.defs
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# USB Host HID keyboard Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS = hidkbd_main.c
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
context:
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f *.o *~ .*.swp .built
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,231 @@
|
||||
/****************************************************************************
|
||||
* examples/hidkbd/null_main.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/usb/usbhost.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* Sanity checking */
|
||||
|
||||
#ifndef CONFIG_USBHOST
|
||||
# error "CONFIG_USBHOST is not defined"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBHOST_INT_DISABLE
|
||||
# error "Interrupt endpoints are disabled (CONFIG_USBHOST_INT_DISABLE)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NFILE_DESCRIPTORS
|
||||
# error "CONFIG_NFILE_DESCRIPTORS > 0 needed"
|
||||
#endif
|
||||
|
||||
/* Provide some default values for other configuration settings */
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_HIDKBD_DEFPRIO
|
||||
# define CONFIG_EXAMPLES_HIDKBD_DEFPRIO 50
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_HIDKBD_STACKSIZE
|
||||
# define CONFIG_EXAMPLES_HIDKBD_STACKSIZE 1024
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_HIDKBD_DEVNAME
|
||||
# define CONFIG_EXAMPLES_HIDKBD_DEVNAME "/dev/kbda"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct usbhost_driver_s *g_drvr;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hidkbd_waiter
|
||||
*
|
||||
* Description:
|
||||
* Wait for USB devices to be connected.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int hidkbd_waiter(int argc, char *argv[])
|
||||
{
|
||||
bool connected = false;
|
||||
int ret;
|
||||
|
||||
printf("hidkbd_waiter: Running\n");
|
||||
for (;;)
|
||||
{
|
||||
/* Wait for the device to change state */
|
||||
|
||||
ret = DRVR_WAIT(g_drvr, connected);
|
||||
DEBUGASSERT(ret == OK);
|
||||
|
||||
connected = !connected;
|
||||
printf("hidkbd_waiter: %s\n", connected ? "connected" : "disconnected");
|
||||
|
||||
/* Did we just become connected? */
|
||||
|
||||
if (connected)
|
||||
{
|
||||
/* Yes.. enumerate the newly connected device */
|
||||
|
||||
(void)DRVR_ENUMERATE(g_drvr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Keep the compiler from complaining */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: user_start
|
||||
****************************************************************************/
|
||||
|
||||
int user_start(int argc, char *argv[])
|
||||
{
|
||||
char buffer[256];
|
||||
pid_t pid;
|
||||
ssize_t nbytes;
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
/* First, register all of the USB host HID keyboard class driver */
|
||||
|
||||
printf("user_start: Register class drivers\n");
|
||||
ret = usbhost_kbdinit();
|
||||
if (ret != OK)
|
||||
{
|
||||
printf("user_start: Failed to register the KBD class\n");
|
||||
}
|
||||
|
||||
/* Then get an instance of the USB host interface */
|
||||
|
||||
printf("user_start: Initialize USB host keyboard driver\n");
|
||||
g_drvr = usbhost_initialize(0);
|
||||
if (g_drvr)
|
||||
{
|
||||
/* Start a thread to handle device connection. */
|
||||
|
||||
printf("user_start: Start hidkbd_waiter\n");
|
||||
|
||||
#ifndef CONFIG_CUSTOM_STACK
|
||||
pid = task_create("usbhost", CONFIG_EXAMPLES_HIDKBD_DEFPRIO,
|
||||
CONFIG_EXAMPLES_HIDKBD_STACKSIZE,
|
||||
(main_t)hidkbd_waiter, (const char **)NULL);
|
||||
#else
|
||||
pid = task_create("usbhost", CONFIG_EXAMPLES_HIDKBD_DEFPRIO,
|
||||
(main_t)hidkbd_waiter, (const char **)NULL);
|
||||
#endif
|
||||
|
||||
/* Now just sleep. Eventually logic here will open the kbd device and
|
||||
* perform the HID keyboard test.
|
||||
*/
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Open the keyboard device. Loop until the device is successfully
|
||||
* opened.
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
|
||||
fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("Failed: %d\n", errno);
|
||||
fflush(stdout);
|
||||
sleep(3);
|
||||
}
|
||||
}
|
||||
while (fd < 0);
|
||||
|
||||
printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
|
||||
fflush(stdout);
|
||||
|
||||
/* Loop until there is a read failure */
|
||||
|
||||
do
|
||||
{
|
||||
/* Read a buffer of data */
|
||||
|
||||
nbytes = read(fd, buffer, 256);
|
||||
if (nbytes > 0)
|
||||
{
|
||||
/* On success, echo the buffer to stdout */
|
||||
|
||||
(void)write(1, buffer, nbytes);
|
||||
}
|
||||
}
|
||||
while (nbytes >= 0);
|
||||
|
||||
printf("Closing device %s: %d\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME, (int)nbytes);
|
||||
fflush(stdout);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
############################################################################
|
||||
# apps/examples/igmp/Makefile
|
||||
#
|
||||
# Copyright (C) 2010 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
|
||||
# IGMP Networking Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS = igmp.c
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
context:
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f *.o *~ .*.swp .built
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
Executable
+142
@@ -0,0 +1,142 @@
|
||||
/****************************************************************************
|
||||
* examples/igmp/igmp.c
|
||||
*
|
||||
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/uip/uip.h>
|
||||
#include <apps/netutils/uiplib.h>
|
||||
#include <apps/netutils/ipmsfilter.h>
|
||||
|
||||
#include "igmp.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Check if the destination address is a multicast address
|
||||
*
|
||||
* - IPv4: multicast addresses lie in the class D group -- The address range
|
||||
* 224.0.0.0 to 239.255.255.255 (224.0.0.0/4)
|
||||
*
|
||||
* - IPv6 multicast addresses are have the high-order octet of the
|
||||
* addresses=0xff (ff00::/8.)
|
||||
*/
|
||||
|
||||
#if ((CONFIG_EXAMPLE_IGMP_GRPADDR & 0xffff0000) < 0xe0000000ul) || \
|
||||
((CONFIG_EXAMPLE_IGMP_GRPADDR & 0xffff0000) > 0xeffffffful)
|
||||
# error "Bad range for IGMP group address"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* user_start
|
||||
****************************************************************************/
|
||||
|
||||
int user_start(int argc, char *argv[])
|
||||
{
|
||||
struct in_addr addr;
|
||||
#if defined(CONFIG_EXAMPLE_IGMP_NOMAC)
|
||||
uint8_t mac[IFHWADDRLEN];
|
||||
#endif
|
||||
|
||||
message("Configuring Ethernet...\n");
|
||||
|
||||
/* Many embedded network interfaces must have a software assigned MAC */
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IGMP_NOMAC
|
||||
mac[0] = 0x00;
|
||||
mac[1] = 0xe0;
|
||||
mac[2] = 0xb0;
|
||||
mac[3] = 0x0b;
|
||||
mac[4] = 0xba;
|
||||
mac[5] = 0xbe;
|
||||
uip_setmacaddr("eth0", mac);
|
||||
#endif
|
||||
|
||||
/* Set up our host address */
|
||||
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLE_IGMP_IPADDR);
|
||||
uip_sethostaddr("eth0", &addr);
|
||||
|
||||
/* Set up the default router address */
|
||||
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLE_IGMP_DRIPADDR);
|
||||
uip_setdraddr("eth0", &addr);
|
||||
|
||||
/* Setup the subnet mask */
|
||||
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLE_IGMP_NETMASK);
|
||||
uip_setnetmask("eth0", &addr);
|
||||
|
||||
/* Not much of a test for now */
|
||||
/* Join the group */
|
||||
|
||||
message("Join group...\n");
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLE_IGMP_GRPADDR);
|
||||
ipmsfilter("eth0", &addr, MCAST_INCLUDE);
|
||||
|
||||
/* Wait a while */
|
||||
|
||||
message("Wait for timeout...\n");
|
||||
sleep(5);
|
||||
|
||||
/* Leave the group */
|
||||
|
||||
message("Leave group...\n");
|
||||
ipmsfilter("eth0", &addr, MCAST_EXCLUDE);
|
||||
|
||||
/* Wait a while */
|
||||
|
||||
sleep(5);
|
||||
message("Exiting...\n");
|
||||
return 0;
|
||||
}
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
* examples/igmp/igmp.h
|
||||
*
|
||||
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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_IGMP_H
|
||||
#define __EXAMPLES_IGMP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Used lib_rawprintf() so that there is no confusion from buffered IO */
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
#else
|
||||
# define message lib_rawprintf
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __EXAMPLES_IGMP_H */
|
||||
@@ -0,0 +1,105 @@
|
||||
############################################################################
|
||||
# apps/examples/lcdrw/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
|
||||
# LCD Read/Write Test
|
||||
|
||||
ASRCS =
|
||||
CSRCS = lcdrw_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 .
|
||||
|
||||
# LCD R/W built-in application info
|
||||
|
||||
APPNAME = lcdrw
|
||||
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_EXAMPLES_LCDRW_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,262 @@
|
||||
/****************************************************************************
|
||||
* examples/lcdrw/lcdrw_main.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <nuttx/lcd/lcd.h>
|
||||
#include <nuttx/nx/nxglib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
/* Most of the NX configuration settings are probbably *not* needed by this
|
||||
* example. But, presumeably you are using NX too and so the checks might
|
||||
* be good for you.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NX
|
||||
# error "CONFIG_NX must be defined to use this test"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NX_LCDDRIVER
|
||||
# error "CONFIG_NX_LCDDRIVER must be defined to use this test"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_LCDRW_BPP
|
||||
# define CONFIG_EXAMPLES_LCDRW_BPP 16
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLES_LCDRW_BPP != 16
|
||||
# error "Currently only RGB565 is supported -- feel free to extend"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NX_DISABLE_16BPP
|
||||
# error "CONFIG_NX_DISABLE_16BPP disables 16-bit support"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_LDCRW_DEVNO
|
||||
# define CONFIG_EXAMPLES_LDCRW_DEVNO 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_LDCRW_XRES
|
||||
# define CONFIG_EXAMPLES_LDCRW_XRES 240
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_LDCRW_YRES
|
||||
# define CONFIG_EXAMPLES_LDCRW_YRES 320
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct lcdrw_instance_s
|
||||
{
|
||||
/* LCD device handle and planeinfo */
|
||||
|
||||
FAR struct lcd_dev_s *dev;
|
||||
struct lcd_planeinfo_s pinfo;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: lcdrw_initialize
|
||||
****************************************************************************/
|
||||
|
||||
static inline int lcdrw_initialize(FAR struct lcdrw_instance_s *inst)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Initialize the LCD device */
|
||||
|
||||
printf("screens_initialize: Initializing LCD\n");
|
||||
ret = up_lcdinitialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "screens_initialize: up_lcdinitialize failed: %d\n", -ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get the device instance. */
|
||||
|
||||
printf("Get LCD instance\n");
|
||||
inst->dev = up_lcdgetdev(CONFIG_EXAMPLES_LDCRW_DEVNO);
|
||||
if (!inst->dev)
|
||||
{
|
||||
fprintf(stderr, "up_lcdgetdev failed, devno=%d\n", CONFIG_EXAMPLES_LDCRW_DEVNO);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Turn the LCD on at 75% power. This should not be necessary. */
|
||||
|
||||
(void)inst->dev->setpower(inst->dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
|
||||
|
||||
/* Get the planeinfo structure */
|
||||
|
||||
ret = inst->dev->getplaneinfo(inst->dev, 0, &inst->pinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "getplaneinfo failed: %d\n", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcdrw_main/user_start
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_LCDRW_BUILTIN
|
||||
# define MAIN_NAME lcdrw_main
|
||||
#else
|
||||
# define MAIN_NAME user_start
|
||||
#endif
|
||||
|
||||
int MAIN_NAME(int argc, char *argv[])
|
||||
{
|
||||
struct lcdrw_instance_s inst;
|
||||
nxgl_coord_t row;
|
||||
nxgl_coord_t col;
|
||||
uint16_t value;
|
||||
uint32_t offset;
|
||||
FAR uint16_t *ptr;
|
||||
int ret;
|
||||
|
||||
/* Initialize the LCD driver */
|
||||
|
||||
ret = lcdrw_initialize(&inst);
|
||||
if (ret < 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Then read each line from the LCD and write to the TIFF file */
|
||||
|
||||
value = 0;
|
||||
for (row = 0; row < CONFIG_EXAMPLES_LDCRW_YRES; row++)
|
||||
{
|
||||
/* Create a dummy row. The important thing is to try all
|
||||
* bit combinations in a predictable way.
|
||||
*/
|
||||
|
||||
ptr = (FAR uint16_t*)inst.pinfo.buffer;
|
||||
for (col = 0; col < CONFIG_EXAMPLES_LDCRW_XRES; col++)
|
||||
{
|
||||
*ptr++ = value++;
|
||||
}
|
||||
|
||||
/* Write the row to the LCD */
|
||||
|
||||
ret = inst.pinfo.putrun(row, 0, inst.pinfo.buffer,
|
||||
CONFIG_EXAMPLES_LDCRW_XRES);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "putrun failed: %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Print a header */
|
||||
|
||||
printf(" ");
|
||||
for (col = 0; col < 15; col++)
|
||||
{
|
||||
printf("---%x ", col);
|
||||
}
|
||||
printf("---f\n");
|
||||
|
||||
/* Then read each line back from the LCD (this would hook into
|
||||
* the TIFF file creation library *very* easily to create a
|
||||
* TIFF file of the returned values).
|
||||
*/
|
||||
|
||||
offset = 0;
|
||||
for (row = 0; row < CONFIG_EXAMPLES_LDCRW_YRES; row++)
|
||||
{
|
||||
/* Read the row */
|
||||
|
||||
ret = inst.pinfo.getrun(row, 0, inst.pinfo.buffer,
|
||||
CONFIG_EXAMPLES_LDCRW_XRES);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "getrun failed: %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Then dump the row to the display */
|
||||
|
||||
ptr = (FAR uint16_t*)inst.pinfo.buffer;
|
||||
for (col = 0; col < CONFIG_EXAMPLES_LDCRW_XRES; col++)
|
||||
{
|
||||
if ((offset & 15) == 0)
|
||||
{
|
||||
printf("%06x ", offset);
|
||||
}
|
||||
|
||||
value = *ptr++;
|
||||
offset++;
|
||||
|
||||
if ((offset & 15) == 0)
|
||||
{
|
||||
printf("%04x\n", value);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%04x ", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
############################################################################
|
||||
# apps/examples/mm/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
|
||||
# Memory Management Test
|
||||
|
||||
ASRCS =
|
||||
CSRCS = mm_main.c
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
context:
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f *.o *~ .*.swp .built
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,300 @@
|
||||
/****************************************************************************
|
||||
* examples/mm/mm_main.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define NTEST_ALLOCS 32
|
||||
|
||||
/* #define STOP_ON_ERRORS do{}while(0) */
|
||||
#define STOP_ON_ERRORS exit(1)
|
||||
|
||||
/* All other definitions derive from these two */
|
||||
|
||||
#define MM_MIN_SHIFT 4 /* 16 bytes */
|
||||
#define MM_MIN_CHUNK (1 << MM_MIN_SHIFT)
|
||||
#define MM_GRAN_MASK (MM_MIN_CHUNK-1)
|
||||
#define MM_ALIGN_UP(a) (((a) + MM_GRAN_MASK) & ~MM_GRAN_MASK)
|
||||
#define MM_ALIGN_DOWN(a) ((a) & ~MM_GRAN_MASK)
|
||||
|
||||
#ifdef CONFIG_SMALL_MEMORY
|
||||
# define SIZEOF_MM_ALLOCNODE 4
|
||||
#else
|
||||
# define SIZEOF_MM_ALLOCNODE 8
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
/* Test allocations */
|
||||
|
||||
static const int alloc_sizes[NTEST_ALLOCS] =
|
||||
{
|
||||
1024, 12, 962, 5692, 10254, 111, 9932, 601,
|
||||
222, 2746, 3, 124321, 68, 776, 6750, 852,
|
||||
4732, 28, 901, 480, 5011, 1536, 2011, 81647,
|
||||
646, 1646, 69179, 194, 2590, 7, 969, 70
|
||||
};
|
||||
|
||||
static const int realloc_sizes[NTEST_ALLOCS] =
|
||||
{
|
||||
18, 3088, 963, 123, 511, 11666, 3723, 42,
|
||||
9374, 1990, 1412, 6, 592, 4088, 11, 5040,
|
||||
8663, 91255, 28, 4346, 9172, 168, 229, 4734,
|
||||
59139, 221, 7830, 30421, 1666, 4, 812, 416
|
||||
};
|
||||
|
||||
static const int random1[NTEST_ALLOCS] =
|
||||
{
|
||||
20, 11, 3, 31, 9, 29, 7, 17,
|
||||
21, 2, 26, 18, 14, 25, 0, 10,
|
||||
27, 19, 22, 28, 8, 30, 12, 15,
|
||||
4, 1, 24, 6, 16, 13, 5, 23
|
||||
};
|
||||
|
||||
static const int random2[NTEST_ALLOCS] =
|
||||
{
|
||||
2, 19, 12, 23, 30, 11, 27, 4,
|
||||
20, 7, 0, 16, 28, 15, 5, 24,
|
||||
10, 17, 25, 31, 8, 29, 3, 26,
|
||||
9, 18, 22, 13, 1, 21, 14, 6
|
||||
};
|
||||
|
||||
static const int random3[NTEST_ALLOCS] =
|
||||
{
|
||||
8, 17, 3, 18, 26, 23, 30, 11,
|
||||
12, 22, 4, 20, 25, 10, 27, 1,
|
||||
29, 14, 19, 21, 0, 31, 7, 24,
|
||||
9, 15, 2, 28, 16, 6, 13, 5
|
||||
};
|
||||
|
||||
static const int alignment[NTEST_ALLOCS/2] =
|
||||
{
|
||||
128, 2048, 131072, 8192, 32, 32768, 16384 , 262144,
|
||||
512, 4096, 65536, 8, 64, 1024, 16, 4
|
||||
};
|
||||
|
||||
static void *allocs[NTEST_ALLOCS];
|
||||
static struct mallinfo alloc_info;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void mm_showmallinfo(void)
|
||||
{
|
||||
alloc_info = mallinfo();
|
||||
printf(" mallinfo:\n");
|
||||
printf(" Total space allocated from system = %ld\n",
|
||||
alloc_info.arena);
|
||||
printf(" Number of non-inuse chunks = %ld\n",
|
||||
alloc_info.ordblks);
|
||||
printf(" Largest non-inuse chunk = %ld\n",
|
||||
alloc_info.mxordblk);
|
||||
printf(" Total allocated space = %ld\n",
|
||||
alloc_info.uordblks);
|
||||
printf(" Total non-inuse space = %ld\n",
|
||||
alloc_info.fordblks);
|
||||
}
|
||||
|
||||
static void do_mallocs(void **mem, const int *size, const int *seq, int n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
j = seq[i];
|
||||
if (!mem[j])
|
||||
{
|
||||
printf("(%d)Allocating %d bytes\n", i, size[j]);
|
||||
mem[j] = malloc(size[j]);
|
||||
printf("(%d)Memory allocated at %p\n", i, mem[j]);
|
||||
if (mem[j] == NULL)
|
||||
{
|
||||
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE);
|
||||
fprintf(stderr, "(%d)malloc failed for allocsize=%d\n", i, allocsize);
|
||||
if (allocsize > alloc_info.mxordblk)
|
||||
{
|
||||
fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(mem[j], 0xAA, size[j]);
|
||||
}
|
||||
|
||||
mm_showmallinfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void do_reallocs(void **mem, const int *oldsize, const int *newsize, const int *seq, int n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
j = seq[i];
|
||||
printf("(%d)Re-allocating at %p from %d to %d bytes\n",
|
||||
i, mem[j], oldsize[j], newsize[j]);
|
||||
mem[j] = realloc(mem[j], newsize[j]);
|
||||
printf("(%d)Memory re-allocated at %p\n", i, mem[j]);
|
||||
if (mem[j] == NULL)
|
||||
{
|
||||
int allocsize = MM_ALIGN_UP(newsize[j] + SIZEOF_MM_ALLOCNODE);
|
||||
fprintf(stderr, "(%d)realloc failed for allocsize=%d\n", i, allocsize);
|
||||
if (allocsize > alloc_info.mxordblk)
|
||||
{
|
||||
fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(mem[j], 0x55, newsize[j]);
|
||||
}
|
||||
|
||||
mm_showmallinfo();
|
||||
}
|
||||
}
|
||||
|
||||
static void do_memaligns(void **mem, const int *size, const int *align, const int *seq, int n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
j = seq[i];
|
||||
printf("(%d)Allocating %d bytes aligned to 0x%08x\n",
|
||||
i, size[j], align[i]);
|
||||
mem[j] = memalign(align[i], size[j]);
|
||||
printf("(%d)Memory allocated at %p\n", i, mem[j]);
|
||||
if (mem[j] == NULL)
|
||||
{
|
||||
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE) + 2*align[i];
|
||||
fprintf(stderr, "(%d)memalign failed for allocsize=%d\n", i, allocsize);
|
||||
if (allocsize > alloc_info.mxordblk)
|
||||
{
|
||||
fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(mem[j], 0x33, size[j]);
|
||||
}
|
||||
|
||||
mm_showmallinfo();
|
||||
}
|
||||
}
|
||||
|
||||
static void do_frees(void **mem, const int *size, const int *seq, int n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
j = seq[i];
|
||||
printf("(%d)Releasing memory at %p (size=%d bytes)\n",
|
||||
i, mem[j], size[j]);
|
||||
free(mem[j]);
|
||||
mem[j] = NULL;
|
||||
|
||||
mm_showmallinfo();
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: user_start
|
||||
****************************************************************************/
|
||||
|
||||
int user_start(int argc, char *argv[])
|
||||
{
|
||||
mm_showmallinfo();
|
||||
|
||||
/* Allocate some memory */
|
||||
|
||||
do_mallocs(allocs, alloc_sizes, random1, NTEST_ALLOCS);
|
||||
|
||||
/* Re-allocate the memory */
|
||||
|
||||
do_reallocs(allocs, alloc_sizes, realloc_sizes, random2, NTEST_ALLOCS);
|
||||
|
||||
/* Release the memory */
|
||||
|
||||
do_frees(allocs, realloc_sizes, random3, NTEST_ALLOCS);
|
||||
|
||||
/* Allocate aligned memory */
|
||||
|
||||
do_memaligns(allocs, alloc_sizes, alignment, random2, NTEST_ALLOCS/2);
|
||||
do_memaligns(allocs, alloc_sizes, alignment, &random2[NTEST_ALLOCS/2], NTEST_ALLOCS/2);
|
||||
|
||||
/* Release aligned memory */
|
||||
|
||||
do_frees(allocs, alloc_sizes, random1, NTEST_ALLOCS);
|
||||
|
||||
printf("TEST COMPLETE\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
############################################################################
|
||||
# apps/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2008, 2010-2010 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
|
||||
# mount() test
|
||||
|
||||
ASRCS =
|
||||
CSRCS = mount_main.c ramdisk.c
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
context:
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f *.o *~ .*.swp .built
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
* examples/mount/mount.h
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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_MOUNT_MOUNT_H
|
||||
#define __EXAMPLES_MOUNT_MOUNT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configure the test */
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_MOUNT_DEVNAME)
|
||||
# if !defined(CONFIG_FS_WRITABLE)
|
||||
# error "Writable filesystem required in this configuration"
|
||||
# endif
|
||||
# undef CONFIG_EXAMPLES_MOUNT_NSECTORS
|
||||
# undef CONFIG_EXAMPLES_MOUNT_SECTORSIZE
|
||||
# undef CONFIG_EXAMPLES_MOUNT_RAMDEVNO
|
||||
# define MOUNT_DEVNAME CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
#else
|
||||
# if !defined(CONFIG_FS_FAT)
|
||||
# error "CONFIG_FS_FAT required in this configuration"
|
||||
# endif
|
||||
# if !defined(CONFIG_EXAMPLES_MOUNT_SECTORSIZE)
|
||||
# define CONFIG_EXAMPLES_MOUNT_SECTORSIZE 512
|
||||
# endif
|
||||
# if !defined(CONFIG_EXAMPLES_MOUNT_NSECTORS)
|
||||
# define CONFIG_EXAMPLES_MOUNT_NSECTORS 2048
|
||||
# endif
|
||||
# if !defined(CONFIG_EXAMPLES_MOUNT_RAMDEVNO)
|
||||
# define CONFIG_EXAMPLES_MOUNT_RAMDEVNO 0
|
||||
# endif
|
||||
# define STR_RAMDEVNO(m) #m
|
||||
# define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m)
|
||||
# define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_EXAMPLES_MOUNT_RAMDEVNO)
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
extern const char g_source[]; /* Mount 'source' path */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
extern int create_ramdisk(void);
|
||||
#endif
|
||||
|
||||
#endif /* __EXAMPLES_MOUNT_MOUNT_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,141 @@
|
||||
/****************************************************************************
|
||||
* examples/mount/ramdisk.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/ramdisk.h>
|
||||
#include <nuttx/mkfatfs.h>
|
||||
|
||||
#include "mount.h"
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BUFFER_SIZE (CONFIG_EXAMPLES_MOUNT_NSECTORS*CONFIG_EXAMPLES_MOUNT_SECTORSIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: create_ramdisk
|
||||
*
|
||||
* Description:
|
||||
* Create a RAM disk of the specified size formatting with a FAT file
|
||||
* system
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Return:
|
||||
* Zero on success, a negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int create_ramdisk(void)
|
||||
{
|
||||
char *pbuffer;
|
||||
int ret;
|
||||
|
||||
/* Allocate a buffer to hold the file system image. */
|
||||
|
||||
pbuffer = (char*)malloc(BUFFER_SIZE);
|
||||
if (!pbuffer)
|
||||
{
|
||||
printf("create_ramdisk: Failed to allocate ramdisk of size %d\n",
|
||||
BUFFER_SIZE);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Register a RAMDISK device to manage this RAM image */
|
||||
|
||||
ret = ramdisk_register(CONFIG_EXAMPLES_MOUNT_RAMDEVNO,
|
||||
pbuffer,
|
||||
CONFIG_EXAMPLES_MOUNT_NSECTORS,
|
||||
CONFIG_EXAMPLES_MOUNT_SECTORSIZE,
|
||||
true);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("create_ramdisk: Failed to register ramdisk at %s: %d\n",
|
||||
g_source, -ret);
|
||||
free(pbuffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Create a FAT filesystem on the ramdisk */
|
||||
|
||||
ret = mkfatfs(g_source, &g_fmt);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n",
|
||||
g_source);
|
||||
/* free(pbuffer); -- RAM disk is registered */
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* !CONFIG_EXAMPLES_MOUNT_DEVNAME */
|
||||
@@ -0,0 +1,142 @@
|
||||
############################################################################
|
||||
# examples/nettest/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2008, 2010-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
|
||||
|
||||
# Basic TCP networking test
|
||||
|
||||
TARG_ASRCS =
|
||||
TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT))
|
||||
|
||||
TARG_CSRCS = nettest.c
|
||||
ifeq ($(CONFIG_EXAMPLE_NETTEST_SERVER),y)
|
||||
TARG_CSRCS += nettest_server.c
|
||||
else
|
||||
TARG_CSRCS += nettest_client.c
|
||||
endif
|
||||
|
||||
TARG_COBJS = $(TARG_CSRCS:.c=$(OBJEXT))
|
||||
|
||||
TARG_SRCS = $(TARG_ASRCS) $(TARG_CSRCS)
|
||||
TARG_OBJS = $(TARG_AOBJS) $(TARG_COBJS)
|
||||
|
||||
TARG_POSIX = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
ifeq ($(WINTOOL),y)
|
||||
TARG_BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
TARG_BIN = "$(TARG_POSIX)"
|
||||
endif
|
||||
|
||||
HOSTCFLAGS += -DCONFIG_EXAMPLE_NETTEST_HOST=1
|
||||
ifeq ($(CONFIG_EXAMPLE_NETTEST_SERVER),y)
|
||||
HOSTCFLAGS += -DCONFIG_EXAMPLE_NETTEST_SERVER=1 \
|
||||
-DCONFIG_EXAMPLE_NETTEST_CLIENTIP="$(CONFIG_EXAMPLE_NETTEST_CLIENTIP)"
|
||||
endif
|
||||
ifeq ($(CONFIG_EXAMPLE_NETTEST_PERFORMANCE),y)
|
||||
HOSTCFLAGS += -DCONFIG_EXAMPLE_NETTEST_PERFORMANCE=1
|
||||
endif
|
||||
|
||||
|
||||
|
||||
HOST_SRCS = host.c
|
||||
ifeq ($(CONFIG_EXAMPLE_NETTEST_SERVER),y)
|
||||
HOST_SRCS += nettest_client.c
|
||||
else
|
||||
HOST_SRCS += nettest_server.c
|
||||
endif
|
||||
|
||||
HOST_OBJS = $(HOST_SRCS:.c=.o)
|
||||
HOST_BIN = host
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# NET test built-in application info
|
||||
|
||||
APPNAME = nettest
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built $(HOST_BIN)
|
||||
.PHONY: clean depend disclean
|
||||
|
||||
$(TARG_AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(TARG_COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
$(HOST_OBJS): %.o: %.c
|
||||
@echo "CC: $<"
|
||||
@$(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
|
||||
|
||||
$(HOST_BIN): $(HOST_OBJS)
|
||||
@echo "LD: $@"
|
||||
@$(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@
|
||||
|
||||
.built: $(TARG_OBJS)
|
||||
@( for obj in $(TARG_OBJS) ; do \
|
||||
$(call ARCHIVE, $(TARG_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 $(TARG_SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(TARG_SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f $(TARG_POSIX) $(HOST_BIN) .built *.o *~ .*.swp
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
* examples/nettest/host.c
|
||||
*
|
||||
* Copyright (C) 2007, 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 "nettest.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* main
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_SERVER
|
||||
send_client();
|
||||
#else
|
||||
recv_server();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/****************************************************************************
|
||||
* examples/nettest/nettest.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 NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/uip/uip.h>
|
||||
#include <apps/netutils/uiplib.h>
|
||||
|
||||
#include "nettest.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* If CONFIG_NSH_BUILTIN_APPS is defined, then it is assumed that you want
|
||||
* to execute the DHCPD daemon as an NSH built-in task.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
# define MAIN_NAME nettest_main
|
||||
# define MAIN_NAME_STRING "nettest_main"
|
||||
#else
|
||||
# define MAIN_NAME user_start
|
||||
# define MAIN_NAME_STRING "user_start"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* user_start
|
||||
****************************************************************************/
|
||||
|
||||
int MAIN_NAME(int argc, char *argv[])
|
||||
{
|
||||
struct in_addr addr;
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_NOMAC
|
||||
uint8_t mac[IFHWADDRLEN];
|
||||
#endif
|
||||
|
||||
/* Many embedded network interfaces must have a software assigned MAC */
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_NOMAC
|
||||
mac[0] = 0x00;
|
||||
mac[1] = 0xe0;
|
||||
mac[2] = 0xb0;
|
||||
mac[3] = 0x0b;
|
||||
mac[4] = 0xba;
|
||||
mac[5] = 0xbe;
|
||||
uip_setmacaddr("eth0", mac);
|
||||
#endif
|
||||
|
||||
/* Set up our host address */
|
||||
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLE_NETTEST_IPADDR);
|
||||
uip_sethostaddr("eth0", &addr);
|
||||
|
||||
/* Set up the default router address */
|
||||
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLE_NETTEST_DRIPADDR);
|
||||
uip_setdraddr("eth0", &addr);
|
||||
|
||||
/* Setup the subnet mask */
|
||||
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLE_NETTEST_NETMASK);
|
||||
uip_setnetmask("eth0", &addr);
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_SERVER
|
||||
recv_server();
|
||||
#else
|
||||
send_client();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/****************************************************************************
|
||||
* examples/nettest/nettest.h
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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_NETTEST_H
|
||||
#define __EXAMPLES_NETTEST_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_HOST
|
||||
#else
|
||||
# include <debug.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_HOST
|
||||
/* HTONS/L macros are unique to uIP */
|
||||
|
||||
# define HTONS(a) htons(a)
|
||||
# define HTONL(a) htonl(a)
|
||||
|
||||
/* Used printf for debug output */
|
||||
|
||||
# ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# else
|
||||
# define message printf
|
||||
# endif
|
||||
|
||||
/* Have SO_LINGER */
|
||||
|
||||
# define NETTEST_HAVE_SOLINGER 1
|
||||
|
||||
#else
|
||||
|
||||
/* Used lib_rawprintf() so that there is not confusion from buffered IO */
|
||||
|
||||
# ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# else
|
||||
# define message lib_rawprintf
|
||||
# endif
|
||||
|
||||
/* At present, uIP does only abortive disconnects */
|
||||
|
||||
# undef NETTEST_HAVE_SOLINGER
|
||||
#endif
|
||||
|
||||
#define PORTNO 5471
|
||||
#define SENDSIZE 4096
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
extern void send_client(void);
|
||||
extern void recv_server(void);
|
||||
|
||||
#endif /* __EXAMPLES_NETTEST_H */
|
||||
@@ -0,0 +1,205 @@
|
||||
/****************************************************************************
|
||||
* examples/nettest/nettest-client.c
|
||||
*
|
||||
* Copyright (C) 2007, 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 <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nettest.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void send_client(void)
|
||||
{
|
||||
struct sockaddr_in myaddr;
|
||||
char *outbuf;
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
char *inbuf;
|
||||
#endif
|
||||
int sockfd;
|
||||
int nbytessent;
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
int nbytesrecvd;
|
||||
int totalbytesrecvd;
|
||||
#endif
|
||||
int ch;
|
||||
int i;
|
||||
|
||||
/* Allocate buffers */
|
||||
|
||||
outbuf = (char*)malloc(SENDSIZE);
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
inbuf = (char*)malloc(SENDSIZE);
|
||||
if (!outbuf || !inbuf)
|
||||
#else
|
||||
if (!outbuf)
|
||||
#endif
|
||||
{
|
||||
message("client: failed to allocate buffers\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Create a new TCP socket */
|
||||
|
||||
sockfd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd < 0)
|
||||
{
|
||||
message("client socket failure %d\n", errno);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
|
||||
/* Connect the socket to the server */
|
||||
|
||||
myaddr.sin_family = AF_INET;
|
||||
myaddr.sin_port = HTONS(PORTNO);
|
||||
#if 0
|
||||
myaddr.sin_addr.s_addr = HTONL(INADDR_LOOPBACK);
|
||||
#else
|
||||
myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLE_NETTEST_CLIENTIP);
|
||||
#endif
|
||||
|
||||
message("client: Connecting...\n");
|
||||
if (connect( sockfd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0)
|
||||
{
|
||||
message("client: connect failure: %d\n", errno);
|
||||
goto errout_with_socket;
|
||||
}
|
||||
message("client: Connected\n");
|
||||
|
||||
/* Initialize the buffer */
|
||||
|
||||
ch = 0x20;
|
||||
for (i = 0; i < SENDSIZE; i++ )
|
||||
{
|
||||
outbuf[i] = ch;
|
||||
if (++ch > 0x7e)
|
||||
{
|
||||
ch = 0x20;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
/* Then send messages forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
nbytessent = send(sockfd, outbuf, SENDSIZE, 0);
|
||||
if (nbytessent < 0)
|
||||
{
|
||||
message("client: send failed: %d\n", errno);
|
||||
goto errout_with_socket;
|
||||
}
|
||||
else if (nbytessent != SENDSIZE)
|
||||
{
|
||||
message("client: Bad send length=%d: %d of \n",
|
||||
nbytessent, SENDSIZE);
|
||||
goto errout_with_socket;
|
||||
}
|
||||
message("Sent %d bytes\n", nbytessent);
|
||||
}
|
||||
#else
|
||||
/* Then send and receive one message */
|
||||
|
||||
message("client: Sending %d bytes\n", SENDSIZE);
|
||||
nbytessent = send(sockfd, outbuf, SENDSIZE, 0);
|
||||
message("client: Sent %d bytes\n", nbytessent);
|
||||
|
||||
if (nbytessent < 0)
|
||||
{
|
||||
message("client: send failed: %d\n", errno);
|
||||
goto errout_with_socket;
|
||||
}
|
||||
else if (nbytessent != SENDSIZE)
|
||||
{
|
||||
message("client: Bad send length: %d Expected: %d\n", nbytessent, SENDSIZE);
|
||||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
totalbytesrecvd = 0;
|
||||
do
|
||||
{
|
||||
message("client: Receiving...\n");
|
||||
nbytesrecvd = recv(sockfd, &inbuf[totalbytesrecvd], SENDSIZE - totalbytesrecvd, 0);
|
||||
|
||||
if (nbytesrecvd < 0)
|
||||
{
|
||||
message("client: recv failed: %d\n", errno);
|
||||
goto errout_with_socket;
|
||||
}
|
||||
totalbytesrecvd += nbytesrecvd;
|
||||
message("client: Received %d of %d bytes\n", totalbytesrecvd, SENDSIZE);
|
||||
}
|
||||
while (totalbytesrecvd < SENDSIZE);
|
||||
|
||||
if (totalbytesrecvd != SENDSIZE)
|
||||
{
|
||||
message("client: Bad recv length: %d Expected: %d\n", totalbytesrecvd, SENDSIZE);
|
||||
goto errout_with_socket;
|
||||
}
|
||||
else if (memcmp(inbuf, outbuf, SENDSIZE) != 0)
|
||||
{
|
||||
message("client: Received buffer does not match sent buffer\n");
|
||||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
free(outbuf);
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
free(inbuf);
|
||||
#endif
|
||||
return;
|
||||
#endif
|
||||
|
||||
errout_with_socket:
|
||||
close(sockfd);
|
||||
|
||||
errout_with_buffers:
|
||||
free(outbuf);
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
free(inbuf);
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
/****************************************************************************
|
||||
* examples/nettest/nettest-server.c
|
||||
*
|
||||
* Copyright (C) 2007, 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 <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nettest.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void recv_server(void)
|
||||
{
|
||||
struct sockaddr_in myaddr;
|
||||
#ifdef NETTEST_HAVE_SOLINGER
|
||||
struct linger ling;
|
||||
#endif
|
||||
char *buffer;
|
||||
int listensd;
|
||||
int acceptsd;
|
||||
socklen_t addrlen;
|
||||
int nbytesread;
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
int totalbytesread;
|
||||
int nbytessent;
|
||||
int ch;
|
||||
int i;
|
||||
#endif
|
||||
int optval;
|
||||
|
||||
/* Allocate a BIG buffer */
|
||||
|
||||
buffer = (char*)malloc(2*SENDSIZE);
|
||||
if (!buffer)
|
||||
{
|
||||
message("server: failed to allocate buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* Create a new TCP socket */
|
||||
|
||||
listensd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (listensd < 0)
|
||||
{
|
||||
message("server: socket failure: %d\n", errno);
|
||||
goto errout_with_buffer;
|
||||
}
|
||||
|
||||
/* Set socket to reuse address */
|
||||
|
||||
optval = 1;
|
||||
if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0)
|
||||
{
|
||||
message("server: setsockopt SO_REUSEADDR failure: %d\n", errno);
|
||||
goto errout_with_listensd;
|
||||
}
|
||||
|
||||
/* Bind the socket to a local address */
|
||||
|
||||
myaddr.sin_family = AF_INET;
|
||||
myaddr.sin_port = HTONS(PORTNO);
|
||||
myaddr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
if (bind(listensd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0)
|
||||
{
|
||||
message("server: bind failure: %d\n", errno);
|
||||
goto errout_with_listensd;
|
||||
}
|
||||
|
||||
/* Listen for connections on the bound TCP socket */
|
||||
|
||||
if (listen(listensd, 5) < 0)
|
||||
{
|
||||
message("server: listen failure %d\n", errno);
|
||||
goto errout_with_listensd;
|
||||
}
|
||||
|
||||
/* Accept only one connection */
|
||||
|
||||
message("server: Accepting connections on port %d\n", PORTNO);
|
||||
addrlen = sizeof(struct sockaddr_in);
|
||||
acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen);
|
||||
if (acceptsd < 0)
|
||||
{
|
||||
message("server: accept failure: %d\n", errno);
|
||||
goto errout_with_listensd;
|
||||
}
|
||||
message("server: Connection accepted -- receiving\n");
|
||||
|
||||
/* Configure to "linger" until all data is sent when the socket is closed */
|
||||
|
||||
#ifdef NETTEST_HAVE_SOLINGER
|
||||
ling.l_onoff = 1;
|
||||
ling.l_linger = 30; /* timeout is seconds */
|
||||
if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0)
|
||||
{
|
||||
message("server: setsockopt SO_LINGER failure: %d\n", errno);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
/* Then receive data forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
nbytesread = recv(acceptsd, buffer, 2*SENDSIZE, 0);
|
||||
if (nbytesread <= 0)
|
||||
{
|
||||
message("server: recv failed: %d\n", errno);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
message("Received %d bytes\n", nbytesread);
|
||||
}
|
||||
#else
|
||||
/* Receive canned message */
|
||||
|
||||
totalbytesread = 0;
|
||||
while (totalbytesread < SENDSIZE)
|
||||
{
|
||||
message("server: Reading...\n");
|
||||
nbytesread = recv(acceptsd, &buffer[totalbytesread], 2*SENDSIZE - totalbytesread, 0);
|
||||
if (nbytesread <= 0)
|
||||
{
|
||||
message("server: recv failed: %d\n", errno);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
|
||||
totalbytesread += nbytesread;
|
||||
message("server: Received %d of %d bytes\n", totalbytesread, SENDSIZE);
|
||||
}
|
||||
|
||||
/* Verify the message */
|
||||
|
||||
if (totalbytesread != SENDSIZE)
|
||||
{
|
||||
message("server: Received %d / Expected %d bytes\n", totalbytesread, SENDSIZE);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
|
||||
ch = 0x20;
|
||||
for (i = 0; i < SENDSIZE; i++ )
|
||||
{
|
||||
if (buffer[i] != ch)
|
||||
{
|
||||
message("server: Byte %d is %02x / Expected %02x\n", i, buffer[i], ch);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
|
||||
if (++ch > 0x7e)
|
||||
{
|
||||
ch = 0x20;
|
||||
}
|
||||
}
|
||||
|
||||
/* Then send the same data back to the client */
|
||||
|
||||
message("server: Sending %d bytes\n", totalbytesread);
|
||||
nbytessent = send(acceptsd, buffer, totalbytesread, 0);
|
||||
if (nbytessent <= 0)
|
||||
{
|
||||
message("server: send failed: %d\n", errno);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
message("server: Sent %d bytes\n", nbytessent);
|
||||
|
||||
/* If this platform only does abortive disconnects, then wait a bit to get the
|
||||
* client side a change to receive the data.
|
||||
*/
|
||||
|
||||
#if 1 /* Do it for all platforms */
|
||||
message("server: Wait before closing\n");
|
||||
sleep(60);
|
||||
#endif
|
||||
|
||||
close(listensd);
|
||||
close(acceptsd);
|
||||
free(buffer);
|
||||
return;
|
||||
#endif
|
||||
|
||||
errout_with_acceptsd:
|
||||
close(acceptsd);
|
||||
|
||||
errout_with_listensd:
|
||||
close(listensd);
|
||||
|
||||
errout_with_buffer:
|
||||
free(buffer);
|
||||
exit(1);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
############################################################################
|
||||
# apps/examples/nsh/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2008, 2010-2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
|
||||
# NuttShell (NSH) Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS = nsh_main.c
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
context:
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f *.o *~ .*.swp .built
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
* examples/nsh/nsh_main.c
|
||||
*
|
||||
* Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <apps/nsh.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: user_start
|
||||
****************************************************************************/
|
||||
|
||||
int user_start(int argc, char *argv[])
|
||||
{
|
||||
int mid_priority;
|
||||
#if defined(CONFIG_NSH_CONSOLE) && defined(CONFIG_NSH_TELNET)
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* Initialize the NSH library */
|
||||
|
||||
nsh_initialize();
|
||||
|
||||
/* Set the priority of this task to something in the middle so that 'nice'
|
||||
* can both raise and lower the priority.
|
||||
*/
|
||||
|
||||
mid_priority = (sched_get_priority_max(SCHED_NSH) + sched_get_priority_min(SCHED_NSH)) >> 1;
|
||||
{
|
||||
struct sched_param param;
|
||||
|
||||
param.sched_priority = mid_priority;
|
||||
(void)sched_setscheduler(0, SCHED_NSH, ¶m);
|
||||
}
|
||||
|
||||
/* If both the console and telnet are selected as front-ends, then run
|
||||
* the telnet front end on another thread.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NSH_CONSOLE) && defined(CONFIG_NSH_TELNET)
|
||||
# ifndef CONFIG_CUSTOM_STACK
|
||||
ret = task_create("nsh_telnetmain", mid_priority, CONFIG_NSH_STACKSIZE,
|
||||
nsh_telnetmain, NULL);
|
||||
# else
|
||||
ret = task_create("nsh_telnetmain", mid_priority, nsh_telnetmain, NULL);
|
||||
# endif
|
||||
if (ret < 0)
|
||||
{
|
||||
/* The daemon is NOT running. Report the the error then fail...
|
||||
* either with the serial console up or just exiting.
|
||||
*/
|
||||
|
||||
fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", errno);
|
||||
}
|
||||
|
||||
/* If only the telnet front-end is selected, run it on this thread */
|
||||
|
||||
#elif defined(CONFIG_NSH_TELNET)
|
||||
return nsh_telnetmain(0, NULL);
|
||||
#endif
|
||||
|
||||
/* If the serial console front end is selected, then run it on this thread */
|
||||
|
||||
#ifdef CONFIG_NSH_CONSOLE
|
||||
return nsh_consolemain(0, NULL);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
############################################################################
|
||||
# examples/null/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2008, 2010-2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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
|
||||
|
||||
# The smallest thing you can build -- the NULL example.
|
||||
|
||||
ASRCS =
|
||||
CSRCS = null_main.c
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
context:
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f *.o *~ .*.swp .built
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
* examples/null/null_main.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: user_start
|
||||
****************************************************************************/
|
||||
|
||||
int user_start(int argc, char *argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
############################################################################
|
||||
# apps/examples/nx/Makefile
|
||||
#
|
||||
# Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
#
|
||||
# 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 = nx_main.c nx_events.c nx_kbdin.c
|
||||
ifeq ($(CONFIG_NX_MULTIUSER),y)
|
||||
CSRCS += nx_server.c
|
||||
endif
|
||||
|
||||
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 .
|
||||
|
||||
# NX built-in application info
|
||||
|
||||
APPNAME = nx
|
||||
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_EXAMPLES_NX_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,337 @@
|
||||
/****************************************************************************
|
||||
* examples/nx/nx_events.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <semaphore.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
#include "nx_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_redraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool morem, FAR void *arg);
|
||||
static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
|
||||
FAR const struct nxgl_point_s *pos,
|
||||
FAR const struct nxgl_rect_s *bounds,
|
||||
FAR void *arg);
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg);
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool morem, FAR void *arg);
|
||||
static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
|
||||
FAR const struct nxgl_point_s *pos,
|
||||
FAR const struct nxgl_rect_s *bounds,
|
||||
FAR void *arg);
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
const struct nx_callback_s g_nxcb =
|
||||
{
|
||||
nxeg_redraw, /* redraw */
|
||||
nxeg_position /* position */
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
, nxeg_mousein /* mousein */
|
||||
#endif
|
||||
#ifdef CONFIG_NX_KBD
|
||||
, nxeg_kbdin /* my kbdin */
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
const struct nx_callback_s g_tbcb =
|
||||
{
|
||||
nxeg_tbredraw, /* redraw */
|
||||
nxeg_tbposition /* position */
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
, nxeg_tbmousein /* mousein */
|
||||
#endif
|
||||
#ifdef CONFIG_NX_KBD
|
||||
, nxeg_tbkbdin /* my kbdin */
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_fillwindow
|
||||
****************************************************************************/
|
||||
|
||||
static inline void nxeg_fillwindow(NXEGWINDOW hwnd,
|
||||
FAR const struct nxgl_rect_s *rect,
|
||||
FAR struct nxeg_state_s *st)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
ret = nx_fill(hwnd, rect, st->color);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_fillwindow: nx_fill failed: %d\n", errno);
|
||||
}
|
||||
#else
|
||||
ret = nxtk_fillwindow(hwnd, rect, st->color);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_fillwindow: nxtk_fillwindow failed: %d\n", errno);
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_NX_KBD
|
||||
nxeg_filltext(hwnd, rect, st);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_fillwindow
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline void nxeg_filltoolbar(NXTKWINDOW htb,
|
||||
FAR const struct nxgl_rect_s *rect,
|
||||
nxgl_mxpixel_t color[CONFIG_NX_NPLANES])
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = nxtk_filltoolbar(htb, rect, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_filltoolbar: nxtk_filltoolbar failed: %d\n", errno);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_redraw
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_redraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool more, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
|
||||
st->wnum, hwnd,
|
||||
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
|
||||
more ? "true" : "false");
|
||||
|
||||
nxeg_fillwindow(hwnd, rect, st);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_position
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
|
||||
FAR const struct nxgl_point_s *pos,
|
||||
FAR const struct nxgl_rect_s *bounds,
|
||||
FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
|
||||
/* Report the position */
|
||||
|
||||
message("nxeg_position%d: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
|
||||
st->wnum, hwnd, size->w, size->h, pos->x, pos->y,
|
||||
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
|
||||
|
||||
/* Have we picked off the window bounds yet? */
|
||||
|
||||
if (!b_haveresolution)
|
||||
{
|
||||
/* Save the window limits (these should be the same for all places and all windows */
|
||||
|
||||
g_xres = bounds->pt2.x;
|
||||
g_yres = bounds->pt2.y;
|
||||
|
||||
b_haveresolution = true;
|
||||
sem_post(&g_semevent);
|
||||
message("nxeg_position2: Have xres=%d yres=%d\n", g_xres, g_yres);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_mousein
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_mousein%d: hwnd=%p pos=(%d,%d) button=%02x\n",
|
||||
st->wnum, hwnd, pos->x, pos->y, buttons);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_tbredraw
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool more, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_tbredraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
|
||||
st->wnum, hwnd,
|
||||
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
|
||||
more ? "true" : "false");
|
||||
nxeg_filltoolbar(hwnd, rect, g_tbcolor);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_position
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
|
||||
FAR const struct nxgl_point_s *pos,
|
||||
FAR const struct nxgl_rect_s *bounds,
|
||||
FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
|
||||
/* Report the position */
|
||||
|
||||
message("nxeg_ptbosition%d: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
|
||||
st->wnum, hwnd, size->w, size->h, pos->x, pos->y,
|
||||
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_tbmousein
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
|
||||
message("nxeg_tbmousein%d: hwnd=%p pos=(%d,%d) button=%02x\n",
|
||||
st->wnum, hwnd, pos->x, pos->y, buttons);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_listenerthread
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
FAR void *nx_listenerthread(FAR void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Process events forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Handle the next event. If we were configured blocking, then
|
||||
* we will stay right here until the next event is received. Since
|
||||
* we have dedicated a while thread to servicing events, it would
|
||||
* be most natural to also select CONFIG_NX_BLOCKING -- if not, the
|
||||
* following would be a tight infinite loop (unless we added addition
|
||||
* logic with nx_eventnotify and sigwait to pace it).
|
||||
*/
|
||||
|
||||
ret = nx_eventhandler(g_hnx);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* An error occurred... assume that we have lost connection with
|
||||
* the server.
|
||||
*/
|
||||
|
||||
message("nx_listenerthread: Lost server connection: %d\n", errno);
|
||||
exit(NXEXIT_LOSTSERVERCONN);
|
||||
}
|
||||
|
||||
/* If we received a message, we must be connected */
|
||||
|
||||
if (!g_connected)
|
||||
{
|
||||
g_connected = true;
|
||||
sem_post(&g_semevent);
|
||||
message("nx_listenerthread: Connected\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,317 @@
|
||||
/****************************************************************************
|
||||
* examples/nx/nx_internal.h
|
||||
*
|
||||
* Copyright (C) 2008-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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_NX_NX_INTERNAL_H
|
||||
#define __EXAMPLES_NX_NX_INTERNAL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_NX
|
||||
# error "NX is not enabled (CONFIG_NX)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_VPLANE
|
||||
# define CONFIG_EXAMPLES_NX_VPLANE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_BPP
|
||||
# define CONFIG_EXAMPLES_NX_BPP 32
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_BGCOLOR
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_BGCOLOR 0x007b68ee
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_BGCOLOR 0x7b5d
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_BGCOLOR ' '
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_COLOR1
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_COLOR1 0x00e6e6fa
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_COLOR1 0xe73f
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_COLOR1 '1'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_COLOR2
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_COLOR2 0x00dcdcdc
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_COLOR2 0xdefb
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_COLOR2 '2'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_TBCOLOR
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_TBCOLOR 0x00a9a9a9
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_TBCOLOR 0xad55
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_TBCOLOR 'T'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_FONTID
|
||||
# define CONFIG_EXAMPLES_NX_FONTID NXFONT_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_FONTCOLOR
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_FONTCOLOR 0x00000000
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_FONTCOLOR 0x0000
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_FONTCOLOR 'F'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT
|
||||
# define CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT 16
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
# ifdef CONFIG_DISABLE_MQUEUE
|
||||
# error "The multi-threaded example requires MQ support (CONFIG_DISABLE_MQUEUE=n)"
|
||||
# endif
|
||||
# ifdef CONFIG_DISABLE_SIGNALS
|
||||
# error "This example requires signal support (CONFIG_DISABLE_SIGNALS=n)"
|
||||
# endif
|
||||
# ifdef CONFIG_DISABLE_PTHREAD
|
||||
# error "This example requires pthread support (CONFIG_DISABLE_PTHREAD=n)"
|
||||
# endif
|
||||
# ifndef CONFIG_NX_BLOCKING
|
||||
# error "This example depends on CONFIG_NX_BLOCKING"
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_STACKSIZE
|
||||
# define CONFIG_EXAMPLES_NX_STACKSIZE 2048
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_LISTENERPRIO
|
||||
# define CONFIG_EXAMPLES_NX_LISTENERPRIO 100
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_CLIENTPRIO
|
||||
# define CONFIG_EXAMPLES_NX_CLIENTPRIO 100
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_SERVERPRIO
|
||||
# define CONFIG_EXAMPLES_NX_SERVERPRIO 120
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_NOTIFYSIGNO
|
||||
# define CONFIG_EXAMPLES_NX_NOTIFYSIGNO 4
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
# define NXEGWINDOW NXWINDOW
|
||||
#else
|
||||
# define NXEGWINDOW NXTKWINDOW
|
||||
#endif
|
||||
|
||||
#define NXTK_MAXKBDCHARS 16
|
||||
|
||||
/* 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
|
||||
****************************************************************************/
|
||||
|
||||
enum exitcode_e
|
||||
{
|
||||
NXEXIT_SUCCESS = 0,
|
||||
NXEXIT_SIGPROCMASK,
|
||||
NXEXIT_SCHEDSETPARAM,
|
||||
NXEXIT_EVENTNOTIFY,
|
||||
NXEXIT_TASKCREATE,
|
||||
NXEXIT_PTHREADCREATE,
|
||||
NXEXIT_EXTINITIALIZE,
|
||||
NXEXIT_FBINITIALIZE,
|
||||
NXEXIT_FBGETVPLANE,
|
||||
NXEXIT_LCDINITIALIZE,
|
||||
NXEXIT_LCDGETDEV,
|
||||
NXEXIT_NXOPEN,
|
||||
NXEXIT_FONTOPEN,
|
||||
NXEXIT_NXOPENTOOLBAR,
|
||||
NXEXIT_NXCONNECT,
|
||||
NXEXIT_NXSETBGCOLOR,
|
||||
NXEXIT_NXOPENWINDOW,
|
||||
NXEXIT_NXSETSIZE,
|
||||
NXEXIT_NXSETPOSITION,
|
||||
NXEXIT_NXLOWER,
|
||||
NXEXIT_NXRAISE,
|
||||
NXEXIT_NXCLOSEWINDOW,
|
||||
NXEXIT_LOSTSERVERCONN
|
||||
};
|
||||
|
||||
/* Describes one cached glyph bitmap */
|
||||
|
||||
struct nxeg_glyph_s
|
||||
{
|
||||
uint8_t code; /* Character code */
|
||||
uint8_t height; /* Height of this glyph (in rows) */
|
||||
uint8_t width; /* Width of this glyph (in pixels) */
|
||||
uint8_t stride; /* Width of the glyph row (in bytes) */
|
||||
FAR uint8_t *bitmap; /* Allocated bitmap memory */
|
||||
};
|
||||
|
||||
/* Describes on character on the display */
|
||||
|
||||
struct nxeg_bitmap_s
|
||||
{
|
||||
struct nxgl_rect_s bounds; /* Size/position of bitmap */
|
||||
FAR const struct nxeg_glyph_s *glyph; /* The cached glyph */
|
||||
};
|
||||
|
||||
/* Describes the overall state of on one window */
|
||||
|
||||
struct nxeg_state_s
|
||||
{
|
||||
uint8_t wnum; /* Window number */
|
||||
nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Window color */
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
uint8_t height; /* Max height of a font in pixels */
|
||||
uint8_t width; /* Max width of a font in pixels */
|
||||
uint8_t spwidth; /* The width of a space */
|
||||
|
||||
uint8_t nchars; /* Number of KBD chars received */
|
||||
uint8_t nglyphs; /* Number of glyphs cached */
|
||||
|
||||
struct nxeg_bitmap_s bm[NXTK_MAXKBDCHARS];
|
||||
struct nxeg_glyph_s glyph[NXTK_MAXKBDCHARS];
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/* The connecton handle */
|
||||
|
||||
extern NXHANDLE g_hnx;
|
||||
|
||||
/* NX callback vtables */
|
||||
|
||||
extern const struct nx_callback_s g_nxcb;
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
extern const struct nx_callback_s g_tbcb;
|
||||
#endif
|
||||
|
||||
/* The font handle */
|
||||
|
||||
extern NXHANDLE g_fonthandle;
|
||||
|
||||
/* The screen resolution */
|
||||
|
||||
extern nxgl_coord_t g_xres;
|
||||
extern nxgl_coord_t g_yres;
|
||||
|
||||
extern bool b_haveresolution;
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
extern bool g_connected;
|
||||
#endif
|
||||
extern sem_t g_semevent;
|
||||
|
||||
/* Colors used to fill window 1 & 2 */
|
||||
|
||||
extern nxgl_mxpixel_t g_color1[CONFIG_NX_NPLANES];
|
||||
extern nxgl_mxpixel_t g_color2[CONFIG_NX_NPLANES];
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
extern nxgl_mxpixel_t g_tbcolor[CONFIG_NX_NPLANES];
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_EXTERNINIT
|
||||
extern FAR NX_DRIVERTYPE *up_nxdrvinit(unsigned int devno);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NX) && defined(CONFIG_NX_MULTIUSER)
|
||||
extern int nx_servertask(int argc, char *argv[]);
|
||||
extern FAR void *nx_listenerthread(FAR void *arg);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
extern void nxeg_kbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, FAR void *arg);
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
extern void nxeg_tbkbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, FAR void *arg);
|
||||
#endif
|
||||
extern void nxeg_filltext(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
FAR struct nxeg_state_s *st);
|
||||
#endif
|
||||
|
||||
#endif /* __EXAMPLES_NX_NX_INTERNAL_H */
|
||||
@@ -0,0 +1,467 @@
|
||||
/****************************************************************************
|
||||
* examples/nx/nx_kbdin.c
|
||||
*
|
||||
* Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
#include "nx_internal.h"
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Select renderer -- Some additional logic would be required to support
|
||||
* pixel depths that are not directly addressable (1,2,4, and 24).
|
||||
*/
|
||||
|
||||
#if CONFIG_EXAMPLES_NX_BPP == 1
|
||||
# define RENDERER nxf_convert_1bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 2
|
||||
# define RENDERER nxf_convert_2bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 4
|
||||
# define RENDERER nxf_convert_4bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 8
|
||||
# define RENDERER nxf_convert_8bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define RENDERER nxf_convert_16bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 24
|
||||
# define RENDERER nxf_convert_24bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define RENDERER nxf_convert_32bpp
|
||||
#else
|
||||
# error "Unsupported CONFIG_EXAMPLES_NX_BPP"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_fillchar
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
FAR const struct nxeg_bitmap_s *bm)
|
||||
{
|
||||
FAR void *src = (FAR void *)bm->glyph->bitmap;
|
||||
struct nxgl_rect_s intersection;
|
||||
int ret;
|
||||
|
||||
/* Handle the special case of spaces which have no glyph bitmap */
|
||||
|
||||
if (src)
|
||||
{
|
||||
/* Get the intersection of the redraw region and the character bitmap */
|
||||
|
||||
nxgl_rectintersect(&intersection, rect, &bm->bounds);
|
||||
if (!nxgl_nullrect(&intersection))
|
||||
{
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
ret = nxtk_bitmapwindow((NXTKWINDOW)hwnd, &intersection, (FAR const void **)&src,
|
||||
&bm->bounds.pt1,
|
||||
(unsigned int)bm->glyph->stride);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_fillchar: nxtk_bitmapwindow failed: %d\n", errno);
|
||||
}
|
||||
#else
|
||||
ret = nx_bitmap((NXWINDOW)hwnd, &intersection, &src,
|
||||
&bm->bounds.pt1,
|
||||
(unsigned int)bm->glyph->stride);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_fillchar: nx_bitmapwindow failed: %d\n", errno);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_renderglyph
|
||||
****************************************************************************/
|
||||
|
||||
static inline FAR const struct nxeg_glyph_s *
|
||||
nxeg_renderglyph(FAR struct nxeg_state_s *st,
|
||||
FAR const struct nx_fontbitmap_s *bm, uint8_t ch)
|
||||
{
|
||||
FAR struct nxeg_glyph_s *glyph = NULL;
|
||||
FAR nxgl_mxpixel_t *ptr;
|
||||
#if CONFIG_EXAMPLES_NX_BPP < 8
|
||||
nxgl_mxpixel_t pixel;
|
||||
#endif
|
||||
int bmsize;
|
||||
int row;
|
||||
int col;
|
||||
int ret;
|
||||
|
||||
/* Make sure that there is room for another glyph */
|
||||
|
||||
message("nxeg_renderglyph: ch=%02x\n", ch);
|
||||
if (st->nglyphs < NXTK_MAXKBDCHARS)
|
||||
{
|
||||
/* Allocate the glyph */
|
||||
|
||||
glyph = &st->glyph[st->nglyphs];
|
||||
glyph->code = ch;
|
||||
|
||||
/* Get the dimensions of the glyph */
|
||||
|
||||
glyph->width = bm->metric.width + bm->metric.xoffset;
|
||||
glyph->height = bm->metric.height + bm->metric.yoffset;
|
||||
|
||||
/* Allocate memory to hold the glyph with its offsets */
|
||||
|
||||
glyph->stride = (glyph->width * CONFIG_EXAMPLES_NX_BPP + 7) / 8;
|
||||
bmsize = glyph->stride * glyph->height;
|
||||
glyph->bitmap = (FAR uint8_t *)malloc(bmsize);
|
||||
|
||||
if (glyph->bitmap)
|
||||
{
|
||||
/* Initialize the glyph memory to the background color */
|
||||
|
||||
#if CONFIG_EXAMPLES_NX_BPP < 8
|
||||
pixel = st->color[0];
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 1
|
||||
/* Pack 1-bit pixels into a 2-bits */
|
||||
|
||||
pixel &= 0x01;
|
||||
pixel = (pixel) << 1 |pixel;
|
||||
# endif
|
||||
# if CONFIG_EXAMPLES_NX_BPP < 4
|
||||
/* Pack 2-bit pixels into a nibble */
|
||||
|
||||
pixel &= 0x03;
|
||||
pixel = (pixel) << 2 |pixel;
|
||||
# endif
|
||||
|
||||
/* Pack 4-bit nibbles into a byte */
|
||||
|
||||
pixel &= 0x0f;
|
||||
pixel = (pixel) << 4 | pixel;
|
||||
|
||||
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
|
||||
for (row = 0; row < glyph->height; row++)
|
||||
{
|
||||
for (col = 0; col < glyph->stride; col++)
|
||||
{
|
||||
/* Transfer the packed bytes into the buffer */
|
||||
|
||||
*ptr++ = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 24
|
||||
# error "Additional logic is needed here for 24bpp support"
|
||||
|
||||
#else /* CONFIG_EXAMPLES_NX_BPP = {8,16,32} */
|
||||
|
||||
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
|
||||
for (row = 0; row < glyph->height; row++)
|
||||
{
|
||||
/* Just copy the color value into the glyph memory */
|
||||
|
||||
for (col = 0; col < glyph->width; col++)
|
||||
{
|
||||
*ptr++ = st->color[0];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then render the glyph into the allocated memory */
|
||||
|
||||
ret = RENDERER((FAR nxgl_mxpixel_t*)glyph->bitmap,
|
||||
glyph->height, glyph->width, glyph->stride,
|
||||
bm, CONFIG_EXAMPLES_NX_FONTCOLOR);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Actually, the RENDERER never returns a failure */
|
||||
|
||||
message("nxeg_renderglyph: RENDERER failed\n");
|
||||
free(glyph->bitmap);
|
||||
glyph->bitmap = NULL;
|
||||
glyph = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Make it permanent */
|
||||
|
||||
st->nglyphs++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return glyph;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_addspace
|
||||
****************************************************************************/
|
||||
|
||||
static inline FAR const struct nxeg_glyph_s *
|
||||
nxeg_addspace(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
FAR struct nxeg_glyph_s *glyph = NULL;
|
||||
|
||||
/* Make sure that there is room for another glyph */
|
||||
|
||||
if (st->nglyphs < NXTK_MAXKBDCHARS)
|
||||
{
|
||||
/* Allocate the NULL glyph */
|
||||
|
||||
glyph = &st->glyph[st->nglyphs];
|
||||
memset(glyph, 0, sizeof(struct nxeg_glyph_s));
|
||||
|
||||
glyph->code = ' ';
|
||||
glyph->width = st->spwidth;
|
||||
|
||||
st->nglyphs++;
|
||||
}
|
||||
return glyph;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_findglyph
|
||||
****************************************************************************/
|
||||
|
||||
static FAR const struct nxeg_glyph_s *
|
||||
nxeg_findglyph(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* First, try to find the glyph in the cache of pre-rendered glyphs */
|
||||
|
||||
for (i = 0; i < st->nglyphs; i++)
|
||||
{
|
||||
if (st->glyph[i].code == ch)
|
||||
{
|
||||
return &st->glyph[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_getglyph
|
||||
****************************************************************************/
|
||||
|
||||
static FAR const struct nxeg_glyph_s *
|
||||
nxeg_getglyph(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
FAR const struct nxeg_glyph_s *glyph;
|
||||
FAR const struct nx_fontbitmap_s *bm;
|
||||
|
||||
/* First, try to find the glyph in the cache of pre-rendered glyphs */
|
||||
|
||||
glyph = nxeg_findglyph(st, ch);
|
||||
if (!glyph)
|
||||
{
|
||||
/* No, it is not cached... Does the code map to a glyph? */
|
||||
|
||||
bm = nxf_getbitmap(g_fonthandle, ch);
|
||||
if (!bm)
|
||||
{
|
||||
/* No, there is no glyph for this code. Use space */
|
||||
|
||||
glyph = nxeg_findglyph(st, ' ');
|
||||
if (!glyph)
|
||||
{
|
||||
/* There isn't fake glyph for ' ' yet... create one */
|
||||
|
||||
glyph = nxeg_addspace(st, ' ');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glyph = nxeg_renderglyph(st, bm, ch);
|
||||
}
|
||||
}
|
||||
return glyph;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_addchar
|
||||
****************************************************************************/
|
||||
|
||||
static FAR const struct nxeg_bitmap_s *
|
||||
nxeg_addchar(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
FAR struct nxeg_bitmap_s *bm = NULL;
|
||||
FAR struct nxeg_bitmap_s *bmleft;
|
||||
nxgl_coord_t leftx;
|
||||
|
||||
/* Is there space for another character on the display? */
|
||||
|
||||
if (st->nchars < NXTK_MAXKBDCHARS)
|
||||
{
|
||||
/* Yes, setup the bitmap */
|
||||
|
||||
bm = &st->bm[st->nchars];
|
||||
|
||||
/* Find the matching glyph */
|
||||
|
||||
bm->glyph = nxeg_getglyph(st, ch);
|
||||
if (!bm->glyph)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Set up the bounds for the bitmap */
|
||||
|
||||
if (st->nchars <= 0)
|
||||
{
|
||||
/* The first character is one space from the left */
|
||||
|
||||
leftx = st->spwidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise, it is to the left of the preceding char */
|
||||
|
||||
bmleft = &st->bm[st->nchars-1];
|
||||
leftx = bmleft->bounds.pt2.x + 1;
|
||||
}
|
||||
|
||||
bm->bounds.pt1.x = leftx;
|
||||
bm->bounds.pt1.y = 2;
|
||||
bm->bounds.pt2.x = leftx + bm->glyph->width - 1;
|
||||
bm->bounds.pt2.y = 2 + bm->glyph->height - 1;
|
||||
|
||||
st->nchars++;
|
||||
}
|
||||
return bm;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_addchars
|
||||
****************************************************************************/
|
||||
|
||||
static inline void nxeg_addchars(NXWINDOW hwnd, FAR struct nxeg_state_s *st,
|
||||
uint8_t nch, FAR const uint8_t *ch)
|
||||
{
|
||||
FAR const struct nxeg_bitmap_s *bm;
|
||||
|
||||
while (nch--)
|
||||
{
|
||||
bm = nxeg_addchar(st, *ch++);
|
||||
if (bm)
|
||||
{
|
||||
nxeg_fillchar(hwnd, &bm->bounds, bm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_kbdin
|
||||
****************************************************************************/
|
||||
|
||||
void nxeg_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
|
||||
FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_kbdin%d: hwnd=%p nch=%d\n", st->wnum, hwnd, nch);
|
||||
nxeg_addchars(hwnd, st, nch, ch);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_tbkbdin
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
void nxeg_tbkbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard input\n");
|
||||
message("nxeg_tbkbdin%d: hwnd=%p nch=%d\n", st->wnum, hwnd, nch);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_filltext
|
||||
****************************************************************************/
|
||||
|
||||
void nxeg_filltext(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
FAR struct nxeg_state_s *st)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Fill each character on the display (Only the characters within rect
|
||||
* will actually be redrawn).
|
||||
*/
|
||||
|
||||
for (i = 0; i < st->nchars; i++)
|
||||
{
|
||||
nxeg_fillchar(hwnd, rect, &st->bm[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NX_KBD */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user