diff options
Diffstat (limited to 'apps')
196 files changed, 0 insertions, 41286 deletions
diff --git a/apps/.gitignore b/apps/.gitignore deleted file mode 100644 index 9eb5181a4..000000000 --- a/apps/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -*.a -*.bdat -*.pdat -.built -.config -.depend -.updated -builtin/builtin_list.h -builtin/builtin_proto.h -Make.dep diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt deleted file mode 100644 index 05cd6176a..000000000 --- a/apps/ChangeLog.txt +++ /dev/null @@ -1,509 +0,0 @@ -5.19 2011-03-12 Gregory Nutt <gnutt@nuttx.org> - - * Initial version of the apps/ directory was released as contributed by - Uros Platise. - -6.0 2011-03-21 Gregory Nutt <gnutt@nuttx.org> - - * README.txt -- README cosmetics - * hello/ -- hello world minor changes - * Makefile -- Makefile cosmetics (I am slowly adding the Darjeeling JVM) - * Make.defs -- New file adds common make definitions for applications. - * hello/Makefile -- Now uses new Make.defs definitions. Added README.txt. - * apps/poweroff -- New application to turn off board power. - * Moved NSH library, netutils, and examples from the nuttx/ directory to - the apps/ directory - * Moved exec_nuttapp machinery into the nuttapp/ directory. - -6.1 2011-04-10 Gregory Nutt <gnutt@nuttx.org> - - * Creation of auto-generated header files now occurs during the context - build phase. - * Added sdcard insert and eject, nsh command '?' and some code remarks - * Renamed nuttapp to namedapp - * namedapp/binfs.c -- Create a tiny filesystem that can be used - to show the internal named apps under /bin. - * Numerous fixes to build system required to support building with native - Windows toolchain. - -6.2 2011-05-06 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/nxffs: Add a test a a configuration that will be used to - verify NXFFS. - -6.3 2011-05-15 Gregory Nutt <gnutt@nuttx.org> - - * apps/interpreter: Add a directory to hold interpreters. The Pascal add- - on module now installs and builds under this directory. - * apps/interpreter/ficl: Added logic to build Ficl (the "Forth Inspired - Command Language"). See http://ficl.sourceforge.net/. - * apps/netutils/dhcpc, dhcpcd, and tftp. If these directories are included - in the configuration but CONFIG_NET_UDP is disable (which is not very wise), - then a make error occurs because tools/mkdep.sh is called with no files. - * system/free: Move Uros' custom free command from vsn/free - * system/install: Add a new install command submitted by Uros Platise. - * examples/rgmp. Add a placeholder for an RGMP build example. - RGMP is a project for running GPOS and RTOS simultaneously on - multi-processor platforms. See http://rgmp.sourceforge.net/wiki/index.php/Main_Page - for further information about RGMP. NOTE: This is an empty example - on initial check-in. - -6.4 2011-06-06 Gregory Nutt <gnutt@nuttx.org> - - * nshlib/nsh_netcmds.c: If a network device name and IP address are provided - with the ifconfig command, then this command will now set the network address. - (Contributed by Yu Qiang). - * netutils/ftpc: A library to support client-side FTP. - * examples/ftpc: A simple add-on to the NSH. From NSH, you can start - this simple FTP shell to transfer files to/from a remote FTP server. - -6.5 2011-06-21 Gregory Nutt <gnutt@nuttx.org> - - * netutils/ftpc: Simpflication and size reduction. - -6.6 2011-07-11 Gregory Nutt <gnutt@nuttx.org> - - * Make.defs, namedapp/namedapp.c: Several structural changes made to get a - clean compile under the ez80 ZDS-II toolchain (no design changes). - * apps/examples/buttons: Add a test for the new standardized button interfaces - * apps/examples/nxtext: Add another NX graphics test. This one focus on - placing text on the background while pop-up windows occur. Text should - continue to update normally with or without the popup windows present. - -6.7 2011-08-02 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/nx and nxtext: These examples can now be built as NSH - "built-in" commands. - * apps/examples/nxhello: The simplest graphics example: It just says - "Hello, World!" in the center of the display. This example can also be - built as an NSH "built-in" command. - * apps/examples/nx, ntext, and nxhello: All updated to use the new - NuttX font interfaces. - * apps/examples/nximage: Another super simple graphics example: It just puts - the NuttX logo in the center of the display. This example can also be - built as an NSH "built-in" command. - * apps/examples/usbstorage: Can now be built as two NSH "built-in" commands: - 'msconn' will connect the USB mass storage device; 'msdis' will disconnect - the USB storage device. - * apps/examples/nx*: All NX header files moved from nuttx/include/nuttx to - nuttx/include/nuttx/nx. - * apps/examples/usbstorage: Added instrumentation to monitor memory usage - to check for memory leaks in the USB storage driver. - * apps/examples/nxhello/nxhello_bkgd.c: Fix handling of allocated glyph - memory. - -6.8 2011-08-11 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/nxlines: Added a test for NX line drawing capabilities. - -6.9 2011-09-11 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/nxlines: Extend the line drawing text to include drawing - of circles. - * apps/system/i2c: Add an I2C test tool that should help to bring up I2C - devices (when it is fully functional). - * apps/nshlib/nsh_timcmds.c: Add the date command that can be used to - show or set the time (only if CONFIG_RTC is set). - -6.10 2011-10-06 Gregory Nutt <gnutt@nuttx.org> - - * apps/system/i2c: Add repitition and address auto-incrementing so that - and command can be executed numerous times. Add a new verify command - that will write to a register, read from register, and verify that - returned value. - * apps/graphics/tiff: Add a library that can be used to create TIFF files. - * apps/examples/tiff: Add a unit test for the TIFF file creation logic - * apps/examples/lcdrw: Add a test to verify if you can or can or read - data from an LCD correctly. - * apps/examples/usbterm: A USB terminal example.. more of a USB chat or - serial bridge: Data received on local console echoed via USB serial; - data received on USB serial is echoed on the local console. - * apps/examples/touchscreen: Add a simple, generic test for any - touschscreen driver. - * Makefile: The apps/ Makefile now checks for an apps/external directory - or symbolic link. If such a directory/link exists (and has a Makefile), - it will be added to the apps/ build. This allows external directories - to be included into the apps/ build by simply creating a symbolic link. - -6.11 2011-11-12 Gregory Nutt <gnutt@nuttx.org> - - (No major changes from 6.10) - -6.12 2011-12-06 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/buttons: The button test can now be executed as an NSH - built in command. - -6.13 2012-12-26 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/dhcpd: May now be built as an NSH built-in application - by setting CONFIG_NSH_BUILTIN_APPS. - * apps/netutils/dhcpd/dhcpd.c: Fix several problems using host order address - where network addresses expected (and vice versa). - * apps/examples/nettest: May now be built as an NSH built-in application - by setting CONFIG_NSH_BUILTIN_APPS. - * apps/examples/nettest: Correct some build issues with the nettest is - built for performance evaluation. - * apps/examples/adc: Add a very simple test to drive and test an ADC - driver. - * apps/examples/pwm: Add an NSH PWM command to drive and test a PWM - driver. - * apps/examples/can: Add an NSH CAN command to drive and test a CAN - driver in loopback mode. - -6.14 2012-01-15 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/buttons/main.c: The test needs to call up_buttoninit() to - properly configure the button interrupt GPIOs. - * apps/examples/pwm: Add support to test the pulse count option recently - added to the PWM interface. - -6.15 2012-02-12 Gregory Nutt <gnutt@nuttx.org> - - * apps/nshlib/nsh_serial.c and nsh_usbdev.c: If NuttX is configured to use - a USB serial console, then NSH needs to wait until the USB console is - connected and available. - * apps/examples/composite: Add a test of the USB composite device. - * apps/examples/Telnetd: Move the tiny uIP shell example from - netutils/Telnetd to examples/Telnetd. Enhanced the Telnetd daemon so that - it supports Telnetd via a TTY device driver: A new TTY device driver is - created when each new Telnet connection is created. The shell thread - is started with stdin, stdout, and stderr mapped to the TTY device. - * netutils/Telnetd: The old uIP Telnet demo is gone. In its place is a new - Telnet infrastructure. The new Telnet daemon creates sessions that are - "wrapped" as character devices and mapped to stdin, stdout, and stderr. - Now the Telnet session can be inherited by spawned tasks. - * examples/Telnetd: Add a test for the new Telnet daemon. - * examples/Telnetd/telnetd_driver.c: Move the internal socket structure from - the daemon's socket array into the driver's state data so that it will be - independent from the the Telnetd daemon. - * apps/system/readline: Moved the old nuttx/lib/stdio/lib_fgets.c here - and renamed it as readline(). The old fgets was simplied and the overloaded - readline functionality was removed. - * apps/netutils/ftpd: Add an FTPD server (does not even compile on initial - checkin). - * apps/examples/ftpd: Add a test for the FTPD server (untest on initial - check-in). - * apps/nshlib/nsh_fscmds.c: Add support for a 'dmesg' command that will - dump the system log if CONFIG_SYSLOG is selected. - -6.16 2012-03-10 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/qencoder: Add a quadrature driver test. - * apps/examples/ostest/fpu.c: Add a test to verify that FPU registers - are properly saved and restored on context switches. - * apps/system/readline/readline.c: readline() will now treat either a - backspace or a DEL character as a backspace (i.e., deleting the character - to the left of the cursor). This makes NSH less dependent on particular - keyboard mappings of the Backspace key. Submitted by Mike Smith. - * apps/examples/cdcacm: An example that illustrates how the CDC/ACM driver - may to connected and disconnected through software control. - * apps/examples/nsh/nsh_main.c: If available, call up_cxxinitialize() to - initialize all statically defined C++ classes. - * apps/nshlib: Now supports a USB serial device for NSH console I/O. This - allows NSH to be used on boards that have USB but no serial connectors. - -6.17 2012-04-14 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/can: Add conditional compilation so that the test can be - configured to only send messages or to only receive messages. This will - let the test work in other modes than simple loopback testing. - * apps/examples/hello and apps/examples/ostest: Can now be built as NSH - built-int functions. - * vsn/hello: Removed. The modified apps/examples/hello is enough "Hello, - World!" - * apps/examples/nxconsole: Add a test of the NX console device. - * apps/examples/nxconsole: The NX console example now supports running - the NuttShell (NSH) within an NX window. - * apps/system/readline: Now uses standard definitions from - include/nuttx/ascii.h and vt100.h - * Kconfig, */Kconfig: Added skeleton Kconfig files to all directories that - may need them. - -6.18 2012-05-19 Gregory Nutt <gnutt@nuttx.org> - - * Kconfig: Continued Kconfig file updates (no longer tracking on a per-file - basis in the ChangeLog) - * apps/examples/watchdog: Add a watchdog timer example. - * apps/examples/tiff: Fix wrong path used for temporary file. - * apps/examples/touchscreen: Standardize the board-specific, touchscreen - initialization interfaces. - -6.19 2012-06-15 Gregory Nutt <gnutt@nuttx.org> - - * apps/nshlib/nsh_usbdev.c: Add the capability to use an arbitrary USB - device as the console (not necessarily /dev/console). This is a useful - option because then you can still use the serial console to debug with. - * apps/nshlib/nsh_usbdev.c: User now has to press ENTER 3 times before - USB console will start. Otherwise, the USB console starts before there - is anyone at the other end to listen. - * apps/nshlib/nsh_usbdev.c and nsh_consolemain.c: Add support for the USB - capability when a USB console is used. - * apps/nshlib/nsh_fscmds.c: Add the 'mv' command - -6.20 2012-07-12 Gregory Nutt <gnutt@nuttx.org> - - * namedapp/exec_namedapp.c - Correct an error when round robin scheduling - is enabled. The priority of the new, named application was erroneously - being set to the priority of the parent thread; losing its configured - priority. Reported by Mike Smith. - -6.21 2012-08-25 Gregory Nutt <gnutt@nuttx.org> - - * apps/include/: Stylistic clean-up of all header files. - * apps/modbus and apps/include/modbus: A port of freemodbus-v1.5.0 - has been added to the NuttX apps/ source tree. - * apps/examples/modbus: A port of the freemodbus-v1.5.0 "demo" - program that will be used to verify the FreeModBus port - * apps/modbus: Don't use strerror(). It is just too big. - * apps/modbus: Add CONFIG_MB_TERMIOS. If the driver doesn't support - termios ioctls, then don't bother trying to configure the baud, parity - etc. - * apps/nshlib: If waitpid() is supported, then NSH now catches the - return value from spawned applications (provided by Mike Smith) - * apps/nshlib: Lock the scheduler while starting built-in applications - in order to eliminate race conditions (also from Mike Smith). - * apps/examples/adc, pwm, and qencoder: Add support for testing - devices with multiple ADC, PWM, and QE devices. - * apps/nshlib/nsh_mntcmds.c: Separated mount-related commands out of - nsh_fscmds.c. Extended to the mount command so that if no arguments - are provided, then the current mountpoints are enumerated. - * apps/nshlib/nsh_mntcmds.c: Add an NSH df command to list the - properties of mounted file systems. - * apps/nshlib/nsh_parse.c: Extend help command options. 'help' with - no arguments outputs a short list of commands. With -v lists all - command line details. A command name can be added to just get - help on one command. - * system/readline.c: If character input/output is interrupted by a - signal, then readline() will try the read/write again. - * apps/*/Make.defs: Numerous fixes needed to use the automated - configuration (from Richard Cochran). - -6.22 2012-09-29 Gregory Nutt <gnutt@nuttx.org> - - * apps/netutils/thttpd/thttpd_cgi.c: Missing NULL in argv[] - list (contributed by Kate). - * apps/nshlib/nsh_parse.c: CONFIG_NSH_DISABLE_WGET not CONFIG_NSH_DISABLE_GET - in one location (found by Kate). - * apps/examples/ostest/prioinherit.c: Limit the number of test - threads to no more than 3 of each priority. Bad things happen - when the existing logic tried to created several hundred test - treads! - * apps/nshlib/nsh.h: Both CONFIG_LIBC_STRERROR and CONFIG_NSH_STRERROR - must be defined to use strerror() with NSH. - * apps/examples/*/*_main.c, system/i2c/i2c_main.c, and others: Added - configuration variable CONFIG_USER_ENTRYPOINT that may be used to change - the default entry from user_start to some other symbol. Contributed by - Kate. - * apps/netutils/webserver/httpd/c: Fix a typo that as introduced in - version r4402: 'lese' instead of 'else' (Noted by Max Holtzberg). - * tools/mkfsdata.pl: The uIP web server CGI image making perl script was - moved from apps/netutils/webserver/makefsdata to nuttx/tools/mkfsdata.pl - (Part of a larger change submitted by Max Holtzberg). - * apps/netutils/webserver, apps/examples/uip, and apps/include/netutils/httpd.h: - The "canned" version of the uIP web servers content that was at - netutils/webserver/httpd_fsdata.c has been replaced with a dynamically - built configuration located at apps/examples/uip (Contributed by - Max Holtzberg). - * apps/netutils/webserver: Several inenhancements from Kate including the - ability to elide scripting and SERVER headers and the ability to map - files into memory before transferring them. - * apps/netutils/webserver: Add ability to map a URL to CGI function. - Contributed by Kate. - * apps/nshlib/nsh_mntcmds.c: The changes of 6.21 introduced holes in the - error handling: Now the number of arguments to mount can be 0 or 4. - Additional parameter checking is required to prevent mysterious errors - (submiteed by Kate). - * apps/netutils/webserver/httpd_mmap.c: Fix errors when the mmap() - length is zero (submitted by Kate). - * apps/netutils/webserver/httpd_sendfile.c: Add and option, - CONFIG_NETUTILS_HTTPD_SENDFILE to transfer files using the NuttX - sendfile() interface. - * apps/netutils/discover: A UDP network discovery utility contributed - by Max Holtzberg. - * apps/examples/discover: A test example for the UDP network discovery - utility (also contribed by Max Holtzberg). - * apps/examples/*/main.c: Too many files called main.c. Each renamed - to something unique so that they will not collide in the archive. - * apps/netutils/xmlrpc: The Embeddable Lightweight XML-RPC Server - discussed at http://www.drdobbs.com/web-development/\ - an-embeddable-lightweight-xml-rpc-server/184405364. Contributed by - Max Holtzberg. - * apps/netutils/uip_listenon.c: Logic in uip_server.c that creates - the listening socket was moved to this new file to support re-use. - Contributed by Kate. - * apps/netutils/webserver/httpd.c: The option CONFIG_NETUTILS_HTTPD_SINGLECONNECT - can now be used to limit the server to a single thread. Option - CONFIG_NETUTILS_HTTPD_TIMEOUT can be used to generate HTTP 408 errors. - Both from Kate. - * apps/netutils/webserver/httpd.c: Improvements to HTTP parser from - Kate. - * apps/netutils/webserver/httpd.c: Add support for Keep-alive connections - (from Kate). - * apps/NxWidget/Kconfig: This is a kludge. I created this NxWidgets - directory that ONLY contains Kconfig. NxWidgets does not live in - either the nuttx/ or the apps/ source trees. This kludge makes it - possible to configure NxWidgets/NxWM without too much trouble (with - the tradeoff being a kind ugly structure and some maintenance issues). - * apps/examples/Make.defs: Missing support for apps/examples/watchdog. - * apps/NxWidgets/Kconfig: Add option to turn on the memory monitor - feature of the NxWidgets/NxWM unit tests. - -6.23 2012-11-05 Gregory Nutt <gnutt@nuttx.org> - - * vsn: Moved all NSH commands from vsn/ to system/. Deleted the vsn/ - directory. - * Makefile: Change order of includes when CONFIG_NEWCONFIG=y. In - that case, namedapp must be included first so that the namedapp - context is established first. If the namedapp context is established - later, it will overwrite any existing namedapp_list.h and nameapp_proto.h - files. - * CONFIG_EXAMPLES_*: To make things consistent, changed all occurrences - of CONFIG_EXAMPLE_* to CONFIG_EXAMPLES_*. - * Kconfig: Fleshed out apps/examples/adc/Kconfig and apps/examples/wget/Kconfig. - There are still a LOT of empty, stub Kconfig files. - * Kconfig: Fleshed out apps/examples/buttons/Kconfig. There are still a LOT - of empty, stub Kconfig files. - * apps/netutils/webserver/httpd.c: Fix a bug that I introduced in - recent check-ins (Darcy Gong). - * apps/netutils/webclient/webclient.c: Fix another but that I introduced - when I was trying to add correct handling for loss of connection (Darcy Gong) - * apps/nshlib/nsh_telnetd.c: Add support for login to Telnet session via - username and password (Darcy Gong). - * apps/netutils/resolv/resolv.c (and files using the DNS resolver): Various - DNS address resolution improvements from Darcy Gong. - * apps/nshlib/nsh_netcmds.c: The ping command now passes a maximum round - trip time to uip_icmpping(). This allows pinging of hosts on complex - networks where the ICMP ECHO round trip time may exceed the ping interval. - * apps/examples/nxtext/nxtext_main.c: Fix bad conditional compilation - when CONFIG_NX_KBD is not defined. Submitted by Petteri Aimonen. - * apps/examples/nximage/nximage_main.c: Add a 5 second delay after the - NX logo is presented so that there is time for the image to be verified. - Suggested by Petteri Aimonen. - * apps/Makefile: Small change that reduces the number of shell invocations - by one (Mike Smith). - * apps/examples/elf: Test example for the ELF loader. - * apps/examples/elf: The ELF module test example appears fully functional. - * apps/netutils/json: Add a snapshot of the cJSON project. Contributed by - Darcy Gong. - * apps/examples/json: Test example for cJSON from Darcy Gong - * apps/nshlib/nsh_netinit.c: Fix static IP DNS problem (Darcy Gong) - * apps/netutils/resolv/resolv.c: DNS fixes from Darcy Gong. - * COPYING: Licensing information added. - * apps/netutils/codec and include/netutils/urldecode.h, base64.h, and md5.h: - A port of the BASE46, MD5 and URL CODEC library from Darcy Gong. - * nsnlib/nsh_codeccmd.c: NSH commands to use the CODEC library. - Contributed by Darcy Gong. - * apps/examples/wgetjson: Test example contributed by Darcy Gong - * apps/examples/cxxtest: A test for the uClibc++ library provided by - Qiang Yu and the RGMP team. - * apps/netutils/webclient, apps/netutils.codes, and apps/examples/wgetjson: - Add support for wget POST interface. Contributed by Darcy Gong. - * apps/examples/relays: A relay example contributed by Darcy Gong. - * apps/nshlib/nsh_netcmds: Add ifup and ifdown commands (from Darcy - Gong). - * apps/nshlib/nsh_netcmds: Extend the ifconfig command so that it - supports setting IP addresses, network masks, name server addresses, - and hardware address (from Darcy Gong). - -6.24 2012-12-20 Gregory Nutt <gnutt@nuttx.org> - - * apps/examples/ostest/roundrobin.c: Replace large tables with - algorithmic prime number generation. This allows the roundrobin - test to run on platforms with minimal SRAM (Freddie Chopin). - * apps/nshlib/nsh_dbgcmds.c: Add hexdump command to dump the contents - of a file (or character device) to the console Contributed by Petteri - Aimonen. - * apps/examples/modbus: Fixes from Freddie Chopin - * apps/examples/modbus/Kconfig: Kconfig logic for FreeModBus contributed - by Freddie Chopin. - * Makefile, */Makefile: Various fixes for Windows native build. Now uses - make foreach loops instead of shell loops. - * apps/examples/elf/test/*/Makefile: OSX doesn't support install -D, use - mkdir -p then install without the -D. From Mike Smith. - * apps/examples/relays/Makefile: Reduced stack requirement (Darcy Gong). - * apps/nshlib and apps/netutils/dhcpc: Extend the NSH ifconfig command plus - various DHCPC improvements(Darcy Gong). - * apps/nshlib/nsh_apps.c: Fix compilation errors when CONFIG_NSH_DISABLEBG=y. - From Freddie Chopin. - * Rename CONFIG_PCODE and CONFIG_FICL as CONFIG_INTERPRETERS_PCODE and - CONFIG_INTERPRETERS_FICL for consistency with other configuration naming. - * apps/examples/keypadtest: A keypad test example contributed by Denis - Carikli. - * apps/examples/elf and nxflat: If CONFIG_BINFMT_EXEPATH is defined, these - tests will now use a relative path to the program and expect the binfmt/ - logic to find the absolute path to the program using the PATH variable. - -6.25 2013-02-01 Gregory Nutt <gnutt@nuttx.org> - - * Makefiles: Removed dependency of distclean on clean in most top-level - files. It makes sense for 'leaf' Makefiles to have this dependency, - but it does not make sense for upper-level Makefiles. - * apps/namedapp/: Renamed to builtins in preparation for another change. - * .context: Removed the .context kludge. This caused lots of problems - when changing configurations because there is no easy way to get the - system to rebuild the context. Now, the context will be rebuilt - whenever there is a change in either .config or the Makefile. - * apps/builtin/registry: Updated new built-in registration logic to handle - cases where (1) old apps/.config is used, and (2) applications ared - removed, not just added. - * apps/examples/nettest/Makefile: Fix an error that crept in during - some of the recent, massive build system changes. - * apps/builtin/Makefile: Need to have auto-generated header files - in place early in the dependency generation phase to avoid warnings. - It is not important if they are only stubbed out header files at - this build phase. - * apps/examples/hidbkd: Now supports decoding of encoded special keys - if CONFIG_EXAMPLES_HIDKBD_ENCODED is defined. - * apps/examples/hidbkd: Add support for decoding key release events - as well. However, the USB HID keyboard drier has not yet been - updated to detect key release events. That is kind of tricky in - the USB HID keyboard report data. - * apps/examples/wlan: Remove non-functional example. - * apps/examples/ostest/vfork.c: Added a test of vfork(). - * apps/exampes/posix_spawn: Added a test of posix_spawn(). - * apps/examples/ostest: Extend signal handler test to catch - death-of-child signals (SIGCHLD). - * apps/examples/ostest/waitpid.c: Add a test for waitpid(), waitid(), - and wait(). - * builtin/binfs.c: Add hooks for dup() method (not implemented). - * builtin/exec_builtin.c, nshlib/nsh_parse.c, and nshlib/nsh_builtin.c: - NSH now supports re-direction of I/O to files (but still not from). - * builtin/binfs.c: Greatly simplified (it is going to need to be - very lightweight). Now supports open, close, and a new ioctl to recover - the builtin filename. The latter will be needed to support a binfs - binfmt. - * builtin/binfs.c: Move apps/builtin/binfs.c to fs/binfs/fs_binfs.c - CONFIG_APPS_BINDIR rename CONFIG_FS_BINFS - * apps/include/builtin.h: Some of the content of - apps/include/apps.h moved to include/nuttx/binfmt/builtin.h. - apps/include/apps.h renamed builtin.h - * apps/builtin/exec_builtins.c: Move builtin - utility functions from apps/builtin/exec_builtins.c to - binfmt/libbuiltin/libbuiltin_utils.c - * apps/nshlib/nsh_mountcmds.c: The block driver/source - argument is now optional. Many files systems do not need - a source and it is really stupid to have to enter a bogus - source parameter. - * apps/nshlib/nsh_fileapp.c: Add the ability to execute a file - from a file system using posix_spawn(). - * apps/builtin/: Extensions from Mike Smith. - * apps/examples/ftpd/Makefile: Name ftpd_start is not the name of - the entrypoint. Should be ftpd_main (from Yan T.) - * apps/netutils/telnetd/telnetd_driver: Was stuck in a loop if - recv[from]() ever returned a value <= 0. - * apps/examples/nettest and poll: Complete Kconfig files. - * apps/examples/ostest/waitpid.c: Need to use WEXITSTATUS() - to decode the correct exit status. - * apps/system/usbmonitor: A daemon that can be used to monitor USB - trace outpout. - * apps/nshlib/nsh_usbdev.c, nsh_consolemain.c, nsh_session.c, nsh_script.c: - Add support for a login script. The init.d/rcS script will be executed - once when NSH starts; the .nshrc script will be executed for each session: - Once for serial, once for each USB connection, once for each Telnet - session. - * apps/system/readline: Correct readline() return value. Was not - any returning special values when end-of-file or read errors - occur (it would return an empty string which is not very useful). - -6.26 2013-xx-xx Gregory Nutt <gnutt@nuttx.org> diff --git a/apps/Kconfig b/apps/Kconfig deleted file mode 100644 index 68c36f5a5..000000000 --- a/apps/Kconfig +++ /dev/null @@ -1,36 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -menu "Built-In Applications" -source "$APPSDIR/builtin/Kconfig" -endmenu - -menu "Examples" -source "$APPSDIR/examples/Kconfig" -endmenu - -menu "Interpreters" -source "$APPSDIR/interpreters/Kconfig" -endmenu - -menu "Network Utilities" -source "$APPSDIR/netutils/Kconfig" -endmenu - -menu "ModBus" -source "$APPSDIR/modbus/Kconfig" -endmenu - -menu "NSH Library" -source "$APPSDIR/nshlib/Kconfig" -endmenu - -menu "NxWidgets/NxWM" -source "$APPSDIR/NxWidgets/Kconfig" -endmenu - -menu "System NSH Add-Ons" -source "$APPSDIR/system/Kconfig" -endmenu diff --git a/apps/Make.defs b/apps/Make.defs deleted file mode 100644 index f7e6aa08d..000000000 --- a/apps/Make.defs +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################ -# apps/Make.defs -# Common make definitions provided to all applications -# -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -BUILTIN_REGISTRY = $(APPDIR)$(DELIM)builtin$(DELIM)registry - -ifeq ($(CONFIG_NUTTX_NEWCONFIG),y) -DEPCONFIG = $(TOPDIR)$(DELIM).config -else -DEPCONFIG = $(TOPDIR)$(DELIM).config $(APPDIR)$(DELIM).config -endif - -define REGISTER - $(Q) echo "Register: $1" - $(Q) echo "{ \"$1\", $2, $3, $4 }," > "$(BUILTIN_REGISTRY)$(DELIM)$4.bdat" - $(Q) echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$4.pdat" - $(Q) touch "$(BUILTIN_REGISTRY)$(DELIM).updated" -endef diff --git a/apps/Makefile b/apps/Makefile deleted file mode 100644 index d3078d069..000000000 --- a/apps/Makefile +++ /dev/null @@ -1,208 +0,0 @@ -############################################################################ -# apps/Makefile -# -# Copyright (C) 2011-2012 Uros Platise. All rights reserved. -# Authors: Uros Platise <uros.platise@isotel.eu> -# Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/Make.defs --include $(TOPDIR)/.config - -APPDIR = ${shell pwd} - -# Application Directories - -# CONFIGURED_APPS is the list of all configured built-in directories/built -# action. It is created by the configured appconfig file (a copy of which -# appears in this directory as .config) -# SUBDIRS is the list of all directories containing Makefiles. It is used -# only for cleaning. builtin must always be the first in the list. This -# list can be extended by the .config file as well. - -CONFIGURED_APPS = - -SUBDIRS = examples interpreters builtin nshlib system - -#SUBDIRS = examples graphics interpreters modbus builtin nshlib netutils system - -# There are two different mechanisms for obtaining the list of configured -# directories: -# -# (1) In the legacy method, these paths are all provided in the appconfig -# file that is copied to the top-level apps/ directory as .config -# (2) With the development of the NuttX configuration tool, however, the -# selected applications are now enabled by the configuration tool. -# The apps/.config file is no longer used. Instead, the set of -# configured build directories can be found by including a Make.defs -# file contained in each of the apps/subdirectories. -# -# When the NuttX configuration tools executes, it will always define the -# configure CONFIG_NUTTX_NEWCONFIG to select between these two cases. Then -# legacy appconfig files will still work but newly configuration files will -# also work. Eventually the CONFIG_NUTTX_NEWCONFIG option will be phased -# out. - -ifeq ($(CONFIG_NUTTX_NEWCONFIG),y) - -# builtin/Make.defs must be included first - -include builtin/Make.defs -include examples/Make.defs -include graphics/Make.defs -include interpreters/Make.defs -include modbus/Make.defs -include netutils/Make.defs -include nshlib/Make.defs -include system/Make.defs - -# INSTALLED_APPS is the list of currently available application directories. It -# is the same as CONFIGURED_APPS, but filtered to exclude any non-existent -# application directory. builtin is always in the list of applications to be -# built. - -INSTALLED_APPS = - -# The legacy case: - -else --include .config - -# INSTALLED_APPS is the list of currently available application directories. It -# is the same as CONFIGURED_APPS, but filtered to exclude any non-existent -# application directory. builtin is always in the list of applications to be -# built. - -INSTALLED_APPS = builtin -endif - -# Create the list of available applications (INSTALLED_APPS) - -define ADD_BUILTIN - INSTALLED_APPS += $(if $(wildcard $1$(DELIM)Makefile),$1,) -endef - -$(foreach BUILTIN, $(CONFIGURED_APPS), $(eval $(call ADD_BUILTIN,$(BUILTIN)))) - -# EXTERNAL_APPS is used to add out of tree apps to the build -INSTALLED_APPS += $(EXTERNAL_APPS) - -# 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. - -EXTERNAL_DIR := $(dir $(wildcard external$(DELIM)Makefile)) - -INSTALLED_APPS += $(EXTERNAL_DIR) -SUBDIRS += $(EXTERNAL_DIR) - -# The final build target - -BIN = libapps$(LIBEXT) - -# Build targets - -all: $(BIN) -.PHONY: $(INSTALLED_APPS) context depend clean distclean - -$(INSTALLED_APPS): - $(Q) $(MAKE) -C $@ TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" - -$(BIN): $(INSTALLED_APPS) - -context: -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - $(Q) for %%G in ($(INSTALLED_APPS)) do ( \ - $(MAKE) -C %%G TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" context \ - ) -else - $(Q) for dir in $(INSTALLED_APPS) ; do \ - $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" context ; \ - done -endif - -.depend: context Makefile $(SRCS) -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - $(Q) for %%G in ($(INSTALLED_APPS)) do ( \ - if exist %%G\.depend del /f /q %%G\.depend \ - $(MAKE) -C %%G TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" depend \ - ) -else - $(Q) for dir in $(INSTALLED_APPS) ; do \ - rm -f $$dir/.depend ; \ - $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" depend ; \ - done -endif - $(Q) touch $@ - -depend: .depend - -clean: -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - $(Q) for %%G in ($(SUBDIRS)) do ( \ - $(MAKE) -C %%G clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" \ - ) -else - $(Q) for dir in $(SUBDIRS) ; do \ - $(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \ - done -endif - $(call DELFILE, $(BIN)) - $(call CLEAN) - -distclean: -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - $(Q) for %%G in ($(SUBDIRS)) do ( \ - $(MAKE) -C %%G distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" \ - ) - $(call DELFILE, .config) - $(call DELFILE, .depend) - $(Q) ( if exist external ( \ - echo ********************************************************" \ - echo * The external directory/link must be removed manually *" \ - echo ********************************************************" \ - ) -else - $(Q) for dir in $(SUBDIRS) ; do \ - $(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \ - done - $(call DELFILE, .config) - $(call DELFILE, .depend) - $(Q) ( if [ -e external ]; then \ - echo "********************************************************"; \ - echo "* The external directory/link must be removed manually *"; \ - echo "********************************************************"; \ - fi; \ - ) -endif - - diff --git a/apps/README.txt b/apps/README.txt deleted file mode 100644 index 55accfcf6..000000000 --- a/apps/README.txt +++ /dev/null @@ -1,273 +0,0 @@ -Application Folder -================== - -Contents --------- - - General - Directory Location - Built-In Applications - NuttShell (NSH) Built-In Commands - Synchronous Built-In Commands - Application Configuration File - Example Built-In Application - Building NuttX with Board-Specific Pieces Outside the Source Tree - -General -------- -This folder provides various applications found in sub-directories. These -applications are not inherently a part of NuttX but are provided to help -you develop your own applications. The apps/ directory is a "break away" -part of the configuration that you may choose to use or not. - -Directory Location ------------------- -The default application directory used by the NuttX build should be named -apps/ (or apps-x.y/ where x.y is the NuttX version number). This apps/ -directory should appear in the directory tree at the same level as the -NuttX directory. Like: - - . - |- nuttx - | - `- apps - -If all of the above conditions are TRUE, then NuttX will be able to -find the application directory. If your application directory has a -different name or is location at a different position, then you will -have to inform the NuttX build system of that location. There are several -ways to do that: - -1) You can define CONFIG_APPS_DIR to be the full path to your application - directory in the NuttX configuration file. -2) You can provide the path to the application directory on the command line - like: make APPDIR=<path> or make CONFIG_APPS_DIR=<path> -3) When you configure NuttX using tools/configure.sh, you can provide that - path to the application directory on the configuration command line - like: ./configure.sh -a <app-dir> <board-name>/<config-name> - -Built-In Applications ---------------------- -NuttX also supports applications that can be started using a name string. -In this case, application entry points with their requirements are gathered -together in two files: - - - builtin/builtin_proto.h Entry points, prototype function - - builtin/builtin_list.h Application specific information and requirements - -The build occurs in several phases as different build targets are executed: -(1) context, (2) depend, and (3) default (all). Application information is -collected during the make context build phase. - -To execute an application function: - - exec_builtin() is defined in the nuttx/include/apps/builtin.h - -NuttShell (NSH) Built-In Commands ---------------------------------- -One use of builtin applications is to provide a way of invoking your custom -application through the NuttShell (NSH) command line. NSH will support -a seamless method invoking the applications, when the following option is -enabled in the NuttX configuration file: - - CONFIG_NSH_BUILTIN_APPS=y - -Applications registered in the apps/builtin/builtin_list.h file will then -be accessible from the NSH command line. If you type 'help' at the NSH -prompt, you will see a list of the registered commands. - -Synchronous Built-In Commands ------------------------------ -By default, built-in commands started from the NSH command line will run -asynchronously with NSH. If you want to force NSH to execute commands -then wait for the command to execute, you can enable that feature by -adding the following to the NuttX configuration file: - -CONFIG_SCHED_WAITPID=y - -The configuration option enables support for the waitpid() RTOS interface. -When that interface is enabled, NSH will use it to wait, sleeping until -the built-in command executes to completion. - -Of course, even with CONFIG_SCHED_WAITPID=y defined, specific commands -can still be forced to run asynchronously by adding the ampersand (&) -after the NSH command. - -Application Configuration File ------------------------------- -The old-style NuttX configuration uses a special configuration file is -used to configure which applications are to be included in the build. -The source for this file is configs/<board>/<configuration>/appconfig. -The existence of the appconfig file in the board configuration directory\ -is sufficient to enable building of applications. - -The appconfig file is copied into the apps/ directory as .config when -NuttX is configured. .config is included in the toplevel apps/Makefile. -As a minimum, this configuration file must define files to add to the -CONFIGURED_APPS list like: - - CONFIGURED_APPS += examples/hello system/poweroff - -The new NuttX configuration uses kconfig-frontends tools and only the -NuttX .config file. The new configuration is indicated by the existence -of the definition CONFIG_NUTTX_NEWCONFIG=y in the NuttX .config file. -If CONFIG_NUTTX_NEWCONFIG is defined, then the Makefile will: - -- Assume that there is no apps/.config file and will instead -- Include Make.defs files from each of the subdirectories. - -When an application is enabled using the kconfig-frontends tool, then -a new definition is added to the NuttX .config file. For example, if -you want to enable apps/examples/hello then the old apps/.config would -have had: - - CONFIGURED_APPS += examples/hello - -But in the new configuration there will be no apps/.config file and, -instead, the NuttX .config will have: - - CONFIG_EXAMPLES_HELLO=y - -This will select the apps/examples/hello in the following way: - -- The top-level make will include examples/Make.defs -- examples/Make.defs will set CONFIGURED_APPS += examples/hello - like this: - - ifeq ($(CONFIG_EXAMPLES_HELLO),y) - CONFIGURED_APPS += examples/hello - endif - -Thus accomplishing the same thing with no apps/.config file. - -Example Built-In Application ----------------------------- -An example application skeleton can be found under the examples/hello -sub-directory. This example shows how a builtin application can be added -to the project. One must define: - -Old configuration method: - - 1. Create sub-directory as: appname - - 2. In this directory there should be: - - - A Makefile, and - - The application source code. - - 3. The application source code should provide the entry point: - appname_main() - - 4. 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 .. - - Look at some of the other Makefiles for examples. Note the - special registration logic needed for the context: target - - 5. Add the to the application to the CONFIGIURED_APPS in the - apps/.config file: - - CONFIGURED_APPS += appname - -New Configuration Method: - - 1. Create sub-directory as: appname - - 2. In this directory there should be: - - - A Make.defs file that would be included by the apps/Makefile - - A Kconfig file that would be used by the configuration tool (see - misc/tools/kconfig-language.txt). This Kconfig file should be - included by the apps/Kconfig file - - A Makefile, and - - The application source code. - - 3. The application source code should provide the entry point: - appname_main() - - 4. 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 .. - - 4b. The Make.defs file should include a line like: - - ifeq ($(CONFIG_APPNAME),y) - CONFIGURED_APPS += appname - endif - -Building NuttX with Board-Specific Pieces Outside the Source Tree ------------------------------------------------------------------ - -Q: Has anyone come up with a tidy way to build NuttX with board- - specific pieces outside the source tree? -A: Here are four: - - 1) There is a make target called 'make export'. It will build - NuttX, then bundle all of the header files, libaries, startup - objects, and other build components into a .zip file. You - can can move that .zip file into any build environment you - want. You even build NuttX under a DOS CMD window. - - This make target is documented in the top level nuttx/README.txt. - - 2) You can replace the entire apps/ directory. If there is - nothing in the apps/ directory that you need, you can define - CONFIG_APPS_DIR in your .config file so that it points to a - different, custom application directory. - - You can copy any pieces that you like from the old apps/directory - to your custom apps directory as necessary. - - This is documented in NuttX/configs/README.txt and - nuttx/Documentation/NuttxPortingGuide.html (Online at - http://nuttx.sourceforge.net/NuttxPortingGuide.html#apndxconfigs - under Build options). And in the apps/README.txt file. - - 3) If you like the random collection of stuff in the apps/ directory - but just want to expand the existing components with your own, - external sub-directory then there is an easy way to that too: - You just create the sympolic link at apps/external that - redirects to your application sub-directory. The apps/Makefile - will always automatically check for the existence of an - apps/external directory and if it exists, it will automatically - incorporate it into the build. - - This feature of the apps/Makefile is documented only here. - - You can, for example, create a script called install.sh that - installs a custom application, configuration, and board specific - directory: - - a) Copy 'MyBoard' directory to configs/MyBoard. - b) Add a symbolic link to MyApplication at apps/external - c) Configure NuttX (usually by: - - tools/configure.sh MyBoard/MyConfiguration - - or simply by copying defconfig->nutt/.config, - setenv.sh->nuttx/setenv.sh, Make.defs->nuttx/Make.defs, - appconfig->apps/.config - - Using the 'external' link makes it especially easy to add a - 'built-in' application an existing configuration. - - 4) Add any link to apps/ - - a) Add symbolic links apps/ to as many other directories as you - want. - b) Then just add the (relative) paths to the links in your - appconfig file (that becomes the apps/.config file). - - That is basically the same as my option #3 but doesn't use the - magic 'external' link. The toplevel apps/Makefile will always - to build whatever in finds in the apps/.config file (plus the - external link if present). diff --git a/apps/_dontignore b/apps/_dontignore deleted file mode 100644 index e69de29bb..000000000 --- a/apps/_dontignore +++ /dev/null diff --git a/apps/builtin/Kconfig b/apps/builtin/Kconfig deleted file mode 100644 index c3371d708..000000000 --- a/apps/builtin/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -if BUILTIN - -config BUILTIN_PROXY_STACKSIZE - int "Builtin Proxy Stack Size" - default 1024 - ---help--- - If exec_builtin uses I/O redirection options, then it will require - an intermediary/proxy task to muck with the file descriptors. This - configuration item specifies the stack size used for the proxy. Default: - 1024 bytes. - -endif diff --git a/apps/builtin/Make.defs b/apps/builtin/Make.defs deleted file mode 100644 index ab6292cc3..000000000 --- a/apps/builtin/Make.defs +++ /dev/null @@ -1,40 +0,0 @@ -############################################################################ -# apps/builtin/Make.defs -# Adds selected applications to apps/ build -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -ifeq ($(CONFIG_BUILTIN),y) -CONFIGURED_APPS += builtin -endif - diff --git a/apps/builtin/Makefile b/apps/builtin/Makefile deleted file mode 100644 index f89532871..000000000 --- a/apps/builtin/Makefile +++ /dev/null @@ -1,130 +0,0 @@ -############################################################################ -# apps/builtin/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Source and object files - -ASRCS = -CSRCS = builtin.c builtin_list.c exec_builtin.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\libapps$(LIBEXT) -else - BIN = ../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . -VPATH = - -# Build Targets - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -registry$(DELIM).updated: - $(V) $(MAKE) -C registry .updated TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" - -builtin_list.h: registry$(DELIM).updated - $(call DELFILE, builtin_list.h) - $(Q) touch builtin_list.h -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - $(Q) for /f %%G in ('dir /b registry\*.bdat`) do ( type registry\%%G >> builtin_list.h ) -else - $(Q) ( \ - filelist=`ls registry/*.bdat 2>/dev/null || echo ""`; \ - for file in $$filelist; \ - do cat $$file >> builtin_list.h; \ - done; \ - ) -endif - -builtin_proto.h: registry$(DELIM).updated - $(call DELFILE, builtin_proto.h) - $(Q) touch builtin_proto.h -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - $(Q) for /f %%G in ('dir /b registry\*.pdat`) do ( type registry\%%G >> builtin_proto.h ) -else - $(Q) ( \ - filelist=`ls registry/*.pdat 2>/dev/null || echo ""`; \ - for file in $$filelist; \ - do cat $$file >> builtin_proto.h; \ - done; \ - ) -endif - -.built: builtin_list.h builtin_proto.h $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -context: - $(Q) $(MAKE) -C registry context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" - -.depend: Makefile $(SRCS) builtin_list.h builtin_proto.h - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(Q) $(MAKE) -C registry clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(Q) $(MAKE) -C registry distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - $(call DELFILE, builtin_list.h) - $(call DELFILE, builtin_proto.h) - --include Make.dep diff --git a/apps/builtin/builtin.c b/apps/builtin/builtin.c deleted file mode 100644 index d26f0a044..000000000 --- a/apps/builtin/builtin.c +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * apps/builtin/builtin.c - * - * Copyright (C) 2011 Uros Platise. All rights reserved. - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Authors: Uros Platise <uros.platise@isotel.eu> - * Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <nuttx/binfmt/builtin.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern const struct builtin_s g_builtins[]; -extern const int g_builtin_count; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -FAR const struct builtin_s *builtin_for_index(int index) -{ - if (index < g_builtin_count) - { - return &g_builtins[index]; - } - return NULL; -} diff --git a/apps/builtin/builtin_list.c b/apps/builtin/builtin_list.c deleted file mode 100644 index a5556bf54..000000000 --- a/apps/builtin/builtin_list.c +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * apps/builtin/builtin_list.c - * - * Copyright (C) 2011 Uros Platise. All rights reserved. - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Authors: Uros Platise <uros.platise@isotel.eu> - * Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <nuttx/binfmt/builtin.h> - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#include "builtin_proto.h" - -const struct builtin_s g_builtins[] = -{ -# include "builtin_list.h" - { NULL, 0, 0, 0 } -}; - -const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - diff --git a/apps/builtin/exec_builtin.c b/apps/builtin/exec_builtin.c deleted file mode 100644 index 5d3a1c08a..000000000 --- a/apps/builtin/exec_builtin.c +++ /dev/null @@ -1,467 +0,0 @@ -/**************************************************************************** - * apps/builtin/exec_builtin.c - * - * Originally by: - * - * Copyright (C) 2011 Uros Platise. All rights reserved. - * Author: Uros Platise <uros.platise@isotel.eu> - * - * With subsequent updates, modifications, and general maintenance by: - * - * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/wait.h> -#include <sched.h> -#include <string.h> -#include <fcntl.h> -#include <semaphore.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/binfmt/builtin.h> -#include <apps/builtin.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_BUILTIN_PROXY_STACKSIZE -# define CONFIG_BUILTIN_PROXY_STACKSIZE 1024 -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct builtin_parms_s -{ - /* Input values */ - - FAR const char *redirfile; - FAR const char **argv; - int oflags; - int index; - - /* Returned values */ - - pid_t result; - int errcode; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static sem_t g_builtin_parmsem = SEM_INITIALIZER(1); -#ifndef CONFIG_SCHED_WAITPID -static sem_t g_builtin_execsem = SEM_INITIALIZER(0); -#endif -static struct builtin_parms_s g_builtin_parms; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: bultin_semtake and builtin_semgive - * - * Description: - * Give and take semaphores - * - * Input Parameters: - * - * sem - The semaphore to act on. - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void bultin_semtake(FAR sem_t *sem) -{ - int ret; - - do - { - ret = sem_wait(sem); - ASSERT(ret == 0 || get_errno() == EINTR); - } - while (ret != 0); -} - -#define builtin_semgive(sem) sem_post(sem) - -/**************************************************************************** - * Name: builtin_taskcreate - * - * Description: - * Execute the builtin task - * - * Returned Value: - * On success, the task ID of the builtin task is returned; On failure, -1 - * (ERROR) is returned and the errno is set appropriately. - * - ****************************************************************************/ - -static int builtin_taskcreate(int index, FAR const char **argv) -{ - FAR const struct builtin_s *b; - int ret; - - b = builtin_for_index(index); - - if (b == NULL) - { - set_errno(ENOENT); - return ERROR; - } - - /* Disable pre-emption. This means that although we start the builtin - * application here, it will not actually run until pre-emption is - * re-enabled below. - */ - - sched_lock(); - - /* Start the builtin application task */ - - ret = TASK_CREATE(b->name, b->priority, b->stacksize, b->main, - (argv) ? &argv[1] : (FAR const char **)NULL); - - /* If robin robin scheduling is enabled, then set the scheduling policy - * of the new task to SCHED_RR before it has a chance to run. - */ - -#if CONFIG_RR_INTERVAL > 0 - if (ret > 0) - { - struct sched_param param; - - /* Pre-emption is disabled so the task creation and the - * following operation will be atomic. The priority of the - * new task cannot yet have changed from its initial value. - */ - - param.sched_priority = b->priority; - (void)sched_setscheduler(ret, SCHED_RR, ¶m); - } -#endif - - /* Now let the builtin application run */ - - sched_unlock(); - - /* Return the task ID of the new task if the task was sucessfully - * started. Otherwise, ret will be ERROR (and the errno value will - * be set appropriately). - */ - - return ret; -} - -/**************************************************************************** - * Name: builtin_proxy - * - * Description: - * Perform output redirection, then execute the builtin task. - * - * Input Parameters: - * Standard task start-up parameters - * - * Returned Value: - * Standard task return value. - * - ****************************************************************************/ - -static int builtin_proxy(int argc, char *argv[]) -{ - int fd; - int ret = ERROR; - - /* Open the output file for redirection */ - - svdbg("Open'ing redirfile=%s oflags=%04x mode=0644\n", - g_builtin_parms.redirfile, g_builtin_parms.oflags); - - fd = open(g_builtin_parms.redirfile, g_builtin_parms.oflags, 0644); - if (fd < 0) - { - /* Remember the errno value. ret is already set to ERROR */ - - g_builtin_parms.errcode = get_errno(); - sdbg("ERROR: open of %s failed: %d\n", - g_builtin_parms.redirfile, g_builtin_parms.errcode); - } - - /* Does the return file descriptor happen to match the required file - * desciptor number? - */ - - else if (fd != 1) - { - /* No.. dup2 to get the correct file number */ - - svdbg("Dup'ing %d->1\n", fd); - - ret = dup2(fd, 1); - if (ret < 0) - { - g_builtin_parms.errcode = get_errno(); - sdbg("ERROR: dup2 failed: %d\n", g_builtin_parms.errcode); - } - - svdbg("Closing fd=%d\n", fd); - close(fd); - } - - /* Was the setup successful? */ - - if (ret == OK) - { - /* Yes.. Start the task. On success, the task ID of the builtin task - * is returned; On failure, -1 (ERROR) is returned and the errno - * is set appropriately. - */ - - ret = builtin_taskcreate(g_builtin_parms.index, g_builtin_parms.argv); - if (ret < 0) - { - g_builtin_parms.errcode = get_errno(); - sdbg("ERROR: builtin_taskcreate failed: %d\n", - g_builtin_parms.errcode); - } - } - - /* NOTE: There is a logical error here if CONFIG_SCHED_HAVE_PARENT is - * defined: The new task is the child of this proxy task, not the - * original caller. As a consequence, operations like waitpid() will - * fail on the caller's thread. - */ - - /* Post the semaphore to inform the parent task that we have completed - * what we need to do. - */ - - g_builtin_parms.result = ret; -#ifndef CONFIG_SCHED_WAITPID - builtin_semgive(&g_builtin_execsem); -#endif - return 0; -} - -/**************************************************************************** - * Name: builtin_startproxy - * - * Description: - * Perform output redirection, then execute the builtin task. - * - * Input Parameters: - * Standard task start-up parameters - * - * Returned Value: - * On success, the task ID of the builtin task is returned; On failure, -1 - * (ERROR) is returned and the errno is set appropriately. - * - ****************************************************************************/ - -static inline int builtin_startproxy(int index, FAR const char **argv, - FAR const char *redirfile, int oflags) -{ - struct sched_param param; - pid_t proxy; - int errcode = OK; -#ifdef CONFIG_SCHED_WAITPID - int status; -#endif - int ret; - - svdbg("index=%d argv=%p redirfile=%s oflags=%04x\n", - index, argv, redirfile, oflags); - - /* We will have to go through an intermediary/proxy task in order to - * perform the I/O redirection. This would be a natural place to fork(). - * However, true fork() behavior requires an MMU and most implementations - * of vfork() are not capable of these operations. - * - * Even without fork(), we can still do the job, but parameter passing is - * messier. Unfortunately, there is no (clean) way to pass binary values - * as a task parameter, so we will use a semaphore-protected global - * structure. - */ - - /* Get exclusive access to the global parameter structure */ - - bultin_semtake(&g_builtin_parmsem); - - /* Populate the parameter structure */ - - g_builtin_parms.redirfile = redirfile; - g_builtin_parms.argv = argv; - g_builtin_parms.result = ERROR; - g_builtin_parms.oflags = oflags; - g_builtin_parms.index = index; - - /* Get the priority of this (parent) task */ - - ret = sched_getparam(0, ¶m); - if (ret < 0) - { - errcode = get_errno(); - sdbg("ERROR: sched_getparam failed: %d\n", errcode); - goto errout_with_sem; - } - - /* Disable pre-emption so that the proxy does not run until we waitpid - * is called. This is probably unnecessary since the builtin_proxy has - * the same priority as this thread; it should be schedule behind this - * task in the ready-to-run list. - */ - -#ifdef CONFIG_SCHED_WAITPID - sched_lock(); -#endif - - /* Start the intermediary/proxy task at the same priority as the parent task. */ - - proxy = TASK_CREATE("builtin_proxy", param.sched_priority, - CONFIG_BUILTIN_PROXY_STACKSIZE, (main_t)builtin_proxy, - (FAR const char **)NULL); - if (proxy < 0) - { - errcode = get_errno(); - sdbg("ERROR: Failed to start builtin_proxy: %d\n", errcode); - goto errout_with_lock; - } - - /* Wait for the proxy to complete its job. We could use waitpid() - * for this. - */ - -#ifdef CONFIG_SCHED_WAITPID - ret = waitpid(proxy, &status, 0); - if (ret < 0) - { - sdbg("ERROR: waitpid() failed: %d\n", get_errno()); - goto errout_with_lock; - } -#else - bultin_semtake(&g_builtin_execsem); -#endif - - /* Get the result and relinquish our access to the parameter structure */ - - set_errno(g_builtin_parms.errcode); - builtin_semgive(&g_builtin_parmsem); - return g_builtin_parms.result; - -errout_with_lock: -#ifdef CONFIG_SCHED_WAITPID - sched_unlock(); -#endif - -errout_with_sem: - set_errno(errcode); - builtin_semgive(&g_builtin_parmsem); - return ERROR; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: exec_builtin - * - * Description: - * Executes builtin applications registered during 'make context' time. - * New application is run in a separate task context (and thread). - * - * Input Parameter: - * filename - Name of the linked-in binary to be started. - * argv - Argument list - * redirfile - If output if redirected, this parameter will be non-NULL - * and will provide the full path to the file. - * oflags - If output is redirected, this parameter will provide the - * open flags to use. This will support file replacement - * of appending to an existing file. - * - * Returned Value: - * This is an end-user function, so it follows the normal convention: - * Returns the PID of the exec'ed module. On failure, it.returns - * -1 (ERROR) and sets errno appropriately. - * - ****************************************************************************/ - -int exec_builtin(FAR const char *appname, FAR const char **argv, - FAR const char *redirfile, int oflags) -{ - int index; - int ret = ERROR; - - /* Verify that an application with this name exists */ - - index = builtin_isavail(appname); - if (index >= 0) - { - /* Is output being redirected? */ - - if (redirfile) - { - ret = builtin_startproxy(index, argv, redirfile, oflags); - } - else - { - /* Start the builtin application task */ - - ret = builtin_taskcreate(index, argv); - } - } - - - /* Return the task ID of the new task if the task was sucessfully - * started. Otherwise, ret will be ERROR (and the errno value will - * be set appropriately). - */ - - return ret; -} diff --git a/apps/builtin/registry/Makefile b/apps/builtin/registry/Makefile deleted file mode 100644 index 4ecd5da9f..000000000 --- a/apps/builtin/registry/Makefile +++ /dev/null @@ -1,61 +0,0 @@ -############################################################################ -# apps/builtin/registry/Makefile -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# NSH Library - -all: -.PHONY: context depend clean distclean - -.updated: $(DEPCONFIG) - $(call DELFILE, *.bdat) - $(call DELFILE, *.pdat) - $(Q) touch .updated - -# This must run before any other context target - -context: .updated - -depend: - -clean: - $(call CLEAN) - -distclean: clean - $(call DELFILE, *.bdat) - $(call DELFILE, *.pdat) - $(call DELFILE, .updated) diff --git a/apps/doxygen_mainpage.dox b/apps/doxygen_mainpage.dox deleted file mode 100644 index 98b0eb690..000000000 --- a/apps/doxygen_mainpage.dox +++ /dev/null @@ -1,49 +0,0 @@ -/** @mainpage PX4 Codebase Overview - -PX4 is an open-source, open-hardware project aiming at providing a high-end autopilot to the academic, hobby and industrial communities (BSD licensed). For full documentation, refer to the official project website: - -https://pixhawk.ethz.ch/px4/ - -Please follow the toolchain installation instructions at https://pixhawk.ethz.ch/px4/dev/px4_quickstart. - -*/ - -/** -@defgroup topics uORB Topics - -Small and efficient object request broker. - -The micro object request broker (uORB) is a very efficient implementation of an object -request broker following the publisher/subscriber design pattern. - -It is in detail described here: -https://pixhawk.ethz.ch/px4/dev/shared_object_communication -*/ - -/** -@defgroup apps Onboard Applications - -This is the list of the main functions of all onboard applications. The use of these -applications is documented here: -https://pixhawk.ethz.ch/px4/users/apps/start - -Developer documentation of individual applications and the uORB data sharing mechanisms -are described here: -https://pixhawk.ethz.ch/px4/dev/apps/start - -*/ - -/** -@defgroup attitude_estimation Attitude Estimation - -*/ - -/** -@defgroup position_estimation Position Estimation - -*/ - -/** - * @addtogroup topics - * @{ - */
\ No newline at end of file diff --git a/apps/examples/Kconfig b/apps/examples/Kconfig deleted file mode 100644 index ec0a97dd4..000000000 --- a/apps/examples/Kconfig +++ /dev/null @@ -1,62 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -source "$APPSDIR/examples/adc/Kconfig" -source "$APPSDIR/examples/buttons/Kconfig" -source "$APPSDIR/examples/can/Kconfig" -source "$APPSDIR/examples/cdcacm/Kconfig" -source "$APPSDIR/examples/composite/Kconfig" -source "$APPSDIR/examples/cxxtest/Kconfig" -source "$APPSDIR/examples/dhcpd/Kconfig" -source "$APPSDIR/examples/elf/Kconfig" -source "$APPSDIR/examples/ftpc/Kconfig" -source "$APPSDIR/examples/ftpd/Kconfig" -source "$APPSDIR/examples/hello/Kconfig" -source "$APPSDIR/examples/helloxx/Kconfig" -source "$APPSDIR/examples/json/Kconfig" -source "$APPSDIR/examples/hidkbd/Kconfig" -source "$APPSDIR/examples/keypadtest/Kconfig" -source "$APPSDIR/examples/igmp/Kconfig" -source "$APPSDIR/examples/lcdrw/Kconfig" -source "$APPSDIR/examples/mm/Kconfig" -source "$APPSDIR/examples/mount/Kconfig" -source "$APPSDIR/examples/modbus/Kconfig" -source "$APPSDIR/examples/nettest/Kconfig" -source "$APPSDIR/examples/nsh/Kconfig" -source "$APPSDIR/examples/null/Kconfig" -source "$APPSDIR/examples/nx/Kconfig" -source "$APPSDIR/examples/nxconsole/Kconfig" -source "$APPSDIR/examples/nxffs/Kconfig" -source "$APPSDIR/examples/nxflat/Kconfig" -source "$APPSDIR/examples/nxhello/Kconfig" -source "$APPSDIR/examples/nximage/Kconfig" -source "$APPSDIR/examples/nxlines/Kconfig" -source "$APPSDIR/examples/nxtext/Kconfig" -source "$APPSDIR/examples/ostest/Kconfig" -source "$APPSDIR/examples/pashello/Kconfig" -source "$APPSDIR/examples/pipe/Kconfig" -source "$APPSDIR/examples/poll/Kconfig" -source "$APPSDIR/examples/pwm/Kconfig" -source "$APPSDIR/examples/posix_spawn/Kconfig" -source "$APPSDIR/examples/qencoder/Kconfig" -source "$APPSDIR/examples/relays/Kconfig" -source "$APPSDIR/examples/rgmp/Kconfig" -source "$APPSDIR/examples/romfs/Kconfig" -source "$APPSDIR/examples/sendmail/Kconfig" -source "$APPSDIR/examples/serloop/Kconfig" -source "$APPSDIR/examples/telnetd/Kconfig" -source "$APPSDIR/examples/thttpd/Kconfig" -source "$APPSDIR/examples/tiff/Kconfig" -source "$APPSDIR/examples/touchscreen/Kconfig" -source "$APPSDIR/examples/udp/Kconfig" -source "$APPSDIR/examples/discover/Kconfig" -source "$APPSDIR/examples/uip/Kconfig" -source "$APPSDIR/examples/usbserial/Kconfig" -source "$APPSDIR/examples/usbstorage/Kconfig" -source "$APPSDIR/examples/usbterm/Kconfig" -source "$APPSDIR/examples/watchdog/Kconfig" -source "$APPSDIR/examples/wget/Kconfig" -source "$APPSDIR/examples/wgetjson/Kconfig" -source "$APPSDIR/examples/xmlrpc/Kconfig" diff --git a/apps/examples/Make.defs b/apps/examples/Make.defs deleted file mode 100644 index 68d4d4340..000000000 --- a/apps/examples/Make.defs +++ /dev/null @@ -1,263 +0,0 @@ -############################################################################ -# apps/examples/Make.defs -# Adds selected applications to apps/ build -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -ifeq ($(CONFIG_EXAMPLES_ADC),y) -CONFIGURED_APPS += examples/adc -endif - -ifeq ($(CONFIG_EXAMPLES_BUTTONS),y) -CONFIGURED_APPS += examples/buttons -endif - -ifeq ($(CONFIG_EXAMPLES_CAN),y) -CONFIGURED_APPS += examples/can -endif - -ifeq ($(CONFIG_EXAMPLES_CDCACM),y) -CONFIGURED_APPS += examples/cdcacm -endif - -ifeq ($(CONFIG_EXAMPLES_COMPOSITE),y) -CONFIGURED_APPS += examples/composite -endif - -ifeq ($(CONFIG_EXAMPLES_CXXTEST),y) -CONFIGURED_APPS += examples/cxxtest -endif - -ifeq ($(CONFIG_EXAMPLES_DHCPD),y) -CONFIGURED_APPS += examples/dhcpd -endif - -ifeq ($(CONFIG_EXAMPLES_DISCOVER),y) -CONFIGURED_APPS += examples/discover -endif - -ifeq ($(CONFIG_EXAMPLES_ELF),y) -CONFIGURED_APPS += examples/elf -endif - -ifeq ($(CONFIG_EXAMPLES_FTPC),y) -CONFIGURED_APPS += examples/ftpc -endif - -ifeq ($(CONFIG_EXAMPLES_FTPD),y) -CONFIGURED_APPS += examples/ftpd -endif - -ifeq ($(CONFIG_EXAMPLES_HELLO),y) -CONFIGURED_APPS += examples/hello -endif - -ifeq ($(CONFIG_EXAMPLES_HELLOXX),y) -CONFIGURED_APPS += examples/helloxx -endif - -ifeq ($(CONFIG_EXAMPLES_HIDKBD),y) -CONFIGURED_APPS += examples/hidkbd -endif - -ifeq ($(CONFIG_EXAMPLES_IGMP),y) -CONFIGURED_APPS += examples/igmp -endif - -ifeq ($(CONFIG_EXAMPLES_JSON),y) -CONFIGURED_APPS += examples/json -endif - -ifeq ($(CONFIG_EXAMPLES_KEYPADTEST),y) -CONFIGURED_APPS += examples/keypadtest -endif - -ifeq ($(CONFIG_EXAMPLES_LCDRW),y) -CONFIGURED_APPS += examples/lcdrw -endif - -ifeq ($(CONFIG_EXAMPLES_MM),y) -CONFIGURED_APPS += examples/mm -endif - -ifeq ($(CONFIG_EXAMPLES_MODBUS),y) -CONFIGURED_APPS += examples/modbus -endif - -ifeq ($(CONFIG_EXAMPLES_MOUNT),y) -CONFIGURED_APPS += examples/mount -endif - -ifeq ($(CONFIG_EXAMPLES_NETTEST),y) -CONFIGURED_APPS += examples/nettest -endif - -ifeq ($(CONFIG_EXAMPLES_NSH),y) -CONFIGURED_APPS += examples/nsh -endif - -ifeq ($(CONFIG_EXAMPLES_NULL),y) -CONFIGURED_APPS += examples/null -endif - -ifeq ($(CONFIG_EXAMPLES_NX),y) -CONFIGURED_APPS += examples/nx -endif - -ifeq ($(CONFIG_EXAMPLES_NXCONSOLE),y) -CONFIGURED_APPS += examples/nxconsole -endif - -ifeq ($(CONFIG_EXAMPLES_NXFFS),y) -CONFIGURED_APPS += examples/nxffs -endif - -ifeq ($(CONFIG_EXAMPLES_NXFLAT),y) -CONFIGURED_APPS += examples/nxflat -endif - -ifeq ($(CONFIG_EXAMPLES_NXHELLO),y) -CONFIGURED_APPS += examples/nxhello -endif - -ifeq ($(CONFIG_EXAMPLES_NXIMAGE),y) -CONFIGURED_APPS += examples/nximage -endif - -ifeq ($(CONFIG_EXAMPLES_NXLINES),y) -CONFIGURED_APPS += examples/nxlines -endif - -ifeq ($(CONFIG_EXAMPLES_NXTEXT),y) -CONFIGURED_APPS += examples/nxtext -endif - -ifeq ($(CONFIG_EXAMPLES_OSTEST),y) -CONFIGURED_APPS += examples/ostest -endif - -ifeq ($(CONFIG_EXAMPLES_PASHELLO),y) -CONFIGURED_APPS += examples/pashello -endif - -ifeq ($(CONFIG_EXAMPLES_PIPE),y) -CONFIGURED_APPS += examples/pipe -endif - -ifeq ($(CONFIG_EXAMPLES_POLL),y) -CONFIGURED_APPS += examples/poll -endif - -ifeq ($(CONFIG_EXAMPLES_PWM),y) -CONFIGURED_APPS += examples/pwm -endif - -ifeq ($(CONFIG_EXAMPLES_POSIXSPAWN),y) -CONFIGURED_APPS += examples/posix_spawn -endif - -ifeq ($(CONFIG_EXAMPLES_QENCODER),y) -CONFIGURED_APPS += examples/qencoder -endif - -ifeq ($(CONFIG_EXAMPLES_RELAYS),y) -CONFIGURED_APPS += examples/relays -endif - -ifeq ($(CONFIG_EXAMPLES_RGMP),y) -CONFIGURED_APPS += examples/rgmp -endif - -ifeq ($(CONFIG_EXAMPLES_ROMFS),y) -CONFIGURED_APPS += examples/romfs -endif - -ifeq ($(CONFIG_EXAMPLES_SENDMAIL),y) -CONFIGURED_APPS += examples/sendmail -endif - -ifeq ($(CONFIG_EXAMPLES_SERLOOP),y) -CONFIGURED_APPS += examples/serloop -endif - -ifeq ($(CONFIG_EXAMPLES_TELNETD),y) -CONFIGURED_APPS += examples/telnetd -endif - -ifeq ($(CONFIG_EXAMPLES_THTTPD),y) -CONFIGURED_APPS += examples/thttpd -endif - -ifeq ($(CONFIG_EXAMPLES_TIFF),y) -CONFIGURED_APPS += examples/tiff -endif - -ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN),y) -CONFIGURED_APPS += examples/touchscreen -endif - -ifeq ($(CONFIG_EXAMPLES_UDP),y) -CONFIGURED_APPS += examples/udp -endif - -ifeq ($(CONFIG_EXAMPLES_UIP),y) -CONFIGURED_APPS += examples/uip -endif - -ifeq ($(CONFIG_EXAMPLES_USBSERIAL),y) -CONFIGURED_APPS += examples/usbserial -endif - -ifeq ($(CONFIG_EXAMPLES_USBMSC),y) -CONFIGURED_APPS += examples/usbmsc -endif - -ifeq ($(CONFIG_EXAMPLES_USBTERM),y) -CONFIGURED_APPS += examples/usbterm -endif - -ifeq ($(CONFIG_EXAMPLES_WATCHDOG),y) -CONFIGURED_APPS += examples/watchdog -endif - -ifeq ($(CONFIG_EXAMPLES_WGET),y) -CONFIGURED_APPS += examples/wget -endif - -ifeq ($(CONFIG_EXAMPLES_WGETJSON),y) -CONFIGURED_APPS += examples/wgetjson -endif - -ifeq ($(CONFIG_EXAMPLES_XMLRPC),y) -CONFIGURED_APPS += examples/xmlrpc -endif diff --git a/apps/examples/Makefile b/apps/examples/Makefile deleted file mode 100644 index 6b614b1aa..000000000 --- a/apps/examples/Makefile +++ /dev/null @@ -1,129 +0,0 @@ -############################################################################ -# apps/examples/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config # Current configuration - -# Sub-directories - -SUBDIRS = adc can cdcacm nsh - -#SUBDIRS = adc buttons can cdcacm composite cxxtest dhcpd discover elf ftpc -#SUBDIRS += ftpd hello helloxx hidkbd igmp json keypadtest lcdrw mm modbus mount -#SUBDIRS += nettest nsh null nx nxconsole nxffs nxflat nxhello nximage -#SUBDIRS += nxlines nxtext ostest pashello pipe poll pwm posix_spawn qencoder -#SUBDIRS += relays rgmp romfs serloop telnetd thttpd tiff touchscreen udp uip -#SUBDIRS += usbserial sendmail usbstorage usbterm watchdog wget wgetjson - -# Sub-directories that might need context setup. Directories may need -# context setup for a variety of reasons, but the most common is because -# the example may be built as an NSH built-in function. -# -# Directories that may be built as NSH built-in functions may have their -# own configuration setting (like CONFIG_EXAMPLES_HELLOXX_BUILTIN), but -# many only depend on the generic CONFIG_NSH_BUILTIN_APPS setting. And -# there a few which an ONLY be built as NSH built-in applications; these -# are included in the list unconditionally. - -CNTXTDIRS = pwm - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) - -CNTXTDIRS += adc can cdcacm - -#CNTXTDIRS += adc can cdcacm composite cxxtest dhcpd discover ftpd hello json -#CNTXTDIRS += keypadtestmodbus nettest nxlines relays qencoder telnetd watchdog -#CNTXTDIRS += wgetjson -endif - -ifeq ($(CONFIG_EXAMPLES_HELLOXX_BUILTIN),y) -CNTXTDIRS += helloxx -endif -ifeq ($(CONFIG_EXAMPLES_LCDRW_BUILTIN),y) -CNTXTDIRS += lcdrw -endif -ifeq ($(CONFIG_EXAMPLES_NX_BUILTIN),y) -CNTXTDIRS += nx -endif -ifeq ($(CONFIG_EXAMPLES_NXHELLO_BUILTIN),y) -CNTXTDIRS += nxhello -endif -ifeq ($(CONFIG_EXAMPLES_NXIMAGE_BUILTIN),y) -CNTXTDIRS += nximage -endif -ifeq ($(CONFIG_EXAMPLES_NXTEXT_BUILTIN),y) -CNTXTDIRS += nxtext -endif -ifeq ($(CONFIG_EXAMPLES_OSTEST_BUILTIN),y) -CNTXTDIRS += ostest -endif -ifeq ($(CONFIG_EXAMPLES_TIFF_BUILTIN),y) -CNTXTDIRS += tiff -endif -ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN),y) -CNTXTDIRS += touchscreen -endif -ifeq ($(CONFIG_EXAMPLES_USBMSC_BUILTIN),y) -CNTXTDIRS += usbstorage -endif -ifeq ($(CONFIG_EXAMPLES_USBTERM_BUILTIN),y) -CNTXTDIRS += usbterm -endif - -all: nothing - -.PHONY: nothing context depend clean distclean - -define SDIR_template -$(1)_$(2): - $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" -endef - -$(foreach SDIR, $(CNTXTDIRS), $(eval $(call SDIR_template,$(SDIR),context))) -$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),depend))) -$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),clean))) -$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) - -nothing: - -context: $(foreach SDIR, $(CNTXTDIRS), $(SDIR)_context) - -depend: $(foreach SDIR, $(SUBDIRS), $(SDIR)_depend) - -clean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_clean) - -distclean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_distclean) - --include Make.dep - diff --git a/apps/examples/README.txt b/apps/examples/README.txt deleted file mode 100644 index 03d43f1a0..000000000 --- a/apps/examples/README.txt +++ /dev/null @@ -1,1928 +0,0 @@ -examples -^^^^^^^^ - - appconfig and CONFIG_APPS - - The examples directory contains several sample applications that - can be linked with NuttX. The specific example is selected in the - configs/<board-name>/appconfig file via the CONFIGURED_APPS setting. - This setting provides the path to the directory containing the - application Makefile (this path is a relative to the apps/ top- - level directory). For example, - - CONFIGURE_APPS += examples/ostest - - Selects the examples/ostest example. - - Built-In functions - - Some of the examples may be built as "built-in" functions that - can be executed at run time (rather than as NuttX "main" programs). - These "built-in" examples can be also be executed from the NuttShell - (NSH) command line. In order to configure these built-in NSH - functions, you have to set up the following: - - - CONFIG_NSH_BUILTIN_APPS - Enable support for external registered, - "named" applications that can be executed from the NSH - command line (see apps/README.txt for more information). - - CONFIG_EXAMPLES_XYZ_BUILTIN -- Build the XYZ example as a "built-in" - that can be executed from the NSH command line (where XYZ is - the specific example. See the following for examples that - support this option). - -examples/adc -^^^^^^^^^^^^ - - A mindlessly simple test of an ADC devices. It simply reads from the - ADC device and dumps the data to the console forever. - - This test depends on these specific ADC/NSH configurations settings (your - specific ADC settings might require additional settings). - - CONFIG_ADC - Enabled ADC support - CONFIG_NSH_BUILTIN_APPS - Build the ADC test as an NSH built-in function. - Default: Built as a standalone problem - - Specific configuration options for this example include: - - CONFIG_EXAMPLES_ADC_DEVPATH - The default path to the ADC device. Default: /dev/adc0 - CONFIG_EXAMPLES_ADC_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS - is defined, then the number of samples is provided on the command line - and this value is ignored. Otherwise, this number of samples is - collected and the program terminates. Default: Samples are collected - indefinitely. - CONFIG_EXAMPLES_ADC_GROUPSIZE - The number of samples to read at once. - Default: 4 - -examples/buttons -^^^^^^^^^^^^^^^^ - - This is a simple configuration that may be used to test the board- - specific button interfaces. Configuration options: - - CONFIG_ARCH_BUTTONS - Must be defined for button support - CONFIG_EXAMPLES_BUTTONS_MIN - Lowest button number (MIN=0) - CONFIG_EXAMPLES_BUTTONS_MAX - Highest button number (MAX=7) - - CONFIG_ARCH_IRQBUTTONS - Must be defined for interrupting button support - CONFIG_EXAMPLES_IRQBUTTONS_MIN - Lowest interrupting button number (MIN=0) - CONFIG_EXAMPLES_IRQBUTTONS_MAX - Highest interrupting button number (MAX=7) - - Name strings for buttons: - - CONFIG_EXAMPLES_BUTTONS_NAME0, CONFIG_EXAMPLES_BUTTONS_NAME1, - CONFIG_EXAMPLES_BUTTONS_NAME2, CONFIG_EXAMPLES_BUTTONS_NAME3, - CONFIG_EXAMPLES_BUTTONS_NAME4, CONFIG_EXAMPLES_BUTTONS_NAME5, - CONFIG_EXAMPLES_BUTTONS_NAME6, CONFIG_EXAMPLES_BUTTONS_NAME7, - - Additional architecture-/board- specific configuration settings may also - be required. - - NOTE: This test exercises internal button driver interfaces. As such, it - relies on internal OS interfaces that are not normally available to a - user-space program. As a result, this example cannot be used if a - NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL). - -examples/can -^^^^^^^^^^^^ - - If the CAN device is configured in loopback mode, then this example can - be used to test the CAN device in loop back mode. It simple sinces a - sequence of CAN messages and verifies that those messages are returned - exactly as sent. - - This test depends on these specific CAN/NSH configurations settings (your - specific CAN settings might require additional settings). - - CONFIG_CAN - Enables CAN support. - CONFIG_CAN_LOOPBACK - A CAN driver may or may not support a loopback - mode for testing. The STM32 CAN driver does support loopback mode. - CONFIG_NSH_BUILTIN_APPS - Build the CAN test as an NSH built-in function. - Default: Built as a standalone problem - - Specific configuration options for this example include: - - CONFIG_EXAMPLES_CAN_DEVPATH - The path to the CAN device. Default: /dev/can0 - CONFIG_EXAMPLES_CAN_NMSGS - If CONFIG_NSH_BUILTIN_APPS - is defined, then the number of loops is provided on the command line - and this value is ignored. Otherwise, this number of CAN message is - collected and the program terminates. Default: If built as an NSH - built-in, the default is 32. Otherwise messages are sent and received - indefinitely. - - The default behavior assumes loopback mode. Messages are sent, then read - and verified. The behavior can be altered for other kinds of testing where - the test only sends or received (but does not verify) can messages. - - CONFIG_EXAMPLES_CAN_READONLY - Only receive messages - CONFIG_EXAMPLES_CAN_WRITEONLY - Only send messages - -examples/cdcacm -^^^^^^^^^^^^^^^ - - This very simple example shows how a USB CDC/ACM serial can be dynamically - connected and disconnected from a host. This example can only be used as - an NSH built-int command. If built-in, then two new NSH commands will be - supported: - - 1. sercon - Connect the CDC/ACM serial device - 2. serdis - Disconnect the CDC/ACM serial device - - Configuration prequisites (not complete): - - CONFIG_USBDEV=y : USB device support must be enabled - CONFIG_CDCACM=y : The CDC/ACM driver must be built - CONFIG_NSH_BUILTIN_APPS : NSH built-in application support must be enabled - - Configuration options specific to this example: - - CONFIG_EXAMPLES_CDCACM_DEVMINOR : The minor number of the CDC/ACM device. - : i.e., the 'x' in /dev/ttyACMx - - If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB, or - CONFIG_USBDEV_TRACE), then the example code will also initialize the USB trace - output. The amount of trace output can be controlled using: - - CONFIG_EXAMPLES_CDCACM_TRACEINIT - Show initialization events - CONFIG_EXAMPLES_CDCACM_TRACECLASS - Show class driver events - CONFIG_EXAMPLES_CDCACM_TRACETRANSFERS - Show data transfer events - CONFIG_EXAMPLES_CDCACM_TRACECONTROLLER - Show controller events - CONFIG_EXAMPLES_CDCACM_TRACEINTERRUPTS - Show interrupt-related events. - - Note: This example is only enables or disable USB CDC/ACM via the NSH - 'sercon' and 'serdis' command. It will enable and disable tracing per - the settings before enabling and after disabling the CDC/ACM device. It - will not, however, monitor buffered trace data in the interim. If - CONFIG_USBDEV_TRACE is defined (and the debug options are not), other - application logic will need to monitor the buffered trace data. - -examples/composite -^^^^^^^^^^^^^^^^^^ - - This example test a USB composite device. The only supported composite is - CDC/ACM serial with a USB mass storage device. - - Required overall configuration: - - CONFIG_USBDEV=y - USB device support - CONFIG_USBDEV_COMPOSITE=y - USB composite device support - CONFIG_COMPOSITE_IAD=y - Interface associate descriptor needed - - CONFIG_CDCACM=y - USB CDC/ACM serial device support - CONFIG_CDCACM_COMPOSITE=y - USB CDC/ACM serial composite device support - CONFIG_CDCACM_IFNOBASE=0 - CDC/ACM interfaces start with number 0 - CONFIG_CDCACM_STRBASE=4 - Base of string numbers (not really needed) - CONFIG_CDCACM_EPINTIN=1 - Endpoint numbers must be unique - CONFIG_CDCACM_EPBULKIN=2 - CONFIG_CDCACM_EPBULKOUT=3 - - CONFIG_USBMSC - USB mass storage device support - CONFIG_USBMSC_COMPOSITE=y - USB mass storage composite device support - CONFIG_USBMSC_IFNOBASE=2 - USB mass storage interfaces start with number 2 - CONFIG_USBMSC_STRBASE=4 - Base of string numbers (needed) - CONFIG_USBMSC_EPBULKOUT=4 - Endpoint numbers must be unique - CONFIG_USBMSC_EPBULKIN=5 - - CONFIG_NSH_BUILTIN_APPS - This example can be built as two NSH "built-in" commands if this option - is selected: 'conn' will connect the USB composite device; 'msdis' - will disconnect the USB composite device. - - Configuration options unique to this example: - - CONFIG_EXAMPLES_COMPOSITE_DEBUGMM - Enables some debug tests to check for memory usage and memory leaks. - - CONFIG_EXAMPLES_COMPOSITE_NLUNS - Defines the number of logical units (LUNs) exported by the USB storage - driver. Each LUN corresponds to one exported block driver (or partition - of a block driver). May be 1, 2, or 3. Default is 1. - CONFIG_EXAMPLES_COMPOSITE_DEVMINOR1 - The minor device number of the block driver for the first LUN. For - example, N in /dev/mmcsdN. Used for registering the block driver. Default - is zero. - CONFIG_EXAMPLES_COMPOSITE_DEVPATH1 - The full path to the registered block driver. Default is "/dev/mmcsd0" - CONFIG_EXAMPLES_COMPOSITE_DEVMINOR2 and CONFIG_EXAMPLES_COMPOSITE_DEVPATH2 - Similar parameters that would have to be provided if CONFIG_EXAMPLES_COMPOSITE_NLUNS - is 2 or 3. No defaults. - CONFIG_EXAMPLES_COMPOSITE_DEVMINOR3 and CONFIG_EXAMPLES_COMPOSITE_DEVPATH2 - Similar parameters that would have to be provided if CONFIG_EXAMPLES_COMPOSITE_NLUNS - is 3. No defaults. - CONFIG_EXAMPLES_COMPOSITE_BUFLEN. Default 256. - - CONFIG_EXAMPLES_COMPOSITE_TTYUSB - The minor number of the USB serial device. - Default is zero (corresponding to /dev/ttyUSB0 or /dev/ttyACM0). Default is zero. - CCONFIG_EXAMPLES_COMPOSITE_SERDEV - The string corresponding to - CONFIG_EXAMPLES_COMPOSITE_TTYUSB. The default is "/dev/ttyUSB0" (for the PL2303 - emulation) or "/dev/ttyACM0" (for the CDC/ACM serial device). - CONFIG_EXAMPLES_COMPOSITE_BUFSIZE - The size of the serial I/O buffer in - bytes. Default 256 bytes. - - If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB), then - the example code will also manage the USB trace output. The amount of trace output - can be controlled using: - - CONFIG_EXAMPLES_COMPOSITE_TRACEINIT - Show initialization events - CONFIG_EXAMPLES_COMPOSITE_TRACECLASS - Show class driver events - CONFIG_EXAMPLES_COMPOSITE_TRACETRANSFERS - Show data transfer events - CONFIG_EXAMPLES_COMPOSITE_TRACECONTROLLER - Show controller events - CONFIG_EXAMPLES_COMPOSITE_TRACEINTERRUPTS - Show interrupt-related events. - -examples/cxxtest -^^^^^^^^^^^^^^^^ - - This is a test of the C++ standard library. At present a port of the uClibc++ - C++ library is available. Due to licensinging issues, the uClibc++ C++ library - is not included in the NuttX source tree by default, but must be installed - (see misc/uClibc++/README.txt for installation). - - The NuttX setting that are required include: - - CONFIG_HAVE_CXX=y - CONFIG_HAVE_CXXINITIALIZE=y - CONFIG_UCLIBCXX=y - - Additional uClibc++ settings may be required in your build environment. - - The uClibc++ test includes simple test of: - - - iostreams, - - STL, - - RTTI, and - - Exceptions - -examples/dhcpd -^^^^^^^^^^^^^^ - - This examples builds a tiny DCHP server for the target system. - - NOTE: For test purposes, this example can be built as a - host-based DHCPD server. This can be built as follows: - - cd examples/dhcpd - make -f Makefile.host TOPDIR=<nuttx-directory> - - NuttX configuration settings: - - CONFIG_NET=y - Of course - CONFIG_NSOCKET_DESCRIPTORS - And, of course, you must allocate some - socket descriptors. - CONFIG_NET_UDP=y - UDP support is required for DHCP - (as well as various other UDP-related - configuration settings) - CONFIG_NET_BROADCAST=y - UDP broadcast support is needed. - - CONFIG_EXAMPLES_DHCPD_NOMAC - (May be defined to use software assigned MAC) - CONFIG_EXAMPLES_DHCPD_IPADDR - Target IP address - CONFIG_EXAMPLES_DHCPD_DRIPADDR - Default router IP addess - CONFIG_EXAMPLES_DHCPD_NETMASK - Network mask - - See also CONFIG_NETUTILS_DHCPD_* settings described elsewhere - and used in netutils/dhcpd/dhcpd.c. These settings are required - to described the behavior of the daemon. - - Applications using this example will need to provide an appconfig - file in the configuration driver with instruction to build applications - like: - - CONFIGURED_APPS += uiplib - -examples/discover -^^^^^^^^^^^^^^^^^ - - This example exercises netutils/discover utility. This example initializes - and starts the UDP discover daemon. This daemon is useful for discovering - devices in local networks, especially with DHCP configured devices. It - listens for UDP broadcasts which also can include a device class so that - groups of devices can be discovered. It is also possible to address all - classes with a kind of broadcast discover. - - This example will automatically be built as an NSH built-in if - CONFIG_NSH_BUILTIN_APPS is selected. Otherwise, it will be a standalone - program with entry point "discover_main". - - NuttX configuration settings: - - CONFIG_EXAMPLES_DISCOVER_DHCPC - DHCP Client - CONFIG_EXAMPLES_DISCOVER_NOMAC - Use canned MAC address - CONFIG_EXAMPLES_DISCOVER_IPADDR - Target IP address - CONFIG_EXAMPLES_DISCOVER_DRIPADDR - Router IP address - CONFIG_EXAMPLES_DISCOVER_NETMASK - Network Mask - -examples/elf -^^^^^^^^^^^^ - - This example builds a small ELF loader test case. This includes several - test programs under examples/elf tests. These tests are build using - the relocatable ELF format and installed in a ROMFS file system. At run time, - each program in the ROMFS file system is executed. Requires CONFIG_ELF. - Other configuration options: - - CONFIG_EXAMPLES_ELF_DEVMINOR - The minor device number of the ROMFS block - driver. For example, the N in /dev/ramN. Used for registering the RAM - block driver that will hold the ROMFS file system containing the ELF - executables to be tested. Default: 0 - - CONFIG_EXAMPLES_ELF_DEVPATH - The path to the ROMFS block driver device. This - must match EXAMPLES_ELF_DEVMINOR. Used for registering the RAM block driver - that will hold the ROMFS file system containing the ELF executables to be - tested. Default: "/dev/ram0" - - NOTES: - - 1. CFLAGS should be provided in CELFFLAGS. RAM and FLASH memory regions - may require long allcs. For ARM, this might be: - - CELFFLAGS = $(CFLAGS) -mlong-calls - - Similarly for C++ flags which must be provided in CXXELFFLAGS. - - 2. Your top-level nuttx/Make.defs file must also include an approproate definition, - LDELFFLAGS, to generate a relocatable ELF object. With GNU LD, this should - include '-r' and '-e main' (or _main on some platforms). - - LDELFFLAGS = -r -e main - - If you use GCC to link, you make also need to include '-nostdlib' or - '-nostartfiles' and '-nodefaultlibs'. - - 3. This example also requires genromfs. genromfs can be build as part of the - nuttx toolchain. Or can built from the genromfs sources that can be found - at misc/tools/genromfs-0.5.2.tar.gz. In any event, the PATH variable must - include the path to the genromfs executable. - - 4. ELF size: The ELF files in this example are, be default, quite large - because they include a lot of "build garbage". You can greatly reduce the - size of the ELF binaries are using the 'objcopy --strip-unneeded' command to - remove un-necessary information from the ELF files. - - 5. Simulator. You cannot use this example with the the NuttX simulator on - Cygwin. That is because the Cygwin GCC does not generate ELF file but - rather some Windows-native binary format. - - If you really want to do this, you can create a NuttX x86 buildroot toolchain - and use that be build the ELF executables for the ROMFS file system. - - 6. Linker scripts. You might also want to use a linker scripts to combine - sections better. An example linker script is at nuttx/binfmt/libelf/gnu-elf.ld. - That example might have to be tuned for your particular linker output to - position additional sections correctly. The GNU LD LDELFFLAGS then might - be: - - LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld - -examples/ftpc -^^^^^^^^^^^^^ - - This is a simple FTP client shell used to exercise the capabilities - of the FTPC library (apps/netutils/ftpc). This example is configured - to that it will only work as a "built-in" program that can be run from - NSH when CONFIG_NSH_BUILTIN_APPS is defined. - - From NSH, the startup command sequence is as follows. This is only - an example, your configration could have different mass storage devices, - mount paths, and FTP directories: - - nsh> mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp - nsh> cd /tmp # cd into the /tmp directory - nsh> ftpc xx.xx.xx.xx[:pp] # Start the FTP client - nfc> login <name> <password> # Log into the FTP server - nfc> help # See a list of FTP commands - - where xx.xx.xx.xx is the IP address of the FTP server and pp is an - optional port number. - - NOTE: By default, FTPC uses readline to get data from stdin. So your - appconfig file must have the following build path: - - CONFIGURED_APPS += system/readline - - NOTE: If you use the ftpc task over a telnet NSH connection, then you - should set the following configuration item: - - CONFIG_EXAMPLES_FTPC_FGETS=y - - By default, the FTPC client will use readline() to get characters from - the console. Readline includes and command-line editor and echos - characters received in stdin back through stdout. Neither of these - behaviors are desire-able if Telnet is used. - - You may also want to define the following in your configuration file. - Otherwise, you will have not feeback about what is going on: - - CONFIG_DEBUG=y - CONFIG_DEBUG_VERBOSE=y - CONFIG_DEBUG_FTPC=y - -examples/ftpd -^^^^^^^^^^^^^^ - - This example exercises the FTPD daemon at apps/netuils/ftpd. Below are - configurations specific to the FTPD example (the FTPD daemon itself may - require other configuration options as well). - - CONFIG_EXAMPLES_FTPD_PRIO - Priority of the FTP daemon. - Default: SCHED_PRIORITY_DEFAULT - CONFIG_EXAMPLES_FTPD_STACKSIZE - Stack size allocated for the - FTP daemon. Default: 2048 - CONFIG_EXAMPLES_FTPD_NONETINIT - Define to suppress configuration of the - network by apps/examples/ftpd. You would need to suppress network - configuration if the network is configuration prior to running the - example. - - NSH always initializes the network so if CONFIG_NSH_BUILTIN_APPS is - defined, so is CONFIG_EXAMPLES_FTPD_NONETINIT (se it does not explicitly - need to be defined in that case): - - CONFIG_NSH_BUILTIN_APPS - Build the FTPD daemon example test as an - NSH built-in function. By default the FTPD daemon will be built - as a standalone application. - - If CONFIG_EXAMPLES_FTPD_NONETINIT is not defined, then the following may - be specified to customized the network configuration: - - CONFIG_EXAMPLES_FTPD_NOMAC - If the hardware has no MAC address of its - own, define this =y to provide a bogus address for testing. - CONFIG_EXAMPLES_FTPD_IPADDR - The target IP address. Default 10.0.0.2 - CONFIG_EXAMPLES_FTPD_DRIPADDR - The default router address. Default - 10.0.0.1 - CONFIG_EXAMPLES_FTPD_NETMASK - The network mask. Default: 255.255.255.0 - - Other required configuration settings: Of course TCP networking support - is required. But here are a couple that are less obvious: - - CONFIG_DISABLE_PTHREAD - pthread support is required - CONFIG_DISABLE_POLL - poll() support is required - - Other FTPD configuration options thay may be of interest: - - CONFIG_FTPD_VENDORID - The vendor name to use in FTP communications. - Default: "NuttX" - CONFIG_FTPD_SERVERID - The server name to use in FTP communications. - Default: "NuttX FTP Server" - CONFIG_FTPD_CMDBUFFERSIZE - The maximum size of one command. Default: - 512 bytes. - CONFIG_FTPD_DATABUFFERSIZE - The size of the I/O buffer for data - transfers. Default: 2048 bytes. - CONFIG_FTPD_WORKERSTACKSIZE - The stacksize to allocate for each - FTP daemon worker thread. Default: 2048 bytes. - - The appconfig file (apps/.config) should include: - - CONFIGURED_APPS += examples/ftpd - CONFIGURED_APPS += netutils/uiplib - CONFIGURED_APPS += netutils/ftpd - -examples/hello -^^^^^^^^^^^^^^ - - This is the mandatory, "Hello, World!!" example. It is little more - than examples/null with a single printf statement. Really useful only - for bringing up new NuttX architectures. - - * CONFIG_NSH_BUILTIN_APPS - Build the "Hello, World" example as an NSH built-in application. - -examples/helloxx -^^^^^^^^^^^^^^^^ - - This is C++ version of the "Hello, World!!" example. It is intended - only to verify that the C++ compiler is functional, that basic C++ - library suupport is available, and that class are instantiated - correctly. - - NuttX configuration prerequisites: - - CONFIG_HAVE_CXX -- Enable C++ Support - - Optional NuttX configuration settings: - - CONFIG_HAVE_CXXINITIALIZE -- Enable support for static constructors - (may not be available on all platforms). - - NuttX configuration settings specific to this examp;le: - - CONFIG_EXAMPLES_HELLOXX_BUILTIN -- Build the helloxx example as a - "built-in" that can be executed from the NSH command line. - CONFIG_EXAMPLES_HELLOXX_NOSTACKCONST - Set if the system does not - support construction of objects on the stack. - - Also needed: - - CONFIG_HAVE_CXX=y - - And you may have to tinker with the following to get libxx to compile - properly: - - CONFIG_CXX_NEWLONG=y or =n - - The argument of the 'new' operators should take a type of size_t. But size_t - has an unknown underlying. In the nuttx sys/types.h header file, size_t - is typed as uint32_t (which is determined by architecture-specific logic). - But the C++ compiler may believe that size_t is of a different type resulting - in compilation errors in the operator. Using the underlying integer type - Instead of size_t seems to resolve the compilation issues. - -examples/hidkbd -^^^^^^^^^^^^^^^^ - - This is a simple test to debug/verify the USB host HID keyboard class - driver. - - CONFIG_EXAMPLES_HIDKBD_DEFPRIO - Priority of "waiter" thread. Default: - 50 - CONFIG_EXAMPLES_HIDKBD_STACKSIZE - Stacksize of "waiter" thread. Default - 1024 - CONFIG_EXAMPLES_HIDKBD_DEVNAME - Name of keyboard device to be used. - Default: "/dev/kbda" - CONFIG_EXAMPLES_HIDKBD_ENCODED - Decode special key press events in the - user buffer. In this case, the example coded will use the interfaces - defined in include/nuttx/input/kbd_codec.h to decode the returned - keyboard data. These special keys include such things as up/down - arrows, home and end keys, etc. If this not defined, only 7-bit print- - able and control ASCII characters will be provided to the user. - Requires CONFIG_HIDKBD_ENCODED && CONFIG_LIB_KBDCODEC - -endif -examples/igmp -^^^^^^^^^^^^^ - - This is a trivial test of the NuttX IGMP capability. It present it - does not do much of value -- Much more is needed in order to verify - the IGMP features! - - * CONFIG_EXAMPLES_IGMP_NOMAC - Set if the hardware has no MAC address; one will be assigned - * CONFIG_EXAMPLES_IGMP_IPADDR - Target board IP address - * CONFIG_EXAMPLES_IGMP_DRIPADDR - Default router address - * CONFIG_EXAMPLES_IGMP_NETMASK - Network mask - * CONFIG_EXAMPLES_IGMP_GRPADDR - Multicast group address - - Applications using this example will need to provide an appconfig - file in the configuration driver with instruction to build applications - like: - - CONFIGURED_APPS += uiplib - -examples/json -^^^^^^^^^^^^^ - - This example exercises the cJSON implementation at apps/netutils/json. - This example contains logic taken from the cJSON project: - - http://sourceforge.net/projects/cjson/ - - The example corresponds to SVN revision r42 (with lots of changes for - NuttX coding standards). As of r42, the SVN repository was last updated - on 2011-10-10 so I presume that the code is stable and there is no risk - of maintaining duplicate logic in the NuttX repository. - -examples/keypadtest -^^^^^^^^^^^^^^^^^^^ - - This is a generic keypad test example. It is similar to the USB hidkbd - example, but makes no assumptions about the underlying keyboard interface. - It uses the interfaces of include/nuttx/input/keypad.h. - - CONFIG_EXAMPLES_KEYPADTEST - Selects the keypadtest example (only need - if the mconf/Kconfig tool is used. - - CONFIG_EXAMPLES_KEYPAD_DEVNAME - The name of the keypad device that will - be opened in order to perform the keypad test. Default: "/dev/keypad" - -examples/lcdrw -^^^^^^^^^^^^^^ - - This example may be used to verify if you can or cannot read data - correctly from an LCD interface. At present, this supports only LCDs - with RGB565 color format. - - * CONFIG_EXAMPLES_LDCRW_DEVNO - LCD device number. Default: 0 - * CONFIG_EXAMPLES_LDCRW_XRES - LCD X resolution. Default: 240 - * CONFIG_EXAMPLES_LDCRW_YRES - LCD Y resolution. Default: 320 - - NOTE: This test exercises internal lcd driver interfaces. As such, it - relies on internal OS interfaces that are not normally available to a - user-space program. As a result, this example cannot be used if a - NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL). - -examples/mm -^^^^^^^^^^^ - - This is a simplified version of the "built-in" memory manager test of - mm/mm_test.c. It is simplified because it does not have access to the - internals of the memory manager as does mm/mm_test.c, but it has the - advantage that it runs in the actual NuttX tasking environment (the - mm/mm_test.c only runs in a PC simulation environment). - -examples/modbus -^^^^^^^^^^^^^^^ - - This is a port of the FreeModbus Linux demo. It derives from the - demos/LINUX directory of the FreeModBus version 1.5.0 (June 6, 2010) - that can be downloaded in its entirety from http://developer.berlios.de/project/showfiles.php?group_id=6120. - - CONFIG_EXAMPLES_MODBUS_PORT, Default 0 (for /dev/ttyS0) - CONFIG_EXAMPLES_MODBUS_BAUD, Default B38400 - CONFIG_EXAMPLES_MODBUS_PARITY, Default MB_PAR_EVEN - - CONFIG_EXAMPLES_MODBUS_REG_INPUT_START, Default 1000 - CONFIG_EXAMPLES_MODBUS_REG_INPUT_NREGS, Default 4 - CONFIG_EXAMPLES_MODBUS_REG_HOLDING_START, Default 2000 - CONFIG_EXAMPLES_MODBUS_REG_HOLDING_NREGS, Default 130 - - The FreeModBus library resides at apps/modbus. See apps/modbus/README.txt - for additional configuration information. - -examples/mount -^^^^^^^^^^^^^^ - - This contains a simple test of filesystem mountpoints. - - * CONFIG_EXAMPLES_MOUNT_DEVNAME - The name of the user-provided block device to mount. - If CONFIG_EXAMPLES_MOUNT_DEVNAME is not provided, then - a RAM disk will be configured. - - * CONFIG_EXAMPLES_MOUNT_NSECTORS - The number of "sectors" in the RAM disk used when - CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined. - - * CONFIG_EXAMPLES_MOUNT_SECTORSIZE - The size of each sectors in the RAM disk used when - CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined. - - * CONFIG_EXAMPLES_MOUNT_RAMDEVNO - The RAM device minor number used to mount the RAM disk used - when CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined. The - default is zero (meaning that "/dev/ram0" will be used). - -examples/nettest -^^^^^^^^^^^^^^^^ - - This is a simple network test for verifying client- and server- - functionality in a TCP/IP connection. - - Applications using this example will need to provide an appconfig - file in the configuration driver with instruction to build applications - like: - - CONFIGURED_APPS += uiplib - -examples/nsh -^^^^^^^^^^^^ - - This directory provides an example of how to configure and use - the NuttShell (NSH) application. NSH is a simple shell - application. NSH is described in its own README located at - apps/nshlib/README.txt - - Applications using this example will need to provide an appconfig - file in the configuration driver with instruction to build applications - like: - - CONFIGURED_APPS += nshlib - - NOTE: If the NSH serial console is used, then following is also - required to build the readline() library: - - CONFIGURED_APPS += system/readline - - And if networking is included: - - CONFIGURED_APPS += uiplib - CONFIGURED_APPS += dhcpc - CONFIGURED_APPS += resolv - CONFIGURED_APPS += tftp - CONFIGURED_APPS += webclient - - If the Telnet console is enabled, then the appconfig file (apps/.config) - should also include: - - CONFIGURED_APPS += netutils/telnetd - - Also if the Telnet console is enabled, make sure that you have the - following set in the NuttX configuration file or else the performance - will be very bad (because there will be only one character per TCP - transfer): - - CONFIG_STDIO_BUFFER_SIZE - Some value >= 64 - CONFIG_STDIO_LINEBUFFER=y - -examples/nx -^^^^^^^^^^^ - - This directory contains a simple test of a subset of the NX APIs - defined in include/nuttx/nx/nx.h. The following configuration options - can be selected: - - CONFIG_EXAMPLES_NX_BUILTIN -- Build the NX example as a "built-in" - that can be executed from the NSH command line - CONFIG_EXAMPLES_NX_VPLANE -- The plane to select from the frame- - buffer driver for use in the test. Default: 0 - CONFIG_EXAMPLES_NX_DEVNO - The LCD device to select from the LCD - driver for use in the test: Default: 0 - CONFIG_EXAMPLES_NX_BGCOLOR -- The color of the background. Default depends on - CONFIG_EXAMPLES_NX_BPP. - CONFIG_EXAMPLES_NX_COLOR1 -- The color of window 1. Default depends on - CONFIG_EXAMPLES_NX_BPP. - CONFIG_EXAMPLES_NX_COLOR2 -- The color of window 2. Default depends on - CONFIG_EXAMPLES_NX_BPP. - CONFIG_EXAMPLES_NX_TBCOLOR -- The color of the toolbar. Default depends on - CONFIG_EXAMPLES_NX_BPP. - CONFIG_EXAMPLES_NX_FONTID - Selects the font (see font ID numbers in - include/nuttx/nx/nxfonts.h) - CONFIG_EXAMPLES_NX_FONTCOLOR -- The color of the fonts. Default depends on - CONFIG_EXAMPLES_NX_BPP. - CONFIG_EXAMPLES_NX_BPP -- Pixels per pixel to use. Valid options - include 2, 4, 8, 16, 24, and 32. Default is 32. - CONFIG_EXAMPLES_NX_RAWWINDOWS -- Use raw windows; Default is to - use pretty, framed NXTK windows with toolbars. - CONFIG_EXAMPLES_NX_EXTERNINIT - The driver for the graphics device on - this platform requires some unusual initialization. This is the - for, for example, SPI LCD/OLED devices. If this configuration is - selected, then the platform code must provide an LCD initialization - function with a prototype like: - - #ifdef CONFIG_NX_LCDDRIVER - FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno); - #else - FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno); - #endif - - This test can be performed with either the single-user version of - NX or with the multiple user version of NX selected with CONFIG_NX_MULTIUSER. - If CONFIG_NX_MULTIUSER is defined, then the following configuration - options also apply: - - CONFIG_EXAMPLES_NX_STACKSIZE -- The stacksize to use when creating - the NX server. Default 2048 - CONFIG_EXAMPLES_NX_CLIENTPRIO -- The client priority. Default: 100 - CONFIG_EXAMPLES_NX_SERVERPRIO -- The server priority. Default: 120 - CONFIG_EXAMPLES_NX_LISTENERPRIO -- The priority of the event listener - thread. Default 80. - CONFIG_EXAMPLES_NX_NOTIFYSIGNO -- The signal number to use with - nx_eventnotify(). Default: 4 - - If CONFIG_NX_MULTIUSER is defined, then the example also expects the - following settings and will generate an error if they are not as expected: - - CONFIG_DISABLE_MQUEUE=n - CONFIG_DISABLE_SIGNALS=n - CONFIG_DISABLE_PTHREAD=n - CONFIG_NX_BLOCKING=y - -examples/nxconsole -^^^^^^^^^^^^^^^^^^ - - This directory contains yet another version of the NuttShell (NSH). This - version uses the NX console device defined in include/nuttx/nx/nxconsole.h - for output. the result is that the NSH input still come from the standard - console input (probably a serial console). But the text output will go to - an NX winbdow. Prerequisite configuration settings for this test include: - - CONFIG_NX=y -- NX graphics must be enabled - CONFIG_NXCONSOLE=y -- The NX console driver must be built - CONFIG_NX_MULTIUSER=y -- NX multi-user support must be enabled. - CONFIG_DISABLE_MQUEUE=n -- Message queue support must be available. - CONFIG_DISABLE_SIGNALS=n -- Signals are needed - CONFIG_DISABLE_PTHREAD=n -- pthreads are needed - CONFIG_NX_BLOCKING=y -- pthread APIs must be blocking - CONFIG_NSH_CONSOLE=y -- NSH must be configured to use a console. - - The following configuration options can be selected to customize the - test: - - CONFIG_EXAMPLES_NXCON_VPLANE -- The plane to select from the frame- - buffer driver for use in the test. Default: 0 - CONFIG_EXAMPLES_NXCON_DEVNO - The LCD device to select from the LCD - driver for use in the test: Default: 0 - CONFIG_EXAMPLES_NXCON_BGCOLOR -- The color of the background. Default - Default is a darker royal blue. - CONFIG_EXAMPLES_NXCON_WCOLOR -- The color of the window. Default is a light - slate blue. - CONFIG_EXAMPLES_NXCON_FONTID -- Selects the font (see font ID numbers in - include/nuttx/nx/nxfonts.h) - CONFIG_EXAMPLES_NXCON_FONTCOLOR -- The color of the fonts. Default is - black. - CONFIG_EXAMPLES_NXCON_BPP -- Pixels per pixel to use. Valid options - include 2, 4, 8, 16, 24, and 32. Default is 32. - CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT -- The height of the toolbar. - Default: 16 - CONFIG_EXAMPLES_NXCON_TBCOLOR -- The color of the toolbar. Default is - a medium grey. - CONFIG_EXAMPLES_NXCON_EXTERNINIT - The driver for the graphics device on - this platform requires some unusual initialization. This is the - for, for example, SPI LCD/OLED devices. If this configuration is - selected, then the platform code must provide an LCD initialization - function with a prototype like: - - #ifdef CONFIG_NX_LCDDRIVER - FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno); - #else - FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno); - #endif - - CONFIG_EXAMPLES_NXCON_MINOR -- The NX console device minor number. - Default is 0 corresponding to /dev/nxcon0 - CONFIG_EXAMPLES_NXCON_DEVNAME -- The quoated, full path to the - NX console device corresponding to CONFIG_EXAMPLES_NXCON_MINOR. - Default: "/dev/nxcon0" - CONFIG_EXAMPLES_NXCONSOLE_PRIO - Priority of the NxConsole task. - Default: SCHED_PRIORITY_DEFAULT - CONFIG_EXAMPLES_NXCONSOLE_STACKSIZE - Stack size allocated for the - NxConsole task. Default: 2048 - - The following configuration settings determine how to set up the NX - server (CONFIG_NX_MULTIUSER): - - CONFIG_EXAMPLES_NXCON_STACKSIZE -- The stacksize to use when creating - the NX server. Default 2048 - CONFIG_EXAMPLES_NXCON_CLIENTPRIO -- The client priority. Default: 100 - CONFIG_EXAMPLES_NXCON_SERVERPRIO -- The server priority. Default: 120 - CONFIG_EXAMPLES_NXCON_LISTENERPRIO -- The priority of the event listener - thread. Default 80. - CONFIG_EXAMPLES_NXCON_NOTIFYSIGNO -- The signal number to use with - nx_eventnotify(). Default: 4 - -examples/nxffs -^^^^^^^^^^^^^^ - - This is a test of the NuttX NXFFS FLASH file system. This is an NXFFS - stress test and beats on the file system very hard. It should only - be used in a simulation environment! Putting this NXFFS test on real - hardware will most likely destroy your FLASH. You have been warned. - -examples/nxflat -^^^^^^^^^^^^^^^ - - This example builds a small NXFLAT test case. This includes several - test programs under examples/nxflat tests. These tests are build using - the NXFLAT format and installed in a ROMFS file system. At run time, - each program in the ROMFS file system is executed. Requires CONFIG_NXFLAT. - -examplex/nxhello -^^^^^^^^^^^^^^^^ - - A very simple graphics example that just says "Hello, World!" in the - center of the display. - - The following configuration options can be selected: - - CONFIG_EXAMPLES_NXHELLO_BUILTIN -- Build the NXHELLO example as a "built-in" - that can be executed from the NSH command line - CONFIG_EXAMPLES_NXHELLO_VPLANE -- The plane to select from the frame- - buffer driver for use in the test. Default: 0 - CONFIG_EXAMPLES_NXHELLO_DEVNO - The LCD device to select from the LCD - driver for use in the test: Default: 0 - CONFIG_EXAMPLES_NXHELLO_BGCOLOR -- The color of the background. Default - depends on CONFIG_EXAMPLES_NXHELLO_BPP. - CONFIG_EXAMPLES_NXHELLO_FONTID - Selects the font (see font ID numbers in - include/nuttx/nx/nxfonts.h) - CONFIG_EXAMPLES_NXHELLO_FONTCOLOR -- The color of the fonts used in the - background window. Default depends on CONFIG_EXAMPLES_NXHELLO_BPP. - CONFIG_EXAMPLES_NXHELLO_BPP -- Pixels per pixel to use. Valid options - include 2, 4, 8, 16, 24, and 32. Default is 32. - CONFIG_EXAMPLES_NXHELLO_EXTERNINIT - The driver for the graphics device on - this platform requires some unusual initialization. This is the - for, for example, SPI LCD/OLED devices. If this configuration is - selected, then the platform code must provide an LCD initialization - function with a prototype like: - - #ifdef CONFIG_NX_LCDDRIVER - FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno); - #else - FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno); - #endif - -examples/nximage -^^^^^^^^^^^^^^^^ - - This is a simple example that just puts the NuttX logo image in the center - of the display. This only works for RGB23 (888), RGB16 (656), RGB8 (332), - and 8-bit greyscale for now. - - CONFIG_EXAMPLES_NXIMAGE_BUILTIN -- Build the NXIMAGE example as a "built-in" - that can be executed from the NSH command line - CONFIG_EXAMPLES_NXIMAGE_VPLANE -- The plane to select from the frame- - buffer driver for use in the test. Default: 0 - CONFIG_EXAMPLES_NXIMAGE_DEVNO - The LCD device to select from the LCD - driver for use in the test: Default: 0 - CONFIG_EXAMPLES_NXIMAGE_BPP -- Pixels per pixel to use. Valid options - include 8, 16, and 24. Default is 16. - CONFIG_EXAMPLES_NXIMAGE_XSCALEp5, CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5, - CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0 -- The logo image width is 160 columns. - One of these may be defined to rescale the image horizontally by .5, 1.5, - or 2.0. - CONFIG_EXAMPLES_NXIMAGE_YSCALEp5, CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5, - CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0 -- The logo image height is 160 rows. - One of these may be defined to rescale the image vertically by .5, 1.5, - or 2.0. - CONFIG_EXAMPLES_NXIMAGE_GREYSCALE -- Grey scale image. Default: RGB. - CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT - The driver for the graphics device on - this platform requires some unusual initialization. This is the - for, for example, SPI LCD/OLED devices. If this configuration is - selected, then the platform code must provide an LCD initialization - function with a prototype like: - - #ifdef CONFIG_NX_LCDDRIVER - FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno); - #else - FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno); - #endif - - How was that run-length encoded image produced? - - a. I used GIMP output the image as a .c file. - b. I added som C logic to palette-ize the RGB image in the GIMP .c file - c. Then I add some simple run-length encoding to palette-ized image. - - NOTE: As of this writing, most of the pixel depth, scaling options, and - combinations thereof have not been tested. - -examplex/nxlines -^^^^^^^^^^^^^^^^ - - A very simple graphics example that just exercised the NX line drawing - logic. - - The following configuration options can be selected: - - CONFIG_EXAMPLES_NXLINES_VPLANE -- The plane to select from the frame- - buffer driver for use in the test. Default: 0 - CONFIG_EXAMPLES_NXLINES_DEVNO - The LCD device to select from the LCD - driver for use in the test: Default: 0 - CONFIG_EXAMPLES_NXLINES_BGCOLOR -- The color of the background. Default - depends on CONFIG_EXAMPLES_NXLINES_BPP. - CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in - pixels (default: 16) - CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the central lines drawn - in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP - (there really is no meaningful default). - CONFIG_EXAMPLES_NXLINES_BORDERWIDTH -- The width of the circular border - drawn in the background window. (default: 16). - CONFIG_EXAMPLES_NXLINES_BORDERCOLOR -- The color of the circular border - drawn in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP - (there really is no meaningful default). - CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR -- The color of the circular region - filled in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP - (there really is no meaningful default). - CONFIG_EXAMPLES_NXLINES_BORDERCOLOR -- The color of the lines drawn in the - background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP (there - really is no meaningful default). - - CONFIG_EXAMPLES_NXLINES_BPP -- Pixels per pixel to use. Valid options - include 2, 4, 8, 16, 24, and 32. Default is 16. - CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on - this platform requires some unusual initialization. This is the - for, for example, SPI LCD/OLED devices. If this configuration is - selected, then the platform code must provide an LCD initialization - function with a prototype like: - - #ifdef CONFIG_NX_LCDDRIVER - FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno); - #else - FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno); - #endif - - CONFIG_NSH_BUILTIN_APPS - Build the NX lines examples as an NSH built-in - function. - -examples/nxtext -^^^^^^^^^^^^^^^ - - This directory contains another simple test of a subset of the NX APIs - defined in include/nuttx/nx/nx.h. This text focuses on text displays on - the dispaly background combined with pop-up displays over the text. - The text display will continue to update while the pop-up is visible. - - NOTE: This example will *only* work with FB drivers and with LCD - drivers that support reading the contents of the internal LCD memory - *unless* you define CONFIG_EXAMPLES_NXTEXT_NOGETRUN. If you notice - garbage on the display or a failure at the point where the display - should scroll, it is probably because you have an LCD driver that is - write-only. - - The following configuration options can be selected: - - CONFIG_EXAMPLES_NXTEXT_BUILTIN -- Build the NXTEXT example as a "built-in" - that can be executed from the NSH command line - CONFIG_EXAMPLES_NXTEXT_VPLANE -- The plane to select from the frame- - buffer driver for use in the test. Default: 0 - CONFIG_EXAMPLES_NXTEXT_DEVNO - The LCD device to select from the LCD - driver for use in the test: Default: 0 - CONFIG_EXAMPLES_NXTEXT_BGCOLOR -- The color of the background. Default - depends on CONFIG_EXAMPLES_NXTEXT_BPP. - CONFIG_EXAMPLES_NXTEXT_BGFONTID - Selects the font to use in the - background text (see font ID numbers in include/nuttx/nx/nxfonts.h) - CONFIG_EXAMPLES_NXTEXT_BGFONTCOLOR -- The color of the fonts used in the - background window. Default depends on CONFIG_EXAMPLES_NXTEXT_BPP. - CONFIG_EXAMPLES_NXTEXT_PUCOLOR -- The color of the pop-up window. Default - depends on CONFIG_EXAMPLES_NXTEXT_BPP. - CONFIG_EXAMPLES_NXTEXT_PUFONTID - Selects the font to use in the pop-up - windows (see font ID numbers in include/nuttx/nx/nxfonts.h) - CONFIG_EXAMPLES_NXTEXT_PUFONTCOLOR -- The color of the fonts used in the - background window. Default depends on CONFIG_EXAMPLES_NXTEXT_BPP. - CONFIG_EXAMPLES_NXTEXT_BPP -- Pixels per pixel to use. Valid options - include 2, 4, 8, 16, 24, and 32. Default is 32. - CONFIG_EXAMPLES_NXTEXT_NOGETRUN -- If your display is read-only OR if - reading is not reliable, then select this configuration to avoid - reading from the display. - CONFIG_EXAMPLES_NXTEXT_EXTERNINIT - The driver for the graphics device on - this platform requires some unusual initialization. This is the - for, for example, SPI LCD/OLED devices. If this configuration is - selected, then the platform code must provide an LCD initialization - function with a prototype like: - - #ifdef CONFIG_NX_LCDDRIVER - FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno); - #else - FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno); - #endif - - CONFIG_EXAMPLES_NXTEXT_BMCACHE - The maximum number of characters that - can be put in the background window. Default is 128. - CONFIG_EXAMPLES_NXTEXT_GLCACHE - The maximum nuber of pre-rendered - fonts that can be retained for the background window. - - This test can be performed with either the single-user version of - NX or with the multiple user version of NX selected with CONFIG_NX_MULTIUSER. - If CONFIG_NX_MULTIUSER is defined, then the following configuration - options also apply: - - CONFIG_EXAMPLES_NXTEXT_STACKSIZE -- The stacksize to use when creating - the NX server. Default 2048 - CONFIG_EXAMPLES_NXTEXT_CLIENTPRIO -- The client priority. Default: 100 - CONFIG_EXAMPLES_NXTEXT_SERVERPRIO -- The server priority. Default: 120 - CONFIG_EXAMPLES_NXTEXT_LISTENERPRIO -- The priority of the event listener - thread. Default 80. - CONFIG_EXAMPLES_NXTEXT_NOTIFYSIGNO -- The signal number to use with - nx_eventnotify(). Default: 4 - - If CONFIG_NX_MULTIUSER is defined, then the example also expects the - following settings and will generate an error if they are not as expected: - - CONFIG_DISABLE_MQUEUE=n - CONFIG_DISABLE_SIGNALS=n - CONFIG_DISABLE_PTHREAD=n - CONFIG_NX_BLOCKING=y - -examples/null -^^^^^^^^^^^^^ - - This is the do nothing application. It is only used for bringing - up new NuttX architectures in the most minimal of environments. - -examples/ostest -^^^^^^^^^^^^^^^ - - This is the NuttX 'qualification' suite. It attempts to exercise - a broad set of OS functionality. Its coverage is not very extensive - as of this writing, but it is used to qualify each NuttX release. - - The behavior of the ostest can be modified with the following - settings in the configs/<board-name>/defconfig file: - - * CONFIG_EXAMPLES_OSTEST_BUILTIN - Build the OS test example as an NSH built-in application. - * CONFIG_EXAMPLES_OSTEST_LOOPS - Used to control the number of executions of the test. If - undefined, the test executes one time. If defined to be - zero, the test runs forever. - * CONFIG_EXAMPLES_OSTEST_STACKSIZE - Used to create the ostest task. Default is 8192. - * CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS - Specifies the number of threads to create in the barrier - test. The default is 8 but a smaller number may be needed on - systems without sufficient memory to start so many threads. - * CONFIG_EXAMPLES_OSTEST_RR_RANGE - During round-robin scheduling test two threads are created. Each of the threads - searches for prime numbers in the configurable range, doing that configurable - number of times. - This value specifies the end of search range and together with number of runs - allows to configure the length of this test - it should last at least a few - tens of seconds. Allowed values [1; 32767], default 10000 - * CONFIG_EXAMPLES_OSTEST_RR_RUNS - During round-robin scheduling test two threads are created. Each of the threads - searches for prime numbers in the configurable range, doing that configurable - number of times. - -examples/pashello -^^^^^^^^^^^^^^^^^ - - This is "Hello, World" implemented via the Pascal P-Code interpreter. In - order to use this example, you must first download and install the - NuttX pascal module. After unpacking the pascal module, you can find - installation instructions in pascal/nuttx/README.txt. - - The correct install location for the NuttX examples and build files is - apps/interpreters. - -examples/pipe -^^^^^^^^^^^^^ - - A test of the mkfifo() and pipe() APIs. - - * CONFIG_EXAMPLES_PIPE_STACKSIZE - Sets the size of the stack to use when creating the child tasks. - The default size is 1024. - -examples/poll -^^^^^^^^^^^^^ - - A test of the poll() and select() APIs using FIFOs and, if available, - stdin, and a TCP/IP socket. In order to build this test, you must the - following selected in your NuttX configuration file: - - CONFIG_NFILE_DESCRIPTORS - Defined to be greater than 0 - CONFIG_DISABLE_POLL - NOT defined - - In order to use the TCP/IP select test, you have also the following - additional things selected in your NuttX configuration file: - - CONFIG_NET - Defined for general network support - CONFIG_NET_TCP - Defined for TCP/IP support - CONFIG_NSOCKET_DESCRIPTORS - Defined to be greater than 0 - CONFIG_NET_NTCP_READAHEAD_BUFFERS - Defined to be greater than zero - - CONFIG_EXAMPLES_POLL_NOMAC - (May be defined to use software assigned MAC) - CONFIG_EXAMPLES_POLL_IPADDR - Target IP address - CONFIG_EXAMPLES_POLL_DRIPADDR - Default router IP addess - CONFIG_EXAMPLES_POLL_NETMASK - Network mask - - In order to for select to work with incoming connections, you - must also select: - - CONFIG_NET_TCPBACKLOG - Incoming connections pend in a backlog until accept() is called. - - In additional to the target device-side example, there is also - a host-side application in this directory. It can be compiled under - Linux or Cygwin as follows: - - cd examples/usbserial - make -f Makefile.host TOPDIR=<nuttx-directory> TARGETIP=<target-ip> - - Where <target-ip> is the IP address of your target board. - - This will generate a small program called 'host'. Usage: - - 1. Build the examples/poll target program with TCP/IP poll support - and start the target. - - 3. Then start the host application: - - ./host - - The host and target will exchange are variety of small messages. Each - message sent from the host should cause the select to return in target. - The target example should read the small message and send it back to - the host. The host should then receive the echo'ed message. - - If networking is enabled, applications using this example will need to - provide an appconfig file in the configuration driver with instruction - to build applications like: - - CONFIGURED_APPS += uiplib - -examples/posix_spawn -^^^^^^^^^^^^^^^^^^^^ - - This is a simple test of the posix_spawn() API. The example derives from - examples/elf. As a result, these tests are built using the relocatable - ELF format installed in a ROMFS file system. At run time, the test program - in the ROMFS file system is spawned using posix_spawn(). - - Requires: - - CONFIG_BINFMT_DISABLE=n - Don't disable the binary loader - CONFIG_ELF=y - Enable ELF binary loader - CONFIG_LIBC_EXECFUNCS=y - Enable support for posix_spawn - CONFIG_EXECFUNCS_SYMTAB="exports" - The name of the symbol table - created by the test. - CONFIG_EXECFUNCS_NSYMBOLS=10 - Value does not matter, it will be - corrected at runtime. - CONFIG_POSIX_SPAWN_STACKSIZE=768 - This default setting. - - Test-specific configuration options: - - CONFIG_EXAMPLES_POSIXSPAWN_DEVMINOR - The minor device number of the ROMFS - block. driver. For example, the N in /dev/ramN. Used for registering the - RAM block driver that will hold the ROMFS file system containing the ELF - executables to be tested. Default: 0 - - CONFIG_EXAMPLES_POSIXSPAWN_DEVPATH - The path to the ROMFS block driver - device. This must match EXAMPLES_POSIXSPAWN_DEVMINOR. Used for - registering the RAM block driver that will hold the ROMFS file system - containing the ELF executables to be tested. Default: "/dev/ram0" - - NOTES: - - 1. CFLAGS should be provided in CELFFLAGS. RAM and FLASH memory regions - may require long allcs. For ARM, this might be: - - CELFFLAGS = $(CFLAGS) -mlong-calls - - Similarly for C++ flags which must be provided in CXXELFFLAGS. - - 2. Your top-level nuttx/Make.defs file must also include an approproate - definition, LDELFFLAGS, to generate a relocatable ELF object. With GNU - LD, this should include '-r' and '-e main' (or _main on some platforms). - - LDELFFLAGS = -r -e main - - If you use GCC to link, you make also need to include '-nostdlib' or - '-nostartfiles' and '-nodefaultlibs'. - - 3. This example also requires genromfs. genromfs can be build as part of the - nuttx toolchain. Or can built from the genromfs sources that can be found - at misc/tools/genromfs-0.5.2.tar.gz. In any event, the PATH variable must - include the path to the genromfs executable. - - 4. ELF size: The ELF files in this example are, be default, quite large - because they include a lot of "build garbage". You can greatly reduce the - size of the ELF binaries are using the 'objcopy --strip-unneeded' command to - remove un-necessary information from the ELF files. - - 5. Simulator. You cannot use this example with the the NuttX simulator on - Cygwin. That is because the Cygwin GCC does not generate ELF file but - rather some Windows-native binary format. - - If you really want to do this, you can create a NuttX x86 buildroot toolchain - and use that be build the ELF executables for the ROMFS file system. - - 6. Linker scripts. You might also want to use a linker scripts to combine - sections better. An example linker script is at nuttx/binfmt/libelf/gnu-elf.ld. - That example might have to be tuned for your particular linker output to - position additional sections correctly. The GNU LD LDELFFLAGS then might - be: - - LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld - -examples/pwm -^^^^^^^^^^^^ - - A test of a PWM device driver. It simply enables a pulsed output for - a specified frequency and duty for a specified period of time. This - example can ONLY be built as an NSH built-in function. - - This test depends on these specific PWM/NSH configurations settings (your - specific PWM settings might require additional settings). - - CONFIG_PWM - Enables PWM support. - CONFIG_EXAMPLES_PWM_COUNT - Enabled PWM pulse count support (if the - hardware supports it). - CONFIG_NSH_BUILTIN_APPS - Build the PWM test as an NSH built-in function. - Default: Not built! The example can only be used as an NSH built-in - application - - Specific configuration options for this example include: - - CONFIG_EXAMPLES_PWM_DEVPATH - The path to the default PWM device. Default: /dev/pwm0 - CONFIG_EXAMPLES_PWM_FREQUENCY - The initial PWM frequency. Default: 100 Hz - CONFIG_EXAMPLES_PWM_DUTYPCT - The initial PWM duty as a percentage. Default: 50% - CONFIG_EXAMPLES_PWM_DURATION - The initial PWM pulse train duration in seconds. - Used only if the current pulse count is zero (pulse count is only supported - if CONFIG_PWM_PULSECOUNT is defined). Default: 5 seconds - CONFIG_EXAMPLES_PWM_PULSECOUNT - The initial PWM pulse count. This option is - only available if CONFIG_PWM_PULSECOUNT is non-zero. Default: 0 (i.e., use - the duration, not the count). - -examples/qencoder -^^^^^^^^^^^^^^^^^ - - This example is a simple test of a Quadrature Encoder driver. It simply reads - positional data from the encoder and prints it., - - This test depends on these specific QE/NSH configurations settings (your - specific PWM settings might require additional settings). - - CONFIG_QENCODER - Enables quadrature encoder support (upper-half driver). - CONFIG_NSH_BUILTIN_APPS - Build the QE test as an NSH built-in function. - Default: Built as a standalone progrem. - - Additional configuration options will mostly likely be required for the board- - specific lower-half driver. See the README.txt file in your board configuration - directory. - - Specific configuration options for this example include: - - CONFIG_EXAMPLES_QENCODER_DEVPATH - The path to the QE device. Default: - /dev/qe0 - CONFIG_EXAMPLES_QENCODER_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_QENCODER_DELAY - This value provides the delay (in - milliseonds) between each sample. If CONFIG_NSH_BUILTIN_APPS - is defined, then this value is the default delay if no other delay is - provided on the command line. Default: 100 milliseconds - -examples/relays -^^^^^^^^^^^^^^^ - - Requires CONFIG_ARCH_RELAYS. - Contributed by Darcy Gong. - - NOTE: This test exercises internal relay driver interfaces. As such, it - relies on internal OS interfaces that are not normally available to a - user-space program. As a result, this example cannot be used if a - NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL). - -examples/rgmp -^^^^^^^^^^^^^ - - RGMP stands for RTOS and GPOS on Multi-Processor. RGMP is a project for - running GPOS and RTOS simultaneously on multi-processor platforms. You can - port your favorite RTOS to RGMP together with an unmodified Linux to form a - hybrid operating system. This makes your application able to use both RTOS - and GPOS features. - - See http://rgmp.sourceforge.net/wiki/index.php/Main_Page for further - - At present, the RGMP example folder contains only an empty rgmp_main.c file. - -examples/romfs -^^^^^^^^^^^^^^ - - This example exercises the romfs filesystem. Configuration options - include: - - * CONFIG_EXAMPLES_ROMFS_RAMDEVNO - The minor device number to use for the ROM disk. The default is - 1 (meaning /dev/ram1) - - * CONFIG_EXAMPLES_ROMFS_SECTORSIZE - The ROM disk sector size to use. Default is 64. - - * CONFIG_EXAMPLES_ROMFS_MOUNTPOINT - The location to mount the ROM disk. Deafault: "/usr/local/share" - -examples/sendmail -^^^^^^^^^^^^^^^^^ - - This examples exercises the uIP SMTP logic by sending a test message - to a selected recipient. This test can also be built to execute on - the Cygwin/Linux host environment: - - cd examples/sendmail - make -f Makefile.host TOPDIR=<nuttx-directory> - - Settings unique to this example include: - - CONFIG_EXAMPLES_SENDMAIL_NOMAC - May be defined to use software assigned MAC (optional) - CONFIG_EXAMPLES_SENDMAIL_IPADDR - Target IP address (required) - CONFIG_EXAMPLES_SENDMAIL_DRIPADDR - Default router IP addess (required) - CONFIG_EXAMPLES_SENDMAILT_NETMASK - Network mask (required) - CONFIG_EXAMPLES_SENDMAIL_RECIPIENT - The recipient of the email (required) - CONFIG_EXAMPLES_SENDMAIL_SENDER - Optional. Default: "nuttx-testing@example.com" - CONFIG_EXAMPLES_SENDMAIL_SUBJECT - Optional. Default: "Testing SMTP from NuttX" - CONFIG_EXAMPLES_SENDMAIL_BODY - Optional. Default: "Test message sent by NuttX" - - NOTE: This test has not been verified on the NuttX target environment. - As of this writing, unit-tested in the Cygwin/Linux host environment. - - NOTE 2: This sendmail example only works for the simplest of - environments. Virus protection software on your host may have - to be disabled to allow you to send messages. Only very open, - unprotected recipients can be used. Most will protect themselves - from this test email because it looks like SPAM. - - Applications using this example will need to provide an appconfig - file in the configuration driver with instruction to build applications - like: - - CONFIGURED_APPS += uiplib - CONFIGURED_APPS += smtp - -examples/serloop -^^^^^^^^^^^^^^^^ - - This is a mindlessly simple loopback test on the console. Useful - for testing new serial drivers. Configuration options include: - - * CONFIG_EXAMPLES_SERLOOP_BUFIO - Use C buffered I/O (getchar/putchar) vs. raw console I/O - (read/read). - -examples/telnetd -^^^^^^^^^^^^^^^^ - - This directory contains a functional port of the tiny uIP shell. In - the NuttX environment, the NuttShell (at apps/nshlib) supercedes this - tiny shell and also supports telnetd. - - CONFIG_EXAMPLES_TELNETD_DAEMONPRIO - Priority of the Telnet daemon. - Default: SCHED_PRIORITY_DEFAULT - CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE - Stack size allocated for the - Telnet daemon. Default: 2048 - CONFIG_EXAMPLES_TELNETD_CLIENTPRIO- Priority of the Telnet client. - Default: SCHED_PRIORITY_DEFAULT - CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE - Stack size allocated for the - Telnet client. Default: 2048 - CONFIG_EXAMPLES_TELNETD_NOMAC - If the hardware has no MAC address of its - own, define this =y to provide a bogus address for testing. - CONFIG_EXAMPLES_TELNETD_IPADDR - The target IP address. Default 10.0.0.2 - CONFIG_EXAMPLES_TELNETD_DRIPADDR - The default router address. Default - 10.0.0.1 - CONFIG_EXAMPLES_TELNETD_NETMASK - The network mask. Default: 255.255.255.0 - - The appconfig file (apps/.config) should include: - - CONFIGURED_APPS += examples/telnetd - CONFIGURED_APPS += netutils/uiplib - CONFIGURED_APPS += netutils/telnetd - - Also, make sure that you have the following set in the NuttX configuration - file or else the performance will be very bad (because there will be only - one character per TCP transfer): - - CONFIG_STDIO_BUFFER_SIZE - Some value >= 64 - CONFIG_STDIO_LINEBUFFER=y - -examples/thttpd -^^^^^^^^^^^^^^^ - - An example that builds netutils/thttpd with some simple NXFLAT - CGI programs. see configs/README.txt for most THTTPD settings. - In addition to those, this example accepts: - - CONFIG_EXAMPLES_THTTPD_NOMAC - (May be defined to use software assigned MAC) - CONFIG_EXAMPLES_THTTPD_DRIPADDR - Default router IP addess - CONFIG_EXAMPLES_THTTPD_NETMASK - Network mask - - Applications using this example will need to provide an appconfig - file in the configuration directory with instruction to build applications - like: - - CONFIGURED_APPS += uiplib - CONFIGURED_APPS += thttpd - -examples/tiff -^^^^^^^^^^^^^ - - This is a simple unit test for the TIFF creation library at apps/graphic/tiff. - It is configured to work in the Linux user-mode simulation and has not been - tested in any other environment. Since the example also depends on some - other logic to mount a file system, currently it will only work as an NSH - built-on, i.e., if the following is defined: - - CONFIG_NSH_BUILTIN_APPS=y - CONFIG_EXAMPLES_TIFF_BUILTIN=y - - At a miniumum, to run in an embedded environment, you will probably have to - change the configured paths to the TIFF files defined in the example. - - CONFIG_EXAMPLES_TIFF_OUTFILE - Name of the resulting TIFF file. Default is - "/tmp/result.tif" - CONFIG_EXAMPLES_TIFF_TMPFILE1/2 - Names of two temporaries files that - will be used in the file creation. Defaults are "/tmp/tmpfile1.dat" and - "/tmp/tmpfile2.dat" - - The following must also be defined in your apps/ configuration file: - - CONFIGURED_APPS += examples/tiff - CONFIGURED_APPS += graphics/tiff - -examples/touchscreen -^^^^^^^^^^^^^^^^^^^^ - - This configuration implements a simple touchscreen test at - apps/examples/touchscreen. This test will create an empty X11 window - and will print the touchscreen output as it is received from the - simulated touchscreen driver. - - CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN - Build the touchscreen test as - an NSH built-in function. Default: Built as a standalone problem - CONFIG_EXAMPLES_TOUCHSCREEN_MINOR - The minor device number. Minor=N - correspnds to touchscreen device /dev/input0. Note this value must - with CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH. Default 0. - CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH - The path to the touchscreen - device. This must be consistent with CONFIG_EXAMPLES_TOUCHSCREEN_MINOR. - Default: "/dev/input0" - CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES - If CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN - 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. - - The following additional configurations must be set in the NuttX - configuration file: - - CONFIG_INPUTP=y - (Plus any touchscreen-specific settings). - - The following must also be defined in your apps configuration file: - - CONFIGURED_APPS += examples/tiff - CONFIGURED_APPS += graphics/tiff - - The board-specific logic must provide the following interfaces that will - be called by the example in order to initialize and uninitialize the - touchscreen hardware: - - int arch_tcinitialize(int minor); - int arch_tcuninitialize(void); - -examples/udp -^^^^^^^^^^^^ - - This is a simple network test for verifying client- and server- - functionality over UDP. - - Applications using this example will need to provide an appconfig - file in the configuration driver with instruction to build applications - like: - - CONFIGURED_APPS += uiplib - -examples/uip -^^^^^^^^^^^^ - - This is a port of uIP tiny webserver example application. Settings - specific to this example include: - - CONFIG_EXAMPLES_UIP_NOMAC - (May be defined to use software assigned MAC) - CONFIG_EXAMPLES_UIP_IPADDR - Target IP address - CONFIG_EXAMPLES_UIP_DRIPADDR - Default router IP addess - CONFIG_EXAMPLES_UIP_NETMASK - Network mask - CONFIG_EXAMPLES_UIP_DHCPC - Select to get IP address via DHCP - - If you use DHCPC, then some special configuration network options are - required. These include: - - CONFIG_NET=y - Of course - CONFIG_NSOCKET_DESCRIPTORS - And, of course, you must allocate some - socket descriptors. - CONFIG_NET_UDP=y - UDP support is required for DHCP - (as well as various other UDP-related - configuration settings). - CONFIG_NET_BROADCAST=y - UDP broadcast support is needed. - CONFIG_NET_BUFSIZE=650 - Per RFC2131 (p. 9), the DHCP client must be - (or larger) prepared to receive DHCP messages of up to - 576 bytes (excluding Ethernet, IP, or UDP - headers and FCS). - - Other configuration items apply also to the selected webserver net utility. - Additional relevant settings for the uIP webserver net utility are: - - CONFIG_NETUTILS_HTTPDSTACKSIZE - CONFIG_NETUTILS_HTTPDFILESTATS - CONFIG_NETUTILS_HTTPDNETSTATS - - Applications using this example will need to provide an appconfig - file in the configuration driver with instruction to build applications - like: - - CONFIGURED_APPS += uiplib - CONFIGURED_APPS += dhcpc - CONFIGURED_APPS += resolv - CONFIGURED_APPS += webserver - - NOTE: This example does depend on the perl script at - nuttx/tools/mkfsdata.pl. You must have perl installed on your - development system at /usr/bin/perl. - -examples/usbserial -^^^^^^^^^^^^^^^^^^ - - TARGET CONFIGURATION: - - This is another implementation of "Hello, World" but this one uses - a USB serial driver. Configuration options can be used to simply - the test. These options include: - - CONFIG_EXAMPLES_USBSERIAL_INONLY - Only verify IN (device-to-host) data transfers. Default: both - CONFIG_EXAMPLES_USBSERIAL_OUTONLY - Only verify OUT (host-to-device) data transfers. Default: both - CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL - Send only small, single packet messages. Default: Send large and small. - CONFIG_EXAMPLES_USBSERIAL_ONLYBIG - Send only large, multi-packet messages. Default: Send large and small. - - If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB), then - the example code will also manage the USB trace output. The amount of trace output - can be controlled using: - - CONFIG_EXAMPLES_USBSERIAL_TRACEINIT - Show initialization events - CONFIG_EXAMPLES_USBSERIAL_TRACECLASS - Show class driver events - CONFIG_EXAMPLES_USBSERIAL_TRACETRANSFERS - Show data transfer events - CONFIG_EXAMPLES_USBSERIAL_TRACECONTROLLER - Show controller events - CONFIG_EXAMPLES_USBSERIAL_TRACEINTERRUPTS - Show interrupt-related events. - - Error results are always shown in the trace output - - HOST-SIDE TEST PROGRAM - - In additional to the target device-side example, there is also a - host-side application in this directory. This host side application - must be executed on a Linux host in order to perform the USBSERIAL - test. The host application can be compiled under Linux (or Cygwin?) - as follows: - - cd examples/usbserial - make -f Makefile.host TOPDIR=<nuttx-directory> - - RUNNING THE TEST - - This will generate a small program called 'host'. Usage: - - 1. Build the examples/usbserial target program and start the target. - - 2. Wait a bit, then do enter: - - dmesg - - At the end of the dmesg output, you should see the serial - device was successfully idenfied and assigned to a tty device, - probably /dev/ttyUSB0 or /dev/ttyACM0 (depending on the configured - USB serial driver). - - 3. Then start the host application: - - ./host [<tty-dev>] - - Where: - - <tty-dev> is the USB TTY device to use. The default is - "/dev/ttyUSB0" (for the PL2303 emulation) or "/dev/ttyACM0" (for - the CDC/ACM serial device). - - The host and target will exchange are variety of very small and very large - serial messages. - -examples/usbstorage -^^^^^^^^^^^^^^^^^^^ - - This example registers a block device driver, then exports the block - the device using the USB storage class driver. In order to use this - example, your board-specific logic must provide the function: - - void usbmsc_archinitialize(void); - - This function will be called by the example/usbstorage in order to - do the actual registration of the block device drivers. For examples - of the implementation of usbmsc_archinitialize() see - configs/mcu123-lpc124x/src/up_usbmsc.c or - configs/stm3210e-eval/src/usbmsc.c - - Configuration options: - - CONFIG_EXAMPLES_USBMSC_BUILTIN - This example can be built as two NSH "built-in" commands if this option - is selected: 'msconn' will connect the USB mass storage device; 'msdis' - will disconnect the USB storage device. - CONFIG_EXAMPLES_USBMSC_NLUNS - Defines the number of logical units (LUNs) exported by the USB storage - driver. Each LUN corresponds to one exported block driver (or partition - of a block driver). May be 1, 2, or 3. Default is 1. - CONFIG_EXAMPLES_USBMSC_DEVMINOR1 - The minor device number of the block driver for the first LUN. For - example, N in /dev/mmcsdN. Used for registering the block driver. Default - is zero. - CONFIG_EXAMPLES_USBMSC_DEVPATH1 - The full path to the registered block driver. Default is "/dev/mmcsd0" - CONFIG_EXAMPLES_USBMSC_DEVMINOR2 and CONFIG_EXAMPLES_USBMSC_DEVPATH2 - Similar parameters that would have to be provided if CONFIG_EXAMPLES_USBMSC_NLUNS - is 2 or 3. No defaults. - CONFIG_EXAMPLES_USBMSC_DEVMINOR3 and CONFIG_EXAMPLES_USBMSC_DEVPATH3 - Similar parameters that would have to be provided if CONFIG_EXAMPLES_USBMSC_NLUNS - is 3. No defaults. - CONFIG_EXAMPLES_USBMSC_DEBUGMM - Enables some debug tests to check for memory usage and memory leaks. - - If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB), then - the example code will also manage the USB trace output. The amount of trace output - can be controlled using: - - CONFIG_EXAMPLES_USBMSC_TRACEINIT - Show initialization events - CONFIG_EXAMPLES_USBMSC_TRACECLASS - Show class driver events - CONFIG_EXAMPLES_USBMSC_TRACETRANSFERS - Show data transfer events - CONFIG_EXAMPLES_USBMSC_TRACECONTROLLER - Show controller events - CONFIG_EXAMPLES_USBMSC_TRACEINTERRUPTS - Show interrupt-related events. - - Error results are always shown in the trace output - - NOTE 1: When built as an NSH add-on command (CONFIG_EXAMPLES_USBMSC_BUILTIN=y), - Caution should be used to assure that the SD drive (or other storage device) is - not in use when the USB storage device is configured. Specifically, the SD - driver should be unmounted like: - - nsh> mount -t vfat /dev/mmcsd0 /mnt/sdcard # Card is mounted in NSH - ... - nsh> umount /mnd/sdcard # Unmount before connecting USB!!! - nsh> msconn # Connect the USB storage device - ... - nsh> msdis # Disconnect USB storate device - nsh> mount -t vfat /dev/mmcsd0 /mnt/sdcard # Restore the mount - - Failure to do this could result in corruption of the SD card format. - - NOTE 2: This test exercises internal USB device driver interfaces. As such, - it relies on internal OS interfaces that are not normally available to a - user-space program. As a result, this example cannot be used if a - NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL). - -examples/usbterm -^^^^^^^^^^^^^^^^ - - This example implements a little USB terminal.. more of a USB "chat" - edited lines are received from the remote host connected via USB - serial and echoed out the target serial console. Edited lines from - the local target serial console are received and forwarded to the - remote host via USB serial. - - Usage: - - Build the example and load into the target FLASH - - Connect on terminal to the target RS-232 connect and configure - for 115200 8N1. For example, suppose this Tera Term on a Windows - box. - - Power up the target board - - Connect the USB to a Linux box. Use the Linux dmesg command to - assure that the connect was successful. The USB CDC ACM device - should appear as /dev/ttyACM0 - - On the Linux box, open minicom with tty=/dev/ttyACM0. - Configure minicom so that (1) local characters are echoed and (2) - so that no CR is required. - - Now what you type on the target Tera Term window should echo on - the Linux minicom window and, conversely, what you type on the - minicom winow should be echo in the target Tera Term window. - - Configuration options: - - CONFIG_EXAMPLES_USBTERM_BUILTIN - Build the usbterm example as an NSH - built-in command. NOTE: This is not fully functional as of this - writing.. It should work, but there is no mechanism in place yet - to exit the USB terminal program and return to NSH. - CONFIG_EXAMPLES_USBTERM_DEVINIT - If defined, then the example will - call a user provided function as part of its initialization: - int usbterm_devinit(void); - And another user provided function at termination: - void usbterm_devuninit(void); - CONFIG_EXAMPLES_USBTERM_BUFLEN - The size of the input and output - buffers used for receiving data. Default 256 bytes. - - If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB, or - CONFIG_USBDEV_TRACE), then the example code will also manage the USB trace - output. The amount of trace output can be controlled using: - - CONFIG_EXAMPLES_USBTERM_TRACEINIT - Show initialization events - CONFIG_EXAMPLES_USBTERM_TRACECLASS - Show class driver events - CONFIG_EXAMPLES_USBTERM_TRACETRANSFERS - Show data transfer events - CONFIG_EXAMPLES_USBTERM_TRACECONTROLLER - Show controller events - CONFIG_EXAMPLES_USBTERM_TRACEINTERRUPTS - Show interrupt-related events. - - NOTE: By default, USBterm uses readline to get data from stdin. So your - appconfig file must have the following build path: - - CONFIGURED_APPS += system/readline - - NOTE: If you use the USBterm task over a telnet NSH connection, then you - should set the following configuration item: - - CONFIG_EXAMPLES_USBTERM_FGETS=y - - By default, the USBterm client will use readline() to get characters from - the console. Readline includes and command-line editor and echos - characters received in stdin back through stdout. Neither of these - behaviors are desire-able if Telnet is used. - - Error results are always shown in the trace output - - Other relevant configuration options: CONFIG_CDCACM selected by the - Prolifics emulation (not defined) and the CDC serial implementation - (when defined). CONFIG_USBDEV_TRACE_INITIALIDSET. - -examples/watchdog -^^^^^^^^^^^^^^^^^ - - A simple test of a watchdog timer driver. Initializes starts the watchdog - timer. It pings the watchdog timer for a period of time then lets the - watchdog timer expire... resetting the CPU is successful. This - example can ONLY be built as an NSH built-in function. - - This test depends on these specific Watchdog/NSH configurations settings (your - specific watchdog hardware settings might require additional settings). - - CONFIG_WATCHDOG- Enables watchdog timer support support. - CONFIG_NSH_BUILTIN_APPS - Build the watchdog time test as an NSH - built-in function. Default: Not built! The example can only be used - as an NSH built-in application - - Specific configuration options for this example include: - - CONFIG_EXAMPLES_WATCHDOG_DEVPATH - The path to the Watchdog device. - Default: /dev/watchdog0 - CONFIG_EXAMPLES_WATCHDOG_PINGTIME - Time in milliseconds that the example - will ping the watchdog before letting the watchdog expire. Default: 5000 - milliseconds - CONFIG_EXAMPLES_WATCHDOG_PINGDELAY - Time delay between pings in - milliseconds. Default: 500 milliseconds. - CONFIG_EXAMPLES_WATCHDOG_TIMEOUT - The watchdog timeout value in - milliseconds before the watchdog timer expires. Default: 2000 - milliseconds. - -examples/wget -^^^^^^^^^^^^^ - - A simple web client example. It will obtain a file from a server using the HTTP - protocol. Settings unique to this example include: - - CONFIG_EXAMPLES_WGET_URL - The URL of the file to get - CONFIG_EXAMPLES_WGET_NOMAC - (May be defined to use software assigned MAC) - CONFIG_EXAMPLES_WGET_IPADDR - Target IP address - CONFIG_EXAMPLES_WGET_DRIPADDR - Default router IP addess - CONFIG_EXAMPLES_WGET_NETMASK - Network mask - - This example uses netutils/webclient. Additional configuration settings apply - to that code as follows (but built-in defaults are probably OK): - - CONFIG_WEBCLIENT_GETMIMETYPE, CONFIG_WEBCLIENT_MAXHTTPLINE, - CONFIG_WEBCLIENT_MAXMIMESIZE, CONFIG_WEBCLIENT_MAXHOSTNAME, - CONFIG_WEBCLIENT_MAXFILENAME - - Of course, the example also requires other settings including CONFIG_NET and - CONFIG_NET_TCP. The example also uses the uIP resolver which requires CONFIG_UDP. - - WARNNG: As of this writing, wget is untested on the target platform. At present - it has been tested only in the host-based configuration described in the following - note. The primary difference is that the target version will rely on the also - untested uIP name resolver. - - NOTE: For test purposes, this example can be built as a host-based wget function. - This can be built as follows: - - cd examples/wget - make -f Makefile.host - - Applications using this example will need to provide an appconfig - file in the configuration driver with instruction to build applications - like: - - CONFIGURED_APPS += uiplib - CONFIGURED_APPS += resolv - CONFIGURED_APPS += webclient - -examples/wget -^^^^^^^^^^^^^ - - Uses wget to get a JSON encoded file, then decodes the file. - - CONFIG_EXAMPLES_WDGETJSON_MAXSIZE - Max. JSON Buffer Size - CONFIG_EXAMPLES_EXAMPLES_WGETJSON_URL - wget URL - -examples/xmlrpc -^^^^^^^^^^^^^^^ - - This example exercises the "Embeddable Lightweight XML-RPC Server" which - is discussed at: - - http://www.drdobbs.com/web-development/an-embeddable-lightweight-xml-rpc-server/184405364 - - Configuration options: - - CONFIG_EXAMPLES_XMLRPC_BUFFERSIZE - HTTP buffer size. Default 1024 - CONFIG_EXAMPLES_XMLRPC_DHCPC - Use DHCP Client. Default n. Ignored - if CONFIG_NSH_BUILTIN_APPS is selected. - CONFIG_EXAMPLES_XMLRPC_NOMAC - Use Canned MAC Address. Defaul n. Ignored - if CONFIG_NSH_BUILTIN_APPS is selected. - CONFIG_EXAMPLES_XMLRPC_IPADDR - Target IP address. Default 0x0a000002. - Ignored if CONFIG_NSH_BUILTIN_APPS is selected. - CONFIG_EXAMPLES_XMLRPC_DRIPADDR - Default Router IP address (Gateway). - Default 0x0a000001. Ignored if CONFIG_NSH_BUILTIN_APPS is selected. - CONFIG_EXAMPLES_XMLRPC_NETMASK - Network Mask. Default 0xffffff00 - Ignored if CONFIG_NSH_BUILTIN_APPS is selected. diff --git a/apps/examples/adc/Kconfig b/apps/examples/adc/Kconfig deleted file mode 100644 index 85c875deb..000000000 --- a/apps/examples/adc/Kconfig +++ /dev/null @@ -1,37 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_ADC - bool "ADC example" - default n - depends on ADC - ---help--- - Enable the ADC example - -if EXAMPLES_ADC - -config EXAMPLES_ADC_DEVPATH - string "ADC device path" - default "/dev/adc0" - ---help--- - The default path to the ADC device. Default: /dev/adc0 - -config EXAMPLES_ADC_NSAMPLES - int "Number of Sample Groups" - default 0 - depends on !NSH_BUILTIN_APPS - ---help--- - If 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: 0 (samples - are collected indefinitely). - -config EXAMPLES_ADC_GROUPSIZE - int "Number of Samples per Group" - default 4 - ---help--- - The number of samples to read at once. Default: 4 - -endif diff --git a/apps/examples/adc/Makefile b/apps/examples/adc/Makefile deleted file mode 100644 index 3cbe843f6..000000000 --- a/apps/examples/adc/Makefile +++ /dev/null @@ -1,109 +0,0 @@ -############################################################################ -# apps/examples/adc/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(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 ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -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) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/adc/adc.h b/apps/examples/adc/adc.h deleted file mode 100644 index 2d8af87e1..000000000 --- a/apps/examples/adc/adc.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** - * examples/examples/adc/adc.h - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_ADC_ADC_H -#define __APPS_EXAMPLES_ADC_ADC_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* CONFIG_NSH_BUILTIN_APPS - Build the ADC test as an NSH built-in function. - * Default: Built as a standalone problem - * CONFIG_EXAMPLES_ADC_DEVPATH - The default path to the ADC device. Default: /dev/adc0 - * CONFIG_EXAMPLES_ADC_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS - * is defined, then the number of samples is provided on the command line - * and this value is ignored. Otherwise, this number of samples is - * collected and the program terminates. Default: Samples are collected - * indefinitely. - * CONFIG_EXAMPLES_ADC_GROUPSIZE - The number of samples to read at once. - * Default: 4 - */ - -#ifndef CONFIG_ADC -# error "ADC device support is not enabled (CONFIG_ADC)" -#endif - -#ifndef CONFIG_EXAMPLES_ADC_DEVPATH -# define CONFIG_EXAMPLES_ADC_DEVPATH "/dev/adc0" -#endif - -#ifndef CONFIG_EXAMPLES_ADC_GROUPSIZE -# define CONFIG_EXAMPLES_ADC_GROUPSIZE 4 -#endif - -/* Debug ********************************************************************/ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG -# define message(...) syslog(__VA_ARGS__) -# define msgflush() -# else -# define message(...) printf(__VA_ARGS__) -# define msgflush() fflush(stdout) -# endif -#else -# ifdef CONFIG_DEBUG -# define message syslog -# define msgflush() -# else -# define message printf -# define msgflush() fflush(stdout) -# endif -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct adc_state_s -{ - bool initialized; - FAR char *devpath; -#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES) - int count; -#endif -}; - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: adc_devinit() - * - * Description: - * Perform architecuture-specific initialization of the ADC hardware. This - * interface must be provided by all configurations using apps/examples/adc - * - ****************************************************************************/ - -int adc_devinit(void); - -#endif /* __APPS_EXAMPLES_ADC_ADC_H */ diff --git a/apps/examples/adc/adc_main.c b/apps/examples/adc/adc_main.c deleted file mode 100644 index 553658fee..000000000 --- a/apps/examples/adc/adc_main.c +++ /dev/null @@ -1,372 +0,0 @@ -/**************************************************************************** - * examples/adc/adc_main.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/analog/adc.h> - -#include "adc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Use CONFIG_EXAMPLES_ADC_NSAMPLES == 0 to mean to collect samples - * indefinitely. - */ - -#ifndef CONFIG_EXAMPLES_ADC_NSAMPLES -# define CONFIG_EXAMPLES_ADC_NSAMPLES 0 -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct adc_state_s g_adcstate; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: adc_devpath - ****************************************************************************/ - -static void adc_devpath(FAR struct adc_state_s *adc, FAR const char *devpath) -{ - /* Get rid of any old device path */ - - if (adc->devpath) - { - free(adc->devpath); - } - - /* Then set-up the new device path by copying the string */ - - adc->devpath = strdup(devpath); -} - -/**************************************************************************** - * Name: adc_help - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static void adc_help(FAR struct adc_state_s *adc) -{ - message("Usage: adc [OPTIONS]\n"); - message("\nArguments are \"sticky\". For example, once the ADC device is\n"); - message("specified, that device will be re-used until it is changed.\n"); - message("\n\"sticky\" OPTIONS include:\n"); - message(" [-p devpath] selects the ADC device. " - "Default: %s Current: %s\n", - CONFIG_EXAMPLES_ADC_DEVPATH, g_adcstate.devpath ? g_adcstate.devpath : "NONE"); - message(" [-n count] selects the samples to collect. " - "Default: 1 Current: %d\n", adc->count); - message(" [-h] shows this message and exits\n"); -} -#endif - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} -#endif - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} -#endif - -/**************************************************************************** - * Name: parse_args - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static void parse_args(FAR struct adc_state_s *adc, int argc, FAR char **argv) -{ - FAR char *ptr; - FAR char *str; - long value; - int index; - int nargs; - - for (index = 1; index < argc; ) - { - ptr = argv[index]; - if (ptr[0] != '-') - { - message("Invalid options format: %s\n", ptr); - exit(0); - } - - switch (ptr[1]) - { - case 'n': - nargs = arg_decimal(&argv[index], &value); - if (value < 0) - { - message("Count must be non-negative: %ld\n", value); - exit(1); - } - - adc->count = (uint32_t)value; - index += nargs; - break; - - case 'p': - nargs = arg_string(&argv[index], &str); - adc_devpath(adc, str); - index += nargs; - break; - - case 'h': - adc_help(adc); - exit(0); - - default: - message("Unsupported option: %s\n", ptr); - adc_help(adc); - exit(1); - } - } -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: adc_main - ****************************************************************************/ - -int adc_main(int argc, char *argv[]) -{ - struct adc_msg_s sample[CONFIG_EXAMPLES_ADC_GROUPSIZE]; - size_t readsize; - ssize_t nbytes; - int fd; - int errval = 0; - int ret; - int i; - - /* Check if we have initialized */ - - if (!g_adcstate.initialized) - { - /* Initialization of the ADC hardware is performed by logic external to - * this test. - */ - - message("adc_main: Initializing external ADC device\n"); - ret = adc_devinit(); - if (ret != OK) - { - message("adc_main: adc_devinit failed: %d\n", ret); - errval = 1; - goto errout; - } - - /* Set the default values */ - - adc_devpath(&g_adcstate, CONFIG_EXAMPLES_ADC_DEVPATH); - -#if CONFIG_EXAMPLES_ADC_NSAMPLES > 0 - g_adcstate.count = CONFIG_EXAMPLES_ADC_NSAMPLES; -#else - g_adcstate.count = 1; -#endif - g_adcstate.initialized = true; - } - - /* Parse the command line */ - -#ifdef CONFIG_NSH_BUILTIN_APPS - parse_args(&g_adcstate, argc, argv); -#endif - - /* If this example is configured as an NX add-on, then limit the number of - * samples that we collect before returning. Otherwise, we never return - */ - -#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_ADC_NSAMPLES > 0 - message("adc_main: g_adcstate.count: %d\n", g_adcstate.count); -#endif - - /* Open the ADC device for reading */ - - message("adc_main: Hardware initialized. Opening the ADC device: %s\n", - g_adcstate.devpath); - - fd = open(g_adcstate.devpath, O_RDONLY); - if (fd < 0) - { - message("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno); - errval = 2; - goto errout; - } - - /* Now loop the appropriate number of times, displaying the collected - * ADC samples. - */ - -#if defined(CONFIG_NSH_BUILTIN_APPS) - for (; g_adcstate.count > 0; g_adcstate.count--) -#elif CONFIG_EXAMPLES_ADC_NSAMPLES > 0 - for (g_adcstate.count = 0; g_adcstate.count < CONFIG_EXAMPLES_ADC_NSAMPLES; g_adcstate.count++) -#else - for (;;) -#endif - { - /* Flush any output before the loop entered or from the previous pass - * through the loop. - */ - - msgflush(); - - /* Read CONFIG_EXAMPLES_ADC_GROUPSIZE samples */ - - readsize = CONFIG_EXAMPLES_ADC_GROUPSIZE * sizeof(struct adc_msg_s); - nbytes = read(fd, sample, readsize); - - /* Handle unexpected return values */ - - if (nbytes < 0) - { - errval = errno; - if (errval != EINTR) - { - message("adc_main: read %s failed: %d\n", - g_adcstate.devpath, errval); - errval = 3; - goto errout_with_dev; - } - - message("adc_main: Interrupted read...\n"); - } - else if (nbytes == 0) - { - message("adc_main: No data read, Ignoring\n"); - } - - /* Print the sample data on successful return */ - - else - { - int nsamples = nbytes / sizeof(struct adc_msg_s); - if (nsamples * sizeof(struct adc_msg_s) != nbytes) - { - message("adc_main: read size=%d is not a multiple of sample size=%d, Ignoring\n", - nbytes, sizeof(struct adc_msg_s)); - } - else - { - message("Sample:\n"); - for (i = 0; i < nsamples ; i++) - { - message("%d: channel: %d value: %d\n", - i, sample[i].am_channel, sample[i].am_data); - } - } - } - } - - close(fd); - return OK; - - /* Error exits */ - -errout_with_dev: - close(fd); - -errout: - message("Terminating!\n"); - msgflush(); - return errval; -} diff --git a/apps/examples/buttons/Kconfig b/apps/examples/buttons/Kconfig deleted file mode 100644 index d145867fc..000000000 --- a/apps/examples/buttons/Kconfig +++ /dev/null @@ -1,63 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_BUTTONS - bool "Buttons example" - default n - ---help--- - Enable the buttons example. May require ARCH_BUTTONS on some boards. - -if EXAMPLES_BUTTONS -config EXAMPLES_BUTTONS_MIN -int "Lowest Button Number" -default 0 - -config EXAMPLES_BUTTONS_MAX -int "Highest Button Number" -default 7 - -if ARCH_IRQBUTTONS -config EXAMPLES_IRQBUTTONS_MIN -int "Lowest Interrupting Button Number" -default 0 - -config EXAMPLES_IRQBUTTONS_MAX -int "Highest Interrupting Button Number" -default 7 - -config EXAMPLES_BUTTONS_NAME0 -string "Button 0 Name" -default "Button 0" - -config EXAMPLES_BUTTONS_NAME1 -string "Button 1 Name" -default "Button 1" - -config EXAMPLES_BUTTONS_NAME2 -string "Button 2 Name" -default "Button 2" - -config EXAMPLES_BUTTONS_NAME3 -string "Button 3 Name" -default "Button 3" - -config EXAMPLES_BUTTONS_NAME4 -string "Button 4 Name" -default "Button 4" - -config EXAMPLES_BUTTONS_NAME5 -string "Button 5 Name" -default "Button 5" - -config EXAMPLES_BUTTONS_NAME6 -string "Button 6 Name" -default "Button 6" - -config EXAMPLES_BUTTONS_NAME7 -string "Button 7 Name" -default "Button 7" - -endif -endif diff --git a/apps/examples/buttons/Makefile b/apps/examples/buttons/Makefile deleted file mode 100644 index a2e8679d4..000000000 --- a/apps/examples/buttons/Makefile +++ /dev/null @@ -1,109 +0,0 @@ -############################################################################ -# apps/examples/buttons/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Hello, World! Example - -ASRCS = -CSRCS = buttons_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# 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) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/buttons/buttons_main.c b/apps/examples/buttons/buttons_main.c deleted file mode 100644 index 655080def..000000000 --- a/apps/examples/buttons/buttons_main.c +++ /dev/null @@ -1,499 +0,0 @@ -/**************************************************************************** - * examples/buttons/buttons_main.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * NOTE: This test exercises internal button driver interfaces. As such, it - * it relies on internal OS interfaces that are not normally available to a - * user-space program. As a result, this example cannot be used if a - * NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL). - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/arch.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <debug.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ - -#ifndef CONFIG_ARCH_BUTTONS -# error "CONFIG_ARCH_BUTTONS is not defined in the configuration" -#endif - -#ifndef CONFIG_EXAMPLES_BUTTONS_NAME0 -# define CONFIG_EXAMPLES_BUTTONS_NAME0 "BUTTON0" -#endif -#ifndef CONFIG_EXAMPLES_BUTTONS_NAME1 -# define CONFIG_EXAMPLES_BUTTONS_NAME1 "BUTTON1" -#endif -#ifndef CONFIG_EXAMPLES_BUTTONS_NAME2 -# define CONFIG_EXAMPLES_BUTTONS_NAME2 "BUTTON2" -#endif -#ifndef CONFIG_EXAMPLES_BUTTONS_NAME3 -# define CONFIG_EXAMPLES_BUTTONS_NAME3 "BUTTON3" -#endif -#ifndef CONFIG_EXAMPLES_BUTTONS_NAME4 -# define CONFIG_EXAMPLES_BUTTONS_NAME4 "BUTTON4" -#endif -#ifndef CONFIG_EXAMPLES_BUTTONS_NAME5 -# define CONFIG_EXAMPLES_BUTTONS_NAME5 "BUTTON5" -#endif -#ifndef CONFIG_EXAMPLES_BUTTONS_NAME6 -# define CONFIG_EXAMPLES_BUTTONS_NAME6 "BUTTON6" -#endif -#ifndef CONFIG_EXAMPLES_BUTTONS_NAME7 -# define CONFIG_EXAMPLES_BUTTONS_NAME7 "BUTTON7" -#endif - -#define BUTTON_MIN 0 -#define BUTTON_MAX 7 - -#ifndef CONFIG_EXAMPLES_BUTTONS_MIN -# define CONFIG_EXAMPLES_BUTTONS_MIN BUTTON_MIN -#endif -#ifndef CONFIG_EXAMPLES_BUTTONS_MAX -# define CONFIG_EXAMPLES_BUTTONS_MAX BUTTON_MAX -#endif - -#if CONFIG_EXAMPLES_BUTTONS_MIN > CONFIG_EXAMPLES_BUTTONS_MAX -# error "CONFIG_EXAMPLES_BUTTONS_MIN > CONFIG_EXAMPLES_BUTTONS_MAX" -#endif -#if CONFIG_EXAMPLES_BUTTONS_MAX > 7 -# error "CONFIG_EXAMPLES_BUTTONS_MAX > 7" -#endif - -#ifndef CONFIG_EXAMPLES_IRQBUTTONS_MIN -# define CONFIG_EXAMPLES_IRQBUTTONS_MIN CONFIG_EXAMPLES_BUTTONS_MIN -#endif -#ifndef CONFIG_EXAMPLES_IRQBUTTONS_MAX -# define CONFIG_EXAMPLES_IRQBUTTONS_MAX CONFIG_EXAMPLES_BUTTONS_MAX -#endif - -#if CONFIG_EXAMPLES_IRQBUTTONS_MIN > CONFIG_EXAMPLES_IRQBUTTONS_MAX -# error "CONFIG_EXAMPLES_IRQBUTTONS_MIN > CONFIG_EXAMPLES_IRQBUTTONS_MAX" -#endif -#if CONFIG_EXAMPLES_IRQBUTTONS_MAX > 7 -# error "CONFIG_EXAMPLES_IRQBUTTONS_MAX > 7" -#endif - -#ifndef MIN -# define MIN(a,b) (a < b ? a : b) -#endif -#ifndef MAX -# define MAX(a,b) (a > b ? a : b) -#endif - -#define MIN_BUTTON MIN(CONFIG_EXAMPLES_BUTTONS_MIN, CONFIG_EXAMPLES_IRQBUTTONS_MIN) -#define MAX_BUTTON MAX(CONFIG_EXAMPLES_BUTTONS_MAX, CONFIG_EXAMPLES_IRQBUTTONS_MAX) - -#define NUM_BUTTONS (MAX_BUTTON - MIN_BUTTON + 1) -#define BUTTON_INDEX(b) ((b)-MIN_BUTTON) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct button_info_s -{ - FAR const char *name; /* Name for the button */ -#ifdef CONFIG_ARCH_IRQBUTTONS - xcpt_t handler; /* Button interrupt handler */ -#endif -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void show_buttons(uint8_t oldset, uint8_t newset); - -#ifdef CONFIG_ARCH_IRQBUTTONS -static void button_handler(int id, int irq); - -#if MIN_BUTTON < 1 -static int button0_handler(int irq, FAR void *context); -#endif -#if MIN_BUTTON < 2 && MAX_BUTTON > 0 -static int button1_handler(int irq, FAR void *context); -#endif -#if MIN_BUTTON < 3 && MAX_BUTTON > 1 -static int button2_handler(int irq, FAR void *context); -#endif -#if MIN_BUTTON < 4 && MAX_BUTTON > 2 -static int button3_handler(int irq, FAR void *context); -#endif -#if MIN_BUTTON < 5 && MAX_BUTTON > 3 -static int button4_handler(int irq, FAR void *context); -#endif -#if MIN_BUTTON < 6 && MAX_BUTTON > 4 -static int button5_handler(int irq, FAR void *context); -#endif -#if MIN_BUTTON < 7 && MAX_BUTTON > 5 -static int button6_handler(int irq, FAR void *context); -#endif -#if MAX_BUTTON > 6 -static int button7_handler(int irq, FAR void *context); -#endif -#endif /* CONFIG_ARCH_IRQBUTTONS */ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - - /* Button Names */ - -static const struct button_info_s g_buttoninfo[NUM_BUTTONS] = -{ -#if MIN_BUTTON < 1 - { - CONFIG_EXAMPLES_BUTTONS_NAME0, -#ifdef CONFIG_ARCH_IRQBUTTONS - button0_handler -#endif - }, -#endif -#if MIN_BUTTON < 2 && MAX_BUTTON > 0 - { - CONFIG_EXAMPLES_BUTTONS_NAME1, -#ifdef CONFIG_ARCH_IRQBUTTONS - button1_handler -#endif - }, -#endif -#if MIN_BUTTON < 3 && MAX_BUTTON > 1 - { - CONFIG_EXAMPLES_BUTTONS_NAME2, -#ifdef CONFIG_ARCH_IRQBUTTONS - button2_handler -#endif - }, -#endif -#if MIN_BUTTON < 4 && MAX_BUTTON > 2 - { - CONFIG_EXAMPLES_BUTTONS_NAME3, -#ifdef CONFIG_ARCH_IRQBUTTONS - button3_handler -#endif - }, -#endif -#if MIN_BUTTON < 5 && MAX_BUTTON > 3 - { - CONFIG_EXAMPLES_BUTTONS_NAME4, -#ifdef CONFIG_ARCH_IRQBUTTONS - button4_handler -#endif - }, -#endif -#if MIN_BUTTON < 6 && MAX_BUTTON > 4 - { - CONFIG_EXAMPLES_BUTTONS_NAME5, -#ifdef CONFIG_ARCH_IRQBUTTONS - button5_handler -#endif - }, -#endif -#if MIN_BUTTON < 7 && MAX_BUTTON > 5 - { - CONFIG_EXAMPLES_BUTTONS_NAME6, -#ifdef CONFIG_ARCH_IRQBUTTONS - button6_handler -#endif - }, -#endif -#if MAX_BUTTON > 6 - { - CONFIG_EXAMPLES_BUTTONS_NAME7, -#ifdef CONFIG_ARCH_IRQBUTTONS - button7_handler -#endif - } -#endif -}; - -/* Last sampled button set */ - -static uint8_t g_oldset; - -/* Used to limit the number of button presses */ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static volatile long g_nbuttons; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void show_buttons(uint8_t oldset, uint8_t newset) -{ - uint8_t chgset = oldset ^ newset; - int i; - - /* Update the count of button presses shown */ - -#ifdef CONFIG_NSH_BUILTIN_APPS - if ((chgset & newset) != 0) - { - g_nbuttons++; - } -#endif - - /* Show each button state change */ - - for (i = MIN_BUTTON; i <= MAX_BUTTON; i++) - { - uint8_t mask = (1 << i); - if ((chgset & mask) != 0) - { - FAR const char *state; - - /* Get the button state */ - - if ((newset & mask) != 0) - { - state = "depressed"; - } - else - { - state = "released"; - } - - /* Use lowsyslog() because we make be executing from an - * interrupt handler. - */ - - lowsyslog(" %s %s\n", g_buttoninfo[BUTTON_INDEX(i)].name, state); - } - } -} - -#ifdef CONFIG_ARCH_IRQBUTTONS -static void button_handler(int id, int irq) -{ - uint8_t newset = up_buttons(); - - lowsyslog("IRQ:%d Button %d:%s SET:%02x:\n", - irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset); - show_buttons(g_oldset, newset); - g_oldset = newset; -} - -#if MIN_BUTTON < 1 -static int button0_handler(int irq, FAR void *context) -{ - button_handler(0, irq); - return OK; -} -#endif - -#if MIN_BUTTON < 2 && MAX_BUTTON > 0 -static int button1_handler(int irq, FAR void *context) -{ - button_handler(1, irq); - return OK; -} -#endif - -#if MIN_BUTTON < 3 && MAX_BUTTON > 1 -static int button2_handler(int irq, FAR void *context) -{ - button_handler(2, irq); - return OK; -} -#endif - -#if MIN_BUTTON < 4 && MAX_BUTTON > 2 -static int button3_handler(int irq, FAR void *context) -{ - button_handler(3, irq); - return OK; -} -#endif - -#if MIN_BUTTON < 5 && MAX_BUTTON > 3 -static int button4_handler(int irq, FAR void *context) -{ - button_handler(4, irq); - return OK; -} -#endif - -#if MIN_BUTTON < 6 && MAX_BUTTON > 4 -static int button5_handler(int irq, FAR void *context) -{ - button_handler(5, irq); - return OK; -} -#endif - -#if MIN_BUTTON < 7 && MAX_BUTTON > 5 -static int button6_handler(int irq, FAR void *context) -{ - button_handler(6, irq); - return OK; -} -#endif - -#if MAX_BUTTON > 6 -static int button7_handler(int irq, FAR void *context) -{ - button_handler(7, irq); - return OK; -} -#endif -#endif /* CONFIG_ARCH_IRQBUTTONS */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * buttons_main - ****************************************************************************/ - -int buttons_main(int argc, char *argv[]) -{ - uint8_t newset; - irqstate_t flags; - int i; - - /* If this example is configured as an NX add-on, then limit the number of - * samples that we collect before returning. Otherwise, we never return - */ - -#ifdef CONFIG_NSH_BUILTIN_APPS - long maxbuttons = 1; - g_nbuttons = 0; - if (argc > 1) - { - maxbuttons = strtol(argv[1], NULL, 10); - } - lowsyslog("maxbuttons: %d\n", maxbuttons); -#endif - - /* Initialize the button GPIOs */ - - up_buttoninit(); - - /* Register to recieve button interrupts */ - -#ifdef CONFIG_ARCH_IRQBUTTONS - for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++) - { - xcpt_t oldhandler = up_irqbutton(i, g_buttoninfo[BUTTON_INDEX(i)].handler); - - /* Use lowsyslog() for compatibility with interrrupt handler output. */ - - lowsyslog("Attached handler at %p to button %d [%s], oldhandler:%p\n", - g_buttoninfo[BUTTON_INDEX(i)].handler, i, - g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler); - - /* Some hardware multiplexes different GPIO button sources to the same - * physical interrupt. If we register multiple such multiplexed button - * interrupts, then the second registration will overwrite the first. In - * this case, the first button interrupts may be aliased to the second - * interrupt handler (or worse, could be lost). - */ - - if (oldhandler != NULL) - { - lowsyslog("WARNING: oldhandler:%p is not NULL! " - "Button events may be lost or aliased!\n", - oldhandler); - } - } -#endif - - /* Poll button state */ - - g_oldset = up_buttons(); -#ifdef CONFIG_NSH_BUILTIN_APPS - while (g_nbuttons < maxbuttons) -#else - for (;;) -#endif - { - /* Get the set of pressed and release buttons. */ - - newset = up_buttons(); - - /* Any changes from the last sample? */ - - if (newset != g_oldset) - { - /* Disable interrupts so that output here will not collide with - * output from an interrupt handler. - */ - - flags = irqsave(); - - /* Use lowsyslog() for compatibility with interrrupt handler - * output. - */ - - lowsyslog("POLL SET:%02x:\n", newset); - show_buttons(g_oldset, newset); - g_oldset = newset; - irqrestore(flags); - } - - /* Sleep a little... but not long. This will determine how fast we - * poll for button changes. - */ - - usleep(150000); /* 150 Milliseconds */ - } - - /* Un-register button handlers */ - -#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NSH_BUILTIN_APPS) - for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++) - { - (void)up_irqbutton(i, NULL); - } -#endif - - return 0; -} - diff --git a/apps/examples/can/Kconfig b/apps/examples/can/Kconfig deleted file mode 100644 index 2b4504d68..000000000 --- a/apps/examples/can/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_CAN - bool "CAN example" - default n - ---help--- - Enable the CAN example - -if EXAMPLES_CAN -endif - diff --git a/apps/examples/can/Makefile b/apps/examples/can/Makefile deleted file mode 100644 index 548c6702c..000000000 --- a/apps/examples/can/Makefile +++ /dev/null @@ -1,109 +0,0 @@ -############################################################################ -# apps/examples/can/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# NuttX NX Graphics Example. - -ASRCS = -CSRCS = can_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Touchscreen built-in application info - -APPNAME = can -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 - -# Common build - -VPATH = - -all: .built -.PHONY: context clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/can/can.h b/apps/examples/can/can.h deleted file mode 100644 index d9f9236f7..000000000 --- a/apps/examples/can/can.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * examples/examples/can/can.h - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_CAN_CAN_H -#define __APPS_EXAMPLES_CAN_CAN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* This test depends on these specific CAN configurations settings (your - * specific CAN settings might require additional settings). - * - * CONFIG_CAN - Enables CAN support. - * CONFIG_CAN_LOOPBACK - A CAN driver may or may not support a loopback - * mode for testing. The STM32 CAN driver does support loopback mode. - * - * Specific configuration options for this example include: - * - * CONFIG_NSH_BUILTIN_APPS - Build the CAN test as an NSH built-in function. - * Default: Built as a standalone problem - * CONFIG_CAN_LOOPBACK - * CONFIG_EXAMPLES_CAN_DEVPATH - The path to the CAN device. Default: /dev/can0 - * CONFIG_EXAMPLES_CAN_NMSGS - If CONFIG_NSH_BUILTIN_APPS - * is defined, then the number of loops is provided on the command line - * and this value is ignored. Otherwise, this number of CAN message is - * collected and the program terminates. Default: If built as an NSH - * built-in, the default is 32. Otherwise messages are sent and received - * indefinitely. - * CONFIG_EXAMPLES_CAN_READONLY - Only receive messages - * CONFIG_EXAMPLES_CAN_WRITEONLY - Only send messages - */ - -#ifndef CONFIG_CAN -# error "CAN device support is not enabled (CONFIG_CAN)" -#endif - -#ifndef CONFIG_CAN_LOOPBACK -# warning "CAN loopback is not enabled (CONFIG_CAN_LOOPBACK)" -#endif - -#ifndef CONFIG_EXAMPLES_CAN_DEVPATH -# define CONFIG_EXAMPLES_CAN_DEVPATH "/dev/can0" -#endif - -#if defined(CONFIG_NSH_BUILTIN_APPS) && !defined(CONFIG_EXAMPLES_CAN_NMSGS) -# define CONFIG_EXAMPLES_CAN_NMSGS 32 -#endif - -/* Debug ********************************************************************/ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG -# define message(...) syslog(__VA_ARGS__) -# define msgflush() -# else -# define message(...) printf(__VA_ARGS__) -# define msgflush() fflush(stdout) -# endif -#else -# ifdef CONFIG_DEBUG -# define message syslog -# define msgflush() -# else -# define message printf -# define msgflush() fflush(stdout) -# endif -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: can_devinit() - * - * Description: - * Perform architecuture-specific initialization of the CAN hardware. This - * interface must be provided by all configurations using apps/examples/can - * - ****************************************************************************/ - -int can_devinit(void); - -#endif /* __APPS_EXAMPLES_CAN_CAN_H */ diff --git a/apps/examples/can/can_main.c b/apps/examples/can/can_main.c deleted file mode 100644 index 482d3f438..000000000 --- a/apps/examples/can/can_main.c +++ /dev/null @@ -1,301 +0,0 @@ -/**************************************************************************** - * examples/can/can_main.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/can.h> - -#include "can.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#if defined(CONFIG_EXAMPLES_CAN_READONLY) -# undef CONFIG_EXAMPLES_CAN_WRITEONLY -# undef CONFIG_EXAMPLES_CAN_READWRITE -# define CAN_OFLAGS O_RDONLY -#elif defined(CONFIG_EXAMPLES_CAN_WRITEONLY) -# undef CONFIG_EXAMPLES_CAN_READWRITE -# define CAN_OFLAGS O_WRONLY -#else -# undef CONFIG_EXAMPLES_CAN_READWRITE -# define CONFIG_EXAMPLES_CAN_READWRITE 1 -# define CAN_OFLAGS O_RDWR -#endif - -#ifdef CONFIG_CAN_EXTID -# define MAX_ID (1 << 29) -#else -# define MAX_ID (1 << 11) -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: can_main - ****************************************************************************/ - -int can_main(int argc, char *argv[]) -{ -#ifndef CONFIG_EXAMPLES_CAN_READONLY - struct can_msg_s txmsg; -#ifdef CONFIG_CAN_EXTID - uint32_t msgid; -#else - uint16_t msgid; -#endif - int msgdlc; - uint8_t msgdata; -#endif - -#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY - struct can_msg_s rxmsg; -#endif - - size_t msgsize; - ssize_t nbytes; -#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_CAN_NMSGS) - long nmsgs; -#endif - - int fd; - int errval = 0; - int ret; - int i; - - /* If this example is configured as an NX add-on, then limit the number of - * samples that we collect before returning. Otherwise, we never return - */ - -#if defined(CONFIG_NSH_BUILTIN_APPS) - nmsgs = CONFIG_EXAMPLES_CAN_NMSGS; - if (argc > 1) - { - nmsgs = strtol(argv[1], NULL, 10); - } - message("can_main: nmsgs: %d\n", nmsgs); -#elif defined(CONFIG_EXAMPLES_CAN_NMSGS) - message("can_main: nmsgs: %d\n", CONFIG_EXAMPLES_CAN_NMSGS); -#endif - - /* Initialization of the CAN hardware is performed by logic external to - * this test. - */ - - message("can_main: Initializing external CAN device\n"); - ret = can_devinit(); - if (ret != OK) - { - message("can_main: can_devinit failed: %d\n", ret); - errval = 1; - goto errout; - } - - /* Open the CAN device for reading */ - - message("can_main: Hardware initialized. Opening the CAN device\n"); - fd = open(CONFIG_EXAMPLES_CAN_DEVPATH, CAN_OFLAGS); - if (fd < 0) - { - message("can_main: open %s failed: %d\n", - CONFIG_EXAMPLES_CAN_DEVPATH, errno); - errval = 2; - goto errout_with_dev; - } - - /* Now loop the appropriate number of times, performing one loopback test - * on each pass. - */ - -#ifndef CONFIG_EXAMPLES_CAN_READONLY - msgdlc = 1; - msgid = 1; - msgdata = 0; -#endif - -#if defined(CONFIG_NSH_BUILTIN_APPS) - for (; nmsgs > 0; nmsgs--) -#elif defined(CONFIG_EXAMPLES_CAN_NMSGS) - for (nmsgs = 0; nmsgs < CONFIG_EXAMPLES_CAN_NMSGS; nmsgs++) -#else - for (;;) -#endif - { - /* Flush any output before the loop entered or from the previous pass - * through the loop. - */ - - msgflush(); - - /* Construct the next TX message */ - -#ifndef CONFIG_EXAMPLES_CAN_READONLY - txmsg.cm_hdr.ch_id = msgid; - txmsg.cm_hdr.ch_rtr = false; - txmsg.cm_hdr.ch_dlc = msgdlc; -#ifdef CONFIG_CAN_EXTID - txmsg.cm_hdr.ch_extid = true; -#endif - - for (i = 0; i < msgdlc; i++) - { - txmsg.cm_data[i] = msgdata + i; - } - - /* Send the TX message */ - - msgsize = CAN_MSGLEN(msgdlc); - nbytes = write(fd, &txmsg, msgsize); - if (nbytes != msgsize) - { - message("ERROR: write(%d) returned %d\n", msgsize, nbytes); - errval = 3; - goto errout_with_dev; - } -#endif - -#ifdef CONFIG_EXAMPLES_CAN_WRITEONLY - message(" ID: %4d DLC: %d\n", msgid, msgdlc); -#endif - - /* Read the RX message */ - -#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY - msgsize = sizeof(struct can_msg_s); - nbytes = read(fd, &rxmsg, msgsize); - if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize) - { - message("ERROR: read(%d) returned %d\n", msgsize, nbytes); - errval = 4; - goto errout_with_dev; - } -#endif - -#ifndef CONFIG_EXAMPLES_CAN_READONLY - message(" ID: %4d DLC: %d\n", rxmsg.cm_hdr.id, rxmsg.cm_hdr.dlc); -#endif - - /* Verify that the received messages are the same */ - -#ifdef CONFIG_EXAMPLES_CAN_READWRITE - if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0) - { - message("ERROR: Sent header does not match received header:\n"); - lib_dumpbuffer("Sent header", (FAR const uint8_t*)&txmsg.cm_hdr, - sizeof(struct can_hdr_s)); - lib_dumpbuffer("Received header", (FAR const uint8_t*)&rxmsg.cm_hdr, - sizeof(struct can_hdr_s)); - errval = 4; - goto errout_with_dev; - } - - if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0) - { - message("ERROR: Data does not match. DLC=%d\n", msgdlc); - for (i = 0; i < msgdlc; i++) - { - message(" %d: TX %02x RX %02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]); - errval = 5; - goto errout_with_dev; - } - } - - /* Report success */ - - message(" ID: %4d DLC: %d -- OK\n", msgid, msgdlc); -#endif - - /* Set up for the next pass */ - -#ifndef CONFIG_EXAMPLES_CAN_READONLY - msgdata += msgdlc; - - if (++msgid >= MAX_ID) - { - msgid = 1; - } - - if (++msgdlc > CAN_MAXDATALEN) - { - msgdlc = 1; - } -#endif - } - -errout_with_dev: - close(fd); - -errout: - message("Terminating!\n"); - msgflush(); - return errval; -} diff --git a/apps/examples/cdcacm/Kconfig b/apps/examples/cdcacm/Kconfig deleted file mode 100644 index 8cd9c6e99..000000000 --- a/apps/examples/cdcacm/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_CDCACM - bool "CAN example" - default n - ---help--- - Enable the USB CDC/ACM class driver example - -if EXAMPLES_CDCACM -endif - diff --git a/apps/examples/cdcacm/Makefile b/apps/examples/cdcacm/Makefile deleted file mode 100644 index 2cf3a107f..000000000 --- a/apps/examples/cdcacm/Makefile +++ /dev/null @@ -1,117 +0,0 @@ -############################################################################ -# apps/examples/cdcacm/Makefile -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# USB CDC/ACM serial mass storage example - -ASRCS = -CSRCS = cdcacm_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# USB CDC/ACM built-in application info - -APPNAME1 = sercon -PRIORITY1 = SCHED_PRIORITY_DEFAULT -STACKSIZE1 = 2048 - -APPNAME2 = serdis -PRIORITY2 = SCHED_PRIORITY_DEFAULT -STACKSIZE2 = 2048 - -# Common build - -VPATH = - -all: .built -.PHONY: context clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(APPNAME1)_main) - -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME2),$(PRIORITY2),$(STACKSIZE2),$(APPNAME2)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep - diff --git a/apps/examples/cdcacm/cdcacm.h b/apps/examples/cdcacm/cdcacm.h deleted file mode 100644 index 1b3b2511c..000000000 --- a/apps/examples/cdcacm/cdcacm.h +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** - * examples/cdcacm/cdcacm.h - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __EXAMPLES_CDCACM_CDCACM_H -#define __EXAMPLES_CDCACM_CDCACM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/usb/usbdev_trace.h> - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* Prerequisites */ - -#ifndef CONFIG_USBDEV -# error "CONFIG_USBDEV is not defined" -#endif - -#ifndef CONFIG_CDCACM -# error "CONFIG_CDCACM is not defined" -#endif - -#ifndef CONFIG_NSH_BUILTIN_APPS -# error "This example can only be built as an NSH built-in application" -#endif - -/* Default configuration values */ - -#ifndef CONFIG_EXAMPLES_CDCACM_DEVMINOR -# define CONFIG_EXAMPLES_CDCACM_DEVMINOR 0 -#endif - -/* Trace Configuration ******************************************************/ - -#ifdef CONFIG_EXAMPLES_CDCACM_TRACEINIT -# define TRACE_INIT_BITS (TRACE_INIT_BIT) -#else -# define TRACE_INIT_BITS (0) -#endif - -#define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) - -#ifdef CONFIG_EXAMPLES_CDCACM_TRACECLASS -# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT) -#else -# define TRACE_CLASS_BITS (0) -#endif - -#ifdef CONFIG_EXAMPLES_CDCACM_TRACETRANSFERS -# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|TRACE_READ_BIT|\ - TRACE_WRITE_BIT|TRACE_COMPLETE_BIT) -#else -# define TRACE_TRANSFER_BITS (0) -#endif - -#ifdef CONFIG_EXAMPLES_CDCACM_TRACECONTROLLER -# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) -#else -# define TRACE_CONTROLLER_BITS (0) -#endif - -#ifdef CONFIG_EXAMPLES_CDCACM_TRACEINTERRUPTS -# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|TRACE_INTEXIT_BIT) -#else -# define TRACE_INTERRUPT_BITS (0) -#endif - -#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|TRACE_CLASS_BITS|\ - TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) - -/* Debug ********************************************************************/ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG -# define message(...) lowsyslog(__VA_ARGS__) -# define msgflush() -# else -# define message(...) printf(__VA_ARGS__) -# define msgflush() fflush(stdout) -# endif -#else -# ifdef CONFIG_DEBUG -# define message lowsyslog -# define msgflush() -# else -# define message printf -# define msgflush() fflush(stdout) -# endif -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* All global variables used by this example are packed into a structure in - * order to avoid name collisions. - */ - -struct cdcacm_state_s -{ - /* This is the handle that references to this particular USB storage driver - * instance. It is only needed if the USB mass storage device example is - * built using CONFIG_NSH_BUILTIN_APPS. In this case, the value - * of the driver handle must be remembered between the 'sercon' and 'msdis' - * commands. - */ - - FAR void *handle; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* All global variables used by this example are packed into a structure in - * order to avoid name collisions. - */ - -extern struct cdcacm_state_s g_cdcacm; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#endif /* __EXAMPLES_CDCACM_CDCACM_H */ diff --git a/apps/examples/cdcacm/cdcacm_main.c b/apps/examples/cdcacm/cdcacm_main.c deleted file mode 100644 index aeb7a9e74..000000000 --- a/apps/examples/cdcacm/cdcacm_main.c +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** - * examples/cdcacm/cdcacm_main.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> - -#include <stdio.h> -#include <debug.h> - -#include <nuttx/usb/usbdev.h> -#include <nuttx/usb/cdcacm.h> - -#include "cdcacm.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* All global variables used by this example are packed into a structure in - * order to avoid name collisions. - */ - -struct cdcacm_state_s g_cdcacm; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * sercon_main - * - * Description: - * This is the main program that configures the CDC/ACM serial device. - * - ****************************************************************************/ - -int sercon_main(int argc, char *argv[]) -{ - int ret; - - /* Check if there is a non-NULL USB mass storage device handle (meaning that the - * USB mass storage device is already configured). - */ - - if (g_cdcacm.handle) - { - message("sercon:: ERROR: Already connected\n"); - return EXIT_FAILURE; - } - - /* Then, in any event, enable trace data collection as configured BEFORE - * enabling the CDC/ACM device. - */ - - usbtrace_enable(TRACE_BITSET); - - /* Initialize the USB CDC/ACM serial driver */ - - message("sercon: Registering CDC/ACM serial driver\n"); - ret = cdcacm_initialize(CONFIG_EXAMPLES_CDCACM_DEVMINOR, &g_cdcacm.handle); - if (ret < 0) - { - message("sercon: ERROR: Failed to create the CDC/ACM serial device: %d\n", -ret); - return EXIT_FAILURE; - } - - message("sercon: Successfully registered the CDC/ACM serial driver\n"); - return EXIT_SUCCESS; -} - -/**************************************************************************** - * serdis_main - * - * Description: - * This is a program entry point that will disconnect the CDC/ACM serial - * device. - * - ****************************************************************************/ - -int serdis_main(int argc, char *argv[]) -{ - /* First check if the USB mass storage device is already connected */ - - if (!g_cdcacm.handle) - { - message("serdis: ERROR: Not connected\n"); - return EXIT_FAILURE; - } - - /* Then, in any event, disable trace data collection as configured BEFORE - * enabling the CDC/ACM device. - */ - - usbtrace_enable(0); - - /* Then disconnect the device and uninitialize the USB mass storage driver */ - - cdcacm_uninitialize(g_cdcacm.handle); - g_cdcacm.handle = NULL; - message("serdis: Disconnected\n"); - return EXIT_SUCCESS; -} diff --git a/apps/examples/hello/Kconfig b/apps/examples/hello/Kconfig deleted file mode 100644 index d697daa8a..000000000 --- a/apps/examples/hello/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_HELLO - bool "\"Hello, World!\" example" - default n - ---help--- - Enable the \"Hello, World!\" example - -if EXAMPLES_HELLO -endif diff --git a/apps/examples/hello/Makefile b/apps/examples/hello/Makefile deleted file mode 100644 index c3b9744d7..000000000 --- a/apps/examples/hello/Makefile +++ /dev/null @@ -1,109 +0,0 @@ -############################################################################ -# apps/examples/hello/Makefile -# -# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Hello, World! built-in application info - -APPNAME = hello -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 - -# Hello, World! Example - -ASRCS = -CSRCS = hello_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/hello/hello_main.c b/apps/examples/hello/hello_main.c deleted file mode 100644 index 229027c36..000000000 --- a/apps/examples/hello/hello_main.c +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * examples/hello/hello_main.c - * - * Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * hello_main - ****************************************************************************/ - -int hello_main(int argc, char *argv[]) -{ - printf("Hello, World!!\n"); - return 0; -} - diff --git a/apps/examples/helloxx/Kconfig b/apps/examples/helloxx/Kconfig deleted file mode 100644 index 336389d24..000000000 --- a/apps/examples/helloxx/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_HELLOXX - bool "\"Hello, World!\" C++ example" - default n - ---help--- - Enable the \"Hello, World!\" C++ example - -if EXAMPLES_HELLOXX -endif diff --git a/apps/examples/helloxx/Makefile b/apps/examples/helloxx/Makefile deleted file mode 100644 index 44d880658..000000000 --- a/apps/examples/helloxx/Makefile +++ /dev/null @@ -1,126 +0,0 @@ -############################################################################ -# apps/examples/helloxx/Makefile -# -# Copyright (C) 2009-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Hello, World! C++ Example - -ASRCS = -CSRCS = -CXXSRCS = helloxx_main.cxx - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) -CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) -OBJS = $(AOBJS) $(COBJS) $(CXXOBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -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 distclean 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) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_EXAMPLES_HELLOXX_BUILTIN),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/helloxx/helloxx_main.cxx b/apps/examples/helloxx/helloxx_main.cxx deleted file mode 100644 index 60fd0487b..000000000 --- a/apps/examples/helloxx/helloxx_main.cxx +++ /dev/null @@ -1,165 +0,0 @@ -//*************************************************************************** -// examples/helloxx/helloxx_main.cxx -// -// Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt <gnutt@nuttx.org> -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX nor the names of its contributors may be -// used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -//*************************************************************************** - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include <nuttx/config.h> - -#include <cstdio> -#include <debug.h> - -#include <nuttx/init.h> -#include <nuttx/arch.h> - -//*************************************************************************** -// Definitions -//*************************************************************************** -// Debug ******************************************************************** -// Non-standard debug that may be enabled just for testing the constructors - -#ifndef CONFIG_DEBUG -# undef CONFIG_DEBUG_CXX -#endif - -#ifdef CONFIG_DEBUG_CXX -# define cxxdbg dbg -# define cxxlldbg lldbg -# ifdef CONFIG_DEBUG_VERBOSE -# define cxxvdbg vdbg -# define cxxllvdbg llvdbg -# else -# define cxxvdbg(x...) -# define cxxllvdbg(x...) -# endif -#else -# define cxxdbg(x...) -# define cxxlldbg(x...) -# define cxxvdbg(x...) -# define cxxllvdbg(x...) -#endif - -//*************************************************************************** -// Private Classes -//*************************************************************************** - -class CHelloWorld -{ - public: - CHelloWorld(void) : mSecret(42) - { - cxxdbg("Constructor: mSecret=%d\n", mSecret); - } - - ~CHelloWorld(void) - { - cxxdbg("Destructor\n"); - } - - bool HelloWorld(void) - { - cxxdbg("HelloWorld: mSecret=%d\n", mSecret); - - if (mSecret != 42) - { - printf("CHelloWorld::HelloWorld: CONSTRUCTION FAILED!\n"); - return false; - } - else - { - printf("CHelloWorld::HelloWorld: Hello, World!!\n"); - return true; - } - } - - private: - int mSecret; -}; - -//*************************************************************************** -// Private Data -//*************************************************************************** - -// Define a statically constructed CHellowWorld instance if C++ static -// initializers are supported by the platform - -#ifdef CONFIG_HAVE_CXXINITIALIZE -static CHelloWorld g_HelloWorld; -#endif - -//*************************************************************************** -// Public Functions -//*************************************************************************** - -/**************************************************************************** - * Name: helloxx_main - ****************************************************************************/ - -int helloxx_main(int argc, char *argv[]) -{ - // If C++ initialization for static constructors is supported, then do - // that first - -#ifdef CONFIG_HAVE_CXXINITIALIZE - up_cxxinitialize(); -#endif - - // Exercise an explictly instantiated C++ object - - CHelloWorld *pHelloWorld = new CHelloWorld; - printf("helloxx_main: Saying hello from the dynamically constructed instance\n"); - pHelloWorld->HelloWorld(); - - // Exercise an C++ object instantiated on the stack - -#ifndef CONFIG_EXAMPLES_HELLOXX_NOSTACKCONST - CHelloWorld HelloWorld; - - printf("helloxx_main: Saying hello from the instance constructed on the stack\n"); - HelloWorld.HelloWorld(); -#endif - - // Exercise an statically constructed C++ object - -#ifdef CONFIG_HAVE_CXXINITIALIZE - printf("helloxx_main: Saying hello from the statically constructed instance\n"); - g_HelloWorld.HelloWorld(); -#endif - - delete pHelloWorld; - return 0; -} - diff --git a/apps/examples/lcdrw/Kconfig b/apps/examples/lcdrw/Kconfig deleted file mode 100644 index 2308ddc60..000000000 --- a/apps/examples/lcdrw/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_LCDRW - bool "LCD read/write example" - default n - ---help--- - Enable the LCD read/write example - -if EXAMPLES_LCDRW -endif diff --git a/apps/examples/mm/Kconfig b/apps/examples/mm/Kconfig deleted file mode 100644 index 81ce4c453..000000000 --- a/apps/examples/mm/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_MM - bool "Memory management example" - default n - ---help--- - Enable the memory management example - -if EXAMPLES_MM -endif diff --git a/apps/examples/mm/Makefile b/apps/examples/mm/Makefile deleted file mode 100644 index 5ba7f4eec..000000000 --- a/apps/examples/mm/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -############################################################################ -# apps/examples/mm/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Memory Management Test - -ASRCS = -CSRCS = mm_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/mm/mm_main.c b/apps/examples/mm/mm_main.c deleted file mode 100644 index 149550418..000000000 --- a/apps/examples/mm/mm_main.c +++ /dev/null @@ -1,300 +0,0 @@ -/**************************************************************************** - * examples/mm/mm_main.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <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: mm_main - ****************************************************************************/ - -int mm_main(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; -} diff --git a/apps/examples/mount/Kconfig b/apps/examples/mount/Kconfig deleted file mode 100644 index b38c4763c..000000000 --- a/apps/examples/mount/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_MOUNT - bool "File system mount example" - default n - ---help--- - Enable the file system mount example - -if EXAMPLES_MOUNT -endif diff --git a/apps/examples/mount/Makefile b/apps/examples/mount/Makefile deleted file mode 100644 index 133bdfa1f..000000000 --- a/apps/examples/mount/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -############################################################################ -# apps/Makefile -# -# Copyright (C) 2007-2008, 2010-2010, 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# mount() test - -ASRCS = -CSRCS = mount_main.c ramdisk.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/mount/mount.h b/apps/examples/mount/mount.h deleted file mode 100644 index c75686086..000000000 --- a/apps/examples/mount/mount.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** - * examples/mount/mount.h - * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __EXAMPLES_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 */ diff --git a/apps/examples/mount/mount_main.c b/apps/examples/mount/mount_main.c deleted file mode 100644 index e0eb8a615..000000000 --- a/apps/examples/mount/mount_main.c +++ /dev/null @@ -1,754 +0,0 @@ -/**************************************************************************** - * examples/mount/mount_main.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 <sys/mount.h> -#include <sys/stat.h> -#include <sys/statfs.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <dirent.h> -#include <errno.h> - -#include "mount.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define TEST_USE_STAT 1 -#define TEST_SHOW_DIRECTORIES 1 -#define TEST_USE_STATFS 1 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char g_mntdir[] = "/mnt"; -static const char g_target[] = "/mnt/fs"; -static const char g_filesystemtype[] = "vfat"; - -static const char g_testdir1[] = "/mnt/fs/TestDir"; -static const char g_testdir2[] = "/mnt/fs/NewDir1"; -static const char g_testdir3[] = "/mnt/fs/NewDir2"; -static const char g_testdir4[] = "/mnt/fs/NewDir3"; -#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME -static const char g_testfile1[] = "/mnt/fs/TestDir/TestFile.txt"; -#endif -static const char g_testfile2[] = "/mnt/fs/TestDir/WrTest1.txt"; -static const char g_testfile3[] = "/mnt/fs/NewDir1/WrTest2.txt"; -static const char g_testfile4[] = "/mnt/fs/NewDir3/Renamed.txt"; -static const char g_testmsg[] = "This is a write test"; - -static int g_nerrors = 0; - -static char g_namebuffer[256]; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - - const char g_source[] = MOUNT_DEVNAME; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#ifdef TEST_USE_STAT -static void show_stat(const char *path, struct stat *ps) -{ - printf("%s stat:\n", path); - printf("\tmode : %08x\n", ps->st_mode); - if (S_ISREG(ps->st_mode)) - { - printf("\ttype : File\n"); - } - else if (S_ISDIR(ps->st_mode)) - { - printf("\ttype : Directory\n"); - } - else if (S_ISCHR(ps->st_mode)) - { - printf("\ttype : Character driver\n"); - } - else if (S_ISBLK(ps->st_mode)) - { - printf("\ttype : Block driver\n"); - } - else - { - printf("\ttype : Unknown\n"); - } - - printf("\tsize : %d (bytes)\n", ps->st_size); - printf("\tblock size : %d (bytes)\n", ps->st_blksize); - printf("\tsize : %d (blocks)\n", ps->st_blocks); - printf("\taccess time : %d\n", ps->st_atime); - printf("\tmodify time : %d\n", ps->st_mtime); - printf("\tchange time : %d\n", ps->st_ctime); -} -#endif - -/**************************************************************************** - * Name: show_statfs - ****************************************************************************/ - -#ifdef TEST_USE_STATFS -static void show_statfs(const char *path) -{ - struct statfs buf; - int ret; - - /* Try stat() against a file or directory. It should fail with expectederror */ - - printf("show_statfs: Try statfs(%s)\n", path); - ret = statfs(path, &buf); - if (ret == 0) - { - printf("show_statfs: statfs(%s) succeeded\n", path); - printf("\tFS Type : %0x\n", buf.f_type); - printf("\tBlock size : %d\n", buf.f_bsize); - printf("\tNumber of blocks : %d\n", buf.f_blocks); - printf("\tFree blocks : %d\n", buf.f_bfree); - printf("\tFree user blocks : %d\n", buf.f_bavail); - printf("\tNumber file nodes : %d\n", buf.f_files); - printf("\tFree file nodes : %d\n", buf.f_ffree); - printf("\tFile name length : %d\n", buf.f_namelen); - } - else - { - printf("show_statfs: ERROR statfs(%s) failed with errno=%d\n", - path, errno); - g_nerrors++; - } -} -#else -# define show_statfs(p) -#endif - -/**************************************************************************** - * Name: show_directories - ****************************************************************************/ - -#ifdef TEST_SHOW_DIRECTORIES -static void show_directories(const char *path, int indent) -{ - DIR *dirp; - struct dirent *direntry; - int i; - - dirp = opendir(path); - if ( !dirp ) - { - printf("show_directories: ERROR opendir(\"%s\") failed with errno=%d\n", - path, errno); - g_nerrors++; - return; - } - - for (direntry = readdir(dirp); direntry; direntry = readdir(dirp)) - { - for (i = 0; i < 2*indent; i++) - { - putchar(' '); - } - if (DIRENT_ISDIRECTORY(direntry->d_type)) - { - char *subdir; - printf("%s/\n", direntry->d_name); - sprintf(g_namebuffer, "%s/%s", path, direntry->d_name); - subdir = strdup(g_namebuffer); - show_directories( subdir, indent + 1); - free(subdir); - } - else - { - printf("%s\n", direntry->d_name); - } - } - - closedir(dirp); -} -#else -# define show_directories(p,i) -#endif - -/**************************************************************************** - * Name: fail_read_open - ****************************************************************************/ -#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME -static void fail_read_open(const char *path, int expectederror) -{ - int fd; - - printf("fail_read_open: Try open(%s) for reading\n", path); - - fd = open(path, O_RDONLY); - if (fd >= 0) - { - printf("fail_read_open: ERROR open(%s) succeeded\n", path); - g_nerrors++; - close(fd); - } - else if (errno != expectederror) - { - printf("fail_read_open: ERROR open(%s) failed with errno=%d (expected %d)\n", - path, errno, expectederror); - g_nerrors++; - } -} -#endif - -/**************************************************************************** - * Name: read_test_file - ****************************************************************************/ - -static void read_test_file(const char *path) -{ - char buffer[128]; - int nbytes; - int fd; - - /* Read a test file that is already on the test file system image */ - - printf("read_test_file: opening %s for reading\n", path); - - fd = open(path, O_RDONLY); - if (fd < 0) - { - printf("read_test_file: ERROR failed to open %s, errno=%d\n", - path, errno); - g_nerrors++; - } - else - { - memset(buffer, 0, 128); - nbytes = read(fd, buffer, 128); - if (nbytes < 0) - { - printf("read_test_file: ERROR failed to read from %s, errno=%d\n", - path, errno); - g_nerrors++; - } - else - { - buffer[127]='\0'; - printf("read_test_file: Read \"%s\" from %s\n", buffer, path); - } - close(fd); - } -} - -/**************************************************************************** - * Name: write_test_file - ****************************************************************************/ - -static void write_test_file(const char *path) -{ - int fd; - - /* Write a test file into a pre-existing file on the test file system */ - - printf("write_test_file: opening %s for writing\n", path); - - fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (fd < 0) - { - printf("write_test_file: ERROR failed to open %s for writing, errno=%d\n", - path, errno); - g_nerrors++; - } - else - { - int nbytes = write(fd, g_testmsg, strlen(g_testmsg)); - if (nbytes < 0) - { - printf("write_test_file: ERROR failed to write to %s, errno=%d\n", - path, errno); - g_nerrors++; - } - else - { - printf("write_test_file: wrote %d bytes to %s\n", nbytes, path); - } - close(fd); - } -} - -/**************************************************************************** - * Name: fail_mkdir - ****************************************************************************/ - -static void fail_mkdir(const char *path, int expectederror) -{ - int ret; - - /* Try mkdir() against a file or directory. It should fail with expectederror */ - - printf("fail_mkdir: Try mkdir(%s)\n", path); - - ret = mkdir(path, 0666); - if (ret == 0) - { - printf("fail_mkdir: ERROR mkdir(%s) succeeded\n", path); - g_nerrors++; - } - else if (errno != expectederror) - { - printf("fail_mkdir: ERROR mkdir(%s) failed with errno=%d (expected %d)\n", - path, errno, expectederror); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: succeed_mkdir - ****************************************************************************/ - -static void succeed_mkdir(const char *path) -{ - int ret; - - printf("succeed_mkdir: Try mkdir(%s)\n", path); - - ret = mkdir(path, 0666); - if (ret != 0) - { - printf("succeed_mkdir: ERROR mkdir(%s) failed with errno=%d\n", - path, errno); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: fail_rmdir - ****************************************************************************/ - -static void fail_rmdir(const char *path, int expectederror) -{ - int ret; - - /* Try rmdir() against a file or directory. It should fail with expectederror */ - - printf("fail_rmdir: Try rmdir(%s)\n", path); - - ret = rmdir(path); - if (ret == 0) - { - printf("fail_rmdir: ERROR rmdir(%s) succeeded\n", path); - g_nerrors++; - } - else if (errno != expectederror) - { - printf("fail_rmdir: ERROR rmdir(%s) failed with errno=%d (expected %d)\n", - path, errno, expectederror); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: succeed_rmdir - ****************************************************************************/ - -static void succeed_rmdir(const char *path) -{ - int ret; - - printf("succeed_rmdir: Try rmdir(%s)\n", path); - - ret = rmdir(path); - if (ret != 0) - { - printf("succeed_rmdir: ERROR rmdir(%s) failed with errno=%d\n", - path, errno); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: fail_unlink - ****************************************************************************/ - -static void fail_unlink(const char *path, int expectederror) -{ - int ret; - - /* Try unlink() against a file or directory. It should fail with expectederror */ - - printf("fail_unlink: Try unlink(%s)\n", path); - - ret = unlink(path); - if (ret == 0) - { - printf("fail_unlink: ERROR unlink(%s) succeeded\n", path); - g_nerrors++; - } - else if (errno != expectederror) - { - printf("fail_unlink: ERROR unlink(%s) failed with errno=%d (expected %d)\n", - path, errno, expectederror); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: succeed_unlink - ****************************************************************************/ - -static void succeed_unlink(const char *path) -{ - int ret; - - /* Try unlink() against the test file. It should succeed. */ - - printf("succeed_unlink: Try unlink(%s)\n", path); - - ret = unlink(path); - if (ret != 0) - { - printf("succeed_unlink: ERROR unlink(%s) failed with errno=%d\n", - path, errno); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: fail_rename - ****************************************************************************/ - -static void fail_rename(const char *oldpath, const char *newpath, int expectederror) -{ - int ret; - - /* Try rename() against a file or directory. It should fail with expectederror */ - - printf("fail_rename: Try rename(%s->%s)\n", oldpath, newpath); - - ret = rename(oldpath, newpath); - if (ret == 0) - { - printf("fail_rename: ERROR rename(%s->%s) succeeded\n", - oldpath, newpath); - g_nerrors++; - } - else if (errno != expectederror) - { - printf("fail_rename: ERROR rename(%s->%s) failed with errno=%d (expected %d)\n", - oldpath, newpath, errno, expectederror); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: succeed_rename - ****************************************************************************/ - -static void succeed_rename(const char *oldpath, const char *newpath) -{ - int ret; - - printf("succeed_rename: Try rename(%s->%s)\n", oldpath, newpath); - - ret = rename(oldpath, newpath); - if (ret != 0) - { - printf("succeed_rename: ERROR rename(%s->%s) failed with errno=%d\n", - oldpath, newpath, errno); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: fail_stat - ****************************************************************************/ - -#ifdef TEST_USE_STAT -static void fail_stat(const char *path, int expectederror) -{ - struct stat buf; - int ret; - - /* Try stat() against a file or directory. It should fail with expectederror */ - - printf("fail_stat: Try stat(%s)\n", path); - - ret = stat(path, &buf); - if (ret == 0) - { - printf("fail_stat: ERROR stat(%s) succeeded\n", path); - show_stat(path, &buf); - g_nerrors++; - } - else if (errno != expectederror) - { - printf("fail_stat: ERROR stat(%s) failed with errno=%d (expected %d)\n", - path, errno, expectederror); - g_nerrors++; - } -} -#else -# define fail_stat(p,e); -#endif - -/**************************************************************************** - * Name: succeed_stat - ****************************************************************************/ - -#ifdef TEST_USE_STAT -static void succeed_stat(const char *path) -{ - struct stat buf; - int ret; - - printf("succeed_stat: Try stat(%s)\n", path); - - ret = stat(path, &buf); - if (ret != 0) - { - printf("succeed_stat: ERROR stat(%s) failed with errno=%d\n", - path, errno); - g_nerrors++; - } - else - { - printf("succeed_stat: stat(%s) succeeded\n", path); - show_stat(path, &buf); - } -} -#else -#define succeed_stat(p) -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mount_main - ****************************************************************************/ - -int mount_main(int argc, char *argv[]) -{ - int ret; - -#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME - /* Create a RAM disk for the test */ - - ret = create_ramdisk(); - if (ret < 0) - { - printf("mount_main: ERROR failed to create RAM disk\n"); - return 1; - } -#endif - - /* Mount the test file system (see arch/sim/src/up_deviceimage.c */ - - printf("mount_main: mounting %s filesystem at target=%s with source=%s\n", - g_filesystemtype, g_target, g_source); - - ret = mount(g_source, g_target, g_filesystemtype, 0, NULL); - printf("mount_main: mount() returned %d\n", ret); - - if (ret == 0) - { - show_statfs(g_mntdir); - show_statfs(g_target); - -#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME - /* Read a test file that is already on the test file system image */ - - show_directories("", 0); - succeed_stat(g_testfile1); - show_statfs(g_testfile1); - read_test_file(g_testfile1); -#else - /* Create the test directory that would have been on the canned filesystem */ - - succeed_mkdir(g_testdir1); - show_directories("", 0); - succeed_stat(g_testdir1); - show_statfs(g_testdir1); -#endif - - /* Write a test file into a pre-existing directory on the test file system */ - - fail_stat(g_testfile2, ENOENT); - write_test_file(g_testfile2); - show_directories("", 0); - succeed_stat(g_testfile2); - show_statfs(g_testfile2); - - /* Read the file that we just wrote */ - - read_test_file(g_testfile2); - - /* Try rmdir() against a file on the directory. It should fail with ENOTDIR */ -#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME - fail_rmdir(g_testfile1, ENOTDIR); -#endif - - /* Try rmdir() against the test directory. It should fail with ENOTEMPTY */ - - fail_rmdir(g_testdir1, ENOTEMPTY); - - /* Try unlink() against the test directory. It should fail with EISDIR */ - - fail_unlink(g_testdir1, EISDIR); - - /* Try unlink() against the test file1. It should succeed. */ -#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME - succeed_unlink(g_testfile1); - fail_stat(g_testfile1, ENOENT); - show_directories("", 0); -#endif - - /* Attempt to open testfile1 should fail with ENOENT */ -#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME - fail_read_open(g_testfile1, ENOENT); -#endif - /* Try rmdir() against the test directory. It should still fail with ENOTEMPTY */ - - fail_rmdir(g_testdir1, ENOTEMPTY); - - /* Try mkdir() against the test file2. It should fail with EEXIST. */ - - fail_mkdir(g_testfile2, EEXIST); - - /* Try unlink() against the test file2. It should succeed. */ - - succeed_unlink(g_testfile2); - show_directories("", 0); - fail_stat(g_testfile2, ENOENT); - - /* Try mkdir() against the test dir1. It should fail with EEXIST. */ - - fail_mkdir(g_testdir1, EEXIST); - - /* Try rmdir() against the test directory. mkdir should now succeed. */ - - succeed_rmdir(g_testdir1); - show_directories("", 0); - fail_stat(g_testdir1, ENOENT); - - /* Try mkdir() against the test dir2. It should succeed */ - - succeed_mkdir(g_testdir2); - show_directories("", 0); - succeed_stat(g_testdir2); - show_statfs(g_testdir2); - - /* Try mkdir() against the test dir2. It should fail with EXIST */ - - fail_mkdir(g_testdir2, EEXIST); - - /* Write a test file into a new directory on the test file system */ - - fail_stat(g_testfile3, ENOENT); - write_test_file(g_testfile3); - show_directories("", 0); - succeed_stat(g_testfile3); - show_statfs(g_testfile3); - - /* Read the file that we just wrote */ - - read_test_file(g_testfile3); - - /* Use mkdir() to create test dir3. It should succeed */ - - fail_stat(g_testdir3, ENOENT); - succeed_mkdir(g_testdir3); - show_directories("", 0); - succeed_stat(g_testdir3); - show_statfs(g_testdir3); - - /* Try rename() on the root directory. Should fail with EXDEV*/ - - fail_rename(g_target, g_testdir4, EXDEV); - - /* Try rename() to an existing directory. Should fail with EEXIST */ - - fail_rename(g_testdir2, g_testdir3, EEXIST); - - /* Try rename() to a non-existing directory. Should succeed */ - - fail_stat(g_testdir4, ENOENT); - succeed_rename(g_testdir3, g_testdir4); - show_directories("", 0); - fail_stat(g_testdir3, ENOENT); - succeed_stat(g_testdir4); - show_statfs(g_testdir4); - - /* Try rename() of file. Should work. */ - - fail_stat(g_testfile4, ENOENT); - succeed_rename(g_testfile3, g_testfile4); - show_directories("", 0); - fail_stat(g_testfile3, ENOENT); - succeed_stat(g_testfile4); - show_statfs(g_testfile4); - - /* Make sure that we can still read the renamed file */ - - read_test_file(g_testfile4); - - /* Unmount the file system */ - - printf("mount_main: Try unmount(%s)\n", g_target); - - ret = umount(g_target); - if (ret != 0) - { - printf("mount_main: ERROR umount() failed, errno %d\n", errno); - g_nerrors++; - } - - printf("mount_main: %d errors reported\n", g_nerrors); - } - - fflush(stdout); - return 0; -} diff --git a/apps/examples/mount/ramdisk.c b/apps/examples/mount/ramdisk.c deleted file mode 100644 index 83ef74e42..000000000 --- a/apps/examples/mount/ramdisk.c +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** - * examples/mount/ramdisk.c - * - * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -#include <nuttx/ramdisk.h> -#include <nuttx/fs/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 */ diff --git a/apps/examples/nsh/Kconfig b/apps/examples/nsh/Kconfig deleted file mode 100644 index 309aa925e..000000000 --- a/apps/examples/nsh/Kconfig +++ /dev/null @@ -1,15 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_NSH - bool "NuttShell (NSH) example" - default n - select NSH_LIBRARY - select SYSTEM_READLINE - ---help--- - Enable the NuttShell (NSH) example - -if EXAMPLES_NSH -endif diff --git a/apps/examples/nsh/Makefile b/apps/examples/nsh/Makefile deleted file mode 100644 index ad687958f..000000000 --- a/apps/examples/nsh/Makefile +++ /dev/null @@ -1,98 +0,0 @@ -############################################################################ -# apps/examples/nsh/Makefile -# -# Copyright (C) 2007-2008, 2010-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# NuttShell (NSH) Example - -ASRCS = -CSRCS = nsh_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -MAXOPTIMIZATION = -Os - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/nsh/nsh_main.c b/apps/examples/nsh/nsh_main.c deleted file mode 100644 index d9bfc2018..000000000 --- a/apps/examples/nsh/nsh_main.c +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** - * examples/nsh/nsh_main.c - * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/stat.h> -#include <stdint.h> -#include <stdio.h> -#include <sched.h> -#include <errno.h> - -#include <nuttx/arch.h> -#if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN) -#include <nuttx/binfmt/builtin.h> -#endif -#if defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_EXECFUNCS_SYMTAB) -#include <nuttx/binfmt/symtab.h> -#endif - -#include <apps/nsh.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* The NSH telnet console requires networking support (and TCP/IP) */ - -#ifndef CONFIG_NET -# undef CONFIG_NSH_TELNET -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* If posix_spawn() is enabled as required for CONFIG_NSH_FILE_APPS, then - * a symbol table is needed by the internals of posix_spawn(). The symbol - * table is needed to support ELF and NXFLAT binaries to dynamically link to - * the base code. However, if only the BINFS file system is supported, then - * no Makefile is needed. - * - * This is a kludge to plug the missing file system in the case where BINFS - * is used. REVISIT: This will, of course, be in the way if you want to - * support ELF or NXFLAT binaries! - */ - -#if defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_EXECFUNCS_SYMTAB) -const struct symtab_s CONFIG_EXECFUNCS_SYMTAB[1]; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_main - ****************************************************************************/ - -int nsh_main(int argc, char *argv[]) -{ - int exitval = 0; - int ret; - - /* Call all C++ static constructors */ - -#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) - up_cxxinitialize(); -#endif - - /* Make sure that we are using our symbol take */ - -#if defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_EXECFUNCS_SYMTAB) - exec_setsymtab(CONFIG_EXECFUNCS_SYMTAB, 0); -#endif - - /* Register the BINFS file system */ - -#if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN) - ret = builtin_initialize(); - if (ret < 0) - { - fprintf(stderr, "ERROR: builtin_initialize failed: %d\n", ret); - exitval = 1; - } -#endif - - /* Initialize the NSH library */ - - nsh_initialize(); - - /* If the Telnet console is selected as a front-end, then start the - * Telnet daemon. - */ - -#ifdef CONFIG_NSH_TELNET - ret = nsh_telnetstart(); - 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", ret); - exitval = 1; - } -#endif - - /* If the serial console front end is selected, then run it on this thread */ - -#ifdef CONFIG_NSH_CONSOLE - ret = nsh_consolemain(0, NULL); - - /* nsh_consolemain() should not return. So if we get here, something - * is wrong. - */ - - fprintf(stderr, "ERROR: nsh_consolemain() returned: %d\n", ret); - exitval = 1; -#endif - - return exitval; -} diff --git a/apps/examples/null/Kconfig b/apps/examples/null/Kconfig deleted file mode 100644 index 1f19dfd2c..000000000 --- a/apps/examples/null/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_NULL - bool "NULL example" - default n - ---help--- - Enable the NULL example - -if EXAMPLES_NULL -endif diff --git a/apps/examples/null/Makefile b/apps/examples/null/Makefile deleted file mode 100644 index 47ec4cdaf..000000000 --- a/apps/examples/null/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -############################################################################ -# examples/null/Makefile -# -# Copyright (C) 2007-2008, 2010-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# 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 ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/null/null_main.c b/apps/examples/null/null_main.c deleted file mode 100644 index c4624bd1d..000000000 --- a/apps/examples/null/null_main.c +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * examples/null/null_main.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 - ****************************************************************************/ - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: null_main - ****************************************************************************/ - -int null_main(int argc, char *argv[]) -{ - return 0; -} diff --git a/apps/examples/ostest/Kconfig b/apps/examples/ostest/Kconfig deleted file mode 100644 index c3fe8f21d..000000000 --- a/apps/examples/ostest/Kconfig +++ /dev/null @@ -1,69 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_OSTEST - bool "OS test example" - default n - ---help--- - Enable the OS test example - -if EXAMPLES_OSTEST - -config EXAMPLES_OSTEST_BUILTIN - bool "NSH built-in application" - default y if NSH_LIBRARY - default n if !NSH_LIBRARY - ---help--- - Build the OS test example as an NSH built-in application. - -config EXAMPLES_OSTEST_LOOPS - int "OS test loop" - default 1 - ---help--- - Used to control the number of executions of the test. If undefined, the test - executes one time. If defined to be zero, the test runs forever. - -config EXAMPLES_OSTEST_STACKSIZE - int "OS test stack size" - default 8192 - ---help--- - Size of the stack used to create the ostest task. Default is 8192. - -config EXAMPLES_OSTEST_NBARRIER_THREADS - int "Number of barrier threads" - default 8 - ---help--- - Specifies the number of threads to create in the barrier test. The default - is 8 but a smaller number may be needed on systems without sufficient memory - to start so many threads. - -config EXAMPLES_OSTEST_RR_RANGE - int "Round-robin test - end of search range" - default 10000 - range 1 32767 - ---help--- - During round-robin scheduling test two threads are created. Each of the threads - searches for prime numbers in the configurable range, doing that configurable - number of times. - - This value specifies the end of search range and together with number of runs - allows to configure the length of this test - it should last at least a few - tens of seconds. Allowed values [1; 32767], default 10000 - -config EXAMPLES_OSTEST_RR_RUNS - int "Round-robin test - number of runs" - default 10 - range 1 32767 - ---help--- - During round-robin scheduling test two threads are created. Each of the threads - searches for prime numbers in the configurable range, doing that configurable - number of times. - - This value specifies the number of times the thread searches the range for - prime numbers and together with end of search range allows to configure the - length of this test - it should last at least a few tens of seconds. Allowed - values [1; 32767], default 10 - -endif diff --git a/apps/examples/ostest/Makefile b/apps/examples/ostest/Makefile deleted file mode 100644 index 5a8ff7293..000000000 --- a/apps/examples/ostest/Makefile +++ /dev/null @@ -1,161 +0,0 @@ -############################################################################ -# apps/examples/ostest/Makefile -# -# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# ostest built-in application info - -APPNAME = ostest -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 - -# NuttX OS Test - -ASRCS = -CSRCS = ostest_main.c dev_null.c - -ifeq ($(CONFIG_ARCH_FPU),y) -CSRCS += fpu.c -endif - -ifeq ($(CONFIG_SCHED_WAITPID),y) -CSRCS += waitpid.c -endif - -ifneq ($(CONFIG_DISABLE_PTHREAD),y) -CSRCS += cancel.c cond.c mutex.c sem.c barrier.c -ifneq ($(CONFIG_RR_INTERVAL),0) -CSRCS += roundrobin.c -endif # CONFIG_RR_INTERVAL -ifeq ($(CONFIG_MUTEX_TYPES),y) -CSRCS += rmutex.c -endif # CONFIG_MUTEX_TYPES -endif # CONFIG_DISABLE_PTHREAD - -ifneq ($(CONFIG_DISABLE_SIGNALS),y) -CSRCS += sighand.c -ifneq ($(CONFIG_DISABLE_PTHREAD),y) -ifneq ($(CONFIG_DISABLE_CLOCK),y) -CSRCS += timedwait.c -endif # CONFIG_DISABLE_CLOCK -endif # CONFIG_DISABLE_PTHREAD -endif # CONFIG_DISABLE_SIGNALS - -ifneq ($(CONFIG_DISABLE_MQUEUE),y) -ifneq ($(CONFIG_DISABLE_PTHREAD),y) -CSRCS += mqueue.c -ifneq ($(CONFIG_DISABLE_CLOCK),y) -CSRCS += timedmqueue.c -endif # CONFIG_DISABLE_CLOCK -endif # CONFIG_DISABLE_PTHREAD -endif # CONFIG_DISABLE_MQUEUE - -ifneq ($(CONFIG_DISABLE_POSIX_TIMERS),y) -CSRCS += posixtimer.c -endif - -ifeq ($(CONFIG_ARCH_HAVE_VFORK),y) -CSRCS += vfork.c -endif - -ifneq ($(CONFIG_DISABLE_SIGNALS),y) -ifneq ($(CONFIG_DISABLE_PTHREAD),y) -ifeq ($(CONFIG_PRIORITY_INHERITANCE),y) -CSRCS += prioinherit.c -endif # CONFIG_PRIORITY_INHERITANCE -endif # CONFIG_DISABLE_PTHREAD -endif # CONFIG_DISABLE_SIGNALS - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_EXAMPLES_OSTEST_BUILTIN),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/ostest/barrier.c b/apps/examples/ostest/barrier.c deleted file mode 100644 index e66496f7b..000000000 --- a/apps/examples/ostest/barrier.c +++ /dev/null @@ -1,208 +0,0 @@ -/**************************************************************************** - * examples/ostest/barrier.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 <stdio.h> -#include <unistd.h> -#include <pthread.h> - -#include "ostest.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define HALF_SECOND 500000L - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static pthread_barrier_t barrier; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: barrier_func - ****************************************************************************/ - -static void *barrier_func(void *parameter) -{ - int id = (int)parameter; - int status; - - printf("barrier_func: Thread %d started\n", id); -#ifndef CONFIG_DISABLE_SIGNALS - usleep(HALF_SECOND); -#endif - - /* Wait at the barrier until all threads are synchronized. */ - - printf("barrier_func: Thread %d calling pthread_barrier_wait()\n", - id); - FFLUSH(); - status = pthread_barrier_wait(&barrier); - if (status == 0) - { - printf("barrier_func: Thread %d, back with " - "status=0 (I am not special)\n", - id, status); - } - else if (status == PTHREAD_BARRIER_SERIAL_THREAD) - { - printf("barrier_func: Thread %d, back with " - "status=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)\n", - id, status); - } - else - { - printf("barrier_func: ERROR thread %d could not get semaphore value\n", - id); - } - FFLUSH(); - -#ifndef CONFIG_DISABLE_SIGNALS - usleep(HALF_SECOND); -#endif - printf("barrier_func: Thread %d done\n", id); - FFLUSH(); - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: barrier_test - ****************************************************************************/ - -void barrier_test(void) -{ - pthread_t barrier_thread[CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS]; - pthread_addr_t result; - pthread_attr_t attr; - pthread_barrierattr_t barrierattr; - int status; - int i; - - printf("barrier_test: Initializing barrier\n"); - - status = pthread_barrierattr_init(&barrierattr); - if (status != OK) - { - printf("barrier_test: pthread_barrierattr_init failed, status=%d\n", - status); - } - - status = pthread_barrier_init(&barrier, &barrierattr, - CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS); - if (status != OK) - { - printf("barrier_test: pthread_barrierattr_init failed, status=%d\n", - status); - } - - /* Create the barrier */ - - status = pthread_barrierattr_init(&barrierattr); - - /* Start CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS thread instances */ - - status = pthread_attr_init(&attr); - if (status != OK) - { - printf("barrier_test: pthread_attr_init failed, status=%d\n", - status); - } - - for (i = 0; i < CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS; i++) - { - status = pthread_create(&barrier_thread[i], &attr, barrier_func, - (pthread_addr_t)i); - if (status != 0) - { - printf("barrier_test: Error in thread %d create, status=%d\n", - i, status); - printf("barrier_test: Test aborted with waiting threads\n"); - goto abort_test; - } - else - { - printf("barrier_test: Thread %d created\n", i); - } - } - FFLUSH(); - - /* Wait for all thread instances to complete */ - - for (i = 0; i < CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS; i++) - { - status = pthread_join(barrier_thread[i], &result); - if (status != 0) - { - printf("barrier_test: Error in thread %d join, status=%d\n", - i, status); - } - else - { - printf("barrier_test: Thread %d completed with result=%p\n", - i, result); - } - } - - /* Destroy the barrier */ - -abort_test: - status = pthread_barrier_destroy(&barrier); - if (status != OK) - { - printf("barrier_test: pthread_barrier_destroy failed, status=%d\n", - status); - } - - status = pthread_barrierattr_destroy(&barrierattr); - if (status != OK) - { - printf("barrier_test: pthread_barrierattr_destroy failed, status=%d\n", - status); - } - FFLUSH(); -} diff --git a/apps/examples/ostest/cancel.c b/apps/examples/ostest/cancel.c deleted file mode 100644 index 11981d819..000000000 --- a/apps/examples/ostest/cancel.c +++ /dev/null @@ -1,333 +0,0 @@ -/*********************************************************************** - * examples/ostest/cancel.c - * - * Copyright (C) 2007-2009 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 <stdio.h> -#include <time.h> -#include <pthread.h> -#include <errno.h> -#include "ostest.h" - -static pthread_mutex_t mutex; -static pthread_cond_t cond; - -static void *thread_waiter(void *parameter) -{ - int status; - - /* Take the mutex */ - - printf("thread_waiter: Taking mutex\n"); - status = pthread_mutex_lock(&mutex); - if (status != 0) - { - printf("thread_waiter: ERROR pthread_mutex_lock failed, status=%d\n", status); - } - - printf("thread_waiter: Starting wait for condition\n"); - - /* Are we a non-cancelable thread? Yes, set the non-cancelable state */ - - if (!parameter) - { - printf("thread_waiter: Setting non-cancelable\n"); - status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - if (status != 0) - { - printf("thread_waiter: ERROR pthread_setcancelstate failed, status=%d\n", status); - } - } - - /* The wait -- we will never awaken from this. */ - - status = pthread_cond_wait(&cond, &mutex); - if (status != 0) - { - printf("thread_waiter: ERROR pthread_cond_wait failed, status=%d\n", status); - } - - /* Release the mutex */ - - printf("thread_waiter: Releasing mutex\n"); - status = pthread_mutex_unlock(&mutex); - if (status != 0) - { - printf("thread_waiter: ERROR pthread_mutex_unlock failed, status=%d\n", status); - } - - /* Set the cancelable state */ - - printf("thread_waiter: Setting cancelable\n"); - status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - if (status != 0) - { - printf("thread_waiter: ERROR pthread_setcancelstate failed, status=%d\n", status); - } - - printf("thread_waiter: Exit with status 0x12345678\n"); - pthread_exit((pthread_addr_t)0x12345678); - return NULL; -} - -static void start_thread(pthread_t *waiter, int cancelable) -{ - pthread_attr_t attr; - int status; - - /* Initialize the mutex */ - - printf("start_thread: Initializing mutex\n"); - status = pthread_mutex_init(&mutex, NULL); - if (status != 0) - { - printf("start_thread: ERROR pthread_mutex_init failed, status=%d\n", status); - } - - /* Initialize the condition variable */ - - printf("start_thread: Initializing cond\n"); - status = pthread_cond_init(&cond, NULL); - if (status != 0) - { - printf("start_thread: ERROR pthread_cond_init failed, status=%d\n", status); - } - - /* Set up attributes */ - - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("start_thread: pthread_attr_init failed, status=%d\n", status); - } - - status = pthread_attr_setstacksize(&attr, STACKSIZE); - if (status != 0) - { - printf("start_thread: pthread_attr_setstacksize failed, status=%d\n", status); - } - - /* Start the waiter thread */ - - printf("start_thread: Starting thread\n"); - status = pthread_create(waiter, &attr, thread_waiter, (pthread_addr_t)cancelable); - if (status != 0) - { - printf("start_thread: ERROR pthread_create failed, status=%d\n", status); - } - - /* Make sure that the waiter thread gets a chance to run */ - - printf("start_thread: Yielding\n"); - pthread_yield(); -} - -static void restart_thread(pthread_t *waiter, int cancelable) -{ - int status; - - /* Destroy the condition variable */ - - printf("restart_thread: Destroying cond\n"); - status = pthread_cond_destroy(&cond); - if (status != 0) - { - printf("restart_thread: ERROR pthread_cond_destroy failed, status=%d\n", status); - } - - /* Destroy the mutex */ - - printf("restart_thread: Destroying mutex\n"); - status = pthread_cond_destroy(&cond); - if (status != 0) - { - printf("restart_thread: ERROR pthread_mutex_destroy failed, status=%d\n", status); - } - - /* Then restart the thread */ - - printf("restart_thread: Re-starting thread\n"); - start_thread(waiter, cancelable); -} - -void cancel_test(void) -{ - pthread_t waiter; - void *result; - int status; - - /* Test 1: Normal Cancel *********************************************/ - /* Start the waiter thread */ - - printf("cancel_test: Test 1: Normal Cancelation\n"); - printf("cancel_test: Starting thread\n"); - start_thread(&waiter, 1); - - /* Then cancel it. It should be in the pthread_cond_wait now */ - - printf("cancel_test: Canceling thread\n"); - status = pthread_cancel(waiter); - if (status != 0) - { - printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status); - } - - /* Then join to the thread to pick up the result (if we don't do - * we will have a memory leak!) - */ - - printf("cancel_test: Joining\n"); - status = pthread_join(waiter, &result); - if (status != 0) - { - printf("cancel_test: ERROR pthread_join failed, status=%d\n", status); - } - else - { - printf("cancel_test: waiter exited with result=%p\n", result); - if (result != PTHREAD_CANCELED) - { - printf("cancel_test: ERROR expected result=%p\n", PTHREAD_CANCELED); - } - else - { - printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n"); - } - } - - /* Test 2: Cancel Detached Thread ************************************/ - - printf("cancel_test: Test 2: Cancelation of detached thread\n"); - printf("cancel_test: Re-starting thread\n"); - restart_thread(&waiter, 1); - - /* Detach the thread */ - - status = pthread_detach(waiter); - if (status != 0) - { - printf("cancel_test: ERROR pthread_detach, status=%d\n", status); - } - - /* Then cancel it. It should be in the pthread_cond_wait now */ - - printf("cancel_test: Canceling thread\n"); - status = pthread_cancel(waiter); - if (status != 0) - { - printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status); - } - - /* Join should now fail */ - - printf("cancel_test: Joining\n"); - status = pthread_join(waiter, &result); - if (status == 0) - { - printf("cancel_test: ERROR pthread_join succeeded\n"); - } - else if (status != ESRCH) - { - printf("cancel_test: ERROR pthread_join failed but with wrong status=%d\n", status); - } - else - { - printf("cancel_test: PASS pthread_join failed with status=ESRCH\n"); - } - - /* Test 3: Non-cancelable threads ************************************/ - - printf("cancel_test: Test 3: Non-cancelable threads\n"); - printf("cancel_test: Re-starting thread (non-cancelable)\n"); - restart_thread(&waiter, 0); - - /* Then cancel it. It should be in the pthread_cond_wait now. The - * behavior here is non-standard: when the thread is at a cancelation - * point, it should be cancelable, even when cancelation is disable. - * - * The cancelation should succeed, because the cancelation is pending. - */ - - printf("cancel_test: Canceling thread\n"); - status = pthread_cancel(waiter); - if (status != 0) - { - printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status); - } - - /* Signal the thread. It should wake up and restore the cancelable state. - * When the cancelable state is re-enabled, the thread should be canceled. - */ - - status = pthread_mutex_lock(&mutex); - if (status != 0) - { - printf("cancel_test: ERROR pthread_mutex_lock failed, status=%d\n", status); - } - - status = pthread_cond_signal(&cond); - if (status != 0) - { - printf("cancel_test: ERROR pthread_cond_signal failed, status=%d\n", status); - } - - status = pthread_mutex_unlock(&mutex); - if (status != 0) - { - printf("cancel_test: ERROR pthread_mutex_unlock failed, status=%d\n", status); - } - - /* Then join to the thread to pick up the result (if we don't do - * we will have a memory leak!) - */ - - printf("cancel_test: Joining\n"); - status = pthread_join(waiter, &result); - if (status != 0) - { - printf("cancel_test: ERROR pthread_join failed, status=%d\n", status); - } - else - { - printf("cancel_test: waiter exited with result=%p\n", result); - if (result != PTHREAD_CANCELED) - { - printf("cancel_test: ERROR expected result=%p\n", PTHREAD_CANCELED); - } - else - { - printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n"); - } - } - -} diff --git a/apps/examples/ostest/cond.c b/apps/examples/ostest/cond.c deleted file mode 100644 index 96468c3e4..000000000 --- a/apps/examples/ostest/cond.c +++ /dev/null @@ -1,294 +0,0 @@ -/*********************************************************************** - * cond.c - * - * Copyright (C) 2007, 2008 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 <stdio.h> -#include <pthread.h> -#include <unistd.h> -#include "ostest.h" - -#ifndef NULL -# define NULL (void*)0 -#endif - -static volatile enum { RUNNING, MUTEX_WAIT, COND_WAIT} waiter_state; - -static pthread_mutex_t mutex; -static pthread_cond_t cond; -static volatile int data_available = 0; -static int waiter_nloops = 0; -static int waiter_waits = 0; -static int waiter_nerrors = 0; -static int signaler_nloops = 0; -static int signaler_already = 0; -static int signaler_state = 0; -static int signaler_nerrors = 0; - -static void *thread_waiter(void *parameter) -{ - int status; - - printf("waiter_thread: Started\n"); - - for(;;) - { - /* Take the mutex */ - - waiter_state = MUTEX_WAIT; - status = pthread_mutex_lock(&mutex); - waiter_state = RUNNING; - - if (status != 0) - { - printf("waiter_thread: ERROR pthread_mutex_lock failed, status=%d\n", status); - waiter_nerrors++; - } - - /* Check if data is available -- if data is not available then - * wait for it - */ - - if (!data_available) - { - /* We are higher priority than the signaler thread so the - * only time that the signaler thread will have a chance to run is when - * we are waiting for the condition variable. In this case, pthread_cond_wait - * will automatically release the mutex for the signaler (then re-acquire - * the mutex before returning. - */ - - waiter_state = COND_WAIT; - status = pthread_cond_wait(&cond, &mutex); - waiter_state = RUNNING; - - if (status != 0) - { - printf("waiter_thread: ERROR pthread_cond_wait failed, status=%d\n", status); - waiter_nerrors++; - } - waiter_waits++; - } - - /* Now data should be available */ - - if (!data_available) - { - printf("waiter_thread: ERROR data not available after wait\n"); - waiter_nerrors++; - } - - /* Clear data available */ - - data_available = 0; - - /* Release the mutex */ - - status = pthread_mutex_unlock(&mutex); - if (status != 0) - { - printf("waiter_thread: ERROR waiter: pthread_mutex_unlock failed, status=%d\n", status); - waiter_nerrors++; - } - - waiter_nloops++; - } - return NULL; -} - -static void *thread_signaler(void *parameter) -{ - int status; - int i; - - printf("thread_signaler: Started\n"); - for (i = 0; i < 32; i++) - { - /* Take the mutex. The waiter is higher priority and should - * run until it waits for the condition. So, at this point - * signaler should be waiting for the condition. - */ - - status = pthread_mutex_lock(&mutex); - if (status != 0) - { - printf("thread_signaler: ERROR pthread_mutex_lock failed, status=%d\n", status); - signaler_nerrors++; - } - - /* Verify the state */ - - if (waiter_state != COND_WAIT) - { - printf("thread_signaler: ERROR waiter state = %d != COND_WAITING\n", waiter_state); - signaler_state++; - } - - if (data_available) - { - printf("thread_signaler: ERROR data already available, waiter_state=%d\n", waiter_state); - signaler_already++; - } - - /* Set data available and signal the waiter */ - - data_available = 1; - status = pthread_cond_signal(&cond); - if (status != 0) - { - printf("thread_signaler: ERROR pthread_cond_signal failed, status=%d\n", status); - signaler_nerrors++; - } - - /* Release the mutex */ - - status = pthread_mutex_unlock(&mutex); - if (status != 0) - { - printf("thread_signaler: ERROR pthread_mutex_unlock failed, status=%d\n", status); - signaler_nerrors++; - } - - signaler_nloops++; - } - - printf("thread_signaler: Terminating\n"); - pthread_exit(NULL); - return NULL; /* Non-reachable -- needed for some compilers */ -} - -void cond_test(void) -{ - pthread_t waiter; - pthread_t signaler; - pthread_attr_t attr; -#ifdef SDCC - pthread_addr_t result; -#endif - struct sched_param sparam; - int prio_min; - int prio_max; - int prio_mid; - int status; - - /* Initialize the mutex */ - - printf("cond_test: Initializing mutex\n"); - status = pthread_mutex_init(&mutex, NULL); - if (status != 0) - { - printf("cond_test: ERROR pthread_mutex_init failed, status=%d\n", status); - } - - /* Initialize the condition variable */ - - printf("cond_test: Initializing cond\n"); - status = pthread_cond_init(&cond, NULL); - if (status != 0) - { - printf("cond_test: ERROR pthread_condinit failed, status=%d\n", status); - } - - /* Start the waiter thread at higher priority */ - - printf("cond_test: Starting waiter\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("cond_test: pthread_attr_init failed, status=%d\n", status); - } - - prio_min = sched_get_priority_min(SCHED_FIFO); - prio_max = sched_get_priority_max(SCHED_FIFO); - prio_mid = (prio_min + prio_max) / 2; - - sparam.sched_priority = prio_mid; - status = pthread_attr_setschedparam(&attr,&sparam); - if (status != OK) - { - printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("cond_test: Set thread 1 priority to %d\n", sparam.sched_priority); - } - - status = pthread_create(&waiter, &attr, thread_waiter, NULL); - if (status != 0) - { - printf("cond_test: pthread_create failed, status=%d\n", status); - } - - printf("cond_test: Starting signaler\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("cond_test: pthread_attr_init failed, status=%d\n", status); - } - - sparam.sched_priority = (prio_min + prio_mid) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); - if (status != OK) - { - printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("cond_test: Set thread 2 priority to %d\n", sparam.sched_priority); - } - - status = pthread_create(&signaler, &attr, thread_signaler, NULL); - if (status != 0) - { - printf("cond_test: pthread_create failed, status=%d\n", status); - } - - /* Wait for the threads to stop */ - -#ifdef SDCC - pthread_join(signaler, &result); -#else - pthread_join(signaler, NULL); -#endif - printf("cond_test: signaler terminated, now cancel the waiter\n"); - pthread_detach(waiter); - pthread_cancel(waiter); - - printf("cond_test: \tWaiter\tSignaler\n"); - printf("cond_test: Loops\t%d\t%d\n", waiter_nloops, signaler_nloops); - printf("cond_test: Errors\t%d\t%d\n", waiter_nerrors, signaler_nerrors); - printf("cond_test:\n"); - printf("cond_test: %d times, waiter did not have to wait for data\n", waiter_nloops - waiter_waits); - printf("cond_test: %d times, data was already available when the signaler run\n", signaler_already); - printf("cond_test: %d times, the waiter was in an unexpected state when the signaler ran\n", signaler_state); -} diff --git a/apps/examples/ostest/dev_null.c b/apps/examples/ostest/dev_null.c deleted file mode 100644 index 34508d05e..000000000 --- a/apps/examples/ostest/dev_null.c +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * examples/ostest/dev_null.c - * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include "ostest.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 - -static FAR char buffer[1024]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int dev_null(void) -{ - int nbytes; - int fd; - - fd = open("/dev/null", O_RDWR); - if (fd < 0) - { - printf("dev_null: ERROR Failed to open /dev/null\n"); - return -1; - } - - nbytes = read(fd, buffer, 1024); - if (nbytes < 0) - { - printf("dev_null: ERROR Failed to read from /dev/null\n"); - close(fd); - return -1; - } - printf("dev_null: Read %d bytes from /dev/null\n", nbytes); - - nbytes = write(fd, buffer, 1024); - if (nbytes < 0) - { - printf("dev_null: ERROR Failed to write to /dev/null\n"); - close(fd); - return -1; - } - printf("dev_null: Wrote %d bytes to /dev/null\n", nbytes); - - close(fd); - return 0; -} - -#endif /*CONFIG_NFILE_DESCRIPTORS */ diff --git a/apps/examples/ostest/fpu.c b/apps/examples/ostest/fpu.c deleted file mode 100644 index 89a1034ce..000000000 --- a/apps/examples/ostest/fpu.c +++ /dev/null @@ -1,344 +0,0 @@ -/*********************************************************************** - * apps/examples/ostest/fpu.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ***********************************************************************/ - -/*********************************************************************** - * Included Files - ***********************************************************************/ - -#include <nuttx/config.h> -#include <sys/wait.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <sched.h> - -#include "ostest.h" - -/*********************************************************************** - * Pre-processor definitions - ***********************************************************************/ -/* Configuration *******************************************************/ - -#undef HAVE_FPU -#ifdef CONFIG_ARCH_FPU -# if defined(CONFIG_EXAMPLES_OSTEST_FPUSIZE) && defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_DISABLE_SIGNALS) -# define HAVE_FPU 1 -# else -# ifndef CONFIG_EXAMPLES_OSTEST_FPUSIZE -# warning "FPU test not built; CONFIG_EXAMPLES_OSTEST_FPUSIZE not defined" -# endif -# ifndef CONFIG_SCHED_WAITPID -# warning "FPU test not built; CONFIG_SCHED_WAITPID not defined" -# endif -# ifdef CONFIG_DISABLE_SIGNALS -# warning "FPU test not built; CONFIG_DISABLE_SIGNALS defined" -# endif -# endif -#endif - -#ifdef HAVE_FPU - -#ifndef CONFIG_EXAMPLES_OSTEST_FPULOOPS -# define CONFIG_EXAMPLES_OSTEST_FPULOOPS 16 -#endif - -#ifndef CONFIG_EXAMPLES_OSTEST_FPUMSDELAY -# define CONFIG_EXAMPLES_OSTEST_FPUMSDELAY 750 -#endif - -#ifndef CONFIG_EXAMPLES_OSTEST_FPUPRIORITY -# define CONFIG_EXAMPLES_OSTEST_FPUPRIORITY SCHED_PRIORITY_DEFAULT -#endif - -#ifndef CONFIG_EXAMPLES_OSTEST_FPUSTACKSIZE -# define CONFIG_EXAMPLES_OSTEST_FPUSTACKSIZE 2048 -#endif - -/* Other defintions ****************************************************/ -/* We'll keep all data using 32-bit values only to force 32-bit alignment. - * This logic has no real notion of the underlying representation. - */ - -#define FPU_WORDSIZE ((CONFIG_EXAMPLES_OSTEST_FPUSIZE+3)>>2) -#define FPU_NTHREADS 2 - -#ifndef NULL -# define NULL (void*)0 -#endif - -/*********************************************************************** - * External Dependencies - ***********************************************************************/ -/* This test is very dependent on support provided by the chip/board- - * layer logic. In particular, it expects the following functions - * to be provided: - */ - -/* Given an array of size CONFIG_EXAMPLES_OSTEST_FPUSIZE, this function - * will return the current FPU registers. - */ - -extern void arch_getfpu(FAR uint32_t *fpusave); - -/* Given two arrays of size CONFIG_EXAMPLES_OSTEST_FPUSIZE this - * function will compare them and return true if they are identical. - */ - -extern bool arch_cmpfpu(FAR const uint32_t *fpusave1, - FAR const uint32_t *fpusave2); - -/*********************************************************************** - * Private Types - ***********************************************************************/ - -struct fpu_threaddata_s -{ - uint32_t save1[FPU_WORDSIZE]; - uint32_t save2[FPU_WORDSIZE]; - - /* These are just dummy values to force the compiler to do the - * requested floating point computations without the nonsense - * computations being optimized away. - */ - - volatile float sp1; - volatile float sp2; - volatile float sp3; - volatile float sp4; - - volatile float dp1; - volatile float dp2; - volatile float dp3; - volatile float dp4; -}; - -/*********************************************************************** - * Private Data - ***********************************************************************/ - -static uint8_t g_fpuno; -/* static */ struct fpu_threaddata_s g_fputhread[FPU_NTHREADS]; - -/*********************************************************************** - * Private Functions - ***********************************************************************/ - -static void fpu_dump(FAR uint32_t *buffer, FAR const char *msg) -{ - int i, j, k; - - printf("%s (%p):\n", msg, buffer); - for (i = 0; i < FPU_WORDSIZE; i += 8) - { - printf(" %04x: ", i); - for (j = 0; j < 8; j++) - { - k = i + j; - - if (k < FPU_WORDSIZE) - { - printf("%08x ", buffer[k]); - } - else - { - printf("\n"); - break; - } - } - printf("\n"); - } -} - -static int fpu_task(int argc, char *argv[]) -{ - FAR struct fpu_threaddata_s *fpu; - register float sp1; - register float sp2; - register float sp3; - register float sp4; - register double dp1; - register double dp2; - register double dp3; - register double dp4; - - int id; - int i; - - /* Which are we? */ - - sched_lock(); - fpu = &g_fputhread[g_fpuno]; - id = (int)(++g_fpuno); - sched_unlock(); - - /* Seed the flowing point values */ - - sp1 = (float)id; - dp1 = (double)id; - - for (i = 0; i < CONFIG_EXAMPLES_OSTEST_FPULOOPS; i++) - { - printf("FPU#%d: pass %d\n", id, i+1); - fflush(stdout); - - /* Set the FPU register save arrays to a known-but-illogical values so - * that we can verify that reading of the registers actually occurs. - */ - - memset(fpu->save1, 0xff, FPU_WORDSIZE * sizeof(uint32_t)); - memset(fpu->save2, 0xff, FPU_WORDSIZE * sizeof(uint32_t)); - - /* Prevent context switches while we set up some stuff */ - - sched_lock(); - - /* Do some trivial floating point operations that should cause some - * changes to floating point registers. First, some single preceision - * nonsense. - */ - - sp4 = (float)3.14159 * sp1; /* Multiple by Pi */ - sp3 = sp4 + (float)1.61803; /* Add the golden ratio */ - sp2 = sp3 / (float)2.71828; /* Divide by Euler's constant */ - sp1 = sp2 + (float)1.0; /* Plus one */ - - fpu->sp1 = sp1; /* Make the compiler believe that somebody cares about the result */ - fpu->sp2 = sp2; - fpu->sp3 = sp3; - fpu->sp4 = sp4; - - /* Again using double precision */ - - dp4 = (double)3.14159 * dp1; /* Multiple by Pi */ - dp3 = dp4 + (double)1.61803; /* Add the golden ratio */ - dp2 = dp3 / (double)2.71828; /* Divide by Euler's constant */ - dp1 = dp2 + (double)1.0; /* Plus one */ - - fpu->dp1 = dp1; /* Make the compiler believe that somebody cares about the result */ - fpu->dp2 = dp2; - fpu->dp3 = dp3; - fpu->dp4 = dp4; - - /* Sample the floating point registers */ - - arch_getfpu(fpu->save1); - - /* Re-read and verify the FPU registers consistently without corruption */ - - arch_getfpu(fpu->save2); - if (!arch_cmpfpu(fpu->save1, fpu->save2)) - { - printf("ERROR FPU#%d: save1 and save2 do not match\n", id); - fpu_dump(fpu->save1, "Values after math operations (save1)"); - fpu_dump(fpu->save2, "Values after verify re-read (save2)"); - return EXIT_FAILURE; - } - - /* Now unlock and sleep for a while -- this should result in some context switches */ - - sched_unlock(); - usleep(CONFIG_EXAMPLES_OSTEST_FPUMSDELAY * 1000); - - /* Several context switches should have occurred. Now verify that the floating - * point registers are still correctly set. - */ - - arch_getfpu(fpu->save2); - if (!arch_cmpfpu(fpu->save1, fpu->save2)) - { - printf("ERROR FPU#%d: save1 and save2 do not match\n", id); - fpu_dump(fpu->save1, "Values before waiting (save1)"); - fpu_dump(fpu->save2, "Values after waiting (save2)"); - return EXIT_FAILURE; - } - } - - printf("FPU#%d: Succeeded\n", id); - fflush(stdout); - return EXIT_SUCCESS; -} -#endif /* HAVE_FPU */ - -/*********************************************************************** - * Private Functions - ***********************************************************************/ - -void fpu_test(void) -{ -#ifdef HAVE_FPU - pid_t task1; - pid_t task2; - int statloc; - - /* Start two two tasks */ - - g_fpuno = 0; - printf("Starting task FPU#1\n"); - task1 = TASK_CREATE("FPU#1", CONFIG_EXAMPLES_OSTEST_FPUPRIORITY, CONFIG_EXAMPLES_OSTEST_FPUSTACKSIZE, fpu_task, NULL); - if (task1 < 0) - { - printf("fpu_test: ERROR Failed to start task FPU#1\n"); - } - else - { - printf("fpu_test: Started task FPU#1 at PID=%d\n", task1); - } - fflush(stdout); - usleep(250); - - printf("Starting task FPU#2\n"); - task2 = TASK_CREATE("FPU#2", CONFIG_EXAMPLES_OSTEST_FPUPRIORITY, CONFIG_EXAMPLES_OSTEST_FPUSTACKSIZE, fpu_task, NULL); - if (task2 < 0) - { - printf("fpu_test: ERROR Failed to start task FPU#1\n"); - } - else - { - printf("fpu_test: Started task FPU#2 at PID=%d\n", task2); - } - - /* Wait for each task to complete */ - - fflush(stdout); - (void)waitpid(task1, &statloc, 0); - (void)waitpid(task2, &statloc, 0); - -#else - printf("fpu_test: ERROR: The FPU test is not properly configured\n"); -#endif - printf("fpu_test: Returning\n"); -} diff --git a/apps/examples/ostest/mqueue.c b/apps/examples/ostest/mqueue.c deleted file mode 100644 index 39ef76a53..000000000 --- a/apps/examples/ostest/mqueue.c +++ /dev/null @@ -1,394 +0,0 @@ -/************************************************************************** - * apps/examples/ostest/mqueue.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 <stdio.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> -#include <fcntl.h> -#include <pthread.h> -#include <mqueue.h> -#include <sched.h> -#include <errno.h> - -#include "ostest.h" - -/************************************************************************** - * Private Definitions - **************************************************************************/ - -#define TEST_MESSAGE "This is a test and only a test" -#if defined(SDCC) || defined(__ZILOG__) - /* Cannot use strlen in array size */ - -# define TEST_MSGLEN (31) -#else - /* Message lenght is the size of the message plus the null terminator */ - -# define TEST_MSGLEN (strlen(TEST_MESSAGE)+1) -#endif - -#define TEST_SEND_NMSGS (10) -#ifndef CONFIG_DISABLE_SIGNALS -# define TEST_RECEIVE_NMSGS (11) -#else -# define TEST_RECEIVE_NMSGS (10) -#endif - -#define HALF_SECOND_USEC_USEC 500000L - -/************************************************************************** - * Private Types - **************************************************************************/ - -/************************************************************************** - * Private Function Prototypes - **************************************************************************/ - -/************************************************************************** - * Global Variables - **************************************************************************/ - -/************************************************************************** - * Private Variables - **************************************************************************/ - -/************************************************************************** - * Private Functions - **************************************************************************/ - -/************************************************************************** - * Public Functions - **************************************************************************/ - -static void *sender_thread(void *arg) -{ - mqd_t mqfd; - char msg_buffer[TEST_MSGLEN]; - struct mq_attr attr; - int status = 0; - int nerrors = 0; - int i; - - printf("sender_thread: Starting\n"); - - /* Fill in attributes for message queue */ - - attr.mq_maxmsg = 20; - attr.mq_msgsize = TEST_MSGLEN; - attr.mq_flags = 0; - - /* Set the flags for the open of the queue. - * Make it a blocking open on the queue, meaning it will block if - * this process tries to send to the queue and the queue is full. - * - * O_CREAT - the queue will get created if it does not already exist. - * O_WRONLY - we are only planning to write to the queue. - * - * Open the queue, and create it if the receiving process hasn't - * already created it. - */ - - mqfd = mq_open("testmq", O_WRONLY|O_CREAT, 0666, &attr); - if (mqfd < 0) - { - printf("sender_thread: ERROR mq_open failed\n"); - pthread_exit((pthread_addr_t)1); - } - - /* Fill in a test message buffer to send */ - - memcpy(msg_buffer, TEST_MESSAGE, TEST_MSGLEN); - - /* Perform the send TEST_SEND_NMSGS times */ - - for (i = 0; i < TEST_SEND_NMSGS; i++) - { - status = mq_send(mqfd, msg_buffer, TEST_MSGLEN, 42); - if (status < 0) - { - printf("sender_thread: ERROR mq_send failure=%d on msg %d\n", status, i); - nerrors++; - } - else - { - printf("sender_thread: mq_send succeeded on msg %d\n", i); - } - } - - /* Close the queue and return success */ - - if (mq_close(mqfd) < 0) - { - printf("sender_thread: ERROR mq_close failed\n"); - } - - printf("sender_thread: returning nerrors=%d\n", nerrors); - return (pthread_addr_t)nerrors; -} - -static void *receiver_thread(void *arg) -{ - mqd_t mqfd; - char msg_buffer[TEST_MSGLEN]; - struct mq_attr attr; - int nbytes; - int nerrors = 0; - int i; - - printf("receiver_thread: Starting\n"); - - /* Fill in attributes for message queue */ - - attr.mq_maxmsg = 20; - attr.mq_msgsize = TEST_MSGLEN; - attr.mq_flags = 0; - - /* Set the flags for the open of the queue. - * Make it a blocking open on the queue, meaning it will block if - * this task tries to read from the queue when the queue is empty - * - * O_CREAT - the queue will get created if it does not already exist. - * O_RDONLY - we are only planning to read from the queue. - * - * Open the queue, and create it if the sending process hasn't - * already created it. - */ - - mqfd = mq_open("testmq", O_RDONLY|O_CREAT, 0666, &attr); - if (mqfd < 0) - { - printf("receiver_thread: ERROR mq_open failed\n"); - pthread_exit((pthread_addr_t)1); - } - - /* Perform the receive TEST_RECEIVE_NMSGS times */ - - for (i = 0; i < TEST_RECEIVE_NMSGS; i++) - { - memset(msg_buffer, 0xaa, TEST_MSGLEN); - nbytes = mq_receive(mqfd, msg_buffer, TEST_MSGLEN, 0); - if (nbytes < 0) - { - /* mq_receive failed. If the error is because of EINTR then - * it is not a failure. - */ - - if (errno != EINTR) - { - printf("receiver_thread: ERROR mq_receive failure on msg %d, errno=%d\n", i, errno); - nerrors++; - } - else - { - printf("receiver_thread: mq_receive interrupted!\n"); - } - } - else if (nbytes != TEST_MSGLEN) - { - printf("receiver_thread: mq_receive return bad size %d on msg %d\n", nbytes, i); - nerrors++; - } - else if (memcmp(TEST_MESSAGE, msg_buffer, nbytes) != 0) - { - int j; - - printf("receiver_thread: mq_receive returned corrupt message on msg %d\n", i); - printf("receiver_thread: i Expected Received\n"); - - for (j = 0; j < TEST_MSGLEN-1; j++) - { - if (isprint(msg_buffer[j])) - { - printf("receiver_thread: %2d %02x (%c) %02x (%c)\n", - j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j], msg_buffer[j]); - } - else - { - printf("receiver_thread: %2d %02x (%c) %02x\n", - j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j]); - } - } - printf("receiver_thread: %2d 00 %02x\n", - j, msg_buffer[j]); - } - else - { - printf("receiver_thread: mq_receive succeeded on msg %d\n", i); - } - } - - /* Close the queue and return success */ - - if (mq_close(mqfd) < 0) - { - printf("receiver_thread: ERROR mq_close failed\n"); - nerrors++; - } - - /* Destroy the queue */ - - if (mq_unlink("testmq") < 0) - { - printf("receiver_thread: ERROR mq_close failed\n"); - nerrors++; - } - - printf("receiver_thread: returning nerrors=%d\n", nerrors); - pthread_exit((pthread_addr_t)nerrors); - return (pthread_addr_t)nerrors; -} - -void mqueue_test(void) -{ - pthread_t sender; - pthread_t receiver; - void *result; - pthread_attr_t attr; - struct sched_param sparam; - int prio_min; - int prio_max; - int prio_mid; - int status; - - /* Start the sending thread at higher priority */ - - printf("mqueue_test: Starting receiver\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("mqueue_test: pthread_attr_init failed, status=%d\n", status); - } - - status = pthread_attr_setstacksize(&attr, STACKSIZE); - if (status != 0) - { - printf("mqueue_test: pthread_attr_setstacksize failed, status=%d\n", status); - } - - prio_min = sched_get_priority_min(SCHED_FIFO); - prio_max = sched_get_priority_max(SCHED_FIFO); - prio_mid = (prio_min + prio_max) / 2; - - sparam.sched_priority = prio_mid; - status = pthread_attr_setschedparam(&attr,&sparam); - if (status != OK) - { - printf("mqueue_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("mqueue_test: Set receiver priority to %d\n", sparam.sched_priority); - } - - status = pthread_create(&receiver, &attr, receiver_thread, NULL); - if (status != 0) - { - printf("mqueue_test: pthread_create failed, status=%d\n", status); - } - - /* Start the sending thread at lower priority */ - - printf("mqueue_test: Starting sender\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("mqueue_test: pthread_attr_init failed, status=%d\n", status); - } - - status = pthread_attr_setstacksize(&attr, STACKSIZE); - if (status != 0) - { - printf("mqueue_test: pthread_attr_setstacksize failed, status=%d\n", status); - } - - sparam.sched_priority = (prio_min + prio_mid) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); - if (status != OK) - { - printf("mqueue_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("mqueue_test: Set sender thread priority to %d\n", sparam.sched_priority); - } - - status = pthread_create(&sender, &attr, sender_thread, NULL); - if (status != 0) - { - printf("mqueue_test: pthread_create failed, status=%d\n", status); - } - - printf("mqueue_test: Waiting for sender to complete\n"); - pthread_join(sender, &result); - if (result != (void*)0) - { - printf("mqueue_test: ERROR sender thread exited with %d errors\n", (int)result); - } - -#ifndef CONFIG_DISABLE_SIGNALS - /* Wake up the receiver thread with a signal */ - - printf("mqueue_test: Killing receiver\n"); - pthread_kill(receiver, 9); - - /* Wait a bit to see if the thread exits on its own */ - - usleep(HALF_SECOND_USEC_USEC); -#endif - - /* Then cancel the thread and see if it did */ - - printf("mqueue_test: Canceling receiver\n"); - status = pthread_cancel(receiver); - if (status == ESRCH) - { - printf("mqueue_test: receiver has already terminated\n"); - } - - pthread_join(receiver, &result); - if (result != (void*)0) - { - printf("mqueue_test: ERROR receiver thread exited with %d errors\n", (int)result); - } -} - - diff --git a/apps/examples/ostest/mutex.c b/apps/examples/ostest/mutex.c deleted file mode 100644 index 0b7f70daa..000000000 --- a/apps/examples/ostest/mutex.c +++ /dev/null @@ -1,142 +0,0 @@ -/*********************************************************************** - * mutex.c - * - * Copyright (C) 2007, 2008 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 <stdio.h> -#include <pthread.h> -#include "ostest.h" - -#ifndef NULL -# define NULL (void*)0 -#endif - -#define NLOOPS 32 - -static pthread_mutex_t mut; -static volatile int my_mutex = 0; -static unsigned long nloops[2] = {0, 0}; -static unsigned long nerrors[2] = {0, 0}; - -static void *thread_func(void *parameter) -{ - int id = (int)parameter; - int ndx = id - 1; - int i; - - for (nloops[ndx] = 0; nloops[ndx] < NLOOPS; nloops[ndx]++) - { - int status = pthread_mutex_lock(&mut); - if (status != 0) - { - printf("ERROR thread %d: pthread_mutex_lock failed, status=%d\n", - id, status); - } - - if (my_mutex == 1) - { - printf("ERROR thread=%d: " - "my_mutex should be zero, instead my_mutex=%d\n", - id, my_mutex); - nerrors[ndx]++; - } - - my_mutex = 1; - for (i = 0; i < 10; i++) - { - pthread_yield(); - } - my_mutex = 0; - - status = pthread_mutex_unlock(&mut); - if (status != 0) - { - printf("ERROR thread %d: pthread_mutex_unlock failed, status=%d\n", - id, status); - } - } - pthread_exit(NULL); - return NULL; /* Non-reachable -- needed for some compilers */ -} - -void mutex_test(void) -{ - pthread_t thread1, thread2; -#ifdef SDCC - pthread_addr_t result1, result2; - pthread_attr_t attr; -#endif - int status; - - /* Initialize the mutex */ - - printf("Initializing mutex\n"); - pthread_mutex_init(&mut, NULL); - - /* Start two thread instances */ - - printf("Starting thread 1\n"); -#ifdef SDCC - (void)pthread_attr_init(&attr); - status = pthread_create(&thread1, &attr, thread_func, (pthread_addr_t)1); -#else - status = pthread_create(&thread1, NULL, thread_func, (pthread_addr_t)1); -#endif - if (status != 0) - { - printf("Error in thread#1 creation\n"); - } - - printf("Starting thread 2\n"); -#ifdef SDCC - status = pthread_create(&thread2, &attr, thread_func, (pthread_addr_t)2); -#else - status = pthread_create(&thread2, NULL, thread_func, (pthread_addr_t)2); -#endif - if (status != 0) - { - printf("Error in thread#2 creation\n"); - } - -#ifdef SDCC - pthread_join(thread1, &result1); - pthread_join(thread2, &result2); -#else - pthread_join(thread1, NULL); - pthread_join(thread2, NULL); -#endif - - printf("\t\tThread1\tThread2\n"); - printf("\tLoops\t%ld\t%ld\n", nloops[0], nloops[1]); - printf("\tErrors\t%ld\t%ld\n", nerrors[0], nerrors[1]); -} diff --git a/apps/examples/ostest/ostest.h b/apps/examples/ostest/ostest.h deleted file mode 100644 index 5217f0a0c..000000000 --- a/apps/examples/ostest/ostest.h +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** - * apps/examples/ostest/ostest.h - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_OSTEST_OSTEST_H -#define __APPS_EXAMPLES_OSTEST_OSTEST_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/* The task_create task size can be specified in the defconfig file */ - -#ifdef CONFIG_EXAMPLES_OSTEST_STACKSIZE -# define STACKSIZE CONFIG_EXAMPLES_OSTEST_STACKSIZE -#else -# define STACKSIZE 8192 -#endif - -/* The number of times to execute the test can be specified in the defconfig - * file. - */ - -#ifndef CONFIG_EXAMPLES_OSTEST_LOOPS -# define CONFIG_EXAMPLES_OSTEST_LOOPS 1 -#endif - -/* This is the number of threads that are created in the barrier test. - * A smaller number should be selected on systems without sufficient memory - * to start so many threads. - */ - -#ifndef CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS -# define CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS 8 -#endif - -/* Priority inheritance */ - -#if defined(CONFIG_DEBUG) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG) -# define dump_nfreeholders(s) printf(s " nfreeholders: %d\n", sem_nfreeholders()) -#else -# define dump_nfreeholders(s) -#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 - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* dev_null.c ***************************************************************/ - -int dev_null(void); - -/* fpu.c ********************************************************************/ - -void fpu_test(void); - -/* waitpid.c ****************************************************************/ - -#ifdef CONFIG_SCHED_WAITPID -int waitpid_test(void); -#endif - -/* mutex.c ******************************************************************/ - -void mutex_test(void); - -/* rmutex.c ******************************************************************/ - -void recursive_mutex_test(void); - -/* sem.c ********************************************************************/ - -void sem_test(void); - -/* cond.c *******************************************************************/ - -void cond_test(void); - -/* mqueue.c *****************************************************************/ - -void mqueue_test(void); - -/* timedmqueue.c ************************************************************/ - -void timedmqueue_test(void); - -/* cancel.c *****************************************************************/ - -void cancel_test(void); - -/* timedwait.c **************************************************************/ - -void timedwait_test(void); - -/* sighand.c ****************************************************************/ - -void sighand_test(void); - -/* posixtimers.c ************************************************************/ - -void timer_test(void); - -/* roundrobin.c *************************************************************/ - -void rr_test(void); - -/* barrier.c ****************************************************************/ - -void barrier_test(void); - -/* prioinherit.c ************************************************************/ - -void priority_inheritance(void); - -/* vfork.c ******************************************************************/ - -#ifdef CONFIG_ARCH_HAVE_VFORK -int vfork_test(void); -#endif - -/* APIs exported (conditionally) by the OS specifically for testing of - * priority inheritance - */ - -#if defined(CONFIG_DEBUG) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG) -void sem_enumholders(FAR sem_t *sem); -int sem_nfreeholders(void); -#else -# define sem_enumholders(sem) -# define sem_nfreeholders() -#endif - -#endif /* __APPS_EXAMPLES_OSTEST_OSTEST_H */ diff --git a/apps/examples/ostest/ostest_main.c b/apps/examples/ostest/ostest_main.c deleted file mode 100644 index 3e4197fdc..000000000 --- a/apps/examples/ostest/ostest_main.c +++ /dev/null @@ -1,564 +0,0 @@ -/**************************************************************************** - * apps/examples/ostest/ostest_main.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <signal.h> -#include <string.h> -#include <sched.h> -#include <errno.h> - -#include <nuttx/init.h> - -#include "ostest.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define PRIORITY 100 -#define NARGS 4 -#define HALF_SECOND_USEC 500000L - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char arg1[] = "Arg1"; -static const char arg2[] = "Arg2"; -static const char arg3[] = "Arg3"; -static const char arg4[] = "Arg4"; - -#if CONFIG_NFILE_DESCRIPTORS > 0 -static const char write_data1[] = "stdio_test: write fd=1\n"; -static const char write_data2[] = "stdio_test: write fd=2\n"; -#endif - -#ifdef SDCC -/* I am not yet certain why SDCC does not like the following - * initializer. It involves some issues with 2- vs 3-byte - * pointer types. - */ - -static const char *g_argv[NARGS+1]; -#else -static const char *g_argv[NARGS+1] = { arg1, arg2, arg3, arg4, NULL }; -#endif - -#ifndef CONFIG_DISABLE_SIGNALS -static struct mallinfo g_mmbefore; -static struct mallinfo g_mmprevious; -static struct mallinfo g_mmafter; -#endif - -#ifndef CONFIG_DISABLE_ENVIRON -const char g_var1_name[] = "Variable1"; -const char g_var1_value[] = "GoodValue1"; -const char g_var2_name[] = "Variable2"; -const char g_var2_value[] = "GoodValue2"; -const char g_var3_name[] = "Variable3"; -const char g_var3_value[] = "GoodValue3"; - -const char g_bad_value1[] = "BadValue1"; -const char g_bad_value2[] = "BadValue2"; - -const char g_putenv_value[] = "Variable1=BadValue3"; - -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: show_memory_usage - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_SIGNALS -static void show_memory_usage(struct mallinfo *mmbefore, - struct mallinfo *mmafter) -{ - printf("VARIABLE BEFORE AFTER\n"); - printf("======== ======== ========\n"); - printf("arena %8x %8x\n", mmbefore->arena, mmafter->arena); - printf("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks); - printf("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk); - printf("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks); - printf("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks); -} -#else -# define show_memory_usage(mm1, mm2) -#endif - -/**************************************************************************** - * Name: check_test_memory_usage - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_SIGNALS -static void check_test_memory_usage(void) -{ - /* Wait a little bit to let any threads terminate */ - - usleep(HALF_SECOND_USEC); - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - g_mmafter = mallinfo(); -#else - (void)mallinfo(&g_mmafter); -#endif - - /* Show the change from the previous time */ - - printf("\nEnd of test memory usage:\n"); - show_memory_usage(&g_mmprevious, &g_mmafter); - - /* Set up for the next test */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - g_mmprevious = g_mmafter; -#else - memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo)); -#endif - - /* If so enabled, show the use of priority inheritance resources */ - - dump_nfreeholders("user_main:"); -} -#else -# define check_test_memory_usage() -#endif - -/**************************************************************************** - * Name: show_variable - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_ENVIRON -static void show_variable(const char *var_name, const char *exptd_value, bool var_valid) -{ - char *actual_value = getenv(var_name); - if (actual_value) - { - if (var_valid) - { - if (strcmp(actual_value, exptd_value) == 0) - { - printf("show_variable: Variable=%s has value=%s\n", var_name, exptd_value); - } - else - { - printf("show_variable: ERROR Variable=%s has the wrong value\n", var_name); - printf("show_variable: found=%s expected=%s\n", actual_value, exptd_value); - } - } - else - { - printf("show_variable: ERROR Variable=%s has a value when it should not\n", var_name); - printf("show_variable: value=%s\n", actual_value); - } - } - else if (var_valid) - { - printf("show_variable: ERROR Variable=%s has no value\n", var_name); - printf("show_variable: Should have had value=%s\n", exptd_value); - } - else - { - printf("show_variable: Variable=%s has no value\n", var_name); - } -} - -static void show_environment(bool var1_valid, bool var2_valid, bool var3_valid) -{ - show_variable(g_var1_name, g_var1_value, var1_valid); - show_variable(g_var2_name, g_var2_value, var2_valid); - show_variable(g_var3_name, g_var3_value, var3_valid); -} -#else -# define show_environment() -#endif - -/**************************************************************************** - * Name: user_main - ****************************************************************************/ - -static int user_main(int argc, char *argv[]) -{ - int i; - - /* Sample the memory usage now */ - -#ifndef CONFIG_DISABLE_SIGNALS - usleep(HALF_SECOND_USEC); - -#ifdef CONFIG_CAN_PASS_STRUCTS - g_mmbefore = mallinfo(); - g_mmprevious = g_mmbefore; -#else - (void)mallinfo(&g_mmbefore); - memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo)); -#endif -#endif - - printf("\nuser_main: Begin argument test\n"); - printf("user_main: Started with argc=%d\n", argc); - - /* Verify passed arguments */ - - if (argc != NARGS + 1) - { - printf("user_main: Error expected argc=%d got argc=%d\n", - NARGS+1, argc); - } - - for (i = 0; i <= NARGS; i++) - { - printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]); - } - - for (i = 1; i <= NARGS; i++) - { - if (strcmp(argv[i], g_argv[i-1]) != 0) - { - printf("user_main: ERROR argv[%d]: Expected \"%s\" found \"%s\"\n", - i, g_argv[i-1], argv[i]); - } - } - check_test_memory_usage(); - - /* If retention of child status is enable, then suppress it for this task. - * This task may produce many, many children (especially if - * CONFIG_EXAMPLES_OSTEST_LOOPS) and it does not harvest their exit status. - * As a result, the test may fail inappropriately unless retention of - * child exit status is disabled. - * - * So basically, this tests that child status can be disabled, but cannot - * verify that status is retained correctly. - */ - -#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) - { - struct sigaction sa; - int ret; - - sa.sa_handler = SIG_IGN; - sa.sa_flags = SA_NOCLDWAIT; - ret = sigaction(SIGCHLD, &sa, NULL); - if (ret < 0) - { - printf("user_main: ERROR: sigaction failed: %d\n", errno); - } - } -#endif - - /* Check environment variables */ -#ifndef CONFIG_DISABLE_ENVIRON - show_environment(true, true, true); - - unsetenv(g_var1_name); - show_environment(false, true, true); - check_test_memory_usage(); - - clearenv(); - show_environment(false, false, false); - check_test_memory_usage(); -#endif - - /* Top of test loop */ - -#if CONFIG_EXAMPLES_OSTEST_LOOPS > 1 - for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++) -#elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0 - for (;;) -#endif - { -#if CONFIG_NFILE_DESCRIPTORS > 0 - /* Checkout /dev/null */ - - printf("\nuser_main: /dev/null test\n"); - dev_null(); - check_test_memory_usage(); -#endif - -#ifdef CONFIG_ARCH_FPU - /* Check that the FPU is properly supported during context switching */ - - printf("\nuser_main: FPU test\n"); - fpu_test(); - check_test_memory_usage(); -#endif - -#ifdef CONFIG_SCHED_WAITPID - /* Check waitpid() and friends */ - - printf("\nuser_main: waitpid test\n"); - waitpid_test(); - check_test_memory_usage(); -#endif - -#ifndef CONFIG_DISABLE_PTHREAD - /* Verify pthreads and pthread mutex */ - - printf("\nuser_main: mutex test\n"); - mutex_test(); - check_test_memory_usage(); -#endif - -#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES) - /* Verify recursive mutexes */ - - printf("\nuser_main: recursive mutex test\n"); - recursive_mutex_test(); - check_test_memory_usage(); -#endif - -#ifndef CONFIG_DISABLE_PTHREAD - /* Verify pthread cancellation */ - - printf("\nuser_main: cancel test\n"); - cancel_test(); - check_test_memory_usage(); -#endif - -#ifndef CONFIG_DISABLE_PTHREAD - /* Verify pthreads and semaphores */ - - printf("\nuser_main: semaphore test\n"); - sem_test(); - check_test_memory_usage(); -#endif - -#ifndef CONFIG_DISABLE_PTHREAD - /* Verify pthreads and condition variables */ - - printf("\nuser_main: condition variable test\n"); -#ifdef CONFIG_PRIORITY_INHERITANCE - printf("\n Skipping, Test logic incompatible with priority inheritance\n"); -#else - cond_test(); - check_test_memory_usage(); -#endif -#endif - -#if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK) - /* Verify pthreads and condition variable timed waits */ - - printf("\nuser_main: timed wait test\n"); - timedwait_test(); - check_test_memory_usage(); -#endif - -#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) - /* Verify pthreads and message queues */ - - printf("\nuser_main: message queue test\n"); - mqueue_test(); - check_test_memory_usage(); -#endif - -#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK) - /* Verify pthreads and message queues */ - - printf("\nuser_main: timed message queue test\n"); - timedmqueue_test(); - check_test_memory_usage(); -#endif - -#ifndef CONFIG_DISABLE_SIGNALS - /* Verify signal handlers */ - - printf("\nuser_main: signal handler test\n"); - sighand_test(); - check_test_memory_usage(); -#endif - -#if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS) - /* Verify posix timers */ - - printf("\nuser_main: POSIX timer test\n"); - timer_test(); - check_test_memory_usage(); -#endif - -#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0 - /* Verify round robin scheduling */ - - printf("\nuser_main: round-robin scheduler test\n"); - rr_test(); - check_test_memory_usage(); -#endif - -#ifndef CONFIG_DISABLE_PTHREAD - /* Verify pthread barriers */ - - printf("\nuser_main: barrier test\n"); - barrier_test(); - check_test_memory_usage(); -#endif - -#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) - /* Verify priority inheritance */ - - printf("\nuser_main: priority inheritance test\n"); - priority_inheritance(); - check_test_memory_usage(); -#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */ - -#ifdef CONFIG_ARCH_HAVE_VFORK - printf("\nuser_main: vfork() test\n"); - vfork_test(); -#endif - - /* Compare memory usage at time ostest_main started until - * user_main exits. These should not be identical, but should - * be similar enough that we can detect any serious OS memory - * leaks. - */ - -#ifndef CONFIG_DISABLE_SIGNALS - usleep(HALF_SECOND_USEC); - -#ifdef CONFIG_CAN_PASS_STRUCTS - g_mmafter = mallinfo(); -#else - (void)mallinfo(&g_mmafter); -#endif - - printf("\nFinal memory usage:\n"); - show_memory_usage(&g_mmbefore, &g_mmafter); -#endif - } - - printf("user_main: Exitting\n"); - return 0; -} - -/**************************************************************************** - * Name: stdio_test - ****************************************************************************/ - -static void stdio_test(void) -{ - /* Verify that we can communicate */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 - write(1, write_data1, sizeof(write_data1)-1); -#endif - printf("stdio_test: Standard I/O Check: printf\n"); - -#if CONFIG_NFILE_DESCRIPTORS > 1 - write(2, write_data2, sizeof(write_data2)-1); -#endif -#if CONFIG_NFILE_STREAMS > 0 - fprintf(stderr, "stdio_test: Standard I/O Check: fprintf to stderr\n"); -#endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * ostest_main - ****************************************************************************/ - -int ostest_main(int argc, char *argv[]) -{ - int result; - - /* Verify that stdio works first */ - - stdio_test(); - -#ifdef SDCC - /* I am not yet certain why SDCC does not like the following initilizers. - * It involves some issues with 2- vs 3-byte pointer types. - */ - - g_argv[0] = arg1; - g_argv[1] = arg2; - g_argv[2] = arg3; - g_argv[3] = arg4; - g_argv[4] = NULL; -#endif - - /* Set up some environment variables */ - -#ifndef CONFIG_DISABLE_ENVIRON - printf("ostest_main: putenv(%s)\n", g_putenv_value); - putenv(g_putenv_value); /* Varaible1=BadValue3 */ - printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value); - setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */ - - printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1); - setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */ - printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value); - setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */ - - printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); - setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */ - printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); - setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */ - show_environment(true, true, true); -#endif - - /* Verify that we can spawn a new task */ - -#ifndef CONFIG_CUSTOM_STACK - result = task_create("ostest", PRIORITY, STACKSIZE, user_main, g_argv); -#else - result = task_create("ostest", PRIORITY, user_main, g_argv); -#endif - if (result == ERROR) - { - printf("ostest_main: ERROR Failed to start user_main\n"); - } - else - { - printf("ostest_main: Started user_main at PID=%d\n", result); - } - - printf("ostest_main: Exitting\n"); - return 0; -} diff --git a/apps/examples/ostest/posixtimer.c b/apps/examples/ostest/posixtimer.c deleted file mode 100644 index ebb1ab79e..000000000 --- a/apps/examples/ostest/posixtimer.c +++ /dev/null @@ -1,262 +0,0 @@ -/*********************************************************************** - * examples/ostest/posixtimer.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 <stdio.h> -#include <unistd.h> -#include <semaphore.h> -#include <signal.h> -#include <sched.h> -#include <errno.h> -#include "ostest.h" - -/************************************************************************** - * Private Definitions - **************************************************************************/ - -#ifndef NULL -# define NULL (void*)0 -#endif - -#define MY_TIMER_SIGNAL 17 -#define SIGVALUE_INT 42 - -/************************************************************************** - * Private Data - **************************************************************************/ - -static sem_t sem; -static int g_nsigreceived = 0; - -/************************************************************************** - * Private Functions - **************************************************************************/ - -static void timer_expiration(int signo, siginfo_t *info, void *ucontext) -{ - sigset_t oldset; - sigset_t allsigs; - int status; - - printf("timer_expiration: Received signal %d\n" , signo); - - g_nsigreceived++; - - /* Check signo */ - - if (signo != MY_TIMER_SIGNAL) - { - printf("timer_expiration: ERROR expected signo=%d\n" , MY_TIMER_SIGNAL); - } - - /* Check siginfo */ - - if (info->si_value.sival_int != SIGVALUE_INT) - { - printf("timer_expiration: ERROR sival_int=%d expected %d\n", - info->si_value.sival_int, SIGVALUE_INT); - } - else - { - printf("timer_expiration: sival_int=%d\n" , info->si_value.sival_int); - } - - if (info->si_signo != MY_TIMER_SIGNAL) - { - printf("timer_expiration: ERROR expected si_signo=%d, got=%d\n", - MY_TIMER_SIGNAL, info->si_signo); - } - - if (info->si_code == SI_TIMER) - { - printf("timer_expiration: si_code=%d (SI_TIMER)\n" , info->si_code); - } - else - { - printf("timer_expiration: ERROR si_code=%d, expected SI_TIMER=%d\n", - info->si_code, SI_TIMER); - } - - /* Check ucontext_t */ - - printf("timer_expiration: ucontext=%p\n" , ucontext); - - /* Check sigprocmask */ - - (void)sigfillset(&allsigs); - status = sigprocmask(SIG_SETMASK, NULL, &oldset); - if (status != OK) - { - printf("timer_expiration: ERROR sigprocmask failed, status=%d\n", - status); - } - - if (oldset != allsigs) - { - printf("timer_expiration: ERROR sigprocmask=%x expected=%x\n", - oldset, allsigs); - } - -} - -/************************************************************************** - * Public Functions - **************************************************************************/ - -void timer_test(void) -{ - sigset_t sigset; - struct sigaction act; - struct sigaction oact; - struct sigevent notify; - struct itimerspec timer; - timer_t timerid; - int status; - int i; - - printf("timer_test: Initializing semaphore to 0\n" ); - sem_init(&sem, 0, 0); - - /* Start waiter thread */ - - printf("timer_test: Unmasking signal %d\n" , MY_TIMER_SIGNAL); - - (void)sigemptyset(&sigset); - (void)sigaddset(&sigset, MY_TIMER_SIGNAL); - status = sigprocmask(SIG_UNBLOCK, &sigset, NULL); - if (status != OK) - { - printf("timer_test: ERROR sigprocmask failed, status=%d\n", - status); - } - - printf("timer_test: Registering signal handler\n" ); - act.sa_sigaction = timer_expiration; - act.sa_flags = SA_SIGINFO; - - (void)sigfillset(&act.sa_mask); - (void)sigdelset(&act.sa_mask, MY_TIMER_SIGNAL); - - status = sigaction(MY_TIMER_SIGNAL, &act, &oact); - if (status != OK) - { - printf("timer_test: ERROR sigaction failed, status=%d\n" , status); - } - -#ifndef SDCC - printf("timer_test: oact.sigaction=%p oact.sa_flags=%x oact.sa_mask=%x\n", - oact.sa_sigaction, oact.sa_flags, oact.sa_mask); -#endif - - /* Create the POSIX timer */ - - printf("timer_test: Creating timer\n" ); - - notify.sigev_notify = SIGEV_SIGNAL; - notify.sigev_signo = MY_TIMER_SIGNAL; - notify.sigev_value.sival_int = SIGVALUE_INT; - - status = timer_create(CLOCK_REALTIME, ¬ify, &timerid); - if (status != OK) - { - printf("timer_test: timer_create failed, errno=%d\n", errno); - goto errorout; - } - - /* Start the POSIX timer */ - - printf("timer_test: Starting timer\n" ); - - timer.it_value.tv_sec = 2; - timer.it_value.tv_nsec = 0; - timer.it_interval.tv_sec = 2; - timer.it_interval.tv_nsec = 0; - - status = timer_settime(timerid, 0, &timer, NULL); - if (status != OK) - { - printf("timer_test: timer_settime failed, errno=%d\n", errno); - goto errorout; - } - - /* Take the semaphore */ - - for (i = 0; i < 5; i++) - { - printf("timer_test: Waiting on semaphore\n" ); - FFLUSH(); - status = sem_wait(&sem); - if (status != 0) - { - int error = errno; - if (error == EINTR) - { - printf("timer_test: sem_wait() successfully interrupted by signal\n" ); - } - else - { - printf("timer_test: ERROR sem_wait failed, errno=%d\n" , error); - } - } - else - { - printf("timer_test: ERROR awakened with no error!\n" ); - } - printf("timer_test: g_nsigreceived=%d\n", g_nsigreceived); - } - -errorout: - sem_destroy(&sem); - - /* Then delete the timer */ - - printf("timer_test: Deleting timer\n" ); - status = timer_delete(timerid); - if (status != OK) - { - printf("timer_test: timer_create failed, errno=%d\n", errno); - } - - /* Detach the signal handler */ - - act.sa_sigaction = SIG_DFL; - status = sigaction(MY_TIMER_SIGNAL, &act, &oact); - - printf("timer_test: done\n" ); - FFLUSH(); -} diff --git a/apps/examples/ostest/prioinherit.c b/apps/examples/ostest/prioinherit.c deleted file mode 100644 index cd04df7e6..000000000 --- a/apps/examples/ostest/prioinherit.c +++ /dev/null @@ -1,559 +0,0 @@ -/**************************************************************************** - * examples/ostest/prioinherit.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 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 <unistd.h> -#include <semaphore.h> -#include <pthread.h> -#include <errno.h> - -#ifdef CONFIG_ARCH_SIM -# include <nuttx/arch.h> -#endif - -#include "ostest.h" - -#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#ifndef CONFIG_SEM_PREALLOCHOLDERS -# define CONFIG_SEM_PREALLOCHOLDERS 0 -#endif - -/* If resources were configured for lots of holders, then run 3 low priority - * threads. Otherwise, just one. - */ - -#if CONFIG_SEM_PREALLOCHOLDERS > 3 -# define NLOWPRI_THREADS 3 -#else -# define NLOWPRI_THREADS 1 -#endif - -#ifndef CONFIG_SEM_NNESTPRIO -# define CONFIG_SEM_NNESTPRIO 0 -#endif - -/* Where resources configured for lots of waiters? If so then run 3 high - * priority threads. Otherwise, just one. - */ - -#if CONFIG_SEM_NNESTPRIO > 3 -# define NHIGHPRI_THREADS 3 -#else -# define NHIGHPRI_THREADS 1 -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -enum thstate_e -{ - NOTSTARTED = 0, - RUNNING, - WAITING, - DONE -}; - -static sem_t g_sem; -static volatile enum thstate_e g_middlestate; -static volatile enum thstate_e g_highstate[NHIGHPRI_THREADS]; -static volatile enum thstate_e g_lowstate[NLOWPRI_THREADS]; -static int g_highpri; -static int g_medpri; -static int g_lowpri; - -/**************************************************************************** - * Name: nhighpri_waiting - ****************************************************************************/ - -static int nhighpri_waiting(void) -{ - int n = 0; - int i; - - for (i = 0; i < NHIGHPRI_THREADS; i++) - { - if (g_highstate[i] == WAITING) - { - n++; - } - } - return n; -} - -/**************************************************************************** - * Name: nhighpri_running - ****************************************************************************/ - -static int nhighpri_running(void) -{ - int n = 0; - int i; - - for (i = 0; i < NHIGHPRI_THREADS; i++) - { - if (g_highstate[i] != DONE) - { - n++; - } - } - return n; -} - -/**************************************************************************** - * Name: highpri_thread - ****************************************************************************/ - -static void *highpri_thread(void *parameter) -{ - int threadno = (int)parameter; - int ret; - - g_highstate[threadno-1] = RUNNING; - - printf("highpri_thread-%d: Started\n", threadno); - FFLUSH(); - sleep(1); - - printf("highpri_thread-%d: Calling sem_wait()\n", threadno); - g_highstate[threadno-1] = WAITING; - ret = sem_wait(&g_sem); - g_highstate[threadno-1] = DONE; - - if (ret != 0) - { - printf("highpri_thread-%d: sem_take failed: %d\n", threadno, ret); - } - else if (g_middlestate == RUNNING) - { - printf("highpri_thread-%d: SUCCESS midpri_thread is still running!\n", threadno); - } - else - { - printf("highpri_thread-%d: ERROR -- midpri_thread has already exited!\n", threadno); - } - - sem_post(&g_sem); - printf("highpri_thread-%d: Okay... I'm done!\n", threadno); - FFLUSH(); - return NULL; -} - -/**************************************************************************** - * Name: hog_cpu - ****************************************************************************/ - -static inline void hog_cpu(void) -{ -#ifdef CONFIG_ARCH_SIM - /* The simulator doesn't have any mechanism to do asynchronous pre-emption - * (basically because it doesn't have any interupts/asynchronous events). - * The simulator does "fake" a timer interrupt in up_idle() -- the idle - * thread that only executes when nothing else is running. In the simulator, - * we cannot suspend the middle priority task, or we wouldn't have the - * test that we want. So, we have no option but to pump the fake clock - * here by calling up_idle(). Sigh! - */ - - up_idle(); -#else - /* On real platforms with a real timer interrupt, we really can hog the - * CPU. When the sleep() goes off in priority_inheritance(), it will - * wake up and start the high priority thread. - */ - - volatile int i; - for (i = 0; i < INT_MAX; i++); -#endif -} - -/**************************************************************************** - * Name: medpri_thread - ****************************************************************************/ - -static void *medpri_thread(void *parameter) -{ - printf("medpri_thread: Started ... I won't let go of the CPU!\n"); - g_middlestate = RUNNING; - FFLUSH(); - - /* The following loop will completely block lowpri_thread from running. - * UNLESS priority inheritance is working. In that case, its priority - * will be boosted. - */ - - while (nhighpri_running() > 0) - { - hog_cpu(); - } - - printf("medpri_thread: Okay... I'm done!\n"); - FFLUSH(); - g_middlestate = DONE; - return NULL; -} - -/**************************************************************************** - * Name: lowpri_thread - ****************************************************************************/ - -static void *lowpri_thread(void *parameter) -{ - void *retval = (void*)-1; - struct sched_param sparam; - int threadno = (int)parameter; - int expected; - int count; - int policy; - int ret; - int nwaiting; - int i; - - g_lowstate[threadno-1] = RUNNING; - printf("lowpri_thread-%d: Started\n", threadno); - - ret = pthread_getschedparam(pthread_self(), &policy, &sparam); - if (ret != 0) - { - printf("lowpri_thread-%d: ERROR pthread_getschedparam failed: %d\n", threadno, ret); - } - else - { - printf("lowpri_thread-%d: initial priority: %d\n", threadno, sparam.sched_priority); - if (sparam.sched_priority != g_lowpri) - { - printf(" ERROR should have been %d\n", g_lowpri); - } - } - - g_lowstate[threadno-1] = WAITING; - ret = sem_wait(&g_sem); - if (ret != 0) - { - printf("lowpri_thread-%d: sem_take failed: %d\n", threadno, ret); - } - else - { - /* Hang on to the thread until the middle priority thread runs */ - - while (g_middlestate == NOTSTARTED && nhighpri_waiting() < NHIGHPRI_THREADS) - { - printf("lowpri_thread-%d: Waiting for the midle pri task to run\n", threadno); - printf(" g_middlestate: %d\n", (int)g_middlestate); - for (i = 0; i < NHIGHPRI_THREADS; i++) - { - printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]); - } - printf(" I still have a count on the semaphore\n"); - sem_enumholders(&g_sem); - FFLUSH(); - sleep(1); - } - - /* Account for all of the semaphore counts. At any given time if there are 'n' - * running hight prioity tasks, then the semaphore count should be '-n' - */ - - sched_lock(); /* Needs to be atomic */ - ret = sem_getvalue(&g_sem, &count); - nwaiting = nhighpri_waiting(); - sched_unlock(); - - if (ret < 0) - { - printf("lowpri_thread-%d: ERROR sem_getvalue failed: %d\n", threadno, errno); - } - printf("lowpri_thread-%d: Sem count: %d, No. highpri thread: %d\n", threadno, count, nwaiting); - - /* The middle priority task is running, let go of the semaphore */ - - if (g_middlestate == RUNNING && nwaiting == -count) - { - /* Good.. the middle priority task is still running and the counts are okay. */ - - retval = NULL; - } - else - { - /* If the sem count is positive, then there all of the higher priority threads - * should have already completed. - */ - - printf("lowpri_thread-%d: %s the middle priority task has already exitted!\n", - threadno, count >= 0 ? "SUCCESS" : "ERROR" ); - printf(" g_middlestate: %d sem count=%d\n", (int)g_middlestate, count); - for (i = 0; i < NHIGHPRI_THREADS; i++) - { - printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]); - } - } - } - - ret = pthread_getschedparam(pthread_self(), &policy, &sparam); - sem_enumholders(&g_sem); - sem_post(&g_sem); - if (ret != 0) - { - printf("lowpri_thread-%d: ERROR pthread_getschedparam failed: %d\n", threadno, ret); - } - else - { - if (nwaiting > 0) - { - expected = g_highpri; - } - else - { - expected = g_lowpri; - } - - printf("lowpri_thread-%d: %s priority before sem_post: %d\n", - threadno, - sparam.sched_priority != expected ? "ERROR" : "SUCCESS", - sparam.sched_priority); - - if (sparam.sched_priority != expected) - { - printf(" ERROR should have been %d\n", expected); - } - } - - ret = pthread_getschedparam(pthread_self(), &policy, &sparam); - if (ret != 0) - { - printf("lowpri_thread-%d: ERROR pthread_getschedparam failed: %d\n", threadno, ret); - } - else - { - printf("lowpri_thread-%d: %s final priority: %d\n", - threadno, - sparam.sched_priority != g_lowpri ? "ERROR" : "SUCCESS", - sparam.sched_priority); - - if (sparam.sched_priority != g_lowpri) - { - printf(" ERROR should have been %d\n", g_lowpri); - } - } - sem_enumholders(&g_sem); - - printf("lowpri_thread-%d: Okay... I'm done!\n", threadno); - FFLUSH(); - g_lowstate[threadno-1] = DONE; - return retval; -} -#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: priority_inheritance - ****************************************************************************/ - -void priority_inheritance(void) -{ -#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) - pthread_t lowpri[NLOWPRI_THREADS]; - pthread_t medpri; - pthread_t highpri[NHIGHPRI_THREADS]; - pthread_addr_t result; - pthread_attr_t attr; - struct sched_param sparam; - int my_pri; - int status; - int i; - - printf("priority_inheritance: Started\n"); - - g_middlestate = NOTSTARTED; - for (i = 0; i < NHIGHPRI_THREADS; i++) g_highstate[i] = NOTSTARTED; - for (i = 0; i < NLOWPRI_THREADS; i++) g_lowstate[i] = NOTSTARTED; - - status = sched_getparam (getpid(), &sparam); - if (status != 0) - { - printf("priority_inheritance: sched_getparam failed\n"); - sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY; - } - my_pri = sparam.sched_priority; - - g_highpri = sched_get_priority_max(SCHED_FIFO); - g_lowpri = sched_get_priority_min(SCHED_FIFO); - g_medpri = my_pri - 1; - - sem_init(&g_sem, 0, NLOWPRI_THREADS); - dump_nfreeholders("priority_inheritance:"); - - /* Start the low priority threads */ - - for (i = 0; i < NLOWPRI_THREADS; i++) - { - int threadno = i+1; - printf("priority_inheritance: Starting lowpri_thread-%d (of %d) at %d\n", - threadno, NLOWPRI_THREADS, g_lowpri); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("priority_inheritance: pthread_attr_init failed, status=%d\n", status); - } - sparam.sched_priority = g_lowpri; - status = pthread_attr_setschedparam(&attr,& sparam); - if (status != OK) - { - printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("priority_inheritance: Set lowpri_thread-%d priority to %d\n", - threadno, sparam.sched_priority); - } - - status = pthread_create(&lowpri[i], &attr, lowpri_thread, (void*)threadno); - if (status != 0) - { - printf("priority_inheritance: pthread_create failed, status=%d\n", status); - } - } - printf("priority_inheritance: Waiting...\n"); - sleep(2); - dump_nfreeholders("priority_inheritance:"); - - /* Start the medium priority thread */ - - printf("priority_inheritance: Starting medpri_thread at %d\n", g_medpri); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("priority_inheritance: pthread_attr_init failed, status=%d\n", status); - } - - sparam.sched_priority = g_medpri; - status = pthread_attr_setschedparam(&attr,& sparam); - if (status != OK) - { - printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("priority_inheritance: Set medpri_thread priority to %d\n", sparam.sched_priority); - } - FFLUSH(); - - status = pthread_create(&medpri, &attr, medpri_thread, NULL); - if (status != 0) - { - printf("priority_inheritance: pthread_create failed, status=%d\n", status); - } - printf("priority_inheritance: Waiting...\n"); - sleep(1); - dump_nfreeholders("priority_inheritance:"); - - /* Start the high priority threads */ - - for (i = 0; i < NHIGHPRI_THREADS; i++) - { - int threadno = i+1; - printf("priority_inheritance: Starting highpri_thread-%d (of %d) at %d\n", - threadno, NHIGHPRI_THREADS, g_highpri); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("priority_inheritance: pthread_attr_init failed, status=%d\n", status); - } - - sparam.sched_priority = g_highpri - i; - status = pthread_attr_setschedparam(&attr,& sparam); - if (status != OK) - { - printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("priority_inheritance: Set highpri_thread-%d priority to %d\n", - threadno, sparam.sched_priority); - } - FFLUSH(); - - status = pthread_create(&highpri[i], &attr, highpri_thread, (void*)threadno); - if (status != 0) - { - printf("priority_inheritance: pthread_create failed, status=%d\n", status); - } - } - dump_nfreeholders("priority_inheritance:"); - FFLUSH(); - - /* Wait for all thread instances to complete */ - - for (i = 0; i < NHIGHPRI_THREADS; i++) - { - printf("priority_inheritance: Waiting for highpri_thread-%d to complete\n", i+1); - FFLUSH(); - (void)pthread_join(highpri[i], &result); - dump_nfreeholders("priority_inheritance:"); - } - printf("priority_inheritance: Waiting for medpri_thread to complete\n"); - FFLUSH(); - (void)pthread_join(medpri, &result); - dump_nfreeholders("priority_inheritance:"); - for (i = 0; i < NLOWPRI_THREADS; i++) - { - printf("priority_inheritance: Waiting for lowpri_thread-%d to complete\n", i+1); - FFLUSH(); - (void)pthread_join(lowpri[i], &result); - dump_nfreeholders("priority_inheritance:"); - } - - printf("priority_inheritance: Finished\n"); - sem_destroy(&g_sem); - dump_nfreeholders("priority_inheritance:"); - FFLUSH(); -#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */ -} diff --git a/apps/examples/ostest/rmutex.c b/apps/examples/ostest/rmutex.c deleted file mode 100644 index ffd99c2df..000000000 --- a/apps/examples/ostest/rmutex.c +++ /dev/null @@ -1,166 +0,0 @@ -/*********************************************************************** - * rmutex.c - * - * Copyright (C) 2008 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 <stdio.h> -#include <pthread.h> -#include "ostest.h" - -#ifndef NULL -# define NULL (void*)0 -#endif - -#define NTHREADS 3 -#define NLOOPS 3 -#define NRECURSIONS 3 - -static pthread_mutex_t mut; - -static void thread_inner(int id, int level) -{ - int status; - if (level < NRECURSIONS) - { - /* Take the mutex */ - - printf("thread_inner[%d, %d]: Locking\n", id, level); - status = pthread_mutex_lock(&mut); - if (status != 0) - { - printf("thread_inner[%d, %d]: ERROR pthread_mutex_lock failed: %d\n", - id, level, status); - } - printf("thread_inner[%d, %d]: Locked\n", id, level); - - /* Give the other threads a chance */ - - pthread_yield(); - thread_inner(id, level+1); - pthread_yield(); - - /* Unlock the mutex */ - - printf("thread_inner[%d, %d]: Unlocking\n", id, level); - status = pthread_mutex_unlock(&mut); - if (status != 0) - { - printf("thread_inner[%d, %d]: ERROR pthread_mutex_unlock failed: %d\n", - id, level, status); - } - printf("thread_inner[%d, %d]: Unlocked\n", id, level); - pthread_yield(); - } -} - -static void *thread_outer(void *parameter) -{ - int i; - printf("thread_outer[%d]: Started\n", (int)parameter); - for (i = 0; i < NLOOPS; i++) - { - printf("thread_outer[%d]: Loop %d\n", (int)parameter, i); - thread_inner((int)parameter, 0); - } - printf("thread_outer[%d]: Exitting\n", (int)parameter); - pthread_exit(NULL); - return NULL; /* Non-reachable -- needed for some compilers */ -} - -void recursive_mutex_test(void) -{ - pthread_t thread[NTHREADS]; -#ifdef SDCC - pthread_addr_t result[NTHREADS]; - pthread_attr_t attr; -#endif - pthread_mutexattr_t mattr; - int type; - int status; - int i; - - /* Initialize the mutex attributes */ - - pthread_mutexattr_init(&mattr); - status = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE); - if (status != 0) - { - printf("recursive_mutex_test: ERROR pthread_mutexattr_settype failed, status=%d\n", status); - } - - status = pthread_mutexattr_gettype(&mattr, &type); - if (status != 0) - { - printf("recursive_mutex_test: ERROR pthread_mutexattr_gettype failed, status=%d\n", status); - } - if (type != PTHREAD_MUTEX_RECURSIVE) - { - printf("recursive_mutex_test: ERROR pthread_mutexattr_gettype return type=%d\n", type); - } - - /* Initialize the mutex */ - - printf("recursive_mutex_test: Initializing mutex\n"); - pthread_mutex_init(&mut, &mattr); - - /* Start the threads -- all at the same, default priority */ - - for (i = 0; i < NTHREADS; i++) - { - printf("recursive_mutex_test: Starting thread %d\n", i+1); -#ifdef SDCC - (void)pthread_attr_init(&attr); - status = pthread_create(&thread[i], &attr, thread_outer, (pthread_addr_t)i+1); -#else - status = pthread_create(&thread[i], NULL, thread_outer, (pthread_addr_t)i+1); -#endif - if (status != 0) - { - printf("recursive_mutex_test: ERRROR thread#%d creation: %d\n", i+1, status); - } - } - - /* Wait for all; of the threads to complete */ - - for (i = 0; i < NTHREADS; i++) - { - printf("recursive_mutex_test: Waiting for thread %d\n", i+1); -#ifdef SDCC - pthread_join(thread[i], &result1); -#else - pthread_join(thread[i], NULL); -#endif - } - - printf("recursive_mutex_test: Complete\n"); -} diff --git a/apps/examples/ostest/roundrobin.c b/apps/examples/ostest/roundrobin.c deleted file mode 100644 index bfd344df3..000000000 --- a/apps/examples/ostest/roundrobin.c +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************** - * examples/ostest/roundrobin.c - * - * Copyright (C) 2007, 2008, 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ********************************************************************************/ - -/******************************************************************************** - * Included Files - ********************************************************************************/ - -#include <nuttx/config.h> -#include <stdio.h> -#include <stdbool.h> -#include "ostest.h" - -#if CONFIG_RR_INTERVAL > 0 - -/******************************************************************************** - * Definitions - ********************************************************************************/ - -/* This numbers should be tuned for different processor speeds via .config file. - * With default values the test takes about 30s on Cortex-M3 @ 24MHz. With 32767 - * range and 10 runs it takes ~320s. */ - -#ifndef CONFIG_EXAMPLES_OSTEST_RR_RANGE -# define CONFIG_EXAMPLES_OSTEST_RR_RANGE 10000 -# warning "CONFIG_EXAMPLES_OSTEST_RR_RANGE undefined, using default value = 10000" -#elif (CONFIG_EXAMPLES_OSTEST_RR_RANGE < 1) || (CONFIG_EXAMPLES_OSTEST_RR_RANGE > 32767) -# define CONFIG_EXAMPLES_OSTEST_RR_RANGE 10000 -# warning "Invalid value of CONFIG_EXAMPLES_OSTEST_RR_RANGE, using default value = 10000" -#endif - -#ifndef CONFIG_EXAMPLES_OSTEST_RR_RUNS -# define CONFIG_EXAMPLES_OSTEST_RR_RUNS 10 -# warning "CONFIG_EXAMPLES_OSTEST_RR_RUNS undefined, using default value = 10" -#elif (CONFIG_EXAMPLES_OSTEST_RR_RUNS < 1) || (CONFIG_EXAMPLES_OSTEST_RR_RUNS > 32767) -# define CONFIG_EXAMPLES_OSTEST_RR_RUNS 10 -# warning "Invalid value of CONFIG_EXAMPLES_OSTEST_RR_RUNS, using default value = 10" -#endif - -/******************************************************************************** - * Private Functions - ********************************************************************************/ - -/******************************************************************************** - * Name: get_primes - * - * Description - * This function searches for prime numbers in the most primitive way possible. - ********************************************************************************/ - -static void get_primes(int *count, int *last) -{ - int number; - int local_count = 0; - *last = 0; // to make compiler happy - - for (number = 1; number < CONFIG_EXAMPLES_OSTEST_RR_RANGE; number++) - { - int div; - bool is_prime = true; - - for (div = 2; div <= number / 2; div++) - if (number % div == 0) - { - is_prime = false; - break; - } - - if (is_prime) - { - local_count++; - *last = number; -#if 0 /* We don't really care what the numbers are */ - printf(" Prime %d: %d\n", local_count, number); -#endif - } - } - - *count = local_count; -} - -/******************************************************************************** - * Name: get_primes_thread - ********************************************************************************/ - -static void *get_primes_thread(void *parameter) -{ - int id = (int)parameter; - int i, count, last; - - printf("get_primes_thread id=%d started, looking for primes < %d, doing %d run(s)\n", - id, CONFIG_EXAMPLES_OSTEST_RR_RANGE, CONFIG_EXAMPLES_OSTEST_RR_RUNS); - - for (i = 0; i < CONFIG_EXAMPLES_OSTEST_RR_RUNS; i++) - { - get_primes(&count, &last); - } - - printf("get_primes_thread id=%d finished, found %d primes, last one was %d\n", - id, count, last); - - pthread_exit(NULL); - return NULL; /* To keep some compilers happy */ -} - -/******************************************************************************** - * Public Functions - ********************************************************************************/ - -/******************************************************************************** - * Name: rr_test - ********************************************************************************/ - -void rr_test(void) -{ - pthread_t get_primes1_thread; - pthread_t get_primes2_thread; - struct sched_param sparam; - pthread_attr_t attr; - pthread_addr_t result; - int status; - - status = pthread_attr_init(&attr); - if (status != OK) - { - printf("rr_test: pthread_attr_init failed, status=%d\n", status); - } - - sparam.sched_priority = sched_get_priority_min(SCHED_FIFO); - status = pthread_attr_setschedparam(&attr, &sparam); - if (status != OK) - { - printf("rr_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("rr_test: Set thread priority to %d\n", sparam.sched_priority); - } - - status = pthread_attr_setschedpolicy(&attr, SCHED_RR); - if (status != OK) - { - printf("rr_test: pthread_attr_setschedpolicy failed, status=%d\n", status); - } - else - { - printf("rr_test: Set thread policy to SCHED_RR\n"); - } - - printf("rr_test: Starting first get_primes_thread\n"); - - status = pthread_create(&get_primes1_thread, &attr, get_primes_thread, (void*)1); - if (status != 0) - { - printf("rr_test: Error in thread 1 creation, status=%d\n", status); - } - - printf("rr_test: Starting second get_primes_thread\n"); - - status = pthread_create(&get_primes2_thread, &attr, get_primes_thread, (void*)2); - if (status != 0) - { - printf("rr_test: Error in thread 2 creation, status=%d\n", status); - } - - printf("rr_test: Waiting for threads to complete -- this should take awhile\n"); - printf("rr_test: If RR scheduling is working, they should start and complete at\n"); - printf("rr_test: about the same time\n"); - - pthread_join(get_primes2_thread, &result); - pthread_join(get_primes1_thread, &result); - printf("rr_test: Done\n"); -} - -#endif /* CONFIG_RR_INTERVAL */ diff --git a/apps/examples/ostest/sem.c b/apps/examples/ostest/sem.c deleted file mode 100644 index 48be57a85..000000000 --- a/apps/examples/ostest/sem.c +++ /dev/null @@ -1,246 +0,0 @@ -/*********************************************************************** - * sem.c - * - * Copyright (C) 2007-2009 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 <stdio.h> -#include <pthread.h> -#include <semaphore.h> -#include <sched.h> -#include "ostest.h" - -#ifndef NULL -# define NULL (void*)0 -#endif - -static sem_t sem; - -static void *waiter_func(void *parameter) -{ - int id = (int)parameter; - int status; - int value; - - printf("waiter_func: Thread %d Started\n", id); - - /* Take the semaphore */ - - status = sem_getvalue(&sem, &value); - if (status < 0) - { - printf("waiter_func: ERROR thread %d could not get semaphore value\n", id); - } - else - { - printf("waiter_func: Thread %d initial semaphore value = %d\n", id, value); - } - - printf("waiter_func: Thread %d waiting on semaphore\n", id); - status = sem_wait(&sem); - if (status != 0) - { - printf("waiter_func: ERROR thread %d sem_wait failed\n", id); - } - printf("waiter_func: Thread %d awakened\n", id); - - status = sem_getvalue(&sem, &value); - if (status < 0) - { - printf("waiter_func: ERROR thread %d could not get semaphore value\n", id); - } - else - { - printf("waiter_func: Thread %d new semaphore value = %d\n", id, value); - } - - printf("waiter_func: Thread %d done\n", id); - return NULL; -} - -static void *poster_func(void *parameter) -{ - int id = (int)parameter; - int status; - int value; - - printf("poster_func: Thread %d started\n", id); - - /* Take the semaphore */ - - do - { - status = sem_getvalue(&sem, &value); - if (status < 0) - { - printf("poster_func: ERROR thread %d could not get semaphore value\n", id); - } - else - { - printf("poster_func: Thread %d semaphore value = %d\n", id, value); - } - - if (value < 0) - { - printf("poster_func: Thread %d posting semaphore\n", id); - status = sem_post(&sem); - if (status != 0) - { - printf("poster_func: ERROR thread %d sem_wait failed\n", id); - } - - pthread_yield(); - - status = sem_getvalue(&sem, &value); - if (status < 0) - { - printf("poster_func: ERROR thread %d could not get semaphore value\n", id); - } - else - { - printf("poster_func: Thread %d new semaphore value = %d\n", id, value); - } - } - } - while (value < 0); - - printf("poster_func: Thread %d done\n", id); - return NULL; - -} - -void sem_test(void) -{ - pthread_t waiter_thread1; - pthread_t waiter_thread2; - pthread_t poster_thread; -#ifdef SDCC - pthread_addr_t result; -#endif - struct sched_param sparam; - int prio_min; - int prio_max; - int prio_mid; - pthread_attr_t attr; - int status; - - printf("sem_test: Initializing semaphore to 0\n"); - sem_init(&sem, 0, 0); - - /* Start two waiter thread instances */ - - printf("sem_test: Starting waiter thread 1\n"); - status = pthread_attr_init(&attr); - if (status != OK) - { - printf("sem_test: pthread_attr_init failed, status=%d\n", status); - } - - prio_min = sched_get_priority_min(SCHED_FIFO); - prio_max = sched_get_priority_max(SCHED_FIFO); - prio_mid = (prio_min + prio_max) / 2; - - sparam.sched_priority = (prio_mid + prio_max) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); - if (status != OK) - { - printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("sem_test: Set thread 1 priority to %d\n", sparam.sched_priority); - } - - status = pthread_create(&waiter_thread1, &attr, waiter_func, (pthread_addr_t)1); - if (status != 0) - { - printf("sem_test: Error in thread 1 creation, status=%d\n", status); - } - - printf("sem_test: Starting waiter thread 2\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("sem_test: pthread_attr_init failed, status=%d\n", status); - } - - sparam.sched_priority = prio_mid; - status = pthread_attr_setschedparam(&attr,&sparam); - if (status != OK) - { - printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("sem_test: Set thread 2 priority to %d\n", sparam.sched_priority); - } - - status = pthread_create(&waiter_thread2, &attr, waiter_func, (pthread_addr_t)2); - if (status != 0) - { - printf("sem_test: Error in thread 2 creation, status=%d\n", status); - } - - printf("sem_test: Starting poster thread 3\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("sem_test: pthread_attr_init failed, status=%d\n", status); - } - - sparam.sched_priority = (prio_min + prio_mid) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); - if (status != OK) - { - printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("sem_test: Set thread 3 priority to %d\n", sparam.sched_priority); - } - - status = pthread_create(&poster_thread, &attr, poster_func, (pthread_addr_t)3); - if (status != 0) - { - printf("sem_test: Error in thread 3 creation, status=%d\n", status); - } - -#ifdef SDCC - pthread_join(waiter_thread1, &result); - pthread_join(waiter_thread2, &result); - pthread_join(poster_thread, &result); -#else - pthread_join(waiter_thread1, NULL); - pthread_join(waiter_thread2, NULL); - pthread_join(poster_thread, NULL); -#endif -} diff --git a/apps/examples/ostest/sighand.c b/apps/examples/ostest/sighand.c deleted file mode 100644 index 32b182c21..000000000 --- a/apps/examples/ostest/sighand.c +++ /dev/null @@ -1,330 +0,0 @@ -/*********************************************************************** - * apps/examples/ostest/sighand.c - * - * Copyright (C) 2007, 2008, 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 <sys/types.h> -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> -#include <semaphore.h> -#include <signal.h> -#include <sched.h> -#include <errno.h> -#include "ostest.h" - -#ifndef NULL -# define NULL (void*)0 -#endif - -#define WAKEUP_SIGNAL 17 -#define SIGVALUE_INT 42 - -static sem_t sem; -static bool sigreceived = false; -static bool threadexited = false; - -#ifdef CONFIG_SCHED_HAVE_PARENT -static void death_of_child(int signo, siginfo_t *info, void *ucontext) -{ - /* Use of printf in a signal handler is NOT safe! It can cause deadlocks! - * Also, signals are not queued by NuttX. As a consequence, some - * notifications will get lost (or the info data can be overwrittedn)! - * Because POSIX does not require signals to be queued, I do not think - * that this is a bug (the overwriting is a bug, however). - */ - - if (info) - { - printf("death_of_child: PID %d received signal=%d code=%d pid=%d status=%d\n", - getpid(), signo, info->si_code, info->si_pid, info->si_status); - } - else - { - printf("death_of_child: PID %d received signal=%d (no info?)\n", - getpid(), signo); - } -} -#endif - -static void wakeup_action(int signo, siginfo_t *info, void *ucontext) -{ - sigset_t oldset; - sigset_t allsigs; - int status; - - /* Use of printf in a signal handler is NOT safe! It can cause deadlocks! */ - - printf("wakeup_action: Received signal %d\n" , signo); - - sigreceived = true; - - /* Check signo */ - - if (signo != WAKEUP_SIGNAL) - { - printf("wakeup_action: ERROR expected signo=%d\n" , WAKEUP_SIGNAL); - } - - /* Check siginfo */ - - if (info->si_value.sival_int != SIGVALUE_INT) - { - printf("wakeup_action: ERROR sival_int=%d expected %d\n", - info->si_value.sival_int, SIGVALUE_INT); - } - else - { - printf("wakeup_action: sival_int=%d\n" , info->si_value.sival_int); - } - - if (info->si_signo != WAKEUP_SIGNAL) - { - printf("wakeup_action: ERROR expected si_signo=%d, got=%d\n", - WAKEUP_SIGNAL, info->si_signo); - } - - printf("wakeup_action: si_code=%d\n" , info->si_code); - - /* Check ucontext_t */ - - printf("wakeup_action: ucontext=%p\n" , ucontext); - - /* Check sigprocmask */ - - (void)sigfillset(&allsigs); - status = sigprocmask(SIG_SETMASK, NULL, &oldset); - if (status != OK) - { - printf("wakeup_action: ERROR sigprocmask failed, status=%d\n", - status); - } - - if (oldset != allsigs) - { - printf("wakeup_action: ERROR sigprocmask=%x expected=%x\n", - oldset, allsigs); - } -} - -static int waiter_main(int argc, char *argv[]) -{ - sigset_t sigset; - struct sigaction act; - struct sigaction oact; - int status; - - printf("waiter_main: Waiter started\n" ); - - printf("waiter_main: Unmasking signal %d\n" , WAKEUP_SIGNAL); - (void)sigemptyset(&sigset); - (void)sigaddset(&sigset, WAKEUP_SIGNAL); - status = sigprocmask(SIG_UNBLOCK, &sigset, NULL); - if (status != OK) - { - printf("waiter_main: ERROR sigprocmask failed, status=%d\n", - status); - } - - printf("waiter_main: Registering signal handler\n" ); - act.sa_sigaction = wakeup_action; - act.sa_flags = SA_SIGINFO; - - (void)sigfillset(&act.sa_mask); - (void)sigdelset(&act.sa_mask, WAKEUP_SIGNAL); - - status = sigaction(WAKEUP_SIGNAL, &act, &oact); - if (status != OK) - { - printf("waiter_main: ERROR sigaction failed, status=%d\n" , status); - } - -#ifndef SDCC - printf("waiter_main: oact.sigaction=%p oact.sa_flags=%x oact.sa_mask=%x\n", - oact.sa_sigaction, oact.sa_flags, oact.sa_mask); -#endif - - /* Take the semaphore */ - - printf("waiter_main: Waiting on semaphore\n" ); - FFLUSH(); - - status = sem_wait(&sem); - if (status != 0) - { - int error = errno; - if (error == EINTR) - { - printf("waiter_main: sem_wait() successfully interrupted by signal\n" ); - } - else - { - printf("waiter_main: ERROR sem_wait failed, errno=%d\n" , error); - } - } - else - { - printf("waiter_main: ERROR awakened with no error!\n" ); - } - - /* Detach the signal handler */ - - act.sa_sigaction = SIG_DFL; - status = sigaction(WAKEUP_SIGNAL, &act, &oact); - - printf("waiter_main: done\n" ); - FFLUSH(); - - threadexited = true; - return 0; -} - -void sighand_test(void) -{ -#ifdef CONFIG_SCHED_HAVE_PARENT - struct sigaction act; - struct sigaction oact; - sigset_t sigset; -#endif - struct sched_param param; - union sigval sigvalue; - pid_t waiterpid; - int policy; - int status; - - printf("sighand_test: Initializing semaphore to 0\n" ); - sem_init(&sem, 0, 0); - -#ifdef CONFIG_SCHED_HAVE_PARENT - printf("sighand_test: Unmasking SIGCHLD\n"); - - (void)sigemptyset(&sigset); - (void)sigaddset(&sigset, SIGCHLD); - status = sigprocmask(SIG_UNBLOCK, &sigset, NULL); - if (status != OK) - { - printf("sighand_test: ERROR sigprocmask failed, status=%d\n", - status); - } - - printf("sighand_test: Registering SIGCHLD handler\n" ); - act.sa_sigaction = death_of_child; - act.sa_flags = SA_SIGINFO; - - (void)sigfillset(&act.sa_mask); - (void)sigdelset(&act.sa_mask, SIGCHLD); - - status = sigaction(SIGCHLD, &act, &oact); - if (status != OK) - { - printf("waiter_main: ERROR sigaction failed, status=%d\n" , status); - } -#endif - - /* Start waiter thread */ - - printf("sighand_test: Starting waiter task\n" ); - status = sched_getparam (0, ¶m); - if (status != OK) - { - printf("sighand_test: ERROR sched_getparam() failed\n" ); - param.sched_priority = PTHREAD_DEFAULT_PRIORITY; - } - - policy = sched_getscheduler(0); - if (policy == ERROR) - { - printf("sighand_test: ERROR sched_getscheduler() failed\n" ); - policy = SCHED_FIFO; - } - - waiterpid = task_create("waiter", param.sched_priority, - PTHREAD_STACK_DEFAULT, waiter_main, NULL); - if (waiterpid == ERROR) - { - printf("sighand_test: ERROR failed to start waiter_main\n" ); - } - else - { - printf("sighand_test: Started waiter_main pid=%d\n", waiterpid); - } - - /* Wait a bit */ - - FFLUSH(); - sleep(2); - - /* Then signal the waiter thread. */ - - printf("sighand_test: Signaling pid=%d with signo=%d sigvalue=%d\n", - waiterpid, WAKEUP_SIGNAL, SIGVALUE_INT); - - sigvalue.sival_int = SIGVALUE_INT; -#ifdef CONFIG_CAN_PASS_STRUCTS - status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue); -#else - status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue.sival_ptr); -#endif - if (status != OK) - { - printf("sighand_test: ERROR sigqueue failed\n" ); - task_delete(waiterpid); - } - - /* Wait a bit */ - - FFLUSH(); - sleep(2); - - /* Then check the result */ - - if (!threadexited) - { - printf("sighand_test: ERROR waiter task did not exit\n" ); - } - - if (!sigreceived) - { - printf("sighand_test: ERROR signal handler did not run\n" ); - } - - /* Detach the signal handler */ - -#ifdef CONFIG_SCHED_HAVE_PARENT - act.sa_sigaction = SIG_DFL; - status = sigaction(SIGCHLD, &act, &oact); -#endif - - printf("sighand_test: done\n" ); - FFLUSH(); -} diff --git a/apps/examples/ostest/timedmqueue.c b/apps/examples/ostest/timedmqueue.c deleted file mode 100644 index 6c3269e84..000000000 --- a/apps/examples/ostest/timedmqueue.c +++ /dev/null @@ -1,387 +0,0 @@ -/************************************************************************** - * apps/examples/ostest/mqueue.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 <stdio.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> -#include <fcntl.h> -#include <pthread.h> -#include <mqueue.h> -#include <sched.h> -#include <errno.h> - -#include "ostest.h" - -/************************************************************************** - * Private Definitions - **************************************************************************/ - -#define TEST_MESSAGE "This is a test and only a test" -#if defined(SDCC) || defined(__ZILOG__) - /* Cannot use strlen in array size */ - -# define TEST_MSGLEN (31) -#else - /* Message lenght is the size of the message plus the null terminator */ - -# define TEST_MSGLEN (strlen(TEST_MESSAGE)+1) -#endif - -#define TEST_SEND_NMSGS (10) -#define TEST_RECEIVE_NMSGS (10) - -/************************************************************************** - * Private Types - **************************************************************************/ - -/************************************************************************** - * Private Function Prototypes - **************************************************************************/ - -/************************************************************************** - * Global Variables - **************************************************************************/ - -/************************************************************************** - * Private Variables - **************************************************************************/ - -/************************************************************************** - * Private Functions - **************************************************************************/ - -/************************************************************************** - * Public Functions - **************************************************************************/ - -static void *sender_thread(void *arg) -{ - mqd_t mqfd; - char msg_buffer[TEST_MSGLEN]; - struct mq_attr attr; - int status = 0; - int nerrors = 0; - int i; - - printf("sender_thread: Starting\n"); - - /* Fill in attributes for message queue */ - - attr.mq_maxmsg = TEST_SEND_NMSGS-1; - attr.mq_msgsize = TEST_MSGLEN; - attr.mq_flags = 0; - - /* Set the flags for the open of the queue. - * Make it a blocking open on the queue, meaning it will block if - * this process tries to send to the queue and the queue is full. - * - * O_CREAT - the queue will get created if it does not already exist. - * O_WRONLY - we are only planning to write to the queue. - * - * Open the queue, and create it if the receiving process hasn't - * already created it. - */ - - mqfd = mq_open("testmq", O_WRONLY|O_CREAT, 0666, &attr); - if (mqfd < 0) - { - printf("sender_thread: ERROR mq_open failed\n"); - pthread_exit((pthread_addr_t)1); - } - - /* Fill in a test message buffer to send */ - - memcpy(msg_buffer, TEST_MESSAGE, TEST_MSGLEN); - - /* Perform the send TEST_SEND_NMSGS times */ - - for (i = 0; i < TEST_SEND_NMSGS; i++) - { - struct timespec ts; - status = clock_gettime(CLOCK_REALTIME, &ts); - if (status != 0) - { - printf("sender_thread: ERROR clock_gettime failed\n"); - } - ts.tv_sec += 5; - - /* The first TEST_SEND_NMSGS-1 send should succeed. The last - * one should fail with errno == ETIMEDOUT - */ - - status = mq_timedsend(mqfd, msg_buffer, TEST_MSGLEN, 42, &ts); - if (status < 0) - { - if (i == TEST_SEND_NMSGS-1 && errno == ETIMEDOUT) - { - printf("sender_thread: mq_timedsend %d timed out as expected\n", i); - } - else - { - printf("sender_thread: ERROR mq_timedsend failure=%d on msg %d\n", errno, i); - nerrors++; - } - } - else - { - if (i == TEST_SEND_NMSGS-1) - { - printf("sender_thread: ERROR mq_timedsend of msg %d succeeded\n", i); - nerrors++; - } - else - { - printf("sender_thread: mq_timedsend succeeded on msg %d\n", i); - } - } - } - - /* Close the queue and return success */ - - if (mq_close(mqfd) < 0) - { - printf("sender_thread: ERROR mq_close failed\n"); - } - - printf("sender_thread: returning nerrors=%d\n", nerrors); - FFLUSH(); - return (pthread_addr_t)nerrors; -} - -static void *receiver_thread(void *arg) -{ - mqd_t mqfd; - char msg_buffer[TEST_MSGLEN]; - struct mq_attr attr; - int nbytes; - int nerrors = 0; - int i; - - printf("receiver_thread: Starting\n"); - - /* Fill in attributes for message queue */ - - attr.mq_maxmsg = TEST_SEND_NMSGS-1; - attr.mq_msgsize = TEST_MSGLEN; - attr.mq_flags = 0; - - /* Set the flags for the open of the queue. - * Make it a blocking open on the queue, meaning it will block if - * this process tries to* send to the queue and the queue is full. - * - * O_CREAT - the queue will get created if it does not already exist. - * O_RDONLY - we are only planning to write to the queue. - * - * Open the queue, and create it if the sending process hasn't - * already created it. - */ - - mqfd = mq_open("testmq", O_RDONLY|O_CREAT, 0666, &attr); - if (mqfd < 0) - { - printf("receiver_thread: ERROR mq_open failed\n"); - pthread_exit((pthread_addr_t)1); - } - - /* Perform the receive TEST_RECEIVE_NMSGS times */ - - for (i = 0; i < TEST_RECEIVE_NMSGS; i++) - { - struct timespec ts; - int status = clock_gettime(CLOCK_REALTIME, &ts); - if (status != 0) - { - printf("sender_thread: ERROR clock_gettime failed\n"); - } - ts.tv_sec += 5; - - /* The first TEST_SEND_NMSGS-1 send should succeed. The last - * one should fail with errno == ETIMEDOUT - */ - - memset(msg_buffer, 0xaa, TEST_MSGLEN); - nbytes = mq_timedreceive(mqfd, msg_buffer, TEST_MSGLEN, 0, &ts); - if (nbytes < 0) - { - if (i == TEST_SEND_NMSGS-1 && errno == ETIMEDOUT) - { - printf("receiver_thread: Receive %d timed out as expected\n", i); - } - else - { - printf("receiver_thread: ERROR mq_timedreceive failure=%d on msg %d\n", errno, i); - nerrors++; - } - } - else if (nbytes != TEST_MSGLEN) - { - printf("receiver_thread: mq_timedreceive return bad size %d on msg %d\n", nbytes, i); - nerrors++; - } - else if (memcmp(TEST_MESSAGE, msg_buffer, nbytes) != 0) - { - int j; - - printf("receiver_thread: mq_timedreceive returned corrupt message on msg %d\n", i); - printf("receiver_thread: i Expected Received\n"); - - for (j = 0; j < TEST_MSGLEN-1; j++) - { - if (isprint(msg_buffer[j])) - { - printf("receiver_thread: %2d %02x (%c) %02x (%c)\n", - j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j], msg_buffer[j]); - } - else - { - printf("receiver_thread: %2d %02x (%c) %02x\n", - j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j]); - } - } - printf("receiver_thread: %2d 00 %02x\n", - j, msg_buffer[j]); - } - else if (i == TEST_SEND_NMSGS-1) - { - printf("receiver_thread: ERROR mq_timedreceive of msg %d succeeded\n", i); - nerrors++; - } - else - { - printf("receiver_thread: mq_timedreceive succeeded on msg %d\n", i); - } - } - - /* Close the queue and return success */ - - if (mq_close(mqfd) < 0) - { - printf("receiver_thread: ERROR mq_close failed\n"); - nerrors++; - } - - /* Destroy the queue */ - - if (mq_unlink("testmq") < 0) - { - printf("receiver_thread: ERROR mq_close failed\n"); - nerrors++; - } - - printf("receiver_thread: returning nerrors=%d\n", nerrors); - FFLUSH(); - pthread_exit((pthread_addr_t)nerrors); - return (pthread_addr_t)nerrors; -} - -void timedmqueue_test(void) -{ - pthread_t sender; - pthread_t receiver; - void *result; - pthread_attr_t attr; - int status; - - /* Start the sending thread at the default priority */ - - printf("timedmqueue_test: Starting sender\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("timedmqueue_test: pthread_attr_init failed, status=%d\n", status); - } - - status = pthread_attr_setstacksize(&attr, STACKSIZE); - if (status != 0) - { - printf("timedmqueue_test: pthread_attr_setstacksize failed, status=%d\n", status); - } - - status = pthread_create(&sender, &attr, sender_thread, NULL); - if (status != 0) - { - printf("timedmqueue_test: pthread_create failed, status=%d\n", status); - } - - /* Wait for the sending thread to complete */ - - printf("timedmqueue_test: Waiting for sender to complete\n"); - pthread_join(sender, &result); - if (result != (void*)0) - { - printf("timedmqueue_test: ERROR sender thread exited with %d errors\n", (int)result); - } - - /* Start the receiving thread at the default priority */ - - printf("timedmqueue_test: Starting receiver\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("timedmqueue_test: pthread_attr_init failed, status=%d\n", status); - } - - status = pthread_attr_setstacksize(&attr, STACKSIZE); - if (status != 0) - { - printf("timedmqueue_test: pthread_attr_setstacksize failed, status=%d\n", status); - } - - status = pthread_create(&receiver, &attr, receiver_thread, NULL); - if (status != 0) - { - printf("timedmqueue_test: pthread_create failed, status=%d\n", status); - } - - /* Wait for the receiving thread to complete */ - - printf("timedmqueue_test: Waiting for receiver to complete\n"); - pthread_join(receiver, &result); - if (result != (void*)0) - { - printf("timedmqueue_test: ERROR receiver thread exited with %d errors\n", (int)result); - } - - printf("timedmqueue_test: Test complete\n"); -} - - diff --git a/apps/examples/ostest/timedwait.c b/apps/examples/ostest/timedwait.c deleted file mode 100644 index 7cf875fb6..000000000 --- a/apps/examples/ostest/timedwait.c +++ /dev/null @@ -1,195 +0,0 @@ -/*********************************************************************** - * examples/ostest/timedwait.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ***********************************************************************/ - -/************************************************************************** - * Included Files - **************************************************************************/ - -#include <stdio.h> -#include <time.h> -#include <pthread.h> -#include <unistd.h> -#include <errno.h> - -#include "ostest.h" - -/************************************************************************** - * Private Definitions - **************************************************************************/ - -/************************************************************************** - * Private Data - **************************************************************************/ - -static pthread_mutex_t mutex; -static pthread_cond_t cond; - -/************************************************************************** - * Private Functions - **************************************************************************/ - -static void *thread_waiter(void *parameter) -{ - struct timespec ts; - int status; - - /* Take the mutex */ - - printf("thread_waiter: Taking mutex\n"); - status = pthread_mutex_lock(&mutex); - if (status != 0) - { - printf("thread_waiter: ERROR pthread_mutex_lock failed, status=%d\n", status); - } - - printf("thread_waiter: Starting 5 second wait for condition\n"); - - status = clock_gettime(CLOCK_REALTIME, &ts); - if (status != 0) - { - printf("thread_waiter: ERROR clock_gettime failed\n"); - } - ts.tv_sec += 5; - - /* The wait -- no-one is ever going to awaken us */ - - status = pthread_cond_timedwait(&cond, &mutex, &ts); - if (status != 0) - { - if (status == ETIMEDOUT) - { - printf("thread_waiter: pthread_cond_timedwait timed out\n"); - } - else - { - printf("thread_waiter: ERROR pthread_cond_timedwait failed, status=%d\n", status); - } - } - else - { - printf("thread_waiter: ERROR pthread_cond_timedwait returned without timeout, status=%d\n", status); - } - - /* Release the mutex */ - - printf("thread_waiter: Releasing mutex\n"); - status = pthread_mutex_unlock(&mutex); - if (status != 0) - { - printf("thread_waiter: ERROR pthread_mutex_unlock failed, status=%d\n", status); - } - - printf("thread_waiter: Exit with status 0x12345678\n"); - pthread_exit((pthread_addr_t)0x12345678); - return NULL; -} - -/************************************************************************** - * Public Definitions - **************************************************************************/ - -void timedwait_test(void) -{ - pthread_t waiter; - pthread_attr_t attr; - struct sched_param sparam; - void *result; - int prio_max; - int status; - - /* Initialize the mutex */ - - printf("thread_waiter: Initializing mutex\n"); - status = pthread_mutex_init(&mutex, NULL); - if (status != 0) - { - printf("timedwait_test: ERROR pthread_mutex_init failed, status=%d\n", status); - } - - /* Initialize the condition variable */ - - printf("timedwait_test: Initializing cond\n"); - status = pthread_cond_init(&cond, NULL); - if (status != 0) - { - printf("timedwait_test: ERROR pthread_condinit failed, status=%d\n", status); - } - - /* Start the waiter thread at higher priority */ - - printf("timedwait_test: Starting waiter\n"); - status = pthread_attr_init(&attr); - if (status != 0) - { - printf("timedwait_test: pthread_attr_init failed, status=%d\n", status); - } - - prio_max = sched_get_priority_max(SCHED_FIFO); - status = sched_getparam (getpid(), &sparam); - if (status != 0) - { - printf("timedwait_test: sched_getparam failed\n"); - sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY; - } - - sparam.sched_priority = (prio_max + sparam.sched_priority) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); - if (status != OK) - { - printf("timedwait_test: pthread_attr_setschedparam failed, status=%d\n", status); - } - else - { - printf("timedwait_test: Set thread 2 priority to %d\n", sparam.sched_priority); - } - - status = pthread_create(&waiter, &attr, thread_waiter, NULL); - if (status != 0) - { - printf("timedwait_test: pthread_create failed, status=%d\n", status); - } - - printf("timedwait_test: Joining\n"); - FFLUSH(); - status = pthread_join(waiter, &result); - if (status != 0) - { - printf("timedwait_test: ERROR pthread_join failed, status=%d\n", status); - } - else - { - printf("timedwait_test: waiter exited with result=%p\n", result); - } -} diff --git a/apps/examples/ostest/vfork.c b/apps/examples/ostest/vfork.c deleted file mode 100644 index 4e1b8c892..000000000 --- a/apps/examples/ostest/vfork.c +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - * examples/ostest/vfork.c - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> - -#include "ostest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_ARCH_HAVE_VFORK) && !defined(CONFIG_DISABLE_SIGNALS) -static volatile bool g_vforkchild; -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int vfork_test(void) -{ -#if defined(CONFIG_ARCH_HAVE_VFORK) && !defined(CONFIG_DISABLE_SIGNALS) - pid_t pid; - - g_vforkchild = false; - pid = vfork(); - if (pid == 0) - { - /* There is not very much that the child is permitted to do. Perhaps - * it can just set g_vforkchild. - */ - - g_vforkchild = true; - exit(0); - } - else if (pid < 0) - { - printf("vfork_test: vfork() failed: %d\n", errno); - return -1; - } - else - { - sleep(1); - if (g_vforkchild) - { - printf("vfork_test: Child %d ran successfully\n", pid); - } - else - { - printf("vfork_test: ERROR Child %d did not run\n", pid); - return -1; - } - } -#endif - - return 0; -} diff --git a/apps/examples/ostest/waitpid.c b/apps/examples/ostest/waitpid.c deleted file mode 100644 index d45410265..000000000 --- a/apps/examples/ostest/waitpid.c +++ /dev/null @@ -1,269 +0,0 @@ -/**************************************************************************** - * examples/ostest/waitpid.c - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/wait.h> -#include <stdbool.h> -#include <stdio.h> -#include <signal.h> -#include <errno.h> - -#include "ostest.h" - -#ifdef CONFIG_SCHED_WAITPID - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define RETURN_STATUS 14 -#define NCHILDREN 3 -#define PRIORITY 100 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static int g_waitpids[NCHILDREN]; - -/**************************************************************************** - * Priviate Functions - ****************************************************************************/ - -static int waitpid_main(int argc, char *argv[]) -{ - pid_t me = getpid(); - - printf("waitpid_main: PID %d Started\n", me); - sleep(3); - printf("waitpid_main: PID %d exitting with result=%d\n", me, RETURN_STATUS); - return RETURN_STATUS; -} - -static void waitpid_start_children(void) -{ - int ret; - int i; - - for (i = 0; i < NCHILDREN; i++) - { - ret = TASK_CREATE("waitpid", PRIORITY, STACKSIZE, waitpid_main, NULL); - if (ret < 0) - { - printf("waitpid_start_child: ERROR Failed to start user_main\n"); - } - else - { - printf("waitpid_start_child: Started waitpid_main at PID=%d\n", ret); - } - - g_waitpids[i] = ret; - } -} - -static void waitpid_last(void) -{ - int stat_loc; - int ret; - - printf("waitpid_last: Waiting for PID=%d with waitpid()\n", - g_waitpids[NCHILDREN-1]); - - ret = (int)waitpid(g_waitpids[NCHILDREN-1], &stat_loc, 0); - if (ret < 0) - { - int errcode = errno; - printf("waitpid_last: ERROR: PID %d waitpid failed: %d\n", - g_waitpids[NCHILDREN-1], errcode); - } - else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) - { - printf("waitpid_last: ERROR: PID %d return status is %d, expected %d\n", - g_waitpids[NCHILDREN-1], WEXITSTATUS(stat_loc), RETURN_STATUS); - } - else - { - printf("waitpid_last: PID %d waitpid succeeded with stat_loc=%04x\n", - g_waitpids[NCHILDREN-1], stat_loc); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int waitpid_test(void) -{ -#ifdef CONFIG_SCHED_HAVE_PARENT - siginfo_t info; -#endif - int stat_loc; - int ret; - - /* Start the children and wait for first one to complete */ - - printf("\nTest waitpid()\n"); - waitpid_start_children(); - - printf("waitpid_test: Waiting for PID=%d with waitpid()\n", g_waitpids[0]); - ret = (int)waitpid(g_waitpids[0], &stat_loc, 0); - if (ret < 0) - { - int errcode = errno; - printf("waitpid_test: ERROR: PID %d waitpid failed: %d\n", - g_waitpids[0], errcode); - } - else if (ret != g_waitpids[0]) - { - printf("waitpid_test: ERROR: PID %d wait returned PID %d\n", - g_waitpids[0], ret); - } - else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) - { - printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", - g_waitpids[0], WEXITSTATUS(stat_loc), RETURN_STATUS); - } - else - { - printf("waitpid_test: PID %d waitpid succeeded with stat_loc=%04x\n", - g_waitpids[0], stat_loc); - } - - /* Wait a big to make sure that the other threads complete */ - - waitpid_last(); - sleep(1); - -#ifdef CONFIG_SCHED_HAVE_PARENT - /* Start the children and wait for first one to complete */ - - printf("\nTest waitid(P_PID)\n"); - waitpid_start_children(); - - printf("waitpid_test: Waiting for PID=%d with waitid()\n", g_waitpids[0]); - ret = waitid(P_PID, (id_t)g_waitpids[0], &info, WEXITED); - if (ret < 0) - { - int errcode = errno; - printf("waitpid_test: ERROR: PID %d waitid failed: %d\n", - g_waitpids[0], errcode); - } - else if (info.si_pid != g_waitpids[0]) - { - printf("waitpid_test: ERROR: PID %d waitid returned PID %d\n", - g_waitpids[0], info.si_pid); - } - else if (info.si_status != RETURN_STATUS) - { - printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", - info.si_pid, info.si_status, RETURN_STATUS); - } - else - { - printf("waitpid_test: waitid PID %d succeeded with si_status=%d\n", - info.si_pid, info.si_status); - } - - /* Wait a big to make sure that the other threads complete */ - - waitpid_last(); - sleep(1); - - /* Start the children and wait for any one to complete */ - - printf("\nTest waitid(P_ALL)\n"); - waitpid_start_children(); - - printf("waitpid_test: Waiting for any child with waitid()\n"); - ret = waitid(P_ALL, 0, &info, WEXITED); - if (ret < 0) - { - int errcode = errno; - printf("waitpid_test: ERROR: waitid failed: %d\n", errcode); - } - else if (info.si_status != RETURN_STATUS) - { - printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", - info.si_pid, info.si_status, RETURN_STATUS); - } - else - { - printf("waitpid_test: PID %d waitid succeeded with si_status=%d\n", - info.si_pid, info.si_status); - } - - /* Wait a big to make sure that the other threads complete */ - - waitpid_last(); - sleep(1); - - /* Start the children and wait for first one to complete */ - - printf("\nTest wait()\n"); - waitpid_start_children(); - - printf("waitpid_test: Waiting for any child with wait()\n"); - ret = (int)wait(&stat_loc); - if (ret < 0) - { - int errcode = errno; - printf("waitpid_test: ERROR: wait failed: %d\n", errcode); - } - else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) - { - printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", - ret, WEXITSTATUS(stat_loc), RETURN_STATUS); - } - else - { - printf("waitpid_test: PID %d wait succeeded with stat_loc=%04x\n", - ret, stat_loc); - } - - /* Wait a big to make sure that the other threads complete */ - - waitpid_last(); - sleep(1); -#endif - - return 0; -} - -#endif /* CONFIG_SCHED_WAITPID */ diff --git a/apps/examples/pipe/Kconfig b/apps/examples/pipe/Kconfig deleted file mode 100644 index 26bc92fcc..000000000 --- a/apps/examples/pipe/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_PIPE - bool "Pipe example" - default n - ---help--- - Enable the pipe example - -if EXAMPLES_PIPE -endif diff --git a/apps/examples/pipe/Makefile b/apps/examples/pipe/Makefile deleted file mode 100644 index bed319085..000000000 --- a/apps/examples/pipe/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -############################################################################ -# apps/examples/pipe/Makefile -# -# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Pipe Example - -ASRCS = -CSRCS = pipe_main.c transfer_test.c interlock_test.c redirect_test.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/pipe/interlock_test.c b/apps/examples/pipe/interlock_test.c deleted file mode 100644 index 20d4113eb..000000000 --- a/apps/examples/pipe/interlock_test.c +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** - * examples/pipe/interlock_test.c - * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <sys/stat.h> - -#include <sys/types.h> - -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include "pipe.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: null_writer - ****************************************************************************/ - -static void *null_writer(pthread_addr_t pvarg) -{ - int fd; - - /* Wait a bit */ - - printf("null_writer: started -- sleeping\n"); - sleep(5); - - /* Then open the FIFO for write access */ - - printf("null_writer: Opening FIFO for write access\n"); - fd = open(FIFO_PATH2, O_WRONLY); - if (fd < 0) - { - fprintf(stderr, "null_writer: Failed to open FIFO %s for writing, errno=%d\n", - FIFO_PATH2, errno); - return (void*)1; - } - - /* Wait a bit more */ - - printf("null_writer: Opened %s for writing -- sleeping\n", FIFO_PATH2); - sleep(5); - - /* Then close the FIFO */ - - printf("null_writer: Closing %s\n", FIFO_PATH2); - if (close(fd) != 0) - { - fprintf(stderr, "null_writer: close failed: %d\n", errno); - } - sleep(5); - - printf("null_writer: Returning success\n"); - return (void*)0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: interlock_test - ****************************************************************************/ - -int interlock_test(void) -{ - pthread_t writerid; - void *value; - char data[16]; - ssize_t nbytes; - int fd; - int ret; - - /* Create a FIFO */ - - ret = mkfifo(FIFO_PATH2, 0666); - if (ret < 0) - { - fprintf(stderr, "interlock_test: mkfifo failed with errno=%d\n", errno); - return 1; - } - - /* Start the null_writer_thread */ - - printf("interlock_test: Starting null_writer thread\n"); - ret = pthread_create(&writerid, NULL, null_writer, (pthread_addr_t)NULL); - if (ret != 0) - { - fprintf(stderr, "interlock_test: Failed to create null_writer thread, error=%d\n", ret); - ret = 2; - goto errout_with_fifo; - } - - /* Open one end of the FIFO for reading. This open call should block until the - * null_writer thread opens the other end of the FIFO for writing. - */ - - printf("interlock_test: Opening FIFO for read access\n"); - fd = open(FIFO_PATH2, O_RDONLY); - if (fd < 0) - { - fprintf(stderr, "interlock_test: Failed to open FIFO %s for reading, errno=%d\n", - FIFO_PATH2, errno); - ret = 3; - goto errout_with_thread; - } - - /* Attempt to read one byte from the FIFO. This should return end-of-file because - * the null_writer closes the FIFO without writing anything. - */ - - printf("interlock_test: Reading from %s\n", FIFO_PATH2); - nbytes = read(fd, data, 16); - if (nbytes < 0 ) - { - fprintf(stderr, "interlock_test: read failed, errno=%d\n", errno); - ret = 4; - goto errout_with_file; - } - else if (ret != 0) - { - fprintf(stderr, "interlock_test: Read %d bytes of data -- aborting: %d\n", nbytes); - ret = 5; - goto errout_with_file; - } - - /* Close the file */ - - printf("interlock_test: Closing %s\n", FIFO_PATH2); - if (close(fd) != 0) - { - fprintf(stderr, "interlock_test: close failed: %d\n", errno); - } - - /* Wait for null_writer thread to complete */ - - printf("interlock_test: Waiting for null_writer thread\n"); - ret = pthread_join(writerid, &value); - if (ret != 0) - { - fprintf(stderr, "interlock_test: pthread_join failed, error=%d\n", ret); - ret = 6; - goto errout_with_fifo; - } - else - { - printf("interlock_test: writer returned %d\n", (int)value); - if (value != (void*)0) - { - ret = 7; - goto errout_with_fifo; - } - } - - /* unlink(FIFO_PATH2); */ - printf("interlock_test: Returning success\n"); - return 0; - -errout_with_file: - if (close(fd) != 0) - { - fprintf(stderr, "interlock_test: close failed: %d\n", errno); - } -errout_with_thread: - pthread_detach(writerid); - pthread_cancel(writerid); -errout_with_fifo: - /* unlink(FIFO_PATH2); */ - printf("interlock_test: Returning %d\n", ret); - return ret; -} diff --git a/apps/examples/pipe/pipe.h b/apps/examples/pipe/pipe.h deleted file mode 100644 index 38143e492..000000000 --- a/apps/examples/pipe/pipe.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * examples/pipe/pipe.h - * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __EXAMPLES_PIPE_PIPE_H -#define __EXAMPLES_PIPE_PIPE_H - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define FIFO_PATH1 "/tmp/testfifo-1" -#define FIFO_PATH2 "/tmp/testfifo-2" - -#ifndef CONFIG_EXAMPLES_PIPE_STACKSIZE -# define CONFIG_EXAMPLES_PIPE_STACKSIZE 1024 -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -extern int transfer_test(int fdin, int fdout); -extern int interlock_test(void); -extern int redirection_test(void); - -#endif /* __EXAMPLES_PIPE_PIPE_H */ diff --git a/apps/examples/pipe/pipe_main.c b/apps/examples/pipe/pipe_main.c deleted file mode 100644 index 63a4f283f..000000000 --- a/apps/examples/pipe/pipe_main.c +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** - * examples/pipe/pipe_main.c - * - * Copyright (C) 2008-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 <sys/stat.h> -#include <stdio.h> -#include <unistd.h> -#include <sched.h> -#include <fcntl.h> -#include <errno.h> - -#include "pipe.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pipe_main - ****************************************************************************/ - -int pipe_main(int argc, char *argv[]) -{ - int filedes[2]; - int ret; - - /* Test FIFO logic */ - - printf("\npipe_main: Performing FIFO test\n"); - ret = mkfifo(FIFO_PATH1, 0666); - if (ret < 0) - { - fprintf(stderr, "pipe_main: mkfifo failed with errno=%d\n", errno); - return 1; - } - - /* Open one end of the FIFO for reading and the other end for writing. NOTE: - * the following might not work on most FIFO implementations because the attempt - * to open just one end of the FIFO for writing might block. The NuttX FIFOs block - * only on open for read-only (see interlock_test()). - */ - - filedes[1] = open(FIFO_PATH1, O_WRONLY); - if (filedes[1] < 0) - { - fprintf(stderr, "pipe_main: Failed to open FIFO %s for writing, errno=%d\n", - FIFO_PATH1, errno); - return 2; - } - - filedes[0] = open(FIFO_PATH1, O_RDONLY); - if (filedes[0] < 0) - { - fprintf(stderr, "pipe_main: Failed to open FIFO %s for reading, errno=%d\n", - FIFO_PATH1, errno); - if (close(filedes[1]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } - return 3; - } - - /* Then perform the test using those file descriptors */ - - ret = transfer_test(filedes[0], filedes[1]); - if (close(filedes[0]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } - if (close(filedes[1]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } - /* unlink(FIFO_PATH1); fails */ - - if (ret != 0) - { - fprintf(stderr, "pipe_main: FIFO test FAILED (%d)\n", ret); - return 4; - } - printf("pipe_main: FIFO test PASSED\n"); - - /* Test PIPE logic */ - - printf("\npipe_main: Performing pipe test\n"); - ret = pipe(filedes); - if (ret < 0) - { - fprintf(stderr, "pipe_main: pipe failed with errno=%d\n", errno); - return 5; - } - - /* Then perform the test using those file descriptors */ - - ret = transfer_test(filedes[0], filedes[1]); - if (close(filedes[0]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } - if (close(filedes[1]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } - - if (ret != 0) - { - fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret); - return 6; - } - printf("pipe_main: PIPE test PASSED\n"); - - /* Perform the FIFO interlock test */ - - printf("\npipe_main: Performing pipe interlock test\n"); - ret = interlock_test(); - if (ret != 0) - { - fprintf(stderr, "pipe_main: FIFO interlock test FAILED (%d)\n", ret); - return 7; - } - printf("pipe_main: PIPE interlock test PASSED\n"); - - /* Perform the pipe redirection test */ - - printf("\npipe_main: Performing redirection test\n"); - ret = redirection_test(); - if (ret != 0) - { - fprintf(stderr, "pipe_main: FIFO redirection test FAILED (%d)\n", ret); - return 7; - } - printf("pipe_main: PIPE redirection test PASSED\n"); - - fflush(stdout); - return 0; -} diff --git a/apps/examples/pipe/redirect_test.c b/apps/examples/pipe/redirect_test.c deleted file mode 100644 index 26fe9bcaa..000000000 --- a/apps/examples/pipe/redirect_test.c +++ /dev/null @@ -1,326 +0,0 @@ -/**************************************************************************** - * examples/pipe/redirect_test.c - * - * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sched.h> -#include <semaphore.h> -#include <errno.h> - -#include "pipe.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define READ_SIZE 37 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static sem_t g_rddone; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: redirect_reader - ****************************************************************************/ - -static int redirect_reader(int argc, char *argv[]) -{ - char buffer[READ_SIZE]; - int fdin; - int fdout; - int ret; - int nbytes = 0; - - printf("redirect_reader: started with fdin=%s\n", argv[1]); - - /* Convert the fdin to binary */ - - fdin = atoi(argv[1]); - fdout = atoi(argv[2]); - - /* Close fdout -- we don't need it */ - - ret = close(fdout); - if (ret != 0) - { - fprintf(stderr, "redirect_reader: failed to close fdout=%d\n", fdout); - return 1; - } - - /* Re-direct the fdin to stdin */ - - ret = dup2(fdin, 0); - if (ret != 0) - { - fprintf(stderr, "redirect_reader: dup2 failed: %d\n", errno); - close(fdin); - return 2; - } - - /* Close the original file descriptor */ - - ret = close(fdin); - if (ret != 0) - { - fprintf(stderr, "redirect_reader: failed to close fdin=%d\n", fdin); - return 3; - } - - /* Then read from stdin until we hit the end of file */ - - fflush(stdout); - for (;;) - { - /* Read from stdin */ - - ret = read(0, buffer, READ_SIZE); - if (ret < 0 ) - { - fprintf(stderr, "redirect_reader: read failed, errno=%d\n", errno); - return 4; - } - else if (ret == 0) - { - break; - } - nbytes += ret; - - /* Echo to stdout */ - - ret = write(1, buffer, ret); - if (ret < 0) - { - fprintf(stderr, "redirect_reader: read failed, errno=%d\n", errno); - return 5; - } - } - - printf("redirect_reader: %d bytes read\n", nbytes); - ret = close(0); - if (ret != 0) - { - fprintf(stderr, "redirect_reader: failed to close fd=0\n"); - return 6; - } - - sem_post(&g_rddone); - printf("redirect_reader: Returning success\n"); - return 0; -} - -/**************************************************************************** - * Name: redirect_writer - ****************************************************************************/ - -static int redirect_writer(int argc, char *argv[]) -{ - int fdin; - int fdout; - int nbytes = 0; - int ret; - - fprintf(stderr, "redirect_writer: started with fdout=%s\n", argv[2]); - - /* Convert the fdout to binary */ - - fdin = atoi(argv[1]); - fdout = atoi(argv[2]); - - /* Close fdin -- we don't need it */ - - ret = close(fdin); - if (ret != 0) - { - fprintf(stderr, "redirect_reader: failed to close fdin=%d\n", fdin); - return 1; - } - - /* Re-direct the fdout to stdout */ - - ret = dup2(fdout, 1); - if (ret != 0) - { - fprintf(stderr, "redirect_writer: dup2 failed: %d\n", errno); - return 2; - } - - /* Close the original file descriptor */ - - ret = close(fdout); - if (ret != 0) - { - fprintf(stderr, "redirect_reader: failed to close fdout=%d\n", fdout); - return 3; - } - - /* Then write a bunch of stuff to stdout */ - - fflush(stderr); - nbytes += printf("\nFour score and seven years ago our fathers brought forth on this continent a new nation,\n"); - nbytes += printf("conceived in Liberty, and dedicated to the proposition that all men are created equal.\n"); - nbytes += printf("\nNow we are engaged in a great civil war, testing whether that nation, or any nation, so\n"); - nbytes += printf("conceived and so dedicated, can long endure. We are met on a great battle-field of that war.\n"); - nbytes += printf("We have come to dedicate a portion of that field, as a final resting place for those who here\n"); - nbytes += printf("gave their lives that that nation might live. It is altogether fitting and proper that we\n"); - nbytes += printf("should do this.\n"); - nbytes += printf("\nBut, in a larger sense, we can not dedicate - we can not consecrate - we can not hallow - this ground.\n"); - nbytes += printf("The brave men, living and dead, who struggled here, have consecrated it, far above our poor power\n"); - nbytes += printf("to add or detract. The world will little note, nor long remember what we say here, but it can\n"); - nbytes += printf("never forget what they did here. It is for us the living, rather, to be dedicated here to the\n"); - nbytes += printf("unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to\n"); - nbytes += printf("be here dedicated to the great task remaining before us - that from these honored dead we take\n"); - nbytes += printf("increased devotion to that cause for which they gave the last full measure of devotion - that we\n"); - nbytes += printf("here highly resolve that these dead shall not have died in vain - that this nation, under God,\n"); - nbytes += printf("shall have a new birth of freedom - and that government of the people, by the people, for the\n"); - nbytes += printf("people, shall not perish from the earth.\n\n"); - fflush(stdout); - - fprintf(stderr, "redirect_writer: %d bytes written\n", nbytes); - - ret = close(1); - if (ret != 0) - { - fprintf(stderr, "redirect_writer: failed to close fd=1\n"); - return 4; - } - - fprintf(stderr, "redirect_writer: Returning success\n"); - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: redirection_test - ****************************************************************************/ - -int redirection_test(void) -{ - const char *argv[3]; - char buffer1[8]; - char buffer2[8]; - int readerid; - int writerid; - int filedes[2]; - int ret; - - sem_init(&g_rddone, 0, 0); - - /* Create the pipe */ - - ret = pipe(filedes); - if (ret < 0) - { - fprintf(stderr, "redirection_test: pipe failed with errno=%d\n", errno); - return 5; - } - - sprintf(buffer1, "%d", filedes[0]); - argv[0] = buffer1; - sprintf(buffer2, "%d", filedes[1]); - argv[1] = buffer2; - argv[2] = NULL; - - /* Start redirect_reader thread */ - - printf("redirection_test: Starting redirect_reader task with fd=%d\n", filedes[0]); - readerid = task_create("redirect_reader", 50, CONFIG_EXAMPLES_PIPE_STACKSIZE, redirect_reader, argv); - if (readerid < 0) - { - fprintf(stderr, "redirection_test: Failed to create redirect_writer task: %d\n", errno); - return 1; - } - - /* Start redirect_writer task */ - - printf("redirection_test: Starting redirect_writer task with fd=%d\n", filedes[1]); - writerid = task_create("redirect_writer", 50, CONFIG_EXAMPLES_PIPE_STACKSIZE, redirect_writer, argv); - if (writerid < 0) - { - fprintf(stderr, "redirection_test: Failed to create redirect_writer task: %d\n", errno); - ret = task_delete(readerid); - if (ret != 0) - { - fprintf(stderr, "redirection_test: Failed to delete redirect_reader task %d\n", errno); - } - return 2; - } - - /* We should be able to close the pipe file descriptors now. */ - - if (close(filedes[0]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } - if (close(filedes[1]) != 0) - { - fprintf(stderr, "pipe_main: close failed: %d\n", errno); - } - - if (ret != 0) - { - fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret); - return 6; - } - - /* Wait for redirect_writer thread to complete */ - - printf("redirection_test: Waiting...\n"); - fflush(stdout); - sem_wait(&g_rddone); - - printf("redirection_test: returning %d\n", ret); - return ret; -} - diff --git a/apps/examples/pipe/transfer_test.c b/apps/examples/pipe/transfer_test.c deleted file mode 100644 index f7c612881..000000000 --- a/apps/examples/pipe/transfer_test.c +++ /dev/null @@ -1,242 +0,0 @@ -/**************************************************************************** - * examples/pipe/transfer_test.c - * - * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <unistd.h> -#include <errno.h> - -#include "pipe.h" - -/**************************************************************************** - * Pre-proecessor Definitions - ****************************************************************************/ - -#define MAX_BYTE 13 - -#define WRITE_SIZE MAX_BYTE -#define NWRITES 1400 -#define NWRITE_BYTES (NWRITES * WRITE_SIZE) - -#define READ_SIZE (2*MAX_BYTE) -#define NREADS (NWRITES / 2) -#define NREAD_BYTES NWRITE_BYTES - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: transfer_reader - ****************************************************************************/ - -static void *transfer_reader(pthread_addr_t pvarg) -{ - char buffer[READ_SIZE]; - int fd = (int)pvarg; - int ret; - int nbytes; - int value; - int ndx; - - printf("transfer_reader: started\n"); - for (nbytes = 0, value = 0; nbytes < NREAD_BYTES;) - { - ret = read(fd, buffer, READ_SIZE); - if (ret < 0 ) - { - fprintf(stderr, "transfer_reader: read failed, errno=%d\n", errno); - return (void*)1; - } - else if (ret == 0) - { - if (nbytes < NREAD_BYTES) - { - fprintf(stderr, "transfer_reader: Too few bytes read -- aborting: %d\n", nbytes); - return (void*)2; - } - break; - } - for (ndx = 0; ndx < ret; ndx++) - { - if (value >= WRITE_SIZE) - { - value = 0; - } - if (buffer[ndx] != value) - { - fprintf(stderr, "transfer_reader: Byte %d, expected %d, found %d\n", - nbytes + ndx, value, buffer[ndx]); - return (void*)3; - } - value++; - } - nbytes += ret; - if (nbytes > NREAD_BYTES) - { - fprintf(stderr, "transfer_reader: Too many bytes read -- aborting: %d\n", nbytes); - return (void*)4; - } - } - printf("transfer_reader: %d bytes read\n", nbytes); - return (void*)0; -} - -/**************************************************************************** - * Name: transfer_writer - ****************************************************************************/ - -static void *transfer_writer(pthread_addr_t pvarg) -{ - char buffer[WRITE_SIZE]; - int fd = (int)pvarg; - int ret; - int i; - - printf("transfer_writer: started\n"); - for (i = 0; i < WRITE_SIZE; i++) - { - buffer[i] = i; - } - - for (i = 0; i < NWRITES; i++) - { - ret = write(fd, buffer, WRITE_SIZE); - if (ret < 0 ) - { - fprintf(stderr, "transfer_writer: write failed, errno=%d\n", errno); - return (void*)1; - } - else if (ret != WRITE_SIZE) - { - fprintf(stderr, "transfer_writer: Unexpected write size=%d\n", ret); - return (void*)2; - } - } - printf("transfer_writer: %d bytes written\n", NWRITE_BYTES); - return (void*)0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: transfer_test - ****************************************************************************/ - -int transfer_test(int fdin, int fdout) -{ - pthread_t readerid; - pthread_t writerid; - void *value; - int tmp; - int ret; - - /* Start transfer_reader thread */ - - printf("transfer_test: Starting transfer_reader thread\n"); - ret = pthread_create(&readerid, NULL, transfer_reader, (pthread_addr_t)fdin); - if (ret != 0) - { - fprintf(stderr, "transfer_test: Failed to create transfer_reader thread, error=%d\n", ret); - return 1; - } - - /* Start transfer_writer thread */ - - printf("transfer_test: Starting transfer_writer thread\n"); - ret = pthread_create(&writerid, NULL, transfer_writer, (pthread_addr_t)fdout); - if (ret != 0) - { - fprintf(stderr, "transfer_test: Failed to create transfer_writer thread, error=%d\n", ret); - pthread_detach(readerid); - ret = pthread_cancel(readerid); - if (ret != 0) - { - fprintf(stderr, "transfer_test: Failed to cancel transfer_reader thread, error=%d\n", ret); - } - return 2; - } - - /* Wait for transfer_writer thread to complete */ - - printf("transfer_test: Waiting for transfer_writer thread\n"); - ret = pthread_join(writerid, &value); - if (ret != 0) - { - fprintf(stderr, "transfer_test: pthread_join failed, error=%d\n", ret); - } - else - { - ret = (int)value; - printf("transfer_test: transfer_writer returned %d\n", ret); - } - - /* Wait for transfer_reader thread to complete */ - - printf("transfer_test: Waiting for transfer_reader thread\n"); - tmp = pthread_join(readerid, &value); - if (tmp != 0) - { - fprintf(stderr, "transfer_test: pthread_join failed, error=%d\n", ret); - } - else - { - tmp = (int)value; - printf("transfer_test: transfer_reader returned %d\n", tmp); - } - - if (ret == 0) - { - ret = tmp; - } - printf("transfer_test: returning %d\n", ret); - return ret; -} - diff --git a/apps/examples/poll/Kconfig b/apps/examples/poll/Kconfig deleted file mode 100644 index f35a9200b..000000000 --- a/apps/examples/poll/Kconfig +++ /dev/null @@ -1,31 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_POLL - bool "Poll example" - default n - depends on !NSH_BUILTIN_APPS - ---help--- - Enable the poll example - -if EXAMPLES_POLL - -config EXAMPLES_POLL_NOMAC - bool "Use Canned MAC Address" - default n - -config EXAMPLES_POLL_IPADDR - hex "Target IP address" - default 0x0a000002 - -config EXAMPLES_POLL_DRIPADDR - hex "Default Router IP address (Gateway)" - default 0x0a000001 - -config EXAMPLES_POLL_NETMASK - hex "Network Mask" - default 0xffffff00 - -endif diff --git a/apps/examples/poll/Makefile b/apps/examples/poll/Makefile deleted file mode 100644 index 13173f125..000000000 --- a/apps/examples/poll/Makefile +++ /dev/null @@ -1,98 +0,0 @@ -############################################################################ -# apps/examples/poll/Makefile -# -# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Device Driver poll()/select() Example - -ASRCS = -CSRCS = poll_main.c poll_listener.c select_listener.c net_listener.c net_reader.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -# Register application -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - $(call DELFILE, host$(HOSTEXEEXT)) - --include Make.dep diff --git a/apps/examples/poll/Makefile.host b/apps/examples/poll/Makefile.host deleted file mode 100644 index 1e6a72089..000000000 --- a/apps/examples/poll/Makefile.host +++ /dev/null @@ -1,54 +0,0 @@ -############################################################################ -# apps/examples/poll/Makefile.host -# -# Copyright (C) 2008, 2009, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -# TOPDIR must be defined on the make command line - -include $(TOPDIR)/.config -include $(TOPDIR)/Make.defs - -SRC = host.c -BIN = host - -DEFINES = -DTARGETIP=\"$(TARGETIP)\" - -all: $(BIN) - -$(BIN): $(SRC) - $(HOSTCC) $(HOSTCFLAGS) $(DEFINES) $^ -o $@ - -clean: - @rm -f $(BIN) *~ .*.swp *.o - $(call CLEAN) - diff --git a/apps/examples/poll/host.c b/apps/examples/poll/host.c deleted file mode 100644 index 302cceb0f..000000000 --- a/apps/examples/poll/host.c +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** - * examples/poll/host.c - * - * Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <sys/socket.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <pthread.h> -#include <string.h> -#include <errno.h> - -#include <netinet/in.h> -#include <arpa/inet.h> - -#define pthread_addr_t void * -#include "poll_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef TARGETIP -# error TARGETIP not defined -#endif - -#define IOBUFFER_SIZE 80 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * main - ****************************************************************************/ - -int main(int argc, char **argv, char **envp) -{ - struct sockaddr_in myaddr; - char outbuf[IOBUFFER_SIZE]; - char inbuf[IOBUFFER_SIZE]; - int sockfd; - int len; - int nbytessent; - int nbytesrecvd; - int i; - - /* 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_outbufs; - } - - /* Connect the socket to the server */ - - myaddr.sin_family = AF_INET; - myaddr.sin_port = htons(LISTENER_PORT); - myaddr.sin_addr.s_addr = inet_addr(TARGETIP); - - message("client: Connecting to %s...\n", TARGETIP); - 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"); - - /* Then send and receive messages */ - - for (i = 0; ; i++) - { - sprintf(outbuf, "Remote message %d", i); - len = strlen(outbuf); - - message("client: Sending '%s' (%d bytes)\n", outbuf, len); - nbytessent = send(sockfd, outbuf, len, 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 != len) - { - message("client: Bad send length: %d Expected: %d\n", nbytessent, len); - goto errout_with_socket; - } - - message("client: Receiving...\n"); - nbytesrecvd = recv(sockfd, inbuf, IOBUFFER_SIZE, 0); - - if (nbytesrecvd < 0) - { - message("client: recv failed: %d\n", errno); - goto errout_with_socket; - } - else if (nbytesrecvd == 0) - { - message("client: The server broke the connections\n"); - goto errout_with_socket; - } - - inbuf[nbytesrecvd] = '\0'; - message("client: Received '%s' (%d bytes)\n", inbuf, nbytesrecvd); - - if (nbytesrecvd != len) - { - message("client: Bad recv length: %d Expected: %d\n", nbytesrecvd, len); - goto errout_with_socket; - } - else if (memcmp(inbuf, outbuf, len) != 0) - { - message("client: Received outbuf does not match sent outbuf\n"); - goto errout_with_socket; - } - - message("client: Sleeping\n"); - sleep(8); - } - - close(sockfd); - return 0; - -errout_with_socket: - close(sockfd); -errout_with_outbufs: - exit(1); -} diff --git a/apps/examples/poll/net_listener.c b/apps/examples/poll/net_listener.c deleted file mode 100644 index 2be98673c..000000000 --- a/apps/examples/poll/net_listener.c +++ /dev/null @@ -1,428 +0,0 @@ -/**************************************************************************** - * examples/poll/net_listener.c - * - * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/stat.h> -#include <sys/select.h> -#include <sys/socket.h> -#include <sys/ioctl.h> - -#include <stdint.h> -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <pthread.h> -#include <errno.h> -#include <debug.h> - -#include <net/if.h> -#include <apps/netutils/uiplib.h> - -#include "poll_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define IOBUFFER_SIZE 80 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct net_listener_s -{ - struct sockaddr_in addr; - fd_set master; - fd_set working; - char buffer[IOBUFFER_SIZE]; - int listensd; - int mxsd; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: net_closeclient - ****************************************************************************/ - -static bool net_closeclient(struct net_listener_s *nls, int sd) -{ - message("net_listener: Closing host side connection sd=%d\n", sd); - close(sd); - FD_CLR(sd, &nls->master); - - /* If we just closed the max SD, then search downward for the next biggest SD. */ - - while (FD_ISSET(nls->mxsd, &nls->master) == false) - { - nls->mxsd -= 1; - } - return true; -} - -/**************************************************************************** - * Name: net_incomingdata - ****************************************************************************/ - -static inline bool net_incomingdata(struct net_listener_s *nls, int sd) -{ - char *ptr; - int nbytes; - int ret; - - /* Read data from the socket */ - -#ifdef FIONBIO - for (;;) -#endif - { - message("net_listener: Read data from sd=%d\n", sd); - ret = recv(sd, nls->buffer, IOBUFFER_SIZE, 0); - if (ret < 0) - { - if (errno != EINTR) - { - message("net_listener: recv failed sd=%d: %d\n", sd, errno); - if (errno != EAGAIN) - { - net_closeclient(nls, sd); - return false; - } - } - } - else if (ret == 0) - { - message("net_listener: Client connection lost sd=%d\n", sd); - net_closeclient(nls, sd); - return false; - } - else - { - nls->buffer[ret]='\0'; - message("poll_listener: Read '%s' (%d bytes)\n", nls->buffer, ret); - - /* Echo the data back to the client */ - - for (nbytes = ret, ptr = nls->buffer; nbytes > 0; ) - { - ret = send(sd, ptr, nbytes, 0); - if (ret < 0) - { - if (errno != EINTR) - { - message("net_listener: Send failed sd=%d: \n", sd, errno); - net_closeclient(nls, sd); - return false; - } - } - else - { - nbytes -= ret; - ptr += ret; - } - } - } - } - return 0; -} - -/**************************************************************************** - * Name: net_connection - ****************************************************************************/ - -static inline bool net_connection(struct net_listener_s *nls) -{ - int sd; - - /* Loop until all connections have been processed */ - -#ifdef FIONBIO - for (;;) -#endif - { - message("net_listener: Accepting new connection on sd=%d\n", nls->listensd); - - sd = accept(nls->listensd, NULL, NULL); - if (sd < 0) - { - message("net_listener: accept failed: %d\n", errno); - - if (errno != EINTR) - { - return false; - } - } - else - { - /* Add the new connection to the master set */ - - message("net_listener: Connection accepted for sd=%d\n", sd); - - FD_SET(sd, &nls->master); - if (sd > nls->mxsd) - { - nls->mxsd = sd; - } - return true; - } - } - return false; -} - -/**************************************************************************** - * Name: net_mksocket - ****************************************************************************/ - -static inline bool net_mksocket(struct net_listener_s *nls) -{ - int value; - int ret; - - /* Create a listening socket */ - - message("net_listener: Initializing listener socket\n"); - nls->listensd = socket(AF_INET, SOCK_STREAM, 0); - if (nls->listensd < 0) - { - message("net_listener: socket failed: %d\n", errno); - return false; - } - - /* Configure the socket */ - - value = 1; - ret = setsockopt(nls->listensd, SOL_SOCKET, SO_REUSEADDR, (char*)&value, sizeof(int)); - if (ret < 0) - { - message("net_listener: setsockopt failed: %d\n", errno); - close(nls->listensd); - return false; - } - - /* Set the socket to non-blocking */ - -#ifdef FIONBIO - ret = ioctl(nls->listensd, FIONBIO, (char *)&value); - if (ret < 0) - { - message("net_listener: ioctl failed: %d\n", errno); - close(nls->listensd); - return false; - } -#endif - - /* Bind the socket */ - - memset(&nls->addr, 0, sizeof(struct sockaddr_in)); - nls->addr.sin_family = AF_INET; - nls->addr.sin_addr.s_addr = htonl(INADDR_ANY); - nls->addr.sin_port = htons(LISTENER_PORT); - ret = bind(nls->listensd, (struct sockaddr *)&nls->addr, sizeof(struct sockaddr_in)); - if (ret < 0) - { - message("net_listener: bind failed: %d\n", errno); - close(nls->listensd); - return false; - } - - /* Mark the socket as a listener */ - - ret = listen(nls->listensd, 32); - if (ret < 0) - { - message("net_listener: bind failed: %d\n", errno); - close(nls->listensd); - return false; - } - - return true; -} - -/**************************************************************************** - * Name: net_configure - ****************************************************************************/ - -static void net_configure(void) -{ - struct in_addr addr; -#if defined(CONFIG_EXAMPLES_POLL_NOMAC) - uint8_t mac[IFHWADDRLEN]; -#endif - - /* Configure uIP */ - /* Many embedded network interfaces must have a software assigned MAC */ - -#ifdef CONFIG_EXAMPLES_POLL_NOMAC - mac[0] = 0x00; - mac[1] = 0xe0; - mac[2] = 0xde; - mac[3] = 0xad; - mac[4] = 0xbe; - mac[5] = 0xef; - uip_setmacaddr("eth0", mac); -#endif - - /* Set up our host address */ - - addr.s_addr = HTONL(CONFIG_EXAMPLES_POLL_IPADDR); - uip_sethostaddr("eth0", &addr); - - /* Set up the default router address */ - - addr.s_addr = HTONL(CONFIG_EXAMPLES_POLL_DRIPADDR); - uip_setdraddr("eth0", &addr); - - /* Setup the subnet mask */ - - addr.s_addr = HTONL(CONFIG_EXAMPLES_POLL_NETMASK); - uip_setnetmask("eth0", &addr); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: net_listener - ****************************************************************************/ - -void *net_listener(pthread_addr_t pvarg) -{ - struct net_listener_s nls; - struct timeval timeout; - int nsds; - int ret; - int i; - - /* Configure uIP */ - - net_configure(); - - /* Set up a listening socket */ - - memset(&nls, 0, sizeof(struct net_listener_s)); - if (!net_mksocket(&nls)) - { - return (void*)1; - } - - /* Initialize the 'master' file descriptor set */ - - FD_ZERO(&nls.master); - nls.mxsd = nls.listensd; - FD_SET(nls.listensd, &nls.master); - - /* Set up a 3 second timeout */ - - timeout.tv_sec = NET_LISTENER_DELAY; - timeout.tv_usec = 0; - - /* Loop waiting for incoming connections or for incoming data - * on any of the connect sockets. - */ - - for (;;) - { - /* Wait on select */ - - message("net_listener: Calling select(), listener sd=%d\n", nls.listensd); - memcpy(&nls.working, &nls.master, sizeof(fd_set)); - ret = select(nls.mxsd + 1, (FAR fd_set*)&nls.working, (FAR fd_set*)NULL, (FAR fd_set*)NULL, &timeout); - if (ret < 0) - { - message("net_listener: select failed: %d\n", errno); - break; - } - - /* Check for timeout */ - - if (ret == 0) - { - message("net_listener: Timeout\n"); - continue; - } - - /* Find which descriptors caused the wakeup */ - - nsds = ret; - for (i = 0; i <= nls.mxsd && nsds > 0; i++) - { - /* Is this descriptor ready? */ - - if (FD_ISSET(i, &nls.working)) - { - /* Yes, is it our listener? */ - - message("net_listener: Activity on sd=%d\n", i); - - nsds--; - if (i == nls.listensd) - { - (void)net_connection(&nls); - } - else - { - net_incomingdata(&nls, i); - } - } - } - } - - /* Cleanup */ - -#if 0 /* Don't get here */ - for (i = 0; i <= nls.mxsd; +i++) - { - if (FD_ISSET(i, &nls.master)) - { - close(i); - } - } -#endif - return NULL; /* Keeps some compilers from complaining */ -} diff --git a/apps/examples/poll/net_reader.c b/apps/examples/poll/net_reader.c deleted file mode 100644 index 2f23bab3c..000000000 --- a/apps/examples/poll/net_reader.c +++ /dev/null @@ -1,317 +0,0 @@ -/**************************************************************************** - * examples/poll/net_reader.c - * - * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/select.h> -#include <sys/socket.h> - -#include <stdint.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <pthread.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#include <net/if.h> -#include <apps/netutils/uiplib.h> - -#include "poll_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define IOBUFFER_SIZE 80 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: net_configure - ****************************************************************************/ - -static void net_configure(void) -{ - struct in_addr addr; -#if defined(CONFIG_EXAMPLES_POLL_NOMAC) - uint8_t mac[IFHWADDRLEN]; -#endif - - /* Configure uIP */ - /* Many embedded network interfaces must have a software assigned MAC */ - -#ifdef CONFIG_EXAMPLES_POLL_NOMAC - mac[0] = 0x00; - mac[1] = 0xe0; - mac[2] = 0xde; - mac[3] = 0xad; - mac[4] = 0xbe; - mac[5] = 0xef; - uip_setmacaddr("eth0", mac); -#endif - - /* Set up our host address */ - - addr.s_addr = HTONL(CONFIG_EXAMPLES_POLL_IPADDR); - uip_sethostaddr("eth0", &addr); - - /* Set up the default router address */ - - addr.s_addr = HTONL(CONFIG_EXAMPLES_POLL_DRIPADDR); - uip_setdraddr("eth0", &addr); - - /* Setup the subnet mask */ - - addr.s_addr = HTONL(CONFIG_EXAMPLES_POLL_NETMASK); - uip_setnetmask("eth0", &addr); -} - -/**************************************************************************** - * Name: net_receive - ****************************************************************************/ - -static void net_receive(int sd) -{ - struct timeval timeout; - char buffer[IOBUFFER_SIZE]; - char *ptr; - fd_set readset; - int nbytes; - int ret; - - /* Set up the timeout */ - - timeout.tv_sec = NET_LISTENER_DELAY; - timeout.tv_usec = 0; - - /* Loop while we have the connection */ - - for (;;) - { - /* Wait for incoming message */ - - do - { - FD_ZERO(&readset); - FD_SET(sd, &readset); - ret = select(sd + 1, (FAR fd_set*)&readset, (FAR fd_set*)NULL, (FAR fd_set*)NULL, &timeout); - } - while (ret < 0 && errno == EINTR); - - /* Something has happened */ - - if (ret < 0) - { - message("net_reader: select failed: %d\n", errno); - return; - } - else if (ret == 0) - { - message("net_reader: Timeout\n"); - } - else - { - message("net_reader: Read data from sd=%d\n", sd); - memset(buffer, '?', IOBUFFER_SIZE); /* Just to make sure we really receive something */ - ret = recv(sd, buffer, IOBUFFER_SIZE, 0); - if (ret < 0) - { - if (errno != EINTR) - { - message("net_reader: recv failed sd=%d: %d\n", sd, errno); - if (errno != EAGAIN) - { - return; - } - } - } - else if (ret == 0) - { - message("net_reader: Client connection lost sd=%d\n", sd); - return; - } - else - { - buffer[ret]='\0'; - message("net_reader: Read '%s' (%d bytes)\n", buffer, ret); - - /* Echo the data back to the client */ - - for (nbytes = ret, ptr = buffer; nbytes > 0; ) - { - ret = send(sd, ptr, nbytes, 0); - if (ret < 0) - { - if (errno != EINTR) - { - message("net_reader: Send failed sd=%d: %d\n", sd, errno); - return; - } - } - else - { - nbytes -= ret; - ptr += ret; - } - } - } - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: net_reader - ****************************************************************************/ - -void *net_reader(pthread_addr_t pvarg) -{ - struct sockaddr_in addr; -#ifdef POLL_HAVE_SOLINGER - struct linger ling; -#endif - int listensd; - int acceptsd; - socklen_t addrlen; - int optval; - - /* Configure uIP */ - - net_configure(); - - /* Create a new TCP socket */ - - listensd = socket(PF_INET, SOCK_STREAM, 0); - if (listensd < 0) - { - message("net_reader: socket failure: %d\n", errno); - goto errout; - } - - /* Set socket to reuse address */ - - optval = 1; - if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) - { - message("net_reader: setsockopt SO_REUSEADDR failure: %d\n", errno); - goto errout_with_listensd; - } - - /* Bind the socket to a local address */ - - addr.sin_family = AF_INET; - addr.sin_port = HTONS(LISTENER_PORT); - addr.sin_addr.s_addr = INADDR_ANY; - - if (bind(listensd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) < 0) - { - message("net_reader: bind failure: %d\n", errno); - goto errout_with_listensd; - } - - /* Listen for connections on the bound TCP socket */ - - if (listen(listensd, 5) < 0) - { - message("net_reader: listen failure %d\n", errno); - goto errout_with_listensd; - } - - /* Connection loop */ - - for (;;) - { - /* Accept only one connection */ - - message("net_reader: Accepting new connections on port %d\n", LISTENER_PORT); - addrlen = sizeof(struct sockaddr_in); - acceptsd = accept(listensd, (struct sockaddr*)&addr, &addrlen); - if (acceptsd < 0) - { - message("net_reader: accept failure: %d\n", errno); - continue; - } - message("net_reader: Connection accepted on sd=%d\n", acceptsd); - - /* Configure to "linger" until all data is sent when the socket is closed */ - -#ifdef POLL_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("net_reader: setsockopt SO_LINGER failure: %d\n", errno); - goto errout_with_acceptsd; - } -#endif - - /* Handle incoming messsages on the connection. */ - - net_receive(acceptsd); - - message("net_reader: Closing sd=%d\n", acceptsd); - close(acceptsd); - } - -#ifdef POLL_HAVE_SOLINGER -errout_with_acceptsd: - close(acceptsd); -#endif -errout_with_listensd: - close(listensd); -errout: - return NULL; -} diff --git a/apps/examples/poll/poll_internal.h b/apps/examples/poll/poll_internal.h deleted file mode 100644 index 759d23f1c..000000000 --- a/apps/examples/poll/poll_internal.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** - * examples/poll/poll_internal.h - * - * Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __EXAMPLES_PIPE_PIPE_H -#define __EXAMPLES_PIPE_PIPE_H - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <pthread.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#ifdef CONFIG_DISABLE_POLL -# error "The polling API is disabled" -#endif - -/* Here are all of the configuration settings that must be met to have TCP/IP - * poll/select support. This kind of looks like overkill. - * - * CONFIG_NET - Network support must be enabled - * CONFIG_NSOCKET_DESCRIPTORS - Socket descriptors must be allocated - * CONFIG_NET_TCP - Only support on TCP (because read-ahead - * ibuffering s not yet support for UDP) - * CONFIG_NET_NTCP_READAHEAD_BUFFERS - TCP/IP read-ahead buffering must be enabled - */ - -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 && \ - defined(CONFIG_NET_TCP) && CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 -# define HAVE_NETPOLL 1 -#else -# undef HAVE_NETPOLL -#endif - -/* If debug is enabled, then use syslog so that OS debug output and - * the test output are synchronized. - * - * These macros will differ depending upon if the toolchain supports - * macros with a variable number of arguments or not. - */ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG -# define message(...) syslog(__VA_ARGS__) -# define msgflush() -# else -# define message(...) printf(__VA_ARGS__) -# define msgflush() fflush(stdout) -# endif -#else -# ifdef CONFIG_DEBUG -# define message syslog -# define msgflush() -# else -# define message printf -# define msgflush() fflush(stdout) -# endif -#endif - -#define FIFO_PATH1 "/dev/fifo0" -#define FIFO_PATH2 "/dev/fifo1" - -#define POLL_LISTENER_DELAY 2000 /* 2 seconds */ -#define SELECT_LISTENER_DELAY 4 /* 4 seconds */ -#define NET_LISTENER_DELAY 3 /* 3 seconds */ -#define WRITER_DELAY 6 /* 6 seconds */ - -#define LISTENER_PORT 5471 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -extern void *poll_listener(pthread_addr_t pvarg); -extern void *select_listener(pthread_addr_t pvarg); - -#ifdef HAVE_NETPOLL -extern void *net_listener(pthread_addr_t pvarg); -extern void *net_reader(pthread_addr_t pvarg); -#endif -#endif /* __EXAMPLES_PIPE_PIPE_H */ diff --git a/apps/examples/poll/poll_listener.c b/apps/examples/poll/poll_listener.c deleted file mode 100644 index fe1c95089..000000000 --- a/apps/examples/poll/poll_listener.c +++ /dev/null @@ -1,262 +0,0 @@ -/**************************************************************************** - * examples/poll/poll_listener.c - * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <pthread.h> -#include <poll.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#include "poll_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#if defined(CONFIG_DEV_CONSOLE) && !defined(CONFIG_DEV_LOWCONSOLE) -# define HAVE_CONSOLE -# define NPOLLFDS 2 -# define CONSNDX 0 -# define FIFONDX 1 -#else -# undef HAVE_CONSOLE -# define NPOLLFDS 1 -# define FIFONDX 0 -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: poll_listener - ****************************************************************************/ - -void *poll_listener(pthread_addr_t pvarg) -{ - struct pollfd fds[NPOLLFDS]; - char buffer[64]; - ssize_t nbytes; - bool timeout; - bool pollin; - int nevents; - int fd; - int ret; - int i; - - /* Open the FIFO for non-blocking read */ - - message("poll_listener: Opening %s for non-blocking read\n", FIFO_PATH1); - fd = open(FIFO_PATH1, O_RDONLY|O_NONBLOCK); - if (fd < 0) - { - message("poll_listener: ERROR Failed to open FIFO %s: %d\n", - FIFO_PATH1, errno); - (void)close(fd); - return (void*)-1; - } - - /* Loop forever */ - - for (;;) - { - message("poll_listener: Calling poll()\n"); - - memset(fds, 0, sizeof(struct pollfd)*NPOLLFDS); -#ifdef HAVE_CONSOLE - fds[CONSNDX].fd = 0; - fds[CONSNDX].events = POLLIN; - fds[CONSNDX].revents = 0; -#endif - fds[FIFONDX].fd = fd; - fds[FIFONDX].events = POLLIN; - fds[FIFONDX].revents = 0; - - timeout = false; - pollin = false; - - ret = poll(fds, NPOLLFDS, POLL_LISTENER_DELAY); - - message("\npoll_listener: poll returned: %d\n", ret); - if (ret < 0) - { - message("poll_listener: ERROR poll failed: %d\n", errno); - } - else if (ret == 0) - { - message("poll_listener: Timeout\n"); - timeout = true; - } - else if (ret > NPOLLFDS) - { - message("poll_listener: ERROR poll reported: %d\n"); - } - else - { - pollin = true; - } - - nevents = 0; - for (i = 0; i < NPOLLFDS; i++) - { - message("poll_listener: FIFO revents[%d]=%02x\n", i, fds[i].revents); - if (timeout) - { - if (fds[i].revents != 0) - { - message("poll_listener: ERROR? expected revents=00, received revents[%d]=%02x\n", - fds[i].revents, i); - } - } - else if (pollin) - { - if (fds[i].revents == POLLIN) - { - nevents++; - } - else if (fds[i].revents != 0) - { - message("poll_listener: ERROR unexpected revents[i]=%02x\n", - i, fds[i].revents); - } - } - } - - if (pollin && nevents != ret) - { - message("poll_listener: ERROR found %d events, poll reported %d\n", nevents, ret); - } - - /* In any event, read until the pipe/serial is empty */ - - for (i = 0; i < NPOLLFDS; i++) - { - do - { -#ifdef HAVE_CONSOLE - /* Hack to work around the fact that the console driver on the - * simulator is always non-blocking. - */ - - if (i == CONSNDX) - { - if ((fds[CONSNDX].revents & POLLIN) != 0) - { - buffer[0] = getchar(); - nbytes = 1; - } - else - { - nbytes = 0; - } - } - else -#endif - { - /* The pipe works differently, it returns whatever data - * it has available without blocking. - */ - - nbytes = read(fds[i].fd, buffer, 63); - } - - if (nbytes <= 0) - { - if (nbytes == 0 || errno == EAGAIN) - { - if ((fds[i].revents & POLLIN) != 0) - { - message("poll_listener: ERROR no read data[%d]\n", i); - } - } - else if (errno != EINTR) - { - message("poll_listener: read[%d] failed: %d\n", i, errno); - } - nbytes = 0; - } - else - { - if (timeout) - { - message("poll_listener: ERROR? Poll timeout, but data read[%d]\n", i); - message(" (might just be a race condition)\n"); - } - - buffer[nbytes] = '\0'; - message("poll_listener: Read[%d] '%s' (%d bytes)\n", i, buffer, nbytes); - } - - /* Suppress error report if no read data on the next time through */ - - fds[i].revents = 0; - } - while (nbytes > 0); - } - - /* Make sure that everything is displayed */ - - msgflush(); - } - - /* Won't get here */ - - (void)close(fd); - return NULL; -} diff --git a/apps/examples/poll/poll_main.c b/apps/examples/poll/poll_main.c deleted file mode 100644 index 0c475fa7a..000000000 --- a/apps/examples/poll/poll_main.c +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************** - * examples/poll/poll_main.c - * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/stat.h> - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <pthread.h> -#include <fcntl.h> -#include <poll.h> -#include <errno.h> -#include <debug.h> - -#include "poll_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: poll_main - ****************************************************************************/ - -int poll_main(int argc, char *argv[]) -{ - char buffer[64]; - ssize_t nbytes; - pthread_t tid1; - pthread_t tid2; -#ifdef HAVE_NETPOLL - pthread_t tid3; -#endif - int count; - int fd1 = -1; - int fd2 = -1; - int ret; - int exitcode = 0; - - /* Open FIFOs */ - - message("\npoll_main: Creating FIFO %s\n", FIFO_PATH1); - ret = mkfifo(FIFO_PATH1, 0666); - if (ret < 0) - { - message("poll_main: mkfifo failed: %d\n", errno); - exitcode = 1; - goto errout; - } - - message("\npoll_main: Creating FIFO %s\n", FIFO_PATH2); - ret = mkfifo(FIFO_PATH2, 0666); - if (ret < 0) - { - message("poll_main: mkfifo failed: %d\n", errno); - exitcode = 2; - goto errout; - } - - /* Open the FIFOs for blocking, write */ - - fd1 = open(FIFO_PATH1, O_WRONLY); - if (fd1 < 0) - { - message("poll_main: Failed to open FIFO %s for writing, errno=%d\n", - FIFO_PATH1, errno); - exitcode = 3; - goto errout; - } - - fd2 = open(FIFO_PATH2, O_WRONLY); - if (fd2 < 0) - { - message("poll_main: Failed to open FIFO %s for writing, errno=%d\n", - FIFO_PATH2, errno); - exitcode = 4; - goto errout; - } - - /* Start the listeners */ - - message("poll_main: Starting poll_listener thread\n"); - - ret = pthread_create(&tid1, NULL, poll_listener, NULL); - if (ret != 0) - { - message("poll_main: Failed to create poll_listener thread: %d\n", ret); - exitcode = 5; - goto errout; - } - - message("poll_main: Starting select_listener thread\n"); - - ret = pthread_create(&tid2, NULL, select_listener, NULL); - if (ret != 0) - { - message("poll_main: Failed to create select_listener thread: %d\n", ret); - exitcode = 6; - goto errout; - } - -#ifdef HAVE_NETPOLL -#ifdef CONFIG_NET_TCPBACKLOG - message("poll_main: Starting net_listener thread\n"); - - ret = pthread_create(&tid3, NULL, net_listener, NULL); -#else - message("poll_main: Starting net_reader thread\n"); - - ret = pthread_create(&tid3, NULL, net_reader, NULL); -#endif - if (ret != 0) - { - message("poll_main: Failed to create net_listener thread: %d\n", ret); - } -#endif - - /* Loop forever */ - - for (count = 0; ; count++) - { - /* Send a message to the listener... this should wake the listener - * from the poll. - */ - - sprintf(buffer, "Message %d", count); - nbytes = write(fd1, buffer, strlen(buffer)); - if (nbytes < 0) - { - message("poll_main: Write to fd1 failed: %d\n", errno); - exitcode = 7; - goto errout; - } - - nbytes = write(fd2, buffer, strlen(buffer)); - if (nbytes < 0) - { - message("poll_main: Write fd2 failed: %d\n", errno); - exitcode = 8; - goto errout; - } - - message("\npoll_main: Sent '%s' (%d bytes)\n", buffer, nbytes); - msgflush(); - - /* Wait awhile. This delay should be long enough that the - * listener will timeout. - */ - - sleep(WRITER_DELAY); - } - -errout: - if (fd1 >= 0) - { - close(fd1); - } - - if (fd2 >= 0) - { - close(fd2); - } - - fflush(stdout); - return exitcode; -} diff --git a/apps/examples/poll/select_listener.c b/apps/examples/poll/select_listener.c deleted file mode 100644 index 5cb7e7805..000000000 --- a/apps/examples/poll/select_listener.c +++ /dev/null @@ -1,193 +0,0 @@ -/**************************************************************************** - * examples/poll/select_listener.c - * - * Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/select.h> -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <pthread.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#include "poll_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: select_listener - ****************************************************************************/ - -void *select_listener(pthread_addr_t pvarg) -{ - fd_set rfds; - struct timeval tv; - char buffer[64]; - ssize_t nbytes; - bool timeout; - bool ready; - int fd; - int ret; - - /* Open the FIFO for non-blocking read */ - - message("select_listener: Opening %s for non-blocking read\n", FIFO_PATH2); - fd = open(FIFO_PATH2, O_RDONLY|O_NONBLOCK); - if (fd < 0) - { - message("select_listener: ERROR Failed to open FIFO %s: %d\n", - FIFO_PATH2, errno); - (void)close(fd); - return (void*)-1; - } - - /* Loop forever */ - - for (;;) - { - message("select_listener: Calling select()\n"); - - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - - tv.tv_sec = SELECT_LISTENER_DELAY; - tv.tv_usec = 0; - - timeout = false; - ready = false; - - ret = select(fd+1, (FAR fd_set*)&rfds, (FAR fd_set*)NULL, (FAR fd_set*)NULL, &tv); - message("\nselect_listener: select returned: %d\n", ret); - - if (ret < 0) - { - message("select_listener: ERROR select failed: %d\n"); - } - else if (ret == 0) - { - message("select_listener: Timeout\n"); - timeout = true; - } - else - { - if (ret != 1) - { - message("select_listener: ERROR poll reported: %d\n"); - } - else - { - ready = true; - } - - if (!FD_ISSET(fd, rfds)) - { - message("select_listener: ERROR fd=%d not in fd_set\n"); - } - } - - /* In any event, read until the pipe is empty */ - - do - { - nbytes = read(fd, buffer, 63); - if (nbytes <= 0) - { - if (nbytes == 0 || errno == EAGAIN) - { - if (ready) - { - message("select_listener: ERROR no read data\n"); - } - } - else if (errno != EINTR) - { - message("select_listener: read failed: %d\n", errno); - } - nbytes = 0; - } - else - { - if (timeout) - { - message("select_listener: ERROR? Poll timeout, but data read\n"); - message(" (might just be a race condition)\n"); - } - - buffer[nbytes] = '\0'; - message("select_listener: Read '%s' (%d bytes)\n", buffer, nbytes); - } - - timeout = false; - ready = false; - } - while (nbytes > 0); - - /* Make sure that everything is displayed */ - - msgflush(); - } - - /* Won't get here */ - - (void)close(fd); - return NULL; -} diff --git a/apps/examples/posix_spawn/Kconfig b/apps/examples/posix_spawn/Kconfig deleted file mode 100644 index 508065913..000000000 --- a/apps/examples/posix_spawn/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_POSIXSPAWN - bool "posix_spawn Unit Test" - default n - ---help--- - Enable the posix_spawn() unit test - -if EXAMPLES_POSIXSPAWN -config EXAMPLES_POSIXSPAWN_DEVMINOR - int "ROMFS Minor Device Number" - default 0 - ---help--- - The minor device number of the ROMFS block. For example, the N in /dev/ramN. - Used for registering the RAM block driver that will hold the ROMFS file system - containing the ELF executables to be tested. Default: 0 - -config EXAMPLES_POSIXSPAWN_DEVPATH - string "ROMFS Devie Path" - default "/dev/ram0" - ---help--- - The path to the ROMFS block driver device. This must match EXAMPLES_POSIXSPAWN_DEVMINOR. - Used for registering the RAM block driver that will hold the ROMFS file system - containing the ELF executables to be tested. Default: "/dev/ram0" - -endif diff --git a/apps/examples/posix_spawn/Makefile b/apps/examples/posix_spawn/Makefile deleted file mode 100644 index 0bfa36e55..000000000 --- a/apps/examples/posix_spawn/Makefile +++ /dev/null @@ -1,130 +0,0 @@ -############################################################################ -# apps/examples/posix_spawn/Makefile -# -# Copyright (C) 2013 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# ELF Example - -ASRCS = -CSRCS = spawn_main.c symtab.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . --dep-path filesystem - -# Build targets - -VPATH = filesystem - -all: build -.PHONY: build clean_filesystem clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -# This is a little messy. The build is broken into two pieces: (1) the -# filesystem/ subdir build that auto-generates several files, and (2) the library -# build. This is done because we need a fresh build context after auto- -# generating the source files. - -build_lib: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - -build: - @$(MAKE) -C filesystem TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) - @$(MAKE) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" build_lib - -context: - -# We can't make dependencies in this directory because the required -# header files may not yet exist. - -.depend: - @touch $@ - -depend: .depend - -clean_filesystem: - @$(MAKE) -C filesystem TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) clean - -clean: clean_filesystem - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - -# There are no dependencies in this directory. Some of more important -# and more obvious dependencies are hard-coded here: - -spawn_main.o: spawn_main.c \ - $(TOPDIR)/include/nuttx/config.h \ - $(TOPDIR)/include/nuttx/compiler.h \ - $(TOPDIR)/include/sys/mount.h \ - $(TOPDIR)/include/stdio.h \ - $(TOPDIR)/include/stdlib.h \ - $(TOPDIR)/include/unistd.h \ - $(TOPDIR)/include/string.h \ - $(TOPDIR)/include/fcntl.h \ - $(TOPDIR)/include/spawn.h \ - $(TOPDIR)/include/debug.h \ - $(TOPDIR)/include/errno.h \ - $(TOPDIR)/include/nuttx/ramdisk.h \ - $(TOPDIR)/include/nuttx/binfmt/elf.h \ - $(TOPDIR)/include/nuttx/binfmt/symtab.h \ - filesystem/romfs.h - -symtab.o: filesystem/symtab.c \ - $(TOPDIR)/include/nuttx/compiler.h \ - $(TOPDIR)/include/nuttx/binfmt/symtab.h diff --git a/apps/examples/posix_spawn/filesystem/Makefile b/apps/examples/posix_spawn/filesystem/Makefile deleted file mode 100644 index 26897426c..000000000 --- a/apps/examples/posix_spawn/filesystem/Makefile +++ /dev/null @@ -1,88 +0,0 @@ -############################################################################ -# apps/examples/posix_spawn/filesystem/Makefile -# -# Copyright (C) 2013 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/Make.defs -include $(APPDIR)$(DELIM)Make.defs - -SPAWN_DIR = $(APPDIR)$(DELIM)examples$(DELIM)posix_spawn -FILESYSTEM_DIR = $(SPAWN_DIR)$(DELIM)filesystem -ROMFS_DIR = $(FILESYSTEM_DIR)$(DELIM)romfs -ROMFS_IMG = $(FILESYSTEM_DIR)$(DELIM)romfs.img -ROMFS_HDR = $(FILESYSTEM_DIR)$(DELIM)romfs.h -SYMTAB_SRC = $(FILESYSTEM_DIR)$(DELIM)symtab.c - -all: $(ROMFS_HDR) $(SYMTAB_SRC) -.PHONY: all hello/hello redirect/redirect clean populate - -# Create the romfs directory - -$(ROMFS_DIR): - $(Q) mkdir $(ROMFS_DIR) - -# Build the hello test program - -hello/hello: - $(Q) $(MAKE) -C hello hello TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)" - -# Build the redirection test program - -redirect/redirect: - $(Q) $(MAKE) -C redirect redirect TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)" - -# Create the romfs.img file from the romfs directory - -$(ROMFS_IMG): hello/hello redirect/redirect testdata.txt $(ROMFS_DIR) - $(Q) $(MAKE) -C hello install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)" - $(Q) $(MAKE) -C redirect install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)" - $(Q) install --mode=0644 testdata.txt $(ROMFS_DIR)/testdata.txt - $(Q) genromfs -f $@ -d $(ROMFS_DIR) -V "POSIXSPAWN" - -# Create the romfs.h header file from the romfs.img file - -$(ROMFS_HDR) : $(ROMFS_IMG) - $(Q) (cd $(FILESYSTEM_DIR); xxd -i romfs.img | sed -e "s/^unsigned/static const unsigned/g" >$@) - -# Create the exported symbol table - -$(SYMTAB_SRC): $(ROMFS_DIR)/hello $(ROMFS_DIR)/redirect $(ROMFS_DIR)/testdata.txt - $(Q) $(FILESYSTEM_DIR)$(DELIM)mksymtab.sh $(ROMFS_DIR) >$@ - -# Clean each subdirectory - -clean: - $(Q) $(MAKE) -C hello clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)" - $(Q) $(MAKE) -C redirect clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)" - $(Q) rm -f $(ROMFS_HDR) $(ROMFS_IMG) $(SYMTAB_SRC) - $(Q) rm -rf $(ROMFS_DIR) diff --git a/apps/examples/posix_spawn/filesystem/hello/hello.c b/apps/examples/posix_spawn/filesystem/hello/hello.c deleted file mode 100644 index 1b269d85f..000000000 --- a/apps/examples/posix_spawn/filesystem/hello/hello.c +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * examples/posix_spawn/filesystem/hello/hello.c - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv) -{ - int i; - - /* Mandatory "Hello, world!" */ - - puts("Getting ready to say \"Hello, world\"\n"); - printf("Hello, world!\n"); - puts("It has been said.\n"); - - /* Print arguments */ - - printf("argc\t= %d\n", argc); - printf("argv\t= 0x%p\n", argv); - - for (i = 0; i < argc; i++) - { - printf("argv[%d]\t= ", i); - if (argv[i]) - { - printf("(0x%p) \"%s\"\n", argv[i], argv[i]); - } - else - { - printf("NULL?\n"); - } - } - - printf("argv[%d]\t= 0x%p\n", argc, argv[argc]); - printf("Goodbye, world!\n"); - return 0; -} diff --git a/apps/examples/posix_spawn/filesystem/mksymtab.sh b/apps/examples/posix_spawn/filesystem/mksymtab.sh deleted file mode 100755 index 51408a89c..000000000 --- a/apps/examples/posix_spawn/filesystem/mksymtab.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -usage="Usage: $0 <test-dir-path>" - -# Check for the required ROMFS directory path - -dir=$1 -if [ -z "$dir" ]; then - echo "ERROR: Missing <test-dir-path>" - echo "" - echo $usage - exit 1 -fi - -if [ ! -d "$dir" ]; then - echo "ERROR: Directory $dir does not exist" - echo "" - echo $usage - exit 1 -fi - -# Extract all of the undefined symbols from the ELF files and create a -# list of sorted, unique undefined variable names. - -varlist=`find ${dir} -executable -type f | xargs nm | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq` - -# Now output the symbol table as a structure in a C source file. All -# undefined symbols are declared as void* types. If the toolchain does -# any kind of checking for function vs. data objects, then this could -# faile - -echo "#include <nuttx/compiler.h>" -echo "#include <nuttx/binfmt/symtab.h>" -echo "" - -for var in $varlist; do - echo "extern void *${var};" -done - -echo "" -echo "const struct symtab_s exports[] = " -echo "{" - -for var in $varlist; do - echo " {\"${var}\", &${var}}," -done - -echo "};" -echo "" -echo "const int nexports = sizeof(exports) / sizeof(struct symtab_s);" - diff --git a/apps/examples/posix_spawn/filesystem/redirect/redirect.c b/apps/examples/posix_spawn/filesystem/redirect/redirect.c deleted file mode 100644 index 61638df79..000000000 --- a/apps/examples/posix_spawn/filesystem/redirect/redirect.c +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** - * examples/posix_spawn/filesystem/redirect/redirect.c - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv) -{ - int ch; - - printf("Entering the stdin redirection test\n"); - - /* stdin should have been redirected to testdata.txt. Read and print until - * we hit the end of file. - */ - - while ((ch = getchar()) != EOF) - { - putchar(ch); - } - - printf("Exit-ing the stdin redirection test\n"); - return 0; -} diff --git a/apps/examples/posix_spawn/filesystem/testdata.txt b/apps/examples/posix_spawn/filesystem/testdata.txt deleted file mode 100644 index bb581fbb5..000000000 --- a/apps/examples/posix_spawn/filesystem/testdata.txt +++ /dev/null @@ -1,2 +0,0 @@ -Now is the time for all good men to come to the aid of their party. - diff --git a/apps/examples/posix_spawn/spawn_main.c b/apps/examples/posix_spawn/spawn_main.c deleted file mode 100644 index 0ca5f9107..000000000 --- a/apps/examples/posix_spawn/spawn_main.c +++ /dev/null @@ -1,460 +0,0 @@ -/**************************************************************************** - * examples/posix_spawn/spawn_main.c - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/compiler.h> - -#include <sys/mount.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <spawn.h> -#include <debug.h> -#include <errno.h> - -#include <nuttx/ramdisk.h> -#include <nuttx/binfmt/elf.h> -#include <nuttx/binfmt/symtab.h> - -#include "filesystem/romfs.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/* Check configuration. This is not all of the configuration settings that - * are required -- only the more obvious. - */ - -#if CONFIG_NFILE_DESCRIPTORS < 1 -# error "You must provide file descriptors via CONFIG_NFILE_DESCRIPTORS in your configuration file" -#endif - -#ifdef CONFIG_BINFMT_DISABLE -# error "The binary loader is disabled (CONFIG_BINFMT_DISABLE)!" -#endif - -#ifndef CONFIG_ELF -# error "You must select CONFIG_ELF in your configuration file" -#endif - -#ifndef CONFIG_FS_ROMFS -# error "You must select CONFIG_FS_ROMFS in your configuration file" -#endif - -#ifdef CONFIG_DISABLE_MOUNTPOINT -# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file" -#endif - -#ifdef CONFIG_BINFMT_DISABLE -# error "You must not disable loadable modules via CONFIG_BINFMT_DISABLE in your configuration file" -#endif - -/* Describe the ROMFS file system */ - -#define SECTORSIZE 512 -#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE) -#define MOUNTPT "/mnt/romfs" - -#ifndef CONFIG_EXAMPLES_ELF_DEVMINOR -# define CONFIG_EXAMPLES_ELF_DEVMINOR 0 -#endif - -#ifndef CONFIG_EXAMPLES_ELF_DEVPATH -# define CONFIG_EXAMPLES_ELF_DEVPATH "/dev/ram0" -#endif - -/* If CONFIG_DEBUG is enabled, use dbg instead of printf so that the - * output will be synchronous with the debug output. - */ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG -# define message(format, arg...) dbg(format, ##arg) -# define err(format, arg...) dbg(format, ##arg) -# else -# define message(format, arg...) printf(format, ##arg) -# define err(format, arg...) fprintf(stderr, format, ##arg) -# endif -#else -# ifdef CONFIG_DEBUG -# define message dbg -# define err dbg -# else -# define message printf -# define err printf -# endif -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static unsigned int g_mminitial; /* Initial memory usage */ -static unsigned int g_mmstep; /* Memory Usage at beginning of test step */ - -static const char delimiter[] = - "****************************************************************************"; -static const char g_redirect[] = "redirect"; -static const char g_hello[] = "hello"; -static const char g_data[] = "testdata.txt"; - -static char fullpath[128]; - -static char * const g_argv[4] = - { "Argument 1", "Argument 2", "Argument 3", NULL }; - -/**************************************************************************** - * Symbols from Auto-Generated Code - ****************************************************************************/ - -extern const struct symtab_s exports[]; -extern const int nexports; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mm_update - ****************************************************************************/ - -static void mm_update(FAR unsigned int *previous, FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - printf("\nMemory Usage %s:\n", msg); - printf(" Before: %8u After: %8u Change: %8d\n", - *previous, mmcurrent.uordblks, (int)mmcurrent.uordblks - (int)*previous); - - /* Set up for the next test */ - - *previous = mmcurrent.uordblks; -} - -/**************************************************************************** - * Name: mm_initmonitor - ****************************************************************************/ - -static void mm_initmonitor(void) -{ - struct mallinfo mmcurrent; - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mminitial = mmcurrent.uordblks; - g_mmstep = mmcurrent.uordblks; - - printf("Initial memory usage: %d\n", mmcurrent.uordblks); -} - -/**************************************************************************** - * Name: testheader - ****************************************************************************/ - -static inline void testheader(FAR const char *progname) -{ - message("\n%s\n* Executing %s\n%s\n\n", delimiter, progname, delimiter); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: spawn_main - ****************************************************************************/ - -int spawn_main(int argc, char *argv[]) -{ - posix_spawn_file_actions_t file_actions; - posix_spawnattr_t attr; - FAR const char *filepath; - pid_t pid; - int ret; - - /* Initialize the memory monitor */ - - mm_initmonitor(); - - /* Initialize the ELF binary loader */ - - message("Initializing the ELF binary loader\n"); - ret = elf_initialize(); - if (ret < 0) - { - err("ERROR: Initialization of the ELF loader failed: %d\n", ret); - exit(1); - } - - mm_update(&g_mmstep, "after elf_initialize"); - - /* Create a ROM disk for the ROMFS filesystem */ - - message("Registering romdisk at /dev/ram%d\n", CONFIG_EXAMPLES_ELF_DEVMINOR); - ret = romdisk_register(CONFIG_EXAMPLES_ELF_DEVMINOR, (FAR uint8_t *)romfs_img, - NSECTORS(romfs_img_len), SECTORSIZE); - if (ret < 0) - { - err("ERROR: romdisk_register failed: %d\n", ret); - elf_uninitialize(); - exit(1); - } - - mm_update(&g_mmstep, "after romdisk_register"); - - /* Mount the file system */ - - message("Mounting ROMFS filesystem at target=%s with source=%s\n", - MOUNTPT, CONFIG_EXAMPLES_ELF_DEVPATH); - - ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, "romfs", MS_RDONLY, NULL); - if (ret < 0) - { - err("ERROR: mount(%s,%s,romfs) failed: %s\n", - CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, errno); - elf_uninitialize(); - } - - mm_update(&g_mmstep, "after mount"); - - /* Does the system support the PATH variable? Has the PATH variable - * already been set? If YES and NO, then set the PATH variable to - * the ROMFS mountpoint. - */ - -#if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL) - (void)setenv("PATH", MOUNTPT, 1); -#endif - - /* Make sure that we are using our symbol take */ - - exec_setsymtab(exports, nexports); - - /************************************************************************* - * Case 1: Simple program with arguments - *************************************************************************/ - - /* Output a seperated so that we can clearly discriminate the output of - * this program from the others. - */ - - testheader(g_hello); - - /* Initialize the attributes file actions structure */ - - ret = posix_spawn_file_actions_init(&file_actions); - if (ret != 0) - { - err("ERROR: posix_spawn_file_actions_init failed: %d\n", ret); - } - posix_spawn_file_actions_dump(&file_actions); - - ret = posix_spawnattr_init(&attr); - if (ret != 0) - { - err("ERROR: posix_spawnattr_init failed: %d\n", ret); - } - posix_spawnattr_dump(&attr); - - mm_update(&g_mmstep, "after file_action/attr init"); - - /* If the binary loader does not support the PATH variable, then - * create the full path to the executable program. Otherwise, - * use the relative path so that the binary loader will have to - * search the PATH variable to find the executable. - */ - -#ifdef CONFIG_BINFMT_EXEPATH - filepath = g_hello; -#else - snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_hello); - filepath = fullpath; -#endif - - /* Execute the program */ - - mm_update(&g_mmstep, "before posix_spawn"); - - ret = posix_spawn(&pid, filepath, &file_actions, &attr, NULL, (FAR char * const*)&g_argv); - if (ret != 0) - { - err("ERROR: posix_spawn failed: %d\n", ret); - } - - sleep(4); - mm_update(&g_mmstep, "after posix_spawn"); - - /* Free attibutes and file actions */ - - ret = posix_spawn_file_actions_destroy(&file_actions); - if (ret != 0) - { - err("ERROR: posix_spawn_file_actions_destroy failed: %d\n", ret); - } - posix_spawn_file_actions_dump(&file_actions); - - ret = posix_spawnattr_destroy(&attr); - if (ret != 0) - { - err("ERROR: posix_spawnattr_destroy failed: %d\n", ret); - } - posix_spawnattr_dump(&attr); - - mm_update(&g_mmstep, "after file_action/attr destruction"); - - /************************************************************************* - * Case 2: Simple program with redirection of stdin to a file input - *************************************************************************/ - - /* Output a seperated so that we can clearly discriminate the output of - * this program from the others. - */ - - testheader(g_redirect); - - /* Initialize the attributes file actions structure */ - - ret = posix_spawn_file_actions_init(&file_actions); - if (ret != 0) - { - err("ERROR: posix_spawn_file_actions_init failed: %d\n", ret); - } - posix_spawn_file_actions_dump(&file_actions); - - ret = posix_spawnattr_init(&attr); - if (ret != 0) - { - err("ERROR: posix_spawnattr_init failed: %d\n", ret); - } - posix_spawnattr_dump(&attr); - - mm_update(&g_mmstep, "after file_action/attr init"); - - /* Set up to close stdin (0) and open testdata.txt as the program input */ - - ret = posix_spawn_file_actions_addclose(&file_actions, 0); - if (ret != 0) - { - err("ERROR: posix_spawn_file_actions_addclose failed: %d\n", ret); - } - posix_spawn_file_actions_dump(&file_actions); - - snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_data); - ret = posix_spawn_file_actions_addopen(&file_actions, 0, fullpath, O_RDONLY, 0644); - if (ret != 0) - { - err("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret); - } - posix_spawn_file_actions_dump(&file_actions); - - mm_update(&g_mmstep, "after adding file_actions"); - - /* If the binary loader does not support the PATH variable, then - * create the full path to the executable program. Otherwise, - * use the relative path so that the binary loader will have to - * search the PATH variable to find the executable. - */ - -#ifdef CONFIG_BINFMT_EXEPATH - filepath = g_redirect; -#else - snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_redirect); - filepath = fullpath; -#endif - - /* Execute the program */ - - mm_update(&g_mmstep, "before posix_spawn"); - - ret = posix_spawn(&pid, filepath, &file_actions, &attr, NULL, NULL); - if (ret != 0) - { - err("ERROR: posix_spawn failed: %d\n", ret); - } - - sleep(2); - mm_update(&g_mmstep, "after posix_spawn"); - - /* Free attibutes and file actions */ - - ret = posix_spawn_file_actions_destroy(&file_actions); - if (ret != 0) - { - err("ERROR: posix_spawn_file_actions_destroy failed: %d\n", ret); - } - posix_spawn_file_actions_dump(&file_actions); - - ret = posix_spawnattr_destroy(&attr); - if (ret != 0) - { - err("ERROR: posix_spawnattr_destroy failed: %d\n", ret); - } - posix_spawnattr_dump(&attr); - - mm_update(&g_mmstep, "after file_action/attr destruction"); - - /* Clean-up */ - - elf_uninitialize(); - - mm_update(&g_mmstep, "End-of-Test"); - return 0; -} diff --git a/apps/examples/pwm/Kconfig b/apps/examples/pwm/Kconfig deleted file mode 100644 index 78edd2178..000000000 --- a/apps/examples/pwm/Kconfig +++ /dev/null @@ -1,48 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_PWM - bool "Pulse width modulation (PWM) example" - default n - depends on PWM && NSH_BUILTIN_APPS - ---help--- - Enable the Pulse width modulation (PWM) example - -if EXAMPLES_PWM - -config EXAMPLES_PWM_DEVPATH - string "PWM device path" - default "/dev/pwm0" - ---help--- - The path to the PWM device. Default: /dev/pwm0 - -config EXAMPLES_PWM_FREQUENCY - int "Default PWM freququency" - default 100 - ---help--- - The default PWM frequency. Default: 100 Hz - -config EXAMPLES_PWM_DUTYPCT - int "Default PWM duty percentage" - default 50 - ---help--- - The default PWM duty as a percentage. Default: 50% - -config EXAMPLES_PWM_DURATION - int "Default PWM duration" - default 5 if !EXAMPLES_PWM_PULSECOUNT - ---help--- - The default PWM pulse train duration in seconds. Used only if the current - pulse count is zero (pulse countis only supported if CONFIG_PWM_PULSECOUNT - is defined). Default: 5 seconds - -config EXAMPLES_PWM_PULSECOUNT - int "Default pulse count" - default 0 - ---help--- - The initial PWM pulse count. This option is only available if CONFIG_PWM_PULSECOUNT - is nonzero. Default: 0 (i.e., use the duration, not the count). - -endif diff --git a/apps/examples/pwm/Makefile b/apps/examples/pwm/Makefile deleted file mode 100644 index ece901a99..000000000 --- a/apps/examples/pwm/Makefile +++ /dev/null @@ -1,109 +0,0 @@ -############################################################################ -# apps/examples/pwm/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# PWM Example. - -ASRCS = -CSRCS = pwm_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# PWM built-in application info - -APPNAME = pwm -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) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/pwm/pwm.h b/apps/examples/pwm/pwm.h deleted file mode 100644 index a6132ca8b..000000000 --- a/apps/examples/pwm/pwm.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** - * examples/examples/pwm/pwm.h - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_PWM_PWM_H -#define __APPS_EXAMPLES_PWM_PWM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* CONFIG_NSH_BUILTIN_APPS - Build the PWM test as an NSH built-in function. - * Default: Not built! The example can only be used as an NSH built-in - * application - * CONFIG_EXAMPLES_PWM_DEVPATH - The path to the PWM device. Default: /dev/pwm0 - * CONFIG_EXAMPLES_PWM_FREQUENCY - The initial PWM frequency. Default: 100 Hz - * CONFIG_EXAMPLES_PWM_DUTYPCT - The initial PWM duty as a percentage. Default: 50% - * CONFIG_EXAMPLES_PWM_DURATION - The initial PWM pulse train duration in seconds. - * Used only if the current pulse count is zero (pulse count is only supported - * if CONFIG_PWM_PULSECOUNT is defined). Default: 5 seconds - * CONFIG_EXAMPLES_PWM_PULSECOUNT - The initial PWM pulse count. This option is - * only available if CONFIG_PWM_PULSECOUNT is defined. Default: 0 (i.e., use - * the duration, not the count). - */ - -#ifndef CONFIG_PWM -# error "PWM device support is not enabled (CONFIG_PWM)" -#endif - -#ifndef CONFIG_NSH_BUILTIN_APPS -# warning "The PWM example only works as an NSH built-in application (CONFIG_NSH_BUILTIN_APPS)" -#endif - -#ifndef CONFIG_EXAMPLES_PWM_DEVPATH -# define CONFIG_EXAMPLES_PWM_DEVPATH "/dev/pwm0" -#endif - -#ifndef CONFIG_EXAMPLES_PWM_FREQUENCY -# define CONFIG_EXAMPLES_PWM_FREQUENCY 100 -#endif - -#ifndef CONFIG_EXAMPLES_PWM_DUTYPCT -# define CONFIG_EXAMPLES_PWM_DUTYPCT 50 -#endif - -#ifndef CONFIG_EXAMPLES_PWM_DURATION -# define CONFIG_EXAMPLES_PWM_DURATION 5 -#endif - -#ifndef CONFIG_EXAMPLES_PWM_COUNT -# define CONFIG_EXAMPLES_PWM_COUNT 0 -#endif - -/* Debug ********************************************************************/ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG -# define message(...) syslog(__VA_ARGS__) -# define msgflush() -# else -# define message(...) printf(__VA_ARGS__) -# define msgflush() fflush(stdout) -# endif -#else -# ifdef CONFIG_DEBUG -# define message syslog -# define msgflush() -# else -# define message printf -# define msgflush() fflush(stdout) -# endif -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: pwm_devinit() - * - * Description: - * Perform architecuture-specific initialization of the PWM hardware. This - * interface must be provided by all configurations using apps/examples/pwm - * - ****************************************************************************/ - -int pwm_devinit(void); - -#endif /* __APPS_EXAMPLES_PWM_PWM_H */ diff --git a/apps/examples/pwm/pwm_main.c b/apps/examples/pwm/pwm_main.c deleted file mode 100644 index a46c10f55..000000000 --- a/apps/examples/pwm/pwm_main.c +++ /dev/null @@ -1,395 +0,0 @@ -/**************************************************************************** - * examples/pwm/pwm_main.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/ioctl.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> -#include <string.h> - -#include <nuttx/pwm.h> - -#include "pwm.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct pwm_state_s -{ - bool initialized; - FAR char *devpath; - uint8_t duty; - uint32_t freq; -#ifdef CONFIG_PWM_PULSECOUNT - uint32_t count; -#endif - int duration; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct pwm_state_s g_pwmstate; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pwm_devpath - ****************************************************************************/ - -static void pwm_devpath(FAR struct pwm_state_s *pwm, FAR const char *devpath) -{ - /* Get rid of any old device path */ - - if (pwm->devpath) - { - free(pwm->devpath); - } - - /* Then set-up the new device path by copying the string */ - - pwm->devpath = strdup(devpath); -} - -/**************************************************************************** - * Name: pwm_help - ****************************************************************************/ - -static void pwm_help(FAR struct pwm_state_s *pwm) -{ - message("Usage: pwm [OPTIONS]\n"); - message("\nArguments are \"sticky\". For example, once the PWM frequency is\n"); - message("specified, that frequency will be re-used until it is changed.\n"); - message("\n\"sticky\" OPTIONS include:\n"); - message(" [-p devpath] selects the PWM device. " - "Default: %s Current: %s\n", - CONFIG_EXAMPLES_PWM_DEVPATH, pwm->devpath ? pwm->devpath : "NONE"); - message(" [-f addr] selects the pulse frequency. " - "Default: %d Hz Current: %d Hz\n", - CONFIG_EXAMPLES_PWM_FREQUENCY, pwm->freq); - message(" [-d duty] selcts the pulse duty as a percentage. " - "Default: %d %% Current: %d %%\n", - CONFIG_EXAMPLES_PWM_DUTYPCT, pwm->duty); -#ifdef CONFIG_PWM_PULSECOUNT - message(" [-n count] selects the pulse count. " - "Default: %d Current: %d\n", - CONFIG_EXAMPLES_PWM_COUNT, pwm->count); -#endif - message(" [-t duration] is the duration of the pulse train in seconds. " - "Default: %d Current: %d\n", - CONFIG_EXAMPLES_PWM_DURATION, pwm->duration); - message(" [-h] shows this message and exits\n"); -} - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -static int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -static int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} - -/**************************************************************************** - * Name: parse_args - ****************************************************************************/ - -static void parse_args(FAR struct pwm_state_s *pwm, int argc, FAR char **argv) -{ - FAR char *ptr; - FAR char *str; - long value; - int index; - int nargs; - - for (index = 1; index < argc; ) - { - ptr = argv[index]; - if (ptr[0] != '-') - { - message("Invalid options format: %s\n", ptr); - exit(0); - } - - switch (ptr[1]) - { - case 'f': - nargs = arg_decimal(&argv[index], &value); - if (value < 1) - { - message("Frequency out of range: %ld\n", value); - exit(1); - } - - pwm->freq = (uint32_t)value; - index += nargs; - break; - - case 'd': - nargs = arg_decimal(&argv[index], &value); - if (value < 1 || value > 99) - { - message("Duty out of range: %ld\n", value); - exit(1); - } - - pwm->duty = (uint8_t)value; - index += nargs; - break; - -#ifdef CONFIG_PWM_PULSECOUNT - case 'n': - nargs = arg_decimal(&argv[index], &value); - if (value < 0) - { - message("Count must be non-negative: %ld\n", value); - exit(1); - } - - pwm->count = (uint32_t)value; - index += nargs; - break; - -#endif - case 'p': - nargs = arg_string(&argv[index], &str); - pwm_devpath(pwm, str); - index += nargs; - break; - - case 't': - nargs = arg_decimal(&argv[index], &value); - if (value < 1 || value > INT_MAX) - { - message("Duration out of range: %ld\n", value); - exit(1); - } - - pwm->duration = (int)value; - index += nargs; - break; - - case 'h': - pwm_help(pwm); - exit(0); - - default: - message("Unsupported option: %s\n", ptr); - pwm_help(pwm); - exit(1); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: pwm_main - ****************************************************************************/ - -int pwm_main(int argc, char *argv[]) -{ - struct pwm_info_s info; - int fd; - int ret; - - /* Initialize the state data */ - - if (!g_pwmstate.initialized) - { - g_pwmstate.duty = CONFIG_EXAMPLES_PWM_DUTYPCT; - g_pwmstate.freq = CONFIG_EXAMPLES_PWM_FREQUENCY; - g_pwmstate.duration = CONFIG_EXAMPLES_PWM_DURATION; -#ifdef CONFIG_PWM_PULSECOUNT - g_pwmstate.count = CONFIG_EXAMPLES_PWM_COUNT; -#endif - g_pwmstate.initialized = true; - } - - /* Parse the command line */ - - parse_args(&g_pwmstate, argc, argv); - - /* Has a device been assigned? */ - - if (!g_pwmstate.devpath) - { - /* No.. use the default device */ - - pwm_devpath(&g_pwmstate, CONFIG_EXAMPLES_PWM_DEVPATH); - } - - /* Initialization of the PWM hardware is performed by logic external to - * this test. - */ - - ret = pwm_devinit(); - if (ret != OK) - { - message("pwm_main: pwm_devinit failed: %d\n", ret); - goto errout; - } - - /* Open the PWM device for reading */ - - fd = open(g_pwmstate.devpath, O_RDONLY); - if (fd < 0) - { - message("pwm_main: open %s failed: %d\n", g_pwmstate.devpath, errno); - goto errout; - } - - /* Configure the characteristics of the pulse train */ - - info.frequency = g_pwmstate.freq; - info.duty = ((uint32_t)g_pwmstate.duty << 16) / 100; -#ifdef CONFIG_PWM_PULSECOUNT - info.count = g_pwmstate.count; - - message("pwm_main: starting output with frequency: %d duty: %08x count: %d\n", - info.frequency, info.duty, info.count); - -#else - message("pwm_main: starting output with frequency: %d duty: %08x\n", - info.frequency, info.duty); - -#endif - - ret = ioctl(fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&info)); - if (ret < 0) - { - message("pwm_main: ioctl(PWMIOC_SETCHARACTERISTICS) failed: %d\n", errno); - goto errout_with_dev; - } - - /* Then start the pulse train. Since the driver was opened in blocking - * mode, this call will block if the count value is greater than zero. - */ - - ret = ioctl(fd, PWMIOC_START, 0); - if (ret < 0) - { - message("pwm_main: ioctl(PWMIOC_START) failed: %d\n", errno); - goto errout_with_dev; - } - - /* It a non-zero count was not specified, then wait for the selected - * duration, then stop the PWM output. - */ - -#ifdef CONFIG_PWM_PULSECOUNT - if (info.count == 0) -#endif - { - /* Wait for the specified duration */ - - sleep(g_pwmstate.duration); - - /* Then stop the pulse train */ - - message("pwm_main: stopping output\n", info.frequency, info.duty); - - ret = ioctl(fd, PWMIOC_STOP, 0); - if (ret < 0) - { - message("pwm_main: ioctl(PWMIOC_STOP) failed: %d\n", errno); - goto errout_with_dev; - } - } - - close(fd); - msgflush(); - return OK; - -errout_with_dev: - close(fd); -errout: - msgflush(); - return ERROR; -} diff --git a/apps/examples/qencoder/Kconfig b/apps/examples/qencoder/Kconfig deleted file mode 100644 index e0026d08c..000000000 --- a/apps/examples/qencoder/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_QENCODER - bool "Quadrature encoder example" - default n - ---help--- - Enable the quadrature encoder example - -if EXAMPLES_QENCODER -endif diff --git a/apps/examples/qencoder/Makefile b/apps/examples/qencoder/Makefile deleted file mode 100644 index 9668796e6..000000000 --- a/apps/examples/qencoder/Makefile +++ /dev/null @@ -1,109 +0,0 @@ -############################################################################ -# apps/examples/qe/Makefile -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# NuttX NX Graphics Example. - -ASRCS = -CSRCS = qe_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Quadrature Encoder built-in application info - -APPNAME = qe -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) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/qencoder/qe.h b/apps/examples/qencoder/qe.h deleted file mode 100644 index 3c20511ca..000000000 --- a/apps/examples/qencoder/qe.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** - * examples/examples/qe/qe.h - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_QENCODER_QE_H -#define __APPS_EXAMPLES_QENCODER_QE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* CONFIG_NSH_BUILTIN_APPS - Build the QE test as an NSH built-in function. - * Default: Built as a standalone problem - * CONFIG_EXAMPLES_QENCODER_DEVPATH - The path to the QE device. Default: - * /dev/qe0 - * CONFIG_EXAMPLES_QENCODER_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_QENCODER_DELAY - This value provides the delay (in - * milliseonds) between each sample. If CONFIG_NSH_BUILTIN_APPS - * is defined, then this value is the default delay if no other delay is - * provided on the command line. Default: 100 milliseconds - */ - -#ifndef CONFIG_QENCODER -# error "QE device support is not enabled (CONFIG_QENCODER)" -#endif - -#ifndef CONFIG_EXAMPLES_QENCODER_DEVPATH -# define CONFIG_EXAMPLES_QENCODER_DEVPATH "/dev/qe0" -#endif - -#ifndef CONFIG_EXAMPLES_QENCODER_DELAY -# define CONFIG_EXAMPLES_QENCODER_DELAY 100 -#endif - -/* Debug ********************************************************************/ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG -# define message(...) syslog(__VA_ARGS__) -# define msgflush() -# else -# define message(...) printf(__VA_ARGS__) -# define msgflush() fflush(stdout) -# endif -#else -# ifdef CONFIG_DEBUG -# define message syslog -# define msgflush() -# else -# define message printf -# define msgflush() fflush(stdout) -# endif -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -struct qe_example_s -{ - bool initialized; /* True: QE devices have been initialized */ - bool reset; /* True: set the count back to zero */ - FAR char *devpath; /* Path to the QE device */ - unsigned int nloops; /* Collect this number of samples */ - unsigned int delay; /* Delay this number of seconds between samples */ -}; -#endif - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -extern struct qe_example_s g_qeexample; -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: qe_devinit() - * - * Description: - * Perform architecuture-specific initialization of the QE hardware. This - * interface must be provided by all configurations using apps/examples/qe - * - ****************************************************************************/ - -int qe_devinit(void); - -#endif /* __APPS_EXAMPLES_QENCODER_QE_H */ diff --git a/apps/examples/qencoder/qe_main.c b/apps/examples/qencoder/qe_main.c deleted file mode 100644 index 8c185ea1b..000000000 --- a/apps/examples/qencoder/qe_main.c +++ /dev/null @@ -1,362 +0,0 @@ -/**************************************************************************** - * examples/qe/qe_main.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/ioctl.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <limits.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/sensors/qencoder.h> - -#include "qe.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -struct qe_example_s g_qeexample; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: qe_devpath - ****************************************************************************/ - -static void qe_devpath(FAR const char *devpath) -{ - /* Get rid of any old device path */ - - if (g_qeexample.devpath) - { - free(g_qeexample.devpath); - } - - /* The set-up the new device path by copying the string */ - - g_qeexample.devpath = strdup(devpath); -} - -/**************************************************************************** - * Name: qe_help - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static void qe_help(void) -{ - message("\nUsage: qe [OPTIONS]\n\n"); - message("OPTIONS include:\n"); - message(" [-p devpath] QE device path\n"); - message(" [-n samples] Number of samples\n"); - message(" [-t msec] Delay between samples (msec)\n"); - message(" [-r] Reset the position to zero\n"); - message(" [-h] Shows this message and exits\n\n"); -} -#endif - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} -#endif - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} -#endif - -/**************************************************************************** - * Name: parse_args - ****************************************************************************/ - -#ifdef CONFIG_NSH_BUILTIN_APPS -static void parse_args(int argc, FAR char **argv) -{ - FAR char *ptr; - FAR char *str; - long value; - int index; - int nargs; - - g_qeexample.reset = false; - g_qeexample.nloops = 1; - g_qeexample.delay = CONFIG_EXAMPLES_QENCODER_DELAY; - - for (index = 1; index < argc; ) - { - ptr = argv[index]; - if (ptr[0] != '-') - { - message("Invalid options format: %s\n", ptr); - exit(0); - } - - switch (ptr[1]) - { - case 'n': - nargs = arg_decimal(&argv[index], &value); - if (value < 0 || value > INT_MAX) - { - message("Sample count out of range: %ld\n", value); - exit(1); - } - - g_qeexample.nloops = (unsigned int)value; - index += nargs; - break; - - case 'p': - nargs = arg_string(&argv[index], &str); - qe_devpath(str); - index += nargs; - break; - - case 't': - nargs = arg_decimal(&argv[index], &value); - if (value < 0 || value > INT_MAX) - { - message("Sample delay out of range: %ld\n", value); - exit(1); - } - - g_qeexample.delay = (unsigned int)value; - index += nargs; - break; - - case 'r': - g_qeexample.reset = true; - index++; - break; - - case 'h': - qe_help(); - exit(EXIT_SUCCESS); - - default: - message("Unsupported option: %s\n", ptr); - qe_help(); - exit(EXIT_FAILURE); - } - } -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: qe_main - ****************************************************************************/ - -int qe_main(int argc, char *argv[]) -{ - int32_t position; - int fd; - int exitval = EXIT_SUCCESS; - int ret; -#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_QENCODER_NSAMPLES) - int nloops; -#endif - - /* Check if we have initialized */ - - if (!g_qeexample.initialized) - { - /* Initialization of the encoder hardware is performed by logic external to - * this test. - */ - - message("qe_main: Initializing external encoder(s)\n"); - ret = qe_devinit(); - if (ret != OK) - { - message("qe_main: qe_devinit failed: %d\n", ret); - exitval = EXIT_FAILURE; - goto errout; - } - - /* Set the default values */ - - qe_devpath(CONFIG_EXAMPLES_QENCODER_DEVPATH); - g_qeexample.initialized = true; - } - - /* Parse command line arguments */ - -#ifdef CONFIG_NSH_BUILTIN_APPS - parse_args(argc, argv); -#endif - - /* Open the encoder device for reading */ - - message("qe_main: Hardware initialized. Opening the encoder device: %s\n", - g_qeexample.devpath); - - fd = open(g_qeexample.devpath, O_RDONLY); - if (fd < 0) - { - message("qe_main: open %s failed: %d\n", g_qeexample.devpath, errno); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - - /* Reset the count if so requested */ - - if (g_qeexample.reset) - { - message("qe_main: Resetting the count...\n"); - ret = ioctl(fd, QEIOC_RESET, 0); - if (ret < 0) - { - message("qe_main: ioctl(QEIOC_RESET) failed: %d\n", errno); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - } - - /* Now loop the appropriate number of times, displaying the collected - * encoder samples. - */ - -#if defined(CONFIG_NSH_BUILTIN_APPS) - message("qe_main: Number of samples: %d\n", g_qeexample.nloops); - for (nloops = 0; nloops < g_qeexample.nloops; nloops++) -#elif defined(CONFIG_EXAMPLES_QENCODER_NSAMPLES) - message("qe_main: Number of samples: %d\n", CONFIG_EXAMPLES_QENCODER_NSAMPLES); - for (nloops = 0; nloops < CONFIG_EXAMPLES_QENCODER_NSAMPLES; nloops++) -#else - for (;;) -#endif - { - /* Flush any output before the loop entered or from the previous pass - * through the loop. - */ - - msgflush(); - - /* Get the positions data using the ioctl */ - - ret = ioctl(fd, QEIOC_POSITION, (unsigned long)((uintptr_t)&position)); - if (ret < 0) - { - message("qe_main: ioctl(QEIOC_POSITION) failed: %d\n", errno); - exitval = EXIT_FAILURE; - goto errout_with_dev; - } - - /* Print the sample data on successful return */ - - else - { - message("qe_main: %3d. %d\n", nloops+1, position); - } - - /* Delay a little bit */ - -#if defined(CONFIG_NSH_BUILTIN_APPS) - usleep(g_qeexample.delay * 1000); -#else - usleep(CONFIG_EXAMPLES_QENCODER_DELAY * 1000); -#endif - } - -errout_with_dev: - close(fd); - -errout: - message("Terminating!\n"); - msgflush(); - return exitval; -} diff --git a/apps/examples/romfs/Kconfig b/apps/examples/romfs/Kconfig deleted file mode 100644 index 5a8c824a3..000000000 --- a/apps/examples/romfs/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_ROMFS - bool "ROMFS example" - default n - ---help--- - Enable the ROMFS example - -if EXAMPLES_ROMFS -endif diff --git a/apps/examples/romfs/Makefile b/apps/examples/romfs/Makefile deleted file mode 100644 index 2b02952ed..000000000 --- a/apps/examples/romfs/Makefile +++ /dev/null @@ -1,115 +0,0 @@ -############################################################################ -# apps/examples/romfs/Makefile -# -# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# ROMFS File System Example - -ASRCS = -CSRCS = romfs_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: checkgenromfs clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -checkgenromfs: - @genromfs -h 1>/dev/null 2>&1 || { \ - echo "Host executable genromfs not available in PATH"; \ - echo "You may need to download in from http://romfs.sourceforge.net/"; \ - exit 1; \ - } - -testdir : testdir.tar.gz - @tar zxf $< || { echo "tar zxf $< failed" ; exit 1 ; } - -testdir.img : checkgenromfs testdir - @genromfs -f $@ -d testdir -V "ROMFS_Test" || { echo "genromfs failed" ; exit 1 ; } - -romfs_testdir.h : testdir.img - @xxd -i $< >$@ || { echo "xxd of $< failed" ; exit 1 ; } - -.built: romfs_testdir.h $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -# Register application -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - $(call DELFILE, testdir.img) - --include Make.dep - diff --git a/apps/examples/romfs/romfs_main.c b/apps/examples/romfs/romfs_main.c deleted file mode 100644 index 3437cb8ac..000000000 --- a/apps/examples/romfs/romfs_main.c +++ /dev/null @@ -1,498 +0,0 @@ -/**************************************************************************** - * examples/romfs/romfs_main.c - * - * Copyright (C) 2008-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. - * - ****************************************************************************/ - -/* Mount the ROMFS image, Verifty that it contains the - * following: - * - * testdir - * |---------- [drwxr-xr-x 4096] adir - * | |------ [-rw-r--r-- 21] anotherfile.txt - * | |------ [drwxr-xr-x 4096] subdir - * | | `-- [-rw-r--r-- 21] subdirfile.txt - * | `------ [-rw-r--r-- 25] yafile.txt - * |---------- [-rw-r--r-- 15] afile.txt - * |---------- [-rw-r--r-- 21] hfile - * `---------- [lrwxrwxrwx 11] ldir -> adir/subdir - * - * testdir/ldir is a soft-link and should not be detectable. - * hfile is a hardlink to subdirfile and should be identical - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <dirent.h> -#include <errno.h> - -#include <nuttx/ramdisk.h> - -#include "romfs_testdir.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/* Configuration settings */ - -#ifndef CONFIG_EXAMPLES_ROMFS_RAMDEVNO -# define CONFIG_EXAMPLES_ROMFS_RAMDEVNO 1 -#endif - -#ifndef CONFIG_EXAMPLES_ROMFS_SECTORSIZE -# define CONFIG_EXAMPLES_ROMFS_SECTORSIZE 64 -#endif - -#ifndef CONFIG_EXAMPLES_ROMFS_MOUNTPOINT -# define CONFIG_EXAMPLES_ROMFS_MOUNTPOINT "/usr/local/share" -#endif - -#ifdef CONFIG_DISABLE_MOUNTPOINT -# error "Mountpoint support is disabled" -#endif - -#if CONFIG_NFILE_DESCRIPTORS < 4 -# error "Not enough file descriptors" -#endif - -#ifndef CONFIG_FS_ROMFS -# error "ROMFS support not enabled" -#endif - -#define NSECTORS(b) (((b)+CONFIG_EXAMPLES_ROMFS_SECTORSIZE-1)/CONFIG_EXAMPLES_ROMFS_SECTORSIZE) -#define STR_RAMDEVNO(m) #m -#define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m) -#define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_EXAMPLES_ROMFS_RAMDEVNO) - -#define SCRATCHBUFFER_SIZE 1024 - -/* Test directory stuff */ - -#define WRITABLE_MODE (S_IWOTH|S_IWGRP|S_IWUSR) -#define READABLE_MODE (S_IROTH|S_IRGRP|S_IRUSR) -#define EXECUTABLE_MODE (S_IXOTH|S_IXGRP|S_IXUSR) - -#define DIRECTORY_MODE (S_IFDIR|READABLE_MODE|EXECUTABLE_MODE) -#define FILE_MODE (S_IFREG|READABLE_MODE) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct node_s -{ - struct node_s *peer; /* Next node in this directory */ - bool directory; /* True: directory */ - bool found; /* True: found and verified */ - const char *name; /* Node name */ - mode_t mode; /* Expected permissions */ - size_t size; /* Expected size */ - union - { - const char *filecontent; /* Context of text file */ - struct node_s *child; /* Subdirectory start */ - } u; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char g_afilecontent[] = "This is a file\n"; -static const char g_anotherfilecontent[] = "This is another file\n"; -static const char g_yafilecontent[] = "This is yet another file\n"; -static const char g_subdirfilecontent[] = "File in subdirectory\n"; - -#define g_hfilecontent g_subdirfilecontent - -static struct node_s g_adir; -static struct node_s g_afile; -static struct node_s g_hfile; - -static struct node_s g_anotherfile; -static struct node_s g_subdir; -static struct node_s g_yafile; - -static struct node_s g_subdirfile; - -static int g_nerrors = 0; - -static char g_scratchbuffer[SCRATCHBUFFER_SIZE]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: - ****************************************************************************/ - -static void connectem(void) -{ - g_adir.peer = &g_afile; - g_adir.directory = true; - g_adir.found = false; - g_adir.name = "adir"; - g_adir.mode = DIRECTORY_MODE; - g_adir.size = 0; - g_adir.u.child = &g_anotherfile; - - g_afile.peer = &g_hfile; - g_afile.directory = false; - g_afile.found = false; - g_afile.name = "afile.txt"; - g_afile.mode = FILE_MODE; - g_afile.size = strlen(g_afilecontent); - g_afile.u.filecontent = g_afilecontent; - - g_hfile.peer = NULL; - g_hfile.directory = false; /* Actually a hard link */ - g_hfile.found = false; - g_hfile.name = "hfile"; - g_hfile.mode = FILE_MODE; - g_hfile.size = strlen(g_hfilecontent); - g_hfile.u.filecontent = g_hfilecontent; - - g_anotherfile.peer = &g_yafile; - g_anotherfile.directory = false; - g_anotherfile.found = false; - g_anotherfile.name = "anotherfile.txt"; - g_anotherfile.mode = FILE_MODE; - g_anotherfile.size = strlen(g_anotherfilecontent); - g_anotherfile.u.filecontent = g_anotherfilecontent; - - g_yafile.peer = &g_subdir; - g_yafile.directory = false; - g_yafile.found = false; - g_yafile.name = "yafile.txt"; - g_yafile.mode = FILE_MODE; - g_yafile.size = strlen(g_yafilecontent); - g_yafile.u.filecontent = g_yafilecontent; - - g_subdir.peer = NULL; - g_subdir.directory = true; - g_subdir.found = false; - g_subdir.name = "subdir"; - g_subdir.mode = DIRECTORY_MODE; - g_subdir.size = 0; - g_subdir.u.child = &g_subdirfile; - - g_subdirfile.peer = NULL; - g_subdirfile.directory = false; - g_subdirfile.found = false; - g_subdirfile.name = "subdirfile.txt"; - g_subdirfile.mode = FILE_MODE; - g_subdirfile.size = strlen(g_subdirfilecontent); - g_subdirfile.u.filecontent = g_subdirfilecontent; -} - -/**************************************************************************** - * Name: findindirectory - ****************************************************************************/ - -static struct node_s *findindirectory(struct node_s *entry, const char *name) -{ - for (; entry; entry = entry->peer) - { - if (!entry->found && strcmp(entry->name, name) == 0) - { - entry->found = true; - return entry; - } - } - return NULL; -} - -/**************************************************************************** - * Name: checkattributes - ****************************************************************************/ - -static void checkattributes(const char *path, mode_t mode, size_t size) -{ - struct stat buf; - int ret; - - ret = stat(path, &buf); - if (ret != 0) - { - printf(" -- ERROR: Failed to stat %s: %d\n", path, errno); - g_nerrors++; - return; - } - - if (mode != buf.st_mode) - { - printf(" -- ERROR: Expected mode %08x, got %08x\n", mode, buf.st_mode); - g_nerrors++; - } - - if (size != buf.st_size) - { - printf(" -- ERROR: Expected size %d, got %d\n", mode, buf.st_size); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: checkfile - ****************************************************************************/ - -static void checkfile(const char *path, struct node_s *node) -{ - ssize_t nbytesread; - char *filedata; - int fd; - - /* Open the file */ - - fd = open(path, O_RDONLY); - if (fd < 0) - { - printf(" -- ERROR: Failed to open %s: %d\n", path, errno); - g_nerrors++; - return; - } - - /* Read and verify the file contents */ - - nbytesread = read(fd, g_scratchbuffer, SCRATCHBUFFER_SIZE); - if (nbytesread < 0) - { - printf(" -- ERROR: Failed to read from %s: %d\n", path, errno); - g_nerrors++; - } - else if (nbytesread != node->size) - { - printf(" -- ERROR: Read %d bytes, expected %d\n", nbytesread, node->size); - g_nerrors++; - } - else if (memcmp(g_scratchbuffer, node->u.filecontent, node->size) != 0) - { - g_scratchbuffer[nbytesread] = '\0'; - printf(" -- ERROR: File content read does not match expectation:\n"); - printf(" -- Read: [%s]\n", g_scratchbuffer); - printf(" -- Expected: [%s]\n", node->u.filecontent); - g_nerrors++; - } - - /* Memory map and verify the file contents */ - - filedata = (char*)mmap(NULL, node->size, PROT_READ, MAP_SHARED|MAP_FILE, fd, 0); - if (!filedata || filedata == (char*)MAP_FAILED) - { - printf(" -- ERROR: mmap of %s failed: %d\n", path, errno); - g_nerrors++; - } - else - { - if (memcmp(filedata, node->u.filecontent, node->size) != 0) - { - memcpy(g_scratchbuffer, filedata, node->size); - g_scratchbuffer[node->size] = '\0'; - printf(" -- ERROR: Mapped file content read does not match expectation:\n"); - printf(" -- Memory: [%s]\n", filedata); - printf(" -- Expected: [%s]\n", node->u.filecontent); - g_nerrors++; - } - munmap(filedata, node->size); - } - - /* Close the file */ - - if (close(fd) != OK) - { - printf(" -- ERROR: Failed to close %s: %d\n", path, errno); - g_nerrors++; - } -} - -/**************************************************************************** - * Name: readdirectories - ****************************************************************************/ - -static void readdirectories(const char *path, struct node_s *entry) -{ - DIR *dirp; - struct node_s *node; - struct dirent *direntry; - char *fullpath; - - printf("Traversing directory: %s\n", path); - dirp = opendir(path); - if (!dirp) - { - printf(" ERROR opendir(\"%s\") failed: %d\n", path, errno); - g_nerrors++; - return; - } - - for (direntry = readdir(dirp); direntry; direntry = readdir(dirp)) - { - if (strcmp(direntry->d_name, ".") == 0 || strcmp(direntry->d_name, "..") == 0) - { - printf(" Skipping %s\n", direntry->d_name); - continue; - } - - node = findindirectory(entry, direntry->d_name); - if (!node) - { - printf(" ERROR: No node found for %s\n", direntry->d_name); - g_nerrors++; - continue; - } - - /* Get the full path to the entry */ - - sprintf(g_scratchbuffer, "%s/%s", path, direntry->d_name); - fullpath = strdup(g_scratchbuffer); - - if (DIRENT_ISDIRECTORY(direntry->d_type)) - { - printf(" DIRECTORY: %s/\n", fullpath); - if (!node->directory) - { - printf(" -- ERROR: Expected type directory\n"); - g_nerrors++; - } - else - { - checkattributes(fullpath, node->mode, 0); - readdirectories(fullpath, node->u.child); - printf("Continuing directory: %s\n", path); - } - } - else - { - printf(" FILE: %s/\n", fullpath); - if (node->directory) - { - printf(" -- ERROR: Expected type file\n"); - g_nerrors++; - } - else - { - checkattributes(fullpath, node->mode, node->size); - checkfile(fullpath, node); - } - } - free(fullpath); - } - - closedir(dirp); -} - -/**************************************************************************** - * Name: checkdirectories - ****************************************************************************/ - -static void checkdirectories(struct node_s *entry) -{ - for (; entry; entry = entry->peer) - { - if (!entry->found ) - { - printf("ERROR: %s never found\n", entry->name); - g_nerrors++; - } - - if (entry->directory) - { - checkdirectories(entry->u.child); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: romfs_main - ****************************************************************************/ - -int romfs_main(int argc, char *argv[]) -{ - int ret; - - /* Create a RAM disk for the test */ - - ret = romdisk_register(CONFIG_EXAMPLES_ROMFS_RAMDEVNO, testdir_img, - NSECTORS(testdir_img_len), CONFIG_EXAMPLES_ROMFS_SECTORSIZE); - if (ret < 0) - { - printf("ERROR: Failed to create RAM disk\n"); - return 1; - } - - /* Mount the test file system */ - - printf("Mounting ROMFS filesystem at target=%s with source=%s\n", - CONFIG_EXAMPLES_ROMFS_MOUNTPOINT, MOUNT_DEVNAME); - - ret = mount(MOUNT_DEVNAME, CONFIG_EXAMPLES_ROMFS_MOUNTPOINT, "romfs", MS_RDONLY, NULL); - if (ret < 0) - { - printf("ERROR: Mount failed: %d\n", errno); - return 1; - } - - /* Perform the test */ - - connectem(); - readdirectories(CONFIG_EXAMPLES_ROMFS_MOUNTPOINT, &g_adir); - checkdirectories(&g_adir); - - if (g_nerrors) - { - printf("Finished with %d errors\n", g_nerrors); - return g_nerrors; - } - - printf("PASSED\n"); - return 0; -} diff --git a/apps/examples/romfs/romfs_testdir.h b/apps/examples/romfs/romfs_testdir.h deleted file mode 100644 index 53f93105c..000000000 --- a/apps/examples/romfs/romfs_testdir.h +++ /dev/null @@ -1,89 +0,0 @@ -unsigned char testdir_img[] = { - 0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x02, 0x60, - 0x27, 0x43, 0x4a, 0x8a, 0x52, 0x4f, 0x4d, 0x46, 0x53, 0x5f, 0x54, 0x65, - 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, - 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xff, 0x97, - 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0x80, 0x2e, 0x2e, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, - 0x93, 0x9b, 0x95, 0xf0, 0x6c, 0x64, 0x69, 0x72, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x64, 0x69, 0x72, - 0x2f, 0x73, 0x75, 0x62, 0x64, 0x69, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, 0x19, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x00, - 0x9e, 0x9b, 0x93, 0xc5, 0x61, 0x64, 0x69, 0x72, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x58, 0x47, 0x43, 0xf1, - 0x61, 0x6e, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x66, 0x69, 0x6c, 0x65, 0x2e, - 0x74, 0x78, 0x74, 0x00, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, - 0x61, 0x6e, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x66, 0x69, 0x6c, 0x65, - 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, - 0xa1, 0xc5, 0x69, 0xd8, 0x79, 0x61, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x74, - 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x68, 0x69, 0x73, - 0x20, 0x69, 0x73, 0x20, 0x79, 0x65, 0x74, 0x20, 0x61, 0x6e, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x0a, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x50, 0x00, 0x00, 0x00, 0x90, - 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xfe, 0x20, 0x2e, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x70, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, - 0xd1, 0xd1, 0xfe, 0x70, 0x2e, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, - 0x00, 0x00, 0x01, 0x90, 0x00, 0x00, 0x00, 0x00, 0x23, 0x18, 0x9c, 0x03, - 0x73, 0x75, 0x62, 0x64, 0x69, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xd2, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x15, 0x3e, 0x3f, 0x06, 0xd8, 0x73, 0x75, 0x62, 0x64, - 0x69, 0x72, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x00, - 0x46, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x6e, 0x20, 0x73, 0x75, 0x62, 0x64, - 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x0a, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, - 0x00, 0x00, 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xfc, 0xa0, - 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, - 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0x70, 0x2e, 0x2e, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, 0x30, 0x00, 0x00, 0x01, 0x90, 0x00, 0x00, 0x00, 0x00, - 0x32, 0x99, 0x92, 0xd4, 0x68, 0x66, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc5, 0x6b, 0x22, 0x0b, - 0x61, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, - 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 -}; -unsigned int testdir_img_len = 1024; diff --git a/apps/examples/romfs/testdir.tar.gz b/apps/examples/romfs/testdir.tar.gz Binary files differdeleted file mode 100644 index cd0e9c518..000000000 --- a/apps/examples/romfs/testdir.tar.gz +++ /dev/null diff --git a/apps/examples/romfs/testdir.txt b/apps/examples/romfs/testdir.txt deleted file mode 100644 index e321d6ded..000000000 --- a/apps/examples/romfs/testdir.txt +++ /dev/null @@ -1,105 +0,0 @@ -VOLUME HEADER: Name=ROMFS_Test -0000000: 2d72 6f6d 3166 732d 0000 0260 2743 4a8a -rom1fs-...`'CJ. -0000010: 524f 4d46 535f 5465 7374 0000 0000 0000 ROMFS_Test...... - -FILE HEADER 1: Name=. -0000020: 0000 0049 0000 0020 0000 0000 d1ff ff97 ...I... ........ -0000030: 2e00 0000 0000 0000 0000 0000 0000 0000 ................ - -FILE HEADER 2: Name=.. -0000040: 0000 0060 0000 0020 0000 0000 d1d1 ff80 ...`... ........ -0000050: 2e2e 0000 0000 0000 0000 0000 0000 0000 ................ - -FILE HEADER 3: Name=ldir -0000060: 0000 0093 0000 0000 0000 000b 939b 95f0 ................ -0000070: 6c64 6972 0000 0000 0000 0000 0000 0000 ldir............ - - FILE CONTENT: - 0000080: 6164 6972 2f73 7562 6469 7200 0000 0000 adir/subdir..... - -FILE HEADER 4: Name=adir -0000090: 0000 0219 0000 00b0 0000 0000 9e9b 93c5 ................ -00000a0: 6164 6972 0000 0000 0000 0000 0000 0000 adir............ - - FILE HEADER 4.1: Name=anotherfile.txt - 00000b0: 0000 00f2 0000 0000 0000 0015 5847 43f1 ............XGC. - 00000c0: 616e 6f74 6865 7266 696c 652e 7478 7400 anotherfile.txt. - - FILE CONTENT: - 00000d0: 5468 6973 2069 7320 616e 6f74 6865 7220 This is another - 00000e0: 6669 6c65 0a00 0000 0000 0000 0000 0000 file............ - - FILE HEADER 4.2: Name=yafile.txt - 00000f0: 0000 0132 0000 0000 0000 0019 a1c5 69d8 ...2..........i. - 0000100: 7961 6669 6c65 2e74 7874 0000 0000 0000 yafile.txt...... - - FILE CONTENT: - 0000110: 5468 6973 2069 7320 7965 7420 616e 6f74 This is yet anot - 0000120: 6865 7220 6669 6c65 0a00 0000 0000 0000 her file........ - - FILE HEADER 4.3: Name=. - 0000130: 0000 0150 0000 0090 0000 0000 d1ff fe20 ...P........... - 0000140: 2e00 0000 0000 0000 0000 0000 0000 0000 ................ - - FILE HEADER 4.4: Name=.. - 0000150: 0000 0170 0000 0020 0000 0000 d1d1 fe70 ...p... .......p - 0000160: 2e2e 0000 0000 0000 0000 0000 0000 0000 ................ - - FILE HEADER 4.5: Name=subdir - 0000170: 0000 0009 0000 0190 0000 0000 2318 9c03 ............#... - 0000180: 7375 6264 6972 0000 0000 0000 0000 0000 subdir.......... - - FILE HEADER 4.5.1: Name=subdirfile.txt - 0000190: 0000 01d2 0000 0000 0000 0015 3e3f 06d8 ............>?.. - 00001a0: 7375 6264 6972 6669 6c65 2e74 7874 0000 subdirfile.txt.. - - FILE CONTENT: - 00001b0: 4669 6c65 2069 6e20 7375 6264 6972 6563 File in subdirec - 00001c0: 746f 7279 0a00 0000 0000 0000 0000 0000 tory............ - - FILE HEADER 4.5.2: Name=. - 00001d0: 0000 01f0 0000 0170 0000 0000 d1ff fca0 .......p........ - 00001e0: 2e00 0000 0000 0000 0000 0000 0000 0000 ................ - - FILE HEADER 4.5.3: Name=.. - 00001f0: 0000 0000 0000 0090 0000 0000 d1d1 ff70 ...............p - 0000200: 2e2e 0000 0000 0000 0000 0000 0000 0000 ................ - -FILE HEADER 5: Name=hfile -0000210: 0000 0230 0000 0190 0000 0000 3299 92d4 ...0........2... -0000220: 6866 696c 6500 0000 0000 0000 0000 0000 hfile........... - -FILE HEADER 6: Name=afile.txt -0000230: 0000 0002 0000 0000 0000 000f c56b 220b .............k". -0000240: 6166 696c 652e 7478 7400 0000 0000 0000 afile.txt....... - - FILE CONTENT: - 0000250: 5468 6973 2069 7320 6120 6669 6c65 0a00 This is a file.. - -PADDING -0000260: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000270: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000280: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000290: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00002a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00002b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00002c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00002d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00002e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00002f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000300: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000310: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000320: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000330: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000340: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000350: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000360: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000370: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000380: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0000390: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00003a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00003b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00003c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00003d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00003e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ -00003f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ diff --git a/apps/examples/serloop/Kconfig b/apps/examples/serloop/Kconfig deleted file mode 100644 index e52d35b3f..000000000 --- a/apps/examples/serloop/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_SERLOOP - bool "Serial loopback example" - default n - ---help--- - Enable the serial loopback example - -if EXAMPLES_SERLOOP -endif diff --git a/apps/examples/serloop/Makefile b/apps/examples/serloop/Makefile deleted file mode 100644 index 4a262884b..000000000 --- a/apps/examples/serloop/Makefile +++ /dev/null @@ -1,98 +0,0 @@ -############################################################################ -# apps/examples/serloop/Makefile -# -# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Mindlessly simple console loopack test - -ASRCS = -CSRCS = serloop_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -# Register application -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep - diff --git a/apps/examples/serloop/serloop_main.c b/apps/examples/serloop/serloop_main.c deleted file mode 100644 index af171fef3..000000000 --- a/apps/examples/serloop/serloop_main.c +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * examples/serloop/serloop_main.c - * - * Copyright (C) 2008-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 <unistd.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * serloop_main - ****************************************************************************/ - -int serloop_main(int argc, char *argv[]) -{ -#ifdef CONFIG_EXAMPLES_SERLOOP_BUFIO - int ch; - - for (;;) - { - ch = getchar(); - if (ch < 1) - { - ch = '!'; - } - else if ((ch < 0x20 || ch > 0x7e) && ch != '\n') - { - ch = '.'; - } - putchar(ch); - } -#else - uint8_t ch; - int ret; - - for (;;) - { - ret = read(0, &ch, 1); - if (ret < 1) - { - ch = '!'; - } - else if ((ch < 0x20 || ch > 0x7e) && ch != '\n') - { - ch = '.'; - } - ret = write(1, &ch, 1); - } -#endif - return 0; -} - diff --git a/apps/examples/watchdog/Kconfig b/apps/examples/watchdog/Kconfig deleted file mode 100644 index 18daf9327..000000000 --- a/apps/examples/watchdog/Kconfig +++ /dev/null @@ -1,40 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config EXAMPLES_WATCHDOG - bool "Watchdog Timer example" - default n - ---help--- - Enable the watchdog timer example - -if EXAMPLES_WATCHDOG - -config EXAMPLES_WATCHDOG_DEVPATH - string "Watchdog device path" - default "/dev/watchdog0" - ---help--- - The path to the watchdog device. Default: /dev/watchdog0 - -config CONFIG_EXAMPLES_WATCHDOG_PINGTIME - int "Watchdog ping time" - default 5000 - ---help--- - Time in milliseconds that the example will ping the watchdog before letting the - watchdog expire. Default: 5000 milliseconds. - -config CONFIG_EXAMPLES_WATCHDOG_PINGDELAY - int "Watchdog ping delay" - default 500 - ---help--- - Time delay between pings in milliseconds. Default: 500 milliseconds. - -config EXAMPLES_WATCHDOG_TIMEOUT - int "Watchdog timeout" - default 2000 - ---help--- - The watchdog timeout value in milliseconds before the watchdog timer - expires. Default: 2000 milliseconds. - -endif diff --git a/apps/examples/watchdog/Makefile b/apps/examples/watchdog/Makefile deleted file mode 100644 index 076272fe3..000000000 --- a/apps/examples/watchdog/Makefile +++ /dev/null @@ -1,109 +0,0 @@ -############################################################################ -# apps/examples/watchdog/Makefile -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Watchdog Timer Example. - -ASRCS = -CSRCS = watchdog_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Touchscreen built-in application info - -APPNAME = wdog -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) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/examples/watchdog/watchdog.h b/apps/examples/watchdog/watchdog.h deleted file mode 100644 index dd4daebb9..000000000 --- a/apps/examples/watchdog/watchdog.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - * examples/examples/watchdog/watchdog.h - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_EXAMPLES_WATCHDOG_WATCHDOG_H -#define __APPS_EXAMPLES_WATCHDOG_WATCHDOG_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* CONFIG_NSH_BUILTIN_APPS - Build the WATCHDOG test as an NSH built-in - * function. Default: Not built! The example can only be used as an NSH - * built-in application - * CONFIG_EXAMPLES_WATCHDOG_DEVPATH - The path to the Watchdog device. - * Default: /dev/watchdog0 - * CONFIG_EXAMPLES_WATCHDOG_PINGTIME - Time in milliseconds that the example - * will ping the watchdog before letting the watchdog expire. Default: 5000 - * milliseconds - * CONFIG_EXAMPLES_WATCHDOG_PINGDELAY - Time delay between pings in - * milliseconds. Default: 500 milliseconds. - * CONFIG_EXAMPLES_WATCHDOG_TIMEOUT - The watchdog timeout value in - * milliseconds before the watchdog timer expires. Default: 2000 - * milliseconds. - */ - -#ifndef CONFIG_WATCHDOG -# error "WATCHDOG device support is not enabled (CONFIG_WATCHDOG)" -#endif - -#ifndef CONFIG_NSH_BUILTIN_APPS -# warning "The WATCHDOG example only works as an NSH built-in application (CONFIG_NSH_BUILTIN_APPS)" -#endif - -#ifndef CONFIG_EXAMPLES_WATCHDOG_DEVPATH -# define CONFIG_EXAMPLES_WATCHDOG_DEVPATH "/dev/watchdog0" -#endif - -#ifndef CONFIG_EXAMPLES_WATCHDOG_PINGTIME -# define CONFIG_EXAMPLES_WATCHDOG_PINGTIME 5000 -#endif - -#ifndef CONFIG_EXAMPLES_WATCHDOG_PINGDELAY -# define CONFIG_EXAMPLES_WATCHDOG_PINGDELAY 500 -#endif - -#ifndef CONFIG_EXAMPLES_WATCHDOG_TIMEOUT -# define CONFIG_EXAMPLES_WATCHDOG_TIMEOUT 2000 -#endif - -/* Debug ********************************************************************/ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_DEBUG -# define message(...) syslog(__VA_ARGS__) -# define msgflush() -# else -# define message(...) printf(__VA_ARGS__) -# define msgflush() fflush(stdout) -# endif -#else -# ifdef CONFIG_DEBUG -# define message syslog -# define msgflush() -# else -# define message printf -# define msgflush() fflush(stdout) -# endif -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#endif /* __APPS_EXAMPLES_WATCHDOG_WATCHDOG_H */ diff --git a/apps/examples/watchdog/watchdog_main.c b/apps/examples/watchdog/watchdog_main.c deleted file mode 100644 index 53099d21a..000000000 --- a/apps/examples/watchdog/watchdog_main.c +++ /dev/null @@ -1,357 +0,0 @@ -/**************************************************************************** - * examples/watchdog/watchdog_main.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/ioctl.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/watchdog.h> - -#include "watchdog.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct wdog_example_s -{ - uint32_t pingtime; - uint32_t pingdelay; - uint32_t timeout; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: wdog_help - ****************************************************************************/ - -static void wdog_help(void) -{ - message("Usage: wdog [-h] [-d <pingtime] [-p <pingdelay>] [-t <timeout>]\n"); - message("\nInitialize the watchdog to the <timeout>. Start the watchdog\n"); - message("timer. Ping for the watchdog for <pingtime> seconds, then let it expire.\n"); - message("\nOptions include:\n"); - message(" [-d <pingtime>] = Selects the <delay> time in milliseconds. Default: %d\n", - CONFIG_EXAMPLES_WATCHDOG_PINGTIME); - message(" [-p <pingdelay] = Time delay between pings in milliseconds. Default: %d\n", - CONFIG_EXAMPLES_WATCHDOG_PINGDELAY); - message(" [-t timeout] = Time in milliseconds that the example will ping the watchdog\n"); - message(" before letting the watchdog expire. Default: %d\n", - CONFIG_EXAMPLES_WATCHDOG_TIMEOUT); - message(" [-h] = Shows this message and exits\n"); -} - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -static int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -static int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} - -/**************************************************************************** - * Name: parse_args - ****************************************************************************/ - -static void parse_args(FAR struct wdog_example_s *wdog, int argc, FAR char **argv) -{ - FAR char *ptr; - long value; - int index; - int nargs; - - wdog->pingtime = CONFIG_EXAMPLES_WATCHDOG_PINGTIME; - wdog->pingdelay = CONFIG_EXAMPLES_WATCHDOG_PINGDELAY; - wdog->timeout = CONFIG_EXAMPLES_WATCHDOG_TIMEOUT; - - for (index = 1; index < argc; ) - { - ptr = argv[index]; - if (ptr[0] != '-') - { - message("Invalid options format: %s\n", ptr); - exit(EXIT_SUCCESS); - } - - switch (ptr[1]) - { - case 'd': - nargs = arg_decimal(&argv[index], &value); - if (value < 1) - { - message("Ping delay out of range: %ld\n", value); - exit(EXIT_FAILURE); - } - - wdog->pingdelay = (uint32_t)value; - index += nargs; - break; - - case 'p': - nargs = arg_decimal(&argv[index], &value); - if (value < 1 || value > 99) - { - message("Ping time out of range: %ld\n", value); - exit(EXIT_FAILURE); - } - - wdog->pingtime = (uint8_t)value; - index += nargs; - break; - - case 't': - nargs = arg_decimal(&argv[index], &value); - if (value < 1 || value > INT_MAX) - { - message("Duration out of range: %ld\n", value); - exit(EXIT_FAILURE); - } - - wdog->timeout = (int)value; - index += nargs; - break; - - case 'h': - wdog_help(); - exit(EXIT_SUCCESS); - - default: - message("Unsupported option: %s\n", ptr); - wdog_help(); - exit(EXIT_FAILURE); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: wdog_main - ****************************************************************************/ - -int wdog_main(int argc, char *argv[]) -{ - struct wdog_example_s wdog; -#ifdef CONFIG_DEBUG_WATCHDOG - struct watchdog_status_s status; -#endif - long elapsed; - int fd; - int ret; - - /* Parse the command line */ - - parse_args(&wdog, argc, argv); - - /* Initialization of the WATCHDOG hardware is performed by logic external to - * this test. - */ - - ret = up_wdginitialize(); - if (ret != OK) - { - message("wdog_main: up_wdginitialize failed: %d\n", ret); - goto errout; - } - - /* Open the watchdog device for reading */ - - fd = open(CONFIG_EXAMPLES_WATCHDOG_DEVPATH, O_RDONLY); - if (fd < 0) - { - message("wdog_main: open %s failed: %d\n", - CONFIG_EXAMPLES_WATCHDOG_DEVPATH, errno); - goto errout; - } - - /* Set the watchdog timeout */ - - ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)wdog.timeout); - if (ret < 0) - { - message("wdog_main: ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno); - goto errout_with_dev; - } - - /* Then start the watchdog timer. */ - - ret = ioctl(fd, WDIOC_START, 0); - if (ret < 0) - { - message("wdog_main: ioctl(WDIOC_START) failed: %d\n", errno); - goto errout_with_dev; - } - - /* Then ping */ - - for (elapsed = 0; elapsed < wdog.pingtime; elapsed += wdog.pingdelay) - { - /* Sleep for the requested amount of time */ - - usleep(wdog.pingdelay * 1000); - - /* Show watchdog status. Only if debug is enabled because this - * could interfere with the timer. - */ - -#ifdef CONFIG_DEBUG_WATCHDOG - ret = ioctl(fd, WDIOC_GETSTATUS, (unsigned long)&status); - if (ret < 0) - { - message("wdog_main: ioctl(WDIOC_GETSTATUS) failed: %d\n", errno); - goto errout_with_dev; - } - message("wdog_main: flags=%08x timeout=%d timeleft=%d\n", - status.flags, status.timeout, status.timeleft); -#endif - - /* Then ping */ - - ret = ioctl(fd, WDIOC_KEEPALIVE, 0); - if (ret < 0) - { - message("wdog_main: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno); - goto errout_with_dev; - } - - message(" ping elapsed=%ld\n", elapsed); - msgflush(); - } - - /* Then stop pinging */ - - for (; ; elapsed += wdog.pingdelay) - { - /* Sleep for the requested amount of time */ - - usleep(wdog.pingdelay * 1000); - - /* Show watchdog status. Only if debug is enabled because this - * could interfere with the timer. - */ - -#ifdef CONFIG_DEBUG_WATCHDOG - ret = ioctl(fd, WDIOC_GETSTATUS, (unsigned long)&status); - if (ret < 0) - { - message("wdog_main: ioctl(WDIOC_GETSTATUS) failed: %d\n", errno); - goto errout_with_dev; - } - message("wdog_main: flags=%08x timeout=%d timeleft=%d\n", - status.flags, status.timeout, status.timeleft); -#endif - - message(" NO ping elapsed=%ld\n", elapsed); - msgflush(); - } - - /* We should not get here */ - - ret = ioctl(fd, WDIOC_STOP, 0); - if (ret < 0) - { - message("wdog_main: ioctl(WDIOC_STOP) failed: %d\n", errno); - goto errout_with_dev; - } - - close(fd); - msgflush(); - return OK; - -errout_with_dev: - close(fd); -errout: - msgflush(); - return ERROR; -} diff --git a/apps/include/builtin.h b/apps/include/builtin.h deleted file mode 100644 index 24cf204fa..000000000 --- a/apps/include/builtin.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * apps/include/builtin.h - * - * Originally by: - * - * Copyright (C) 2011 Uros Platise. All rights reserved. - * Author: Uros Platise <uros.platise@isotel.eu> - * - * With subsequent updates, modifications, and general maintenance by: - * - * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_BUILTIN_H -#define __APPS_INCLUDE_BUILTIN_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> - -#include <nuttx/binfmt/builtin.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: exec_builtin - * - * Description: - * Executes builtin applications registered during 'make context' time. - * New application is run in a separate task context (and thread). - * - * Input Parameter: - * filename - Name of the linked-in binary to be started. - * argv - Argument list - * redirfile - If output if redirected, this parameter will be non-NULL - * and will provide the full path to the file. - * oflags - If output is redirected, this parameter will provide the - * open flags to use. This will support file replacement - * of appending to an existing file. - * - * Returned Value: - * This is an end-user function, so it follows the normal convention: - * Returns the PID of the exec'ed module. On failure, it.returns - * -1 (ERROR) and sets errno appropriately. - * - ****************************************************************************/ - -EXTERN int exec_builtin(FAR const char *appname, FAR const char **argv, - FAR const char *redirfile, int oflags); - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __APPS_INCLUDE_BUILTIN_H */ diff --git a/apps/include/ftpc.h b/apps/include/ftpc.h deleted file mode 100644 index f9a73676a..000000000 --- a/apps/include/ftpc.h +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** - * apps/include/ftpc.h - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_FTPC_H -#define __APPS_INCLUDE_FTPC_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <stdbool.h> -#include <signal.h> -#include <time.h> - -#include <netinet/in.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ - -#ifndef CONFIG_FTP_DEFTIMEO -# define CONFIG_FTP_DEFTIMEO 30 -#endif - -#ifndef CONFIG_FTP_ANONPWD -# define CONFIG_FTP_ANONPWD "" -#endif - -#ifndef CONFIG_FTP_DEFPORT -# define CONFIG_FTP_DEFPORT 21 -#endif - -#ifndef CONFIG_FTP_MAXREPLY -# define CONFIG_FTP_MAXREPLY 256 -#endif - -#ifndef CONFIG_FTP_TMPDIR -# define CONFIG_FTP_TMPDIR "/tmp" -#endif - -#ifndef CONFIG_FTP_BUFSIZE -# define CONFIG_FTP_BUFSIZE 1024 -#endif - -#ifndef CONFIG_FTP_MAXPATH -# define CONFIG_FTP_MAXPATH 256 -#endif - -#ifndef CONFIG_FTP_SIGNAL -# define CONFIG_FTP_SIGNAL SIGUSR1 -#endif - -/* Interface arguments ******************************************************/ -/* These definitions describe how a put operation should be performed */ - -#define FTPC_PUT_NORMAL 0 /* Just PUT the file on the server */ -#define FTPC_PUT_APPEND 1 /* Append file to an existing file on the server */ -#define FTPC_PUT_UNIQUE 2 /* Create a uniquely named file on the server */ -#define FTPC_PUT_RESUME 3 /* Resume a previously started PUT transfer */ - -/* These definitions describe how a get operation should be performed */ - -#define FTPC_GET_NORMAL 0 /* Just GET the file from the server */ -#define FTPC_GET_APPEND 1 /* Append new file to an existing file */ -#define FTPC_GET_RESUME 3 /* Resume a previously started GET transfer */ - -/* Transfer mode encoding */ - -#define FTPC_XFRMODE_UNKNOWN 0 /* Nothing has been transferred yet */ -#define FTPC_XFRMODE_ASCII 1 /* Last transfer was ASCII mode */ -#define FTPC_XFRMODE_BINARY 2 /* Last transfer was binary mode */ - -/**************************************************************************** - * Public Types - ****************************************************************************/ -/* This "handle" describes the FTP session */ - -typedef FAR void *SESSION; - -/* This structure provides information to connect to a host FTP server. - * - * addr - The IPv4 address of the FTP server (or the proxy) for the FTP - * server. - * port - The port number on the FTP server to connect to (in host byte - * order). This is usually port 21 for FTP. You may set this - * value to zero to let FTPC select the default port number for - * you (it will use CONFIG_FTP_DEFPORT). - */ - -struct ftpc_connect_s -{ - struct in_addr addr; /* Server/proxy IP address */ - uint16_t port; /* Server/proxy port number (usually 21) in network order */ -}; - -/* This structure provides FTP login information */ - -struct ftpc_login_s -{ - FAR const char *uname; /* Login uname */ - FAR const char *pwd; /* Login pwd */ - FAR const char *rdir; /* Initial remote directory */ - bool pasv; /* true: passive connection mode */ -}; - -/* This structure describes one simple directory listing. The directory - * list container as well the individual filename strings are allocated. - * The number of names in tha actual allocated array is variable, given - * by the nnames field. - * - * Since the structure and file names are allocated, they must be freed - * by calling ftpc_dirfree() when they are no longer needed. Allocated - * name strings maby be "stolen" from the array but the pointer int the - * array should be nullified so that the string is not freed by - * ftpc_dirfree(). - */ - -struct ftpc_dirlist_s -{ - unsigned int nnames; /* Number of entries in name[] array */ - FAR char *name[1]; /* Filename with absolute path */ -}; - -#define SIZEOF_FTPC_DIRLIST(n) \ - (sizeof(struct ftpc_dirlist_s) + ((n)-1)*sizeof(FAR char *)) - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -/* Connection management ****************************************************/ - -EXTERN SESSION ftpc_connect(FAR struct ftpc_connect_s *server); -EXTERN void ftpc_disconnect(SESSION handle); - -/* FTP commands *************************************************************/ - -EXTERN int ftpc_login(SESSION handle, FAR struct ftpc_login_s *login); -EXTERN int ftpc_quit(SESSION handle); - -EXTERN int ftpc_chdir(SESSION handle, FAR const char *path); -EXTERN FAR char *ftpc_rpwd(SESSION handle); -EXTERN int ftpc_cdup(SESSION handle); -EXTERN int ftpc_mkdir(SESSION handle, FAR const char *path); -EXTERN int ftpc_rmdir(SESSION handle, FAR const char *path); - -EXTERN int ftpc_unlink(SESSION handle, FAR const char *path); -EXTERN int ftpc_chmod(SESSION handle, FAR const char *path, FAR const char *mode); -EXTERN int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname); -EXTERN off_t ftpc_filesize(SESSION handle, FAR const char *path); -EXTERN time_t ftpc_filetime(SESSION handle, FAR const char *filename); - -EXTERN int ftpc_idle(SESSION handle, unsigned int idletime); -EXTERN int ftpc_noop(SESSION handle); -EXTERN int ftpc_help(SESSION handle, FAR const char *arg); - -/* Directory listings *******************************************************/ - -EXTERN FAR struct ftpc_dirlist_s *ftpc_listdir(SESSION handle, - FAR const char *dirpath); -EXTERN void ftpc_dirfree(FAR struct ftpc_dirlist_s *dirlist); - -/* File transfers ***********************************************************/ - -EXTERN int ftpc_getfile(SESSION handle, FAR const char *rname, - FAR const char *lname, uint8_t how, uint8_t xfrmode); -EXTERN int ftp_putfile(SESSION handle, FAR const char *lname, - FAR const char *rname, uint8_t how, uint8_t xfrmode); - -/* FTP response *************************************************************/ - -EXTERN FAR char *ftpc_response(SESSION handle); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_FTPC_H */ diff --git a/apps/include/nsh.h b/apps/include/nsh.h deleted file mode 100644 index 8e469a555..000000000 --- a/apps/include/nsh.h +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** - * apps/include/nsh.h - * - * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_NSH_H -#define __APPS_INCLUDE_NSH_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ -/* If a USB device is selected for the NSH console then we need to handle some - * special start-up conditions. - */ - -#undef HAVE_USB_CONSOLE -#if defined(CONFIG_USBDEV) - -/* Check for a PL2303 serial console. Use console device "/dev/console". */ - -# if defined(CONFIG_PL2303) && defined(CONFIG_PL2303_CONSOLE) -# define HAVE_USB_CONSOLE 1 - -/* Check for a CDC/ACM serial console. Use console device "/dev/console". */ - -# elif defined(CONFIG_CDCACM) && defined(CONFIG_CDCACM_CONSOLE) -# define HAVE_USB_CONSOLE 1 - -/* Check for a generic USB console. In this case, the USB console device - * must be provided in CONFIG_NSH_CONDEV. - */ - -# elif defined(CONFIG_NSH_USBCONSOLE) -# define HAVE_USB_CONSOLE 1 -# endif -#endif - -#if CONFIG_RR_INTERVAL > 0 -# define SCHED_NSH SCHED_RR -#else -# define SCHED_NSH SCHED_FIFO -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_initialize - * - * Description: - * This nterfaces is used to initialize the NuttShell (NSH). - * nsh_initialize() should be called one during application start-up prior - * to executing either nsh_consolemain() or nsh_telnetstart(). - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -void nsh_initialize(void); - -/**************************************************************************** - * Name: nsh_consolemain - * - * Description: - * This interfaces maybe to called or started with task_start to start a - * single an NSH instance that operates on stdin and stdout. This - * function does not return. - * - * This function handles generic /dev/console character devices, or - * special USB console devices. The USB console requires some special - * operations to handle the cases where the session is lost when the - * USB device is unplugged and restarted when the USB device is plugged - * in again. - * - * Input Parameters: - * Standard task start-up arguments. These are not used. argc may be - * zero and argv may be NULL. - * - * Returned Values: - * This function does not normally return. exit() is usually called to - * terminate the NSH session. This function will return in the event of - * an error. In that case, a nonzero value is returned (EXIT_FAILURE=1). - * - ****************************************************************************/ - -int nsh_consolemain(int argc, char *argv[]); - -/**************************************************************************** - * Name: nsh_telnetstart - * - * Description: - * nsh_telnetstart() starts the Telnet daemon that will allow multiple - * NSH connections via Telnet. This function returns immediately after - * the daemon has been started. - * - * Input Parameters: - * None. All of the properties of the Telnet daemon are controlled by - * NuttX configuration setting. - * - * Returned Values: - * The task ID of the Telnet daemon was successfully started. A negated - * errno value will be returned on failure. - * - ****************************************************************************/ - -int nsh_telnetstart(void); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_NSH_H */ diff --git a/apps/include/readline.h b/apps/include/readline.h deleted file mode 100644 index 647778210..000000000 --- a/apps/include/readline.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * apps/include/readline.h - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_READLINE_H -#define __APPS_INCLUDE_READLINE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: readline - * - * readline() reads in at most one less than 'buflen' characters from - * 'instream' and stores them into the buffer pointed to by 'buf'. - * Characters are echoed on 'outstream'. Reading stops after an EOF or a - * newline. If a newline is read, it is stored into the buffer. A null - * terminator is stored after the last character in the buffer. - * - * This version of realine assumes that we are reading and writing to - * a VT100 console. This will not work well if 'instream' or 'outstream' - * corresponds to a raw byte steam. - * - * This function is inspired by the GNU readline but is an entirely - * different creature. - * - * Input Parameters: - * buf - The user allocated buffer to be filled. - * buflen - the size of the buffer. - * instream - The stream to read characters from - * outstream - The stream to each characters to. - * - * Returned values: - * On success, the (positive) number of bytes transferred is returned. - * A length of zero would indicated an end of file condition. An failure, - * a negated errno value is returned. - * - **************************************************************************/ - -EXTERN ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_READLINE_H */ diff --git a/apps/include/tiff.h b/apps/include/tiff.h deleted file mode 100644 index 378af9fe0..000000000 --- a/apps/include/tiff.h +++ /dev/null @@ -1,465 +0,0 @@ -/************************************************************************************ - * apps/include/tiff.h - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Reference: - * "TIFF, Revision 6.0, Final," June 3, 1992, Adobe Developers Association. - * - * 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_INCLUDE_TIFF_H -#define __APPS_INCLUDE_TIFF_H - -/************************************************************************************ - * Included Files - ************************************************************************************/ - -#include <nuttx/config.h> -#include <sys/types.h> -#include <nuttx/nx/nxglib.h> - -/************************************************************************************ - * Pre-Processor Definitions - ************************************************************************************/ -/* Configuration ********************************************************************/ - -/* TIFF File Format Definitions *****************************************************/ -/* Values for the IFD field type */ - -#define IFD_FIELD_BYTE 1 /* 8-bit unsigned integer */ -#define IFD_FIELD_ASCII 2 /* 8-bit byte that contains a 7-bit ASCII code. - * The last byte must be NUL */ -#define IFD_FIELD_SHORT 3 /* 16-bit (2-byte) unsigned integer */ -#define IFD_FIELD_LONG 4 /* 32-bit (4-byte) unsigned integer */ -#define IFD_FIELD_RATIONAL 5 /* Two LONGs: the first represents the - * numerator of a fraction, the second the - * denominator */ -#define IFD_FIELD_SBYTE 6 /* An 8-bit signed (twos-complement) integer */ -#define IFD_FIELD_UNDEFINED 7 /* An 8-bit byte that may contain anything, - * depending on the definition of the field */ -#define IFD_FIELD_SSHORT 8 /* A 16-bit (2-byte) signed (twos-complement) - * integer */ -#define IFD_FIELD_SLONG 9 /* A 32-bit (4-byte) signed (twos-complement) - * integer */ -#define IFD_FIELD_SRATIONAL 10 /* Two SLONG’s: the first represents the - * numerator of a fraction, the second the - * denominator */ -#define IFD_FIELD_FLOAT 11 /* Single precision (4-byte) IEEE format */ -#define IFD_FIELD_DOUBLE 12 /* Double precision (8-byte) IEEE format */ - -/* Values for the IFD tag type */ - -#define IFD_TAG_NEWSUBFILETYPE 254 /* NewSubfileType, LONG */ -# define TAG_NEWSUBFILETYPE_REDUCED (1 << 0) /* Bit 0: Reduced resolution verson of image */ -# define TAG_NEWSUBFILETYPE_SINGLE (1 << 1) /* Bit 1: Single page of a multi-page image */ -# define TAG_NEWSUBFILETYPE_TRANSP (1 << 2) /* Bit 2: Defines a transparency mask for image */ -#define IFD_TAG_SUBFILETYPE 255 /* SubfileType, SHORT */ -# define TAG_SUBFILETYPE_FULL 1 /* Full-resolution image data */ -# define TAG_SUBFILETYPE_REDUCED 2 /* Reduced-resolution image data */ -# define TAG_SUBFILETYPE_SINGLE 3 /* Single page of a multi-page image */ -#define IFD_TAG_IMAGEWIDTH 256 /* ImageLength, SHORT or LONG (Required) */ -#define IFD_TAG_IMAGELENGTH 257 /* ImageWidth, SHORT or LONG (Required) */ -#define IFD_TAG_BITSPERSAMPLE 258 /* BitsPerSample, SHORT (Required - * in greyscale and pallette-color image files) */ -#define IFD_TAG_COMPRESSION 259 /* Compression, SHORT (Required) */ -# define TAG_COMP_NONE 1 /* No compression */ -# define TAG_COMP_CCITT 2 /* CCITT Group 3 1-Dimensional Modified Huffman - * run length encoding */ -# define TAG_COMP_T4 3 /* CCITT T.4 bi-level encoding */ -# define TAG_COMP_T6 4 /* CCITT T.6 bi-level encoding */ -# define TAG_COMP_LZW 5 /* LZW */ -# define TAG_COMP_JPEG 6 /* LZW */ -# define TAG_COMP_PACKBITS 32773 /* PackBits compression */ -#define IFD_TAG_PMI 262 /* PhotometricInterpretation, SHORT (Required) */ -# define TAG_PMI_WHITE 0 /* WhiteIsZero */ -# define TAG_PMI_BLACK 1 /* BlackIsZero */ -# define TAG_PMI_RGB 2 /* RGB */ -# define TAG_PMI_PALETTE 3 /* Palette color */ -# define TAG_PMI_TRANSP 4 /* Transparency mask */ -# define TAG_PMI_CMYK 5 /* CMYK */ -# define TAG_PMI_YCbCr 6 /* YCbCr */ -# define TAG_PMI_CIELAB 8 /* 1976 CIE L*a*b* */ -#define IFD_TAG_THRESHHOLDING 263 /* Threshholding, SHORT */ -# define TAG_THRESHHOLD_NONE 1 /* No dithering or halftoning has been applied */ -# define TAG_THRESHHOLD_ORDERED 2 /* Ordered dither or halftone technique has been applied */ -# define TAG_THRESHHOLD_RANDOM 3 /* Randomized process has been applied */ -#define IFD_TAG_CELLWIDTH 264 /* CellWidth, SHORT */ -#define IFD_TAG_CELLLENGTH 265 /* CellLength, SHORT */ -#define IFD_TAG_FILLORDER 266 /* FillOrder, SHORT */ -# define TAG_FILLORDER_HIGH 1 /* Lower column values are stored in the - * higher-order bits */ -# define TAG_FILLORDER_LOW 2 /* Lower column values are stored in the - * lower-order bits */ -#define IFD_TAG_DOCUMENTNAME 269 /* DocumentName, ASCII */ -#define IFD_TAG_IMAGEDESCRIPTION 270 /* ImageDescription, ASCII */ -#define IFD_TAG_MAKE 271 /* Make, ASCII */ -#define IFD_TAG_MODEL 272 /* Model, ASCII */ -#define IFD_TAG_STRIPOFFSETS 273 /* StripOffsets, SHORT or LONG (Required) */ -#define IFD_TAG_ORIENTATION 274 /* Orientation, SHORT */ -# define TAG_ORIENTATION_TL 1 /* (0,0)=top left */ -# define TAG_ORIENTATION_TR 2 /* (0,0)=top right */ -# define TAG_ORIENTATION_BR 3 /* (0,0)=bottom right */ -# define TAG_ORIENTATION_BL 4 /* (0,0)=bottom left */ -# define TAG_ORIENTATION_LT 5 /* (0,0)=left top */ -# define TAG_ORIENTATION_RT 6 /* (0,0)=right top */ -# define TAG_ORIENTATION_RB 7 /* (0,0)=right bottom */ -# define TAG_ORIENTATION_LB 8 /* (0,0)=left bottom */ -#define IFD_TAG_SAMPLESPERPIXEL 277 /* SamplesPerPixel, SHORT (Required in - * RGB full color files) */ -#define IFD_TAG_ROWSPERSTRIP 278 /* RowsPerStrip, SHORT or LONG (Required) */ -#define IFD_TAG_STRIPCOUNTS 279 /* StripByteCounts, SHORT or LONG (Required) */ -#define IFD_TAG_MINSAMPLEVALUE 280 /* MinSampleValue, SHORT */ -#define IFD_TAG_MAXSAMPLEVALUE 281 /* MaxSampleValue, SHORT */ -#define IFD_TAG_XRESOLUTION 282 /* XResolution, RATIONAL (Required) */ -#define IFD_TAG_YRESOLUTION 283 /* YResolution, RATIONAL (Required) */ -#define IFD_TAG_PLANARCONFIG 284 /* PlanarConfiguration, SHORT */ -# define TAG_PLCONFIG_CHUNKY 1 /* Chunky format */ -# define TAG_PLCONFIG_PLANAR 2 /* Planar format */ -#define IFD_TAG_PAGENAME 285 /* PageName, ASCII */ -#define IFD_TAG_XPOSITION 286 /* XPosition, RATIONAL */ -#define IFD_TAG_YPOSITION 287 /* YPosition, RATIONAL */ -#define IFD_TAG_FREEOFFSETS 288 /* FreeOffsets, LONG */ -#define IFD_TAG_FREEBYTECOUNTS 289 /* FreeByteCounts, LONG */ -#define IFD_TAG_GRAYRESPONSEUNIT 290 /* GrayResponseUnit, SHORT */ -# define TAG_GRAYRESPUNIT_10THS 1 /* Number represents tenths of a unit */ -# define TAG_GRAYRESPUNIT_100THS 2 /* Number represents hundredths of a unit */ -# define TAG_GRAYRESPUNIT_1KTHS 3 /* Number represents thousandths of a unit */ -# define TAG_GRAYRESPUNIT_10KTHS 4 /* Number represents ten-thousandths of a unit */ -# define TAG_GRAYRESPUNIT_100KTHS 5 /* Number represents hundred-thousandths of a unit */ -#define IFD_TAG_GRAYRESPONSECURVE 291 /* GrayResponseCurve, SHORT */ -#define IFD_TAG_T4OPTIONS 292 /* T4Options, LONG */ -# define TAG_T4OPTIONS_2D (1 << 0) /* 2-dimensional coding */ -# define TAG_T4OPTIONS_NONE (1 << 1) /* Uncompressed mode */ -# define TAG_T4OPTIONS_FILL (1 << 2) /* Fill bits have been added */ -#define IFD_TAG_T6OPTIONS 293 /* T6Options, LONG */ -# define TAG_T6OPTIONS_NONE (1 << 1) /* Uncompressed mode allowed */ -#define IFD_TAG_RESUNIT 296 /* ResolutionUnit, SHORT (Required) */ -# define TAG_RESUNIT_NONE 1 /* No absolute unit of measurement */ -# define TAG_RESUNIT_INCH 2 /* Inch (default) */ -# define TAG_RESUNIT_CENTIMETER 3 /* Centimeter */ -#define IFD_TAG_PAGENUMBER 297 /* PageNumber, SHORT */ -#define IFD_TAG_TRANSFERFUNCTION 301 /* TransferFunction, SHORT */ -#define IFD_TAG_SOFTWARE 305 /* Software, ASCII */ -#define IFD_TAG_DATETIME 306 /* DateTime, ASCII */ -#define IFD_TAG_ARTIST 315 /* Artist, ASCII */ -#define IFD_TAG_HOSTCOMPUTER 316 /* HostComputer, ASCII */ -#define IFD_TAG_PREDICTOR 317 /* Predictor SHORT */ -# define TAG_PREDICTOR_NONE 1 /* No prediction scheme used before coding */ -# define TAG_PREDICTOR_HORIZ 2 /* Horizontal differencing */ -#define IFD_TAG_WHITEPOINT 318 /* WhitePoint, RATIONAL */ -#define IFD_TAG_PRIMARYCHROMA 319 /* PrimaryChromaticities, RATIONAL */ -#define IFD_TAG_COLORMAP 320 /* ColorMap, SHORT (Required in palette - * color image files) */ -#define IFD_TAG_HALFTONEHINTS 321 /* HalftoneHints, SHORT */ -#define IFD_TAG_TILEWIDTH 322 /* TileWidth, SHORT or LONG */ -#define IFD_TAG_TILELENGTH 323 /* TileLength, SHORT or LONG */ -#define IFD_TAG_TILEOFFSETS 324 /* TileOffsets, LONG */ -#define IFD_TAG_TILEBYTECOUNTS 325 /* TileByteCounts, SHORT or LONG */ -#define IFD_TAG_INKSET 332 /* InkSet, SHORT */ -# define TAG_INKSET_CMYK 1 /* CMYK */ -# define TAG_INKSET_OTHER 2 /* Not CMYK */ -#define IFD_TAG_INKNAMES 333 /* InkNames, ASCII */ -#define IFD_TAG_NUMBEROFINKS 334 /* NumberOfInks, SHORT */ -#define IFD_TAG_DOTRANGE 336 /* DotRange, BYTE or SHORT */ -#define IFD_TAG_TARGETPRINTER 337 /* TargetPrinter, ASCII */ -#define IFD_TAG_EXTRASAMPLES 338 /* ExtraSamples, SHORT */ -# define TAG_EXTSAMP_UNSPEC 0 /* Unspecified */ -# define TAG_EXTSAMP_ASSOCALPHA 1 /* Associated alpha data */ -# define TAG_EXTSAMP_UNASSALPHA 2 /* Unassociated alpha data */ -#define IFD_TAG_SAMPLEFORMAT 339 /* SampleFormat, SHORT */ -# define TAG_SAMPLEFMT_UNSIGED 1 /* Unsigned integer data */ -# define TAG_SAMPLEFMT_SIGNED 2 /* Two’s complement signed integer data */ -# define TAG_SAMPLEFMT_FLOAT 3 /* IEEE floating point data */ -# define TAG_SAMPLEFMT_UNDEFINED 4 /* Undefined data format */ -#define IFD_TAG_SMINSAMPLEVALUE 340 /* SMinSampleValue, type matches sample data */ -#define IFD_TAG_SMAXSAMPLEVALUE 341 /* SMaxSampleValue, type matches sample data */ -#define IFD_TAG_TRANSFERRANGE 342 /* TransferRange, SHORT */ -#define IFD_TAG_JPEGPROC 512 /* JPEGProc, SHORT */ -#define IFD_TAG_JPEGFMT 513 /* JPEGInterchangeFormat, LONG */ -#define IFD_TAG_JPEGLENGTH 514 /* JPEGInterchangeFormatLength, LONG */ -#define IFD_TAG_JPEGRESTART 515 /* JPEGRestartInterval, SHORT */ -#define IFD_TAG_JPEGLLPREDICTORS 517 /* JPEGLosslessPredictors, SHORT */ -#define IFD_TAG_JPEGPOINTXFORMS 518 /* JPEGPointTransforms, SHORT */ -#define IFD_TAG_JPEGQTABLES 519 /* JPEGQTables, LONG */ -#define IFD_TAG_JPEGDCTABLES 520 /* JPEGDCTables, LONG */ -#define IFD_TAG_JPEGACTABLES 521 /* JPEGACTables, LONG */ -#define IFD_TAG_YCbCrCOEFFS 529 /* YCbCrCoefficients, RATIONAL */ -#define IFD_TAG_YCbCrSUBSAMPLING 530 /* YCbCrSubSampling, SHORT */ -#define IFD_TAG_YCbCrPOSITIONING 531 /* YCbCrPositioning, SHORT */ -#define IFD_TAG_REFERENCEBW 532 /* ReferenceBlackWhite, RATIONAL */ -#define IFD_TAG_COPYRIGHT 33432 /* Copyright, ASCII */ - -/************************************************************************************ - * Public Types - ************************************************************************************/ -/* TIFF File Format Structure *******************************************************/ -/* "A TIFF file begins with an 8-byte image file header that points to an - * image file directory (IFD). An image file directory contains information - * about the image, as well as pointers to the actual image data." - */ - -struct tiff_header_s -{ - uint8_t order[2]; /* 0-1: Byte order: "II"=little endian, "MM"=big endian */ - uint8_t magic[2]; /* 2-3: 42 in appropriate byte order */ - uint8_t offset[4]; /* 4-7: Offset to the first IFD */ -}; -#define SIZEOF_TIFF_HEADER 8 - -/* "An Image File Directory (IFD) consists of a 2-byte count of the number - * of directory entries (i.e., the number of fields), followed by a sequence - * of 12-byte field entries, followed by a 4-byte offset of the next IFD (or - * 0 if none). - * - * Each 12-byte IFD entry has the following format: - */ - -struct tiff_ifdentry_s -{ - uint8_t tag[2]; /* 0-1: The Tag that identifies the field */ - uint8_t type[2]; /* 2-3 The field Type */ - uint8_t count[4]; /* 4-7: The number of values of the indicated type */ - uint8_t offset[4]; /* 8-11: The Value Offset (or the value itself) */ -}; -#define SIZEOF_IFD_ENTRY 12 - -/************************************************************************************/ -/* Structures needed to interface with the TIFF file creation library )and also - * structures used only internally by the TIFF file creation library). - */ - -/* This structure describes on strip in tmpfile2 */ - -struct tiff_strip_s -{ - uint32_t offset; /* Offset to the strip data in tmpfile1 */ - uint32_t count; /* Count of pixels in the strip */ -}; - -/* This structure is used only internally by the TIFF file creation library to - * manage file offsets. - */ - -struct tiff_filefmt_s -{ - uint16_t nifdentries; /* Number of IFD entries */ - uint16_t soifdoffset; /* Offset to StripOffset IFD entry */ - uint16_t sbcifdoffset; /* Offset to StripByteCount IFD entry */ - uint16_t valoffset; /* Offset to first values */ - uint16_t xresoffset; /* Offset to XResolution values */ - uint16_t yresoffset; /* Offset to yResolution values */ - uint16_t swoffset; /* Offset to Software string */ - uint16_t dateoffset; /* Offset to DateTime string */ - uint16_t sbcoffset; /* Offset to StripByteCount values */ -}; - -/* These type is used to hold information about the TIFF file under - * construction - */ - -struct tiff_info_s -{ - /* The first fields are used to pass information to the TIFF file creation - * logic via tiff_initialize(). - * - * Filenames. Three file names are required. (1) path to the final - * output file and (2) two paths to temporary files. One temporary file - * (tmpfile1) will be used to hold the strip image data and the other - * (tmpfile2) will be used to hold strip offset and count information. - * - * colorfmt - Specifies the form of the color data that will be provided - * in the strip data. These are the FB_FMT_* definitions - * provided in include/nuttx/fb.h. Only the following values - * are supported: - * - * FB_FMT_Y1 BPP=1, monochrome, 0=black - * FB_FMT_Y4 BPP=4, 4-bit greyscale, 0=black - * FB_FMT_Y8 BPP=8, 8-bit greyscale, 0=black - * FB_FMT_RGB16_565 BPP=16 R=6, G=6, B=5 - * FB_FMT_RGB24 BPP=24 R=8, G=8, B=8 - * - * rps - TIFF RowsPerStrip - * imgwidth - TIFF ImageWidth, Number of columns in the image - * imgheight - TIFF ImageLength, Number of rows in the image - */ - - FAR const char *outfile; /* Full path to the final output file name */ - FAR const char *tmpfile1; /* Full path to first temporary file */ - FAR const char *tmpfile2; /* Full path to second temporary file */ - - uint8_t colorfmt; /* See FB_FMT_* definitions in include/nuttx/fb.h */ - nxgl_coord_t rps; /* TIFF RowsPerStrip */ - nxgl_coord_t imgwidth; /* TIFF ImageWidth, Number of columns in the image */ - nxgl_coord_t imgheight; /* TIFF ImageLength, Number of rows in the image */ - - /* The caller must provide an I/O buffer as well. This I/O buffer will - * used for color conversions and as the intermediate buffer for copying - * files. The larger the buffer, the better the performance. - */ - - FAR uint8_t *iobuffer; /* IO buffer allocated by the caller */ - unsigned int iosize; /* The size of the I/O buffer in bytes */ - - /* The second set of fields are used only internally by the TIFF file - * creation logic. These fields must be set to zero initially by the - * caller of tiff_initialize(). User logic should not depend upon any - * definitions in the following -- they are subject to change without - * notice. They are only exposed here so that the caller can allocate - * memory for their storage. - */ - - uint8_t imgflags; /* Bit-encoded image flags */ - nxgl_coord_t nstrips; /* Number of strips in tmpfile3 */ - size_t pps; /* Pixels per strip */ - size_t bps; /* Bytes per strip */ - int outfd; /* outfile file descriptor */ - int tmp1fd; /* tmpfile1 file descriptor */ - int tmp2fd; /* tmpfile2 file descriptor */ - off_t outsize; /* Current size of outfile */ - off_t tmp1size; /* Current size of tmpfile1 */ - off_t tmp2size; /* Current size of tmpfile2 */ - - /* Points to an internal constant structure of file offsets */ - - FAR const struct tiff_filefmt_s *filefmt; -}; - -/************************************************************************************ - * Public Function Prototypes - ************************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/************************************************************************************ - * Name: tiff_initialize - * - * Description: - * Setup to create a new TIFF file. The overall steps to creating a TIFF file are - * as follows: - * - * 1) Create an initialize a struct tiff_info_s instance - * 2) Call tiff_initialize() to setup the file creation - * 3) Call tiff_addstrip() repeatedly to add strips to the graphic image - * 4) Call tiff_finalize() to complete the file creation. - * - * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state instance. - * - * Returned Value: - * Zero (OK) on success. A negated errno value on failure. - * - ************************************************************************************/ - -EXTERN int tiff_initialize(FAR struct tiff_info_s *info); - -/************************************************************************************ - * Name: tiff_addstrip - * - * Description: - * Add an image data strip. The size of the strip in pixels must be equal to - * the RowsPerStrip x ImageWidth values that were provided to tiff_initialize(). - * - * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state instance. - * buffer - A buffer containing a single row of data. - * - * Returned Value: - * Zero (OK) on success. A negated errno value on failure. - * - ************************************************************************************/ - -EXTERN int tiff_addstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip); - -/************************************************************************************ - * Name: tiff_finalize - * - * Description: - * Finalize the TIFF output file, completing the TIFF file creation steps. - * - * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state instance. - * - * Returned Value: - * Zero (OK) on success. A negated errno value on failure. - * - ************************************************************************************/ - -EXTERN int tiff_finalize(FAR struct tiff_info_s *info); - -/************************************************************************************ - * Name: tiff_abort - * - * Description: - * Abort the TIFF file creation and create-up resources. - * - * Input Parameters: - * info - A pointer to the caller allocated parameter passing/TIFF state instance. - * - * Returned Value: - * None - * - ************************************************************************************/ - -EXTERN void tiff_abort(FAR struct tiff_info_s *info); - -/************************************************************************************ - * Name: tiff_put/get16/32 - * - * Description: - * Put and get 16 and 32 values in the correct byte order at the specified position. - * - * Input Parameters: - * dest - The location to store the multi-byte data (put only) - * src - The location to get the multi-byte data (get only) - * - * Returned Value: - * None (put) - * The extracted value (get) - * - ************************************************************************************/ - -EXTERN void tiff_put16(FAR uint8_t *dest, uint16_t value); -EXTERN void tiff_put32(FAR uint8_t *dest, uint32_t value); -EXTERN uint16_t tiff_get16(FAR uint8_t *dest); -EXTERN uint32_t tiff_get32(FAR uint8_t *dest); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __APPS_INCLUDE_TIFF_H */ diff --git a/apps/include/usbmonitor.h b/apps/include/usbmonitor.h deleted file mode 100644 index 01fa060b0..000000000 --- a/apps/include/usbmonitor.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** - * apps/include/usbmonitor.h - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_INCLUDE_USBMONITOR_H -#define __APPS_INCLUDE_USBMONITOR_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#ifdef CONFIG_SYSTEM_USBMONITOR - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: usbmon_start and usbmon_stop - * - * Start and top the USB monitor daemon. These are normally controlled - * from the USB command line, but the ability to control these - * programmatically is also helpful (for example, so that the daemon is - * running before NSH starts). - * - * Input Parameters: - * Standard task parameters. These can be called or spawned. Since the - * return almost immediately, it is fine to just call the functions. The - * parameters are not used so you can pass 0 and NULL, respectivley; this - * is done this way so that these functions can be NSH builtin - * applications. - * - * Returned values: - * Standard task return values (zero meaning success). - * - **************************************************************************/ - -int usbmonitor_start(int argc, char **argv); -int usbmonitor_stop(int argc, char **argv); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* CONFIG_SYSTEM_USBMONITOR */ -#endif /* __APPS_INCLUDE_USBMONITOR_H */ diff --git a/apps/interpreters/Kconfig b/apps/interpreters/Kconfig deleted file mode 100644 index 6e7d1ac4f..000000000 --- a/apps/interpreters/Kconfig +++ /dev/null @@ -1,21 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -comment "Interpreters" - -source "$APPSDIR/interpreters/ficl/Kconfig" - -config INTERPRETERS_PCODE - bool "Pascal p-code interpreter" - default n - ---help--- - Enable support for the Pascal p-code interpreter. See README file at misc/pascal - and also the README.txt file in the apps/interpreter directory. Use of this - configuration implies that you have performed the required installation of the - Pascal run-time code. - -if INTERPRETERS_PCODE -endif - diff --git a/apps/interpreters/Make.defs b/apps/interpreters/Make.defs deleted file mode 100644 index 5d808d5d6..000000000 --- a/apps/interpreters/Make.defs +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################ -# apps/interpreters/Make.defs -# Adds selected applications to apps/ build -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -ifeq ($(CONFIG_INTERPRETERS_PCODE),y) -CONFIGURED_APPS += interpreters/pcode -endif - -ifeq ($(CONFIG_INTERPRETERS_FICL),y) -CONFIGURED_APPS += interpreters/ficl -endif diff --git a/apps/interpreters/Makefile b/apps/interpreters/Makefile deleted file mode 100644 index f78528714..000000000 --- a/apps/interpreters/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -############################################################################ -# apps/interpreters/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 - -# Sub-directories containing interpreter runtime - -SUBDIRS = pcode ficl - -# Create the list of installed runtime modules (INSTALLED_DIRS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) -define ADD_DIRECTORY -INSTALLED_DIRS += ${shell if exist $1\Makefile (echo $1)} -endef -else -define ADD_DIRECTORY -INSTALLED_DIRS += ${shell if [ -r $1/Makefile ]; then echo "$1"; fi} -endef -endif - -$(foreach DIR, $(SUBDIRS), $(eval $(call ADD_DIRECTORY,$(DIR)))) - -all: nothing -.PHONY: nothing context depend clean distclean - -define SDIR_template -$(1)_$(2): - $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" -endef - -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),depend))) -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),clean))) -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) - -nothing: - -context: - -depend: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_depend) - -clean: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_clean) - -distclean: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_distclean) diff --git a/apps/interpreters/README.txt b/apps/interpreters/README.txt deleted file mode 100644 index f33c75df1..000000000 --- a/apps/interpreters/README.txt +++ /dev/null @@ -1,67 +0,0 @@ -apps/interpreters README file -============================= - -This apps/ directory is set aside to hold interpreters that may be -incorporated into NuttX. - -ficl ----- - - This is DIY port of Ficl (the "Forth Inspired Command Language"). See - http://ficl.sourceforge.net/. It is a "DIY" port because the Ficl source - is not in that directory, only an environment and instructions that will - let you build Ficl under NuttX. The rest is up to you. - -pcode ------ - - At present, only the NuttX Pascal add-on is supported. This NuttX add-on - must be downloaded separately (or is available in an SVN snapshot in the - misc/pascal directory). - - This Pascal add-on must be installed into the NuttX apps/ directory. After - unpacking the Pascal add-on package, an installation script and README.txt - instructions can be found at pascal/nuttx. - - INSTALL.sh -- The script that performs the operation. Usage: - - ./INSTALL.sh [-16|-32] <install-dir> - - If you are using this standard NuttX apps/ package, the correct - location for the <install-dir> is apps/interpreters. That is - where the examples and build logic will expect to find the pcode - sub-directory. - - Example: - - ./INSTALL.sh -16 $PWD/../../../apps/interpreters - - After installation, the NuttX apps/interpresters directory will contain - the following files - - pcode - |-- Makefile - |-- include - | `-- Common header files - |-- libboff - | `-- Pascal object format (POFF) library - `--insn - |-- include - | `-- model-specific header files - `-- prun - `-- model-specific source files - - pashello - - There is a simple Pascal example at apps/examples/pashello. This is the - standard "Hello, World!" example written in Pascal and interpreted from - Pascal P-Code at runtime. To use this example, place the following in - your appconfig file" - - # Path to example in apps/examples containing the passhello_main entry point - - CONFIGURED_APPS += examples/pashello - - # Path to the Pascal p-code runtime interpreter module - - CONFIGURED_APPS += interpreters/pcode diff --git a/apps/interpreters/ficl/Kconfig b/apps/interpreters/ficl/Kconfig deleted file mode 100644 index ba6a7bc35..000000000 --- a/apps/interpreters/ficl/Kconfig +++ /dev/null @@ -1,16 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config INTERPRETERS_FICL - bool "Ficl Forth interpreter" - default n - ---help--- - Enable support for the Ficl interpreter interpreter. See README.txt file in the - apps/interpreters/ficl directory. Use of this configuration assumes - that you have performed the required installation of the Ficl run-time code. - -if INTERPRETERS_FICL -endif - diff --git a/apps/interpreters/ficl/Makefile b/apps/interpreters/ficl/Makefile deleted file mode 100644 index 3b2dc7ab9..000000000 --- a/apps/interpreters/ficl/Makefile +++ /dev/null @@ -1,118 +0,0 @@ -############################################################################ -# apps/interpreters/ficl/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -BUILDDIR := ${shell pwd | sed -e 's/ /\\ /g'} - --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# Tools - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# Include paths - -CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(BUILDDIR)/$(FICL_SUBDIR) $(BUILDDIR)/src} - -# Source Files - -ASRCS = -CXXSRCS = -CSRCS = nuttx.c - --include Make.srcs - -ASRCS += $(FICL_ASRCS) -CXXSRCS += $(FICL_CXXSRCS) -CSRCS += $(FICL_CSRCS) - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOT_DEPPATH = --dep-path . -SRC_DEPPATH = --dep-path src - -VPATH = src:$(FICL_SUBDIR) - -all: .built -.PHONY: debug context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -debug: - @#echo "FICL: $(FICL_SUBDIR)" - @#echo "VPATH: $(VPATH)" - @#echo "CFLAGS: $(CFLAGS)" - -.built: debug $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -context: - -.depend: debug Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOT_DEPPATH) $(SRC_DEPPATH) $(FICL_DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/interpreters/ficl/README.txt b/apps/interpreters/ficl/README.txt deleted file mode 100644 index bac9f3148..000000000 --- a/apps/interpreters/ficl/README.txt +++ /dev/null @@ -1,42 +0,0 @@ -apps/interpreter/README.txt -=========================== - -Ficl is a programming language interpreter designed to be embedded into -other systems as a command, macro, and development prototyping language. -Ficl is an acronym for "Forth Inspired Command Language". See -http://ficl.sourceforge.net/ - -Build Instructions ------------------- - -Disclaimer: This installation steps have only been exercised using Ficl -4.1.0. With new versions you will likely have to make some adjustments -to this instructtions or to the files within this directory. Think of this -information as "recommendations" -- not necessarily proven instructions. - -1. CD to apps/interpreters/ficl - -2. Download Ficl: http://sourceforge.net/projects/ficl/files/ - -3. Uznip the Ficl compressed file. - - For example, 'unzip ficl-4.1.0.zip' will leave the file - apps/interpreters/ficl/ficl-4.1.0 - -4. Configure to build Ficl in the apps/interpreters/ficl directory using - the configure.sh script. - - For example, './configure.sh ficl-4.1.0' will leave the Makefile - fragment 'Make.srcs' in the ficl build directory. - -5. Create your NuttX configuration. The appconfig file should include - (1) the path to your application code, and (2) the path to the Ficl - build directory. That latter would appear as the following line in - your appconfig file: - - CONFIGURED_APPS += interpreters/ficl - - 6. Configure and build NuttX. On successful completion, the Ficl objects - will be available in apps/libapps.a and that NuttX binary will be - linked against that file. Of course, Ficl will do nothing unless - you have written some application code that uses it! diff --git a/apps/interpreters/ficl/configure.sh b/apps/interpreters/ficl/configure.sh deleted file mode 100755 index cadc1d48a..000000000 --- a/apps/interpreters/ficl/configure.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -USAGE="$0 <Ficl-dir>" - -FICLDIR=$1 -if [ -z "${FICLDIR}" ]; then - echo "Missing command line argument" - echo $USAGE - exit 1 -fi - -if [ ! -d "${FICLDIR}" ]; then - echo "Sub-directory ${FICLDIR} does not exist" - echo $USAGE - exit 1 -fi - -if [ ! -r "${FICLDIR}/Makefile" ]; then - echo "Readable ${FICLDIR}/Makefile does not exist" - echo $USAGE - exit 1 -fi - -OBJECTS=`grep "^OBJECTS" ${FICLDIR}/Makefile` -if [ -z "${OBJECTS}" ]; then - echo "No OBJECTS found in ${FICLDIR}/Makefile" - echo $USAGE - exit 1 -fi - -OBJLIST=`echo ${OBJECTS} | cut -d'=' -f2 | sed -e "s/unix\.o//g"` - -rm -f Make.srcs -echo "# apps/interpreters/ficl/Make.obs" >> Make.srcs -echo "# Auto-generated file.. Do not edit" >> Make.srcs -echo "" >> Make.srcs -echo "FICL_SUBDIR = ${1}" >> Make.srcs -echo "FICL_DEPPATH = --dep-path ${1}" >> Make.srcs - -unset CSRCS -for OBJ in ${OBJLIST}; do - SRC=`echo ${OBJ} | sed -e "s/\.o/\.c/g"` - CSRCS=${CSRCS}" ${SRC}" -done -echo "FICL_ASRCS = " >> Make.srcs -echo "FICL_CXXSRCS = " >> Make.srcs -echo "FICL_CSRCS = ${CSRCS}" >> Make.srcs diff --git a/apps/interpreters/ficl/src/nuttx.c b/apps/interpreters/ficl/src/nuttx.c deleted file mode 100644 index 16b3fa1db..000000000 --- a/apps/interpreters/ficl/src/nuttx.c +++ /dev/null @@ -1,65 +0,0 @@ -#include <sys/stat.h> -#include <sys/statfs.h> - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> - -#include "ficl.h" - -void *ficlMalloc(size_t size) -{ - return malloc(size); -} - -void *ficlRealloc(void *p, size_t size) -{ - return realloc(p, size); -} - -void ficlFree(void *p) -{ - free(p); -} - -void ficlCallbackDefaultTextOut(ficlCallback *callback, char *message) -{ - FICL_IGNORE(callback); - if (message != NULL) - fputs(message, stdout); - else - fflush(stdout); - return; -} - -int ficlFileStatus(char *filename, int *status) -{ - struct stat statbuf; - if (stat(filename, &statbuf) == 0) - { - *status = statbuf.st_mode; - return 0; - } - *status = ENOENT; - return -1; -} - -long ficlFileSize(ficlFile *ff) -{ - struct stat statbuf; - if (ff == NULL) - return -1; - - statbuf.st_size = -1; - if (fstat(fileno(ff->f), &statbuf) != 0) - return -1; - - return statbuf.st_size; -} - -void ficlSystemCompilePlatform(ficlSystem *system) -{ - return; -} - - diff --git a/apps/interpreters/ficl/src/nuttx.h b/apps/interpreters/ficl/src/nuttx.h deleted file mode 100644 index e44031066..000000000 --- a/apps/interpreters/ficl/src/nuttx.h +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdint.h> - -typedef int8_t ficlInteger8; -typedef uint8_t ficlUnsigned8; -typedef int16_t ficlInteger16; -typedef uint16_t ficlUnsigned16; -typedef int32_t ficlInteger32; -typedef uint32_t ficlUnsigned32; - -typedef intptr_t ficlInteger; -typedef uintptr_t ficlUnsigned; -typedef float ficlFloat; - -#define FICL_PLATFORM_BASIC_TYPES (1) -#define FICL_PLATFORM_HAS_2INTEGER (0) -#define FICL_PLATFORM_HAS_FTRUNCATE (0) - -#define FICL_PLATFORM_OS "ansi" -#define FICL_PLATFORM_ARCHITECTURE "unknown" diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig deleted file mode 100644 index d7a7b8a99..000000000 --- a/apps/nshlib/Kconfig +++ /dev/null @@ -1,667 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config NSH_LIBRARY - bool "NSH Library" - default n - select SYSTEM_READLINE - ---help--- - Build the NSH support library. This is used, for example, by examples/nsh - in order to implement the full NuttShell (NSH). - -if NSH_LIBRARY -config NSH_BUILTIN_APPS - bool "Enable built-in applications" - default n - depends on BUILTIN - ---help--- - Support external registered, "built-in" applications that can be - executed from the NSH command line (see apps/README.txt for - more information). This options requires support for builtin - applications (BUILTIN). - -config NSH_FILE_APPS - bool "Enable execution of program files" - default n - depends on LIBC_EXECFUNCS - ---help--- - Support execution of program files residing within a file - system. This options requires support for the posix_spawn() - interface (LIBC_EXECFUNCS). - -menu "Disable Individual commands" - -config NSH_DISABLE_BASE64DEC - bool "Disable base64dec" - default n - depends on NETUTILS_CODECS && CODECS_BASE64 - -config NSH_DISABLE_BASE64ENC - bool "Disable base64enc" - default n - depends on NETUTILS_CODECS && CODECS_BASE64 - -config NSH_DISABLE_CAT - bool "Disable cat" - default n - -config NSH_DISABLE_CD - bool "Disable cd" - default n - -config NSH_DISABLE_CP - bool "Disable cp" - default n - -config NSH_DISABLE_CMP - bool "Disable cmp" - default n - -config NSH_DISABLE_DD - bool "Disable dd" - default n - -config NSH_DISABLE_ECHO - bool "Disable echo" - default n - -config NSH_DISABLE_EXEC - bool "Disable exec" - default n - -config NSH_DISABLE_EXIT - bool "Disable exit" - default n - -config NSH_DISABLE_FREE - bool "Disable free" - default n - -config NSH_DISABLE_GET - bool "Disable get" - default n - -config NSH_DISABLE_HELP - bool "Disable help" - default n - -config NSH_DISABLE_HEXDUMP - bool "Disable hexdump" - default n - -config NSH_DISABLE_IFCONFIG - bool "Disable ifconfig" - default n - -config NSH_DISABLE_KILL - bool "Disable kill" - default n - -config NSH_DISABLE_LOSETUP - bool "Disable losetup" - default n - -config NSH_DISABLE_LS - bool "Disable ls" - default n - -config NSH_DISABLE_MB - bool "Disable mb" - default n - -config NSH_DISABLE_MD5 - bool "Disable md5" - default n - depends on NETUTILS_CODECS && CODECS_HASH_MD5 - -config NSH_DISABLE_MKDIR - bool "Disable mkdir" - default n - -config NSH_DISABLE_MKFATFS - bool "Disable mkfatfs" - default n - -config NSH_DISABLE_MKFIFO - bool "Disable mkfifo" - default n - -config NSH_DISABLE_MKRD - bool "Disable mkrd" - default n - -config NSH_DISABLE_MH - bool "Disable mh" - default n - -config NSH_DISABLE_MOUNT - bool "Disable mount" - default n - -config NSH_DISABLE_MW - bool "Disable mw" - default n - -config NSH_DISABLE_NSFMOUNT - bool "Disable nfsmount" - default n - -config NSH_DISABLE_PS - bool "Disable ps" - default n - -config NSH_DISABLE_PING - bool "Disable ping" - default n - -config NSH_DISABLE_PUT - bool "Disable put" - default n - -config NSH_DISABLE_PWD - bool "Disable pwd" - default n - -config NSH_DISABLE_RM - bool "Disable rm" - default n - -config NSH_DISABLE_RMDIR - bool "Disable rmdir" - default n - -config NSH_DISABLE_SET - bool "Disable set" - default n - -config NSH_DISABLE_SH - bool "Disable sh" - default n - -config NSH_DISABLE_SLEEP - bool "Disable sleep" - default n - -config NSH_DISABLE_TEST - bool "Disable test" - default n - -config NSH_DISABLE_UMOUNT - bool "Disable umount" - default n - -config NSH_DISABLE_UNSET - bool "Disable unset" - default n - -config NSH_DISABLE_URLDECODE - bool "Disable urldecode" - default n - depends on NETUTILS_CODECS && CODECS_URLCODE - -config NSH_DISABLE_URLENCODE - bool "Disable urlencode" - default n - depends on NETUTILS_CODECS && CODECS_URLCODE - -config NSH_DISABLE_USLEEP - bool "Disable usleep" - default n - -config NSH_DISABLE_WGET - bool "Disable wget" - default n - -config NSH_DISABLE_XD - bool "Disable xd" - default n - -endmenu - -config NSH_CODECS_BUFSIZE - int "File buffer size used by CODEC commands" - default 128 - -config NSH_FILEIOSIZE - int "NSH I/O buffer size" - default 1024 - ---help--- - Size of a static I/O buffer used for file access (ignored if - there is no filesystem). Default is 1024. - -config NSH_STRERROR - bool "Use strerror()" - default n - depends on LIBC_STRERROR - ---help--- - strerror(errno) makes more readable output but strerror() is - very large and will not be used unless this setting is 'y' - This setting depends upon the strerror() having been enabled - with LIBC_STRERROR. - -config NSH_LINELEN - int "Max command line length" - default 80 - ---help--- - The maximum length of one command line and of one output line. - Default: 80 - -config NSH_NESTDEPTH - int "Maximum command nesting" - default 3 - ---help--- - The maximum number of nested if-then[-else]-fi sequences that - are permissable. Default: 3 - -config NSH_DISABLESCRIPT - bool "Disable script support" - default n - ---help--- - This can be set to 'y' to suppress support for scripting. This - setting disables the 'sh', 'test', and '[' commands and the - if-then[-else]-fi construct. This would only be set on systems - where a minimal footprint is a necessity and scripting is not. - -config NSH_DISABLEBG - bool "Disable background commands" - default n - ---help--- - This can be set to 'y' to suppress support for background - commands. This setting disables the 'nice' command prefix and - the '&' command suffix. This would only be set on systems - where a minimal footprint is a necessity and background command - execution is not. - -config NSH_MMCSDMINOR - int "MMC/SD minor device number" - default 0 - ---help--- - If the architecture supports an MMC/SD slot and if the NSH - architecture specific logic is present, this option will provide - the MMC/SD minor number, i.e., the MMC/SD block driver will - be registered as /dev/mmcsdN where N is the minor number. - Default is zero. - -config NSH_ROMFSETC - bool "Support ROMFS start-up script" - default n - depends on FS_ROMFS - ---help--- - Mount a ROMFS filesystem at /etc and provide a startup script - at /etc/init.d/rcS. The default startup script will mount - a FAT FS RAMDISK at /tmp but the logic is easily extensible. - -endif - -if NSH_ROMFSETC - -config NSH_ROMFSRC - bool "Support ROMFS login script" - default n - ---help--- - The ROMFS start-up script will be executed excactly once. For - simple, persistence consoles (like a serial console). But with - other other kinds of consoles, there may be multiple, transient - sessions (such as Telnet and USB consoles). In these cases, you - may need another script that is executed at the beginning of each - session. Selecting this option enables support for such a login - script - -config NSH_ROMFSMOUNTPT - string "ROMFS mount point" - default "/etc" - ---help--- - The default mountpoint for the ROMFS volume is /etc, but that - can be changed with this setting. This must be a absolute path - beginning with '/'. - -config NSH_INITSCRIPT - string "Relative path to startup script" - default "init.d/rcS" - ---help--- - This is the relative path to the startup script within the mountpoint. - The default is init.d/rcS. This is a relative path and must not - start with '/'. - -config NSH_RCSCRIPT - string "Relative path to login script" - default ".nshrc" - depends on NSH_ROMFSRC - ---help--- - This is the relative path to the login script within the mountpoint. - The default is .nshrc. This is a relative path and must not - start with '/'. - -config NSH_ROMFSDEVNO - int "ROMFS block device minor number" - default 0 - ---help--- - This is the minor number of the ROMFS block device. The default is - '0' corresponding to /dev/ram0. - -config NSH_ROMFSSECTSIZE - int "ROMFS sector size" - default 64 - ---help--- - This is the sector size to use with the ROMFS volume. Since the - default volume is very small, this defaults to 64 but should be - increased if the ROMFS volume were to be become large. Any value - selected must be a power of 2. - -config NSH_FATDEVNO - int "FAT block device minor number" - default 0 - depends on FS_FAT - ---help--- - When the default rcS file used when NSH_ROMFSETC is selected, it - will mount a FAT FS under /tmp. This is the minor number of the FAT - FS block device. The default is '1' corresponding to /dev/ram1. - -config NSH_FATSECTSIZE - int "FAT sector size" - default 512 - depends on FS_FAT - ---help--- - When the default rcS file used when NSH_ROMFSETC is selected, it - will mount a FAT FS under /tmp. This is the sector size use with the - FAT FS. Default is 512. - -config NSH_FATNSECTORS - int "FAT number of sectors" - default 1024 - depends on FS_FAT - ---help--- - When the default rcS file used when NSH_ROMFSETC is selected, it - will mount a FAT FS under /tmp. This is the number of sectors to use - with the FAT FS. Defualt is 1024. The amount of memory used by the - FAT FS will be NSH_FATSECTSIZE * NSH_FATNSECTORS bytes. - -config NSH_FATMOUNTPT - string "FAT mount point" - default "/tmp" - depends on FS_FAT - ---help--- - When the default rcS file used when NSH_ROMFSETC is selected, it - will mount a FAT FS under /tmp. This is the location where the FAT - FS will be mounted. Default is "/tmp". - -endif - -if NSH_LIBRARY -config NSH_CONSOLE - bool "Use console" - default y - ---help--- - If NSH_CONSOLE is set to 'y', then a character driver - console front-end is selected (/dev/console). - - Normally, the serial console device is a UART and RS-232 - interface. However, if USBDEV is defined, then a USB - serial device may, instead, be used if the one of - the following are defined: - - PL2303 and PL2303_CONSOLE - Set up the Prolifics PL2303 - emulation as a console device at /dev/console. - - CDCACM and CDCACM_CONSOLE - Set up the CDC/ACM serial - device as a console device at dev/console. - - NSH_USBCONSOLE and NSH_USBCONDEV - Sets up some other USB - serial device as the NSH console (not necessarily dev/console). - -config NSH_USBCONSOLE - bool "Use a USB console" - default n - depends on NSH_CONSOLE && USBDEV - ---help--- - If defined, then the an arbitrary USB device may be used - to as the NSH console. In this case, NSH_USBCONDEV must - be defined to indicate which USB device to use as the - console. - -config NSH_USBCONDEV - string "USB console device" - default "/dev/ttyACM0" - depends on NSH_USBCONSOLE - ---help--- - If NSH_USBCONSOLE is set to 'y', then NSH_USBCONDEV must - also be set to select the USB device used to support the - NSH console. This should be set to the quoted name of a - readable/write-able USB driver such as: - NSH_USBCONDEV="/dev/ttyACM0". - -config USBDEV_MINOR - int "USB console device minor number" - default 0 - depends on NSH_USBCONSOLE - ---help--- - If there are more than one USB devices, then a USB device - minor number may also need to be provided. Default: 0 - -comment "USB Trace Support" -config NSH_USBDEV_TRACE - bool "Enable Builtin USB Trace Support" - default n - depends on USBDEV && (DEBUG || USBDEV_TRACE) - ---help--- - Enable builtin USB trace support in NSH. If selected, buffered USB - trace data will be presented each time a command is provided to NSH. - The USB trace data will be sent to the console unless DEBUG set or - unless you are using a USB console. In those cases, the trace data - will go to the SYSLOG device. - - If not enabled, the USB trace support can be provided by external - logic such as apps/system/usbmonitor. - -if NSH_USBDEV_TRACE - -config NSH_USBDEV_TRACEINIT - bool "Show initialization events" - default n - ---help--- - Show initialization events - -config NSH_USBDEV_TRACECLASS - bool "Show class driver events" - default n - ---help--- - Show class driver events - -config NSH_USBDEV_TRACETRANSFERS - bool "Show data transfer events" - default n - ---help--- - Show data transfer events - -config NSH_USBDEV_TRACECONTROLLER - bool "Show controller events" - default n - ---help--- - Show controller events - -config NSH_USBDEV_TRACEINTERRUPTS - bool "Show interrupt-related events" - default n - ---help--- - Show interrupt-related events - -endif - -config NSH_CONDEV - bool "Default console device" - default "/dev/console" - depends on NSH_CONSOLE && !NSH_USBCONSOLE - ---help--- - If NSH_CONSOLE is set to 'y', then NSH_CONDEV - may also be set to select the serial device used to support - the NSH console. This should be set to the quoted name of a - readable/write-able character driver such as: - NSH_CONDEV="/dev/ttyS1". This is useful, for example, - to separate the NSH command line from the system console when - the system console is used to provide debug output. Default: - stdin and stdout (probably "/dev/console") - - NOTE: When any other device other than /dev/console is used - for a user interface, (1) linefeeds (\n) will not be expanded to - carriage return / linefeeds (\r\n). You will need to set - your terminal program to account for this. And (2) input is - not automatically echoed so you will have to turn local echo on. - -config NSH_ARCHINIT - bool "Have architecture-specific initialization" - default n - ---help--- - Set if your board provides architecture specific initialization - via the board-specific function nsh_archinitialize(). This - function will be called early in NSH initialization to allow - board logic to do such things as configure MMC/SD slots. - -config NSH_TELNET - bool "Use Telnet console" - default n - depends on NET && NET_TCP - ---help--- - If NSH_TELNET is set to 'y', then a TELENET - server front-end is selected. When this option is provided, - you may log into NuttX remotely using telnet in order to - access NSH. - -endif - -if NSH_TELNET -config NSH_TELNETD_PORT - int "Telnet port number" - default 23 - ---help--- - The telnet daemon will listen on this TCP port number for connections. - Default: 23 - -config NSH_TELNETD_DAEMONPRIO - int "Telnet daemon priority" - default 100 - ---help--- - Priority of the Telnet daemon. Default: 100 - -config NSH_TELNETD_DAEMONSTACKSIZE - int "Telnet daemon stack size" - default 2048 - ---help--- - Stack size allocated for the Telnet daemon. Default: 2048 - -config NSH_TELNETD_CLIENTPRIO - int "Telnet client priority" - default 100 - ---help--- - Priority of the Telnet client. Default: 100 - -config NSH_TELNETD_CLIENTSTACKSIZE - int "Telnet client stack size" - default 2048 - ---help--- - Stack size allocated for the Telnet client. Default: 2048 - -config NSH_IOBUFFER_SIZE - int "Telnet I/O buffer size" - default 512 - ---help--- - Determines the size of the I/O buffer to use for sending/ - receiving TELNET commands/reponses. Default: 512 - -config NSH_TELNET_LOGIN - bool "Telnet Login" - default n - ---help--- - If defined, then the Telnet user will be required to provide a - username and password to start the NSH shell. - -if NSH_TELNET_LOGIN - -config NSH_TELNET_USERNAME - string "Login Username" - default "admin" - ---help--- - Login user name. Default: "admin" - -config NSH_TELNET_PASSWORD - string "Login Password" - default "nuttx" - ---help--- - Login password: Default: "nuttx" - -config NSH_TELNET_FAILCOUNT - int "Login Retry Count" - default 3 - ---help--- - Number of login retry attempts. - -endif -endif - -config NSH_DHCPC - bool "Use DHCP to get IP address" - default n - depends on NSH_LIBRARY && NET && NET_UDP && NET_BROADCAST - ---help--- - Obtain the IP address via DHCP. - - Per RFC2131 (p. 9), the DHCP client must be prepared to receive DHCP - messages of up to 576 bytes (excluding Ethernet, IP, or UDP headers and FCS). - -config NSH_IPADDR - hex "Target IP address" - default 0xa0000002 - depends on NSH_LIBRARY && NET && !NSH_DHCPC - ---help--- - If NSH_DHCPC is NOT set, then the static IP address must be provided. - This is a 32-bit integer value in host order. So, as an example, - 0x10000002 would be 10.0.0.2. - -config NSH_DRIPADDR - hex "Router IP address" - default 0xa0000001 - depends on NSH_LIBRARY && NET && !NSH_DHCPC - ---help--- - Default router IP address (aka, Gateway). This is a 32-bit integer - value in host order. So, as an example, 0x10000001 would be 10.0.0.1. - -config NSH_NETMASK - hex "Network mask" - default 0xffffff00 - depends on NSH_LIBRARY && NET && !NSH_DHCPC - ---help--- - Network mask. This is a 32-bit integer value in host order. So, as - an example, 0xffffff00 would be 255.255.255.0. - -config NSH_DNS - bool "Use DNS" - default n - depends on NSH_LIBRARY && NET && NET_UDP && NET_BROADCAST - ---help--- - Configure to use a DNS. - -config NSH_DNSIPADDR - hex "DNS IP address" - default 0xa0000001 - depends on NSH_DNS - ---help--- - Configure the DNS address. This is a 32-bit integer value in host - order. So, as an example, 0xa0000001 would be 10.0.0.1. - -config NSH_NOMAC - bool "Hardware has no MAC address" - default n - depends on NSH_LIBRARY && NET - ---help--- - Set if your ethernet hardware has no built-in MAC address. - If set, a bogus MAC will be assigned. - -config NSH_MAX_ROUNDTRIP - int "Max Ping Round-Trip (DSEC)" - default 20 - depends on NSH_LIBRARY && NET && !NSH_DISABLE_PING - ---help--- - This is the maximum round trip for a response to a ICMP ECHO request. - It is in units of deciseconds. The default is 20 (2 seconds). - diff --git a/apps/nshlib/Make.defs b/apps/nshlib/Make.defs deleted file mode 100644 index 2bacb5b79..000000000 --- a/apps/nshlib/Make.defs +++ /dev/null @@ -1,40 +0,0 @@ -############################################################################ -# apps/nshlib/Make.defs -# Adds selected applications to apps/ build -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -ifeq ($(CONFIG_NSH_LIBRARY),y) -CONFIGURED_APPS += nshlib -endif - diff --git a/apps/nshlib/Makefile b/apps/nshlib/Makefile deleted file mode 100644 index 4256a1091..000000000 --- a/apps/nshlib/Makefile +++ /dev/null @@ -1,144 +0,0 @@ -############################################################################ -# apps/nshlib/Makefile -# -# Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# NSH Library - -ASRCS = -CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_script.c nsh_session.c -CSRCS += nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_mmcmds.c nsh_envcmds.c -CSRCS += nsh_dbgcmds.c - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -CSRCS += nsh_builtin.c -endif - -ifeq ($(CONFIG_NSH_FILE_APPS),y) -CSRCS += nsh_fileapps.c -endif - -ifeq ($(CONFIG_NSH_ROMFSETC),y) -CSRCS += nsh_romfsetc.c -endif - -ifeq ($(CONFIG_NET),y) -CSRCS += nsh_netinit.c nsh_netcmds.c -endif - -ifeq ($(CONFIG_RTC),y) -CSRCS += nsh_timcmds.c -endif - -ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) -CSRCS += nsh_mntcmds.c -endif - -ifeq ($(CONFIG_NSH_CONSOLE),y) -CSRCS += nsh_consolemain.c -endif - -ifeq ($(CONFIG_NSH_TELNET),y) -CSRCS += nsh_telnetd.c -endif - -ifneq ($(CONFIG_NSH_DISABLESCRIPT),y) -CSRCS += nsh_test.c -endif - -ifeq ($(CONFIG_USBDEV),y) -CSRCS += nsh_usbdev.c -endif - -ifeq ($(CONFIG_NETUTILS_CODECS),y) -CSRCS += nsh_codeccmd.c -endif - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\libapps$(LIBEXT) -else - BIN = ../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . -VPATH = - -MAXOPTIMIZATION = -Os - -# Build targets - -all: .built -.PHONY: context .depend depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - @touch .built - -context: - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep - diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt deleted file mode 100644 index a03f4a8ee..000000000 --- a/apps/nshlib/README.txt +++ /dev/null @@ -1,1218 +0,0 @@ -apps/nshlib -^^^^^^^^^^^ - - This directory contains the NuttShell (NSH) library. This library can be - linked with other logic to provide a simple shell application for NuttX. - - - Console/NSH Front End - - Command Overview - - Conditional Command Execution - - Built-In Variables - - Current Working Directory - Environment Variables - - NSH Start-Up Script - - Simple Commands - - NSH Configuration Settings - Command Dependencies on Configuration Settings - NSH-Specific Configuration Settings - - Common Problems - -Console/NSH Front End -^^^^^^^^^^^^^^^^^^^^^ - - Using settings in the configuration file, NSH may be configured to - use either the serial stdin/out or a telnet connection as the console - or BOTH. When NSH is started, you will see the following welcome on - either console: - - NuttShell (NSH) - nsh> - - 'nsh>' is the NSH prompt and indicates that you may enter a command - from the console. - -Command Overview -^^^^^^^^^^^^^^^^ - - This directory contains the NuttShell (NSH). This is a simple - shell-like application. At present, NSH supports the following commands - forms: - - Simple command: <cmd> - Command with re-directed output: <cmd> > <file> - <cmd> >> <file> - Background command: <cmd> & - Re-directed background command: <cmd> > <file> & - <cmd> >> <file> & - - Where: - - <cmd> is any one of the simple commands listed later. - <file> is the full or relative path to any writable object - in the filesystem name space (file or character driver). - Such objects will be referred to simply as files throughout - this README. - - NSH executes at the mid-priority (128). Backgrounded commands can - be made to execute at higher or lower priorities using nice: - - [nice [-d <niceness>>]] <cmd> [> <file>|>> <file>] [&] - - Where <niceness> is any value between -20 and 19 where lower - (more negative values) correspond to higher priorities. The - default niceness is 10. - -Conditional Command Execution -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - An if-then[-else]-fi construct is also supported in order to - support conditional execution of commands. This works from the - command line but is primarily intended for use within NSH scripts - (see the sh commnd). The syntax is as follows: - - if <cmd> - then - [sequence of <cmd>] - else - [sequence of <cmd>] - fi - -Built-In Variables -^^^^^^^^^^^^^^^^^^ - - $? - The result of the last simple command execution - -Current Working Directory -^^^^^^^^^^^^^^^^^^^^^^^^^ - - All path arguments to commands may be either an absolute path or a - path relative to the current working directory. The current working - directory is set using the 'cd' command and can be queried either - by using the 'pwd' command or by using the 'echo $PWD' command. - - Environment Variables: - ---------------------- - - PWD - The current working directory - OLDPWD - The previous working directory - -NSH Start-Up Script -^^^^^^^^^^^^^^^^^^^ - -NSH supports options to provide a start up script for NSH. In general -this capability is enabled with CONFIG_NSH_ROMFSETC, but has -several other related configuration options as described in the final -section of this README. This capability also depends on: - - - CONFIG_DISABLE_MOUNTPOINT not set - - CONFIG_NFILE_DESCRIPTORS > 4 - - CONFIG_FS_ROMFS - -Default Start-Up Behavior -------------------------- - -The implementation that is provided is intended to provide great flexibility -for the use of Start-Up files. This paragraph will discuss the general -behavior when all of the configuration options are set to the default -values. - -In this default case, enabling CONFIG_NSH_ROMFSETC will cause -NSH to behave as follows at NSH startup time: - -- NSH will create a read-only RAM disk (a ROM disk), containing a tiny - ROMFS filesystem containing the following: - - |--init.d/ - `-- rcS - - Where rcS is the NSH start-up script - -- NSH will then mount the ROMFS filesystem at /etc, resulting in: - - |--dev/ - | `-- ram0 - `--etc/ - `--init.d/ - `-- rcS - -- By default, the contents of rcS script are: - - # Create a RAMDISK and mount it at XXXRDMOUNTPOUNTXXX - - mkrd -m 1 -s 512 1024 - mkfatfs /dev/ram1 - mount -t vfat /dev/ram1 /tmp - -- NSH will execute the script at /etc/init.d/rcS at start-up (before the - first NSH prompt. After execution of the script, the root FS will look - like: - - |--dev/ - | |-- ram0 - | `-- ram1 - |--etc/ - | `--init.d/ - | `-- rcS - `--tmp/ - -Modifying the ROMFS Image -------------------------- - -The contents of the /etc directory are retained in the file -apps/nshlib/nsh_romfsimg.h (OR, if CONFIG_NSH_ARCHROMFS -is defined, include/arch/board/rcs.template). In order to modify -the start-up behavior, there are three things to study: - -1. Configuration Options. - The additional CONFIG_NSH_ROMFSETC configuration options - discussed in the final section of this README. - -2. tools/mkromfsimg.sh Script. - The script tools/mkromfsimg.sh creates nsh_romfsimg.h. - It is not automatically executed. If you want to change the - configuration settings associated with creating and mounting - the /tmp directory, then it will be necessary to re-generate - this header file using the mkromfsimg.sh script. - - The behavior of this script depends upon three things: - - - The configuration settings of the installed NuttX configuration. - - The genromfs tool (available from http://romfs.sourceforge.net). - - The file apps/nshlib/rcS.template (OR, if - CONFIG_NSH_ARCHROMFS is defined, include/arch/board/rcs.template) - -3. rcS.template. - The file apps/nshlib/rcS.template contains the general form - of the rcS file; configured values are plugged into this - template file to produce the final rcS file. - -NOTE: - - apps/nshlib/rcS.template generates the standard, default - nsh_romfsimg.h file. If CONFIG_NSH_ARCHROMFS is defined - in the NuttX configuration file, then a custom, board-specific - nsh_romfsimg.h file residing in configs/<board>/include will be - used. NOTE when the OS is configured, include/arch/board will - be linked to configs/<board>/include. - -All of the startup-behavior is contained in rcS.template. The -role of mkromfsimg.sh is to (1) apply the specific configuration -settings to rcS.template to create the final rcS, and (2) to -generate the header file nsh_romfsimg.h containg the ROMFS -file system image. - -Simple Commands -^^^^^^^^^^^^^^^ - -o [ <expression> ] -o test <expression> - - These are two alternative forms of the same command. They support - evaluation of a boolean expression which sets $?. This command - is used most frequently as the conditional command following the - 'if' in the if-then[-else]-fi construct. - - Expression Syntax: - ------------------ - - expression = simple-expression | !expression | - expression -o expression | expression -a expression - - simple-expression = unary-expression | binary-expression - - unary-expression = string-unary | file-unary - - string-unary = -n string | -z string - - file-unary = -b file | -c file | -d file | -e file | -f file | - -r file | -s file | -w file - - binary-expression = string-binary | numeric-binary - - string-binary = string = string | string == string | string != string - - numeric-binary = integer -eq integer | integer -ge integer | - integer -gt integer | integer -le integer | - integer -lt integer | integer -ne integer - -o base64dec [-w] [-f] <string or filepath> - -o base64dec [-w] [-f] <string or filepath> - -o cat <path> [<path> [<path> ...]] - - This command copies and concatentates all of the files at <path> - to the console (or to another file if the output is redirected). - -o cd [<dir-path>|-|~|..] - - Changes the current working directory (PWD). Also sets the - previous working directory environment variable (OLDPWD). - - FORMS: - ------ - - 'cd <dir-path>' sets the current working directory to <dir-path>. - 'cd -' sets the current working directory to the previous - working directory ($OLDPWD). Equivalent to 'cd $OLDPWD'. - 'cd' or 'cd ~' set the current working directory to the 'home' - directory. The 'home' directory can be configured by setting - CONFIG_LIB_HOMEDIR in the configuration file. The default - 'home' directory is '/'. - 'cd ..' sets the current working directory to the parent directory. - -o cp <source-path> <dest-path> - - Copy of the contents of the file at <source-path> to the location - in the filesystem indicated by <path-path> - -o date [-s "MMM DD HH:MM:SS YYYY"] - - Show or set the current date and time. This command is only supported - if the platform supported RTC hardware (CONFIG_RTC=y). - - Only one format is used both on display and when setting the date/time: - MMM DD HH:MM:SS YYYY. For example, - - data -s "Sep 1 11:30:00 2011" - - 24-hour time format is assumed. - -o dd if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>] - - Copy blocks from <infile> to <outfile>. <nfile> or <outfile> may - be the path to a standard file, a character device, or a block device. - - Examples: - - 1. Read from character device, write to regular file. This will - create a new file of the specified size filled with zero. - - nsh> dd if=/dev/zero of=/tmp/zeros bs=64 count=16 - nsh> ls -l /tmp - /tmp: - -rw-rw-rw- 1024 ZEROS - - 2. Read from character device, write to block device. This will - fill the entire block device with zeros. - - nsh> ls -l /dev - /dev: - brw-rw-rw- 0 ram0 - crw-rw-rw- 0 zero - nsh> dd if=/dev/zero of=/dev/ram0 - - 3. Read from a block devic, write to a character device. This - will read the entire block device and dump the contents in - the bit bucket. - - nsh> ls -l /dev - /dev: - crw-rw-rw- 0 null - brw-rw-rw- 0 ram0 - nsh> dd if=/dev/ram0 of=/dev/null - -o df - - Show the state of each mounted volume. - - Example: - - nsh> mount - /etc type romfs - /tmp type vfat - nsh> df - Block Number - Size Blocks Used Available Mounted on - 64 6 6 0 /etc - 512 985 2 983 /tmp - nsh> - -o echo [<string|$name> [<string|$name>...]] - - Copy the sequence of strings and expanded environment variables to - console out (or to a file if the output is re-directed). - -o exec <hex-address> - - Execute the user logic at address <hex-address>. NSH will pause - until the execution unless the user logic is executed in background - via 'exec <hex-address> &' - -o exit - - Exit NSH. Only useful if you have started some other tasks (perhaps - using the 'exec' command') and you would like to have NSH out of the - way. - -o free - - Show the current state of the memory allocator. For example, - - nsh> free - free - total used free largest - Mem: 4194288 1591552 2602736 2601584 - - Where: - total - This is the total size of memory allocated for use - by malloc in bytes. - used - This is the total size of memory occupied by - chunks handed out by malloc. - free - This is the total size of memory occupied by - free (not in use) chunks. - largest - Size of the largest free (not in use) chunk - -o get [-b|-n] [-f <local-path>] -h <ip-address> <remote-path> - - Use TFTP to copy the file at <remote-address> from the host whose IP - address is identified by <ip-address>. Other options: - - -f <local-path> - The file will be saved relative to the current working directory - unless <local-path> is provided. - -b|-n - Selects either binary ("octect") or test ("netascii") transfer - mode. Default: text. - -o help [-v] [<cmd>] - - Presents summary information about NSH commands to console. Options: - - -v - Show verbose output will full command usage - - <cmd> - Show full command usage only for this command - -o hexdump <file or device> - - Dump data in hexadecimal format from a file or character device. - -o ifconfig [nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>] - - Show the current configuration of the network, for example: - - nsh> ifconfig - eth0 HWaddr 00:18:11:80:10:06 - IPaddr:10.0.0.2 DRaddr:10.0.0.1 Mask:255.255.255.0 - - if uIP statistics are enabled (CONFIG_NET_STATISTICS), then - this command will also show the detailed state of uIP. - -o ifdown <nic-name> - - Take down the interface identified by the name <nic-name>. - - Example: - - ifdown eth0 - -o ifup <nic-name> - - Bring up down the interface identified by the name <nic-name>. - - Example: - - ifup eth0 - -o kill -<signal> <pid> - - Send the <signal> to the task identified by <pid>. - -o losetup [-d <dev-path>] | [[-o <offset>] [-r] <ldev-path> <file-path>] - - Setup or teardown the loop device: - - 1. Teardown the setup for the loop device at <dev-path>: - - losetup d <dev-path> - - 2. Setup the loop device at <dev-path> to access the file at <file-path> - as a block device: - - losetup [-o <offset>] [-r] <dev-path> <file-path> - - Example: - - nsh> dd if=/dev/zero of=/tmp/image bs=512 count=512 - nsh> ls -l /tmp - /tmp: - -rw-rw-rw- 262144 IMAGE - nsh> losetup /dev/loop0 /tmp/image - nsh> ls -l /dev - /dev: - brw-rw-rw- 0 loop0 - nsh> mkfatfs /dev/loop0 - nsh> mount -t vfat /dev/loop0 /mnt/example - nsh> ls -l /mnt - ls -l /mnt - /mnt: - drw-rw-rw- 0 example/ - nsh> echo "This is a test" >/mnt/example/atest.txt - nsh> ls -l /mnt/example - /mnt/example: - -rw-rw-rw- 16 ATEST.TXT - nsh> cat /mnt/example/atest.txt - This is a test - nsh> - -o ls [-lRs] <dir-path> - - Show the contents of the directory at <dir-path>. NOTE: - <dir-path> must refer to a directory and no other filesystem - object. - - Options: - -------- - - -R Show the constents of specified directory and all of its - sub-directories. - -s Show the size of the files along with the filenames in the - listing - -l Show size and mode information along with the filenames - in the listing. - -o md5 [-f] <string or filepath> - -o mb <hex-address>[=<hex-value>][ <hex-byte-count>] -o mh <hex-address>[=<hex-value>][ <hex-byte-count>] -o mw <hex-address>[=<hex-value>][ <hex-byte-count>] - - Access memory using byte size access (mb), 16-bit accesses (mh), - or 32-bit access (mw). In each case, - - <hex-address>. Specifies the address to be accessed. The current - value at that address will always be read and displayed. - <hex-address>=<hex-value>. Read the value, then write <hex-value> - to the location. - <hex-byte-count>. Perform the mb, mh, or mw operation on a total - of <hex-byte-count> bytes, increment the <hex-address> appropriately - after each access - - Example - - nsh> mh 0 16 - 0 = 0x0c1e - 2 = 0x0100 - 4 = 0x0c1e - 6 = 0x0110 - 8 = 0x0c1e - a = 0x0120 - c = 0x0c1e - e = 0x0130 - 10 = 0x0c1e - 12 = 0x0140 - 14 = 0x0c1e - nsh> - -o mkdir <path> - - Create the directory at <path>. All components of of <path> - except the final directory name must exist on a mounted file - system; the final directory must not. - - Recall that NuttX uses a pseudo filesystem for its root file system. - The mkdir command can only be used to create directories in volumes - set up with the mount command; it cannot be used to create directories - in the pseudo filesystem. - - Example: - ^^^^^^^^ - - nsh> mkdir /mnt/fs/tmp - nsh> ls -l /mnt/fs - /mnt/fs: - drw-rw-rw- 0 TESTDIR/ - drw-rw-rw- 0 TMP/ - nsh> - -o mkfatfs <path> - - Format a fat file system on the block device specified by path. - NSH provides this command to access the mkfatfs() NuttX API. - This block device must reside in the NuttX pseudo filesystem and - must have been created by some call to register_blockdriver() (see - include/nuttx/fs/fs.h). - -o mkfifo <path> - - Creates a FIFO character device anywhere in the pseudo file system, - creating whatever pseudo directories that may be needed to complete - the full path. By convention, however, device drivers are place in - the standard /dev directory. After it is created, the FIFO device - may be used as any other device driver. NSH provides this command - to access the mkfifo() NuttX API. - - Example: - ^^^^^^^^ - - nsh> ls -l /dev - /dev: - crw-rw-rw- 0 console - crw-rw-rw- 0 null - brw-rw-rw- 0 ram0 - nsh> mkfifo /dev/fifo - nsh> ls -l /dev - ls -l /dev - /dev: - crw-rw-rw- 0 console - crw-rw-rw- 0 fifo - crw-rw-rw- 0 null - brw-rw-rw- 0 ram0 - nsh> - -o mkrd [-m <minor>] [-s <sector-size>] <nsectors> - - Create a ramdisk consisting of <nsectors>, each of size - <sector-size> (or 512 bytes if <sector-size> is not specified. - The ramdisk will be registered as /dev/ram<n> (if <n> is not - specified, mkrd will attempt to register the ramdisk as - /dev/ram0. - - Example: - ^^^^^^^^ - - nsh> ls /dev - /dev: - console - null - ttyS0 - ttyS1 - nsh> mkrd 1024 - nsh> ls /dev - /dev: - console - null - ram0 - ttyS0 - ttyS1 - nsh> - - Once the ramdisk has been created, it may be formatted using - the mkfatfs command and mounted using the mount command. - - Example: - ^^^^^^^^ - nsh> mkrd 1024 - nsh> mkfatfs /dev/ram0 - nsh> mount -t vfat /dev/ram0 /tmp - nsh> ls /tmp - /tmp: - nsh> - -o mount [-t <fstype> <block-device> <dir-path>] - - The mount command performs one of two different operations. If no - paramters are provided on the command line after the mount command, - then the 'mount' command will enumerate all of the current - mountpoints on the console. - - If the mount parameters are provied on the command after the 'mount' - command, then the 'mount' command will mount a file system in the - NuttX pseudo-file system. 'mount' performs a three way association, - binding: - - File system. The '-t <fstype>' option identifies the type of - file system that has been formatted on the <block-device>. As - of this writing, vfat is the only supported value for <fstype> - - Block Device. The <block-device> argument is the full or relative - path to a block driver inode in the pseudo filesystem. By convention, - this is a name under the /dev sub-directory. This <block-device> - must have been previously formatted with the same file system - type as specified by <fstype> - - Mount Point. The mount point is the location in the pseudo file - system where the mounted volume will appear. This mount point - can only reside in the NuttX pseudo filesystem. By convention, this - mount point is a subdirectory under /mnt. The mount command will - create whatever pseudo directories that may be needed to complete - the full path but the full path must not already exist. - - After the volume has been mounted in the NuttX pseudo file - system, it may be access in the same way as other objects in the - file system. - - Examples: - ^^^^^^^^^ - - nsh> ls -l /dev - /dev: - crw-rw-rw- 0 console - crw-rw-rw- 0 null - brw-rw-rw- 0 ram0 - nsh> ls /mnt - nsh: ls: no such directory: /mnt - nsh> mount -t vfat /dev/ram0 /mnt/fs - nsh> ls -l /mnt/fs/testdir - /mnt/fs/testdir: - -rw-rw-rw- 15 TESTFILE.TXT - nsh> echo "This is a test" >/mnt/fs/testdir/example.txt - nsh> ls -l /mnt/fs/testdir - /mnt/fs/testdir: - -rw-rw-rw- 15 TESTFILE.TXT - -rw-rw-rw- 16 EXAMPLE.TXT - nsh> cat /mnt/fs/testdir/example.txt - This is a test - nsh> - - nsh> mount - /etc type romfs - /tmp type vfat - /mnt/fs type vfat - -o mv <old-path> <new-path> - - Rename the file object at <old-path> to <new-path>. Both paths must - reside in the same mounted filesystem. - -o nfsmount <server-address> <mount-point> <remote-path> - - Mount the remote NFS server directory <remote-path> at <mount-point> on the target machine. - <server-address> is the IP address of the remote server. - -o ps - - Show the currently active threads and tasks. For example, - - nsh> ps - PID PRI SCHD TYPE NP STATE NAME - 0 0 FIFO TASK READY Idle Task() - 1 128 RR TASK RUNNING init() - 2 128 FIFO TASK WAITSEM nsh_telnetmain() - 3 100 RR PTHREAD WAITSEM <pthread>(21) - nsh> - -o ping [-c <count>] [-i <interval>] <ip-address> - - Test the network communication with a remote peer. Example, - - nsh> 10.0.0.1 - PING 10.0.0.1 56 bytes of data - 56 bytes from 10.0.0.1: icmp_seq=1 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=2 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=3 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=4 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=5 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=6 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=7 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=8 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=9 time=0 ms - 56 bytes from 10.0.0.1: icmp_seq=10 time=0 ms - 10 packets transmitted, 10 received, 0% packet loss, time 10190 ms - nsh> - -o put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path> - - Copy the file at <local-address> to the host whose IP address is - identified by <ip-address>. Other options: - - -f <remote-path> - The file will be saved with the same name on the host unless - unless <local-path> is provided. - -b|-n - Selects either binary ("octect") or test ("netascii") transfer - mode. Default: text. - -o pwd - - Show the current working directory. - - nsh> cd /dev - nsh> pwd - /dev - nsh> - - Same as 'echo $PWD' - - nsh> echo $PWD - /dev - nsh> - -o rm <file-path> - - Remove the specified <file-path> name from the mounted file system. - Recall that NuttX uses a pseudo filesystem for its root file system. - The rm command can only be used to remove (unlink) files in volumes - set up with the mount command; it cannot be used to remove names from - the pseudo filesystem. - - Example: - ^^^^^^^^ - - nsh> ls /mnt/fs/testdir - /mnt/fs/testdir: - TESTFILE.TXT - EXAMPLE.TXT - nsh> rm /mnt/fs/testdir/example.txt - nsh> ls /mnt/fs/testdir - /mnt/fs/testdir: - TESTFILE.TXT - nsh> - -o rmdir <dir-path> - - Remove the specified <dir-path> directory from the mounted file system. - Recall that NuttX uses a pseudo filesystem for its root file system. The - rmdir command can only be used to remove directories from volumes set up - with the mount command; it cannot be used to remove directories from the - pseudo filesystem. - - Example: - ^^^^^^^^ - - nsh> mkdir /mnt/fs/tmp - nsh> ls -l /mnt/fs - /mnt/fs: - drw-rw-rw- 0 TESTDIR/ - drw-rw-rw- 0 TMP/ - nsh> rmdir /mnt/fs/tmp - nsh> ls -l /mnt/fs - ls -l /mnt/fs - /mnt/fs: - drw-rw-rw- 0 TESTDIR/ - nsh> - -o set <name> <value> - - Set the environment variable <name> to the sting <value>. - For example, - - nsh> echo $foobar - - nsh> set foobar foovalue - nsh> echo $foobar - foovalue - nsh> - -o sh <script-path> - - Execute the sequence of NSH commands in the file referred - to by <script-path>. - -o sleep <sec> - - Pause execution (sleep) of <sec> seconds. - -o unset <name> - - Remove the value associated with the environment variable - <name>. Example: - - nsh> echo $foobar - foovalue - nsh> unset foobar - nsh> echo $foobar - - nsh> - - o urldecode [-f] <string or filepath> - - o urlencode [-f] <string or filepath> - -o usleep <usec> - - Pause execution (sleep) of <usec> microseconds. - -o wget [-o <local-path>] <url> - - Use HTTP to copy the file at <url> to the current directory. - Options: - - -o <local-path> - The file will be saved relative to the current working directory - and with the same name as on the HTTP server unless <local-path> - is provided. - -o xd <hex-address> <byte-count> - - Dump <byte-count> bytes of data from address <hex-address> - - Example: - ^^^^^^^^ - - nsh> xd 410e0 512 - Hex dump: - 0000: 00 00 00 00 9c 9d 03 00 00 00 00 01 11 01 10 06 ................ - 0010: 12 01 11 01 25 08 13 0b 03 08 1b 08 00 00 02 24 ....%..........$ - ... - 01f0: 08 3a 0b 3b 0b 49 13 00 00 04 13 01 01 13 03 08 .:.;.I.......... - nsh> - -NSH Configuration Settings -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The availability of the above commands depends upon features that -may or may not be enabled in the NuttX configuration file. The -following table indicates the dependency of each command on NuttX -configuration settings. General configuration settings are discussed -in the NuttX Porting Guide. Configuration settings specific to NSH -as discussed at the bottom of this README file. - -Command Dependencies on Configuration Settings -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - Command Depends on Configuration - ---------- -------------------------- - [ !CONFIG_NSH_DISABLESCRIPT - base64dec CONFIG_NETUTILS_CODECS && CONFIG_CODECS_BASE64 - base64enc CONFIG_NETUTILS_CODECS && CONFIG_CODECS_BASE64 - cat CONFIG_NFILE_DESCRIPTORS > 0 - cd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0 - cp CONFIG_NFILE_DESCRIPTORS > 0 - dd CONFIG_NFILE_DESCRIPTORS > 0 - df !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE (see note 3) - echo -- - exec -- - exit -- - free -- - get CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1) - help -- - hexdump CONFIG_NFILE_DESCRIPTORS > 0 - ifconfig CONFIG_NET - ifdown CONFIG_NET - ifup CONFIG_NET - kill !CONFIG_DISABLE_SIGNALS - losetup !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 - ls CONFIG_NFILE_DESCRIPTORS > 0 - md5 CONFIG_NETUTILS_CODECS && CONFIG_CODECS_HASH_MD5 - mb,mh,mw --- - mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) - mkfatfs !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT - mkfifo CONFIG_NFILE_DESCRIPTORS > 0 - mkrd !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) - mount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE (see note 3) - mv !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) - nfsmount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET && CONFIG_NFS - ping CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING && !CONFIG_DISABLE_CLOCK && !CONFIG_DISABLE_SIGNALS - ps -- - put CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1,2) - pwd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0 - rm !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) - rmdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) - set !CONFIG_DISABLE_ENVIRON - sh CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !CONFIG_NSH_DISABLESCRIPT - sleep !CONFIG_DISABLE_SIGNALS - test !CONFIG_NSH_DISABLESCRIPT - umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE - unset !CONFIG_DISABLE_ENVIRON - urldecode CONFIG_NETUTILS_CODECS && CONFIG_CODECS_URLCODE - urlencode CONFIG_NETUTILS_CODECS && CONFIG_CODECS_URLCODE - usleep !CONFIG_DISABLE_SIGNALS - get CONFIG_NET && CONFIG_NET_TCP && CONFIG_NFILE_DESCRIPTORS > 0 - xd --- - -* NOTES: - 1. Because of hardware padding, the actual buffersize required for put and get - operations size may be larger. - 2. Special TFTP server start-up optionss will probably be required to permit - creation of file for the correct operation of the put command. - 3. CONFIG_FS_READABLE is not a user configuration but is set automatically - if any readable filesystem is selected. At present, this is either CONFIG_FS_FAT - and CONFIG_FS_ROMFS. - 4. CONFIG_FS_WRITABLE is not a user configuration but is set automatically - if any writable filesystem is selected. At present, this is only CONFIG_FS_FAT. - -In addition, each NSH command can be individually disabled via one of the following -settings. All of these settings make the configuration of NSH potentially complex but -also allow it to squeeze into very small memory footprints. - - CONFIG_NSH_DISABLE_BASE64DEC, CONFIG_NSH_DISABLE_BASE64ENC, CONFIG_NSH_DISABLE_CAT, - CONFIG_NSH_DISABLE_CD, CONFIG_NSH_DISABLE_CP, CONFIG_NSH_DISABLE_DD, - CONFIG_NSH_DISABLE_DF, CONFIG_NSH_DISABLE_ECHO, CONFIG_NSH_DISABLE_EXEC, - CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE, CONFIG_NSH_DISABLE_GET, - CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_HEXDUMP, CONFIG_NSH_DISABLE_IFCONFIG, - CONFIG_NSH_DISABLE_IFUPDOWN, CONFIG_NSH_DISABLE_KILL, CONFIG_NSH_DISABLE_LOSETUP, - CONFIG_NSH_DISABLE_LS, CONFIG_NSH_DISABLE_MD5 CONFIG_NSH_DISABLE_MB, - CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS, CONFIG_NSH_DISABLE_MKFIFO, - CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH, CONFIG_NSH_DISABLE_MOUNT, - CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV, CONFIG_NSH_DISABLE_NFSMOUNT, - CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING, CONFIG_NSH_DISABLE_PUT, - CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR, - CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SLEEP, - CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT, CONFIG_NSH_DISABLE_UNSET, - CONFIG_NSH_DISABLE_URLDECODE, CONFIG_NSH_DISABLE_URLENCODE, CONFIG_NSH_DISABLE_USLEEP, - CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD - -Verbose help output can be suppressed by defining CONFIG_NSH_HELP_TERSE. In that -case, the help command is still available but will be slightly smaller. - -NSH-Specific Configuration Settings -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - The behavior of NSH can be modified with the following settings in - the configs/<board-name>/defconfig file: - - * CONFIG_NSH_BUILTIN_APPS - Support external registered, "builtin" applications that can be - executed from the NSH command line (see apps/README.txt for - more information). - - * CONFIG_NSH_FILEIOSIZE - Size of a static I/O buffer used for file access (ignored if - there is no filesystem). Default is 1024. - - * CONFIG_NSH_STRERROR - strerror(errno) makes more readable output but strerror() is - very large and will not be used unless this setting is 'y'. - This setting depends upon the strerror() having been enabled - with CONFIG_LIBC_STRERROR. - - * CONFIG_NSH_LINELEN - The maximum length of one command line and of one output line. - Default: 80 - - * CONFIG_NSH_NESTDEPTH - The maximum number of nested if-then[-else]-fi sequences that - are permissable. Default: 3 - - * CONFIG_NSH_DISABLESCRIPT - This can be set to 'y' to suppress support for scripting. This - setting disables the 'sh', 'test', and '[' commands and the - if-then[-else]-fi construct. This would only be set on systems - where a minimal footprint is a necessity and scripting is not. - - * CONFIG_NSH_DISABLEBG - This can be set to 'y' to suppress support for background - commands. This setting disables the 'nice' command prefix and - the '&' command suffix. This would only be set on systems - where a minimal footprint is a necessity and background command - execution is not. - - * CONFIG_NSH_MMCSDMINOR - If the architecture supports an MMC/SD slot and if the NSH - architecture specific logic is present, this option will provide - the MMC/SD minor number, i.e., the MMC/SD block driver will - be registered as /dev/mmcsdN where N is the minor number. - Default is zero. - - * CONFIG_NSH_ROMFSETC - Mount a ROMFS filesystem at /etc and provide a startup script - at /etc/init.d/rcS. The default startup script will mount - a FAT FS RAMDISK at /tmp but the logic is easily extensible. - - * CONFIG_NSH_CONSOLE - If CONFIG_NSH_CONSOLE is set to 'y', then a serial - console front-end is selected. - - Normally, the serial console device is a UART and RS-232 - interface. However, if CONFIG_USBDEV is defined, then a USB - serial device may, instead, be used if the one of - the following are defined: - - CONFIG_PL2303 and CONFIG_PL2303_CONSOLE - Sets up the - Prolifics PL2303 emulation as a console device - at /dev/console. - - CONFIG_CDCACM and CONFIG_CDCACM_CONSOLE - Sets up the - CDC/ACM serial device as a console device at - dev/console. - - CONFIG_NSH_USBCONSOLE - If defined, then the an arbitrary USB device may be used - to as the NSH console. In this case, CONFIG_NSH_USBCONDEV - must be defined to indicate which USB device to use as - the console. - - CONFIG_NSH_USBCONDEV - If CONFIG_NSH_USBCONSOLE is set to 'y', then CONFIG_NSH_USBCONDEV - must also be set to select the USB device used to support - the NSH console. This should be set to the quoted name of a - readable/write-able USB driver such as: - CONFIG_NSH_USBCONDEV="/dev/ttyACM0". - - If there are more than one USB devices, then a USB device - minor number may also need to be provided: - - CONFIG_NSH_USBDEV_MINOR - The minor device number of the USB device. Default: 0 - - CONFIG_NSH_USBDEV_TRACE - If USB tracing is enabled (CONFIG_USBDEV_TRACE), then NSH can - be configured to show the buffered USB trace data afer each - NSH command: - - If CONFIG_NSH_USBDEV_TRACE is selected, then USB trace data - can be filtered as follows. Default: Only USB errors are traced. - - CONFIG_NSH_USBDEV_TRACEINIT - Show initialization events - CONFIG_NSH_USBDEV_TRACECLASS - Show class driver events - CONFIG_NSH_USBDEV_TRACETRANSFERS - Show data transfer events - CONFIG_NSH_USBDEV_TRACECONTROLLER - Show controller events - CONFIG_NSH_USBDEV_TRACEINTERRUPTS - Show interrupt-related events. - - * CONFIG_NSH_CONDEV - If CONFIG_NSH_CONSOLE is set to 'y', then CONFIG_NSH_CONDEV - may also be set to select the serial device used to support - the NSH console. This should be set to the quoted name of a - readable/write-able character driver such as: - CONFIG_NSH_CONDEV="/dev/ttyS1". This is useful, for example, - to separate the NSH command line from the system console when - the system console is used to provide debug output. Default: - stdin and stdout (probably "/dev/console") - - NOTE: When any other device other than /dev/console is used - for a user interface, (1) linefeeds (\n) will not be expanded to - carriage return / linefeeds (\r\n). You will need to set - your terminal program to account for this. And (2) input is - not automatically echoed so you will have to turn local echo on. - - * CONFIG_NSH_TELNET - If CONFIG_NSH_TELNET is set to 'y', then a TELENET - server front-end is selected. When this option is provided, - you may log into NuttX remotely using telnet in order to - access NSH. - - * CONFIG_NSH_ARCHINIT - Set if your board provides architecture specific initialization - via the board-specific function nsh_archinitialize(). This - function will be called early in NSH initialization to allow - board logic to do such things as configure MMC/SD slots. - - If Telnet is selected for the NSH console, then we must configure - the resources used by the Telnet daemon and by the Telnet clients. - - * CONFIG_NSH_TELNETD_PORT - The telnet daemon will listen on this - TCP port number for connections. Default: 23 - - * CONFIG_NSH_TELNETD_DAEMONPRIO - Priority of the Telnet daemon. - Default: SCHED_PRIORITY_DEFAULT - - * CONFIG_NSH_TELNETD_DAEMONSTACKSIZE - Stack size allocated for the - Telnet daemon. Default: 2048 - - * CONFIG_NSH_TELNETD_CLIENTPRIO- Priority of the Telnet client. - Default: SCHED_PRIORITY_DEFAULT - - * CONFIG_NSH_TELNETD_CLIENTSTACKSIZE - Stack size allocated for the - Telnet client. Default: 2048 - - One or both of CONFIG_NSH_CONSOLE and CONFIG_NSH_TELNET - must be defined. If CONFIG_NSH_TELNET is selected, then there some - other configuration settings that apply: - - * CONFIG_NET=y - Of course, networking must be enabled - - * CONFIG_NSOCKET_DESCRIPTORS - And, of course, you must allocate some socket descriptors. - - * CONFIG_NET_TCP=y - TCP/IP support is required for telnet (as well as various other TCP-related - configuration settings). - - * CONFIG_NSH_IOBUFFER_SIZE - Determines the size of the I/O buffer to use for sending/ - receiving TELNET commands/reponses - - * CONFIG_NSH_DHCPC - Obtain the IP address via DHCP. - - * CONFIG_NSH_IPADDR - If CONFIG_NSH_DHCPC is NOT set, then the static IP - address must be provided. - - * CONFIG_NSH_DRIPADDR - Default router IP address - - * CONFIG_NSH_NETMASK - Network mask - - * CONFIG_NSH_NOMAC - Set if your ethernet hardware has no built-in MAC address. - If set, a bogus MAC will be assigned. - - * CONFIG_NSH_MAX_ROUNDTRIP - This is the maximum round trip for a response to a ICMP ECHO request. - It is in units of deciseconds. The default is 20 (2 seconds). - - If you use DHCPC, then some special configuration network options are - required. These include: - - * CONFIG_NET=y - Of course, networking must be enabled - - * CONFIG_NSOCKET_DESCRIPTORS - And, of course, you must allocate some socket descriptors. - - * CONFIG_NET_UDP=y - UDP support is required for DHCP (as well as various other UDP-related - configuration settings) - - * CONFIG_NET_BROADCAST=y - UDP broadcast support is needed. - - * CONFIG_NET_BUFSIZE=650 (or larger) - Per RFC2131 (p. 9), the DHCP client must be prepared to receive DHCP - messages of up to 576 bytes (excluding Ethernet, IP, or UDP headers and FCS). - - If CONFIG_NSH_ROMFSETC is selected, then the following additional - configuration setting apply: - - * CONFIG_NSH_ROMFSMOUNTPT - The default mountpoint for the ROMFS volume is /etc, but that - can be changed with this setting. This must be a absolute path - beginning with '/'. - - * CONFIG_NSH_INITSCRIPT - This is the relative path to the startup script within the mountpoint. - The default is init.d/rcS. This is a relative path and must not - start with '/'. - - * CONFIG_NSH_ROMFSDEVNO - This is the minor number of the ROMFS block device. The default is - '0' corresponding to /dev/ram0. - - * CONFIG_NSH_ROMFSSECTSIZE - This is the sector size to use with the ROMFS volume. Since the - default volume is very small, this defaults to 64 but should be - increased if the ROMFS volume were to be become large. Any value - selected must be a power of 2. - - When the default rcS file used when CONFIG_NSH_ROMFSETC is - selected, it will mount a FAT FS under /tmp. The following selections - describe that FAT FS. - - * CONFIG_NSH_FATDEVNO - This is the minor number of the FAT FS block device. The default is - '1' corresponding to /dev/ram1. - - * CONFIG_NSH_FATSECTSIZE - This is the sector size use with the FAT FS. Default is 512. - - * CONFIG_NSH_FATNSECTORS - This is the number of sectors to use with the FAT FS. Defalt is - 1024. The amount of memory used by the FAT FS will be - CONFIG_NSH_FATSECTSIZE * CONFIG_NSH_FATNSECTORS - bytes. - - * CONFIG_NSH_FATMOUNTPT - This is the location where the FAT FS will be mounted. Default - is /tmp. - -Common Problems -^^^^^^^^^^^^^^^ - - Problem: - Using NSH over serial, the "nsh>" prompt repeats over and over again - with no serial input. - Usual Cause: - NSH over serial needs to use the interrupt driven serial driver - (drivers/serial/serial.c) not the polled serial driver (drivers/serial/lowconsole.c). - Make sure that the polled console is disabled in the OS configuration - file, .config. That file should have CONFIG_DEV_LOWCONSOLE=n for - NSH over serial. - - Problem: - The function 'readline' is undefined. - Usual Cause: - The following is missing from your appconfig file: - - CONFIGURED_APPS += system/readline - diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h deleted file mode 100644 index 83cf25aa7..000000000 --- a/apps/nshlib/nsh.h +++ /dev/null @@ -1,757 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh.h - * - * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_NSHLIB_NSH_H -#define __APPS_NSHLIB_NSH_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> - -#include <stdio.h> -#include <stdint.h> -#include <stdbool.h> -#include <unistd.h> -#include <errno.h> - -#include <nuttx/usb/usbdev_trace.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* The background commands require pthread support */ - -#ifdef CONFIG_DISABLE_PTHREAD -# ifndef CONFIG_NSH_DISABLEBG -# define CONFIG_NSH_DISABLEBG 1 -# endif -#endif - -/* Telnetd requires networking support */ - -#ifndef CONFIG_NET -# undef CONFIG_NSH_TELNET -#endif - -/* One front end must be defined */ - -#if !defined(CONFIG_NSH_CONSOLE) && !defined(CONFIG_NSH_TELNET) -# error "No NSH front end defined" -#endif - -/* If a USB device is selected for the NSH console then we need to handle some - * special start-up conditions. - */ - -#undef HAVE_USB_CONSOLE -#if defined(CONFIG_USBDEV) - -/* Check for a PL2303 serial console. Use console device "/dev/console". */ - -# if defined(CONFIG_PL2303) && defined(CONFIG_PL2303_CONSOLE) -# define HAVE_USB_CONSOLE 1 - -/* Check for a CDC/ACM serial console. Use console device "/dev/console". */ - -# elif defined(CONFIG_CDCACM) && defined(CONFIG_CDCACM_CONSOLE) -# define HAVE_USB_CONSOLE 1 - -/* Check for a generic USB console. In this case, the USB console device - * must be provided in CONFIG_NSH_CONDEV. - */ - -# elif defined(CONFIG_NSH_USBCONSOLE) -# define HAVE_USB_CONSOLE 1 -# endif -#endif - -/* Defaults for the USB console */ - -#ifdef HAVE_USB_CONSOLE - -/* The default USB console device minor number is 0*/ - -# ifndef CONFIG_NSH_USBDEV_MINOR -# define CONFIG_NSH_USBDEV_MINOR 0 -# endif - -/* The default console device is always /dev/console */ - -# ifndef CONFIG_NSH_USBCONDEV -# define CONFIG_NSH_USBCONDEV "/dev/console" -# endif - -/* USB trace settings */ - -# ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_NSH_USBDEV_TRACE -# endif - -# ifdef CONFIG_NSH_USBDEV_TRACE -# ifdef CONFIG_NSH_USBDEV_TRACEINIT -# define TRACE_INIT_BITS (TRACE_INIT_BIT) -# else -# define TRACE_INIT_BITS (0) -# endif - -# define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) - -# ifdef CONFIG_NSH_USBDEV_TRACECLASS -# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|\ - TRACE_CLASSSTATE_BIT) -# else -# define TRACE_CLASS_BITS (0) -# endif - -# ifdef CONFIG_NSH_USBDEV_TRACETRANSFERS -# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|\ - TRACE_READ_BIT|TRACE_WRITE_BIT|\ - TRACE_COMPLETE_BIT) -# else -# define TRACE_TRANSFER_BITS (0) -# endif - -# ifdef CONFIG_NSH_USBDEV_TRACECONTROLLER -# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) -# else -# define TRACE_CONTROLLER_BITS (0) -# endif - -# ifdef CONFIG_NSH_USBDEV_TRACEINTERRUPTS -# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|\ - TRACE_INTEXIT_BIT) -# else -# define TRACE_INTERRUPT_BITS (0) -# endif - -# define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|\ - TRACE_CLASS_BITS|TRACE_TRANSFER_BITS|\ - TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) - -# endif /* CONFIG_NSH_USBDEV_TRACE */ -#endif /* HAVE_USB_CONSOLE */ - -/* If Telnet is selected for the NSH console, then we must configure - * the resources used by the Telnet daemon and by the Telnet clients. - * - * CONFIG_NSH_TELNETD_PORT - The telnet daemon will listen on this. - * port. Default: 23 - * CONFIG_NSH_TELNETD_DAEMONPRIO - Priority of the Telnet daemon. - * Default: SCHED_PRIORITY_DEFAULT - * CONFIG_NSH_TELNETD_DAEMONSTACKSIZE - Stack size allocated for the - * Telnet daemon. Default: 2048 - * CONFIG_NSH_TELNETD_CLIENTPRIO - Priority of the Telnet client. - * Default: SCHED_PRIORITY_DEFAULT - * CONFIG_NSH_TELNETD_CLIENTSTACKSIZE - Stack size allocated for the - * Telnet client. Default: 2048 - * CONFIG_NSH_TELNET_LOGIN - Support a simple Telnet login. - * - * If CONFIG_NSH_TELNET_LOGIN is defined, then these additional - * options may be specified: - * - * CONFIG_NSH_TELNET_USERNAME - Login user name. Default: "admin" - * CONFIG_NSH_TELNET_PASSWORD - Login password: Default: "nuttx" - * CONFIG_NSH_TELNET_FAILCOUNT - Number of login retry attempts. - * Default 3. - */ - -#ifndef CONFIG_NSH_TELNETD_PORT -# define CONFIG_NSH_TELNETD_PORT 23 -#endif - -#ifndef CONFIG_NSH_TELNETD_DAEMONPRIO -# define CONFIG_NSH_TELNETD_DAEMONPRIO SCHED_PRIORITY_DEFAULT -#endif - -#ifndef CONFIG_NSH_TELNETD_DAEMONSTACKSIZE -# define CONFIG_NSH_TELNETD_DAEMONSTACKSIZE 2048 -#endif - -#ifndef CONFIG_NSH_TELNETD_CLIENTPRIO -# define CONFIG_NSH_TELNETD_CLIENTPRIO SCHED_PRIORITY_DEFAULT -#endif - -#ifndef CONFIG_NSH_TELNETD_CLIENTSTACKSIZE -# define CONFIG_NSH_TELNETD_CLIENTSTACKSIZE 2048 -#endif - -#ifdef CONFIG_NSH_TELNET_LOGIN - -# ifndef CONFIG_NSH_TELNET_USERNAME -# define CONFIG_NSH_TELNET_USERNAME "admin" -# endif - -# ifndef CONFIG_NSH_TELNET_PASSWORD -# define CONFIG_NSH_TELNET_PASSWORD "nuttx" -# endif - -# ifndef CONFIG_NSH_TELNET_FAILCOUNT -# define CONFIG_NSH_TELNET_FAILCOUNT 3 -# endif - -#endif /* CONFIG_NSH_TELNET_LOGIN */ - -/* CONFIG_NSH_MAX_ROUNDTRIP - This is the maximum round trip for a response to - * a ICMP ECHO request. It is in units of deciseconds. The default is 20 - * (2 seconds). - */ - -#ifndef CONFIG_NSH_MAX_ROUNDTRIP -# define CONFIG_NSH_MAX_ROUNDTRIP 20 -#endif - -/* Verify support for ROMFS /etc directory support options */ - -#ifdef CONFIG_NSH_ROMFSETC -# ifdef CONFIG_DISABLE_MOUNTPOINT -# error "Mountpoint support is disabled" -# undef CONFIG_NSH_ROMFSETC -# endif - -# if CONFIG_NFILE_DESCRIPTORS < 4 -# error "Not enough file descriptors" -# undef CONFIG_NSH_ROMFSETC -# endif - -# ifndef CONFIG_FS_ROMFS -# error "ROMFS support not enabled" -# undef CONFIG_NSH_ROMFSETC -# endif - -# ifndef CONFIG_NSH_ROMFSMOUNTPT -# define CONFIG_NSH_ROMFSMOUNTPT "/etc" -# endif - -# ifndef CONFIG_NSH_INITSCRIPT -# define CONFIG_NSH_INITSCRIPT "init.d/rcS" -# endif - -# undef NSH_INITPATH -# define NSH_INITPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_INITSCRIPT - -# ifdef CONFIG_NSH_ROMFSRC -# ifndef CONFIG_NSH_RCSCRIPT -# define CONFIG_NSH_RCSCRIPT ".nshrc" -# endif - -# undef NSH_RCPATH -# define NSH_RCPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_RCSCRIPT -# endif - -# ifndef CONFIG_NSH_ROMFSDEVNO -# define CONFIG_NSH_ROMFSDEVNO 0 -# endif - -# ifndef CONFIG_NSH_ROMFSSECTSIZE -# define CONFIG_NSH_ROMFSSECTSIZE 64 -# endif - -# define NSECTORS(b) (((b)+CONFIG_NSH_ROMFSSECTSIZE-1)/CONFIG_NSH_ROMFSSECTSIZE) -# define STR_RAMDEVNO(m) #m -# define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m) -# define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_NSH_ROMFSDEVNO) - -#else - -# undef CONFIG_NSH_ROMFSRC -# undef CONFIG_NSH_ROMFSMOUNTPT -# undef CONFIG_NSH_INITSCRIPT -# undef CONFIG_NSH_RCSCRIPT -# undef CONFIG_NSH_ROMFSDEVNO -# undef CONFIG_NSH_ROMFSSECTSIZE - -#endif - -/* This is the maximum number of arguments that will be accepted for a - * command. Here we attempt to select the smallest number possible depending - * upon the of commands that are available. Most commands use six or fewer - * arguments, but there are a few that require more. - * - * This value is also configurable with CONFIG_NSH_MAXARGUMENTS. This - * configurability is necessary since there may also be external, "built-in" - * commands that require more commands than NSH is aware of. - */ - -#ifndef CONFIG_NSH_MAXARGUMENTS -# define CONFIG_NSH_MAXARGUMENTS 6 -#endif - -#if CONFIG_NSH_MAXARGUMENTS < 11 -# if defined(CONFIG_NET) && !defined(CONFIG_NSH_DISABLE_IFCONFIG) -# undef CONFIG_NSH_MAXARGUMENTS -# define CONFIG_NSH_MAXARGUMENTS 11 -# endif -#endif - -#if CONFIG_NSH_MAXARGUMENTS < 7 -# if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -# if !defined(CONFIG_NSH_DISABLE_GET) || !defined(CONFIG_NSH_DISABLE_PUT) -# undef CONFIG_NSH_MAXARGUMENTS -# define CONFIG_NSH_MAXARGUMENTS 7 -# endif -# endif -#endif - -/* strerror() produces much nicer output but is, however, quite large and - * will only be used if CONFIG_NSH_STRERROR is defined. Note that the strerror - * interface must also have been enabled with CONFIG_LIBC_STRERROR. - */ - -#ifndef CONFIG_LIBC_STRERROR -# undef CONFIG_NSH_STRERROR -#endif - -#ifdef CONFIG_NSH_STRERROR -# define NSH_ERRNO strerror(errno) -# define NSH_ERRNO_OF(err) strerror(err) -#else -# define NSH_ERRNO (errno) -# define NSH_ERRNO_OF(err) (err) -#endif - -/* Maximum size of one command line (telnet or serial) */ - -#ifndef CONFIG_NSH_LINELEN -# define CONFIG_NSH_LINELEN 80 -#endif - -/* The following two settings are used only in the telnetd interface */ - -#ifndef CONFIG_NSH_IOBUFFER_SIZE -# define CONFIG_NSH_IOBUFFER_SIZE 512 -#endif - -/* The maximum number of nested if-then[-else]-fi sequences that - * are permissable. - */ - -#ifndef CONFIG_NSH_NESTDEPTH -# define CONFIG_NSH_NESTDEPTH 3 -#endif - -/* Define to enable dumping of all input/output buffers */ - -#undef CONFIG_NSH_TELNETD_DUMPBUFFER -#undef CONFIG_NSH_FULLPATH - -/* Make sure that the home directory is defined */ - -#ifndef CONFIG_LIB_HOMEDIR -# define CONFIG_LIB_HOMEDIR "/" -#endif - -/* Stubs used when working directory is not supported */ - -#if CONFIG_NFILE_DESCRIPTORS <= 0 || defined(CONFIG_DISABLE_ENVIRON) -# define nsh_getfullpath(v,p) ((char*)(p)) -# define nsh_freefullpath(p) -#endif - -/* The size of the I/O buffer may be specified in the - * configs/<board-name>defconfig file -- provided that it is at least as - * large as PATH_MAX. - */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# ifdef CONFIG_NSH_FILEIOSIZE -# if CONFIG_NSH_FILEIOSIZE > (PATH_MAX + 1) -# define IOBUFFERSIZE CONFIG_NSH_FILEIOSIZE -# else -# define IOBUFFERSIZE (PATH_MAX + 1) -# endif -# else -# define IOBUFFERSIZE 1024 -# endif -# else -# define IOBUFFERSIZE (PATH_MAX + 1) -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -enum nsh_parser_e -{ - NSH_PARSER_NORMAL = 0, - NSH_PARSER_IF, - NSH_PARSER_THEN, - NSH_PARSER_ELSE -}; - -struct nsh_state_s -{ - uint8_t ns_ifcond : 1; /* Value of command in 'if' statement */ - uint8_t ns_disabled : 1; /* TRUE: Unconditionally disabled */ - uint8_t ns_unused : 4; - uint8_t ns_state : 2; /* Parser state (see enum nsh_parser_e) */ -}; - -struct nsh_parser_s -{ -#ifndef CONFIG_NSH_DISABLEBG - bool np_bg; /* true: The last command executed in background */ -#endif - bool np_redirect; /* true: Output from the last command was re-directed */ - bool np_fail; /* true: The last command failed */ -#ifndef CONFIG_NSH_DISABLESCRIPT - uint8_t np_ndx; /* Current index into np_st[] */ -#endif -#ifndef CONFIG_NSH_DISABLEBG - int np_nice; /* "nice" value applied to last background cmd */ -#endif - - /* This is a stack of parser state information. It supports nested - * execution of commands that span multiple lines (like if-then-else-fi) - */ - -#ifndef CONFIG_NSH_DISABLESCRIPT - struct nsh_state_s np_st[CONFIG_NSH_NESTDEPTH]; -#endif -}; - -struct nsh_vtbl_s; /* Defined in nsh_console.h */ -typedef int (*cmd_t)(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern const char g_nshgreeting[]; -#if defined(CONFIG_NSH_TELNET_LOGIN) && defined(CONFIG_NSH_TELNET) -extern const char g_telnetgreeting[]; -extern const char g_userprompt[]; -extern const char g_passwordprompt[]; -extern const char g_loginsuccess[]; -extern const char g_badcredentials[]; -extern const char g_loginfailure[]; -#endif -extern const char g_nshprompt[]; -extern const char g_nshsyntax[]; -extern const char g_fmtargrequired[]; -extern const char g_fmtarginvalid[]; -extern const char g_fmtargrange[]; -extern const char g_fmtcmdnotfound[]; -extern const char g_fmtnosuch[]; -extern const char g_fmttoomanyargs[]; -extern const char g_fmtdeepnesting[]; -extern const char g_fmtcontext[]; -extern const char g_fmtcmdfailed[]; -extern const char g_fmtcmdoutofmemory[]; -extern const char g_fmtinternalerror[]; -#ifndef CONFIG_DISABLE_SIGNALS -extern const char g_fmtsignalrecvd[]; -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Initialization */ - -#ifdef CONFIG_NSH_ROMFSETC -int nsh_romfsetc(void); -#else -# define nsh_romfsetc() (-ENOSYS) -#endif - -#ifdef CONFIG_NET -int nsh_netinit(void); -#else -# define nsh_netinit() (-ENOSYS) -#endif - -#ifdef HAVE_USB_CONSOLE -int nsh_usbconsole(void); -#else -# define nsh_usbconsole() (-ENOSYS) -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT) -int nsh_script(FAR struct nsh_vtbl_s *vtbl, const char *cmd, const char *path); -#ifdef CONFIG_NSH_ROMFSETC -int nsh_initscript(FAR struct nsh_vtbl_s *vtbl); -#ifdef CONFIG_NSH_ROMFSRC -int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl); -#endif -#endif -#endif - -/* Architecture-specific initialization */ - -#ifdef CONFIG_NSH_ARCHINIT -int nsh_archinitialize(void); -#else -# define nsh_archinitialize() (-ENOSYS) -#endif - -/* Basic session and message handling */ - -struct console_stdio_s; -int nsh_session(FAR struct console_stdio_s *pstate); -int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline); - -/* Application interface */ - -#ifdef CONFIG_NSH_BUILTIN_APPS -int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, - FAR char **argv, FAR const char *redirfile, int oflags); -#endif - -#ifdef CONFIG_NSH_FILE_APPS -int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, - FAR char **argv, FAR const char *redirfile, int oflags); -#endif - -/* Working directory support */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -FAR const char *nsh_getcwd(void); -char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl, const char *relpath); -void nsh_freefullpath(char *relpath); -#endif - -/* Debug */ - -void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, - const uint8_t *buffer, ssize_t nbytes); - -/* USB debug support */ - -#ifdef CONFIG_NSH_USBDEV_TRACE -void nsh_usbtrace(void); -#endif - -/* Shell command handlers */ - -#ifndef CONFIG_NSH_DISABLE_ECHO - int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -#ifndef CONFIG_NSH_DISABLE_EXEC - int cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -#ifndef CONFIG_NSH_DISABLE_MB - int cmd_mb(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -#ifndef CONFIG_NSH_DISABLE_MH - int cmd_mh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -#ifndef CONFIG_NSH_DISABLE_MW - int cmd_mw(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -#ifndef CONFIG_NSH_DISABLE_FREE - int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -#ifndef CONFIG_NSH_DISABLE_PS - int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -#ifndef CONFIG_NSH_DISABLE_XD - int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif - -#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST) - int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); - int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif - -#ifndef CONFIG_DISABLE_CLOCK -# if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) - int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_CAT - int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_CP - int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_CMP - int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_DD - int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_HEXDUMP - int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_LS - int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# if defined(CONFIG_SYSLOG) && defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG) - int cmd_dmesg(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT) -# ifndef CONFIG_NSH_DISABLE_SH - int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# endif /* CONFIG_NFILE_STREAMS && !CONFIG_NSH_DISABLESCRIPT */ -# ifndef CONFIG_DISABLE_MOUNTPOINT -# ifndef CONFIG_NSH_DISABLE_LOSETUP - int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_MKFIFO - int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifdef CONFIG_FS_READABLE -# ifndef CONFIG_NSH_DISABLE_DF - int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_MOUNT - int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_UMOUNT - int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifdef CONFIG_FS_WRITABLE -# ifndef CONFIG_NSH_DISABLE_MKDIR - int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_MKRD - int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_MV - int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_RM - int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_RMDIR - int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# endif /* CONFIG_FS_WRITABLE */ -# endif /* CONFIG_FS_READABLE */ -# ifdef CONFIG_FS_FAT -# ifndef CONFIG_NSH_DISABLE_MKFATFS - int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# endif /* CONFIG_FS_FAT */ -# endif /* !CONFIG_DISABLE_MOUNTPOINT */ -# if !defined(CONFIG_DISABLE_ENVIRON) -# ifndef CONFIG_NSH_DISABLE_CD - int cmd_cd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_PWD - int cmd_pwd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# endif /* !CONFIG_DISABLE_MOUNTPOINT */ -#endif /* CONFIG_NFILE_DESCRIPTORS */ - -#if defined(CONFIG_NET) -# ifndef CONFIG_NSH_DISABLE_IFCONFIG - int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_IFUPDOWN - int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); - int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_GET - int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_PUT - int cmd_put(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif -#if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_WGET - int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif -#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ - !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) -# ifndef CONFIG_NSH_DISABLE_PING - int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ - defined(CONFIG_FS_READABLE) && defined(CONFIG_NFS) -# ifndef CONFIG_NSH_DISABLE_NFSMOUNT - int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif -#endif - -#ifndef CONFIG_DISABLE_ENVIRON -# ifndef CONFIG_NSH_DISABLE_SET - int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_UNSET - int cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif /* CONFIG_DISABLE_ENVIRON */ - -#ifndef CONFIG_DISABLE_SIGNALS -# ifndef CONFIG_NSH_DISABLE_KILL - int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_SLEEP - int cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_USLEEP - int cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif /* CONFIG_DISABLE_SIGNALS */ - -#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64) -# ifndef CONFIG_NSH_DISABLE_BASE64DEC - int cmd_base64decode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_BASE64ENC - int cmd_base64encode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif - -#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5) -# ifndef CONFIG_NSH_DISABLE_MD5 - int cmd_md5(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif - -#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE) -# ifndef CONFIG_NSH_DISABLE_URLDECODE - int cmd_urlencode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_URLENCODE - int cmd_urldecode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -#endif - -#endif /* __APPS_NSHLIB_NSH_H */ diff --git a/apps/nshlib/nsh_builtin.c b/apps/nshlib/nsh_builtin.c deleted file mode 100644 index 0d5a0231c..000000000 --- a/apps/nshlib/nsh_builtin.c +++ /dev/null @@ -1,262 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_builtin.c - * - * Originally by: - * - * Copyright (C) 2011 Uros Platise. All rights reserved. - * Author: Uros Platise <uros.platise@isotel.eu> - * - * With subsequent updates, modifications, and general maintenance by: - * - * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#ifdef CONFIG_SCHED_WAITPID -# include <sys/wait.h> -#endif - -#include <stdbool.h> -#include <errno.h> -#include <string.h> - -#include <nuttx/binfmt/builtin.h> -#include <apps/builtin.h> - -#include "nsh.h" -#include "nsh_console.h" - -#ifdef CONFIG_NSH_BUILTIN_APPS - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_builtin - * - * Description: - * Attempt to execute the application task whose name is 'cmd' - * - * Returned Value: - * <0 If exec_builtin() fails, then the negated errno value - * is returned. - * -1 (ERROR) if the application task corresponding to 'cmd' could not - * be started (possibly because it doesn not exist). - * 0 (OK) if the application task corresponding to 'cmd' was - * and successfully started. If CONFIG_SCHED_WAITPID is - * defined, this return value also indicates that the - * application returned successful status (EXIT_SUCCESS) - * 1 If CONFIG_SCHED_WAITPID is defined, then this return value - * indicates that the application task was spawned successfully - * but returned failure exit status. - * - ****************************************************************************/ - -int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, - FAR char **argv, FAR const char *redirfile, int oflags) -{ - int ret = OK; - - /* Lock the scheduler in an attempt to prevent the application from - * running until waitpid() has been called. - */ - - sched_lock(); - - /* Try to find and execute the command within the list of builtin - * applications. - */ - - ret = exec_builtin(cmd, (FAR const char **)argv, redirfile, oflags); - if (ret >= 0) - { - /* The application was successfully started with pre-emption disabled. - * In the simplest cases, the application will not have run because the - * the scheduler is locked. But in the case where I/O was redirected, a - * proxy task ran and broke our lock. As result, the application may - * have aso ran if its priority was higher than than the priority of - * this thread. - * - * If the application did not run to completion and if the application - * was not backgrounded, then we need to wait here for the application - * to exit. This only works works with the following options: - * - * - CONFIG_NSH_DISABLEBG - Do not run commands in background - * - CONFIG_SCHED_WAITPID - Required to run external commands in - * foreground - */ - -#ifdef CONFIG_SCHED_WAITPID - - /* CONFIG_SCHED_WAITPID is selected, so we may run the command in - * foreground unless we were specifically requested to run the command - * in background (and running commands in background is enabled). - */ - -# ifndef CONFIG_NSH_DISABLEBG - if (vtbl->np.np_bg == false) -# endif /* CONFIG_NSH_DISABLEBG */ - { - int rc = 0; - - /* Wait for the application to exit. We did lock the scheduler - * above, but that does not guarantee that the application did not - * already run to completion in the case where I/O was redirected. - * Here the scheduler will be unlocked while waitpid is waiting - * and if the application has not yet run, it will now be able to - * do so. - * - * Also, if CONFIG_SCHED_HAVE_PARENT is defined waitpid() might fail - * even if task is still active: If the I/O was re-directed by a - * proxy task, then the ask is a child of the proxy, and not this - * task. waitpid() fails with ECHILD in either case. - */ - - ret = waitpid(ret, &rc, 0); - if (ret < 0) - { - /* If the child thread does not exist, waitpid() will return - * the error ECHLD. Since we know that the task was successfully - * started, this must be one of the cases described above; we - * have to assume that the task already exit'ed. In this case, - * we have no idea if the application ran successfully or not - * (because NuttX does not retain exit status of child tasks). - * Let's assume that is did run successfully. - */ - - int errcode = errno; - if (errcode == ECHILD) - { - ret = OK; - } - else - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "waitpid", - NSH_ERRNO_OF(errcode)); - } - } - - /* Waitpid completed the wait successfully */ - - else - { - /* We can't return the exact status (nsh has nowhere to put it) - * so just pass back zero/nonzero in a fashion that doesn't look - * like an error. - */ - - ret = (rc == 0) ? OK : 1; - - /* TODO: Set the environment variable '?' to a string corresponding - * to WEXITSTATUS(rc) so that $? will expand to the exit status of - * the most recently executed task. - */ - } - } -# ifndef CONFIG_NSH_DISABLEBG - else -# endif /* CONFIG_NSH_DISABLEBG */ -#endif /* CONFIG_SCHED_WAITPID */ - - /* We get here if either: - * - * - CONFIG_SCHED_WAITPID is not selected meaning that all commands - * have to be run in background, or - * - CONFIG_SCHED_WAITPID and CONFIG_NSH_DISABLEBG are both selected, but the - * user requested to run the command in background. - * - * NOTE that the case of a) CONFIG_SCHED_WAITPID is not selected and - * b) CONFIG_NSH_DISABLEBG selected cannot be supported. In that event, all - * commands will have to run in background. The waitpid() API must be - * available to support running the command in foreground. - */ - -#if !defined(CONFIG_SCHED_WAITPID) || !defined(CONFIG_NSH_DISABLEBG) - { - struct sched_param param; - sched_getparam(ret, ¶m); - nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority); - - /* Backgrounded commands always 'succeed' as long as we can start - * them. - */ - - ret = OK; - } -#endif /* !CONFIG_SCHED_WAITPID || !CONFIG_NSH_DISABLEBG */ - } - - sched_unlock(); - - /* If exec_builtin() or waitpid() failed, then return -1 (ERROR) with the - * errno value set appropriately. - */ - - if (ret < 0) - { - return ERROR; - } - - return ret; -} - -#endif /* CONFIG_NSH_BUILTIN_APPS */ diff --git a/apps/nshlib/nsh_codeccmd.c b/apps/nshlib/nsh_codeccmd.c deleted file mode 100644 index 779fc5ecd..000000000 --- a/apps/nshlib/nsh_codeccmd.c +++ /dev/null @@ -1,538 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_codeccmd.c - * - * This file is part of NuttX, contributed by Darcy Gong - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Darcy Gong 2012-10-30 - * - * 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> -#ifdef CONFIG_NETUTILS_CODECS - -#include <sys/stat.h> -#include <stdint.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <sched.h> -#include <fcntl.h> -#include <libgen.h> -#include <errno.h> -#include <debug.h> - -#if defined(CONFIG_NSH_DISABLE_URLENCODE) && defined(CONFIG_NSH_DISABLE_URLDECODE) -# undef CONFIG_CODECS_URLCODE -#endif - -#ifdef CONFIG_CODECS_URLCODE -#include <apps/netutils/urldecode.h> -#endif - -#if defined(CONFIG_NSH_DISABLE_BASE64ENC) && defined(CONFIG_NSH_DISABLE_BASE64ENC) -# undef CONFIG_CODECS_BASE64 -#endif - -#ifdef CONFIG_CODECS_BASE64 -#include <apps/netutils/base64.h> -#endif - -#if defined(CONFIG_CODECS_HASH_MD5) && !defined(CONFIG_NSH_DISABLE_MD5) -#include <apps/netutils/md5.h> -#endif - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_NSH_CODECS_BUFSIZE -# define CONFIG_NSH_CODECS_BUFSIZE 128 -#endif - -#define CODEC_MODE_URLENCODE 1 -#define CODEC_MODE_URLDECODE 2 -#define CODEC_MODE_BASE64ENC 3 -#define CODEC_MODE_BASE64DEC 4 -#define CODEC_MODE_HASH_MD5 5 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef void (*codec_callback_t)(FAR char *src_buff, int src_buff_len, - FAR char *dst_buff, FAR int *dst_buff_len, - int mode); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: urlencode_cb - ****************************************************************************/ - -#if defined(CONFIG_CODECS_URLCODE) && !defined(CONFIG_NSH_DISABLE_URLENCODE) -static void urlencode_cb(FAR char *src_buff, int src_buff_len, - FAR char *dst_buff, FAR int *dst_buff_len, int mode) -{ - urlencode(src_buff,src_buff_len,dst_buff,dst_buff_len); -} -#endif - -/**************************************************************************** - * Name: urldecode_cb - ****************************************************************************/ - -#if defined(CONFIG_CODECS_URLCODE) && !defined(CONFIG_NSH_DISABLE_URLDECODE) -static void urldecode_cb(FAR char *src_buff, int src_buff_len, FAR char *dst_buff, - FAR int *dst_buff_len, int mode) -{ - urldecode(src_buff,src_buff_len,dst_buff,dst_buff_len); -} -#endif - -/**************************************************************************** - * Name: b64enc_cb - ****************************************************************************/ - -#if defined(CONFIG_CODECS_BASE64) && !defined(CONFIG_NSH_DISABLE_BASE64ENC) -static void b64enc_cb(FAR char *src_buff, int src_buff_len, FAR char *dst_buff, - FAR int *dst_buff_len, int mode) -{ - if (mode == 0) - { - //dst_buff = - base64_encode((unsigned char *)src_buff, src_buff_len, - (unsigned char *)dst_buff, (size_t *)dst_buff_len); - } - else - { - //dst_buff = - base64w_encode((unsigned char *)src_buff, src_buff_len, - (unsigned char *)dst_buff, (size_t *)dst_buff_len); - } -} -#endif - -/**************************************************************************** - * Name: b64dec_cb - ****************************************************************************/ - -#if defined(CONFIG_CODECS_BASE64) && !defined(CONFIG_NSH_DISABLE_BASE64DEC) -static void b64dec_cb(FAR char *src_buff, int src_buff_len, FAR char *dst_buff, - FAR int *dst_buff_len, int mode) -{ - if (mode == 0) - { - //dst_buff = - base64_decode((unsigned char *)src_buff, src_buff_len, - (unsigned char *)dst_buff, (size_t *)dst_buff_len); - } - else - { - //dst_buff = - base64w_decode((unsigned char *)src_buff, src_buff_len, - (unsigned char *)dst_buff,(size_t *)dst_buff_len); - } -} -#endif - -/**************************************************************************** - * Name: md5_cb - ****************************************************************************/ - -#if defined(CONFIG_CODECS_HASH_MD5) && !defined(CONFIG_NSH_DISABLE_MD5) -static void md5_cb(FAR char *src_buff, int src_buff_len, FAR char *dst_buff, - FAR int *dst_buff_len, int mode) -{ - MD5Update((MD5_CTX *)dst_buff, (unsigned char *)src_buff, src_buff_len); -} -#endif - -/**************************************************************************** - * Name: calc_codec_buffsize - ****************************************************************************/ - -static int calc_codec_buffsize(int src_buffsize, uint8_t mode) -{ - switch (mode) - { - case CODEC_MODE_URLENCODE: - return src_buffsize*3+1; - case CODEC_MODE_URLDECODE: - return src_buffsize+1; - case CODEC_MODE_BASE64ENC: - return ((src_buffsize + 2)/ 3 * 4)+1; - case CODEC_MODE_BASE64DEC: - return (src_buffsize / 4 * 3 + 2)+1; - case CODEC_MODE_HASH_MD5: - return 32+1; - default: - return src_buffsize+1; - } -} - -/**************************************************************************** - * Name: cmd_codecs_proc - ****************************************************************************/ - -static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv, - uint8_t mode, codec_callback_t func) -{ -#if defined(CONFIG_CODECS_HASH_MD5) && !defined(CONFIG_NSH_DISABLE_MD5) - static const unsigned char hex_chars[] = "0123456789abcdef"; - MD5_CTX ctx; - unsigned char mac[16]; - char *pSrc; - char *pDest; -#endif - - char *localfile = NULL; - char *src_buffer = NULL; - char *buffer = NULL; - char *fullpath = NULL; - const char *fmt; - char *s_data; - bool badarg = false; - bool is_file = false; - bool is_websafe=false; - int option; - int fd = -1; - int buff_len = 0; - int src_buff_len = 0; - int i = 0; - int ret = OK; - - /* Get the command options */ - - while ((option = getopt(argc, argv, ":fw")) != ERROR) - { - switch (option) - { - case 'f': - is_file = true; - break; - -#ifdef CONFIG_CODECS_BASE64 - case 'w': - is_websafe = true; - - if (!(mode == CODEC_MODE_BASE64ENC || mode == CODEC_MODE_BASE64DEC)) - { - badarg = true; - } - break; -#endif - case ':': - nsh_output(vtbl, g_fmtargrequired, argv[0]); - badarg = true; - break; - - case '?': - default: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - break; - } - } - - /* If a bad argument was encountered, then return without processing the command */ - - if (badarg) - { - return ERROR; - } - - /* There should be exactly on parameter left on the command-line */ - - if (optind == argc-1) - { - s_data = argv[optind]; - } - else if (optind >= argc) - { - fmt = g_fmttoomanyargs; - goto errout; - } - else - { - fmt = g_fmtargrequired; - goto errout; - } - -#if defined(CONFIG_CODECS_HASH_MD5) && !defined(CONFIG_NSH_DISABLE_MD5) - if (mode == CODEC_MODE_HASH_MD5) - { - MD5Init(&ctx); - } -#endif - - if (is_file) - { - /* Get the local file name */ - - localfile = s_data; - - /* Get the full path to the local file */ - - fullpath = nsh_getfullpath(vtbl, localfile); - - /* Open the local file for writing */ - - fd = open(fullpath, O_RDONLY|O_TRUNC, 0644); - if (fd < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO); - ret = ERROR; - goto exit; - } - - src_buffer = malloc(CONFIG_NSH_CODECS_BUFSIZE+2); -#if defined(CONFIG_CODECS_BASE64) && !defined(CONFIG_NSH_DISABLE_BASE64ENC) - if (mode == CODEC_MODE_BASE64ENC) - { - src_buff_len = CONFIG_NSH_CODECS_BUFSIZE / 3 * 3; - } - else -#endif - { - src_buff_len = CONFIG_NSH_CODECS_BUFSIZE; - } - - buff_len = calc_codec_buffsize(src_buff_len+2, mode); - buffer = malloc(buff_len); - while(true) - { - memset(src_buffer, 0, src_buff_len+2); - ret=read(fd, src_buffer, src_buff_len); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO); - ret = ERROR; - goto exit; - } - else if(ret==0) - { - break; - } - -#if defined(CONFIG_CODECS_URLCODE) && !defined(CONFIG_NSH_DISABLE_URLDECODE) - if (mode == CODEC_MODE_URLDECODE) - { - if (src_buffer[src_buff_len-1]=='%') - { - ret += read(fd,&src_buffer[src_buff_len],2); - } - else if (src_buffer[src_buff_len-2]=='%') - { - ret += read(fd,&src_buffer[src_buff_len],1); - } - } -#endif - memset(buffer, 0, buff_len); - if (func) - { -#if defined(CONFIG_CODECS_HASH_MD5) && !defined(CONFIG_NSH_DISABLE_MD5) - if (mode == CODEC_MODE_HASH_MD5) - { - func(src_buffer, ret, (char *)&ctx, &buff_len,0); - } - else -#endif - { - func(src_buffer, ret, buffer, &buff_len,(is_websafe)?1:0); - nsh_output(vtbl, "%s", buffer); - } - } - - buff_len = calc_codec_buffsize(src_buff_len+2, mode); - } - -#if defined(CONFIG_CODECS_HASH_MD5) && !defined(CONFIG_NSH_DISABLE_MD5) - if (mode == CODEC_MODE_HASH_MD5) - { - MD5Final(mac, &ctx); - pSrc = (char *)&mac; - pDest = buffer; - for(i=0;i<16;i++,pSrc++) - { - *pDest++ = hex_chars[(*pSrc) >> 4]; - *pDest++ = hex_chars[(*pSrc) & 0x0f]; - } - - *pDest='\0'; - nsh_output(vtbl, "%s\n", buffer); - } -#endif - ret = OK; - goto exit; - } - else - { - src_buffer = s_data; - src_buff_len = strlen(s_data); - buff_len = calc_codec_buffsize(src_buff_len, mode); - buffer = malloc(buff_len); - buffer[0]=0; - if (!buffer) - { - fmt = g_fmtcmdoutofmemory; - goto errout; - } - - memset(buffer, 0, buff_len); - if (func) - { -#if defined(CONFIG_CODECS_HASH_MD5) && !defined(CONFIG_NSH_DISABLE_MD5) - if (mode == CODEC_MODE_HASH_MD5) - { - func(src_buffer, src_buff_len, (char *)&ctx, &buff_len, 0); - MD5Final(mac, &ctx); - pSrc = (char *)&mac; - pDest = buffer; - for(i=0;i<16;i++,pSrc++) - { - *pDest++ = hex_chars[(*pSrc) >> 4]; - *pDest++ = hex_chars[(*pSrc) & 0x0f]; - } - - *pDest='\0'; - } - else -#endif - { - func(src_buffer, src_buff_len, buffer, &buff_len,(is_websafe)?1:0); - } - } - - nsh_output(vtbl, "%s\n",buffer); - src_buffer = NULL; - goto exit; - } - -exit: - if (fd >= 0) - { - close(fd); - } - - if (fullpath) - { - free(fullpath); - } - - if (src_buffer) - { - free(src_buffer); - } - - if (buffer) - { - free(buffer); - } - - return ret; - -errout: - nsh_output(vtbl, fmt, argv[0]); - ret = ERROR; - goto exit; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_urlencode - ****************************************************************************/ - -#if defined(CONFIG_CODECS_URLCODE) && !defined(CONFIG_NSH_DISABLE_URLENCODE) -int cmd_urlencode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - return cmd_codecs_proc(vtbl, argc, argv, CODEC_MODE_URLENCODE, urlencode_cb); -} -#endif - -/**************************************************************************** - * Name: cmd_urldecode - ****************************************************************************/ - -#if defined(CONFIG_CODECS_URLCODE) && !defined(CONFIG_NSH_DISABLE_URLDECODE) -int cmd_urldecode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - return cmd_codecs_proc(vtbl, argc, argv, CODEC_MODE_URLDECODE, urldecode_cb); -} -#endif - -/**************************************************************************** - * Name: cmd_base64encode - ****************************************************************************/ - -#if defined(CONFIG_CODECS_BASE64) && !defined(CONFIG_NSH_DISABLE_BASE64ENC) -int cmd_base64encode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - return cmd_codecs_proc(vtbl, argc, argv, CODEC_MODE_BASE64ENC, b64enc_cb); -} -#endif - -/**************************************************************************** - * Name: cmd_base64decode - ****************************************************************************/ - -#if defined(CONFIG_CODECS_BASE64) && !defined(CONFIG_NSH_DISABLE_BASE64DEC) -int cmd_base64decode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - return cmd_codecs_proc(vtbl, argc, argv, CODEC_MODE_BASE64DEC, b64dec_cb); -} -#endif - -/**************************************************************************** - * Name: cmd_md5 - ****************************************************************************/ - -#if defined(CONFIG_CODECS_HASH_MD5) && !defined(CONFIG_NSH_DISABLE_MD5) -int cmd_md5(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - return cmd_codecs_proc(vtbl,argc,argv,CODEC_MODE_HASH_MD5,md5_cb); -} -#endif - -#endif /* CONFIG_NETUTILS_CODECS */ diff --git a/apps/nshlib/nsh_console.c b/apps/nshlib/nsh_console.c deleted file mode 100644 index 1b8f5f6ac..000000000 --- a/apps/nshlib/nsh_console.c +++ /dev/null @@ -1,437 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_serial.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <stdarg.h> -#include <assert.h> -#include <errno.h> -#include <debug.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct serialsave_s -{ - int cn_outfd; /* Re-directed output file descriptor */ - FILE *cn_outstream; /* Re-directed output stream */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLEBG -static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl); -#endif -static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl); -static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl, - FAR const void *buffer, size_t nbytes); -static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl, - FAR const char *fmt, ...); -static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl); -static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd, - FAR uint8_t *save); -static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl, - FAR uint8_t *save); -static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl, int exitstatus) - noreturn_function; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_openifnotopen - ****************************************************************************/ - -static int nsh_openifnotopen(struct console_stdio_s *pstate) -{ - /* The stream is open in a lazy fashion. This is done because the file - * descriptor may be opened on a different task than the stream. - */ - - if (!pstate->cn_outstream) - { - pstate->cn_outstream = fdopen(pstate->cn_outfd, "w"); - if (!pstate->cn_outstream) - { - return ERROR; - } - } - return 0; -} - -/**************************************************************************** - * Name: nsh_closeifnotclosed - * - * Description: - * Close the output stream if it is not the standard output stream. - * - ****************************************************************************/ - -static void nsh_closeifnotclosed(struct console_stdio_s *pstate) -{ - if (pstate->cn_outstream == OUTSTREAM(pstate)) - { - fflush(OUTSTREAM(pstate)); - pstate->cn_outfd = OUTFD(pstate); - } - else - { - if (pstate->cn_outstream) - { - fflush(pstate->cn_outstream); - fclose(pstate->cn_outstream); - } - else if (pstate->cn_outfd >= 0 && pstate->cn_outfd != OUTFD(pstate)) - { - close(pstate->cn_outfd); - } - - pstate->cn_outfd = -1; - pstate->cn_outstream = NULL; - } -} - -/**************************************************************************** - * Name: nsh_consolewrite - * - * Description: - * write a buffer to the remote shell window. - * - * Currently only used by cat. - * - ****************************************************************************/ - -static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer, size_t nbytes) -{ - FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl; - ssize_t ret; - - /* The stream is open in a lazy fashion. This is done because the file - * descriptor may be opened on a different task than the stream. The - * actual open will then occur with the first output from the new task. - */ - - if (nsh_openifnotopen(pstate) != 0) - { - return (ssize_t)ERROR; - } - - /* Write the data to the output stream */ - - ret = fwrite(buffer, 1, nbytes, pstate->cn_outstream); - if (ret < 0) - { - dbg("[%d] Failed to send buffer: %d\n", pstate->cn_outfd, errno); - } - return ret; -} - -/**************************************************************************** - * Name: nsh_consoleoutput - * - * Description: - * Print a string to the currently selected stream. - * - ****************************************************************************/ - -static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...) -{ - FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl; - va_list ap; - int ret; - - /* The stream is open in a lazy fashion. This is done because the file - * descriptor may be opened on a different task than the stream. The - * actual open will then occur with the first output from the new task. - */ - - if (nsh_openifnotopen(pstate) != 0) - { - return ERROR; - } - - va_start(ap, fmt); - ret = vfprintf(pstate->cn_outstream, fmt, ap); - va_end(ap); - - return ret; -} - -/**************************************************************************** - * Name: nsh_consolelinebuffer - * - * Description: - * Return a reference to the current line buffer - * - ****************************************************************************/ - -static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl) -{ - FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl; - return pstate->cn_line; -} - -/**************************************************************************** - * Name: nsh_consoleclone - * - * Description: - * Make an independent copy of the vtbl - * - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLEBG -static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl) -{ - FAR struct console_stdio_s *pclone = nsh_newconsole(); - return &pclone->cn_vtbl; -} -#endif - -/**************************************************************************** - * Name: nsh_consolerelease - * - * Description: - * Release the cloned instance - * - ****************************************************************************/ - -static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl) -{ - FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl; - - /* Close the output stream */ - - nsh_closeifnotclosed(pstate); - - /* Close the console stream */ - -#ifdef CONFIG_NSH_CONDEV - (void)fclose(pstate->cn_constream); -#endif - - /* Then release the vtable container */ - - free(pstate); -} - -/**************************************************************************** - * Name: nsh_consoleredirect - * - * Description: - * Set up for redirected output. This function is called from nsh_parse() - * in two different contexts: - * - * 1) Redirected background commands of the form: command > xyz.text & - * - * In this case: - * - vtbl: A newly allocated and initialized instance created by - * nsh_consoleclone, - * - fd:- The file descriptor of the redirected output - * - save: NULL - * - * nsh_consolerelease() will perform the clean-up when the clone is - * destroyed. - * - * 2) Redirected foreground commands of the form: command > xyz.txt - * - * In this case: - * - vtbl: The current state structure, - * - fd: The file descriptor of the redirected output - * - save: Where to save the re-directed registers. - * - * nsh_consoleundirect() will perform the clean-up after the redirected - * command completes. - * - ****************************************************************************/ - -static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd, FAR uint8_t *save) -{ - FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl; - FAR struct serialsave_s *ssave = (FAR struct serialsave_s *)save; - - /* Case 1: Redirected foreground commands */ - - if (ssave) - { - /* pstate->cn_outstream and cn_outfd refer refer to the - * currently opened output stream. If the output stream is open, flush - * any pending output. - */ - - if (pstate->cn_outstream) - { - fflush(pstate->cn_outstream); - } - - /* Save the current fd and stream values. These will be restored - * when nsh_consoleundirect() is called. - */ - - ssave->cn_outfd = pstate->cn_outfd; - ssave->cn_outstream = pstate->cn_outstream; - } - else - { - /* nsh_consoleclone() set pstate->cn_outfd and cn_outstream to refer - * to standard out. We just want to leave these alone and overwrite - * them with the fd for the re-directed stream. - */ - } - - /* In either case, set the fd of the new, re-directed output and nullify - * the output stream (it will be fdopen'ed if it is used). - */ - - pstate->cn_outfd = fd; - pstate->cn_outstream = NULL; -} - -/**************************************************************************** - * Name: nsh_consoleundirect - * - * Description: - * Set up for redirected output - * - ****************************************************************************/ - -static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl, FAR uint8_t *save) -{ - FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl; - FAR struct serialsave_s *ssave = (FAR struct serialsave_s *)save; - - nsh_closeifnotclosed(pstate); - pstate->cn_outfd = ssave->cn_outfd; - pstate->cn_outstream = ssave->cn_outstream; -} - -/**************************************************************************** - * Name: nsh_consoleexit - * - * Description: - * Exit the shell task - * - ****************************************************************************/ - -static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl, int exitstatus) -{ - /* Destroy ourself then exit with the provided status */ - - nsh_consolerelease(vtbl); - exit(exitstatus); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_newconsole - ****************************************************************************/ - -FAR struct console_stdio_s *nsh_newconsole(void) -{ - struct console_stdio_s *pstate = (struct console_stdio_s *)zalloc(sizeof(struct console_stdio_s)); - if (pstate) - { - /* Initialize the call table */ - -#ifndef CONFIG_NSH_DISABLEBG - pstate->cn_vtbl.clone = nsh_consoleclone; - pstate->cn_vtbl.release = nsh_consolerelease; -#endif - pstate->cn_vtbl.write = nsh_consolewrite; - pstate->cn_vtbl.output = nsh_consoleoutput; - pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer; - pstate->cn_vtbl.redirect = nsh_consoleredirect; - pstate->cn_vtbl.undirect = nsh_consoleundirect; - pstate->cn_vtbl.exit = nsh_consoleexit; - - /* (Re-) open the console input device */ - -#ifdef CONFIG_NSH_CONDEV - pstate->cn_confd = open(CONFIG_NSH_CONDEV, O_RDWR); - if (pstate->cn_confd < 0) - { - free(pstate); - return NULL; - } - - /* Create a standard C stream on the console device */ - - pstate->cn_constream = fdopen(pstate->cn_confd, "r+"); - if (!pstate->cn_constream) - { - close(pstate->cn_confd); - free(pstate); - return NULL; - } -#endif - - /* Initialize the output stream */ - - pstate->cn_outfd = OUTFD(pstate); - pstate->cn_outstream = OUTSTREAM(pstate); - } - return pstate; -} diff --git a/apps/nshlib/nsh_console.h b/apps/nshlib/nsh_console.h deleted file mode 100644 index 4dc2938cb..000000000 --- a/apps/nshlib/nsh_console.h +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_console.h - * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_NSHLIB_NSH_CONSOLE_H -#define __APPS_NSHLIB_NSH_CONSOLE_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> - -#include <stdio.h> -#include <stdint.h> -#include <stdbool.h> -#include <errno.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Method access macros */ - -#define nsh_clone(v) (v)->clone(v) -#define nsh_release(v) (v)->release(v) -#define nsh_write(v,b,n) (v)->write(v,b,n) -#define nsh_linebuffer(v) (v)->linebuffer(v) -#define nsh_redirect(v,f,s) (v)->redirect(v,f,s) -#define nsh_undirect(v,s) (v)->undirect(v,s) -#define nsh_exit(v,s) (v)->exit(v,s) - -#ifdef CONFIG_CPP_HAVE_VARARGS -# define nsh_output(v, fmt...) (v)->output(v, ##fmt) -#else -# define nsh_output vtbl->output -#endif - -/* Size of info to be saved in call to nsh_redirect */ - -#define SAVE_SIZE (sizeof(int) + sizeof(FILE*) + sizeof(bool)) - -/* Are we using the NuttX console for I/O? Or some other character device? */ - -#ifdef CONFIG_NSH_CONDEV -# define INFD(p) ((p)->cn_confd) -# define INSTREAM(p) ((p)->cn_constream) -# define OUTFD(p) ((p)->cn_confd) -# define OUTSTREAM(p) ((p)->cn_constream) -#else -# define INFD(p) 0 -# define INSTREAM(p) stdin -# define OUTFD(p) 1 -# define OUTSTREAM(p) stdout -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ -/* This describes a generic console front-end */ - -struct nsh_vtbl_s -{ - /* This function pointers are "hooks" into the front end logic to - * handle things like output of command results, redirection, etc. - * -- all of which must be done in a way that is unique to the nature - * of the front end. - */ - -#ifndef CONFIG_NSH_DISABLEBG - FAR struct nsh_vtbl_s *(*clone)(FAR struct nsh_vtbl_s *vtbl); - void (*addref)(FAR struct nsh_vtbl_s *vtbl); - void (*release)(FAR struct nsh_vtbl_s *vtbl); -#endif - ssize_t (*write)(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer, size_t nbytes); - int (*output)(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...); - FAR char *(*linebuffer)(FAR struct nsh_vtbl_s *vtbl); - void (*redirect)(FAR struct nsh_vtbl_s *vtbl, int fd, FAR uint8_t *save); - void (*undirect)(FAR struct nsh_vtbl_s *vtbl, FAR uint8_t *save); - void (*exit)(FAR struct nsh_vtbl_s *vtbl, int exitstatus) noreturn_function; - - /* Parser state data */ - - struct nsh_parser_s np; -}; - -/* This structure describes a console front-end that is based on stdin and - * stdout (which is all of the supported console types at the time being). - */ - -struct console_stdio_s -{ - /* NSH front-end call table */ - - struct nsh_vtbl_s cn_vtbl; - - /* NSH input/output streams */ - -#ifdef CONFIG_NSH_CONDEV - int cn_confd; /* Console I/O file descriptor */ -#endif - int cn_outfd; /* Output file descriptor (possibly redirected) */ -#ifdef CONFIG_NSH_CONDEV - FILE *cn_constream; /* Console I/O stream (possibly redirected) */ -#endif - FILE *cn_outstream; /* Output stream */ - - /* Line input buffer */ - - char cn_line[CONFIG_NSH_LINELEN]; -}; - - - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Defined in nsh_console.c *************************************************/ - -FAR struct console_stdio_s *nsh_newconsole(void); - -#endif /* __APPS_NSHLIB_NSH_CONSOLE_H */ diff --git a/apps/nshlib/nsh_consolemain.c b/apps/nshlib/nsh_consolemain.c deleted file mode 100644 index 8be44f7aa..000000000 --- a/apps/nshlib/nsh_consolemain.c +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_consolemain.c - * - * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name 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 <stdio.h> -#include <assert.h> - -#include <apps/readline.h> - -#include "nsh.h" -#include "nsh_console.h" - -#ifndef HAVE_USB_CONSOLE - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_consolemain (Normal character device version) - * - * Description: - * This interfaces maybe to called or started with task_start to start a - * single an NSH instance that operates on stdin and stdout. This - * function does not normally return (see below). - * - * This version of nsh_consolmain handles generic /dev/console character - * devices (see nsh_usbdev.c for another version for special USB console - * devices). - * - * Input Parameters: - * Standard task start-up arguments. These are not used. argc may be - * zero and argv may be NULL. - * - * Returned Values: - * This function does not normally return. exit() is usually called to - * terminate the NSH session. This function will return in the event of - * an error. In that case, a nonzero value is returned (EXIT_FAILURE=1). - * - ****************************************************************************/ - -int nsh_consolemain(int argc, char *argv[]) -{ - FAR struct console_stdio_s *pstate = nsh_newconsole(); - int ret; - - DEBUGASSERT(pstate); - - /* Execute the start-up script */ - -#ifdef CONFIG_NSH_ROMFSETC - (void)nsh_initscript(&pstate->cn_vtbl); -#endif - - /* Initialize any USB tracing options that were requested */ - -#ifdef CONFIG_NSH_USBDEV_TRACE - usbtrace_enable(TRACE_BITSET); -#endif - - /* Execute the session */ - - ret = nsh_session(pstate); - - /* Exit upon return */ - - nsh_exit(&pstate->cn_vtbl, ret); - return ret; -} - -#endif /* !HAVE_USB_CONSOLE */ diff --git a/apps/nshlib/nsh_dbgcmds.c b/apps/nshlib/nsh_dbgcmds.c deleted file mode 100644 index 85a4ccb9c..000000000 --- a/apps/nshlib/nsh_dbgcmds.c +++ /dev/null @@ -1,415 +0,0 @@ -/**************************************************************************** - * apps/nshlib/dbg_dbgcmds.c - * - * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <stdint.h> -#include <stdbool.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# include <fcntl.h> -#endif - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct dbgmem_s -{ - bool dm_write; /* true: perfrom write operation */ - void *dm_addr; /* Address to access */ - uint32_t dm_value; /* Value to write */ - unsigned int dm_count; /* The number of bytes to access */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mem_parse - ****************************************************************************/ - -int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv, - struct dbgmem_s *mem) -{ - char *pcvalue = strchr(argv[1], '='); - unsigned long lvalue = 0; - - /* Check if we are writing a value */ - - if (pcvalue) - { - *pcvalue = '\0'; - pcvalue++; - - lvalue = (unsigned long)strtol(pcvalue, NULL, 16); - if (lvalue > 0xffffffffL) - { - return -EINVAL; - } - - mem->dm_write = true; - mem->dm_value = (uint32_t)lvalue; - } - else - { - mem->dm_write = false; - mem->dm_value = 0; - } - - /* Get the address to be accessed */ - - mem->dm_addr = (void*)((uintptr_t)strtol(argv[1], NULL, 16)); - - /* Get the number of bytes to access */ - - if (argc > 2) - { - mem->dm_count = (unsigned int)strtol(argv[2], NULL, 16); - } - else - { - mem->dm_count = 1; - } - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_mb - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_MB -int cmd_mb(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct dbgmem_s mem; - volatile uint8_t *ptr; - int ret; - int i; - - ret = mem_parse(vtbl, argc, argv, &mem); - if (ret == 0) - { - /* Loop for the number of requested bytes */ - - for (i = 0, ptr = (volatile uint8_t*)mem.dm_addr; i < mem.dm_count; i++, ptr++) - { - /* Print the value at the address */ - - nsh_output(vtbl, " %p = 0x%02x", ptr, *ptr); - - /* Are we supposed to write a value to this address? */ - - if (mem.dm_write) - { - /* Yes, was the supplied value within range? */ - - if (mem.dm_value > 0x000000ff) - { - nsh_output(vtbl, g_fmtargrange, argv[0]); - return ERROR; - } - - /* Write the value and re-read the address so that we print its - * current value (if the address is a process address, then the - * value read might not necessarily be the value written). - */ - - *ptr = (uint8_t)mem.dm_value; - nsh_output(vtbl, " -> 0x%02x", *ptr); - } - - /* Make sure we end it with a newline */ - - nsh_output(vtbl, "\n", *ptr); - } - } - return ret; -} -#endif - -/**************************************************************************** - * Name: cmd_mh - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_MH -int cmd_mh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct dbgmem_s mem; - volatile uint16_t *ptr; - int ret; - int i; - - ret = mem_parse(vtbl, argc, argv, &mem); - if (ret == 0) - { - /* Loop for the number of requested bytes */ - - for (i = 0, ptr = (volatile uint16_t*)mem.dm_addr; i < mem.dm_count; i += 2, ptr++) - { - /* Print the value at the address */ - - nsh_output(vtbl, " %p = 0x%04x", ptr, *ptr); - - /* Are we supposed to write a value to this address? */ - - if (mem.dm_write) - { - /* Yes, was the supplied value within range? */ - - if (mem.dm_value > 0x0000ffff) - { - nsh_output(vtbl, g_fmtargrange, argv[0]); - return ERROR; - } - - /* Write the value and re-read the address so that we print its - * current value (if the address is a process address, then the - * value read might not necessarily be the value written). - */ - - *ptr = (uint16_t)mem.dm_value; - nsh_output(vtbl, " -> 0x%04x", *ptr); - } - - /* Make sure we end it with a newline */ - - nsh_output(vtbl, "\n", *ptr); - } - } - return ret; -} -#endif - -/**************************************************************************** - * Name: cmd_mw - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_MW -int cmd_mw(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct dbgmem_s mem; - volatile uint32_t *ptr; - int ret; - int i; - - ret = mem_parse(vtbl, argc, argv, &mem); - if (ret == 0) - { - /* Loop for the number of requested bytes */ - - for (i = 0, ptr = (volatile uint32_t*)mem.dm_addr; i < mem.dm_count; i += 4, ptr++) - { - /* Print the value at the address */ - - nsh_output(vtbl, " %p = 0x%08x", ptr, *ptr); - - /* Are we supposed to write a value to this address? */ - - if (mem.dm_write) - { - /* Write the value and re-read the address so that we print its - * current value (if the address is a process address, then the - * value read might not necessarily be the value written). - */ - - *ptr = mem.dm_value; - nsh_output(vtbl, " -> 0x%08x", *ptr); - } - - /* Make sure we end it with a newline */ - - nsh_output(vtbl, "\n", *ptr); - } - } - return ret; -} -#endif - -/**************************************************************************** - * Name: nsh_dumpbuffer - ****************************************************************************/ - -void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, - const uint8_t *buffer, ssize_t nbytes) -{ - char line[128]; - int ch; - int i; - int j; - - nsh_output(vtbl, "%s:\n", msg); - for (i = 0; i < nbytes; i += 16) - { - sprintf(line, "%04x: ", i); - - for ( j = 0; j < 16; j++) - { - if (i + j < nbytes) - { - sprintf(&line[strlen(line)], "%02x ", buffer[i+j] ); - } - else - { - strcpy(&line[strlen(line)], " "); - } - } - - for ( j = 0; j < 16; j++) - { - if (i + j < nbytes) - { - ch = buffer[i+j]; - sprintf(&line[strlen(line)], "%c", ch >= 0x20 && ch <= 0x7e ? ch : '.'); - } - } - nsh_output(vtbl, "%s\n", line); - } -} - -/**************************************************************************** - * Name: cmd_xd, hex dump of memory - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_XD -int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - FAR char *addr; - FAR char *endptr; - int nbytes; - - addr = (char*)((uintptr_t)strtol(argv[1], &endptr, 16)); - if (argv[0][0] == '\0' || *endptr != '\0') - { - return ERROR; - } - - nbytes = (int)strtol(argv[2], &endptr, 0); - if (argv[0][0] == '\0' || *endptr != '\0' || nbytes < 0) - { - return ERROR; - } - - nsh_dumpbuffer(vtbl, "Hex dump", (uint8_t*)addr, nbytes); - return OK; -} -#endif - -/**************************************************************************** - * Name: cmd_hexdump, hex dump of files - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_HEXDUMP -int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - uint8_t buffer[IOBUFFERSIZE]; - char msg[32]; - int position; - int fd; - int ret = OK; - - /* Open the file for reading */ - - fd = open(argv[1], O_RDONLY); - if (fd < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "open", NSH_ERRNO); - return ERROR; - } - - position = 0; - for (;;) - { - int nbytesread = read(fd, buffer, IOBUFFERSIZE); - - /* Check for read errors */ - - if (nbytesread < 0) - { - int errval = errno; - nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "read", NSH_ERRNO_OF(errval)); - ret = ERROR; - break; - } - else if (nbytesread > 0) - { - snprintf(msg, sizeof(msg), "%s at %08x", argv[1], position); - nsh_dumpbuffer(vtbl, msg, buffer, nbytesread); - position += nbytesread; - } - else - { - break; // EOF - } - } - - (void)close(fd); - return ret; -} -#endif -#endif diff --git a/apps/nshlib/nsh_ddcmd.c b/apps/nshlib/nsh_ddcmd.c deleted file mode 100644 index e6ef2523c..000000000 --- a/apps/nshlib/nsh_ddcmd.c +++ /dev/null @@ -1,643 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_ddcmd.c - * - * Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/stat.h> - -#include <stdint.h> -#include <stdbool.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <debug.h> -#include <errno.h> - -#include <nuttx/fs/fs.h> - -#include "nsh.h" -#include "nsh_console.h" - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_NSH_DISABLE_DD) - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/* If no sector size is specified wity BS=, then the following default value - * is used. - */ - -#define DEFAULT_SECTSIZE 512 - -/* At present, piping of input and output are not support, i.e., both of= - * and if= arguments are required. - */ - -#undef CAN_PIPE_FROM_STD - -/* Function pointer calls are only need if block drivers are supported - * (or, rather, if mount points are supported in the file system) - */ - -#ifndef CONFIG_DISABLE_MOUNTPOINT -# define DD_INFD ((dd)->inf.fd) -# define DD_INHANDLE ((dd)->inf.handle) -# define DD_OUTFD ((dd)->outf.fd) -# define DD_OUTHANDLE ((dd)->outf.handle) -# define DD_READ(dd) ((dd)->infread(dd)) -# define DD_WRITE(dd) ((dd)->outfwrite(dd)) -# define DD_INCLOSE(dd) ((dd)->infclose(dd)) -# define DD_OUTCLOSE(dd) ((dd)->outfclose(dd)) -#else -# define DD_INFD ((dd)->infd) -# undef DD_INHANDLE -# define DD_OUTFD ((dd)->outfd) -# undef DD_OUTHANDLE -# define DD_READ(dd) dd_readch(dd) -# define DD_WRITE(dd) dd_writech(dd) -# define DD_INCLOSE(dd) dd_infclosech(dd) -# define DD_OUTCLOSE(dd) dd_outfclosech(dd) -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct dd_s -{ - FAR struct nsh_vtbl_s *vtbl; - -#ifndef CONFIG_DISABLE_MOUNTPOINT - union - { - FAR void *handle; /* BCH lib handle for block device*/ - int fd; /* File descriptor of the character device */ - } inf; -#else - int infd; /* File descriptor of the input device */ -#endif - -#ifndef CONFIG_DISABLE_MOUNTPOINT - union - { - FAR void *handle; /* BCH lib handle for block device*/ - int fd; /* File descriptor of the character device */ - } outf; -#else - int outfd; /* File descriptor of the output device */ -#endif - - uint32_t nsectors; /* Number of sectors to transfer */ - uint32_t sector; /* The current sector number */ - uint32_t skip; /* The number of sectors skipped on input */ - bool eof; /* true: The of the input or output file has been hit */ - uint16_t sectsize; /* Size of one sector */ - uint16_t nbytes; /* Number of valid bytes in the buffer */ - uint8_t *buffer; /* Buffer of data to write to the output file */ - - /* Function pointers to handle differences between block and character devices */ - -#ifndef CONFIG_DISABLE_MOUNTPOINT - int (*infread)(struct dd_s *dd); - void (*infclose)(struct dd_s *dd); - int (*outfwrite)(struct dd_s *dd); - void (*outfclose)(struct dd_s *dd); -#endif -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char g_dd[] = "dd"; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dd_outfcloseblk - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_MOUNTPOINT -static void dd_outfcloseblk(struct dd_s *dd) -{ - (void)bchlib_teardown(DD_OUTHANDLE); -} -#endif - - -/**************************************************************************** - * Name: dd_outfclosech - ****************************************************************************/ - -static void dd_outfclosech(struct dd_s *dd) -{ - (void)close(DD_OUTFD); -} - -/**************************************************************************** - * Name: dd_infcloseblk - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_MOUNTPOINT -static void dd_infcloseblk(struct dd_s *dd) -{ - (void)bchlib_teardown(DD_INHANDLE); -} -#endif - -/**************************************************************************** - * Name: dd_infclosech - ****************************************************************************/ - -static void dd_infclosech(struct dd_s *dd) -{ - (void)close(DD_INFD); -} - -/**************************************************************************** - * Name: dd_writeblk - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_MOUNTPOINT -static int dd_writeblk(struct dd_s *dd) -{ - ssize_t nbytes; - off_t offset = (dd->sector - dd->skip) * dd->sectsize; - - /* Write the sector at the specified offset */ - - nbytes = bchlib_write(DD_OUTHANDLE, (char*)dd->buffer, offset, dd->sectsize); - if (nbytes < 0) - { - /* bchlib_write return -EFBIG on attempts to write past the end of - * the device. - */ - - if (nbytes == -EFBIG) - { - dd->eof = true; /* Set end-of-file */ - } - else - { - FAR struct nsh_vtbl_s *vtbl = dd->vtbl; - nsh_output(vtbl, g_fmtcmdfailed, g_dd, "bshlib_write", NSH_ERRNO_OF(-nbytes)); - return ERROR; - } - } - - return OK; -} -#endif - -/**************************************************************************** - * Name: dd_writech - ****************************************************************************/ - -static int dd_writech(struct dd_s *dd) -{ - uint8_t *buffer = dd->buffer; - uint16_t written ; - ssize_t nbytes; - - /* Is the out buffer full (or is this the last one)? */ - - written = 0; - do - { - nbytes = write(DD_OUTFD, buffer, dd->sectsize - written); - if (nbytes < 0) - { - FAR struct nsh_vtbl_s *vtbl = dd->vtbl; - nsh_output(vtbl, g_fmtcmdfailed, g_dd, "write", NSH_ERRNO_OF(-nbytes)); - return ERROR; - } - - written += nbytes; - buffer += nbytes; - } - while (written < dd->sectsize); - - return OK; -} - -/**************************************************************************** - * Name: dd_readblk - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_MOUNTPOINT -static int dd_readblk(struct dd_s *dd) -{ - ssize_t nbytes; - off_t offset = dd->sector * dd->sectsize; - - nbytes = bchlib_read(DD_INHANDLE, (char*)dd->buffer, offset, dd->sectsize); - if (nbytes < 0) - { - FAR struct nsh_vtbl_s *vtbl = dd->vtbl; - nsh_output(vtbl, g_fmtcmdfailed, g_dd, "bshlib_read", NSH_ERRNO_OF(-nbytes)); - return ERROR; - } - - /* bchlib_read return 0 on attempts to write past the end of the device. */ - - dd->nbytes = nbytes; - dd->eof = (nbytes == 0); - return OK; -} -#endif - -/**************************************************************************** - * Name: dd_readch - ****************************************************************************/ - -static int dd_readch(struct dd_s *dd) -{ - uint8_t *buffer = dd->buffer; - ssize_t nbytes; - - dd->nbytes = 0; - do - { - nbytes = read(DD_INFD, buffer, dd->sectsize - dd->nbytes); - if (nbytes < 0) - { - FAR struct nsh_vtbl_s *vtbl = dd->vtbl; - nsh_output(vtbl, g_fmtcmdfailed, g_dd, "read", NSH_ERRNO_OF(-nbytes)); - return ERROR; - } - - dd->nbytes += nbytes; - buffer += nbytes; - } - while (dd->nbytes < dd->sectsize && nbytes > 0); - - dd->eof |= (dd->nbytes == 0); - return OK; -} - -/**************************************************************************** - * Name: dd_infopen - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_MOUNTPOINT -static int dd_filetype(const char *filename) -{ - struct stat sb; - int ret; - - /* Get the type of the file */ - - ret = stat(filename, &sb); - if (ret < 0) - { - return ERROR; /* Return -1 on failure */ - } - - return S_ISBLK(sb.st_mode); /* Return true(1) if block, false(0) if char */ -} -#endif - -/**************************************************************************** - * Name: dd_infopen - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_MOUNTPOINT -static inline int dd_infopen(const char *name, struct dd_s *dd) -{ - FAR struct nsh_vtbl_s *vtbl = dd->vtbl; - int ret; - int type; - - /* Get the type of the input file */ - - type = dd_filetype(name); - if (type < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, g_dd, "stat", NSH_ERRNO_OF(-type)); - return type; - } - - /* Open the input file */ - - if (!type) - { - DD_INFD = open(name, O_RDONLY); - if (DD_INFD < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO); - return ERROR; - } - - dd->infread = dd_readch; /* Character oriented read */ - dd->infclose = dd_infclosech; - } - else - { - ret = bchlib_setup(name, true, &DD_INHANDLE); - if (ret < 0) - { - return ERROR; - } - - dd->infread = dd_readblk; - dd->infclose = dd_infcloseblk; - } - return OK; -} -#else -static inline int dd_infopen(const char *name, struct dd_s *dd) -{ - DD_INFD = open(name, O_RDONLY); - if (DD_INFD < 0) - { - FAR struct nsh_vtbl_s *vtbl = dd->vtbl; - nsh_output(vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO); - return ERROR; - } - return OK; -} -#endif - -/**************************************************************************** - * Name: dd_outfopen - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_MOUNTPOINT -static inline int dd_outfopen(const char *name, struct dd_s *dd) -{ - int type; - int ret = OK; - - /* Get the type of the output file */ - - type = dd_filetype(name); - - /* Open the block driver for input */ - - if (type == true) - { - ret = bchlib_setup(name, true, &DD_OUTHANDLE); - if (ret < 0) - { - return ERROR; - } - - dd->outfwrite = dd_writeblk; /* Block oriented write */ - dd->outfclose = dd_outfcloseblk; - } - - /* Otherwise, the file is character oriented or does not exist */ - - else - { - DD_OUTFD = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (DD_OUTFD < 0) - { - FAR struct nsh_vtbl_s *vtbl = dd->vtbl; - nsh_output(vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO); - return ERROR; - } - - dd->outfwrite = dd_writech; /* Character oriented write */ - dd->outfclose = dd_outfclosech; - } - return OK; -} -#else -static inline int dd_outfopen(const char *name, struct dd_s *dd) -{ - DD_OUTFD = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (DD_OUTFD < 0) - { - nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO); - return ERROR; - } - return OK; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_dd - ****************************************************************************/ - -int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct dd_s dd; - char *infile = NULL; - char *outfile = NULL; - int ret = ERROR; - int i; - - /* Initialize the dd structure */ - - memset(&dd, 0, sizeof(struct dd_s)); - dd.vtbl = vtbl; /* For nsh_output */ - dd.sectsize = DEFAULT_SECTSIZE; /* Sector size if 'bs=' not provided */ - dd.nsectors = 0xffffffff; /* MAX_UINT32 */ - - /* If no IF= option is provided on the command line, then read - * from stdin. - */ - -#ifdef CAN_PIPE_FROM_STD - DD_INFD = 0; /* stdin */ -#ifndef CONFIG_NSH_DISABLE_DD - dd.infread = readch; /* Character oriented read */ - dd.infclose = noclose; /* Don't close stdin */ -#endif -#endif - /* If no OF= option is provided on the command line, then write - * to stdout. - */ - -#ifdef CAN_PIPE_FROM_STD - DD_OUTDF = 1; /* stdout */ -#ifndef CONFIG_NSH_DISABLE_DD - dd.outfwrite = writech; /* Character oriented write */ - dd.outfclose = noclose; /* Don't close stdout */ -#endif -#endif - - /* Parse command line parameters */ - - for (i = 1; i < argc; i++) - { - if (strncmp(argv[i], "if=", 3) == 0) - { - infile = nsh_getfullpath(vtbl, &argv[i][3]); - } - else if (strncmp(argv[i], "of=", 3) == 0) - { - outfile = nsh_getfullpath(vtbl, &argv[i][3]); - } - else if (strncmp(argv[i], "bs=", 3) == 0) - { - dd.sectsize = atoi(&argv[i][3]); - } - else if (strncmp(argv[i], "count=", 6) == 0) - { - dd.nsectors = atoi(&argv[i][6]); - } - else if (strncmp(argv[i], "skip=", 5) == 0) - { - dd.skip = atoi(&argv[i][5]); - } - } - -#ifndef CAN_PIPE_FROM_STD - if (!infile || !outfile) - { - nsh_output(vtbl, g_fmtargrequired, g_dd); - goto errout_with_paths; - } -#endif - - if (dd.skip > dd.nsectors) - { - nsh_output(vtbl, g_fmtarginvalid, g_dd); - goto errout_with_paths; - } - - /* Allocate the I/O buffer */ - - dd.buffer = malloc(dd.sectsize); - if (!dd.buffer) - { - nsh_output(vtbl, g_fmtcmdoutofmemory, g_dd); - goto errout_with_paths; - } - - /* Open the input file */ - - ret = dd_infopen(infile, &dd); - if (ret < 0) - { - goto errout_with_paths; - } - - /* Open the output file */ - - ret = dd_outfopen(outfile, &dd); - if (ret < 0) - { - goto errout_with_inf; - } - - /* Then perform the data transfer */ - - dd.sector = 0; - while (!dd.eof && dd.nsectors > 0) - { - /* Read one sector from from the input */ - - ret = DD_READ(&dd); - if (ret < 0) - { - goto errout_with_outf; - } - - /* Has the incoming data stream ended? */ - - if (!dd.eof) - { - /* Pad with zero if necessary (at the end of file only) */ - - for (i = dd.nbytes; i < dd.sectsize; i++) - { - dd.buffer[i] = 0; - } - - /* Write one sector to the output file */ - - if (dd.sector >= dd.skip) - { - ret = DD_WRITE(&dd); - if (ret < 0) - { - goto errout_with_outf; - } - - /* Decrement to show that a sector was written */ - - dd.nsectors--; - } - - /* Increment the sector number */ - - dd.sector++; - } - } - ret = OK; - -errout_with_outf: - DD_INCLOSE(&dd); -errout_with_inf: - DD_OUTCLOSE(&dd); - free(dd.buffer); -errout_with_paths: - if (infile) - { - free(infile); - } - if (outfile) - { - free(outfile); - } - return ret; -} - -#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_NSH_DISABLE_DD */ - diff --git a/apps/nshlib/nsh_envcmds.c b/apps/nshlib/nsh_envcmds.c deleted file mode 100644 index 07b775517..000000000 --- a/apps/nshlib/nsh_envcmds.c +++ /dev/null @@ -1,338 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_envcmds.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <libgen.h> -#include <errno.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -static const char g_pwd[] = "PWD"; -static const char g_oldpwd[] = "OLDPWD"; -static const char g_home[] = CONFIG_LIB_HOMEDIR; -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_getwd - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -static inline FAR const char *nsh_getwd(const char *wd) -{ - const char *val; - - /* If no working directory is defined, then default to the home directory */ - - val = getenv(wd); - if (!val) - { - val = g_home; - } - return val; -} -#endif - -/**************************************************************************** - * Name: nsh_getdirpath - ****************************************************************************/ - -static inline char *nsh_getdirpath(FAR struct nsh_vtbl_s *vtbl, - const char *dirpath, const char *relpath) -{ - char *alloc; - int len; - - /* Handle the special case where the dirpath is simply "/" */ - - if (strcmp(dirpath, "/") == 0) - { - len = strlen(relpath) + 2; - alloc = (char*)malloc(len); - if (alloc) - { - sprintf(alloc, "/%s", relpath); - } - } - else - { - len = strlen(dirpath) + strlen(relpath) + 2; - alloc = (char*)malloc(len); - if (alloc) - { - sprintf(alloc, "%s/%s", dirpath, relpath); - } - } - - if (!alloc) - { - nsh_output(vtbl, g_fmtcmdoutofmemory, "nsh_getdirpath"); - } - return alloc; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_getwd - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -FAR const char *nsh_getcwd(void) -{ - return nsh_getwd(g_pwd); -} -#endif - -/**************************************************************************** - * Name: nsh_getfullpath - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl, const char *relpath) -{ - const char *wd; - - /* Handle some special cases */ - - if (!relpath || relpath[0] == '\0') - { - /* No relative path provided */ - - return strdup(g_home); - } - else if (relpath[0] == '/') - { - return strdup(relpath); - } - - /* Get the path to the current working directory */ - - wd = nsh_getcwd(); - - /* Fake the '.' directory */ - - if (strcmp(relpath, ".") == 0) - { - return strdup(wd); - } - - /* Return the full path */ - - return nsh_getdirpath(vtbl, wd, relpath); -} -#endif - -/**************************************************************************** - * Name: nsh_freefullpath - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -void nsh_freefullpath(char *relpath) -{ - if (relpath) - { - free(relpath); - } -} -#endif - -/**************************************************************************** - * Name: cmd_cd - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -#ifndef CONFIG_NSH_DISABLE_CD -int cmd_cd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - const char *path = argv[1]; - char *alloc = NULL; - char *fullpath = NULL; - int ret = OK; - - /* Check for special arguments */ - - if (argc < 2 || strcmp(path, "~") == 0) - { - path = g_home; - } - else if (strcmp(path, "-") == 0) - { - alloc = strdup(nsh_getwd(g_oldpwd)); - path = alloc; - } - else if (strcmp(path, "..") == 0) - { - alloc = strdup(nsh_getcwd()); - path = dirname(alloc); - } - else - { - fullpath = nsh_getfullpath(vtbl, path); - path = fullpath; - } - - /* Set the new workding directory */ - - ret = chdir(path); - if (ret != 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "chdir", NSH_ERRNO); - ret = ERROR; - } - - /* Free any memory that was allocated */ - - if (alloc) - { - free(alloc); - } - - if (fullpath) - { - nsh_freefullpath(fullpath); - } - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_echo - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_ECHO -int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - int i; - - /* echo each argument, separated by a space as it must have been on the - * command line - */ - - for (i = 1; i < argc; i++) - { - nsh_output(vtbl, "%s ", argv[i]); - } - nsh_output(vtbl, "\n"); - return OK; -} -#endif - -/**************************************************************************** - * Name: cmd_pwd - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -#ifndef CONFIG_NSH_DISABLE_PWD -int cmd_pwd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - nsh_output(vtbl, "%s\n", nsh_getcwd()); - return OK; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_set - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_ENVIRON -#ifndef CONFIG_NSH_DISABLE_SET -int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - int ret = setenv(argv[1], argv[2], TRUE); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "setenv", NSH_ERRNO); - } - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_unset - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_ENVIRON -#ifndef CONFIG_NSH_DISABLE_UNSET -int cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - int ret = unsetenv(argv[1]); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "unsetenv", NSH_ERRNO); - } - return ret; -} -#endif -#endif diff --git a/apps/nshlib/nsh_fileapps.c b/apps/nshlib/nsh_fileapps.c deleted file mode 100644 index 9ff230f1a..000000000 --- a/apps/nshlib/nsh_fileapps.c +++ /dev/null @@ -1,314 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_fileapps.c - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#ifdef CONFIG_SCHED_WAITPID -# include <sys/wait.h> -#endif - -#include <stdbool.h> -#include <spawn.h> -#include <errno.h> -#include <string.h> - -#include "nsh.h" -#include "nsh_console.h" - -#ifdef CONFIG_NSH_FILE_APPS - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_fileapp - * - * Description: - * Attempt to execute the application task whose name is 'cmd' - * - * Returned Value: - * <0 If exec_builtin() fails, then the negated errno value - * is returned. - * -1 (ERROR) if the application task corresponding to 'cmd' could not - * be started (possibly because it doesn not exist). - * 0 (OK) if the application task corresponding to 'cmd' was - * and successfully started. If CONFIG_SCHED_WAITPID is - * defined, this return value also indicates that the - * application returned successful status (EXIT_SUCCESS) - * 1 If CONFIG_SCHED_WAITPID is defined, then this return value - * indicates that the application task was spawned successfully - * but returned failure exit status. - * - ****************************************************************************/ - -int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, - FAR char **argv, FAR const char *redirfile, int oflags) -{ - posix_spawn_file_actions_t file_actions; - posix_spawnattr_t attr; - pid_t pid; - int ret; - - /* Initialize the attributes file actions structure */ - - ret = posix_spawn_file_actions_init(&file_actions); - if (ret != 0) - { - /* posix_spawn_file_actions_init returns a positive errno value on - * failure. - */ - - nsh_output(vtbl, g_fmtcmdfailed, cmd, "posix_spawn_file_actions_init", - NSH_ERRNO_OF(ret)); - goto errout; - } - - ret = posix_spawnattr_init(&attr); - if (ret != 0) - { - /* posix_spawnattr_init returns a positive errno value on failure. */ - - nsh_output(vtbl, g_fmtcmdfailed, cmd, "posix_spawnattr_init", - NSH_ERRNO); - goto errout_with_actions; - } - - /* Handle re-direction of output */ - - if (redirfile) - { - ret = posix_spawn_file_actions_addopen(&file_actions, 1, redirfile, - oflags, 0644); - if (ret != 0) - { - /* posix_spawn_file_actions_addopen returns a positive errno - * value on failure. - */ - - nsh_output(vtbl, g_fmtcmdfailed, cmd, - "posix_spawn_file_actions_addopen", - NSH_ERRNO); - goto errout_with_attrs; - } - } - - /* Lock the scheduler in an attempt to prevent the application from - * running until waitpid() has been called. - */ - - sched_lock(); - - /* Execute the program. posix_spawnp returns a positive errno value on - * failure. - */ - - ret = posix_spawnp(&pid, cmd, &file_actions, &attr, &argv[1], NULL); - if (ret == OK) - { - /* The application was successfully started with pre-emption disabled. - * In the simplest cases, the application will not have run because the - * the scheduler is locked. But in the case where I/O was redirected, a - * proxy task ran and broke our lock. As result, the application may - * have aso ran if its priority was higher than than the priority of - * this thread. - * - * If the application did not run to completion and if the application - * was not backgrounded, then we need to wait here for the application - * to exit. This only works works with the following options: - * - * - CONFIG_NSH_DISABLEBG - Do not run commands in background - * - CONFIG_SCHED_WAITPID - Required to run external commands in - * foreground - */ - -#ifdef CONFIG_SCHED_WAITPID - - /* CONFIG_SCHED_WAITPID is selected, so we may run the command in - * foreground unless we were specifically requested to run the command - * in background (and running commands in background is enabled). - */ - -# ifndef CONFIG_NSH_DISABLEBG - if (vtbl->np.np_bg == false) -# endif /* CONFIG_NSH_DISABLEBG */ - { - int rc = 0; - - /* Wait for the application to exit. We did lock the scheduler - * above, but that does not guarantee that the application did not - * already run to completion in the case where I/O was redirected. - * Here the scheduler will be unlocked while waitpid is waiting - * and if the application has not yet run, it will now be able to - * do so. - */ - - ret = waitpid(pid, &rc, 0); - if (ret < 0) - { - /* If the child thread does not exist, waitpid() will return - * the error ECHLD. Since we know that the task was successfully - * started, this must be one of the cases described above; we - * have to assume that the task already exit'ed. In this case, - * we have no idea if the application ran successfully or not - * (because NuttX does not retain exit status of child tasks). - * Let's assume that is did run successfully. - */ - - int errcode = errno; - if (errcode == ECHILD) - { - ret = OK; - } - else - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "waitpid", - NSH_ERRNO_OF(errcode)); - } - } - - /* Waitpid completed the wait successfully */ - - else - { - /* We can't return the exact status (nsh has nowhere to put it) - * so just pass back zero/nonzero in a fashion that doesn't look - * like an error. - */ - - ret = (rc == 0) ? OK : 1; - - /* TODO: Set the environment variable '?' to a string corresponding - * to WEXITSTATUS(rc) so that $? will expand to the exit status of - * the most recently executed task. - */ - } - } -# ifndef CONFIG_NSH_DISABLEBG - else -# endif /* CONFIG_NSH_DISABLEBG */ -#endif /* CONFIG_SCHED_WAITPID */ - - /* We get here if either: - * - * - CONFIG_SCHED_WAITPID is not selected meaning that all commands - * have to be run in background, or - * - CONFIG_SCHED_WAITPID and CONFIG_NSH_DISABLEBG are both selected, but the - * user requested to run the command in background. - * - * NOTE that the case of a) CONFIG_SCHED_WAITPID is not selected and - * b) CONFIG_NSH_DISABLEBG selected cannot be supported. In that event, all - * commands will have to run in background. The waitpid() API must be - * available to support running the command in foreground. - */ - -#if !defined(CONFIG_SCHED_WAITPID) || !defined(CONFIG_NSH_DISABLEBG) - { - struct sched_param param; - sched_getparam(ret, ¶m); - nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority); - - /* Backgrounded commands always 'succeed' as long as we can start - * them. - */ - - ret = OK; - } -#endif /* !CONFIG_SCHED_WAITPID || !CONFIG_NSH_DISABLEBG */ - } - - sched_unlock(); - - /* Free attibutes and file actions. Ignoring return values in the case - * of an error. - */ - -errout_with_actions: - (void)posix_spawn_file_actions_destroy(&file_actions); - -errout_with_attrs: - (void)posix_spawnattr_destroy(&attr); - -errout: - /* Most posix_spawn interfaces return a positive errno value on failure - * and do not set the errno variable. - */ - - if (ret > 0) - { - /* Set the errno value and return -1 */ - - set_errno(ret); - ret = ERROR; - } - else if (ret < 0) - { - /* Return -1 on failure. errno should have been set. */ - - ret = ERROR; - } - - return ret; -} - -#endif /* CONFIG_NSH_FILE_APPS */ diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c deleted file mode 100644 index 83717e416..000000000 --- a/apps/nshlib/nsh_fscmds.c +++ /dev/null @@ -1,1315 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_fscmds.c - * - * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <stdint.h> -#include <stdbool.h> - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# include <sys/stat.h> -# include <fcntl.h> -# if !defined(CONFIG_DISABLE_MOUNTPOINT) -# ifdef CONFIG_FS_READABLE /* Need at least one filesytem in configuration */ -# include <sys/mount.h> -# include <nuttx/ramdisk.h> -# endif -# ifdef CONFIG_FS_FAT -# include <nuttx/fs/mkfatfs.h> -# endif -# ifdef CONFIG_NFS -# include <sys/socket.h> -# include <netinet/in.h> -# include <nuttx/fs/nfs.h> -# endif -# ifdef CONFIG_RAMLOG_SYSLOG -# include <nuttx/ramlog.h> -# endif -#endif -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <dirent.h> -#include <limits.h> -#include <libgen.h> -#include <errno.h> -#include <debug.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define LSFLAGS_SIZE 1 -#define LSFLAGS_LONG 2 -#define LSFLAGS_RECURSIVE 4 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -typedef int (*direntry_handler_t)(FAR struct nsh_vtbl_s *, const char *, - struct dirent *, void *); - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Common buffer for file I/O. Note the use of this common buffer precludes - * multiple copies of NSH running concurrently. It should be allocated per - * NSH instance and retained in the "vtbl" as is done for the telnet - * connection. - */ - -static char g_iobuffer[IOBUFFERSIZE]; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: trim_dir - ****************************************************************************/ - -static void trim_dir(char *arg) -{ - /* Skip any trailing '/' characters (unless it is also the leading '/') */ - - int len = strlen(arg) - 1; - while (len > 0 && arg[len] == '/') - { - arg[len] = '\0'; - len--; - } -} - -/**************************************************************************** - * Name: nsh_getdirpath - ****************************************************************************/ - -static char *nsh_getdirpath(const char *path, const char *file) -{ - /* Handle the case where all that is left is '/' */ - - if (strcmp(path, "/") == 0) - { - sprintf(g_iobuffer, "/%s", file); - } - else - { - sprintf(g_iobuffer, "%s/%s", path, file); - } - - g_iobuffer[PATH_MAX] = '\0'; - return strdup(g_iobuffer); -} - -/**************************************************************************** - * Name: foreach_direntry - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -static int foreach_direntry(FAR struct nsh_vtbl_s *vtbl, const char *cmd, const char *dirpath, - direntry_handler_t handler, void *pvarg) -{ - DIR *dirp; - int ret = OK; - - /* Trim trailing '/' from directory names */ - -#ifdef CONFIG_NSH_FULLPATH - trim_dir(arg); -#endif - - /* Open the directory */ - - dirp = opendir(dirpath); - - if (!dirp) - { - /* Failed to open the directory */ - - nsh_output(vtbl, g_fmtnosuch, cmd, "directory", dirpath); - return ERROR; - } - - /* Read each directory entry */ - - for (;;) - { - struct dirent *entryp = readdir(dirp); - if (!entryp) - { - /* Finished with this directory */ - - break; - } - - /* Call the handler with this directory entry */ - - if (handler(vtbl, dirpath, entryp, pvarg) < 0) - { - /* The handler reported a problem */ - - ret = ERROR; - break; - } - } - - closedir(dirp); - return ret; -} -#endif - -/**************************************************************************** - * Name: ls_specialdir - ****************************************************************************/ - -static inline int ls_specialdir(const char *dir) -{ - /* '.' and '..' directories are not listed like normal directories */ - - return (strcmp(dir, ".") == 0 || strcmp(dir, "..") == 0); -} - -/**************************************************************************** - * Name: ls_handler - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -static int ls_handler(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct dirent *entryp, void *pvarg) -{ - unsigned int lsflags = (unsigned int)pvarg; - int ret; - - /* Check if any options will require that we stat the file */ - - if ((lsflags & (LSFLAGS_SIZE|LSFLAGS_LONG)) != 0) - { - struct stat buf; - char *fullpath = nsh_getdirpath(dirpath, entryp->d_name); - - /* Yes, stat the file */ - - ret = stat(fullpath, &buf); - free(fullpath); - if (ret != 0) - { - nsh_output(vtbl, g_fmtcmdfailed, "ls", "stat", NSH_ERRNO); - return ERROR; - } - - if ((lsflags & LSFLAGS_LONG) != 0) - { - char details[] = "----------"; - if (S_ISDIR(buf.st_mode)) - { - details[0]='d'; - } - else if (S_ISCHR(buf.st_mode)) - { - details[0]='c'; - } - else if (S_ISBLK(buf.st_mode)) - { - details[0]='b'; - } - - if ((buf.st_mode & S_IRUSR) != 0) - { - details[1]='r'; - } - - if ((buf.st_mode & S_IWUSR) != 0) - { - details[2]='w'; - } - - if ((buf.st_mode & S_IXUSR) != 0) - { - details[3]='x'; - } - - if ((buf.st_mode & S_IRGRP) != 0) - { - details[4]='r'; - } - - if ((buf.st_mode & S_IWGRP) != 0) - { - details[5]='w'; - } - - if ((buf.st_mode & S_IXGRP) != 0) - { - details[6]='x'; - } - - if ((buf.st_mode & S_IROTH) != 0) - { - details[7]='r'; - } - - if ((buf.st_mode & S_IWOTH) != 0) - { - details[8]='w'; - } - - if ((buf.st_mode & S_IXOTH) != 0) - { - details[9]='x'; - } - - nsh_output(vtbl, " %s", details); - } - - if ((lsflags & LSFLAGS_SIZE) != 0) - { - nsh_output(vtbl, "%8d", buf.st_size); - } - } - - /* then provide the filename that is common to normal and verbose output */ - -#ifdef CONFIG_NSH_FULLPATH - nsh_output(vtbl, " %s/%s", arg, entryp->d_name); -#else - nsh_output(vtbl, " %s", entryp->d_name); -#endif - - if (DIRENT_ISDIRECTORY(entryp->d_type) && !ls_specialdir(entryp->d_name)) - { - nsh_output(vtbl, "/\n"); - } - else - { - nsh_output(vtbl, "\n"); - } - return OK; -} -#endif - -/**************************************************************************** - * Name: ls_recursive - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, - struct dirent *entryp, void *pvarg) -{ - int ret = OK; - - /* Is this entry a directory (and not one of the special directories, . and ..)? */ - - if (DIRENT_ISDIRECTORY(entryp->d_type) && !ls_specialdir(entryp->d_name)) - { - /* Yes.. */ - - char *newpath; - newpath = nsh_getdirpath(dirpath, entryp->d_name); - - /* List the directory contents */ - - nsh_output(vtbl, "%s:\n", newpath); - - /* Traverse the directory */ - - ret = foreach_direntry(vtbl, "ls", newpath, ls_handler, pvarg); - if (ret == 0) - { - /* Then recurse to list each directory within the directory */ - - ret = foreach_direntry(vtbl, "ls", newpath, ls_recursive, pvarg); - free(newpath); - } - } - return ret; -} -#endif - -/**************************************************************************** - * Name: cat_common - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_CAT -static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, - FAR const char *filename) -{ - char buffer[IOBUFFERSIZE]; - int fd; - int ret = OK; - - /* Open the file for reading */ - - fd = open(filename, O_RDONLY); - if (fd < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO); - return ERROR; - } - - /* And just dump it byte for byte into stdout */ - - for (;;) - { - int nbytesread = read(fd, buffer, IOBUFFERSIZE); - - /* Check for read errors */ - - if (nbytesread < 0) - { - int errval = errno; - - /* EINTR is not an error (but will stop stop the cat) */ - -#ifndef CONFIG_DISABLE_SIGNALS - if (errval == EINTR) - { - nsh_output(vtbl, g_fmtsignalrecvd, cmd); - } - else -#endif - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "read", NSH_ERRNO_OF(errval)); - } - - ret = ERROR; - break; - } - - /* Check for data successfully read */ - - else if (nbytesread > 0) - { - int nbyteswritten = 0; - - while (nbyteswritten < nbytesread) - { - ssize_t n = nsh_write(vtbl, buffer, nbytesread); - if (n < 0) - { - int errval = errno; - - /* EINTR is not an error (but will stop stop the cat) */ - - #ifndef CONFIG_DISABLE_SIGNALS - if (errval == EINTR) - { - nsh_output(vtbl, g_fmtsignalrecvd, cmd); - } - else -#endif - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "write", NSH_ERRNO); - } - - ret = ERROR; - break; - } - else - { - nbyteswritten += n; - } - } - } - - /* Otherwise, it is the end of file */ - - else - { - break; - } - } - - (void)close(fd); - return ret; -} -#endif -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_cat - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_CAT -int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *fullpath; - int i; - int ret = OK; - - /* Loop for each file name on the command line */ - - for (i = 1; i < argc && ret == OK; i++) - { - /* Get the fullpath to the file */ - - fullpath = nsh_getfullpath(vtbl, argv[i]); - if (!fullpath) - { - ret = ERROR; - } - else - { - /* Dump the file to the console */ - - ret = cat_common(vtbl, argv[0], fullpath); - - /* Free the allocated full path */ - - nsh_freefullpath(fullpath); - } - } - - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_dmesg - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SYSLOG) && \ - defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG) -int cmd_dmesg(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - return cat_common(vtbl, argv[0], CONFIG_SYSLOG_DEVPATH); -} -#endif - -/**************************************************************************** - * Name: cmd_cp - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_CP -int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct stat buf; - char *srcpath = NULL; - char *destpath = NULL; - char *allocpath = NULL; - int oflags = O_WRONLY|O_CREAT|O_TRUNC; - int rdfd; - int wrfd; - int ret = ERROR; - - /* Get the full path to the source file */ - - srcpath = nsh_getfullpath(vtbl, argv[1]); - if (!srcpath) - { - goto errout; - } - - /* Open the source file for reading */ - - rdfd = open(srcpath, O_RDONLY); - if (rdfd < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO); - goto errout_with_srcpath; - } - - /* Get the full path to the destination file or directory */ - - destpath = nsh_getfullpath(vtbl, argv[2]); - if (!destpath) - { - goto errout_with_rdfd; - } - - /* Check if the destination is a directory */ - - ret = stat(destpath, &buf); - if (ret == 0) - { - /* Something exists here... is it a directory? */ - - if (S_ISDIR(buf.st_mode)) - { - /* Yes, it is a directory. Remove any trailing '/' characters from the path */ - - trim_dir(argv[2]); - - /* Construct the full path to the new file */ - - allocpath = nsh_getdirpath(argv[2], basename(argv[1]) ); - if (!allocpath) - { - nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]); - goto errout_with_destpath; - } - - /* Open then dest for writing */ - - nsh_freefullpath(destpath); - destpath = allocpath; - } - else if (!S_ISREG(buf.st_mode)) - { - /* Maybe it is a driver? */ - - oflags = O_WRONLY; - } - } - - /* Now open the destination */ - - wrfd = open(destpath, oflags, 0666); - if (wrfd < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO); - goto errout_with_allocpath; - } - - /* Now copy the file */ - - for (;;) - { - int nbytesread; - int nbyteswritten; - - do - { - nbytesread = read(rdfd, g_iobuffer, IOBUFFERSIZE); - if (nbytesread == 0) - { - /* End of file */ - - ret = OK; - goto errout_with_wrfd; - } - else if (nbytesread < 0) - { - /* EINTR is not an error (but will still stop the copy) */ - -#ifndef CONFIG_DISABLE_SIGNALS - if (errno == EINTR) - { - nsh_output(vtbl, g_fmtsignalrecvd, argv[0]); - } - else -#endif - { - /* Read error */ - - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO); - } - goto errout_with_wrfd; - } - } - while (nbytesread <= 0); - - do - { - nbyteswritten = write(wrfd, g_iobuffer, nbytesread); - if (nbyteswritten >= 0) - { - nbytesread -= nbyteswritten; - } - else - { - /* EINTR is not an error (but will still stop the copy) */ - -#ifndef CONFIG_DISABLE_SIGNALS - if (errno == EINTR) - { - nsh_output(vtbl, g_fmtsignalrecvd, argv[0]); - } - else -#endif - { - /* Read error */ - - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO); - } - goto errout_with_wrfd; - } - } - while (nbytesread > 0); - } - -errout_with_wrfd: - close(wrfd); - -errout_with_allocpath: - if (allocpath) - { - free(allocpath); - } - -errout_with_destpath: - if (destpath && !allocpath) - { - nsh_freefullpath(destpath); - } - -errout_with_rdfd: - close(rdfd); - -errout_with_srcpath: - if (srcpath) - { - nsh_freefullpath(srcpath); - } -errout: - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_losetup - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) -#ifndef CONFIG_NSH_DISABLE_LOSETUP -int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *loopdev = NULL; - char *filepath = NULL; - bool teardown = false; - bool readonly = false; - off_t offset = 0; - bool badarg = false; - int ret = ERROR; - int option; - - /* Get the losetup options: Two forms are supported: - * - * losetup -d <loop-device> - * losetup [-o <offset>] [-r] <loop-device> <filename> - * - * NOTE that the -o and -r options are accepted with the -d option, but - * will be ignored. - */ - - while ((option = getopt(argc, argv, "d:o:r")) != ERROR) - { - switch (option) - { - case 'd': - loopdev = nsh_getfullpath(vtbl, optarg); - teardown = true; - break; - - case 'o': - offset = atoi(optarg); - break; - - case 'r': - readonly = true; - break; - - case '?': - default: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - break; - } - } - - /* If a bad argument was encountered, then return without processing the command */ - - if (badarg) - { - goto errout_with_paths; - } - - /* If this is not a tear down operation, then additional command line - * parameters are required. - */ - - if (!teardown) - { - /* There must be two arguments on the command line after the options */ - - if (optind + 1 < argc) - { - loopdev = nsh_getfullpath(vtbl, argv[optind]); - optind++; - - filepath = nsh_getfullpath(vtbl, argv[optind]); - optind++; - } - else - { - nsh_output(vtbl, g_fmtargrequired, argv[0]); - goto errout_with_paths; - } - } - - /* There should be nothing else on the command line */ - - if (optind < argc) - { - nsh_output(vtbl, g_fmttoomanyargs, argv[0]); - goto errout_with_paths; - } - - /* Perform the teardown operation */ - - if (teardown) - { - /* Tear down the loop device. */ - - ret = loteardown(loopdev); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "loteardown", NSH_ERRNO_OF(-ret)); - goto errout_with_paths; - } - } - else - { - /* Set up the loop device */ - - ret = losetup(loopdev, filepath, 512, offset, readonly); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "losetup", NSH_ERRNO_OF(-ret)); - goto errout_with_paths; - } - } - - /* Free memory */ - -errout_with_paths: - if (loopdev) - { - free(loopdev); - } - - if (filepath) - { - free(filepath); - } - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_ls - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_LS -int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - const char *relpath; - unsigned int lsflags = 0; - char *fullpath; - bool badarg = false; - int ret; - - /* Get the ls options */ - - int option; - while ((option = getopt(argc, argv, "lRs")) != ERROR) - { - switch (option) - { - case 'l': - lsflags |= (LSFLAGS_SIZE|LSFLAGS_LONG); - break; - - case 'R': - lsflags |= LSFLAGS_RECURSIVE; - break; - - case 's': - lsflags |= LSFLAGS_SIZE; - break; - - case '?': - default: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - break; - } - } - - /* If a bad argument was encountered, then return without processing the command */ - - if (badarg) - { - return ERROR; - } - - /* There may be one argument after the options */ - - if (optind + 1 < argc) - { - nsh_output(vtbl, g_fmttoomanyargs, argv[0]); - return ERROR; - } - else if (optind >= argc) - { -#ifndef CONFIG_DISABLE_ENVIRON - relpath = nsh_getcwd(); -#else - nsh_output(vtbl, g_fmtargrequired, argv[0]); - return ERROR; -#endif - } - else - { - relpath = argv[optind]; - } - - /* Get the fullpath to the directory */ - - fullpath = nsh_getfullpath(vtbl, relpath); - if (!fullpath) - { - return ERROR; - } - - /* List the directory contents */ - - nsh_output(vtbl, "%s:\n", fullpath); - ret = foreach_direntry(vtbl, "ls", fullpath, ls_handler, (void*)lsflags); - if (ret == OK && (lsflags & LSFLAGS_RECURSIVE) != 0) - { - /* Then recurse to list each directory within the directory */ - - ret = foreach_direntry(vtbl, "ls", fullpath, ls_recursive, (void*)lsflags); - } - nsh_freefullpath(fullpath); - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_mkdir - ****************************************************************************/ - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -#ifndef CONFIG_NSH_DISABLE_MKDIR -int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *fullpath = nsh_getfullpath(vtbl, argv[1]); - int ret = ERROR; - - if (fullpath) - { - ret = mkdir(fullpath, 0777); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkdir", NSH_ERRNO); - } - nsh_freefullpath(fullpath); - } - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_mkfatfs - ****************************************************************************/ - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT) -#ifndef CONFIG_NSH_DISABLE_MKFATFS -int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct fat_format_s fmt = FAT_FORMAT_INITIALIZER; - char *fullpath = nsh_getfullpath(vtbl, argv[1]); - int ret = ERROR; - - if (fullpath) - { - ret = mkfatfs(fullpath, &fmt); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfatfs", NSH_ERRNO); - } - nsh_freefullpath(fullpath); - } - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_mkfifo - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_MKFIFO -int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *fullpath = nsh_getfullpath(vtbl, argv[1]); - int ret = ERROR; - - if (fullpath) - { - ret = mkfifo(fullpath, 0777); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfifo", NSH_ERRNO); - } - nsh_freefullpath(fullpath); - } - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_mkrd - ****************************************************************************/ - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -#ifndef CONFIG_NSH_DISABLE_MKRD -int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - const char *fmt; - uint8_t *buffer; - uint32_t nsectors; - bool badarg = false; - int sectsize = 512; - int minor = 0; - int ret; - - /* Get the mkrd options */ - - int option; - while ((option = getopt(argc, argv, ":m:s:")) != ERROR) - { - switch (option) - { - case 'm': - minor = atoi(optarg); - if (minor < 0 || minor > 255) - { - nsh_output(vtbl, g_fmtargrange, argv[0]); - badarg = true; - } - break; - - case 's': - sectsize = atoi(optarg); - if (minor < 0 || minor > 16384) - { - nsh_output(vtbl, g_fmtargrange, argv[0]); - badarg = true; - } - break; - - case ':': - nsh_output(vtbl, g_fmtargrequired, argv[0]); - badarg = true; - break; - - case '?': - default: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - break; - } - } - - /* If a bad argument was encountered, then return without processing the command */ - - if (badarg) - { - return ERROR; - } - - /* There should be exactly on parameter left on the command-line */ - - if (optind == argc-1) - { - nsectors = (uint32_t)atoi(argv[optind]); - } - else if (optind >= argc) - { - fmt = g_fmttoomanyargs; - goto errout_with_fmt; - } - else - { - fmt = g_fmtargrequired; - goto errout_with_fmt; - } - - /* Allocate the memory backing up the ramdisk */ - - buffer = (uint8_t*)malloc(sectsize * nsectors); - if (!buffer) - { - fmt = g_fmtcmdoutofmemory; - goto errout_with_fmt; - } - -#ifdef CONFIG_DEBUG_VERBOSE - memset(buffer, 0, sectsize * nsectors); -#endif - dbg("RAMDISK at %p\n", buffer); - - /* Then register the ramdisk */ - - ret = ramdisk_register(minor, buffer, nsectors, sectsize, true); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ramdisk_register", NSH_ERRNO_OF(-ret)); - free(buffer); - return ERROR; - } - return ret; - -errout_with_fmt: - nsh_output(vtbl, fmt, argv[0]); - return ERROR; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_mv - ****************************************************************************/ - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -#ifndef CONFIG_NSH_DISABLE_MV -int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *oldpath; - char *newpath; - int ret; - - /* Get the full path to the old and new file paths */ - - oldpath = nsh_getfullpath(vtbl, argv[1]); - if (!oldpath) - { - return ERROR; - } - - newpath = nsh_getfullpath(vtbl, argv[2]); - if (!newpath) - { - nsh_freefullpath(newpath); - return ERROR; - } - - /* Perform the mount */ - - ret = rename(oldpath, newpath); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rename", NSH_ERRNO); - } - - /* Free the file paths */ - - nsh_freefullpath(oldpath); - nsh_freefullpath(newpath); - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_rm - ****************************************************************************/ - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -#ifndef CONFIG_NSH_DISABLE_RM -int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *fullpath = nsh_getfullpath(vtbl, argv[1]); - int ret = ERROR; - - if (fullpath) - { - ret = unlink(fullpath); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "unlink", NSH_ERRNO); - } - nsh_freefullpath(fullpath); - } - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_rmdir - ****************************************************************************/ - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -#ifndef CONFIG_NSH_DISABLE_RMDIR -int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *fullpath = nsh_getfullpath(vtbl, argv[1]); - int ret = ERROR; - - if (fullpath) - { - ret = rmdir(fullpath); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rmdir", NSH_ERRNO); - } - nsh_freefullpath(fullpath); - } - return ret; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_sh - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT) -#ifndef CONFIG_NSH_DISABLE_SH -int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - return nsh_script(vtbl, argv[0], argv[1]); -} -#endif -#endif - - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_CMP -int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *path1 = NULL; - char *path2 = NULL; - int fd1 = -1, fd2 = -1; - int ret = ERROR; - unsigned total_read = 0; - - /* Get the full path to the two files */ - - path1 = nsh_getfullpath(vtbl, argv[1]); - if (!path1) - { - goto errout; - } - - path2 = nsh_getfullpath(vtbl, argv[2]); - if (!path2) - { - goto errout; - } - - /* Open the files for reading */ - fd1 = open(path1, O_RDONLY); - if (fd1 < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO); - goto errout; - } - - fd2 = open(path2, O_RDONLY); - if (fd2 < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO); - goto errout; - } - - for (;;) - { - char buf1[128]; - char buf2[128]; - - int nbytesread1 = read(fd1, buf1, sizeof(buf1)); - int nbytesread2 = read(fd2, buf2, sizeof(buf2)); - - if (nbytesread1 < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO); - goto errout; - } - - if (nbytesread2 < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO); - goto errout; - } - - total_read += nbytesread1>nbytesread2?nbytesread2:nbytesread1; - - if (nbytesread1 != nbytesread2 || memcmp(buf1, buf2, nbytesread1) != 0) - { - nsh_output(vtbl, "files differ: byte %u\n", total_read); - goto errout; - } - - if (nbytesread1 < sizeof(buf1)) break; - } - - ret = OK; - -errout: - if (fd1 != -1) close(fd1); - if (fd2 != -1) close(fd2); - return ret; -} -#endif -#endif diff --git a/apps/nshlib/nsh_init.c b/apps/nshlib/nsh_init.c deleted file mode 100644 index 7c7e78ea1..000000000 --- a/apps/nshlib/nsh_init.c +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_init.c - * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include "nsh.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_initialize - * - * Description: - * This nterfaces is used to initialize the NuttShell (NSH). - * nsh_initialize() should be called one during application start-up prior - * to executing either nsh_consolemain() or nsh_telnetstart(). - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -void nsh_initialize(void) -{ - /* Mount the /etc filesystem */ - - (void)nsh_romfsetc(); - - /* Perform architecture-specific initialization (if available) */ - - (void)nsh_archinitialize(); - - /* Bring up the network */ - - (void)nsh_netinit(); -} - diff --git a/apps/nshlib/nsh_mmcmds.c b/apps/nshlib/nsh_mmcmds.c deleted file mode 100644 index 545ae60ad..000000000 --- a/apps/nshlib/nsh_mmcmds.c +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_mmcmds.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_free - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_FREE -int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct mallinfo mem; - -#ifdef CONFIG_CAN_PASS_STRUCTS - mem = mallinfo(); -#else - (void)mallinfo(&mem); -#endif - - nsh_output(vtbl, " total used free largest\n"); - nsh_output(vtbl, "Mem: %11d%11d%11d%11d\n", - mem.arena, mem.uordblks, mem.fordblks, mem.mxordblk); - - return OK; -} -#endif /* !CONFIG_NSH_DISABLE_FREE */ diff --git a/apps/nshlib/nsh_mntcmds.c b/apps/nshlib/nsh_mntcmds.c deleted file mode 100644 index f8e3a142a..000000000 --- a/apps/nshlib/nsh_mntcmds.c +++ /dev/null @@ -1,467 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_mntcmds.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/types.h> -#include <sys/mount.h> -#include <sys/statfs.h> - -#include <stdint.h> -#include <stdbool.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/fs/nfs.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: df_handler - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ - defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) -static int df_handler(FAR const char *mountpoint, - FAR struct statfs *statbuf, FAR void *arg) -{ - FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg; - - DEBUGASSERT(mountpoint && statbuf && vtbl); - - nsh_output(vtbl, "%6ld %8ld %8ld %8ld %s\n", - statbuf->f_bsize, statbuf->f_blocks, - statbuf->f_blocks - statbuf->f_bavail, statbuf->f_bavail, - mountpoint); - - return OK; -} -#endif - -/**************************************************************************** - * Name: mount_handler - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ - defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) -static int mount_handler(FAR const char *mountpoint, - FAR struct statfs *statbuf, FAR void *arg) -{ - FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg; - FAR const char *fstype; - - DEBUGASSERT(mountpoint && statbuf && vtbl); - - /* Get the file system type */ - - switch (statbuf->f_type) - { -#ifdef CONFIG_FS_FAT - case MSDOS_SUPER_MAGIC: - fstype = "vfat"; - break; -#endif - -#ifdef CONFIG_FS_ROMFS - case ROMFS_MAGIC: - fstype = "romfs"; - break; -#endif - -#ifdef CONFIG_FS_BINFS - case BINFS_MAGIC: - fstype = "binfs"; - break; -#endif - -#ifdef CONFIG_FS_NXFFS - case NXFFS_MAGIC: - fstype = "nxffs"; - break; -#endif - -#ifdef CONFIG_NFS - case NFS_SUPER_MAGIC: - fstype = "nfs"; - break; -#endif - - default: - fstype = "Unrecognized"; - break; - } - - nsh_output(vtbl, " %s type %s\n", mountpoint, fstype); - return OK; -} -#endif - -/**************************************************************************** - * Name: mount_show - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ - defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) -static inline int mount_show(FAR struct nsh_vtbl_s *vtbl, FAR const char *progname) -{ - return foreach_mountpoint(mount_handler, (FAR void *)vtbl); -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_df - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ - defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF) -int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - nsh_output(vtbl, " Block Number\n"); - nsh_output(vtbl, " Size Blocks Used Available Mounted on\n"); - - return foreach_mountpoint(df_handler, (FAR void *)vtbl); -} -#endif - -/**************************************************************************** - * Name: cmd_mount - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ - defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) -int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - FAR const char *source; - FAR char *fullsource; - FAR const char *target; - FAR char *fulltarget; - FAR const char *filesystem = NULL; - bool badarg = false; - int option; - int ret; - - /* The mount command behaves differently if no parameters are provided */ - - if (argc < 2) - { - return mount_show(vtbl, argv[0]); - } - - /* Get the mount options. NOTE: getopt() is not thread safe nor re-entrant. - * To keep its state proper for the next usage, it is necessary to parse to - * the end of the line even if an error occurs. If an error occurs, this - * logic just sets 'badarg' and continues. - */ - - while ((option = getopt(argc, argv, ":t:")) != ERROR) - { - switch (option) - { - case 't': - filesystem = optarg; - break; - - case ':': - nsh_output(vtbl, g_fmtargrequired, argv[0]); - badarg = true; - break; - - case '?': - default: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - break; - } - } - - /* If a bad argument was encountered, then return without processing the - * command. - */ - - if (badarg) - { - return ERROR; - } - - /* There may be one or two required arguments after the options: the source - * and target paths. Some file systems do not require the source parameter - * so if there is only one parameter left, it must be the target. - */ - - if (optind >= argc) - { - nsh_output(vtbl, g_fmtargrequired, argv[0]); - return ERROR; - } - - source = NULL; - target = argv[optind]; - optind++; - - if (optind < argc) - { - source = target; - target = argv[optind]; - optind++; - - if (optind < argc) - { - nsh_output(vtbl, g_fmttoomanyargs, argv[0]); - return ERROR; - } - } - - /* While the above parsing for the -t argument looks nice, the -t argument - * not really optional. - */ - - if (!filesystem) - { - nsh_output(vtbl, g_fmtargrequired, argv[0]); - return ERROR; - } - - /* The source and target paths might be relative to the current - * working directory. - */ - - fullsource = NULL; - fulltarget = NULL; - - if (source) - { - fullsource = nsh_getfullpath(vtbl, source); - if (!fullsource) - { - return ERROR; - } - } - - fulltarget = nsh_getfullpath(vtbl, target); - if (!fulltarget) - { - ret = ERROR; - goto errout; - } - - /* Perform the mount */ - - ret = mount(fullsource, fulltarget, filesystem, 0, NULL); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO); - } - -errout: - if (fullsource) - { - nsh_freefullpath(fullsource); - } - - if (fulltarget) - { - nsh_freefullpath(fulltarget); - } - - return ret; -} -#endif - -/**************************************************************************** - * Name: cmd_nfsmount - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ - defined(CONFIG_NET) && defined(CONFIG_NFS) && !defined(CONFIG_NSH_DISABLE_NFSMOUNT) -int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct nfs_args data; - FAR char *address; - FAR char *lpath; - FAR char *rpath; - bool badarg = false; -#ifdef CONFIG_NET_IPv6 - FAR struct sockaddr_in6 *sin; - struct in6_addr inaddr; -#else - FAR struct sockaddr_in *sin; - struct in_addr inaddr; -#endif - int ret; - - /* If a bad argument was encountered, then return without processing the - * command. - */ - - if (badarg) - { - return ERROR; - } - - /* The fist argument on the command line should be the NFS server IP address - * in standard IPv4 (or IPv6) dot format. - */ - - address = argv[1]; - if (!address) - { - return ERROR; - } - - /* The local mount point path (lpath) might be relative to the current working - * directory. - */ - - lpath = nsh_getfullpath(vtbl, argv[2]); - if (!lpath) - { - return ERROR; - } - - /* Get the remote mount point path */ - - rpath = argv[3]; - - /* Convert the IP address string into its binary form */ - -#ifdef CONFIG_NET_IPv6 - ret = inet_pton(AF_INET6, address, &inaddr); -#else - ret = inet_pton(AF_INET, address, &inaddr); -#endif - if (ret != 1) - { - nsh_freefullpath(lpath); - return ERROR; - } - - /* Place all of the NFS arguements into the nfs_args structure */ - - memset(&data, 0, sizeof(data)); - -#ifdef CONFIG_NET_IPv6 - sin = (FAR struct sockaddr_in6 *)&data.addr; - sin->sin_family = AF_INET6; - sin->sin_port = htons(NFS_PMAPPORT); - memcpy(&sin->sin6_addr, &inaddr, sizeof(struct in6_addr)); - data.addrlen = sizeof(struct sockaddr_in6); -#else - sin = (FAR struct sockaddr_in *)&data.addr; - sin->sin_family = AF_INET; - sin->sin_port = htons(NFS_PMAPPORT); - sin->sin_addr = inaddr; - data.addrlen = sizeof(struct sockaddr_in); -#endif - - data.sotype = SOCK_DGRAM; - data.path = rpath; - data.flags = 0; /* 0=Use all defaults */ - - /* Perform the mount */ - - ret = mount(NULL, lpath, "nfs", 0, (FAR void *)&data); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO); - } - - /* We no longer need the allocated mount point path */ - - nsh_freefullpath(lpath); - return ret; -} -#endif - -/**************************************************************************** - * Name: cmd_umount - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ - defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_UMOUNT) -int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *fullpath = nsh_getfullpath(vtbl, argv[1]); - int ret = ERROR; - - if (fullpath) - { - /* Perform the umount */ - - ret = umount(fullpath); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "umount", NSH_ERRNO); - } - nsh_freefullpath(fullpath); - } - - return ret; -} -#endif diff --git a/apps/nshlib/nsh_netcmds.c b/apps/nshlib/nsh_netcmds.c deleted file mode 100644 index 473045c40..000000000 --- a/apps/nshlib/nsh_netcmds.c +++ /dev/null @@ -1,1153 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_netcmds.c - * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#ifdef CONFIG_NET - -#include <sys/stat.h> /* Needed for open */ -#include <stdint.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <sched.h> -#include <fcntl.h> /* Needed for open */ -#include <libgen.h> /* Needed for basename */ -#include <errno.h> -#include <debug.h> - -#include <net/ethernet.h> -#include <netinet/ether.h> - -#include <nuttx/net/net.h> -#include <nuttx/clock.h> -#include <nuttx/net/uip/uip.h> -#include <nuttx/net/uip/uip-arch.h> - -#ifdef CONFIG_NET_STATISTICS -# include <nuttx/net/uip/uip.h> -#endif - -#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ - !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) -# include <apps/netutils/uiplib.h> -# include <apps/netutils/resolv.h> -#endif - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -# include <apps/netutils/uiplib.h> -# include <apps/netutils/tftp.h> -#endif - -#if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_WGET -# include <apps/netutils/uiplib.h> -# include <apps/netutils/webclient.h> -# endif -#endif - -#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) -# ifdef CONFIG_HAVE_GETHOSTBYNAME -# include <netdb.h> -# else -# include <apps/netutils/resolv.h> -# endif -# include <apps/netutils/dhcpc.h> -#endif - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/* Size of the ECHO data */ - -#define DEFAULT_PING_DATALEN 56 - -/* Get the larger value */ - -#ifndef MAX -# define MAX(a,b) (a > b ? a : b) -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -struct tftpc_args_s -{ - bool binary; /* true:binary ("octect") false:text ("netascii") */ - bool allocated; /* true: destpath is allocated */ - char *destpath; /* Path at destination */ - const char *srcpath; /* Path at src */ - in_addr_t ipaddr; /* Host IP address */ -}; -#endif - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ - !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) -static uint16_t g_pingid = 0; -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ping_newid - ****************************************************************************/ - -#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ - !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) -static inline uint16_t ping_newid(void) -{ - irqstate_t save = irqsave(); - uint16_t ret = ++g_pingid; - irqrestore(save); - return ret; -} -#endif - -/**************************************************************************** - * Name: uip_statistics - ****************************************************************************/ - -#if defined(CONFIG_NET_STATISTICS) && !defined(CONFIG_NSH_DISABLE_IFCONFIG) -static inline void uip_statistics(FAR struct nsh_vtbl_s *vtbl) -{ - nsh_output(vtbl, "uIP IP "); -#ifdef CONFIG_NET_TCP - nsh_output(vtbl, " TCP"); -#endif -#ifdef CONFIG_NET_UDP - nsh_output(vtbl, " UDP"); -#endif -#ifdef CONFIG_NET_ICMP - nsh_output(vtbl, " ICMP"); -#endif - nsh_output(vtbl, "\n"); - - /* Received packets */ - - nsh_output(vtbl, "Received %04x",uip_stat.ip.recv); -#ifdef CONFIG_NET_TCP - nsh_output(vtbl, " %04x",uip_stat.tcp.recv); -#endif -#ifdef CONFIG_NET_UDP - nsh_output(vtbl, " %04x",uip_stat.udp.recv); -#endif -#ifdef CONFIG_NET_ICMP - nsh_output(vtbl, " %04x",uip_stat.icmp.recv); -#endif - nsh_output(vtbl, "\n"); - - /* Dropped packets */ - - nsh_output(vtbl, "Dropped %04x",uip_stat.ip.drop); -#ifdef CONFIG_NET_TCP - nsh_output(vtbl, " %04x",uip_stat.tcp.drop); -#endif -#ifdef CONFIG_NET_UDP - nsh_output(vtbl, " %04x",uip_stat.udp.drop); -#endif -#ifdef CONFIG_NET_ICMP - nsh_output(vtbl, " %04x",uip_stat.icmp.drop); -#endif - nsh_output(vtbl, "\n"); - - nsh_output(vtbl, " IP VHL: %04x HBL: %04x\n", - uip_stat.ip.vhlerr, uip_stat.ip.hblenerr); - nsh_output(vtbl, " LBL: %04x Frg: %04x\n", - uip_stat.ip.lblenerr, uip_stat.ip.fragerr); - - nsh_output(vtbl, " Checksum %04x",uip_stat.ip.chkerr); -#ifdef CONFIG_NET_TCP - nsh_output(vtbl, " %04x",uip_stat.tcp.chkerr); -#endif -#ifdef CONFIG_NET_UDP - nsh_output(vtbl, " %04x",uip_stat.udp.chkerr); -#endif -#ifdef CONFIG_NET_ICMP - nsh_output(vtbl, " ----"); -#endif - nsh_output(vtbl, "\n"); - -#ifdef CONFIG_NET_TCP - nsh_output(vtbl, " TCP ACK: %04x SYN: %04x\n", - uip_stat.tcp.ackerr, uip_stat.tcp.syndrop); - nsh_output(vtbl, " RST: %04x %04x\n", - uip_stat.tcp.rst, uip_stat.tcp.synrst); -#endif - - nsh_output(vtbl, " Type %04x",uip_stat.ip.protoerr); -#ifdef CONFIG_NET_TCP - nsh_output(vtbl, " ----"); -#endif -#ifdef CONFIG_NET_UDP - nsh_output(vtbl, " ----"); -#endif -#ifdef CONFIG_NET_ICMP - nsh_output(vtbl, " %04x",uip_stat.icmp.typeerr); -#endif - nsh_output(vtbl, "\n"); - - /* Sent packets */ - - nsh_output(vtbl, "Sent ----",uip_stat.ip.sent); -#ifdef CONFIG_NET_TCP - nsh_output(vtbl, " %04x",uip_stat.tcp.sent); -#endif -#ifdef CONFIG_NET_UDP - nsh_output(vtbl, " %04x",uip_stat.udp.sent); -#endif -#ifdef CONFIG_NET_ICMP - nsh_output(vtbl, " %04x",uip_stat.icmp.sent); -#endif - nsh_output(vtbl, "\n"); - -#ifdef CONFIG_NET_TCP - nsh_output(vtbl, " Rexmit ---- %04x",uip_stat.tcp.rexmit); -#ifdef CONFIG_NET_UDP - nsh_output(vtbl, " ----"); -#endif -#ifdef CONFIG_NET_ICMP - nsh_output(vtbl, " ----"); -#endif - nsh_output(vtbl, "\n"); -#endif - nsh_output(vtbl, "\n"); -} -#else -# define uip_statistics(vtbl) -#endif - - -/**************************************************************************** - * Name: ifconfig_callback - ****************************************************************************/ - -int ifconfig_callback(FAR struct uip_driver_s *dev, void *arg) -{ - struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg; - struct in_addr addr; - bool is_running = false; - int ret; - - ret = uip_getifstatus(dev->d_ifname,&is_running); - if (ret != OK) - { - nsh_output(vtbl, "\tGet %s interface flags error: %d\n", - dev->d_ifname, ret); - } - - nsh_output(vtbl, "%s\tHWaddr %s at %s\n", - dev->d_ifname, ether_ntoa(&dev->d_mac), (is_running)?"UP":"DOWN"); - - addr.s_addr = dev->d_ipaddr; - nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr)); - - addr.s_addr = dev->d_draddr; - nsh_output(vtbl, "DRaddr:%s ", inet_ntoa(addr)); - - addr.s_addr = dev->d_netmask; - nsh_output(vtbl, "Mask:%s\n", inet_ntoa(addr)); - -#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) - resolv_getserver(&addr); - nsh_output(vtbl, "\tDNSaddr:%s\n", inet_ntoa(addr)); -#endif - - nsh_output(vtbl, "\n"); - return OK; -} - -/**************************************************************************** - * Name: tftpc_parseargs - ****************************************************************************/ - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -int tftpc_parseargs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv, - struct tftpc_args_s *args) -{ - FAR const char *fmt = g_fmtarginvalid; - bool badarg = false; - int option; - - /* Get the ping options */ - - memset(args, 0, sizeof(struct tftpc_args_s)); - while ((option = getopt(argc, argv, ":bnf:h:")) != ERROR) - { - switch (option) - { - case 'b': - args->binary = true; - break; - - case 'n': - args->binary = false; - break; - - case 'f': - args->destpath = optarg; - break; - - case 'h': - if (!uiplib_ipaddrconv(optarg, (FAR unsigned char*)&args->ipaddr)) - { - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - } - break; - - case ':': - nsh_output(vtbl, g_fmtargrequired, argv[0]); - badarg = true; - break; - - case '?': - default: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - break; - } - } - - /* If a bad argument was encountered, then return without processing the command */ - - if (badarg) - { - return ERROR; - } - - /* There should be exactly one parameter left on the command-line */ - - if (optind == argc-1) - { - args->srcpath = argv[optind]; - } - - /* optind == argc means that there is nothing left on the command-line */ - - else if (optind >= argc) - { - fmt = g_fmtargrequired; - goto errout; - } - - /* optind < argc-1 means that there are too many arguments on the - * command-line - */ - - else - { - fmt = g_fmttoomanyargs; - goto errout; - } - - /* The HOST IP address is also required */ - - if (!args->ipaddr) - { - fmt = g_fmtargrequired; - goto errout; - } - - /* If the destpath was not provided, then we have do a little work. */ - - if (!args->destpath) - { - char *tmp1; - char *tmp2; - - /* Copy the srcpath... baseanme might modify it */ - - fmt = g_fmtcmdoutofmemory; - tmp1 = strdup(args->srcpath); - if (!tmp1) - { - goto errout; - } - - /* Get the basename of the srcpath */ - - tmp2 = basename(tmp1); - if (!tmp2) - { - free(tmp1); - goto errout; - } - - /* Use that basename as the destpath */ - - args->destpath = strdup(tmp2); - free(tmp1); - if (!args->destpath) - { - goto errout; - } - args->allocated = true; - } - - return OK; - -errout: - nsh_output(vtbl, fmt, argv[0]); - return ERROR; -} -#endif - -/**************************************************************************** - * Name: wget_callback - ****************************************************************************/ - -#if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_WGET -static void wget_callback(FAR char **buffer, int offset, int datend, - FAR int *buflen, FAR void *arg) -{ - (void)write((int)arg, &((*buffer)[offset]), datend - offset); -} -#endif -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_get - ****************************************************************************/ - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_GET -int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct tftpc_args_s args; - char *fullpath; - - /* Parse the input parameter list */ - - if (tftpc_parseargs(vtbl, argc, argv, &args) != OK) - { - return ERROR; - } - - /* Get the full path to the local file */ - - fullpath = nsh_getfullpath(vtbl, args.srcpath); - - /* Then perform the TFTP get operation */ - - if (tftpget(args.srcpath, fullpath, args.ipaddr, args.binary) != OK) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "tftpget", NSH_ERRNO); - } - - /* Release any allocated memory */ - - if (args.allocated) - { - free(args.destpath); - } - free(fullpath); - return OK; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_ifup - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_IFUPDOWN -int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - FAR char *intf = NULL; - int ret; - - if (argc != 2) - { - nsh_output(vtbl, "Please select nic_name:\n"); - netdev_foreach(ifconfig_callback, vtbl); - return OK; - } - - intf = argv[1]; - ret = uip_ifup(intf); - nsh_output(vtbl, "ifup %s...%s\n", intf, (ret == OK) ? "OK" : "Failed"); - return ret; -} -#endif - -/**************************************************************************** - * Name: cmd_ifdown - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_IFUPDOWN -int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - FAR char *intf = NULL; - int ret; - - if (argc != 2) - { - nsh_output(vtbl, "Please select nic_name:\n"); - netdev_foreach(ifconfig_callback, vtbl); - return OK; - } - - intf = argv[1]; - ret = uip_ifdown(intf); - nsh_output(vtbl, "ifdown %s...%s\n", intf, (ret == OK) ? "OK" : "Failed"); - return ret; -} -#endif - -/**************************************************************************** - * Name: cmd_ifconfig - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_IFCONFIG -int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct in_addr addr; - in_addr_t gip; - int i; - FAR char *intf = NULL; - FAR char *hostip = NULL; - FAR char *gwip = NULL; - FAR char *mask = NULL; - FAR char *tmp = NULL; - FAR char *hw = NULL; - FAR char *dns = NULL; - bool badarg = false; - uint8_t mac[IFHWADDRLEN]; -#if defined(CONFIG_NSH_DHCPC) - FAR void *handle; -#endif - - /* With one or no arguments, ifconfig simply shows the status of ethernet - * device: - * - * ifconfig - * ifconfig [nic_name] - */ - - if (argc <= 2) - { - netdev_foreach(ifconfig_callback, vtbl); - uip_statistics(vtbl); - return OK; - } - - /* If both the network interface name and an IP address are supplied as - * arguments, then ifconfig will set the address of the ethernet device: - * - * ifconfig nic_name ip_address - */ - - if (argc > 2) - { - for(i = 0; i < argc; i++) - { - if (i == 1) - { - intf = argv[i]; - } - else if (i == 2) - { - hostip = argv[i]; - } - else - { - tmp = argv[i]; - if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || !strcmp(tmp, "gateway")) - { - if (argc-1 >= i+1) - { - gwip = argv[i+1]; - i++; - } - else - { - badarg = true; - } - } - else if(!strcmp(tmp, "netmask")) - { - if (argc-1 >= i+1) - { - mask = argv[i+1]; - i++; - } - else - { - badarg = true; - } - } - else if(!strcmp(tmp, "hw")) - { - if (argc-1>=i+1) - { - hw = argv[i+1]; - i++; - badarg = !uiplib_hwmacconv(hw, mac); - } - else - { - badarg = true; - } - } - else if(!strcmp(tmp, "dns")) - { - if (argc-1 >= i+1) - { - dns = argv[i+1]; - i++; - } - else - { - badarg = true; - } - } - } - } - } - - if (badarg) - { - nsh_output(vtbl, g_fmtargrequired, argv[0]); - return ERROR; - } - - /* Set Hardware ethernet MAC addr */ - - if (hw) - { - ndbg("HW MAC: %s\n", hw); - uip_setmacaddr(intf, mac); - } - -#if defined(CONFIG_NSH_DHCPC) - if (!strcmp(hostip, "dhcp")) - { - /* Set DHCP addr */ - - ndbg("DHCPC Mode\n"); - gip = addr.s_addr = 0; - } - else -#endif - { - /* Set host IP address */ - - ndbg("Host IP: %s\n", hostip); - gip = addr.s_addr = inet_addr(hostip); - } - - uip_sethostaddr(intf, &addr); - - /* Set gateway */ - - if (gwip) - { - ndbg("Gateway: %s\n", gwip); - gip = addr.s_addr = inet_addr(gwip); - } - else - { - if (gip) - { - ndbg("Gateway: default\n"); - gip = NTOHL(gip); - gip &= ~0x000000ff; - gip |= 0x00000001; - gip = HTONL(gip); - } - - addr.s_addr = gip; - } - - uip_setdraddr(intf, &addr); - - /* Set network mask */ - - if (mask) - { - ndbg("Netmask: %s\n",mask); - addr.s_addr = inet_addr(mask); - } - else - { - ndbg("Netmask: Default\n"); - addr.s_addr = inet_addr("255.255.255.0"); - } - - uip_setnetmask(intf, &addr); - -#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) - if (dns) - { - ndbg("DNS: %s\n", dns); - addr.s_addr = inet_addr(dns); - } - else - { - ndbg("DNS: Default\n"); - addr.s_addr = gip; - } - - resolv_conf(&addr); -#endif - -#if defined(CONFIG_NSH_DHCPC) - /* Get the MAC address of the NIC */ - - if (!gip) - { - uip_getmacaddr("eth0", mac); - - /* Set up the DHCPC modules */ - - handle = dhcpc_open(&mac, IFHWADDRLEN); - - /* Get an IP address. Note that there is no logic for renewing the IP address in this - * example. The address should be renewed in ds.lease_time/2 seconds. - */ - - if (handle) - { - struct dhcpc_state ds; - - (void)dhcpc_request(handle, &ds); - uip_sethostaddr("eth0", &ds.ipaddr); - - if (ds.netmask.s_addr != 0) - { - uip_setnetmask("eth0", &ds.netmask); - } - - if (ds.default_router.s_addr != 0) - { - uip_setdraddr("eth0", &ds.default_router); - } - - if (ds.dnsaddr.s_addr != 0) - { - resolv_conf(&ds.dnsaddr); - } - - dhcpc_close(handle); - } - } -#endif - - return OK; -} -#endif - -/**************************************************************************** - * Name: cmd_ping - ****************************************************************************/ - -#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ - !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) -#ifndef CONFIG_NSH_DISABLE_PING -int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - FAR const char *fmt = g_fmtarginvalid; - const char *staddr; - uip_ipaddr_t ipaddr; - uint32_t start; - uint32_t next; - uint32_t dsec = 10; - uint32_t maxwait; - uint16_t id; - bool badarg = false; - int count = 10; - int option; - int seqno; - int replies = 0; - int elapsed; - int tmp; - int i; - - /* Get the ping options */ - - while ((option = getopt(argc, argv, ":c:i:")) != ERROR) - { - switch (option) - { - case 'c': - count = atoi(optarg); - if (count < 1 || count > 10000) - { - nsh_output(vtbl, g_fmtargrange, argv[0]); - badarg = true; - } - break; - - case 'i': - tmp = atoi(optarg); - if (tmp < 1 || tmp >= 4294) - { - nsh_output(vtbl, g_fmtargrange, argv[0]); - badarg = true; - } - else - { - dsec = 10 * tmp; - } - break; - - case ':': - nsh_output(vtbl, g_fmtargrequired, argv[0]); - badarg = true; - break; - - case '?': - default: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - break; - } - } - - /* If a bad argument was encountered, then return without processing the command */ - - if (badarg) - { - return ERROR; - } - - /* There should be exactly on parameter left on the command-line */ - - if (optind == argc-1) - { - staddr = argv[optind]; - if (dns_gethostip(staddr, &ipaddr) < 0) - { - goto errout; - } - } - else if (optind >= argc) - { - fmt = g_fmttoomanyargs; - goto errout; - } - else - { - fmt = g_fmtargrequired; - goto errout; - } - - /* Get the ID to use */ - - id = ping_newid(); - - /* The maximum wait for a response will be the larger of the inter-ping time and - * the configured maximum round-trip time. - */ - - maxwait = MAX(dsec, CONFIG_NSH_MAX_ROUNDTRIP); - - /* Loop for the specified count */ - - nsh_output(vtbl, "PING %d.%d.%d.%d %d bytes of data\n", - (ipaddr ) & 0xff, (ipaddr >> 8 ) & 0xff, - (ipaddr >> 16 ) & 0xff, (ipaddr >> 24 ) & 0xff, - DEFAULT_PING_DATALEN); - - start = g_system_timer; - for (i = 1; i <= count; i++) - { - /* Send the ECHO request and wait for the response */ - - next = g_system_timer; - seqno = uip_ping(ipaddr, id, i, DEFAULT_PING_DATALEN, maxwait); - - /* Was any response returned? We can tell if a non-negative sequence - * number was returned. - */ - - if (seqno >= 0 && seqno <= i) - { - /* Get the elapsed time from the time that the request was - * sent until the response was received. If we got a response - * to an earlier request, then fudge the elpased time. - */ - - elapsed = TICK2MSEC(g_system_timer - next); - if (seqno < i) - { - elapsed += 100 * dsec * (i - seqno); - } - - /* Report the receipt of the reply */ - - nsh_output(vtbl, "%d bytes from %s: icmp_seq=%d time=%d ms\n", - DEFAULT_PING_DATALEN, staddr, seqno, elapsed); - replies++; - } - - /* Wait for the remainder of the interval. If the last seqno<i, - * then this is a bad idea... we will probably lose the response - * to the current request! - */ - - elapsed = TICK2DSEC(g_system_timer - next); - if (elapsed < dsec) - { - usleep(100000 * (dsec - elapsed)); - } - } - - /* Get the total elapsed time */ - - elapsed = TICK2MSEC(g_system_timer - start); - - /* Calculate the percentage of lost packets */ - - tmp = (100*(count - replies) + (count >> 1)) / count; - - nsh_output(vtbl, "%d packets transmitted, %d received, %d%% packet loss, time %d ms\n", - count, replies, tmp, elapsed); - return OK; - -errout: - nsh_output(vtbl, fmt, argv[0]); - return ERROR; -} -#endif -#endif /* CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING */ - -/**************************************************************************** - * Name: cmd_put - ****************************************************************************/ - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_PUT -int cmd_put(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - struct tftpc_args_s args; - char *fullpath; - - /* Parse the input parameter list */ - - if (tftpc_parseargs(vtbl, argc, argv, &args) != OK) - { - return ERROR; - } - - /* Get the full path to the local file */ - - fullpath = nsh_getfullpath(vtbl, args.srcpath); - - /* Then perform the TFTP put operation */ - - if (tftpput(fullpath, args.destpath, args.ipaddr, args.binary) != OK) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "tftpput", NSH_ERRNO); - } - - /* Release any allocated memory */ - - if (args.allocated) - { - free(args.destpath); - } - free(fullpath); - return OK; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_wget - ****************************************************************************/ - -#if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_WGET -int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *localfile = NULL; - char *allocfile = NULL; - char *buffer = NULL; - char *fullpath = NULL; - char *url; - const char *fmt; - bool badarg = false; - int option; - int fd = -1; - int ret; - - /* Get the wget options */ - - while ((option = getopt(argc, argv, ":o:")) != ERROR) - { - switch (option) - { - case 'o': - localfile = optarg; - break; - - case ':': - nsh_output(vtbl, g_fmtargrequired, argv[0]); - badarg = true; - break; - - case '?': - default: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - badarg = true; - break; - } - } - - /* If a bad argument was encountered, then return without processing the command */ - - if (badarg) - { - return ERROR; - } - - /* There should be exactly on parameter left on the command-line */ - - if (optind == argc-1) - { - url = argv[optind]; - } - else if (optind >= argc) - { - fmt = g_fmttoomanyargs; - goto errout; - } - else - { - fmt = g_fmtargrequired; - goto errout; - } - - /* Get the local file name */ - - if (!localfile) - { - allocfile = strdup(url); - localfile = basename(allocfile); - } - - /* Get the full path to the local file */ - - fullpath = nsh_getfullpath(vtbl, localfile); - - /* Open the local file for writing */ - - fd = open(fullpath, O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (fd < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO); - ret = ERROR; - goto exit; - } - - /* Allocate an I/O buffer */ - - buffer = malloc(512); - if (!buffer) - { - fmt = g_fmtcmdoutofmemory; - goto errout; - } - - /* And perform the wget */ - - ret = wget(url, buffer, 512, wget_callback, (FAR void *)fd); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "wget", NSH_ERRNO); - goto exit; - } - - /* Free allocated resources */ - -exit: - if (fd >= 0) - { - close(fd); - } - if (allocfile) - { - free(allocfile); - } - if (fullpath) - { - free(fullpath); - } - if (buffer) - { - free(buffer); - } - return ret; - -errout: - nsh_output(vtbl, fmt, argv[0]); - ret = ERROR; - goto exit; -} -#endif -#endif - -#endif /* CONFIG_NET */ diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c deleted file mode 100644 index 58d238312..000000000 --- a/apps/nshlib/nsh_netinit.c +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_netinit.c - * - * Copyright (C) 2010-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * This is influenced by similar logic from uIP: - * - * Author: Adam Dunkels <adam@sics.se> - * Copyright (c) 2003, Adam Dunkels. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <debug.h> - -#include <net/if.h> - -#include <apps/netutils/uiplib.h> -#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) -# include <apps/netutils/resolv.h> -# include <apps/netutils/dhcpc.h> -#endif - -#include "nsh.h" - -#ifdef CONFIG_NET - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#if defined(CONFIG_NSH_DRIPADDR) && !defined(CONFIG_NSH_DNSIPADDR) -# define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_netinit - * - * Description: - * Initialize the network per the selected NuttX configuration - * - ****************************************************************************/ - -int nsh_netinit(void) -{ - struct in_addr addr; -#if defined(CONFIG_NSH_DHCPC) - FAR void *handle; -#endif -#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_NOMAC) - uint8_t mac[IFHWADDRLEN]; -#endif - -/* Many embedded network interfaces must have a software assigned MAC */ - -#ifdef CONFIG_NSH_NOMAC - mac[0] = 0x00; - mac[1] = 0xe0; - mac[2] = 0xde; - mac[3] = 0xad; - mac[4] = 0xbe; - mac[5] = 0xef; - uip_setmacaddr("eth0", mac); -#endif - - /* Set up our host address */ - -#if !defined(CONFIG_NSH_DHCPC) - addr.s_addr = HTONL(CONFIG_NSH_IPADDR); -#else - addr.s_addr = 0; -#endif - uip_sethostaddr("eth0", &addr); - - /* Set up the default router address */ - - addr.s_addr = HTONL(CONFIG_NSH_DRIPADDR); - uip_setdraddr("eth0", &addr); - - /* Setup the subnet mask */ - - addr.s_addr = HTONL(CONFIG_NSH_NETMASK); - uip_setnetmask("eth0", &addr); - -#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) - /* Set up the resolver */ - - resolv_init(); -#if defined(CONFIG_NSH_DNS) - addr.s_addr = HTONL(CONFIG_NSH_DNSIPADDR); - resolv_conf(&addr); -#endif -#endif - -#if defined(CONFIG_NSH_DHCPC) - /* Get the MAC address of the NIC */ - - uip_getmacaddr("eth0", mac); - - /* Set up the DHCPC modules */ - - handle = dhcpc_open(&mac, IFHWADDRLEN); - - /* Get an IP address. Note that there is no logic for renewing the IP address in this - * example. The address should be renewed in ds.lease_time/2 seconds. - */ - - if (handle) - { - struct dhcpc_state ds; - (void)dhcpc_request(handle, &ds); - uip_sethostaddr("eth0", &ds.ipaddr); - if (ds.netmask.s_addr != 0) - { - uip_setnetmask("eth0", &ds.netmask); - } - if (ds.default_router.s_addr != 0) - { - uip_setdraddr("eth0", &ds.default_router); - } - if (ds.dnsaddr.s_addr != 0) - { - resolv_conf(&ds.dnsaddr); - } - dhcpc_close(handle); - } -#endif - - return OK; -} - -#endif /* CONFIG_NET */ diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c deleted file mode 100644 index 4d8f04b23..000000000 --- a/apps/nshlib/nsh_parse.c +++ /dev/null @@ -1,1645 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_parse.c - * - * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/stat.h> - -#include <stdint.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <sched.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/version.h> - -#ifndef CONFIG_NSH_DISABLEBG -# include <pthread.h> -#endif - -#ifdef CONFIG_NSH_BUILTIN_APPS -# include <nuttx/binfmt/builtin.h> -#endif - -#include <apps/nsh.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Argument list size - * - * argv[0]: The command name. - * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS) - * argv[argc-3]: Possibly '>' or '>>' - * argv[argc-2]: Possibly <file> - * argv[argc-1]: Possibly '&' (if pthreads are enabled) - * argv[argc]: NULL terminating pointer - * - * Maximum size is CONFIG_NSH_MAXARGUMENTS+5 - */ - -#ifndef CONFIG_NSH_DISABLEBG -# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+5) -#else -# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+4) -#endif - -/* Help command summary layout */ - -#define MAX_CMDLEN 12 -#define CMDS_PER_LINE 6 - -#define NUM_CMDS ((sizeof(g_cmdmap)/sizeof(struct cmdmap_s)) - 1) -#define NUM_CMD_ROWS ((NUM_CMDS + (CMDS_PER_LINE-1)) / CMDS_PER_LINE) - -/**************************************************************************** - * Private 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 */ -}; - -#ifndef CONFIG_NSH_DISABLEBG -struct cmdarg_s -{ - FAR struct nsh_vtbl_s *vtbl; /* For front-end interaction */ - int fd; /* FD for output redirection */ - int argc; /* Number of arguments in argv */ - FAR char *argv[MAX_ARGV_ENTRIES]; /* Argument list */ -}; -#endif - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_HELP -static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif - -#ifndef CONFIG_NSH_DISABLE_EXIT -static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char g_delim[] = " \t\n"; -static const char g_redirect1[] = ">"; -static const char g_redirect2[] = ">>"; -static const char g_exitstatus[] = "$?"; -static const char g_success[] = "0"; -static const char g_failure[] = "1"; - -static const struct cmdmap_s g_cmdmap[] = -{ -#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST) - { "[", cmd_lbracket, 4, CONFIG_NSH_MAXARGUMENTS, "<expression> ]" }, -#endif - -#ifndef CONFIG_NSH_DISABLE_HELP - { "?", cmd_help, 1, 1, NULL }, -#endif - -#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64) -# ifndef CONFIG_NSH_DISABLE_BASE64DEC - { "base64dec", cmd_base64decode, 2, 4, "[-w] [-f] <string or filepath>" }, -# endif -# ifndef CONFIG_NSH_DISABLE_BASE64ENC - { "base64enc", cmd_base64encode, 2, 4, "[-w] [-f] <string or filepath>" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_CAT - { "cat", cmd_cat, 2, CONFIG_NSH_MAXARGUMENTS, "<path> [<path> [<path> ...]]" }, -# endif -#ifndef CONFIG_DISABLE_ENVIRON -# ifndef CONFIG_NSH_DISABLE_CD - { "cd", cmd_cd, 1, 2, "[<dir-path>|-|~|..]" }, -# endif -#endif -# ifndef CONFIG_NSH_DISABLE_CP - { "cp", cmd_cp, 3, 3, "<source-path> <dest-path>" }, -# endif -# ifndef CONFIG_NSH_DISABLE_CMP - { "cmp", cmd_cmp, 3, 3, "<path1> <path2>" }, -# endif -#endif - -#if defined (CONFIG_RTC) && !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_NSH_DISABLE_DATE) - { "date", cmd_date, 1, 3, "[-s \"MMM DD HH:MM:SS YYYY\"]" }, -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_NSH_DISABLE_DD) - { "dd", cmd_dd, 3, 6, "if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]" }, -# endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ - defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF) - { "df", cmd_df, 1, 1, NULL }, -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SYSLOG) && \ - defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG) - { "dmesg", cmd_dmesg, 1, 1, NULL }, -#endif - -#ifndef CONFIG_NSH_DISABLE_ECHO -# ifndef CONFIG_DISABLE_ENVIRON - { "echo", cmd_echo, 0, CONFIG_NSH_MAXARGUMENTS, "[<string|$name> [<string|$name>...]]" }, -# else - { "echo", cmd_echo, 0, CONFIG_NSH_MAXARGUMENTS, "[<string> [<string>...]]" }, -# endif -#endif - -#ifndef CONFIG_NSH_DISABLE_EXEC - { "exec", cmd_exec, 2, 3, "<hex-address>" }, -#endif -#ifndef CONFIG_NSH_DISABLE_EXIT - { "exit", cmd_exit, 1, 1, NULL }, -#endif - -#ifndef CONFIG_NSH_DISABLE_FREE - { "free", cmd_free, 1, 1, NULL }, -#endif - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_GET - { "get", cmd_get, 4, 7, "[-b|-n] [-f <local-path>] -h <ip-address> <remote-path>" }, -# endif -#endif - -#ifndef CONFIG_NSH_DISABLE_HELP -# ifdef CONFIG_NSH_HELP_TERSE - { "help", cmd_help, 1, 2, "[<cmd>]" }, -#else - { "help", cmd_help, 1, 3, "[-v] [<cmd>]" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#ifndef CONFIG_NSH_DISABLE_HEXDUMP - { "hexdump", cmd_hexdump, 2, 2, "<file or device>" }, -#endif -#endif - -#ifdef CONFIG_NET -# ifndef CONFIG_NSH_DISABLE_IFCONFIG - { "ifconfig", cmd_ifconfig, 1, 11, "[nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]" }, -# endif -# ifndef CONFIG_NSH_DISABLE_IFUPDOWN - { "ifdown", cmd_ifdown, 2, 2, "<nic_name>" }, - { "ifup", cmd_ifup, 2, 2, "<nic_name>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_SIGNALS -# ifndef CONFIG_NSH_DISABLE_KILL - { "kill", cmd_kill, 3, 3, "-<signal> <pid>" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) -# ifndef CONFIG_NSH_DISABLE_LOSETUP - { "losetup", cmd_losetup, 3, 6, "[-d <dev-path>] | [[-o <offset>] [-r] <dev-path> <file-path>]" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_LS - { "ls", cmd_ls, 1, 5, "[-lRs] <dir-path>" }, -# endif -#endif - -#ifndef CONFIG_NSH_DISABLE_MB - { "mb", cmd_mb, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, -#endif - -#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5) -# ifndef CONFIG_NSH_DISABLE_MD5 - { "md5", cmd_md5, 2, 3, "[-f] <string or filepath>" }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -# ifndef CONFIG_NSH_DISABLE_MKDIR - { "mkdir", cmd_mkdir, 2, 2, "<path>" }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT) -# ifndef CONFIG_NSH_DISABLE_MKFATFS - { "mkfatfs", cmd_mkfatfs, 2, 2, "<path>" }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_MKFIFO - { "mkfifo", cmd_mkfifo, 2, 2, "<path>" }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -# ifndef CONFIG_NSH_DISABLE_MKRD - { "mkrd", cmd_mkrd, 2, 6, "[-m <minor>] [-s <sector-size>] <nsectors>" }, -# endif -#endif - -#ifndef CONFIG_NSH_DISABLE_MH - { "mh", cmd_mh, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) -# ifndef CONFIG_NSH_DISABLE_MOUNT - { "mount", cmd_mount, 1, 5, "[-t <fstype> [<block-device>] <mount-point>]" }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -# ifndef CONFIG_NSH_DISABLE_MV - { "mv", cmd_mv, 3, 3, "<old-path> <new-path>" }, -# endif -#endif - -#ifndef CONFIG_NSH_DISABLE_MW - { "mw", cmd_mw, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ - defined(CONFIG_NET) && defined(CONFIG_NFS) -# ifndef CONFIG_NSH_DISABLE_NFSMOUNT - { "nfsmount", cmd_nfsmount, 4, 4, "<server-address> <mount-point> <remote-path>" }, -# endif -#endif - -#if defined(CONFIG_NET) && defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ - !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) -# ifndef CONFIG_NSH_DISABLE_PING - { "ping", cmd_ping, 2, 6, "[-c <count>] [-i <interval>] <ip-address>" }, -# endif -#endif - -#ifndef CONFIG_NSH_DISABLE_PS - { "ps", cmd_ps, 1, 1, NULL }, -#endif - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_PUT - { "put", cmd_put, 4, 7, "[-b|-n] [-f <remote-path>] -h <ip-address> <local-path>" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -# ifndef CONFIG_NSH_DISABLE_PWD - { "pwd", cmd_pwd, 1, 1, NULL }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -# ifndef CONFIG_NSH_DISABLE_RM - { "rm", cmd_rm, 2, 2, "<file-path>" }, -# endif -# ifndef CONFIG_NSH_DISABLE_RMDIR - { "rmdir", cmd_rmdir, 2, 2, "<dir-path>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_ENVIRON -# ifndef CONFIG_NSH_DISABLE_SET - { "set", cmd_set, 3, 3, "<name> <value>" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT) -# ifndef CONFIG_NSH_DISABLE_SH - { "sh", cmd_sh, 2, 2, "<script-path>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_SIGNALS -# ifndef CONFIG_NSH_DISABLE_SLEEP - { "sleep", cmd_sleep, 2, 2, "<sec>" }, -# endif -#endif - -#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST) - { "test", cmd_test, 3, CONFIG_NSH_MAXARGUMENTS, "<expression>" }, -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) -# ifndef CONFIG_NSH_DISABLE_UMOUNT - { "umount", cmd_umount, 2, 2, "<dir-path>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_ENVIRON -# ifndef CONFIG_NSH_DISABLE_UNSET - { "unset", cmd_unset, 2, 2, "<name>" }, -# endif -#endif - -#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE) -# ifndef CONFIG_NSH_DISABLE_URLDECODE - { "urldecode", cmd_urldecode, 2, 3, "[-f] <string or filepath>" }, -# endif -# ifndef CONFIG_NSH_DISABLE_URLENCODE - { "urlencode", cmd_urlencode, 2, 3, "[-f] <string or filepath>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_SIGNALS -# ifndef CONFIG_NSH_DISABLE_USLEEP - { "usleep", cmd_usleep, 2, 2, "<usec>" }, -# endif -#endif - -#if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_WGET - { "wget", cmd_wget, 2, 4, "[-o <local-path>] <url>" }, -# endif -#endif - -#ifndef CONFIG_NSH_DISABLE_XD - { "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" }, -#endif - - { NULL, NULL, 1, 1, NULL } -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* If NuttX versioning information is available, Include that information - * in the NSH greeting. - */ - -#if CONFIG_VERSION_MAJOR != 0 || CONFIG_VERSION_MINOR != 0 -const char g_nshgreeting[] = "\nNuttShell (NSH) NuttX-" CONFIG_VERSION_STRING "\n"; -#else -const char g_nshgreeting[] = "\nNuttShell (NSH)\n"; -#endif - -/* Telnet login prompts */ - -#if defined(CONFIG_NSH_TELNET_LOGIN) && defined(CONFIG_NSH_TELNET) -const char g_telnetgreeting[] = "\nWelcome to NuttShell(NSH) Telnet Server...\n"; -const char g_userprompt[] = "login: "; -const char g_passwordprompt[] = "password: "; -const char g_loginsuccess[] = "\nUser Logged-in!\n"; -const char g_badcredentials[] = "\nInvalid username or password\n"; -const char g_loginfailure[] = "Login failed!\n"; -#endif - -/* The NSH prompt */ - -const char g_nshprompt[] = "nsh> "; - -/* Common, message formats */ - -const char g_nshsyntax[] = "nsh: %s: syntax error\n"; -const char g_fmtargrequired[] = "nsh: %s: missing required argument(s)\n"; -const char g_fmtarginvalid[] = "nsh: %s: argument invalid\n"; -const char g_fmtargrange[] = "nsh: %s: value out of range\n"; -const char g_fmtcmdnotfound[] = "nsh: %s: command not found\n"; -const char g_fmtnosuch[] = "nsh: %s: no such %s: %s\n"; -const char g_fmttoomanyargs[] = "nsh: %s: too many arguments\n"; -const char g_fmtdeepnesting[] = "nsh: %s: nesting too deep\n"; -const char g_fmtcontext[] = "nsh: %s: not valid in this context\n"; -#ifdef CONFIG_NSH_STRERROR -const char g_fmtcmdfailed[] = "nsh: %s: %s failed: %s\n"; -#else -const char g_fmtcmdfailed[] = "nsh: %s: %s failed: %d\n"; -#endif -const char g_fmtcmdoutofmemory[] = "nsh: %s: out of memory\n"; -const char g_fmtinternalerror[] = "nsh: %s: Internal error\n"; -#ifndef CONFIG_DISABLE_SIGNALS -const char g_fmtsignalrecvd[] = "nsh: %s: Interrupted by signal\n"; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: help_cmdlist - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_HELP -static inline void help_cmdlist(FAR struct nsh_vtbl_s *vtbl) -{ - int i; - int j; - int k; - - /* Print the command name in NUM_CMD_ROWS rows with CMDS_PER_LINE commands - * on each line. - */ - - for (i = 0; i < NUM_CMD_ROWS; i++) - { - nsh_output(vtbl, " "); - for (j = 0, k = i; j < CMDS_PER_LINE && k < NUM_CMDS; j++, k += NUM_CMD_ROWS) - { - nsh_output(vtbl, "%-12s", g_cmdmap[k].cmd); - } - - nsh_output(vtbl, "\n"); - } -} -#endif - -/**************************************************************************** - * Name: help_usage - ****************************************************************************/ - -#if !defined(CONFIG_NSH_DISABLE_HELP) && !defined(CONFIG_NSH_HELP_TERSE) -static inline void help_usage(FAR struct nsh_vtbl_s *vtbl) -{ - nsh_output(vtbl, "NSH command forms:\n"); -#ifndef CONFIG_NSH_DISABLEBG - nsh_output(vtbl, " [nice [-d <niceness>>]] <cmd> [> <file>|>> <file>] [&]\n"); -#else - nsh_output(vtbl, " <cmd> [> <file>|>> <file>]\n"); -#endif -#ifndef CONFIG_NSH_DISABLESCRIPT - nsh_output(vtbl, "OR\n"); - nsh_output(vtbl, " if <cmd>\n"); - nsh_output(vtbl, " then\n"); - nsh_output(vtbl, " [sequence of <cmd>]\n"); - nsh_output(vtbl, " else\n"); - nsh_output(vtbl, " [sequence of <cmd>]\n"); - nsh_output(vtbl, " fi\n\n"); -#endif -} -#endif - -/**************************************************************************** - * Name: help_showcmd - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_HELP -static void help_showcmd(FAR struct nsh_vtbl_s *vtbl, - FAR const struct cmdmap_s *cmdmap) -{ - if (cmdmap->usage) - { - nsh_output(vtbl, " %s %s\n", cmdmap->cmd, cmdmap->usage); - } - else - { - nsh_output(vtbl, " %s\n", cmdmap->cmd); - } -} -#endif - -/**************************************************************************** - * Name: help_cmd - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_HELP -static int help_cmd(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd) -{ - FAR const struct cmdmap_s *cmdmap; - - /* Find the command in the command table */ - - for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++) - { - /* Is this the one we are looking for? */ - - if (strcmp(cmdmap->cmd, cmd) == 0) - { - /* Yes... show it */ - - nsh_output(vtbl, "%s usage:", cmd); - help_showcmd(vtbl, cmdmap); - return OK; - } - } - - nsh_output(vtbl, g_fmtcmdnotfound, cmd); - return ERROR; -} -#endif - -/**************************************************************************** - * Name: help_allcmds - ****************************************************************************/ - -#if !defined(CONFIG_NSH_DISABLE_HELP) && !defined(CONFIG_NSH_HELP_TERSE) -static inline void help_allcmds(FAR struct nsh_vtbl_s *vtbl) -{ - FAR const struct cmdmap_s *cmdmap; - - /* Show all of the commands in the command table */ - - for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++) - { - help_showcmd(vtbl, cmdmap); - } -} -#endif - -/**************************************************************************** - * Name: help_builtins - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_HELP -static inline void help_builtins(FAR struct nsh_vtbl_s *vtbl) -{ -#ifdef CONFIG_NSH_BUILTIN_APPS - FAR const char *name; - int i; - - /* List the set of available built-in commands */ - - nsh_output(vtbl, "\nBuiltin Apps:\n"); - for (i = 0; (name = builtin_getname(i)) != NULL; i++) - { - nsh_output(vtbl, " %s\n", name); - } -#endif -} -#endif - -/**************************************************************************** - * Name: cmd_help - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_HELP -static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - FAR const char *cmd = NULL; -#ifndef CONFIG_NSH_HELP_TERSE - bool verbose = false; - int i; -#endif - - /* The command may be followed by a verbose option */ - -#ifndef CONFIG_NSH_HELP_TERSE - i = 1; - if (argc > i) - { - if (strcmp(argv[i], "-v") == 0) - { - verbose = true; - i++; - } - } - - /* The command line may end with a command name */ - - if (argc > i) - { - cmd = argv[i]; - } - - /* Show the generic usage if verbose is requested */ - - if (verbose) - { - help_usage(vtbl); - } -#else - if (argc > 1) - { - cmd = argv[1]; - } -#endif - - /* Are we showing help on a single command? */ - - if (cmd) - { - /* Yes.. show the single command */ - - help_cmd(vtbl, cmd); - } - else - { - /* In verbose mode, show detailed help for all commands */ - -#ifndef CONFIG_NSH_HELP_TERSE - if (verbose) - { - nsh_output(vtbl, "Where <cmd> is one of:\n"); - help_allcmds(vtbl); - } - - /* Otherwise, just show the list of command names */ - - else -#endif - { - help_cmd(vtbl, "help"); - nsh_output(vtbl, "\n"); - help_cmdlist(vtbl); - } - - /* And show the list of built-in applications */ - - help_builtins(vtbl); - } - - return OK; -} -#endif - -/**************************************************************************** - * Name: cmd_unrecognized - ****************************************************************************/ - -static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - nsh_output(vtbl, g_fmtcmdnotfound, argv[0]); - return ERROR; -} - -/**************************************************************************** - * Name: cmd_exit - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_EXIT -static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - nsh_exit(vtbl, 0); - return OK; -} -#endif - -/**************************************************************************** - * Name: nsh_execute - * - * Description: - * Execute the command in argv[0] - * - * Returned Value: - * -1 (ERRROR) if the command was unsuccessful - * 0 (OK) if the command was successful - * - ****************************************************************************/ - -static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]) -{ - const struct cmdmap_s *cmdmap; - const char *cmd; - cmd_t handler = cmd_unrecognized; - int ret; - - /* The form of argv is: - * - * argv[0]: The command name. This is argv[0] when the arguments - * are, finally, received by the command vtblr - * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS) - * 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 */ - - nsh_output(vtbl, g_fmtargrequired, cmd); - return ERROR; - } - else if (argc > cmdmap->maxargs) - { - /* More than the maximum number were provided */ - - nsh_output(vtbl, g_fmttoomanyargs, cmd); - return ERROR; - } - else - { - /* A valid number of arguments were provided (this does - * not mean they are right). - */ - - handler = cmdmap->handler; - break; - } - } - } - - ret = handler(vtbl, argc, argv); - return ret; -} - -/**************************************************************************** - * Name: nsh_releaseargs - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLEBG -static void nsh_releaseargs(struct cmdarg_s *arg) -{ - FAR struct nsh_vtbl_s *vtbl = arg->vtbl; - int i; - - /* If the output was redirected, then file descriptor should - * be closed. The created task has its one, independent copy of - * the file descriptor - */ - - if (vtbl->np.np_redirect) - { - (void)close(arg->fd); - } - - /* Released the cloned vtbl instance */ - - nsh_release(vtbl); - - /* Release the cloned args */ - - for (i = 0; i < arg->argc; i++) - { - free(arg->argv[i]); - } - free(arg); -} -#endif - -/**************************************************************************** - * Name: nsh_child - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLEBG -static pthread_addr_t nsh_child(pthread_addr_t arg) -{ - struct cmdarg_s *carg = (struct cmdarg_s *)arg; - int ret; - - dbg("BG %s\n", carg->argv[0]); - - /* Execute the specified command on the child thread */ - - ret = nsh_execute(carg->vtbl, carg->argc, carg->argv); - - /* Released the cloned arguments */ - - dbg("BG %s complete\n", carg->argv[0]); - nsh_releaseargs(carg); - return (void*)ret; -} -#endif - -/**************************************************************************** - * Name: nsh_cloneargs - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLEBG -static inline struct cmdarg_s *nsh_cloneargs(FAR struct nsh_vtbl_s *vtbl, - int fd, int argc, char *argv[]) -{ - struct cmdarg_s *ret = (struct cmdarg_s *)zalloc(sizeof(struct cmdarg_s)); - int i; - - if (ret) - { - ret->vtbl = vtbl; - ret->fd = fd; - ret->argc = argc; - - for (i = 0; i < argc; i++) - { - ret->argv[i] = strdup(argv[i]); - } - } - return ret; -} -#endif - -/**************************************************************************** - * Name: nsh_argument - ****************************************************************************/ - -char *nsh_argument(FAR struct nsh_vtbl_s *vtbl, char **saveptr) -{ - char *pbegin = *saveptr; - char *pend = NULL; - const char *term; -#ifndef CONFIG_DISABLE_ENVIRON - bool quoted = false; -#endif - - /* 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 '>' -- redirection of output? */ - - if (*pbegin == '>') - { - /* Yes.. does it begin with ">>"? */ - - if (*(pbegin + 1) == '>') - { - *saveptr = pbegin + 2; - pbegin = (char*)g_redirect2; - } - else - { - *saveptr = pbegin + 1; - pbegin = (char*)g_redirect1; - } - } - - /* 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 = "\""; -#ifndef CONFIG_DISABLE_ENVIRON - quoted = true; -#endif - } - 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; - -#ifndef CONFIG_DISABLE_ENVIRON - /* Check for references to environment variables */ - - if (pbegin[0] == '$' && !quoted) - { - /* Check for built-in variables */ - - if (strcmp(pbegin, g_exitstatus) == 0) - { - if (vtbl->np.np_fail) - { - return (char*)g_failure; - } - else - { - return (char*)g_success; - } - } - - /* Not a built-in? Return the value of the environment variable with this name */ - - else - { - char *value = getenv(pbegin+1); - if (value) - { - return value; - } - else - { - return (char*)""; - } - } - } -#endif - } - - /* Return the beginning of the token. */ - - return pbegin; -} - -/**************************************************************************** - * Name: nsh_cmdenabled - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLESCRIPT -static inline bool nsh_cmdenabled(FAR struct nsh_vtbl_s *vtbl) -{ - struct nsh_parser_s *np = &vtbl->np; - bool ret = !np->np_st[np->np_ndx].ns_disabled; - if (ret) - { - switch (np->np_st[np->np_ndx].ns_state) - { - case NSH_PARSER_NORMAL : - case NSH_PARSER_IF: - default: - break; - - case NSH_PARSER_THEN: - ret = !np->np_st[np->np_ndx].ns_ifcond; - break; - - case NSH_PARSER_ELSE: - ret = np->np_st[np->np_ndx].ns_ifcond; - break; - } - } - return ret; -} -#endif - -/**************************************************************************** - * Name: nsh_ifthenelse - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLESCRIPT -static inline int nsh_ifthenelse(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR char **saveptr) -{ - struct nsh_parser_s *np = &vtbl->np; - FAR char *cmd = *ppcmd; - bool disabled; - - if (cmd) - { - /* Check if the command is preceeded by "if" */ - - if (strcmp(cmd, "if") == 0) - { - /* Get the cmd following the if */ - - *ppcmd = nsh_argument(vtbl, saveptr); - if (!*ppcmd) - { - nsh_output(vtbl, g_fmtarginvalid, "if"); - goto errout; - } - - /* Verify that "if" is valid in this context */ - - if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_NORMAL && - np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN && - np->np_st[np->np_ndx].ns_state != NSH_PARSER_ELSE) - { - nsh_output(vtbl, g_fmtcontext, "if"); - goto errout; - } - - /* Check if we have exceeded the maximum depth of nesting */ - - if (np->np_ndx >= CONFIG_NSH_NESTDEPTH-1) - { - nsh_output(vtbl, g_fmtdeepnesting, "if"); - goto errout; - } - - /* "Push" the old state and set the new state */ - - disabled = !nsh_cmdenabled(vtbl); - np->np_ndx++; - np->np_st[np->np_ndx].ns_state = NSH_PARSER_IF; - np->np_st[np->np_ndx].ns_disabled = disabled; - np->np_st[np->np_ndx].ns_ifcond = false; - } - else if (strcmp(cmd, "then") == 0) - { - /* Get the cmd following the then -- there shouldn't be one */ - - *ppcmd = nsh_argument(vtbl, saveptr); - if (*ppcmd) - { - nsh_output(vtbl, g_fmtarginvalid, "then"); - goto errout; - } - - /* Verify that "then" is valid in this context */ - - if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_IF) - { - nsh_output(vtbl, g_fmtcontext, "then"); - goto errout; - } - np->np_st[np->np_ndx].ns_state = NSH_PARSER_THEN; - } - else if (strcmp(cmd, "else") == 0) - { - /* Get the cmd following the else -- there shouldn't be one */ - - *ppcmd = nsh_argument(vtbl, saveptr); - if (*ppcmd) - { - nsh_output(vtbl, g_fmtarginvalid, "else"); - goto errout; - } - - /* Verify that "then" is valid in this context */ - - if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN) - { - nsh_output(vtbl, g_fmtcontext, "else"); - goto errout; - } - np->np_st[np->np_ndx].ns_state = NSH_PARSER_ELSE; - } - else if (strcmp(cmd, "fi") == 0) - { - /* Get the cmd following the fi -- there should be one */ - - *ppcmd = nsh_argument(vtbl, saveptr); - if (*ppcmd) - { - nsh_output(vtbl, g_fmtarginvalid, "fi"); - goto errout; - } - - /* Verify that "fi" is valid in this context */ - - if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN && - np->np_st[np->np_ndx].ns_state != NSH_PARSER_ELSE) - { - nsh_output(vtbl, g_fmtcontext, "fi"); - goto errout; - } - - if (np->np_ndx < 1) /* Shouldn't happen */ - { - nsh_output(vtbl, g_fmtinternalerror, "if"); - goto errout; - } - - /* "Pop" the previous state */ - - np->np_ndx--; - } - else if (np->np_st[np->np_ndx].ns_state == NSH_PARSER_IF) - { - nsh_output(vtbl, g_fmtcontext, cmd); - goto errout; - } - } - return OK; - -errout: - np->np_ndx = 0; - np->np_st[0].ns_state = NSH_PARSER_NORMAL; - np->np_st[0].ns_disabled = false; - np->np_st[0].ns_ifcond = false; - return ERROR; -} -#endif - -/**************************************************************************** - * Name: nsh_saveresult - ****************************************************************************/ - -static inline int nsh_saveresult(FAR struct nsh_vtbl_s *vtbl, bool result) -{ - struct nsh_parser_s *np = &vtbl->np; - -#ifndef CONFIG_NSH_DISABLESCRIPT - if (np->np_st[np->np_ndx].ns_state == NSH_PARSER_IF) - { - np->np_fail = false; - np->np_st[np->np_ndx].ns_ifcond = result; - return OK; - } - else -#endif - { - np->np_fail = result; - return result ? ERROR : OK; - } -} - -/**************************************************************************** - * Name: nsh_nice - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLEBG -static inline int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR char **saveptr) -{ - FAR char *cmd = *ppcmd; - - vtbl->np.np_nice = 0; - if (cmd) - { - /* Check if the command is preceded by "nice" */ - - if (strcmp(cmd, "nice") == 0) - { - /* Nicenesses range from -20 (most favorable scheduling) to 19 - * (least favorable). Default is 10. - */ - - vtbl->np.np_nice = 10; - - /* Get the cmd (or -d option of nice command) */ - - cmd = nsh_argument(vtbl, saveptr); - if (cmd && strcmp(cmd, "-d") == 0) - { - FAR char *val = nsh_argument(vtbl, saveptr); - if (val) - { - char *endptr; - vtbl->np.np_nice = (int)strtol(val, &endptr, 0); - if (vtbl->np.np_nice > 19 || vtbl->np.np_nice < -20 || - endptr == val || *endptr != '\0') - { - nsh_output(vtbl, g_fmtarginvalid, "nice"); - return ERROR; - } - cmd = nsh_argument(vtbl, saveptr); - } - } - - /* Return the real command name */ - - *ppcmd = cmd; - } - } - return OK; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_parse - * - * Description: - * This function parses and executes one NSH command. - * - ****************************************************************************/ - -int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) -{ - FAR char *argv[MAX_ARGV_ENTRIES]; - FAR char *saveptr; - FAR char *cmd; - FAR char *redirfile = NULL; - int fd = -1; - int oflags = 0; - int argc; - int ret; - - /* Initialize parser state */ - - memset(argv, 0, MAX_ARGV_ENTRIES*sizeof(FAR char *)); -#ifndef CONFIG_NSH_DISABLEBG - vtbl->np.np_bg = false; -#endif - vtbl->np.np_redirect = false; - - /* Parse out the command at the beginning of the line */ - - saveptr = cmdline; - cmd = nsh_argument(vtbl, &saveptr); - - /* Handler if-then-else-fi */ - -#ifndef CONFIG_NSH_DISABLESCRIPT - if (nsh_ifthenelse(vtbl, &cmd, &saveptr) != 0) - { - goto errout; - } -#endif - - /* Handle nice */ - -#ifndef CONFIG_NSH_DISABLEBG - if (nsh_nice(vtbl, &cmd, &saveptr) != 0) - { - goto errout; - } -#endif - - /* Check if any command was provided -OR- if command processing is - * currently disabled. - */ - -#ifndef CONFIG_NSH_DISABLESCRIPT - if (!cmd || !nsh_cmdenabled(vtbl)) -#else - if (!cmd) -#endif - { - /* An empty line is not an error and an unprocessed command cannot - * generate an error, but neither should they change the last - * command status. - */ - - return OK; - } - - /* Parse all of the arguments following the command name. The form - * of argv is: - * - * argv[0]: The command name. - * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS) - * argv[argc-3]: Possibly '>' or '>>' - * argv[argc-2]: Possibly <file> - * argv[argc-1]: Possibly '&' - * argv[argc]: NULL terminating pointer - * - * Maximum size is CONFIG_NSH_MAXARGUMENTS+5 - */ - - argv[0] = cmd; - for (argc = 1; argc < MAX_ARGV_ENTRIES-1; argc++) - { - argv[argc] = nsh_argument(vtbl, &saveptr); - if (!argv[argc]) - { - break; - } - } - - argv[argc] = NULL; - - /* Check if the command should run in background */ - -#ifndef CONFIG_NSH_DISABLEBG - if (argc > 1 && strcmp(argv[argc-1], "&") == 0) - { - vtbl->np.np_bg = true; - argv[argc-1] = NULL; - argc--; - } -#endif - - /* Check if the output was re-directed using > or >> */ - - if (argc > 2) - { - /* Check for redirection to a new file */ - - if (strcmp(argv[argc-2], g_redirect1) == 0) - { - vtbl->np.np_redirect = true; - oflags = O_WRONLY|O_CREAT|O_TRUNC; - redirfile = nsh_getfullpath(vtbl, argv[argc-1]); - argc -= 2; - } - - /* Check for redirection by appending to an existing file */ - - else if (strcmp(argv[argc-2], g_redirect2) == 0) - { - vtbl->np.np_redirect = true; - oflags = O_WRONLY|O_CREAT|O_APPEND; - redirfile = nsh_getfullpath(vtbl, argv[argc-1]); - argc -= 2; - } - } - - /* Check if the maximum number of arguments was exceeded */ - - if (argc > CONFIG_NSH_MAXARGUMENTS) - { - nsh_output(vtbl, g_fmttoomanyargs, cmd); - } - - /* Does this command correspond to an application filename? - * nsh_fileapp() returns: - * - * -1 (ERROR) if the application task corresponding to 'argv[0]' could not - * be started (possibly because it doesn not exist). - * 0 (OK) if the application task corresponding to 'argv[0]' was - * and successfully started. If CONFIG_SCHED_WAITPID is - * defined, this return value also indicates that the - * application returned successful status (EXIT_SUCCESS) - * 1 If CONFIG_SCHED_WAITPID is defined, then this return value - * indicates that the application task was spawned successfully - * but returned failure exit status. - * - * Note the priority if not effected by nice-ness. - */ - -#ifdef CONFIG_NSH_FILE_APPS - ret = nsh_fileapp(vtbl, argv[0], argv, redirfile, oflags); - if (ret >= 0) - { - /* nsh_fileapp() returned 0 or 1. This means that the builtin - * command was successfully started (although it may not have ran - * successfully). So certainly it is not an NSH command. - */ - - return nsh_saveresult(vtbl, ret != OK); - } - - /* No, not a built in command (or, at least, we were unable to start a - * builtin command of that name). Treat it like an NSH command. - */ - -#endif - - /* Does this command correspond to a builtin command? - * nsh_builtin() returns: - * - * -1 (ERROR) if the application task corresponding to 'argv[0]' could not - * be started (possibly because it doesn not exist). - * 0 (OK) if the application task corresponding to 'argv[0]' was - * and successfully started. If CONFIG_SCHED_WAITPID is - * defined, this return value also indicates that the - * application returned successful status (EXIT_SUCCESS) - * 1 If CONFIG_SCHED_WAITPID is defined, then this return value - * indicates that the application task was spawned successfully - * but returned failure exit status. - * - * Note the priority if not effected by nice-ness. - */ - -#if defined(CONFIG_NSH_BUILTIN_APPS) && (!defined(CONFIG_NSH_FILE_APPS) || !defined(CONFIG_FS_BINFS)) - ret = nsh_builtin(vtbl, argv[0], argv, redirfile, oflags); - if (ret >= 0) - { - /* nsh_builtin() returned 0 or 1. This means that the builtin - * command was successfully started (although it may not have ran - * successfully). So certainly it is not an NSH command. - */ - - return nsh_saveresult(vtbl, ret != OK); - } - - /* No, not a built in command (or, at least, we were unable to start a - * builtin command of that name). Treat it like an NSH command. - */ - -#endif - - /* Redirected output? */ - - if (vtbl->np.np_redirect) - { - /* Open the redirection file. This file will eventually - * be closed by a call to either nsh_release (if the command - * is executed in the background) or by nsh_undirect if the - * command is executed in the foreground. - */ - - fd = open(redirfile, oflags, 0666); - nsh_freefullpath(redirfile); - redirfile = NULL; - - if (fd < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO); - goto errout; - } - } - - /* Handle the case where the command is executed in background. - * However is app is to be started as builtin new process will - * be created anyway, so skip this step. - */ - -#ifndef CONFIG_NSH_DISABLEBG - if (vtbl->np.np_bg) - { - struct sched_param param; - struct nsh_vtbl_s *bkgvtbl; - struct cmdarg_s *args; - pthread_attr_t attr; - pthread_t thread; - - /* Get a cloned copy of the vtbl with reference count=1. - * after the command has been processed, the nsh_release() call - * at the end of nsh_child() will destroy the clone. - */ - - bkgvtbl = nsh_clone(vtbl); - if (!bkgvtbl) - { - goto errout_with_redirect; - } - - /* Create a container for the command arguments */ - - args = nsh_cloneargs(bkgvtbl, fd, argc, argv); - if (!args) - { - nsh_release(bkgvtbl); - goto errout_with_redirect; - } - - /* Handle redirection of output via a file descriptor */ - - if (vtbl->np.np_redirect) - { - (void)nsh_redirect(bkgvtbl, fd, NULL); - } - - /* Get the execution priority of this task */ - - ret = sched_getparam(0, ¶m); - if (ret != 0) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "sched_getparm", NSH_ERRNO); - nsh_releaseargs(args); - nsh_release(bkgvtbl); - goto errout; - } - - /* Determine the priority to execute the command */ - - if (vtbl->np.np_nice != 0) - { - int priority = param.sched_priority - vtbl->np.np_nice; - if (vtbl->np.np_nice < 0) - { - int max_priority = sched_get_priority_max(SCHED_NSH); - if (priority > max_priority) - { - priority = max_priority; - } - } - else - { - int min_priority = sched_get_priority_min(SCHED_NSH); - if (priority < min_priority) - { - priority = min_priority; - } - } - - param.sched_priority = priority; - } - - /* Set up the thread attributes */ - - (void)pthread_attr_init(&attr); - (void)pthread_attr_setschedpolicy(&attr, SCHED_NSH); - (void)pthread_attr_setschedparam(&attr, ¶m); - - /* Execute the command as a separate thread at the appropriate priority */ - - ret = pthread_create(&thread, &attr, nsh_child, (pthread_addr_t)args); - if (ret != 0) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "pthread_create", NSH_ERRNO_OF(ret)); - nsh_releaseargs(args); - nsh_release(bkgvtbl); - goto errout; - } - - nsh_output(vtbl, "%s [%d:%d]\n", cmd, thread, param.sched_priority); - } - else -#endif - { - uint8_t save[SAVE_SIZE]; - - /* Handle redirection of output via a file descriptor */ - - if (vtbl->np.np_redirect) - { - nsh_redirect(vtbl, fd, save); - } - - /* Then execute the command in "foreground" -- i.e., while the user waits - * for the next prompt. nsh_execute will return: - * - * -1 (ERRROR) if the command was unsuccessful - * 0 (OK) if the command was successful - */ - - ret = nsh_execute(vtbl, argc, argv); - - /* Restore the original output. Undirect will close the redirection - * file descriptor. - */ - - if (vtbl->np.np_redirect) - { - nsh_undirect(vtbl, save); - } - - /* Mark errors so that it is possible to test for non-zero return values - * in nsh scripts. - */ - - if (ret < 0) - { - goto errout; - } - } - - /* Return success if the command succeeded (or at least, starting of the - * command task succeeded). - */ - - return nsh_saveresult(vtbl, false); - -#ifndef CONFIG_NSH_DISABLEBG -errout_with_redirect: - if (vtbl->np.np_redirect) - { - close(fd); - } -#endif -errout: - return nsh_saveresult(vtbl, true); -} diff --git a/apps/nshlib/nsh_proccmds.c b/apps/nshlib/nsh_proccmds.c deleted file mode 100644 index 487214501..000000000 --- a/apps/nshlib/nsh_proccmds.c +++ /dev/null @@ -1,310 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_proccmds.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sched.h> -#include <errno.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* The returned value should be zero for sucess or TRUE or non zero for - * failure or FALSE. - */ - -typedef int (*exec_t)(void); - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_PS -static const char *g_statenames[] = -{ - "INVALID ", - "PENDING ", - "READY ", - "RUNNING ", - "INACTIVE", - "WAITSEM ", -#ifndef CONFIG_DISABLE_MQUEUE - "WAITSIG ", -#endif -#ifndef CONFIG_DISABLE_MQUEUE - "MQNEMPTY", - "MQNFULL " -#endif -}; - -static const char *g_ttypenames[4] = -{ - "TASK ", - "PTHREAD", - "KTHREAD", - "--?-- " -}; -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ps_task - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_PS -static void ps_task(FAR _TCB *tcb, FAR void *arg) -{ - struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg; -#if CONFIG_MAX_TASK_ARGS > 2 - int i; -#endif - - /* Show task status */ - - nsh_output(vtbl, "%5d %3d %4s %7s%c%c %8s ", - tcb->pid, tcb->sched_priority, - tcb->flags & TCB_FLAG_ROUND_ROBIN ? "RR " : "FIFO", - g_ttypenames[(tcb->flags & TCB_FLAG_TTYPE_MASK) >> TCB_FLAG_TTYPE_SHIFT], - tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : ' ', - tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : ' ', - g_statenames[tcb->task_state]); - - /* Show task name and arguments */ - - nsh_output(vtbl, "%s(", tcb->argv[0]); - - /* Special case 1st argument (no comma) */ - - if (tcb->argv[1]) - { - nsh_output(vtbl, "%p", tcb->argv[1]); - } - - /* Then any additional arguments */ - -#if CONFIG_MAX_TASK_ARGS > 2 - for (i = 2; i <= CONFIG_MAX_TASK_ARGS && tcb->argv[i]; i++) - { - nsh_output(vtbl, ", %p", tcb->argv[i]); - } -#endif - nsh_output(vtbl, ")\n"); -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_exec - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_EXEC -int cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *endptr; - uintptr_t addr; - - addr = (uintptr_t)strtol(argv[1], &endptr, 0); - if (!addr || endptr == argv[1] || *endptr != '\0') - { - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - return ERROR; - } - - nsh_output(vtbl, "Calling %p\n", (exec_t)addr); - return ((exec_t)addr)(); -} -#endif - -/**************************************************************************** - * Name: cmd_ps - ****************************************************************************/ - -#ifndef CONFIG_NSH_DISABLE_PS -int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - nsh_output(vtbl, "PID PRI SCHD TYPE NP STATE NAME\n"); - sched_foreach(ps_task, vtbl); - return OK; -} -#endif - -/**************************************************************************** - * Name: cmd_kill - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_SIGNALS -#ifndef CONFIG_NSH_DISABLE_KILL -int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *ptr; - char *endptr; - long signal; - long pid; - - /* Check incoming parameters. The first parameter should be "-<signal>" */ - - ptr = argv[1]; - if (*ptr != '-' || ptr[1] < '0' || ptr[1] > '9') - { - goto invalid_arg; - } - - /* Extract the signal number */ - - signal = strtol(&ptr[1], &endptr, 0); - - /* The second parameter should be <pid> */ - - ptr = argv[2]; - if (*ptr < '0' || *ptr > '9') - { - goto invalid_arg; - } - - /* Extract athe pid */ - - pid = strtol(ptr, &endptr, 0); - - /* Send the signal. Kill return values: - * - * EINVAL An invalid signal was specified. - * EPERM The process does not have permission to send the signal to any - * of the target processes. - * ESRCH The pid or process group does not exist. - * ENOSYS Do not support sending signals to process groups. - */ - - if (kill((pid_t)pid, (int)signal) == 0) - { - return OK; - } - - switch (errno) - { - case EINVAL: - goto invalid_arg; - - case ESRCH: - nsh_output(vtbl, g_fmtnosuch, argv[0], "task", argv[2]); - return ERROR; - - case EPERM: - case ENOSYS: - default: - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "kill", NSH_ERRNO); - return ERROR; - } - -invalid_arg: - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - return ERROR; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_sleep - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_SIGNALS -#ifndef CONFIG_NSH_DISABLE_SLEEP -int cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *endptr; - long secs; - - secs = strtol(argv[1], &endptr, 0); - if (!secs || endptr == argv[1] || *endptr != '\0') - { - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - return ERROR; - } - sleep(secs); - return OK; -} -#endif -#endif - -/**************************************************************************** - * Name: cmd_usleep - ****************************************************************************/ - -#ifndef CONFIG_DISABLE_SIGNALS -#ifndef CONFIG_NSH_DISABLE_USLEEP -int cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - char *endptr; - long usecs; - - usecs = strtol(argv[1], &endptr, 0); - if (!usecs || endptr == argv[1] || *endptr != '\0') - { - nsh_output(vtbl, g_fmtarginvalid, argv[0]); - return ERROR; - } - usleep(usecs); - return OK; -} -#endif -#endif diff --git a/apps/nshlib/nsh_romfsetc.c b/apps/nshlib/nsh_romfsetc.c deleted file mode 100644 index 4134b45a3..000000000 --- a/apps/nshlib/nsh_romfsetc.c +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_romfsetc.c - * - * Copyright (C) 2008-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/mount.h> -#include <debug.h> -#include <errno.h> - -#include <nuttx/ramdisk.h> - -#include "nsh.h" - -#ifdef CONFIG_NSH_ROMFSETC - -/* Should we use the default ROMFS image? Or a custom, board-specific - * ROMFS image? - */ - -#ifdef CONFIG_NSH_ARCHROMFS -# include <arch/board/nsh_romfsimg.h> -#else -# include "nsh_romfsimg.h" -#endif - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_romfsetc - ****************************************************************************/ - -int nsh_romfsetc(void) -{ - int ret; - - /* Create a ROM disk for the /etc filesystem */ - - ret = romdisk_register(CONFIG_NSH_ROMFSDEVNO, romfs_img, - NSECTORS(romfs_img_len), CONFIG_NSH_ROMFSSECTSIZE); - if (ret < 0) - { - dbg("nsh: romdisk_register failed: %d\n", -ret); - return ERROR; - } - - /* Mount the file system */ - - vdbg("Mounting ROMFS filesystem at target=%s with source=%s\n", - CONFIG_NSH_ROMFSMOUNTPT, MOUNT_DEVNAME); - - ret = mount(MOUNT_DEVNAME, CONFIG_NSH_ROMFSMOUNTPT, "romfs", MS_RDONLY, NULL); - if (ret < 0) - { - dbg("nsh: mount(%s,%s,romfs) failed: %d\n", - MOUNT_DEVNAME, CONFIG_NSH_ROMFSMOUNTPT, errno); - return ERROR; - } - return OK; -} - -#endif /* CONFIG_NSH_ROMFSETC */ - diff --git a/apps/nshlib/nsh_romfsimg.h b/apps/nshlib/nsh_romfsimg.h deleted file mode 100644 index 49b0ad166..000000000 --- a/apps/nshlib/nsh_romfsimg.h +++ /dev/null @@ -1,89 +0,0 @@ -unsigned char romfs_img[] = { - 0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x01, 0x50, - 0x9f, 0x13, 0x82, 0x87, 0x4e, 0x53, 0x48, 0x49, 0x6e, 0x69, 0x74, 0x56, - 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, - 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xff, 0x97, - 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0x80, 0x2e, 0x2e, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, - 0x68, 0x2d, 0x96, 0x03, 0x69, 0x6e, 0x69, 0x74, 0x2e, 0x64, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, - 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xff, 0x00, - 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x6e, 0x8d, 0x9c, 0xab, 0x58, 0x72, 0x63, 0x53, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x20, 0x61, 0x20, 0x52, - 0x41, 0x4d, 0x44, 0x49, 0x53, 0x4b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6d, - 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x69, 0x74, 0x20, 0x61, 0x74, 0x20, 0x2f, - 0x74, 0x6d, 0x70, 0x0a, 0x0a, 0x6d, 0x6b, 0x72, 0x64, 0x20, 0x2d, 0x6d, - 0x20, 0x32, 0x20, 0x2d, 0x73, 0x20, 0x35, 0x31, 0x32, 0x20, 0x31, 0x30, - 0x32, 0x34, 0x0a, 0x6d, 0x6b, 0x66, 0x61, 0x74, 0x66, 0x73, 0x20, 0x2f, - 0x64, 0x65, 0x76, 0x2f, 0x72, 0x61, 0x6d, 0x32, 0x0a, 0x6d, 0x6f, 0x75, - 0x6e, 0x74, 0x20, 0x2d, 0x74, 0x20, 0x76, 0x66, 0x61, 0x74, 0x20, 0x2f, - 0x64, 0x65, 0x76, 0x2f, 0x72, 0x61, 0x6d, 0x32, 0x20, 0x2f, 0x74, 0x6d, - 0x70, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0xe0, 0x2e, 0x2e, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 -}; -unsigned int romfs_img_len = 1024; diff --git a/apps/nshlib/nsh_script.c b/apps/nshlib/nsh_script.c deleted file mode 100644 index 3aa698b31..000000000 --- a/apps/nshlib/nsh_script.c +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_script.c - * - * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include "nsh.h" -#include "nsh_console.h" - -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT) - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_script - * - * Description: - * Execute the NSH script at path. - * - ****************************************************************************/ - -int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, - FAR const char *path) -{ - char *fullpath; - FILE *stream; - char *buffer; - char *pret; - int ret = ERROR; - - /* The path to the script may be relative to the current working directory */ - - fullpath = nsh_getfullpath(vtbl, path); - if (!fullpath) - { - return ERROR; - } - - /* Get a reference to the common input buffer */ - - buffer = nsh_linebuffer(vtbl); - if (buffer) - { - /* Open the file containing the script */ - - stream = fopen(fullpath, "r"); - if (!stream) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO); - nsh_freefullpath(fullpath); - return ERROR; - } - - /* Loop, processing each command line in the script file (or - * until an error occurs) - */ - - do - { - /* Get the next line of input from the file */ - - fflush(stdout); - pret = fgets(buffer, CONFIG_NSH_LINELEN, stream); - if (pret) - { - /* Parse process the command. NOTE: this is recursive... - * we got to cmd_sh via a call to nsh_parse. So some - * considerable amount of stack may be used. - */ - - ret = nsh_parse(vtbl, buffer); - } - } - while (pret && ret == OK); - fclose(stream); - } - - nsh_freefullpath(fullpath); - return ret; -} - -/**************************************************************************** - * Name: nsh_initscript - * - * Description: - * Attempt to execute the configured initialization script. This script - * should be executed once when NSH starts. nsh_initscript is idempotent - * and may, however, be called multiple times (the script will be executed - * once. - * - ****************************************************************************/ - -#ifdef CONFIG_NSH_ROMFSETC -int nsh_initscript(FAR struct nsh_vtbl_s *vtbl) -{ - static bool initialized; - bool already; - int ret = OK; - - /* Atomic test and set of the initialized flag */ - - sched_lock(); - already = initialized; - initialized = true; - sched_unlock(); - - /* If we have not already executed the init script, then do so now */ - - if (!already) - { - ret = nsh_script(vtbl, "init", NSH_INITPATH); - } - - return ret; -} - -/**************************************************************************** - * Name: nsh_loginscript - * - * Description: - * Attempt to execute the configured login script. This script - * should be executed when each NSH session starts. - * - ****************************************************************************/ - -#ifdef CONFIG_NSH_ROMFSRC -int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl) -{ - return nsh_script(vtbl, "login", NSH_RCPATH); -} -#endif -#endif /* CONFIG_NSH_ROMFSETC */ - -#endif /* CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !CONFIG_NSH_DISABLESCRIPT */ diff --git a/apps/nshlib/nsh_session.c b/apps/nshlib/nsh_session.c deleted file mode 100644 index 8079b2de5..000000000 --- a/apps/nshlib/nsh_session.c +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_session.c - * - * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name 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 <stdio.h> -#include <stdlib.h> - -#include <apps/readline.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_session - * - * Description: - * This is the common session logic or any NSH session. This function - * return when an error reading from the input stream occurs, presumably - * signaling the end of the session. - * - * This function: - * - Executes the NSH logic script - * - Presents a greeting - * - Then provides a prompt then gets and processes the command line. - * - This continues until an error occurs, then the session returns. - * - * Input Parameters: - * pstate - Abstracts the underlying session. - * - * Returned Values: - * EXIT_SUCESS or EXIT_FAILURE is returned. - * - ****************************************************************************/ - -int nsh_session(FAR struct console_stdio_s *pstate) -{ - int ret; - - DEBUGASSERT(pstate); - - /* Present a greeting */ - - fputs(g_nshgreeting, pstate->cn_outstream); - fflush(pstate->cn_outstream); - - /* Execute the login script */ - -#ifdef CONFIG_NSH_ROMFSRC - (void)nsh_loginscript(&pstate->cn_vtbl); -#endif - - /* Then enter the command line parsing loop */ - - for (;;) - { - /* For the case of debugging the USB console... dump collected USB trace data */ - -#ifdef CONFIG_NSH_USBDEV_TRACE - nsh_usbtrace(); -#endif - - /* Display the prompt string */ - - fputs(g_nshprompt, pstate->cn_outstream); - fflush(pstate->cn_outstream); - - /* Get the next line of input */ - - ret = readline(pstate->cn_line, CONFIG_NSH_LINELEN, - INSTREAM(pstate), OUTSTREAM(pstate)); - if (ret > 0) - { - /* Parse process the command */ - - (void)nsh_parse(&pstate->cn_vtbl, pstate->cn_line); - fflush(pstate->cn_outstream); - } - - /* Readline normally returns the number of characters read, - * but will return 0 on end of file or a negative value - * if an error occurs. Either will cause the session to - * terminate. - */ - - else - { - fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_session", - "readline", NSH_ERRNO_OF(-ret)); - return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; - } - } - - /* We do not get here, but this is necessary to keep some compilers happy. - * But others will complain that this code is not reachable. - */ - - return EXIT_SUCCESS; -} diff --git a/apps/nshlib/nsh_telnetd.c b/apps/nshlib/nsh_telnetd.c deleted file mode 100644 index 76ed81086..000000000 --- a/apps/nshlib/nsh_telnetd.c +++ /dev/null @@ -1,318 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_telnetd.c - * - * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name 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 <stdio.h> -#include <unistd.h> -#include <assert.h> -#include <debug.h> -#include <string.h> - -#include <apps/netutils/telnetd.h> - -#include "nsh.h" -#include "nsh_console.h" - -#ifdef CONFIG_NSH_TELNET - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef CONFIG_NSH_TELNET_LOGIN - -# define TELNET_IAC 255 -# define TELNET_WILL 251 -# define TELNET_WONT 252 -# define TELNET_DO 253 -# define TELNET_DONT 254 -# define TELNET_USE_ECHO 1 -# define TELNET_NOTUSE_ECHO 0 - -#endif /* CONFIG_NSH_TELNET_LOGIN */ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_telnetecho - ****************************************************************************/ - -#ifdef CONFIG_NSH_TELNET_LOGIN -void nsh_telnetecho(struct console_stdio_s *pstate, uint8_t is_use) -{ - uint8_t optbuf[4]; - optbuf[0] = TELNET_IAC; - optbuf[1] = (is_use == TELNET_USE_ECHO) ? TELNET_WILL : TELNET_DO; - optbuf[2] = 1; - optbuf[3] = 0; - fputs((char *)optbuf, pstate->cn_outstream); - fflush(pstate->cn_outstream); -} -#endif - -/**************************************************************************** - * Name: nsh_telnetlogin - ****************************************************************************/ - -#ifdef CONFIG_NSH_TELNET_LOGIN -int nsh_telnetlogin(struct console_stdio_s *pstate) -{ - char username[16]; - char password[16]; - uint8_t i; - - /* Present the NSH Telnet greeting */ - - fputs(g_telnetgreeting, pstate->cn_outstream); - fflush(pstate->cn_outstream); - - /* Loop for the configured number of retries */ - - for(i = 0; i < CONFIG_NSH_TELNET_FAILCOUNT; i++) - { - /* Ask for the login username */ - - fputs(g_userprompt, pstate->cn_outstream); - fflush(pstate->cn_outstream); - if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, INSTREAM(pstate)) != NULL) - { - strcpy(username, pstate->cn_line); - username[strlen(pstate->cn_line) - 1] = 0; - } - - /* Ask for the login password */ - - fputs(g_passwordprompt, pstate->cn_outstream); - fflush(pstate->cn_outstream); - nsh_telnetecho(pstate, TELNET_NOTUSE_ECHO); - if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, INSTREAM(pstate)) != NULL) - { - /* Verify the username and password */ - - strcpy(password,pstate->cn_line); - password[strlen(pstate->cn_line) - 1] = 0; - - if (strcmp(password, CONFIG_NSH_TELNET_PASSWORD) == 0 && - strcmp(username, CONFIG_NSH_TELNET_USERNAME) == 0) - { - fputs(g_loginsuccess, pstate->cn_outstream); - fflush(pstate->cn_outstream); - nsh_telnetecho(pstate, TELNET_USE_ECHO); - return OK; - } - else - { - fputs(g_badcredentials, pstate->cn_outstream); - fflush(pstate->cn_outstream); - } - } - - nsh_telnetecho(pstate, TELNET_USE_ECHO); - } - - /* Too many failed login attempts */ - - fputs(g_loginfailure, pstate->cn_outstream); - fflush(pstate->cn_outstream); - return -1; -} -#endif /* CONFIG_NSH_TELNET_LOGIN */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_telnetmain - ****************************************************************************/ - -int nsh_telnetmain(int argc, char *argv[]) -{ - FAR struct console_stdio_s *pstate = nsh_newconsole(); - DEBUGASSERT(pstate != NULL); - - dbg("Session [%d] Started\n", getpid()); - - /* Login User and Password Check */ - -#ifdef CONFIG_NSH_TELNET_LOGIN - if (nsh_telnetlogin(pstate) != OK) - { - nsh_exit(&pstate->cn_vtbl, 1); - return -1; /* nsh_exit does not return */ - } -#endif /* CONFIG_NSH_TELNET_LOGIN */ - - /* The following logic mostly the same as the login in nsh_session.c. It - * differs only in that gets() is called to get the command instead of - * readline(). - */ - - /* Present the NSH greeting */ - - fputs(g_nshgreeting, pstate->cn_outstream); - fflush(pstate->cn_outstream); - - /* Execute the startup script. If standard console is also defined, then - * we will not bother with the initscript here (although it is safe to - * call nshinitscript multiple times). - */ - -#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE) - (void)nsh_initscript(&pstate->cn_vtbl); -#endif - - /* Execute the login script */ - -#ifdef CONFIG_NSH_ROMFSRC - (void)nsh_loginscript(&pstate->cn_vtbl); -#endif - - /* Then enter the command line parsing loop */ - - for (;;) - { - /* Display the prompt string */ - - fputs(g_nshprompt, pstate->cn_outstream); - fflush(pstate->cn_outstream); - - /* Get the next line of input from the Telnet client */ - - if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, INSTREAM(pstate)) != NULL) - { - /* Parse process the received Telnet command */ - - (void)nsh_parse(&pstate->cn_vtbl, pstate->cn_line); - fflush(pstate->cn_outstream); - } - else - { - fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain", - "fgets", NSH_ERRNO); - nsh_exit(&pstate->cn_vtbl, 1); - } - } - - /* Clean up */ - - nsh_exit(&pstate->cn_vtbl, 0); - - /* We do not get here, but this is necessary to keep some compilers happy */ - - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_telnetstart - * - * Description: - * nsh_telnetstart() starts the Telnet daemon that will allow multiple - * NSH connections via Telnet. This function returns immediately after - * the daemon has been started. - * - * Input Parameters: - * None. All of the properties of the Telnet daemon are controlled by - * NuttX configuration setting. - * - * Returned Values: - * The task ID of the Telnet daemon was successfully started. A negated - * errno value will be returned on failure. - * - ****************************************************************************/ - -int nsh_telnetstart(void) -{ - struct telnetd_config_s config; - int ret; - - /* Initialize any USB tracing options that were requested. If standard - * console is also defined, then we will defer this step to the standard - * console. - */ - -#if defined(CONFIG_NSH_USBDEV_TRACE) && !defined(CONFIG_NSH_CONSOLE) - usbtrace_enable(TRACE_BITSET); -#endif - - /* Configure the telnet daemon */ - - config.d_port = HTONS(CONFIG_NSH_TELNETD_PORT); - config.d_priority = CONFIG_NSH_TELNETD_DAEMONPRIO; - config.d_stacksize = CONFIG_NSH_TELNETD_DAEMONSTACKSIZE; - config.t_priority = CONFIG_NSH_TELNETD_CLIENTPRIO; - config.t_stacksize = CONFIG_NSH_TELNETD_CLIENTSTACKSIZE; - config.t_entry = nsh_telnetmain; - - /* Start the telnet daemon */ - - vdbg("Starting the Telnet daemon\n"); - ret = telnetd_start(&config); - if (ret < 0) - { - dbg("Failed to tart the Telnet daemon: %d\n", ret); - } - - return ret; -} - -#endif /* CONFIG_NSH_TELNET */ diff --git a/apps/nshlib/nsh_test.c b/apps/nshlib/nsh_test.c deleted file mode 100644 index 6e1b65e5f..000000000 --- a/apps/nshlib/nsh_test.c +++ /dev/null @@ -1,438 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_test.c - * - * Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* Test syntax: - * - * expression = simple-expression | !expression | - * expression -o expression | expression -a expression - * - * simple-expression = unary-expression | binary-expression - * - * unary-expression = string-unary | file-unary - * - * string-unary = -n string | -z string - * - * file-unary = -b file | -c file | -d file | -e file | -f file | - * -r file | -s file | -w file - * - * binary-expression = string-binary | numeric-binary - * - * string-binary = string = string | string == string | string != string - * - * numeric-binary = integer -eq integer | integer -ge integer | - * integer -gt integer | integer -le integer | - * integer -lt integer | integer -ne integer - * - * Note that the smallest expression consists of two strings. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <sys/stat.h> -#include <stdlib.h> -#include <string.h> - -#include "nsh.h" -#include "nsh_console.h" - -#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST) - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define TEST_TRUE OK -#define TEST_FALSE ERROR -#define TEST_ERROR 1 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: binaryexpression - ****************************************************************************/ - -static inline int binaryexpression(FAR struct nsh_vtbl_s *vtbl, char **argv) -{ - char *endptr; - long integer1; - long integer2; - - /* STRING2 = STRING2 */ - - if (strcmp(argv[1], "=") == 0 || strcmp(argv[1], "==") == 0) - { - /* Return true if the strings are identical */ - - return strcmp(argv[0], argv[2]) == 0 ? TEST_TRUE : TEST_FALSE; - } - - /* STRING1 != STRING2 */ - - if (strcmp(argv[1], "!=") == 0) - { - /* Return true if the strings are different */ - - return strcmp(argv[0], argv[2]) != 0 ? TEST_TRUE : TEST_FALSE; - } - - /* The remaining operators assuming that the two values are integers */ - - integer1 = strtol(argv[0], &endptr, 0); - if (argv[0][0] == '\0' || *endptr != '\0') - { - return TEST_ERROR; - } - - integer2 = strtol(argv[2], &endptr, 0); - if (argv[2][0] == '\0' || *endptr != '\0') - { - return TEST_ERROR; - } - - /* INTEGER1 -eq INTEGER2 */ - - if (strcmp(argv[1], "-eq") == 0) - { - /* Return true if the strings are different */ - - return integer1 == integer2 ? TEST_TRUE : TEST_FALSE; - } - - /* INTEGER1 -ge INTEGER2 */ - - if (strcmp(argv[1], "-ge") == 0) - { - /* Return true if the strings are different */ - - return integer1 >= integer2 ? TEST_TRUE : TEST_FALSE; - } - - /* INTEGER1 -gt INTEGER2 */ - - if (strcmp(argv[1], "-gt") == 0) - { - /* Return true if the strings are different */ - - return integer1 > integer2 ? TEST_TRUE : TEST_FALSE; - } - - /* INTEGER1 -le INTEGER2 */ - - if (strcmp(argv[1], "-le") == 0) - { - /* Return true if the strings are different */ - - return integer1 <= integer2 ? TEST_TRUE : TEST_FALSE; - } - - /* INTEGER1 -lt INTEGER2 */ - - if (strcmp(argv[1], "-lt") == 0) - { - /* Return true if the strings are different */ - - return integer1 < integer2 ? TEST_TRUE : TEST_FALSE; - } - - /* INTEGER1 -ne INTEGER2 */ - - if (strcmp(argv[1], "-ne") == 0) - { - /* Return true if the strings are different */ - - return integer1 != integer2 ? TEST_TRUE : TEST_FALSE; - } - - return TEST_ERROR; -} - -/**************************************************************************** - * Name: unaryexpression - ****************************************************************************/ - -static inline int unaryexpression(FAR struct nsh_vtbl_s *vtbl, char **argv) -{ - struct stat buf; - char *fullpath; - int ret; - - /* -n STRING */ - - if (strcmp(argv[0], "-n") == 0) - { - /* Return true if the length of the string is non-zero */ - - return strlen(argv[1]) != 0 ? TEST_TRUE : TEST_FALSE; - } - - /* -z STRING */ - - if (strcmp(argv[0], "-z") == 0) - { - /* Return true if the length of the string is zero */ - - return strlen(argv[1]) == 0 ? TEST_TRUE : TEST_FALSE; - } - - /* All of the remaining assume that the following argument is the - * path to a file. - */ - - fullpath = nsh_getfullpath(vtbl, argv[1]); - if (!fullpath) - { - return TEST_FALSE; - } - - ret = stat(fullpath, &buf); - nsh_freefullpath(fullpath); - - if (ret != 0) - { - /* The file does not exist (or another error occurred) -- return FALSE */ - - return TEST_FALSE; - } - - /* -b FILE */ - - if (strcmp(argv[0], "-b") == 0) - { - /* Return true if the path is a block device */ - - return S_ISBLK(buf.st_mode) ? TEST_TRUE : TEST_FALSE; - } - - /* -c FILE */ - - if (strcmp(argv[0], "-c") == 0) - { - /* Return true if the path is a character device */ - - return S_ISCHR(buf.st_mode) ? TEST_TRUE : TEST_FALSE; - } - - /* -d FILE */ - - if (strcmp(argv[0], "-d") == 0) - { - /* Return true if the path is a directory */ - - return S_ISDIR(buf.st_mode) ? TEST_TRUE : TEST_FALSE; - } - - /* -e FILE */ - - if (strcmp(argv[0], "-e") == 0) - { - /* Return true if the file exists */ - - return TEST_TRUE; - } - - /* -f FILE */ - - if (strcmp(argv[0], "-f") == 0) - { - /* Return true if the path refers to a regular file */ - - return S_ISREG(buf.st_mode) ? TEST_TRUE : TEST_FALSE; - } - - /* -r FILE */ - - if (strcmp(argv[0], "-r") == 0) - { - /* Return true if the file is readable */ - - return (buf.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)) != 0 ? TEST_TRUE : TEST_FALSE; - } - - /* -s FILE */ - - if (strcmp(argv[0], "-s") == 0) - { - /* Return true if the size of the file is greater than zero */ - - return buf.st_size > 0 ? TEST_TRUE : TEST_FALSE; - } - - /* -w FILE */ - - if (strcmp(argv[0], "-w") == 0) - { - /* Return true if the file is write-able */ - - return (buf.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) != 0 ? TEST_TRUE : TEST_FALSE; - } - - /* Unrecognized operator */ - - return TEST_ERROR; -} - -/**************************************************************************** - * Name: expression - ****************************************************************************/ - -static int expression(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - int value; - int i = 0; - - /* Check for unary operations on expressions */ - - if (strcmp(argv[0], "!") == 0) - { - if (argc < 2) - { - goto errout_syntax; - } - return expression(vtbl, argc-1, &argv[1]) == TEST_TRUE ? TEST_FALSE : TEST_TRUE; - } - - /* Check for unary operations on simple, typed arguments */ - - else if (argv[0][0] == '-') - { - if (argc < 2) - { - goto errout_syntax; - } - i += 2; - value = unaryexpression(vtbl, argv); - } - - /* Check for binary operations on simple, typed arguments */ - - else - { - if (argc < 3) - { - goto errout_syntax; - } - i += 3; - value = binaryexpression(vtbl, argv); - } - - /* Test if there any failure */ - - if (value == TEST_ERROR) - { - goto errout_syntax; - } - - /* Is there anything after the simple expression? */ - - if (i < argc) - { - /* EXPRESSION -a EXPRESSION */ - - if (strcmp(argv[i], "-a") == 0) - { - if (value != TEST_TRUE) - { - return TEST_FALSE; - } - else - { - i++; - return expression(vtbl, argc-i, &argv[i]); - } - } - - /* EXPRESSION -o EXPRESSION */ - - else if (strcmp(argv[i], "-o") == 0) - { - if (value == TEST_TRUE) - { - return TEST_TRUE; - } - else - { - i++; - return expression(vtbl, argc-i, &argv[i]); - } - } - else - { - goto errout_syntax; - } - } - return value; - -errout_syntax: - nsh_output(vtbl, g_nshsyntax, "test"); - return TEST_FALSE; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_test - ****************************************************************************/ - -int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - return expression(vtbl, argc-1, &argv[1]); -} - -/**************************************************************************** - * Name: cmd_lbracket - ****************************************************************************/ - -int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - if (strcmp(argv[argc-1], "]") != 0) - { - nsh_output(vtbl, g_nshsyntax, argv[0]); - return ERROR; - } - else - { - return expression(vtbl, argc-2, &argv[1]); - } -} - -#endif /* !CONFIG_NSH_DISABLESCRIPT && !CONFIG_NSH_DISABLE_TEST */ diff --git a/apps/nshlib/nsh_timcmds.c b/apps/nshlib/nsh_timcmds.c deleted file mode 100644 index bc2bda6f4..000000000 --- a/apps/nshlib/nsh_timcmds.c +++ /dev/null @@ -1,331 +0,0 @@ -/**************************************************************************** - * apps/nshlib/dbg_timcmds.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <time.h> - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define MAX_TIME_STRING 80 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined (CONFIG_RTC) && !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_NSH_DISABLE_DATE) -static FAR const char * const g_datemontab[] = -{ - "jan", "feb", "mar", "apr", "may", "jun", - "jul", "aug", "sep", "oct", "nov", "dec" -}; -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: date_month - ****************************************************************************/ - -#if defined (CONFIG_RTC) && !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_NSH_DISABLE_DATE) -static inline int date_month(FAR const char *abbrev) -{ - int i; - - for (i = 0; i < 12; i++) - { - if (strncasecmp(g_datemontab[i], abbrev, 3) == 0) - { - return i; - } - } - return ERROR; -} -#endif - -/**************************************************************************** - * Name: date_gettime - ****************************************************************************/ - -#if defined (CONFIG_RTC) && !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_NSH_DISABLE_DATE) -static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name) -{ - static const char format[] = "%b %d %H:%M:%S %Y"; - struct timespec ts; - struct tm tm; - char timbuf[MAX_TIME_STRING]; - int ret; - - /* Get the current time */ - - ret = clock_gettime(CLOCK_REALTIME, &ts); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, name, "clock_gettime", NSH_ERRNO); - return ERROR; - } - - /* Break the current time up into the format needed by strftime */ - - (void)gmtime_r((FAR const time_t*)&ts.tv_sec, &tm); - - /* Show the current time in the requested format */ - - (void)strftime(timbuf, MAX_TIME_STRING, format, &tm); - nsh_output(vtbl, "%s\n", timbuf); - return OK; -} -#endif - -/**************************************************************************** - * Name: date_settime - ****************************************************************************/ - -#if defined (CONFIG_RTC) && !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_NSH_DISABLE_DATE) -static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name, - FAR char *newtime) -{ - struct timespec ts; - struct tm tm; - FAR char *token; - FAR char *saveptr; - long result; - int ret; - - /* Only this date format is supported: MMM DD HH:MM:SS YYYY */ - /* Get the month abbreviation */ - - token = strtok_r(newtime, " \t",&saveptr); - if (token == NULL) - { - goto errout_bad_parm; - } - - tm.tm_mon = date_month(token); - if (tm.tm_mon < 0) - { - goto errout_bad_parm; - } - - /* Get the day of the month. NOTE: Accepts day-of-month up to 31 for all months */ - - token = strtok_r(NULL, " \t",&saveptr); - if (token == NULL) - { - goto errout_bad_parm; - } - - result = strtol(token, NULL, 10); - if (result < 1 || result > 31) - { - goto errout_bad_parm; - } - tm.tm_mday = (int)result; - - /* Get the hours */ - - token = strtok_r(NULL, " \t:", &saveptr); - if (token == NULL) - { - goto errout_bad_parm; - } - - result = strtol(token, NULL, 10); - if (result < 0 || result > 23) - { - goto errout_bad_parm; - } - tm.tm_hour = (int)result; - - /* Get the minutes */ - - token = strtok_r(NULL, " \t:", &saveptr); - if (token == NULL) - { - goto errout_bad_parm; - } - - result = strtol(token, NULL, 10); - if (result < 0 || result > 59) - { - goto errout_bad_parm; - } - tm.tm_min = (int)result; - - /* Get the seconds */ - - token = strtok_r(NULL, " \t:", &saveptr); - if (token == NULL) - { - goto errout_bad_parm; - } - - result = strtol(token, NULL, 10); - if (result < 0 || result > 61) - { - goto errout_bad_parm; - } - tm.tm_sec = (int)result; - - /* And finally the year */ - - token = strtok_r(NULL, " \t", &saveptr); - if (token == NULL) - { - goto errout_bad_parm; - } - - result = strtol(token, NULL, 10); - if (result < 1900 || result > 2100) - { - goto errout_bad_parm; - } - tm.tm_year = (int)result - 1900; - - /* Convert this to the right form, then set the timer */ - - ts.tv_sec = mktime(&tm); - ts.tv_nsec = 0; - - ret = clock_settime(CLOCK_REALTIME, &ts); - if (ret < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, name, "clock_settime", NSH_ERRNO); - return ERROR; - } - return OK; - -errout_bad_parm: - nsh_output(vtbl, g_fmtarginvalid, name); - return ERROR; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cmd_date - ****************************************************************************/ - -#if defined (CONFIG_RTC) && !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_NSH_DISABLE_DATE) -int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - FAR char *newtime = NULL; - FAR const char *errfmt; - bool badarg = false; - int option; - int ret; - - /* Get the date options: date [-s time] [+FORMAT] */ - - while ((option = getopt(argc, argv, "s:")) != ERROR) - { - if (option == 's') - { - /* We will be setting the time */ - - newtime = optarg; - } - else /* option = '?' */ - { - /* We need to parse to the end anyway so that getopt stays healthy */ - - badarg = true; - } - } - - /* If a bad argument was encountered then exit with an error */ - - if (badarg) - { - errfmt = g_fmtarginvalid; - goto errout; - } - - /* optind < argc-1 means that there are additional, unexpected arguments on - * th command-line - */ - - if (optind < argc) - { - errfmt = g_fmttoomanyargs; - goto errout; - } - - /* Display or set the time */ - - if (newtime) - { - ret = date_settime(vtbl, argv[0], newtime); - } - else - { - ret = date_showtime(vtbl, argv[0]); - } - return ret; - -errout: - nsh_output(vtbl, errfmt, argv[0]); - return ERROR; -} -#endif diff --git a/apps/nshlib/nsh_usbdev.c b/apps/nshlib/nsh_usbdev.c deleted file mode 100644 index 193fe0d79..000000000 --- a/apps/nshlib/nsh_usbdev.c +++ /dev/null @@ -1,391 +0,0 @@ -/**************************************************************************** - * apps/nshlib/nsh_usbdev.c - * - * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <assert.h> -#include <debug.h> - -#ifdef CONFIG_CDCACM -# include <nuttx/usb/cdcacm.h> -#endif - -#ifdef CONFIG_CDCACM -# include <nuttx/usb/pl2303.h> -#endif - -#include "nsh.h" -#include "nsh_console.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Output USB trace data to the console device using printf() unless (1) - * debug is enabled, then we want to keep the trace output in sync with the - * debug output by using syslog()we are using a USB console. In that case, - * we don't want the trace output on the USB console; let's try sending it - * a SYSLOG device (hopefully one is set up!) - */ - -#if defined(CONFIG_DEBUG) || defined(HAVE_USB_CONSOLE) -# define trmessage syslog -#else -# define trmessage printf -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_tracecallback - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_tracecallback - * - * Description: - * This is part of the USB trace logic - * - ****************************************************************************/ - -#ifdef CONFIG_NSH_USBDEV_TRACE -static int nsh_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf((trprintf_t)trmessage, trace->event, trace->value); - return 0; -} -#endif - -/**************************************************************************** - * Name: nsh_configstdio - * - * Description: - * Configure standard I/O - * - ****************************************************************************/ - -#ifdef HAVE_USB_CONSOLE -static void nsh_configstdio(int fd) -{ - /* Make sure the stdin, stdout, and stderr are closed */ - - (void)fclose(stdin); - (void)fclose(stdout); - (void)fclose(stderr); - - /* Dup the fd to create standard fd 0-2 */ - - (void)dup2(fd, 0); - (void)dup2(fd, 1); - (void)dup2(fd, 2); - - /* fdopen to get the stdin, stdout and stderr streams. The following logic depends - * on the fact that the library layer will allocate FILEs in order. And since - * we closed stdin, stdout, and stderr above, that is what we should get. - * - * fd = 0 is stdin (read-only) - * fd = 1 is stdout (write-only, append) - * fd = 2 is stderr (write-only, append) - */ - - (void)fdopen(0, "r"); - (void)fdopen(1, "a"); - (void)fdopen(2, "a"); -} -#endif - -/**************************************************************************** - * Name: nsh_nullstdio - * - * Description: - * Use /dev/null for standard I/O - * - ****************************************************************************/ - -#ifdef HAVE_USB_CONSOLE -static int nsh_nullstdio(void) -{ - int fd; - - /* Open /dev/null for read/write access */ - - fd = open("/dev/null", O_RDWR); - if (fd >= 0) - { - /* Configure standard I/O to use /dev/null */ - - nsh_configstdio(fd); - - /* We can close the original file descriptor now (unless it was one of - * 0-2) - */ - - if (fd > 2) - { - close(fd); - } - - return OK; - } - - return fd; -} -#endif - -/**************************************************************************** - * Name: nsh_waitusbready - * - * Description: - * Wait for the USB console device to be ready - * - ****************************************************************************/ - -#ifdef HAVE_USB_CONSOLE -static int nsh_waitusbready(void) -{ - char inch; - ssize_t nbytes; - int nlc; - int fd; - - /* Don't start the NSH console until the console device is ready. Chances - * are, we get here with no functional console. The USB console will not - * be available until the device is connected to the host and until the - * host-side application opens the connection. - */ - - /* Open the USB serial device for read/write access */ - - do - { - /* Try to open the console */ - - fd = open(CONFIG_NSH_USBCONDEV, O_RDWR); - if (fd < 0) - { - /* ENOTCONN means that the USB device is not yet connected. Anything - * else is bad. - */ - - DEBUGASSERT(errno == ENOTCONN); - - /* Sleep a bit and try again */ - - sleep(2); - } - } - while (fd < 0); - - /* Now waiting until we successfully read a carriage return a few times. - * That is a sure way of know that there is something at the other end of - * the USB serial connection that is ready to talk with us. The user needs - * to hit ENTER a few times to get things started. - */ - - nlc = 0; - do - { - /* Read one byte */ - - inch = 0; - nbytes = read(fd, &inch, 1); - - /* Is it a carriage return (or maybe a newline)? */ - - if (nbytes == 1 && (inch == '\n' || inch == '\r')) - { - /* Yes.. increment the count */ - - nlc++; - } - else - { - /* No.. Reset the count. We need to see 3 in a row to continue. */ - - nlc = 0; - } - } - while (nlc < 3); - - /* Configure standard I/O */ - - nsh_configstdio(fd); - - /* We can close the original file descriptor now (unless it was one of 0-2) */ - - if (fd > 2) - { - close(fd); - } - - return OK; -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_consolemain (USB console version) - * - * Description: - * This interfaces maybe to called or started with task_start to start a - * single an NSH instance that operates on stdin and stdout. This - * function does not return. - * - * This function handles generic /dev/console character devices, or - * special USB console devices. The USB console requires some special - * operations to handle the cases where the session is lost when the - * USB device is unplugged and restarted when the USB device is plugged - * in again. - * - * Input Parameters: - * Standard task start-up arguments. These are not used. argc may be - * zero and argv may be NULL. - * - * Returned Values: - * This function does not return nor does it ever exit (unless the user - * executes the NSH exit command). - * - ****************************************************************************/ - -#ifdef HAVE_USB_CONSOLE -int nsh_consolemain(int argc, char *argv[]) -{ - FAR struct console_stdio_s *pstate = nsh_newconsole(); - int ret; - - DEBUGASSERT(pstate); - - /* Initialize any USB tracing options that were requested */ - -#ifdef CONFIG_NSH_USBDEV_TRACE - usbtrace_enable(TRACE_BITSET); -#endif - - /* Initialize the USB serial driver */ - -#if defined(CONFIG_PL2303) || defined(CONFIG_CDCACM) -#ifdef CONFIG_CDCACM - ret = cdcacm_initialize(CONFIG_NSH_USBDEV_MINOR, NULL); -#else - ret = usbdev_serialinitialize(CONFIG_NSH_USBDEV_MINOR); -#endif - DEBUGASSERT(ret == OK); -#endif - - /* Configure to use /dev/null if we do not have a valid console. */ - -#ifndef CONFIG_DEV_CONSOLE - (void)nsh_nullstdio(); -#endif - - /* Execute the one-time start-up script (output may go to /dev/null) */ - -#ifdef CONFIG_NSH_ROMFSETC - (void)nsh_initscript(&pstate->cn_vtbl); -#endif - - /* Now loop, executing creating a session for each USB connection */ - - for (;;) - { - /* Wait for the USB to be connected to the host and switch - * standard I/O to the USB serial device. - */ - - ret = nsh_waitusbready(); - DEBUGASSERT(ret == OK); - - /* Execute the session */ - - (void)nsh_session(pstate); - - /* Switch to /dev/null because we probably no longer have a - * valid console device. - */ - - (void)nsh_nullstdio(); - } -} -#endif - -/**************************************************************************** - * Name: nsh_usbtrace - * - * Description: - * The function is called from the nsh_session() to dump USB data to the - * SYSLOG device. - * - * Input Parameters: - * None - * - * Returned Values: - * None - * - ****************************************************************************/ - -#ifdef CONFIG_NSH_USBDEV_TRACE -void nsh_usbtrace(void) -{ - (void)usbtrace_enumerate(nsh_tracecallback, NULL); -} -#endif diff --git a/apps/nshlib/rcS.template b/apps/nshlib/rcS.template deleted file mode 100644 index 996f37fb1..000000000 --- a/apps/nshlib/rcS.template +++ /dev/null @@ -1,5 +0,0 @@ -# Create a RAMDISK and mount it at XXXRDMOUNTPOUNTXXX - -mkrd -m XXXMKRDMINORXXX -s XXMKRDSECTORSIZEXXX XXMKRDBLOCKSXXX -mkfatfs /dev/ramXXXMKRDMINORXXX -mount -t vfat /dev/ramXXXMKRDMINORXXX XXXRDMOUNTPOUNTXXX diff --git a/apps/system/Kconfig b/apps/system/Kconfig deleted file mode 100644 index 6c8651088..000000000 --- a/apps/system/Kconfig +++ /dev/null @@ -1,40 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -menu "Custom Free Memory Command" -source "$APPSDIR/system/free/Kconfig" -endmenu - -menu "I2C tool" -source "$APPSDIR/system/i2c/Kconfig" -endmenu - -menu "FLASH Program Installation" -source "$APPSDIR/system/install/Kconfig" -endmenu - -menu "readline()" -source "$APPSDIR/system/readline/Kconfig" -endmenu - -menu "Power Off" -source "$APPSDIR/system/poweroff/Kconfig" -endmenu - -menu "RAMTRON" -source "$APPSDIR/system/ramtron/Kconfig" -endmenu - -menu "SD Card" -source "$APPSDIR/system/sdcard/Kconfig" -endmenu - -menu "Sysinfo" -source "$APPSDIR/system/sysinfo/Kconfig" -endmenu - -menu "USB Monitor" -source "$APPSDIR/system/usbmonitor/Kconfig" -endmenu diff --git a/apps/system/Make.defs b/apps/system/Make.defs deleted file mode 100644 index 3c679f112..000000000 --- a/apps/system/Make.defs +++ /dev/null @@ -1,71 +0,0 @@ -############################################################################ -# apps/system/Make.defs -# Adds selected applications to apps/ build -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -ifeq ($(CONFIG_SYSTEM_FREE),y) -CONFIGURED_APPS += system/free -endif - -ifeq ($(CONFIG_SYSTEM_I2CTOOL),y) -CONFIGURED_APPS += system/i2c -endif - -ifeq ($(CONFIG_SYSTEM_INSTALL),y) -CONFIGURED_APPS += system/install -endif - -ifeq ($(CONFIG_SYSTEM_READLINE),y) -CONFIGURED_APPS += system/readline -endif - -ifeq ($(CONFIG_SYSTEM_POWEROFF),y) -CONFIGURED_APPS += system/poweroff -endif - -ifeq ($(CONFIG_SYSTEM_RAMTRON),y) -CONFIGURED_APPS += system/ramtron -endif - -ifeq ($(CONFIG_SYSTEM_SDCARD),y) -CONFIGURED_APPS += system/sdcard -endif - -ifeq ($(CONFIG_SYSTEM_SYSINFO),y) -CONFIGURED_APPS += system/sysinfo -endif - -ifeq ($(CONFIG_SYSTEM_USBMONITOR),y) -CONFIGURED_APPS += system/usbmonitor -endif diff --git a/apps/system/Makefile b/apps/system/Makefile deleted file mode 100644 index f39eedec4..000000000 --- a/apps/system/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -############################################################################ -# apps/system/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config # Current configuration - -# Sub-directories containing system task - -SUBDIRS = free i2c install readline poweroff ramtron sdcard sysinfo usbmonitor - -# Create the list of installed runtime modules (INSTALLED_DIRS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) -define ADD_DIRECTORY - INSTALLED_DIRS += $(if $(wildcard .\$1\Makefile),$1,) -endef -else -define ADD_DIRECTORY - INSTALLED_DIRS += $(if $(wildcard ./$1/Makefile),$1,) -endef -endif - -$(foreach DIR, $(SUBDIRS), $(eval $(call ADD_DIRECTORY,$(DIR)))) - -all: nothing -.PHONY: nothing context depend clean distclean - -define SDIR_template -$(1)_$(2): - $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" -endef - -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),depend))) -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),clean))) -$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) - -nothing: - -context: - -depend: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_depend) - -clean: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_clean) - -distclean: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_distclean) diff --git a/apps/system/free/Kconfig b/apps/system/free/Kconfig deleted file mode 100644 index 239559867..000000000 --- a/apps/system/free/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config SYSTEM_FREE - bool "NSH free command replacement" - default n - ---help--- - Enable support for the NSH free replacement command. - -if SYSTEM_FREE -endif - diff --git a/apps/system/free/Makefile b/apps/system/free/Makefile deleted file mode 100644 index 58ca7956c..000000000 --- a/apps/system/free/Makefile +++ /dev/null @@ -1,120 +0,0 @@ -############################################################################ -# apps/system/free/Makefile -# -# Copyright (C) 2011-2012 Uros Platise. All rights reserved. -# Author: Uros Platise <uros.platise@isotel.eu> -# Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -# TODO, this makefile should run make under the app dirs, instead of -# sourcing the Make.defs! - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# Hello Application -# TODO: appname can be automatically extracted from the directory name - -APPNAME = free -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 768 - -ASRCS = -CSRCS = free.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -# Register application - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -# Create dependencies - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/system/free/free.c b/apps/system/free/free.c deleted file mode 100644 index c44cd5e22..000000000 --- a/apps/system/free/free.c +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - * apps/system/free/free.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/progmem.h> - -#include <stdio.h> -#include <stdlib.h> - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* TODO Max block size only works on uniform prog mem */ - -static void free_getprogmeminfo(struct mallinfo * mem) -{ - uint16_t page = 0, stpage = 0xFFFF; - uint16_t pagesize = 0; - int status; - - mem->arena = 0; - mem->fordblks = 0; - mem->uordblks = 0; - mem->mxordblk = 0; - - for (status=0, page=0; status >= 0; page++) - { - status = up_progmem_ispageerased(page); - pagesize = up_progmem_pagesize(page); - - mem->arena += pagesize; - - /* Is this beginning of new free space section */ - - if (status == 0) - { - if (stpage == 0xFFFF) stpage = page; - mem->fordblks += pagesize; - } - else if (status != 0) - { - mem->uordblks += pagesize; - - if (stpage != 0xFFFF && up_progmem_isuniform()) - { - stpage = page - stpage; - if (stpage > mem->mxordblk) - { - mem->mxordblk = stpage; - } - stpage = 0xFFFF; - } - } - } - - mem->mxordblk *= pagesize; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int free_main(int argc, char **argv) -{ - struct mallinfo data; - struct mallinfo prog; - -#ifdef CONFIG_CAN_PASS_STRUCTS - data = mallinfo(); -#else - (void)mallinfo(&data); -#endif - - free_getprogmeminfo(&prog); - - printf(" total used free largest\n"); - printf("Data: %11d%11d%11d%11d\n", - data.arena, data.uordblks, data.fordblks, data.mxordblk); - printf("Prog: %11d%11d%11d%11d\n", - prog.arena, prog.uordblks, prog.fordblks, prog.mxordblk); - - return OK; -} diff --git a/apps/system/i2c/Kconfig b/apps/system/i2c/Kconfig deleted file mode 100644 index 745378b37..000000000 --- a/apps/system/i2c/Kconfig +++ /dev/null @@ -1,61 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - - -config SYSTEM_I2CTOOL - bool "I2C tool" - default n - depends on I2C - ---help--- - Enable support for the I2C tool. - -config I2CTOOL_BUILTIN - bool "NSH built-in command" - default y - depends on SYSTEM_I2CTOOL && NSH_BUILTIN_APPS - ---help--- - Build the tools as an NSH built-in command - -config I2CTOOL_MINBUS - int "Minimum bus number" - default 0 - depends on SYSTEM_I2CTOOL - ---help--- - Smallest bus index supported by the hardware (default 0). - -config I2CTOOL_MAXBUS - int "Maximum bus number" - depends on SYSTEM_I2CTOOL - default 3 - ---help--- - Largest bus index supported by the hardware (default 3) - -config I2CTOOL_MINADDR - hex "Minimum I2C address" - depends on SYSTEM_I2CTOOL - default 0x03 - ---help--- - Minium 7-bit device address (default: 0x03) - -config I2CTOOL_MAXADDR - hex "Maximum I2C address" - depends on SYSTEM_I2CTOOL - default 0x77 - ---help--- - Largest 7-bit device address (default: 0x77) - -config I2CTOOL_MAXREGADDR - hex "Maximum I2C register address" - default 0xff - depends on SYSTEM_I2CTOOL - ---help--- - Largest I2C register address (default: 0xff) - -config I2CTOOL_DEFFREQ - int "Default I2C frequency" - default 4000000 - depends on SYSTEM_I2CTOOL - ---help--- - Default I2C frequency (default: 4000000) diff --git a/apps/system/i2c/Makefile b/apps/system/i2c/Makefile deleted file mode 100644 index 7f0e6005b..000000000 --- a/apps/system/i2c/Makefile +++ /dev/null @@ -1,108 +0,0 @@ -############################################################################ -# apps/system/i2c/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# I2C tool - -ASRCS = -CSRCS = i2c_bus.c i2c_common.c i2c_dev.c i2c_get.c i2c_main.c i2c_set.c i2c_verf.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . -VPATH = - -APPNAME = i2c -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 -MAXOPTIMIZATION = -Os - -# Build Targets - -all: .built -.PHONY: context .depend depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep - diff --git a/apps/system/i2c/README.txt b/apps/system/i2c/README.txt deleted file mode 100644 index 7b432533b..000000000 --- a/apps/system/i2c/README.txt +++ /dev/null @@ -1,397 +0,0 @@ -README File for the I2C Tool
-============================
-
-The I2C tool provides a way to debug I2C related problems. This README file
-will provide usage information for the I2C tools.
-
-CONTENTS
-========
-
- o System Requirements
- - I2C Driver
- - Configuration Options
- o Help
- o Common Line Form
- o Common Command Options
- - "Sticky" Options
- - Environment variables
- - Common Option Summary
- o Command summary
- - bus
- - dev
- - get
- - set
- - verf
- o I2C Build Configuration
- - NuttX Configuration Requirements
- - I2C Tool Configuration Options
-
-System Requirements
-===================
-
-I2C Driver
-----------
-In order to use the I2C driver, you system -- in particular, your I2C driver --
-must meet certain requirements:
-
-1. It support calling up_i2cinitialize() numerous times, resetting the I2C
- hardware on each (initial) time. up_i2cuninitialize() will be called after
- each call to up_i2cinitialize() to free any resources and disable the I2C.
-2. up_i2cinitialize must accept any interface number without crashing. It
- must simply return NULL if the device is not supported.
-3. The I2C driver must support the transfer method (CONFIG_I2C_TRANSFER=y).
-
-The I2C tool is designed to be implemented as a NuttShell (NSH) add-on. Read
-the apps/nshlib/README.txt file for information about add-ons.
-
-Configuration Options
----------------------
-CONFIG_I2CTOOL_BUILTIN - Build the tools as an NSH built-in command
-CONFIG_I2CTOOL_MINBUS - Smallest bus index supported by the hardware (default 0).
-CONFIG_I2CTOOL_MAXBUS - Largest bus index supported by the hardware (default 3)
-CONFIG_I2CTOOL_MINADDR - Minium device address (default: 0x03)
-CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77)
-CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff)
-CONFIG_I2CTOOL_DEFFREQ - Default frequency (default: 4000000)
-
-HELP
-====
-
-First of all, the I2C tools supports a pretty extensive help output. That
-help output can be view by entering either:
-
- nsh> i2c help
-
-or
-
- nsh> i2c ?
-
-Here is an example of the help output. I shows the general form of the
-command line, the various I2C commands supported with their unique command
-line options, and a more detailed summary of the command I2C command
-options.
-
- nsh> i2c help
- Usage: i2c <cmd> [arguments]
- Where <cmd> is one of:
-
- Show help : ?
- List buses : bus
- List devices : dev [OPTIONS] <first> <last>
- Read register : get [OPTIONS] [<repititions>]
- Show help : help
- Write register: set [OPTIONS] <value> [<repititions>]
- Verify access : verf [OPTIONS] <value> [<repititions>]
-
- Where common "sticky" OPTIONS include:
- [-a addr] is the I2C device address (hex). Default: 03 Current: 03
- [-b bus] is the I2C bus number (decimal). Default: 1 Current: 1
- [-r regaddr] is the I2C device register address (hex). Default: 00 Current: 00
- [-w width] is the data width (8 or 16 decimal). Default: 8 Current: 8
- [-s|n], send/don't send start between command and data. Default: -n Current: -n
- [-i|j], Auto increment|don't increment regaddr on repititions. Default: NO Current: NO
- [-f freq] I2C frequency. Default: 100000 Current: 100000
-
- NOTES:
- o An environment variable like $PATH may be used for any argument.
- o Arguments are "sticky". For example, once the I2C address is
- specified, that address will be re-used until it is changed.
-
- WARNING:
- o The I2C dev command may have bad side effects on your I2C devices.
- Use only at your own risk.
-
-COMMAND LINE FORM
-=================
-
-The I2C is started from NSH by invoking the 'i2c' command from the NSH
-command line. The general form of the 'i2c' command is:
-
- i2c <cmd> [arguments]
-
-Where <cmd> is a "sub-command" and identifies one I2C operations supported
-by the tool. [arguments] represents the list of arguments needed to perform
-the I2C operation. Those arguments vary from command to command as
-described below. However, there is also a core set of common OPTIONS
-supported by all commands. So perhaps a better representation of the
-general I2C command would be:
-
- i2c <cmd> [OPTIONS] [arguments]
-
-Where [OPTIONS] represents the common options and and arguments represent
-the operation-specific arguments.
-
-COMMON COMMAND OPTIONS
-======================
-
-"Sticky" Options
-----------------
-In order to interact with I2C devices, there are a number of I2C parameters
-that must be set correctly. One way to do this would be to provide to set
-the value of each separate command for each I2C parameter. The I2C tool
-takes a different approach, instead: The I2C configuration can be specified
-as a (potentially long) sequence of command line arguments.
-
-These arguments, however, are "sticky." They are sticky in the sense that
-once you set the I2C parameter, that value will remain until it is reset
-with a new value (or until you reset the board).
-
-Environment Variables
----------------------
-NOTE also that if environment variables are not disabled (by
-CONFIG_DISABLE_ENVIRON=y), then these options may also be environment
-variables. Environment variables must be preceded with the special
-character $. For example, PWD is the variable that holds the current
-working directory and so $PWD could be used as a command line argument. The
-use of environment variables on the I2C tools command is really only useful
-if you wish to write NSH scripts to execute a longer, more complex series of
-I2C commands.
-
-Common Option Summary
----------------------
-
-[-a addr] is the I2C device address (hex). Default: 03 Current: 03
-
- The [-a addr] sets the I2C device address. The valid range is 0x03
- through 0x77 (this valid range is controlled by the configuration settings
- CONFIG_I2CTOOL_MINADDR and CONFIG_I2CTOOL_MAXADDR). If you are working
- with the same device, the address needs to be set only once.
-
- All I2C address are 7-bit, hexadecimal values.
-
- NOTE 1: Notice in the "help" output above it shows both default value of
- the I2C address (03 hex) and the current address value (also 03 hex).
-
- NOTE 2: Sometimes I2C addresses are represented as 8-bit values (with
- bit zero indicating a read or write operation). The I2C tool uses a
- 7-bit representation of the address with bit 7 unused and no read/write
- indication in bit 0. Essentially, the 7-bit address is like the 8-bit
- address shifted right by 1.
-
- NOTE 3: Most I2C bus controllers will also support 10-bit addressing.
- That capability has not been integrated into the I2C tool as of this
- writing.
-
-[-b bus] is the I2C bus number (decimal). Default: 1 Current: 1
-
- Most devices support multiple I2C devices and also have unique bus
- numbering. This option identifies which bus you are working with now.
- The valid range of bus numbers is controlled by the configuration settings
- CONFIG_I2CTOOL_MINBUS and CONFIG_I2CTOOL_MAXBUS.
-
- The bus numbers are small, decimal numbers.
-
-[-r regaddr] is the I2C device register address (hex). Default: 00 Current: 00
-
- The I2C set and get commands will access registers on the I2C device. This
- option selects the device register address (sometimes called the sub-address).
- This is an 8-bit hexadecimal value. The maximum value is determined by
- the configuration setting CONFIG_I2CTOOL_MAXREGADDR.
-
-[-w width] is the data width (8 or 16 decimal). Default: 8 Current: 8
-
- Device register data may be 8-bit or 16-bit. This options selects one of
- those two data widths.
-
-[-s|n], send/don't send start between command and data. Default: -n Current: -n
-
- This determines whether or not there should be a new I2C START between
- sending of the register address and sending/receiving of the register data.
-
-[-i|j], Auto increment|don't increment regaddr on repititions. Default: NO Current: NO
-
- On commands that take a optional number of repetitions, the option can be
- used to temporarily increment the regaddr value by one on each repitition.
-
-[-f freq] I2C frequency. Default: 400000 Current: 400000
-
- The [-f freq] sets the frequency of the I2C device.
-
-COMMAND SUMMARY
-===============
-
-We have already seen the I2C help (or ?) commands above. This section will
-discuss the remaining commands.
-
-List buses: bus [OPTIONS]
---------------------------
-
-This command will simply list all of the configured I2C buses and indicate
-which are supported by the driver and which are not:
-
- BUS EXISTS?
- Bus 1: YES
- Bus 2: NO
-
-The valid range of bus numbers is controlled by the configuration settings
-CONFIG_I2CTOOL_MINBUS and CONFIG_I2CTOOL_MAXBUS.
-
-List devices: dev [OPTIONS] <first> <last>
-------------------------------------------
-
-The 'dev' command will attempt to identify all of the I2C devices on the
-selected bus. The <first> and <last> arguments are 7-bit, hexadecimal
-I2C addresses. This command will examine a range of addresses beginning
-with <first> and continuing through <last>. It will request the value
-of register zero from each device.
-
-If the device at an address responds, then this command will display the
-address of the device. If the device does not respond, this command will
-display "--". The resulting display is like:
-
-nsh> i2c dev 03 77
- 0 1 2 3 4 5 6 7 8 9 a b c d e f
-00: -- -- -- -- -- -- -- -- -- -- -- -- --
-10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-40: -- -- -- -- -- -- -- -- -- 49 -- -- -- -- -- --
-50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-70: -- -- -- -- -- -- -- --
-
-WARNINGS:
- o The I2C dev command may have bad side effects on certain I2C devices.
- For example, if could cause data loss in an EEPROM device.
- o The I2C dev command also depends upon the underlying behavior of the
- I2C driver. How does the driver respond to addressing failures?
-
-Read register: get [OPTIONS]
-----------------------------
-
- This command will read the value of the I2C register using the selected
- I2C parameters in the common options. No other arguments are required.
-
- This command with write the 8-bit address value then read an 8- or 16-bit
- data value from the device. Optionally, it may re-start the transfer
- before obtaining the data.
-
- An optional <repititions> argument can be supplied to repeat the
- read operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- read will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- READ Bus: 1 Addr: 49 Subaddr: 04 Value: 96
-
- All values (except the bus numbers) are hexadecimal.
-
-Write register: set [OPTIONS] <value>
--------------------------------------
-
- This command will write a value to an I2C register using the selected
- I2C parameters in the common options. The value to write must be provided
- as the final, hexadecimal value. This value may be an 8-bit value (in the
- range 00-ff) or a 16-bit value (in the range 0000-ffff), depending upon
- the selected data width.
-
- This command will write the 8-bit address value then write the 8- or 16-bit
- data value to the device. Optionally, it may re-start the transfer
- before writing the data.
-
- An optional <repititions> argument can be supplied to repeat the
- write operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- written will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- WROTE Bus: 1 Addr: 49 Subaddr: 04 Value: 96
-
- All values (except the bus numbers) are hexadecimal.
-
-Verify access : verf [OPTIONS] <value> [<repititions>]
-------------------------------------------------------
-
- This command combines writing and reading from an I2C device register.
- It will write a value to an will write a value to an I2C register using
- the selected I2C parameters in the common options just as described for
- tie 'set' command. Then this command will read the value back just
- as described with the 'get' command. Finally, this command will compare
- the value read and against the value written and emit an error message
- if they do not match.
-
- If no value is provided, then this command will use the register address
- itself as the data, providing for a address-in-address test.
-
- An optional <repititions> argument can be supplied to repeat the
- verify operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- written will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- VERIFY Bus: 1 Addr: 49 Subaddr: 04 Wrote: 96 Read: 92 FAILURE
-
- All values (except the bus numbers) are hexadecimal.
-
-I2C BUILD CONFIGURATION
-=======================
-
-NuttX Configuration Requirements
---------------------------------
-The I2C tools requires the following in your NuttX configuration:
-
-1. Device-specific I2C support must be enabled. The I2C tool will call the
- platform-specific function up_i2cinitialize() to get instances of the
- I2C interface and the platform-specific function up_i2cuninitialize()
- to discard instances of the I2C interface.
-
- NOTE 1: The I2C interface is defined in include/nuttx/i2c.h.
-
- NOTE 2: This I2C tool uses direct I2C device interfaces. As such, it
- relies on internal OS interfaces that are not normally available to a
- user-space program. As a result, the I2C tool cannot be used if a
- NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL).
-
-2. I2C driver configuration
-
- The CONFIG_I2C_TRANSFER option must also be set in your NuttX
- configuration. This configuration is the defconfig file in your
- configuration directory that is copied to the NuttX top-level
- directory as .config when NuttX is configured.
-
- CONFIG_I2C_TRANSFER=y
-
- NOTE: CONFIG_I2C_TRANSFER adds extra methods to the I2C interface.
- Not all I2C interfaces support these extra methods. If your platform's
- I2C driver does not support these extra methods, then you cannot use
- the I2C tool unless you extend the support in your platform I2C
- driver.
-
-3. Application configuration.
-
- The path to the I2C tool directory must also be set in your NuttX
- application configuration. This application configuration is the
- appconfig file in your configuration directory that is copied to the
- NuttX application directory as .config when NuttX is configured.
-
- CONFIGURE_APPS += system/i2c
-
-I2C Tool Configuration Options
-------------------------------
-
-The default behavior of the I2C tool can be modified by the setting the
-options in the NuttX configuration. This configuration is the defconfig
-file in your configuration directory that is copied to the NuttX top-level
-directory as .config when NuttX is configured.
-
- CONFIG_I2CTOOL_BUILTIN: Build the tools as an NSH built-in command
- CONFIG_I2CTOOL_MINBUS: Smallest bus index supported by the hardware (default 0).
- CONFIG_I2CTOOL_MAXBUS: Largest bus index supported by the hardware (default 3)
- CONFIG_I2CTOOL_MINADDR: Minium device address (default: 0x03)
- CONFIG_I2CTOOL_MAXADDR: Largest device address (default: 0x77)
- CONFIG_I2CTOOL_MAXREGADDR: Largest register address (default: 0xff)
- CONFIG_I2CTOOL_DEFFREQ: Default frequency (default: 4000000)
diff --git a/apps/system/i2c/i2c_bus.c b/apps/system/i2c/i2c_bus.c deleted file mode 100644 index a684166ff..000000000 --- a/apps/system/i2c/i2c_bus.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_bus.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_bus - ****************************************************************************/ - -int i2ccmd_bus(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - FAR struct i2c_dev_s *dev; - int i; - - i2ctool_printf(i2ctool, " BUS EXISTS?\n"); - for (i = CONFIG_I2CTOOL_MINBUS; i <= CONFIG_I2CTOOL_MAXBUS; i++) - { - dev = up_i2cinitialize(i); - if (dev) - { - i2ctool_printf(i2ctool, "Bus %d: YES\n", i); - (void)up_i2cuninitialize(dev); - } - else - { - i2ctool_printf(i2ctool, "Bus %d: NO\n", i); - } - } - - return OK; -} diff --git a/apps/system/i2c/i2c_common.c b/apps/system/i2c/i2c_common.c deleted file mode 100644 index 4af648c7d..000000000 --- a/apps/system/i2c/i2c_common.c +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_common.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: common_args - ****************************************************************************/ - -int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) -{ - FAR char *ptr = *arg; - long value; - int ret; - - if (ptr[0] != '-') - { - goto invalid_argument; - } - - switch (ptr[1]) - { - case 'a': - ret = arg_hex(arg, &value); - if (value < CONFIG_I2CTOOL_MINADDR || value > CONFIG_I2CTOOL_MAXADDR) - { - goto out_of_range; - } - - i2ctool->addr = (uint8_t) value; - return ret; - - case 'b': - ret = arg_decimal(arg, &value); - if (value < CONFIG_I2CTOOL_MINBUS || value > CONFIG_I2CTOOL_MAXBUS) - { - goto out_of_range; - } - - i2ctool->bus = (uint8_t) value; - return ret; - - case 'f': - ret = arg_decimal(arg, &value); - if (value == 0) - { - goto out_of_range; - } - - i2ctool->freq = value; - return ret; - - case 'i': - i2ctool->autoincr = true; - return 1; - - case 'j': - i2ctool->autoincr = false; - return 1; - - case 'n': - i2ctool->start = false; - return 1; - - case 'r': - ret = arg_hex(arg, &value); - if (value < 0 || value > CONFIG_I2CTOOL_MAXREGADDR) - { - goto out_of_range; - } - - i2ctool->regaddr = (uint8_t) value; - return ret; - - case 's': - i2ctool->start = true; - return 1; - - case 'w': - ret = arg_decimal(arg, &value); - if (value != 8 && value != 16) - { - goto out_of_range; - } - - i2ctool->width = (uint8_t) value; - return ret; - - default: - goto invalid_argument; - } - -invalid_argument: - i2ctool_printf(i2ctool, g_i2carginvalid, ptr); - return ERROR; - -out_of_range: - i2ctool_printf(i2ctool, g_i2cargrange, ptr); - return ERROR; -} - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} - -/**************************************************************************** - * Name: arg_hex - ****************************************************************************/ - -int arg_hex(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 16); - return ret; -} diff --git a/apps/system/i2c/i2c_dev.c b/apps/system/i2c/i2c_dev.c deleted file mode 100644 index 3d0480a15..000000000 --- a/apps/system/i2c/i2c_dev.c +++ /dev/null @@ -1,235 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_dev.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_dev - ****************************************************************************/ - -int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - FAR struct i2c_dev_s *dev; - struct i2c_msg_s msg[2]; - FAR char *ptr; - union - { - uint16_t data16; - uint8_t data8; - } u; - - uint8_t regaddr; - long first; - long last; - int addr; - int nargs; - int argndx; - int ret; - int i; - int j; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There should be exactly two more things on the command line: The first and - * last addresses to be probed. - */ - - if (argndx+1 < argc) - { - first = strtol(argv[argndx], NULL, 16); - last = strtol(argv[argndx+1], NULL, 16); - if (first < 0 || first > 0x7f || last < 0 || last > 0x7f || first > last) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx += 2; - } - else - { - i2ctool_printf(i2ctool, g_i2cargrequired, argv[0]); - return ERROR; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - - /* Probe each address */ - - i2ctool_printf(i2ctool, " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); - for (i = 0; i < 128; i += 16) - { - i2ctool_printf(i2ctool, "%02x: ", i); - for (j = 0; j < 16; j++) - { - /* Skip addresses that are out of the selected range */ - - addr = i+j; - if (addr < first || addr > last) - { - i2ctool_printf(i2ctool, " "); - continue; - } - - /* Set the I2C address */ - - I2C_SETADDRESS(dev, addr, 7); - - /* Set up data structures */ - - regaddr = 0; - - msg[0].addr = addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = addr; - msg[1].flags = I2C_M_READ; - if (i2ctool->width == 8) - { - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret == OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - if (ret == OK) - { - i2ctool_printf(i2ctool, "%02x ", addr); - } - else - { - i2ctool_printf(i2ctool, "-- "); - } - } - i2ctool_printf(i2ctool, "\n"); - i2ctool_flush(i2ctool); - } - - (void)up_i2cuninitialize(dev); - return OK; -} diff --git a/apps/system/i2c/i2c_get.c b/apps/system/i2c/i2c_get.c deleted file mode 100644 index 08510af4b..000000000 --- a/apps/system/i2c/i2c_get.c +++ /dev/null @@ -1,257 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_get.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_get - ****************************************************************************/ - -int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint16_t result; - uint8_t regaddr; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* Read from the I2C bus */ - - ret = i2ctool_get(i2ctool, dev, regaddr, &result); - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "READ Bus: %d Addr: %02x Subaddr: %02x Value: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x\n", result); - } - else - { - i2ctool_printf(i2ctool, "%04x\n", result); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} - -/**************************************************************************** - * Name: i2ctool_get - ****************************************************************************/ - -int i2ctool_get(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t *result) -{ - struct i2c_msg_s msg[2]; - union - { - uint16_t data16; - uint8_t data8; - } u; - int ret; - - /* Set up data structures */ - - msg[0].addr = i2ctool->addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = i2ctool->addr; - msg[1].flags = I2C_M_READ; - if (i2ctool->width == 8) - { - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret== OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - /* Return the result of the read operation */ - - if (ret == OK) - { - if (i2ctool->width == 8) - { - *result = (uint16_t)u.data8; - } - else - { - *result = u.data16; - } - } - return ret; -} diff --git a/apps/system/i2c/i2c_main.c b/apps/system/i2c/i2c_main.c deleted file mode 100644 index 0cf6786cb..000000000 --- a/apps/system/i2c/i2c_main.c +++ /dev/null @@ -1,446 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_main.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <stdarg.h> -#include <assert.h> -#include <errno.h> -#include <debug.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv); -static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **argv); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -struct i2ctool_s g_i2ctool; - -static const struct cmdmap_s g_i2ccmds[] = -{ - { "?", i2ccmd_help, "Show help ", NULL }, - { "bus", i2ccmd_bus, "List busses ", NULL }, - { "dev", i2ccmd_dev, "List devices ", "[OPTIONS] <first> <last>" }, - { "get", i2ccmd_get, "Read register ", "[OPTIONS] [<repititions>]" }, - { "help", i2ccmd_help, "Show help ", NULL }, - { "set", i2ccmd_set, "Write register", "[OPTIONS] <value> [<repititions>]" }, - { "verf", i2ccmd_verf, "Verify access ", "[OPTIONS] [<value>] [<repititions>]" }, - { NULL, NULL, NULL, NULL } -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Common, message formats */ - -const char g_i2cargrequired[] = "i2ctool: %s: missing required argument(s)\n"; -const char g_i2carginvalid[] = "i2ctool: %s: argument invalid\n"; -const char g_i2cargrange[] = "i2ctool: %s: value out of range\n"; -const char g_i2ccmdnotfound[] = "i2ctool: %s: command not found\n"; -const char g_i2ctoomanyargs[] = "i2ctool: %s: too many arguments\n"; -const char g_i2ccmdfailed[] = "i2ctool: %s: %s failed: %d\n"; -const char g_i2cxfrerror[] = "i2ctool: %s: Transfer failed: %d\n"; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_help - ****************************************************************************/ - -static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - const struct cmdmap_s *ptr; - - i2ctool_printf(i2ctool, "Usage: i2c <cmd> [arguments]\n"); - i2ctool_printf(i2ctool, "Where <cmd> is one of:\n\n"); - for (ptr = g_i2ccmds; ptr->cmd; ptr++) - { - if (ptr->usage) - { - i2ctool_printf(i2ctool, " %s: %s %s\n", ptr->desc, ptr->cmd, ptr->usage); - } - else - { - i2ctool_printf(i2ctool, " %s: %s\n", ptr->desc, ptr->cmd); - } - } - - i2ctool_printf(i2ctool, "\nWhere common \"sticky\" OPTIONS include:\n"); - i2ctool_printf(i2ctool, " [-a addr] is the I2C device address (hex). " - "Default: %02x Current: %02x\n", - CONFIG_I2CTOOL_MINADDR, i2ctool->addr); - i2ctool_printf(i2ctool, " [-b bus] is the I2C bus number (decimal). " - "Default: %d Current: %d\n", - CONFIG_I2CTOOL_MINBUS, i2ctool->bus); - i2ctool_printf(i2ctool, " [-r regaddr] is the I2C device register address (hex). " - "Default: 00 Current: %02x\n", - i2ctool->regaddr); - i2ctool_printf(i2ctool, " [-w width] is the data width (8 or 16 decimal). " - "Default: 8 Current: %d\n", - i2ctool->width); - i2ctool_printf(i2ctool, " [-s|n], send/don't send start between command and data. " - "Default: -n Current: %s\n", - i2ctool->start ? "-s" : "-n"); - i2ctool_printf(i2ctool, " [-i|j], Auto increment|don't increment regaddr on repititions. " - "Default: NO Current: %s\n", - i2ctool->autoincr ? "YES" : "NO"); - i2ctool_printf(i2ctool, " [-f freq] I2C frequency. " - "Default: %d Current: %d\n", - CONFIG_I2CTOOL_DEFFREQ, i2ctool->freq); - i2ctool_printf(i2ctool, "\nNOTES:\n"); -#ifndef CONFIG_DISABLE_ENVIRON - i2ctool_printf(i2ctool, "o An environment variable like $PATH may be used for any argument.\n"); -#endif - i2ctool_printf(i2ctool, "o Arguments are \"sticky\". For example, once the I2C address is\n"); - i2ctool_printf(i2ctool, " specified, that address will be re-used until it is changed.\n"); - i2ctool_printf(i2ctool, "\nWARNING:\n"); - i2ctool_printf(i2ctool, "o The I2C dev command may have bad side effects on your I2C devices.\n"); - i2ctool_printf(i2ctool, " Use only at your own risk.\n"); - return OK; -} - -/**************************************************************************** - * Name: i2ccmd_unrecognized - ****************************************************************************/ - -static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - i2ctool_printf(i2ctool, g_i2ccmdnotfound, argv[0]); - return ERROR; -} - -/**************************************************************************** - * Name: i2c_execute - ****************************************************************************/ - -static int i2c_execute(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) -{ - const struct cmdmap_s *cmdmap; - const char *cmd; - cmd_t handler; - int ret; - - /* The form of argv is: - * - * argv[0]: The command name. This is argv[0] when the arguments - * are, finally, received by the command vtblr - * argv[1]: The beginning of argument (up to MAX_ARGUMENTS) - * argv[argc]: NULL terminating pointer - */ - - /* See if the command is one that we understand */ - - cmd = argv[0]; - handler = i2ccmd_unrecognized; - - for (cmdmap = g_i2ccmds; cmdmap->cmd; cmdmap++) - { - if (strcmp(cmdmap->cmd, cmd) == 0) - { - handler = cmdmap->handler; - break; - } - } - - ret = handler(i2ctool, argc, argv); - return ret; -} - -/**************************************************************************** - * Name: i2c_argument - ****************************************************************************/ - -FAR char *i2c_argument(FAR struct i2ctool_s *i2ctool, int argc, char *argv[], int *pindex) -{ - FAR char *arg; - int index = *pindex; - - /* If we are at the end of the arguments with nothing, then return NULL */ - - if (index >= argc) - { - return NULL; - } - - /* Get the return parameter */ - - arg = argv[index]; - *pindex = index + 1; - -#ifndef CONFIG_DISABLE_ENVIRON - /* Check for references to environment variables */ - - if (arg[0] == '$') - { - /* Return the value of the environment variable with this name */ - - FAR char *value = getenv(arg+1); - if (value) - { - return value; - } - else - { - return (FAR char*)""; - } - } -#endif - - /* Return the next argument. */ - - return arg; -} - -/**************************************************************************** - * Name: i2c_parse - ****************************************************************************/ - -int i2c_parse(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) -{ - FAR char *newargs[MAX_ARGUMENTS+2]; - FAR char *cmd; - int nargs; - int index; - - /* Parse out the command, skipping the first argument (the program name)*/ - - index = 1; - cmd = i2c_argument(i2ctool, argc, argv, &index); - - /* Check if any command was provided */ - - if (!cmd) - { - /* An empty line is not an error and an unprocessed command cannot - * generate an error, but neither should they change the last - * command status. - */ - - return i2ccmd_help(i2ctool, 0, NULL); - } - - /* Parse all of the arguments following the command name. */ - - newargs[0] = cmd; - for (nargs = 1; nargs <= MAX_ARGUMENTS; nargs++) - { - newargs[nargs] = i2c_argument(i2ctool, argc, argv, &index); - if (!newargs[nargs]) - { - break; - } - } - newargs[nargs] = NULL; - - /* Then execute the command */ - - return i2c_execute(i2ctool, nargs, newargs); -} - -/**************************************************************************** - * Name: i2c_setup - ****************************************************************************/ - -static inline int i2c_setup(FAR struct i2ctool_s *i2ctool) -{ - /* Initialize the output stream */ - -#ifdef CONFIG_I2CTOOL_OUTDEV - i2ctool->ss_outfd = open(CONFIG_I2CTOOL_OUTDEV, O_WRONLY); - if (i2ctool->ss_outfd < 0) - { - fprintf(stderr, g_i2ccmdfailed, "open", errno); - return ERROR; - } - - /* Create a standard C stream on the console device */ - - i2ctool->ss_outstream = fdopen(i2ctool->ss_outfd, "w"); - if (!i2ctool->ss_outstream) - { - fprintf(stderr, g_i2ccmdfailed, "fdopen", errno); - return ERROR; - } -#endif - - return OK; -} - -/**************************************************************************** - * Name: i2c_teardown - * - * Description: - * Close the output stream if it is not the standard output stream. - * - ****************************************************************************/ - -static void i2c_teardown(FAR struct i2ctool_s *i2ctool) -{ - fflush(OUTSTREAM(&g_i2ctool)); - -#ifdef CONFIG_I2CTOOL_OUTDEV - fclose(i2ctool->ss_outstream); -#endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2c_main - ****************************************************************************/ - -int i2c_main(int argc, char *argv[]) -{ - /* Verify settings */ - - if (g_i2ctool.bus < CONFIG_I2CTOOL_MINBUS || g_i2ctool.bus > CONFIG_I2CTOOL_MAXBUS) - { - g_i2ctool.bus = CONFIG_I2CTOOL_MINBUS; - } - - if (g_i2ctool.addr < CONFIG_I2CTOOL_MINADDR || g_i2ctool.addr > CONFIG_I2CTOOL_MAXADDR) - { - g_i2ctool.addr = CONFIG_I2CTOOL_MINADDR; - } - - if (g_i2ctool.regaddr < CONFIG_I2CTOOL_MAXREGADDR) - { - g_i2ctool.regaddr = 0; - } - - if (g_i2ctool.width != 8 && g_i2ctool.width != 16) - { - g_i2ctool.width = 8; - } - - if (g_i2ctool.freq == 0) - { - g_i2ctool.freq = CONFIG_I2CTOOL_DEFFREQ; - } - - /* Parse process the command line */ - - i2c_setup(&g_i2ctool); - (void)i2c_parse(&g_i2ctool, argc, argv); - - i2ctool_flush(&g_i2ctool); - i2c_teardown(&g_i2ctool); - return OK; -} - -/**************************************************************************** - * Name: i2ctool_printf - * - * Description: - * Print a string to the currently selected stream. - * - ****************************************************************************/ - -int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = vfprintf(OUTSTREAM(i2ctool), fmt, ap); - va_end(ap); - - return ret; -} - -/**************************************************************************** - * Name: i2ctool_write - * - * Description: - * write a buffer to the currently selected stream. - * - ****************************************************************************/ - -ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes) -{ - ssize_t ret; - - /* Write the data to the output stream */ - - ret = fwrite(buffer, 1, nbytes, OUTSTREAM(i2ctool)); - if (ret < 0) - { - dbg("[%d] Failed to send buffer: %d\n", OUTFD(i2ctool), errno); - } - return ret; -} - -/**************************************************************************** - * Name: i2ctool_flush - * - * Description: - * Flush buffered I/O to the currently selected stream. - * - ****************************************************************************/ - -void i2ctool_flush(FAR struct i2ctool_s *i2ctool) -{ - fflush(OUTSTREAM(i2ctool)); -} diff --git a/apps/system/i2c/i2c_set.c b/apps/system/i2c/i2c_set.c deleted file mode 100644 index 5baf7f835..000000000 --- a/apps/system/i2c/i2c_set.c +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_set.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_set - ****************************************************************************/ - -int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint8_t regaddr; - long value; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There must be at least one more thing on the command line: The value - * to be written. - */ - - if (argndx < argc) - { - value = strtol(argv[argndx], NULL, 16); - if (i2ctool->width == 8) - { - if (value < 0 || value > 255) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - } - else if (value < 0 || value > 65535) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - else - { - i2ctool_printf(i2ctool, g_i2cargrequired, argv[0]); - return ERROR; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* Write to the I2C bus */ - - ret = i2ctool_set(i2ctool, dev, regaddr, (uint16_t)value); - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "WROTE Bus: %d Addr: %02x Subaddr: %02x Value: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x\n", (int)value); - } - else - { - i2ctool_printf(i2ctool, "%04x\n", (int)value); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} - -/**************************************************************************** - * Name: i2ctool_set - ****************************************************************************/ - -int i2ctool_set(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t value) -{ - struct i2c_msg_s msg[2]; - union - { - uint16_t data16; - uint8_t data8; - } u; - int ret; - - /* Set up data structures */ - - msg[0].addr = i2ctool->addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = i2ctool->addr; - msg[1].flags = 0; - if (i2ctool->width == 8) - { - u.data8 = (uint8_t)value; - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - u.data16 = value; - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret == OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - return ret; -} diff --git a/apps/system/i2c/i2c_verf.c b/apps/system/i2c/i2c_verf.c deleted file mode 100644 index 109e9c4ce..000000000 --- a/apps/system/i2c/i2c_verf.c +++ /dev/null @@ -1,249 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_verf.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_verf - ****************************************************************************/ - -int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint16_t rdvalue; - uint8_t regaddr; - bool addrinaddr; - long wrvalue; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* The options may be followed by the optional wrvalue to be written. If omitted, then - * the register address will be used as the wrvalue, providing an address-in-address - * test. - */ - - addrinaddr = true; - wrvalue = 0; - - if (argndx < argc) - { - wrvalue = strtol(argv[argndx], NULL, 16); - if (i2ctool->width == 8) - { - if (wrvalue < 0 || wrvalue > 255) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - } - else if (wrvalue < 0 || wrvalue > 65535) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - addrinaddr = false; - argndx++; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* If we are performing an address-in-address test, then use the register - * address as the value to write. - */ - - if (addrinaddr) - { - wrvalue = regaddr; - } - - /* Write to the I2C bus */ - - ret = i2ctool_set(i2ctool, dev, regaddr, (uint16_t)wrvalue); - if (ret == OK) - { - /* Read the value back from the I2C bus */ - - ret = i2ctool_get(i2ctool, dev, regaddr, &rdvalue); - } - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "VERIFY Bus: %d Addr: %02x Subaddr: %02x Wrote: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x Read: %02x", (int)wrvalue, (int)rdvalue); - } - else - { - i2ctool_printf(i2ctool, "%04x Read: %04x", (int)wrvalue, (int)rdvalue); - } - - if (wrvalue != rdvalue) - { - i2ctool_printf(i2ctool, " <<< FAILURE\n"); - } - else - { - i2ctool_printf(i2ctool, "\n"); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} diff --git a/apps/system/i2c/i2ctool.h b/apps/system/i2c/i2ctool.h deleted file mode 100644 index 4ff26d03e..000000000 --- a/apps/system/i2c/i2ctool.h +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2ctool.h - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_SYSTEM_I2C_I2CTOOLS_H -#define __APPS_SYSTEM_I2C_I2CTOOLS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/compiler.h> - -#include <sys/types.h> -#include <stdio.h> -#include <stdint.h> -#include <stdbool.h> -#include <errno.h> - -#include <nuttx/i2c.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* CONFIG_I2CTOOL_BUILTIN - Build the tools as an NSH built-in command - * CONFIG_I2CTOOL_MINBUS - Smallest bus index supported by the hardware (default 0). - * CONFIG_I2CTOOL_MAXBUS - Largest bus index supported by the hardware (default 3) - * CONFIG_I2CTOOL_MINADDR - Minium device address (default: 0x03) - * CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77) - * CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff) - * CONFIG_I2CTOOL_DEFFREQ - Default frequency (default: 4000000) - */ - -#ifndef CONFIG_I2C_TRANSFER -# error "CONFIG_I2C_TRANSFER is required in the configuration" -#endif - -#ifndef CONFIG_I2CTOOL_MINBUS -# define CONFIG_I2CTOOL_MINBUS 0 -#endif - -#ifndef CONFIG_I2CTOOL_MAXBUS -# define CONFIG_I2CTOOL_MAXBUS 3 -#endif - -#ifndef CONFIG_I2CTOOL_MINADDR -# define CONFIG_I2CTOOL_MINADDR 0x03 -#endif - -#ifndef CONFIG_I2CTOOL_MAXADDR -# define CONFIG_I2CTOOL_MAXADDR 0x77 -#endif - -#ifndef CONFIG_I2CTOOL_MAXREGADDR -# define CONFIG_I2CTOOL_MAXREGADDR 0xff -#endif - -#ifndef CONFIG_I2CTOOL_DEFFREQ -# define CONFIG_I2CTOOL_DEFFREQ 100000 -#endif - -/* This is the maximum number of arguments that will be accepted for a - * command. The only real limit is in the OS configuration that limits - * the number of parameters passed to a task. - */ - -#define MAX_ARGUMENTS (CONFIG_MAX_TASK_ARGS-1) - -/* Maximum size of one command line */ - -#define MAX_LINELEN 80 - -/* Are we using the NuttX console for I/O? Or some other character device? */ - -#ifdef CONFIG_I2CTOOL_INDEV -# define INFD(p) ((p)->ss_infd) -# define INSTREAM(p) ((p)->ss_instream) -#else -# define INFD(p) 0 -# define INSTREAM(p) stdin -#endif - -#ifdef CONFIG_I2CTOOL_OUTDEV -# define OUTFD(p) ((p)->ss_outfd) -# define OUTSTREAM(p) ((p)->ss_outstream) -#else -# define OUTFD(p) 1 -# define OUTSTREAM(p) stdout -#endif - -/* Output is via printf but can be changed using this macro */ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# define i2c_output(v, fmt...) printf(v, ##fmt) -#else -# define i2c_output printf -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct i2ctool_s -{ - /* Sticky options */ - - uint8_t addr; /* [-a addr] is the I2C device address */ - uint8_t bus; /* [-b bus] is the I2C bus number */ - uint8_t regaddr; /* [-r regaddr] is the I2C device register address */ - uint8_t width; /* [-w width] is the data width (8 or 16) */ - bool start; /* [-s|n], send|don't send start between command and data */ - bool autoincr; /* [-i|j], Auto increment|don't increment regaddr on repititions */ - uint32_t freq; /* [-f freq] I2C frequency */ - - /* Output streams */ - -#ifdef CONFIG_I2CTOOL_OUTDEV - int ss_outfd; /* Output file descriptor */ - FILE *ss_outstream; /* Output stream */ -#endif -}; - -typedef int (*cmd_t)(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); - -struct cmdmap_s -{ - FAR const char *cmd; /* Name of the command */ - cmd_t handler; /* Function that handles the command */ - FAR const char *desc; /* Short description */ - FAR const char *usage; /* Usage instructions for 'help' command */ -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern const char g_i2cargrequired[]; -extern const char g_i2carginvalid[]; -extern const char g_i2cargrange[]; -extern const char g_i2ccmdnotfound[]; -extern const char g_i2ctoomanyargs[]; -extern const char g_i2ccmdfailed[]; -extern const char g_i2cxfrerror[]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Message handler */ - -ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes); -int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...); -void i2ctool_flush(FAR struct i2ctool_s *i2ctool); - -/* Command handlers */ - -int i2ccmd_bus(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); - -/* I2C access functions */ - -int i2ctool_get(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t addr, uint16_t *result); -int i2ctool_set(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t value); - -/* Common logic */ - -int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg); -int arg_string(FAR char **arg, FAR char **value); -int arg_decimal(FAR char **arg, FAR long *value); -int arg_hex(FAR char **arg, FAR long *value); - -#endif /* __APPS_SYSTEM_I2C_I2CTOOLS_H */ diff --git a/apps/system/install/Kconfig b/apps/system/install/Kconfig deleted file mode 100644 index a48f67f20..000000000 --- a/apps/system/install/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config SYSTEM_INSTALL - bool "FLASH installation tool" - default n - ---help--- - Enable support for the FLASH installation tool. - -if SYSTEM_INSTALL -endif - diff --git a/apps/system/install/Makefile b/apps/system/install/Makefile deleted file mode 100644 index 07d42887a..000000000 --- a/apps/system/install/Makefile +++ /dev/null @@ -1,121 +0,0 @@ -############################################################################ -# apps/system/install/Makefile -# -# Copyright (C) 2011 Uros Platise. All rights reserved. -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Uros Platise <uros.platise@isotel.eu> -# Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -# TODO, this makefile should run make under the app dirs, instead of -# sourcing the Make.defs! - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# Hello Application -# TODO: appname can be automatically extracted from the directory name - -APPNAME = install -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 1024 - -ASRCS = -CSRCS = install.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -# Register application - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -# Create dependencies - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/system/install/README.txt b/apps/system/install/README.txt deleted file mode 100644 index 66e9b0939..000000000 --- a/apps/system/install/README.txt +++ /dev/null @@ -1,26 +0,0 @@ - -Install Program -=============== - - Source: NuttX - Author: Uros Platise - Date: 7. May 2011 - -This application installs XIP application by placing it directly into -the program memory (flash) area into free area and creates a start-up -script into selected directory (i.e. /usr/bin/progname). - -Usage: - install [--stack RequiredStackSpace] [--priority Priority] - source-file destination-directory - -If stackspace is not given default stack space of 4096 Bytes is used. -If priority is not given system default is used. - -Additional options: - - --remove destination-file i.e. install --remove /usr/bin/myapp - --force to replace existing installation - --start <page> install app at or after <page> - --margin <pages> leave some free space after the kernel - Default is 16 pages so kernel may grow. diff --git a/apps/system/install/install.c b/apps/system/install/install.c deleted file mode 100644 index fd14b7a6f..000000000 --- a/apps/system/install/install.c +++ /dev/null @@ -1,470 +0,0 @@ -/**************************************************************************** - * apps/system/install/install.c - * - * Copyright (C) 2011 Uros Platise. All rights reserved. - * Author: Uros Platise <uros.platise@isotel.eu> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/progmem.h> -#include <sys/stat.h> - -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ACTION_INSTALL 0x01 -#define ACTION_REMOVE 0x00 -#define ACTION_REINSTALL 0x03 -#define ACTION_INSUFPARAM 0x80 - -#define INSTALL_PROGRAMBLOCKSIZE 1024 - -/**************************************************************************** - * Private data - ****************************************************************************/ - -static const char *install_help = - "Installs XIP program into flash and creates a start-up script in the\n" - "destination directory.\n\n" - "Usage:\t%s [options] source-file.xip destination-directory\n\n" - "Example:\n\t%s --stack 1024 /sdcard/demo.xip /usr/bin\n\n" - "Options:\n" - "\t--stack <required_stack_space>\n" - "\t--priority <priority>\n" - "\t--remove <dest-file>\tRemoves installed application\n" - "\t--force\t\t\tReplaces existing installation\n" - "\t--start <page>\t\tInstalls application at or after <page>\n" - "\t--margin <pages>\tLeave some free space after the kernel (default 16)\n"; - -static const char *install_script_text = - "# XIP stacksize=%x priority=%x size=%x\n"; - -static const char *install_script_exec = - "exec 0x%x\n"; - -/**************************************************************************** - * Private functions - ****************************************************************************/ - -static int install_getstartpage(int startpage, int pagemargin, int desiredsize) -{ - uint16_t page = 0, stpage = 0xffff; - uint16_t pagesize = 0; - int maxlen = -1; - int maxlen_start = 0xffff; - int status; - - for (status=0, page=0; status >= 0; page++) - { - status = up_progmem_ispageerased(page); - pagesize = up_progmem_pagesize(page); - - /* Is this beginning of new free space section */ - - if (status == 0) - { - if (stpage == 0xffff) stpage = page; - } - else if (status != 0) - { - if (stpage != 0xffff) - { - if ((page - stpage) > maxlen) - { - if (maxlen==-1) - { - /* First time found sth? */ - - stpage += pagemargin; - maxlen = 0; - } - - if(stpage < startpage) - { - stpage = startpage; - } - - if (page > stpage) - { - maxlen = page - stpage; - maxlen_start = stpage; - } - - if (maxlen*pagesize >= desiredsize) - { - /* printf("Found page at %d ... %d\n", stpage, page); */ - return maxlen_start*pagesize; - } - } - - stpage = 0xffff; - } - } - } - - /* Requested space is not available */ - - return -1; -} - -static int install_programflash(int startaddr, const char *source) -{ - int status; - int count; - int totalsize = 0; - char *buf; - FILE *fp; - - if ((buf = malloc(INSTALL_PROGRAMBLOCKSIZE)) == NULL) - { - return -ENOMEM; - } - - if ((fp = fopen(source, "r"))) - { - do - { - count = fread(buf, 1, INSTALL_PROGRAMBLOCKSIZE, fp); - - if ((status = up_progmem_write(startaddr, buf, count)) < 0) - { - totalsize = status; - break; - } - - startaddr += count; - totalsize += count; - } - while(count); - } - else - { - totalsize = -errno; - } - - fclose(fp); - free(buf); - - return totalsize; -} - -static void install_getscriptname(char *scriptname, const char *progname, const char *destdir) -{ - const char * progonly; - - /* I.e. as /usr/bin */ - - strcpy(scriptname, destdir); - - /* extract from i.e. /sdcard/demo -> /demo, together with / */ - - progonly = strrchr(progname, '/'); - strcat(scriptname, progonly); -} - -static int install_getprogsize(const char *progname) -{ - struct stat fileinfo; - - if (stat(progname, &fileinfo) < 0) - { - return -1; - } - - return fileinfo.st_size; -} - -static int install_alreadyexists(const char *scriptname) -{ - FILE *fp; - - if ((fp = fopen(scriptname, "r")) == NULL) - { - return 0; - } - - fclose(fp); - return 1; -} - -static int install_createscript(int addr, int stacksize, int progsize, - int priority, const char *scriptname) -{ - FILE *fp; - - if ((fp = fopen(scriptname, "w+")) == NULL) - { - return -errno; - } - - fprintf(fp, install_script_text, stacksize, priority, progsize); - fprintf(fp, install_script_exec, addr); - - fflush(fp); - fclose(fp); - - return 0; -} - -static int install_getlasthexvalue(FILE *fp, char delimiter) -{ - char buf[128]; - char *p; - - if (fgets(buf, 127, fp)) - { - if ((p = strrchr(buf, delimiter))) - { - return strtol(p+1, NULL, 16); - } - } - - return -1; -} - -static int install_remove(const char *scriptname) -{ - FILE *fp; - int progsize, addr, freedsize; - uint16_t page; - int status = 0; - - /* Parse script */ - - if ((fp = fopen(scriptname, "r"))) - { - progsize = install_getlasthexvalue(fp,'='); - addr = install_getlasthexvalue(fp,' '); - freedsize = progsize; - } - else - { - return -errno; - } - - fclose(fp); - - /* Remove pages */ - - if (progsize <= 0 || addr <= 0) - { - return -EIO; - } - - do - { - if ((page = up_progmem_getpage(addr)) < 0) - { - status = -page; - break; - } - - if (up_progmem_erasepage(page) < 0) - { - status = -page; - break; - } - - addr += up_progmem_pagesize(page); - progsize -= up_progmem_pagesize(page); - - } - while(progsize > 0); - - if (status < 0) - { - return status; - } - - /* Remove script file */ - - if (unlink(scriptname) < 0) - { - return -errno; - } - - return freedsize; -} - - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int install_main(int argc, char *argv[]) -{ - int i; - int progsize; - int scrsta; - int stacksize = 4096; - int priority = SCHED_PRIORITY_DEFAULT; - int pagemargin = 16; - int startpage = 0; - int startaddr = 0; - int action = ACTION_INSTALL; - char scriptname[128]; - - /* Supported? */ - - if (!up_progmem_isuniform()) - { - fprintf(stderr, "Error: install supports uniform organization only.\n"); - return -1; - } - - /* Parse arguments */ - - for (i=1; i<argc; i++) - { - if (argv[i][0]=='-' && argv[i][1]=='-' && i<=argc) - { - if (strcmp(argv[i]+2, "stack")==0) - { - stacksize = atoi(argv[++i]); - } - else if (strcmp(argv[i]+2, "priority")==0) - { - priority = atoi(argv[++i]); - } - else if (strcmp(argv[i]+2, "start")==0) - { - startpage = atoi(argv[++i]); - } - else if (strcmp(argv[i]+2, "margin")==0) - { - pagemargin = atoi(argv[++i]); - } - else if (strcmp(argv[i]+2, "remove")==0) - { - action = ACTION_REMOVE; - } - else if (strcmp(argv[i]+2, "force")==0) - { - action = ACTION_REINSTALL; - } - else fprintf(stderr, "Unknown option: %s\n", argv[i]); - } - else - { - break; - } - } - - /* Do the job */ - - switch(action & 1) - { - case ACTION_REMOVE: - if (i > argc-1) - { - action = ACTION_INSUFPARAM; - break; /* are there sufficient parameters */ - } - - if ((scrsta=install_remove(argv[i])) < 0) - { - fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta)); - return -1; - } - - printf("Removed %s and freed %d bytes\n", argv[i], scrsta); - return 0; - - case ACTION_INSTALL: - if (i > argc-2) - { - action = ACTION_INSUFPARAM; - break; /* are there sufficient parameters */ - } - - install_getscriptname(scriptname, argv[i], argv[i+1]); - - /* script-exists? */ - - if (install_alreadyexists(scriptname) == 1) - { - if (action != ACTION_REINSTALL) - { - fprintf(stderr, "Program with that name already exists.\n"); - return -EEXIST; - } - - if ((scrsta = install_remove(scriptname)) < 0) - { - fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta)); - return -1; - } - - printf("Replacing %s\n", scriptname); - } - - startaddr = install_getstartpage(startpage, pagemargin, install_getprogsize(argv[i])); - if (startpage < 0) - { - fprintf(stderr, "Not enough memory\n"); - return -ENOMEM; - } - - if ((progsize = install_programflash(startaddr, argv[i])) <= 0) - { - fprintf(stderr, "Error writing program memory: %s\n" - "Note: Flash pages are not released, so you may try again and program will be\n" - " written in other pages.\n", strerror(-progsize)); - return -EIO; - } - - if ((scrsta = install_createscript(startaddr, stacksize, progsize, - priority, scriptname)) < 0) - { - fprintf(stderr, "Error writing program script at %s: %s\n", - argv[i+1], strerror(-scrsta)); - return -EIO; - } - - printf("Installed application of size %d bytes to program memory [%xh - %xh].\n", - progsize, startaddr, startaddr + progsize); - return 0; - } - - fprintf(stderr, install_help, argv[0], argv[0]); - return -1; -} diff --git a/apps/system/readline/Kconfig b/apps/system/readline/Kconfig deleted file mode 100644 index 6482b1204..000000000 --- a/apps/system/readline/Kconfig +++ /dev/null @@ -1,22 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config SYSTEM_READLINE - bool "readline() support" - default n - ---help--- - Enable support for the readline() function. - -if SYSTEM_READLINE -config READLINE_ECHO - bool "Echo character input" - default y - ---help--- - Echo received character input back via stdout. This is normal - behavior and should be selected unless the source of stdin input - already has local echo support or you need to suppress the back-channel - responses for any other reason. - -endif diff --git a/apps/system/readline/Makefile b/apps/system/readline/Makefile deleted file mode 100644 index 040fd2e28..000000000 --- a/apps/system/readline/Makefile +++ /dev/null @@ -1,106 +0,0 @@ -############################################################################ -# apps/system/readline/Makefile -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# The Readline Library - -ASRCS = -CSRCS = readline.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -# Context build phase target - -context: - -# Dependency build phase target - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -# Housekeeping targets - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c deleted file mode 100644 index a8240a62a..000000000 --- a/apps/system/readline/readline.c +++ /dev/null @@ -1,432 +0,0 @@ -/**************************************************************************** - * apps/system/readline/readline.c - * - * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include <debug.h> - -#include <nuttx/ascii.h> -#include <nuttx/vt100.h> - -#include <apps/readline.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* In some systems, the underlying serial logic may automatically echo - * characters back to the console. We will assume that that is not the case - & here - */ - -#define CONFIG_READLINE_ECHO 1 - -/* Some environments may return CR as end-of-line, others LF, and others - * both. If not specified, the logic here assumes either (but not both) as - * the default. - */ - -#if defined(CONFIG_EOL_IS_CR) -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_LF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_EITHER_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -#else -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# define CONFIG_EOL_IS_EITHER_CRLF 1 -#endif - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ -/* <esc>[K is the VT100 command erases to the end of the line. */ - -static const char g_erasetoeol[] = VT100_CLEAREOL; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: readline_rawgetc - ****************************************************************************/ - -static inline int readline_rawgetc(int infd) -{ - char buffer; - ssize_t nread; - - /* Loop until we successfully read a character (or until an unexpected - * error occurs). - */ - - for (;;) - { - /* Read one character from the incoming stream */ - - nread = read(infd, &buffer, 1); - - /* Check for end-of-file. */ - - if (nread == 0) - { - /* Return zero on end-of-file */ - - return 0; - } - - /* Check if an error occurred */ - - else if (nread < 0) - { - /* EINTR is not really an error; it simply means that a signal we - * received while watiing for intput. - */ - - int errcode = errno; - if (errcode != EINTR) - { - return -errcode; - } - - continue; - } - - else if (buffer == '\0') - { - /* Ignore NUL characters, since they look like EOF to our caller */ - - continue; - } - - /* Success, return the character that was read */ - - return (int)buffer; - } -} - -/**************************************************************************** - * Name: readline_consoleputc - ****************************************************************************/ - -#ifdef CONFIG_READLINE_ECHO -static inline void readline_consoleputc(int ch, int outfd) -{ - char buffer = ch; - ssize_t nwritten; - - /* Loop until we successfully write a character (or until an unexpected - * error occurs). - */ - - do - { - /* Write the character to the outgoing stream */ - - nwritten = write(outfd, &buffer, 1); - - /* Check for irrecoverable write errors. */ - - if (nwritten < 0 && errno != EINTR) - { - break; - } - } - while (nwritten < 1); -} -#endif - -/**************************************************************************** - * Name: readline_consolewrite - ****************************************************************************/ - -#ifdef CONFIG_READLINE_ECHO -static inline void readline_consolewrite(int outfd, FAR const char *buffer, size_t buflen) -{ - (void)write(outfd, buffer, buflen); -} -#endif - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: readline - * - * readline() reads in at most one less than 'buflen' characters from - * 'instream' and stores them into the buffer pointed to by 'buf'. - * Characters are echoed on 'outstream'. Reading stops after an EOF or a - * newline. If a newline is read, it is stored into the buffer. A null - * terminator is stored after the last character in the buffer. - * - * This version of realine assumes that we are reading and writing to - * a VT100 console. This will not work well if 'instream' or 'outstream' - * corresponds to a raw byte steam. - * - * This function is inspired by the GNU readline but is an entirely - * different creature. - * - * Input Parameters: - * buf - The user allocated buffer to be filled. - * buflen - the size of the buffer. - * instream - The stream to read characters from - * outstream - The stream to each characters to. - * - * Returned values: - * On success, the (positive) number of bytes transferred is returned. - * A length of zero would indicate an end of file condition. On failure, - * a negated errno value is returned. - * - **************************************************************************/ - -ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) -{ - int infd; - int outfd; - int escape; - int nch; - - /* Sanity checks */ - - if (!instream || !outstream || !buf || buflen < 1) - { - return -EINVAL; - } - - if (buflen < 2) - { - *buf = '\0'; - return 0; - } - - /* Extract the file descriptions. This is cheating (and horribly non- - * standard) - */ - - infd = instream->fs_filedes; - outfd = outstream->fs_filedes; - - /* <esc>[K is the VT100 command that erases to the end of the line. */ - -#ifdef CONFIG_READLINE_ECHO - readline_consolewrite(outfd, g_erasetoeol, sizeof(g_erasetoeol)); -#endif - - /* Read characters until we have a full line. On each the loop we must - * be assured that there are two free bytes in the line buffer: One for - * the next character and one for the null terminator. - */ - - escape = 0; - nch = 0; - - for(;;) - { - /* Get the next character */ - - int ch = readline_rawgetc(infd); - - /* Check for end-of-file or read error */ - - if (ch <= 0) - { - /* Did we already received some data? */ - - if (nch > 0) - { - /* Yes.. Terminate the line (which might be zero length) - * and return the data that was received. The end-of-file - * or error condition will be reported next time. - */ - - buf[nch] = '\0'; - return nch; - } - - return ch; - } - - /* Are we processing a VT100 escape sequence */ - - else if (escape) - { - /* Yes, is it an <esc>[, 3 byte sequence */ - - if (ch != ASCII_LBRACKET || escape == 2) - { - /* We are finished with the escape sequence */ - - escape = 0; - ch = 'a'; - } - else - { - /* The next character is the end of a 3-byte sequence. - * NOTE: Some of the <esc>[ sequences are longer than - * 3-bytes, but I have not encountered any in normal use - * yet and, so, have not provided the decoding logic. - */ - - escape = 2; - } - } - - /* Check for backspace - * - * There are several notions of backspace, for an elaborate summary see - * http://www.ibb.net/~anne/keyboard.html. There is no clean solution. - * Here both DEL and backspace are treated like backspace here. The - * Unix/Linux screen terminal by default outputs DEL (0x7f) when the - * backspace key is pressed. - */ - - else if (ch == ASCII_BS || ch == ASCII_DEL) - { - /* Eliminate that last character in the buffer. */ - - if (nch > 0) - { - nch--; - -#ifdef CONFIG_READLINE_ECHO - /* Echo the backspace character on the console. Always output - * the backspace character because the VT100 terminal doesn't - * understand DEL properly. - */ - - readline_consoleputc(ASCII_BS, outfd); - readline_consolewrite(outfd, g_erasetoeol, sizeof(g_erasetoeol)); -#endif - } - } - - /* Check for the beginning of a VT100 escape sequence */ - - else if (ch == ASCII_ESC) - { - /* The next character is escaped */ - - escape = 1; - } - - /* Check for end-of-line. This is tricky only in that some - * environments may return CR as end-of-line, others LF, and - * others both. - */ - -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) - else if (ch == '\n') -#elif defined(CONFIG_EOL_IS_CR) - else if (ch == '\r') -#elif CONFIG_EOL_IS_EITHER_CRLF - else if (ch == '\n' || ch == '\r') -#endif - { - /* The newline is stored in the buffer along with the null - * terminator. - */ - - buf[nch++] = '\n'; - buf[nch] = '\0'; - -#ifdef CONFIG_READLINE_ECHO - /* Echo the newline to the console */ - - readline_consoleputc('\n', outfd); -#endif - return nch; - } - - /* Otherwise, check if the character is printable and, if so, put the - * character in the line buffer - */ - - else if (isprint(ch)) - { - buf[nch++] = ch; - -#ifdef CONFIG_READLINE_ECHO - /* Echo the character to the console */ - - readline_consoleputc(ch, outfd); -#endif - /* Check if there is room for another character and the line's - * null terminator. If not then we have to end the line now. - */ - - if (nch + 1 >= buflen) - { - buf[nch] = '\0'; - return nch; - } - } - } -} - diff --git a/apps/system/usbmonitor/Kconfig b/apps/system/usbmonitor/Kconfig deleted file mode 100644 index bde97de15..000000000 --- a/apps/system/usbmonitor/Kconfig +++ /dev/null @@ -1,67 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config SYSTEM_USBMONITOR - bool "USB Monitor" - default n - depends on USBDEV && USBDEV_TRACE && SYSLOG - ---help--- - If USB device tracing is enabled (USBDEV_TRACE), then this option - will select the USB monitor. The USB monitor is a daemon that will - periodically collect the buffered USB trace data and dump it to the - SYSLOG device. - -if SYSTEM_USBMONITOR - -config SYSTEM_USBMONITOR_STACKSIZE - int "USB Monitor daemon stack size" - default 2048 - ---help--- - The stack size to use the the USB monitor daemon. Default: 2048 - -config SYSTEM_USBMONITOR_PRIORITY - int "USB Monitor daemon priority" - default 50 - ---help--- - The priority to use the the USB monitor daemon. Default: 50 - -config SYSTEM_USBMONITOR_INTERVAL - int "USB Monitor dump frequency" - default 2 - ---help--- - The rate in seconds that the USB monitor will wait before dumping - the next set of buffered USB trace data. Default: 2 seconds. - -config SYSTEM_USBMONITOR_TRACEINIT - bool "Show initialization events" - default n - ---help--- - Show initialization events - -config SYSTEM_USBMONITOR_TRACECLASS - bool "Show class driver events" - default n - ---help--- - Show class driver events - -config SYSTEM_USBMONITOR_TRACETRANSFERS - bool "Show data transfer events" - default n - ---help--- - Show data transfer events - -config SYSTEM_USBMONITOR_TRACECONTROLLER - bool "Show controller events" - default n - ---help--- - Show controller events - -config SYSTEM_USBMONITOR_TRACEINTERRUPTS - bool "Show interrupt-related events" - default n - ---help--- - Show interrupt-related events -endif - diff --git a/apps/system/usbmonitor/Makefile b/apps/system/usbmonitor/Makefile deleted file mode 100644 index 56b6ccee1..000000000 --- a/apps/system/usbmonitor/Makefile +++ /dev/null @@ -1,117 +0,0 @@ -############################################################################ -# apps/system/usbmonitor/Makefile -# -# Copyright (C) 2013 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -ifeq ($(WINTOOL),y) -INCDIROPT = -w -endif - -# USB Monitor Application - -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 768 - -ASRCS = -CSRCS = usbmonitor.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . - -# Common build - -VPATH = - -all: .built -.PHONY: context depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -# Register application - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)usbmonitor_start.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,"usbmon_start",$(PRIORITY),$(STACKSIZE),usbmonitor_start) - -$(BUILTIN_REGISTRY)$(DELIM)usbmonitor_stop.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,"usbmon_stop",$(PRIORITY),$(STACKSIZE),usbmonitor_stop) - -context: $(BUILTIN_REGISTRY)$(DELIM)usbmonitor_start.bdat $(BUILTIN_REGISTRY)$(DELIM)usbmonitor_stop.bdat -else -context: -endif - -# Create dependencies - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep diff --git a/apps/system/usbmonitor/usbmonitor.c b/apps/system/usbmonitor/usbmonitor.c deleted file mode 100644 index cde945b43..000000000 --- a/apps/system/usbmonitor/usbmonitor.c +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** - * apps/system/usbmonitor/usbmonitor.c - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/progmem.h> - -#include <sys/types.h> -#include <stdbool.h> -#include <unistd.h> -#include <sched.h> -#include <syslog.h> -#include <errno.h> - -#include <nuttx/usb/usbdev_trace.h> - -#ifdef CONFIG_SYSTEM_USBMONITOR - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define USBMON_PREFIX "USB Monitor: " - -/* Configuration ************************************************************/ - -#ifndef CONFIG_SYSTEM_USBMONITOR_STACKSIZE -# define CONFIG_SYSTEM_USBMONITOR_STACKSIZE 2048 -#endif - -#ifndef CONFIG_SYSTEM_USBMONITOR_PRIORITY -# define CONFIG_SYSTEM_USBMONITOR_PRIORITY 50 -#endif - -#ifndef CONFIG_SYSTEM_USBMONITOR_INTERVAL -# define CONFIG_SYSTEM_USBMONITOR_INTERVAL 2 -#endif - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACEINIT -# define TRACE_INIT_BITS (TRACE_INIT_BIT) -#else -# define TRACE_INIT_BITS (0) -#endif - -#define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACECLASS -# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|\ - TRACE_CLASSSTATE_BIT) -#else -# define TRACE_CLASS_BITS (0) -#endif - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACETRANSFERS -# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|\ - TRACE_READ_BIT|TRACE_WRITE_BIT|\ - TRACE_COMPLETE_BIT) -#else -# define TRACE_TRANSFER_BITS (0) -#endif - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACECONTROLLER -# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) -#else -# define TRACE_CONTROLLER_BITS (0) -#endif - -#ifdef CONFIG_SYSTEM_USBMONITOR_TRACEINTERRUPTS -# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|\ - TRACE_INTEXIT_BIT) -#else -# define TRACE_INTERRUPT_BITS (0) -#endif - -#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|\ - TRACE_CLASS_BITS|TRACE_TRANSFER_BITS|\ - TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct usbmon_state_s -{ - volatile bool started; - volatile bool stop; - pid_t pid; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct usbmon_state_s g_usbmonitor; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int usbmonitor_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf((trprintf_t)syslog, trace->event, trace->value); - return 0; -} - -static int usbmonitor_daemon(int argc, char **argv) -{ - syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid); - - /* Loop until we detect that there is a request to stop. */ - - while (!g_usbmonitor.stop) - { - sleep(CONFIG_SYSTEM_USBMONITOR_INTERVAL); - (void)usbtrace_enumerate(usbmonitor_tracecallback, NULL); - } - - /* Stopped */ - - g_usbmonitor.stop = false; - g_usbmonitor.started = false; - syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int usbmonitor_start(int argc, char **argv) -{ - /* Has the monitor already started? */ - - sched_lock(); - if (!g_usbmonitor.started) - { - int ret; - - /* No.. start it now */ - - /* First, initialize any USB tracing options that were requested */ - - usbtrace_enable(TRACE_BITSET); - - /* Then start the USB monitoring daemon */ - - g_usbmonitor.started = true; - g_usbmonitor.stop = false; - - ret = TASK_CREATE("USB Monitor", CONFIG_SYSTEM_USBMONITOR_PRIORITY, - CONFIG_SYSTEM_USBMONITOR_STACKSIZE, - (main_t)usbmonitor_daemon, (const char **)NULL); - if (ret < 0) - { - int errcode = errno; - syslog(USBMON_PREFIX - "ERROR: Failed to start the USB monitor: %d\n", - errcode); - } - else - { - g_usbmonitor.pid = ret; - syslog(USBMON_PREFIX "Started: %d\n", g_usbmonitor.pid); - } - - sched_unlock(); - return 0; - } - - sched_unlock(); - syslog(USBMON_PREFIX "%s: %d\n", - g_usbmonitor.stop ? "Stopping" : "Running", g_usbmonitor.pid); - return 0; -} - -int usbmonitor_stop(int argc, char **argv) -{ - /* Has the monitor already started? */ - - if (g_usbmonitor.started) - { - /* Stop the USB monitor. The next time the monitor wakes up, - * it will see the the stop indication and will exist. - */ - - syslog(USBMON_PREFIX "Stopping: %d\n", g_usbmonitor.pid); - g_usbmonitor.stop = true; - - /* We may as well disable tracing since there is no listener */ - - usbtrace_enable(0); - } - - syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); - return 0; -} - -#endif /* CONFIG_SYSTEM_USBMONITOR */ |