diff --git a/examples/README.txt b/examples/README.txt index e5e48b20a..f96cc78d9 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -2212,81 +2212,6 @@ examples/usbserial The host and target will exchange are variety of very small and very large serial messages. -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_NSH_BUILTIN_APPS - 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_FEATURES 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 - defconfig file must have the following build path: - - CONFIG_SYSTEM_READLINE=y - - 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/ustream ^^^^^^^^^^^^^^^^ diff --git a/examples/hidkbd/Kconfig b/examples/hidkbd/Kconfig index 7d6e6eb53..3f2bc7a5d 100644 --- a/examples/hidkbd/Kconfig +++ b/examples/hidkbd/Kconfig @@ -6,24 +6,11 @@ config EXAMPLES_HIDKBD bool "USB HID keyboard example" default n - depends on !BUILD_PROTECTED && !BUILD_KERNEL ---help--- Enable the USB HID keyboard example if EXAMPLES_HIDKBD -config EXAMPLES_HIDKBD_DEFPRIO - int "Waiter Thread Priority" - default 50 - ---help--- - Priority of "waiter" thread. Default: 50 - -config EXAMPLES_HIDKBD_STACKSIZE - int "Waiter Thread Stack Size" - default 1024 - ---help--- - Stacksize of "waiter" thread. Default 1024 - config EXAMPLES_HIDKBD_DEVNAME string "Keyboard Device Name" default "/dev/kbda" diff --git a/examples/hidkbd/Makefile b/examples/hidkbd/Makefile index 8b0298ea9..deed9c074 100644 --- a/examples/hidkbd/Makefile +++ b/examples/hidkbd/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/examples/hidkbd/Makefile # -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,13 +37,20 @@ # USB Host HID keyboard Example +CONFIG_EXAMPLES_HIDKBD_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_EXAMPLES_HIDKBD_STACKSIZE ?= 2048 + APPNAME = hidkbd +PRIORITY = $(CONFIG_EXAMPLES_HIDKBD_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_HIDKBD_STACKSIZE) + +# Hello, World! Example ASRCS = CSRCS = MAINSRC = hidkbd_main.c -CONFIG_XYZ_PROGNAME ?= hidkbd$(EXEEXT) -PROGNAME = $(CONFIG_XYZ_PROGNAME) +CONFIG_EXAMPLES_HIDKBD_PROGNAME ?= hidkbd$(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_HIDKBD_PROGNAME) include $(APPDIR)/Application.mk diff --git a/examples/hidkbd/hidkbd_main.c b/examples/hidkbd/hidkbd_main.c index c0a3c49bd..c93889069 100644 --- a/examples/hidkbd/hidkbd_main.c +++ b/examples/hidkbd/hidkbd_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/hidkbd/hidkbd_main.c * - * Copyright (C) 2011, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,16 +39,9 @@ #include -#include -#include - #include #include #include -#include -#include -#include -#include #include #include @@ -79,14 +72,6 @@ /* Provide some default values for other configuration settings */ -#ifndef CONFIG_EXAMPLES_HIDKBD_DEFPRIO -# define CONFIG_EXAMPLES_HIDKBD_DEFPRIO 50 -#endif - -#ifndef CONFIG_EXAMPLES_HIDKBD_STACKSIZE -# define CONFIG_EXAMPLES_HIDKBD_STACKSIZE 1024 -#endif - #ifndef CONFIG_EXAMPLES_HIDKBD_DEVNAME # define CONFIG_EXAMPLES_HIDKBD_DEVNAME "/dev/kbda" #endif @@ -108,22 +93,6 @@ struct hidbkd_instream_s }; #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static FAR struct usbhost_connection_s *g_usbconn; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ -/* The platform-specific code must provide a wrapper called - * arch_usbhost_initialize() that will perform the actual USB host - * initialization. - */ - -FAR struct usbhost_connection_s *arch_usbhost_initialize(void); - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -223,41 +192,6 @@ static void hidkbd_decode(FAR char *buffer, ssize_t nbytes) } #endif -/**************************************************************************** - * Name: hidkbd_waiter - * - * Description: - * Wait for USB devices to be connected. - * - ****************************************************************************/ - -static int hidkbd_waiter(int argc, char *argv[]) -{ - FAR struct usbhost_hubport_s *hport; - - printf("hidkbd_waiter: Running\n"); - for (;;) - { - /* Wait for the device to change state */ - - DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport)); - printf("hidkbd_waiter: %s\n", hport->connected ? "connected" : "disconnected"); - - /* Did we just become connected? */ - - if (hport->connected) - { - /* Yes.. enumerate the newly connected device */ - - (void)CONN_ENUMERATE(g_usbconn, hport); - } - } - - /* Keep the compiler from complaining */ - - return 0; -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -273,88 +207,58 @@ int hidkbd_main(int argc, char *argv[]) #endif { char buffer[256]; - pid_t pid; ssize_t nbytes; int fd; - int ret; - /* First, register all of the USB host HID keyboard class driver */ - - printf("hidkbd_main: Register class drivers\n"); - ret = usbhost_kbdinit(); - if (ret != OK) - { - printf("hidkbd_main: Failed to register the KBD class\n"); - } - - /* Then get an instance of the USB host interface. The platform-specific - * code must provide a wrapper called arch_usbhost_initialize() that will - * perform the actual USB host initialization. + /* Eventually logic here will open the kbd device and perform the HID + * keyboard test. */ - printf("hidkbd_main: Initialize USB host keyboard driver\n"); - g_usbconn = arch_usbhost_initialize(); - if (g_usbconn) + for (;;) { - /* Start a thread to handle device connection. */ - - printf("hidkbd_main: Start hidkbd_waiter\n"); - - pid = task_create("usbhost", CONFIG_EXAMPLES_HIDKBD_DEFPRIO, - CONFIG_EXAMPLES_HIDKBD_STACKSIZE, - (main_t)hidkbd_waiter, (FAR char * const *)NULL); - UNUSED(pid); - - /* Now just sleep. Eventually logic here will open the kbd device and - * perform the HID keyboard test. + /* Open the keyboard device. Loop until the device is successfully + * opened. */ - for (;;) + do { - /* Open the keyboard device. Loop until the device is successfully - * opened. - */ - - do + printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME); + fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY); + if (fd < 0) { - printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME); - fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY); - if (fd < 0) - { - printf("Failed: %d\n", errno); - fflush(stdout); - sleep(3); - } + printf("Failed: %d\n", errno); + fflush(stdout); + sleep(3); } - while (fd < 0); + } + while (fd < 0); - printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME); - fflush(stdout); + printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME); + fflush(stdout); - /* Loop until there is a read failure (or EOF?) */ + /* Loop until there is a read failure (or EOF?) */ - do + do + { + /* Read a buffer of data */ + + nbytes = read(fd, buffer, 256); + if (nbytes > 0) { - /* Read a buffer of data */ - - nbytes = read(fd, buffer, 256); - if (nbytes > 0) - { - /* On success, echo the buffer to stdout */ + /* On success, echo the buffer to stdout */ #ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED - hidkbd_decode(buffer, nbytes); + hidkbd_decode(buffer, nbytes); #else - (void)write(1, buffer, nbytes); + (void)write(1, buffer, nbytes); #endif - } } - while (nbytes > 0); - - printf("Closing device %s: %d\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME, (int)nbytes); - fflush(stdout); - close(fd); } + while (nbytes > 0); + + printf("Closing device %s: %d\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME, (int)nbytes); + fflush(stdout); + close(fd); } return 0; diff --git a/examples/nrf24l01_term/Kconfig b/examples/nrf24l01_term/Kconfig index a207017b9..ddb950669 100644 --- a/examples/nrf24l01_term/Kconfig +++ b/examples/nrf24l01_term/Kconfig @@ -6,6 +6,7 @@ config EXAMPLES_NRF24L01TERM bool "Basic nRF24L01 terminal" default n + depends on DRIVERS_WIRELESS if EXAMPLES_NRF24L01TERM endif diff --git a/examples/usbterm/.gitignore b/examples/usbterm/.gitignore deleted file mode 100644 index fa1ec7579..000000000 --- a/examples/usbterm/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -/Make.dep -/.depend -/.built -/*.asm -/*.obj -/*.rel -/*.lst -/*.sym -/*.adb -/*.lib -/*.src diff --git a/examples/usbterm/Kconfig b/examples/usbterm/Kconfig deleted file mode 100644 index 208aed452..000000000 --- a/examples/usbterm/Kconfig +++ /dev/null @@ -1,64 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -config EXAMPLES_USBTERM - bool "USB serial terminal example" - default n - ---help--- - Enable the USB serial terminal example - -if EXAMPLES_USBTERM - -config EXAMPLES_USBTERM_TRACEINIT - bool "USB Trace Initialization" - default n - depends on USBDEV_TRACE || DEBUG_USB - ---help--- - If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB), - then the example code will also manage the USB trace output. The - amount of trace output can be controlled this configuration value: - This setting will show USB initialization events - -config EXAMPLES_USBTERM_TRACECLASS - bool "USB Trace Class" - default n - depends on USBDEV_TRACE || DEBUG_USB - ---help--- - If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB), - then the example code will also manage the USB trace output. The - amount of trace output can be controlled this configuration value: - This setting will show USB class driver events - -config EXAMPLES_USBTERM_TRACETRANSFERS - bool "USB Trace Transfers" - default n - depends on USBDEV_TRACE || DEBUG_USB - ---help--- - If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB), - then the example code will also manage the USB trace output. The - amount of trace output can be controlled this configuration value: - This setting will show USB data transfer events - -config EXAMPLES_USBTERM_TRACECONTROLLER - bool "USB Trace Device Controller Events" - default n - depends on USBDEV_TRACE || DEBUG_USB - ---help--- - If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB), - then the example code will also manage the USB trace output. The - amount of trace output can be controlled this configuration value: - This setting will show USB device controller events - -config EXAMPLES_USBTERM_TRACEINTERRUPTS - bool "USB Trace Device Controller Interrupt Events" - default n - depends on USBDEV_TRACE || DEBUG_USB - ---help--- - If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB), - then the example code will also manage the USB trace output. The - amount of trace output can be controlled this configuration value: - This setting will show USB device controller interrupt-related events. - -endif diff --git a/examples/usbterm/Make.defs b/examples/usbterm/Make.defs deleted file mode 100644 index cfc516092..000000000 --- a/examples/usbterm/Make.defs +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################ -# apps/examples/usbterm/Make.defs -# Adds selected applications to apps/ build -# -# Copyright (C) 2015 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# 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_USBTERM),y) -CONFIGURED_APPS += examples/usbterm -endif diff --git a/examples/usbterm/Makefile b/examples/usbterm/Makefile deleted file mode 100644 index 98e7d8128..000000000 --- a/examples/usbterm/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -############################################################################ -# apps/examples/usbterm/Makefile -# -# Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# 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 - -# USB terminal example - -ASRCS = -CSRCS = -MAINSRC = usbterm_main.c - -CONFIG_XYZ_PROGNAME ?= usbterm$(EXEEXT) -PROGNAME = $(CONFIG_XYZ_PROGNAME) - -# Built-in application info - -APPNAME = usbterm -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 - -include $(APPDIR)/Application.mk diff --git a/examples/usbterm/usbterm.h b/examples/usbterm/usbterm.h deleted file mode 100644 index 25bf85a0d..000000000 --- a/examples/usbterm/usbterm.h +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** - * examples/usbterm/usbterm.h - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * 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_USBTERM_USBTERM_H -#define __APPS_EXAMPLES_USBTERM_USBTERM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ - -#ifndef CONFIG_EXAMPLES_USBTERM_BUFLEN -# define CONFIG_EXAMPLES_USBTERM_BUFLEN 256 -#endif - -#ifndef CONFIG_USBDEV_TRACE_INITIALIDSET -# define CONFIG_USBDEV_TRACE_INITIALIDSET 0 -#endif - -#ifdef CONFIG_EXAMPLES_USBTERM_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_USBTERM_TRACECLASS -# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT) -#else -# define TRACE_CLASS_BITS (0) -#endif - -#ifdef CONFIG_EXAMPLES_USBTERM_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_USBTERM_TRACECONTROLLER -# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) -#else -# define TRACE_CONTROLLER_BITS (0) -#endif - -#ifdef CONFIG_EXAMPLES_USBTERM_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) - -#ifdef CONFIG_CDCACM -# define USBTERM_DEVNAME "/dev/ttyACM0" -#else -# define USBTERM_DEVNAME "/dev/ttyUSB0" -#endif - -#define IOBUFFER_SIZE 256 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* All USB terminal state data is packaged in a single structure to minimize - * name conflicts with other global symbols -- a poor man's name space. - */ - -struct usbterm_globals_s -{ - FILE *instream; /* Stream for incoming USB data */ - FILE *outstream; /* Stream for outgoing USB data */ - pthread_t listener; /* USB terminal listener thread */ - bool peer; /* True: A peer is connected to the serial port on - * the remote host */ - - /* Buffers for incoming and outgoing data */ - - char inbuffer[CONFIG_EXAMPLES_USBTERM_BUFLEN]; - char outbuffer[CONFIG_EXAMPLES_USBTERM_BUFLEN]; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* USB terminal state data */ - -extern struct usbterm_globals_s g_usbterm; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ -/**************************************************************************** - * Name: - * - * Description: - * If CONFIG_EXAMPLES_USBTERM_DEVINIT is defined, then the example will - * call this user provided function as part of its initialization. - * - ****************************************************************************/ - -#ifdef CONFIG_EXAMPLES_USBTERM_DEVINIT -int usbterm_devinit(void); -#endif - -/**************************************************************************** - * Name: - * - * Description: - * If CONFIG_EXAMPLES_USBTERM_DEVINIT is defined, then the example will - * call this user provided function as part of its termination sequeunce. - * - ****************************************************************************/ - -#ifdef CONFIG_EXAMPLES_USBTERM_DEVINIT -void usbterm_devuninit(void); -#endif - -#endif /* __APPS_EXAMPLES_USBTERM_USBTERM_H */ diff --git a/examples/usbterm/usbterm_main.c b/examples/usbterm/usbterm_main.c deleted file mode 100644 index 71450dfbd..000000000 --- a/examples/usbterm/usbterm_main.c +++ /dev/null @@ -1,388 +0,0 @@ -/**************************************************************************** - * examples/usbterm/usbterm_main.c - * - * Copyright (C) 2011-2013, 2015-2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * 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 - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "system/readline.h" - -#include -#include - -#ifdef CONFIG_CDCACM -# include -#endif - -#ifdef CONFIG_CDCACM -# include -#endif - -#include "usbterm.h" - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* USB terminal state data */ - -struct usbterm_globals_s g_usbterm; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: trace_callback - * - * Description: - * Callback from USB trace instrumentation. - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV_TRACE -static int trace_callback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf((trprintf_t)trmessage, trace->event, trace->value); - return 0; -} -#endif - -/**************************************************************************** - * Name: dumptrace - * - * Description: - * Dump collected trace data. - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV_TRACE -static void dumptrace(void) -{ - (void)usbtrace_enumerate(trace_callback, NULL); -} -#else -# define dumptrace() -#endif - -/**************************************************************************** - * Name: usbterm_listener - * - * Description: - * Entry point for the listener thread. - * - ****************************************************************************/ - -static FAR void *usbterm_listener(FAR void *parameter) -{ - printf("usbterm_listener: Waiting for remote input\n"); - for (;;) - { - /* Display the prompt string on the remote USB serial connection -- only - * if we know that there is someone listening at the other end. The - * remote side must initiate the the conversation. - */ - - if (g_usbterm.peer) - { - fputs("\rusbterm> ", g_usbterm.outstream); - fflush(g_usbterm.outstream); - } - - /* Get the next line of input from the remote USB serial connection */ - - if (fgets(g_usbterm.inbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, g_usbterm.instream)) - { - /* If we receive anything, then we can be assured that there is someone - * with the serial driver open on the remote host. - */ - - g_usbterm.peer = true; - - /* Echo the line on the local stdout */ - - fputs(g_usbterm.inbuffer, stdout); - - /* Display the prompt string on stdout */ - - fputs("usbterm> ", stdout); - fflush(stdout); - } - - /* If USB tracing is enabled, then dump all collected trace data to stdout */ - - dumptrace(); - } - - /* Won't get here */ - - return NULL; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: usbterm_main - * - * Description: - * Main entry point for the USB serial terminal example. - * - ****************************************************************************/ - -#ifdef CONFIG_BUILD_KERNEL -int main(int argc, FAR char *argv[]) -#else -int usbterm_main(int argc, char *argv[]) -#endif -{ - struct boardioc_usbdev_ctrl_s ctrl; - FAR void *handle; - pthread_attr_t attr; - int ret; - - /* Initialize global data */ - - memset(&g_usbterm, 0, sizeof(struct usbterm_globals_s)); - - /* Initialization of the USB hardware may be performed by logic external to - * this test. - */ - -#ifdef CONFIG_EXAMPLES_USBTERM_DEVINIT - printf("usbterm_main: Performing external device initialization\n"); - ret = usbterm_devinit(); - if (ret != OK) - { - printf("usbterm_main: usbterm_devinit failed: %d\n", ret); - goto errout; - } -#endif - - /* Initialize the USB serial driver */ - - printf("usbterm_main: Registering USB serial driver\n"); - -#ifdef CONFIG_CDCACM - - ctrl.usbdev = BOARDIOC_USBDEV_CDCACM; - ctrl.action = BOARDIOC_USBDEV_CONNECT; - ctrl.instance = 0; - ctrl.handle = &handle; - -#else - - ctrl.usbdev = BOARDIOC_USBDEV_PL2303; - ctrl.action = BOARDIOC_USBDEV_CONNECT; - ctrl.instance = 0; - ctrl.handle = &handle; - -#endif - - ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - if (ret < 0) - { - printf("usbterm_main: ERROR: Failed to create the USB serial device: %d\n", -ret); - goto errout_with_devinit; - } - - printf("usbterm_main: Successfully registered the serial driver\n"); - -#if defined(CONFIG_USBDEV_TRACE) && CONFIG_USBDEV_TRACE_INITIALIDSET != 0 - /* If USB tracing is enabled and tracing of initial USB events is specified, - * then dump all collected trace data to stdout - */ - - sleep(5); - dumptrace(); -#endif - - /* Then, in any event, configure trace data collection as configured */ - - usbtrace_enable(TRACE_BITSET); - - /* Open the USB serial device for writing */ - - do - { - printf("usbterm_main: Opening USB serial driver\n"); - - g_usbterm.outstream = fopen(USBTERM_DEVNAME, "w"); - if (g_usbterm.outstream == NULL) - { - int errcode = errno; - printf("usbterm_main: ERROR: Failed to open " USBTERM_DEVNAME " for writing: %d\n", - errcode); - - /* ENOTCONN means that the USB device is not yet connected */ - - if (errcode == ENOTCONN) - { - printf("usbterm_main: Not connected. Wait and try again.\n"); - sleep(5); - } - else - { - /* Give up on other errors */ - - goto errout_with_devinit; - } - } - - /* If USB tracing is enabled, then dump all collected trace data to stdout */ - - dumptrace(); - } - while (g_usbterm.outstream == NULL); - - /* Open the USB serial device for reading. Since we are already connected, this - * should not fail. - */ - - g_usbterm.instream = fopen(USBTERM_DEVNAME, "r"); - if (g_usbterm.instream == NULL) - { - printf("usbterm_main: ERROR: Failed to open " USBTERM_DEVNAME " for reading: %d\n", errno); - goto errout_with_outstream; - } - - printf("usbterm_main: Successfully opened the serial driver\n"); - - /* Start the USB term listener thread */ - - printf("usbterm_main: Starting the listener thread\n"); - - ret = pthread_attr_init(&attr); - if (ret != OK) - { - printf("usbterm_main: pthread_attr_init failed: %d\n", ret); - goto errout_with_streams; - } - - ret = pthread_create(&g_usbterm.listener, &attr, - usbterm_listener, (pthread_addr_t)0); - if (ret != 0) - { - printf("usbterm_main: Error in thread creation: %d\n", ret); - goto errout_with_streams; - } - - /* Send messages and get responses -- forever */ - - printf("usbterm_main: Waiting for local input\n"); - for (;;) - { - /* Display the prompt string on stdout */ - - fputs("usbterm> ", stdout); - fflush(stdout); - - /* Get the next line of input */ - -#ifdef CONFIG_EXAMPLES_USBTERM_FGETS - /* fgets returns NULL on end-of-file or any I/O error */ - - if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin) == NULL) - { - printf("ERROR: fgets failed: %d\n", errno); - return 1; - } -#else - ret = readline(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin, stdout); - - /* Readline normally returns the number of characters read, - * but will return EOF on end of file or if an error occurs. Either - * will cause the session to terminate. - */ - - if (ret == EOF) - { - printf("ERROR: readline failed: %d\n", ret); - return 1; - } -#endif - /* Is there anyone listening on the other end? */ - - else if (g_usbterm.peer) - { - /* Yes.. Send the line of input via USB */ - - fputs(g_usbterm.outbuffer, g_usbterm.outstream); - - /* Display the prompt string on the remote USB serial connection */ - - fputs("\rusbterm> ", g_usbterm.outstream); - fflush(g_usbterm.outstream); - } - else - { - printf("Still waiting for remote peer. Please try again later.\n"); - } - - /* If USB tracing is enabled, then dump all collected trace data to stdout */ - - dumptrace(); - } - - /* Error exits */ - -errout_with_streams: - fclose(g_usbterm.instream); -errout_with_outstream: - fclose(g_usbterm.outstream); -errout_with_devinit: -#ifdef CONFIG_EXAMPLES_USBTERM_DEVINIT - usbterm_devuninit(); -errout: -#endif - printf("usbterm_main: Aborting\n"); - return 1; -} - diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c index 71fc3795c..231dc2526 100644 --- a/nshlib/nsh_parse.c +++ b/nshlib/nsh_parse.c @@ -1,7 +1,7 @@ /**************************************************************************** * apps/nshlib/nsh_parse.c * - * Copyright (C) 2007-2013, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013, 2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -1180,7 +1180,11 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline, else #endif { - /* Just to catch any dangling else clauses */ + /* Not a special character... skip to the next character in the + * cmdline. + */ + + working++; } } }