From fca6da8248c6dada5f8be8ceb173792a6f25d80c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 9 Mar 2017 15:37:16 -0600 Subject: [PATCH] apps/examples/usbterm: Removed because it is not very useful and because it can be configured to use an illegal call into the OS. --- examples/README.txt | 75 ------ examples/usbterm/.gitignore | 11 - examples/usbterm/Kconfig | 64 ------ examples/usbterm/Make.defs | 39 ---- examples/usbterm/Makefile | 53 ----- examples/usbterm/usbterm.h | 165 -------------- examples/usbterm/usbterm_main.c | 388 -------------------------------- 7 files changed, 795 deletions(-) delete mode 100644 examples/usbterm/.gitignore delete mode 100644 examples/usbterm/Kconfig delete mode 100644 examples/usbterm/Make.defs delete mode 100644 examples/usbterm/Makefile delete mode 100644 examples/usbterm/usbterm.h delete mode 100644 examples/usbterm/usbterm_main.c 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/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; -} -