apps/system/composite: Remove usb serial loopback test code we can achieve the same effect by cat or dd command.
This commit is contained in:
parent
31a7b99f9c
commit
2c8b9e786d
@ -6,7 +6,7 @@
|
||||
menuconfig SYSTEM_COMPOSITE
|
||||
tristate "USB Composite Device Commands"
|
||||
default n
|
||||
depends on LIB_BOARDCTL && USBDEV_COMPOSITE && !KERNEL_BUILD
|
||||
depends on LIB_BOARDCTL && USBDEV_COMPOSITE && !BUILD_PROTECTED && !BUILD_KERNEL
|
||||
select BOARDCTL_USBDEVCTRL
|
||||
---help---
|
||||
Enable the USB composite class controls. These controls include:
|
||||
@ -24,25 +24,6 @@ config SYSTEM_COMPOSITE_DEFCONFIG
|
||||
this is the default configuration that the conn command will use if
|
||||
no configuration ID is provided on the command line.
|
||||
|
||||
if CDCACM_COMPOSITE
|
||||
|
||||
config SYSTEM_COMPOSITE_SERDEV
|
||||
string "USB serial device path"
|
||||
default "/dev/ttyACM0"
|
||||
---help---
|
||||
The string corresponding to SYSTEM_COMPOSITE_TTYUSB. If
|
||||
SYSTEM_COMPOSITE_TTYUSB is zero, then this would be "/dev/ttyUSB0"
|
||||
(for the PL2303 emulation) or "/dev/ttyACM0" (for the CDC/ACM serial
|
||||
device).
|
||||
|
||||
config SYSTEM_COMPOSITE_BUFSIZE
|
||||
int "Serial I/O buffer size"
|
||||
default 256
|
||||
---help---
|
||||
The size of the serial I/O buffer in bytes. Default 256 bytes.
|
||||
|
||||
endif # CDCACM_COMPOSITE
|
||||
|
||||
if USBDEV_TRACE || DEBUG_USB
|
||||
|
||||
config SYSTEM_COMPOSITE_TRACEINIT
|
||||
|
@ -60,31 +60,6 @@ system/composite
|
||||
CONFIG_SYSTEM_COMPOSITE_DEBUGMM
|
||||
Enables some debug tests to check for memory usage and memory leaks.
|
||||
|
||||
CONFIG_SYSTEM_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_SYSTEM_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_SYSTEM_COMPOSITE_DEVPATH1
|
||||
The full path to the registered block driver. Default is "/dev/mmcsd0"
|
||||
CONFIG_SYSTEM_COMPOSITE_DEVMINOR2 and CONFIG_SYSTEM_COMPOSITE_DEVPATH2
|
||||
Similar parameters that would have to be provided if CONFIG_SYSTEM_COMPOSITE_NLUNS
|
||||
is 2 or 3. No defaults.
|
||||
CONFIG_SYSTEM_COMPOSITE_DEVMINOR3 and CONFIG_SYSTEM_COMPOSITE_DEVPATH2
|
||||
Similar parameters that would have to be provided if CONFIG_SYSTEM_COMPOSITE_NLUNS
|
||||
is 3. No defaults.
|
||||
|
||||
CONFIG_SYSTEM_COMPOSITE_TTYUSB - The minor number of the USB serial device.
|
||||
Default is zero (corresponding to /dev/ttyUSB0 or /dev/ttyACM0). Default is zero.
|
||||
CCONFIG_SYSTEM_COMPOSITE_SERDEV - The string corresponding to
|
||||
CONFIG_SYSTEM_COMPOSITE_TTYUSB. The default is "/dev/ttyUSB0" (for the PL2303
|
||||
emulation) or "/dev/ttyACM0" (for the CDC/ACM serial device).
|
||||
CONFIG_SYSTEM_COMPOSITE_BUFSIZE - The size of the serial I/O buffer in
|
||||
bytes. Default 256 bytes.
|
||||
|
||||
If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB), then
|
||||
the add-on code will also manage the USB trace output. The amount of trace output
|
||||
can be controlled using:
|
||||
|
@ -65,60 +65,6 @@
|
||||
# error "USB CDC/ACM serial composite device support is not enabled (CONFIG_CDCACM_COMPOSITE)"
|
||||
#endif
|
||||
|
||||
/* Add-on Mass Storagte Class default values */
|
||||
|
||||
#ifndef CONFIG_SYSTEM_COMPOSITE_NLUNS
|
||||
# define CONFIG_SYSTEM_COMPOSITE_NLUNS 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SYSTEM_COMPOSITE_DEVMINOR1
|
||||
# define CONFIG_SYSTEM_COMPOSITE_DEVMINOR1 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SYSTEM_COMPOSITE_DEVPATH1
|
||||
# define CONFIG_SYSTEM_COMPOSITE_DEVPATH1 "/dev/mmcsd0"
|
||||
#endif
|
||||
|
||||
#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 1
|
||||
# ifndef CONFIG_SYSTEM_COMPOSITE_DEVMINOR2
|
||||
# error "CONFIG_SYSTEM_COMPOSITE_DEVMINOR2 for LUN=2"
|
||||
# endif
|
||||
# ifndef CONFIG_SYSTEM_COMPOSITE_DEVPATH2
|
||||
# error "CONFIG_SYSTEM_COMPOSITE_DEVPATH2 for LUN=2"
|
||||
# endif
|
||||
# if CONFIG_SYSTEM_COMPOSITE_NLUNS > 2
|
||||
# ifndef CONFIG_SYSTEM_COMPOSITE_DEVMINOR3
|
||||
# error "CONFIG_SYSTEM_COMPOSITE_DEVMINOR2 for LUN=3"
|
||||
# endif
|
||||
# ifndef CONFIG_SYSTEM_COMPOSITE_DEVPATH2
|
||||
# error "CONFIG_SYSTEM_COMPOSITE_DEVPATH2 for LUN=3"
|
||||
# endif
|
||||
# if CONFIG_SYSTEM_COMPOSITE_NLUNS > 3
|
||||
# error "CONFIG_SYSTEM_COMPOSITE_NLUNS must be {1,2,3}"
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Add-on CDC/ACM default values */
|
||||
|
||||
#ifndef CONFIG_SYSTEM_COMPOSITE_TTYUSB
|
||||
# define CONFIG_SYSTEM_COMPOSITE_TTYUSB 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SYSTEM_COMPOSITE_SERDEV
|
||||
# if CONFIG_SYSTEM_COMPOSITE_TTYUSB != 0
|
||||
# error "Serial device unknown (CONFIG_SYSTEM_COMPOSITE_SERDEV)"
|
||||
# elif defined(CONFIG_CDCACM)
|
||||
# define CONFIG_SYSTEM_COMPOSITE_SERDEV "/dev/ttyACM0"
|
||||
# else
|
||||
# define CONFIG_SYSTEM_COMPOSITE_SERDEV "/dev/ttyUSB0"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SYSTEM_COMPOSITE_BUFSIZE
|
||||
# define CONFIG_SYSTEM_COMPOSITE_BUFSIZE 256
|
||||
#endif
|
||||
|
||||
/* Trace initialization *****************************************************/
|
||||
|
||||
#ifndef CONFIG_USBDEV_TRACE_INITIALIDSET
|
||||
@ -172,20 +118,12 @@
|
||||
struct composite_state_s
|
||||
{
|
||||
/* This is the handle that references to this particular USB composite
|
||||
* driver instance. It is only needed if the add-on is built using
|
||||
* CONFIG_NSH_BUILTIN_APPS. In this case, the value of the driver handle
|
||||
* must be remembered between the 'conn' and 'disconn' commands.
|
||||
* driver instance. The value of the driver handle must be remembered
|
||||
* between the 'conn' and 'disconn' commands.
|
||||
*/
|
||||
|
||||
FAR void *cmphandle; /* Composite device handle */
|
||||
|
||||
#ifndef CONFIG_NSH_BUILTIN_APPS
|
||||
/* Serial file descriptors */
|
||||
|
||||
int outfd; /* Blocking write-only */
|
||||
int infd; /* Non-blockig read-only */
|
||||
#endif
|
||||
|
||||
/* Heap usage samples. These are useful for checking USB storage memory
|
||||
* usage and for tracking down memoryh leaks.
|
||||
*/
|
||||
@ -195,12 +133,6 @@ struct composite_state_s
|
||||
struct mallinfo mmprevious; /* The last memory usage sample */
|
||||
struct mallinfo mmcurrent; /* The current memory usage sample */
|
||||
#endif
|
||||
|
||||
/* Serial I/O buffer */
|
||||
|
||||
#ifndef CONFIG_NSH_BUILTIN_APPS
|
||||
uint8_t serbuf[CONFIG_SYSTEM_COMPOSITE_BUFSIZE];
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -64,9 +64,7 @@
|
||||
|
||||
#undef NEED_DUMPTRACE
|
||||
#ifdef CONFIG_USBDEV_TRACE
|
||||
# if !defined(CONFIG_NSH_BUILTIN_APPS)
|
||||
# define NEED_DUMPTRACE 1
|
||||
# elif CONFIG_USBDEV_TRACE_INITIALIDSET != 0
|
||||
# if CONFIG_USBDEV_TRACE_INITIALIDSET != 0
|
||||
# define NEED_DUMPTRACE 1
|
||||
# endif
|
||||
#endif
|
||||
@ -393,119 +391,6 @@ static int dumptrace(void)
|
||||
# define dumptrace() (OK)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: open_serial
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NSH_BUILTIN_APPS
|
||||
static int open_serial(void)
|
||||
{
|
||||
int errcode;
|
||||
#ifdef CONFIG_USBDEV_TRACE
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* Open the USB serial device for writing (blocking) */
|
||||
|
||||
do
|
||||
{
|
||||
printf("open_serial: Opening USB serial driver\n");
|
||||
g_composite.outfd = open(CONFIG_SYSTEM_COMPOSITE_SERDEV, O_WRONLY);
|
||||
if (g_composite.outfd < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
fprintf(stderr, "open_serial: ERROR: Failed to open %s for writing: %d\n",
|
||||
CONFIG_SYSTEM_COMPOSITE_SERDEV, errcode);
|
||||
|
||||
/* ENOTCONN means that the USB device is not yet connected */
|
||||
|
||||
if (errcode == ENOTCONN)
|
||||
{
|
||||
printf("open_serial: Not connected. Wait and try again.\n");
|
||||
sleep(5);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Give up on other errors */
|
||||
|
||||
printf("open_serial: Aborting\n");
|
||||
return -errcode;
|
||||
}
|
||||
}
|
||||
|
||||
/* If USB tracing is enabled, then dump all collected trace data to
|
||||
* stdout.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_USBDEV_TRACE
|
||||
ret = dumptrace();
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
while (g_composite.outfd < 0);
|
||||
|
||||
/* Open the USB serial device for reading (non-blocking) */
|
||||
|
||||
g_composite.infd = open(CONFIG_SYSTEM_COMPOSITE_SERDEV, O_RDONLY|O_NONBLOCK);
|
||||
if (g_composite.infd < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
fprintf(stderr, "open_serial: ERROR: Failed to open%s for reading: %d\n",
|
||||
CONFIG_SYSTEM_COMPOSITE_SERDEV, errcode);
|
||||
close(g_composite.outfd);
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
printf("open_serial: Successfully opened the serial driver\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: echo_serial
|
||||
****************************************************************************/
|
||||
|
||||
static int echo_serial(void)
|
||||
{
|
||||
ssize_t bytesread;
|
||||
ssize_t byteswritten;
|
||||
int errcode;
|
||||
|
||||
/* Read data */
|
||||
|
||||
bytesread = read(g_composite.infd, g_composite.serbuf, CONFIG_SYSTEM_COMPOSITE_BUFSIZE);
|
||||
if (bytesread < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
if (errcode != EAGAIN)
|
||||
{
|
||||
fprintf(stderr, "echo_serial: ERROR: read failed: %d\n", errcode);
|
||||
return -errcode;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Echo data */
|
||||
|
||||
byteswritten = write(g_composite.outfd, g_composite.serbuf, bytesread);
|
||||
if (byteswritten < 0)
|
||||
{
|
||||
errcode = errno;
|
||||
fprintf(stderr, "echo_serial: ERROR: write failed: %d\n", errcode);
|
||||
return -errcode;
|
||||
}
|
||||
else if (byteswritten != bytesread)
|
||||
{
|
||||
fprintf(stderr, "echo_serial: ERROR: read size: %d write size: %d\n",
|
||||
bytesread, byteswritten);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -531,7 +416,6 @@ int main(int argc, FAR char *argv[])
|
||||
* do a little error checking to assure that we are not being called re-entrantly.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
/* Check if there is a non-NULL USB mass storage device handle (meaning that the
|
||||
* USB mass storage device is already configured).
|
||||
*/
|
||||
@ -541,7 +425,6 @@ int main(int argc, FAR char *argv[])
|
||||
fprintf(stderr, "conn_main: ERROR: Already connected\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* There is one optional argument.. the interface configuration ID */
|
||||
|
||||
@ -605,31 +488,8 @@ int main(int argc, FAR char *argv[])
|
||||
|
||||
check_test_memory_usage("After boardctl(BOARDIOC_USBDEV_CONTROL)");
|
||||
|
||||
#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);
|
||||
ret = dumptrace();
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout_bad_dump;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* It this program was configued as an NSH command, then just exit now. */
|
||||
|
||||
#ifndef CONFIG_NSH_BUILTIN_APPS
|
||||
/* Otherwise, this thread will hang around and monitor the USB activity */
|
||||
|
||||
/* Open the serial driver */
|
||||
|
||||
ret = open_serial();
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
#ifdef NEED_DUMPTRACE
|
||||
/* This thread will hang around and monitor the USB activity */
|
||||
|
||||
/* Now looping */
|
||||
|
||||
@ -640,64 +500,24 @@ int main(int argc, FAR char *argv[])
|
||||
fflush(stdout);
|
||||
sleep(5);
|
||||
|
||||
/* Echo any serial data */
|
||||
|
||||
ret = echo_serial();
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Dump trace data */
|
||||
|
||||
# ifdef CONFIG_USBDEV_TRACE
|
||||
printf("\n" "conn_main: USB TRACE DATA:\n");
|
||||
ret = dumptrace();
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
break;
|
||||
}
|
||||
|
||||
check_test_memory_usage("After usbtrace_enumerate()");
|
||||
# else
|
||||
printf("conn_main: Still alive\n");
|
||||
# endif
|
||||
}
|
||||
#else
|
||||
|
||||
printf("conn_main: Connected\n");
|
||||
check_test_memory_usage("After composite device connection");
|
||||
#endif
|
||||
|
||||
/* Dump debug memory usage */
|
||||
|
||||
printf("conn_main: Exiting\n");
|
||||
#ifndef CONFIG_NSH_BUILTIN_APPS
|
||||
close(g_composite.infd);
|
||||
close(g_composite.outfd);
|
||||
#endif
|
||||
final_memory_usage("Final memory usage");
|
||||
return 0;
|
||||
|
||||
#if defined(CONFIG_USBDEV_TRACE) && CONFIG_USBDEV_TRACE_INITIALIDSET != 0
|
||||
errout_bad_dump:
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NSH_BUILTIN_APPS
|
||||
errout:
|
||||
close(g_composite.infd);
|
||||
close(g_composite.outfd);
|
||||
#endif
|
||||
|
||||
ctrl.usbdev = BOARDIOC_USBDEV_COMPOSITE;
|
||||
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
|
||||
ctrl.instance = 0;
|
||||
ctrl.config = config;
|
||||
ctrl.handle = &g_composite.cmphandle;
|
||||
|
||||
(void)boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
|
||||
final_memory_usage("Final memory usage");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user