Fix packet size calculation in CDC/ACM and PL2303 USB serial drivers
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4771 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
fcc07454f1
commit
66eeafb87a
@ -230,3 +230,7 @@
|
|||||||
initialization interfaces.
|
initialization interfaces.
|
||||||
|
|
||||||
6.19 2012-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
6.19 2012-xx-xx 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.
|
||||||
|
@ -916,6 +916,33 @@ NSH-Specific Configuration Settings
|
|||||||
CDC/ACM serial device as a console device at
|
CDC/ACM serial device as a console device at
|
||||||
dev/console.
|
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_UBSDEV_MINOR
|
||||||
|
The minor device number of the USB device. Default: 0
|
||||||
|
|
||||||
|
If USB tracing is enabled, then NSH will initialize USB
|
||||||
|
tracing as requested by the following:
|
||||||
|
|
||||||
|
CONFIG_NSH_UBSDEV_TRACEINIT
|
||||||
|
Bit set with each bit enabling a trace option (see
|
||||||
|
include/nuttx/usb/usbdev_trace.h). Default: Only USB errors
|
||||||
|
are traced.
|
||||||
|
|
||||||
* CONFIG_NSH_CONDEV
|
* CONFIG_NSH_CONDEV
|
||||||
If CONFIG_NSH_CONSOLE is set to 'y', then 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
|
may also be set to select the serial device used to support
|
||||||
|
36
nshlib/nsh.h
36
nshlib/nsh.h
@ -49,6 +49,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/usb/usbdev_trace.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -79,10 +81,44 @@
|
|||||||
|
|
||||||
#undef HAVE_USB_CONSOLE
|
#undef HAVE_USB_CONSOLE
|
||||||
#if defined(CONFIG_USBDEV)
|
#if defined(CONFIG_USBDEV)
|
||||||
|
|
||||||
|
/* Check for a PL2303 serial console. Use console device "/dev/console". */
|
||||||
|
|
||||||
# if defined(CONFIG_PL2303) && defined(CONFIG_PL2303_CONSOLE)
|
# if defined(CONFIG_PL2303) && defined(CONFIG_PL2303_CONSOLE)
|
||||||
# define HAVE_USB_CONSOLE 1
|
# 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)
|
# elif defined(CONFIG_CDCACM) && defined(CONFIG_CDCACM_CONSOLE)
|
||||||
# define HAVE_USB_CONSOLE 1
|
# define HAVE_USB_CONSOLE 1
|
||||||
|
|
||||||
|
/* Check for other USB console. 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_UBSDEV_MINOR
|
||||||
|
# define CONFIG_NSH_UBSDEV_MINOR 0
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* USB trace settings */
|
||||||
|
|
||||||
|
# ifndef CONFIG_NSH_UBSDEV_TRACEINIT
|
||||||
|
# define CONFIG_NSH_UBSDEV_TRACEINIT (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT)
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* The default console device is always /dev/console */
|
||||||
|
|
||||||
|
# ifndef CONFIG_NSH_USBCONDEV
|
||||||
|
# define CONFIG_NSH_USBCONDEV "/dev/console"
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -95,6 +95,10 @@ int nsh_usbconsole(void)
|
|||||||
int fd;
|
int fd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Initialize any USB tracing options that were requested */
|
||||||
|
|
||||||
|
usbtrace_enable(CONFIG_NSH_UBSDEV_TRACEINIT);
|
||||||
|
|
||||||
/* Don't start the NSH console until the console device is ready. Chances
|
/* 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
|
* 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
|
* be available until the device is connected to the host and until the
|
||||||
@ -103,12 +107,14 @@ int nsh_usbconsole(void)
|
|||||||
|
|
||||||
/* Initialize the USB serial driver */
|
/* Initialize the USB serial driver */
|
||||||
|
|
||||||
|
#if defined(CONFIG_PL2303) || defined(CONFIG_CDCACM)
|
||||||
#ifdef CONFIG_CDCACM
|
#ifdef CONFIG_CDCACM
|
||||||
ret = cdcacm_initialize(0, NULL);
|
ret = cdcacm_initialize(CONFIG_NSH_UBSDEV_MINOR, NULL);
|
||||||
#else
|
#else
|
||||||
ret = usbdev_serialinitialize(0);
|
ret = usbdev_serialinitialize(CONFIG_NSH_UBSDEV_MINOR);
|
||||||
#endif
|
#endif
|
||||||
DEBUGASSERT(ret == OK);
|
DEBUGASSERT(ret == OK);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Make sure the stdin, stdout, and stderr are closed */
|
/* Make sure the stdin, stdout, and stderr are closed */
|
||||||
|
|
||||||
@ -122,14 +128,16 @@ int nsh_usbconsole(void)
|
|||||||
{
|
{
|
||||||
/* Try to open the console */
|
/* Try to open the console */
|
||||||
|
|
||||||
fd = open("/dev/console", O_RDWR);
|
fd = open(CONFIG_NSH_USBCONDEV, O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
|
int errval = errno;
|
||||||
|
|
||||||
/* ENOTCONN means that the USB device is not yet connected. Anything
|
/* ENOTCONN means that the USB device is not yet connected. Anything
|
||||||
* else is bad.
|
* else is bad.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(errno == ENOTCONN);
|
DEBUGASSERT(errval == ENOTCONN);
|
||||||
|
|
||||||
/* Sleep a bit and try again */
|
/* Sleep a bit and try again */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user