Skip to content
Snippets Groups Projects
Commit cbe4bf2e authored by patacongo's avatar patacongo
Browse files

Extend USB trace logic

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2212 42af7a65-404d-4744-a932-0658087f49c3
parent e80850b3
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,6 @@ endif
ifeq ($(CONFIG_USBSTRG),y)
USBDEV_CSRCS += usbdev_storage.c usbdev_scsi.c
endif
USBDEV_CSRCS += usbdev_trace.c usbdev_trprint.c
USBDEV_CSRCS += usbdev_trace.c usbdev_trprintf.c
endif
/****************************************************************************
* drivers/usbdev/usbdev_trace.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
......@@ -57,6 +57,10 @@
# define CONFIG_USBDEV_TRACE_NRECORDS 128
#endif
#ifndef CONFIG_USBDEV_TRACE_INITIALIDSET
# define CONFIG_USBDEV_TRACE_INITIALIDSET 0
#endif
/****************************************************************************
* Private Types
****************************************************************************/
......@@ -76,7 +80,7 @@ static uint16 g_tail = 0;
#endif
#if defined(CONFIG_USBDEV_TRACE) || (defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_USB))
static usbtrace_idset_t g_maskedidset = 0;
static usbtrace_idset_t g_maskedidset = CONFIG_USBDEV_TRACE_INITIALIDSET;
#endif
/****************************************************************************
......@@ -163,178 +167,10 @@ void usbtrace(uint16 event, uint16 value)
}
}
#else
switch (event)
{
case TRACE_DEVINIT:
lldbg("USB controller initialization: %04x\n", value);
break;
case TRACE_DEVUNINIT:
lldbg("USB controller un-initialization: %04x\n", value);
break;
case TRACE_DEVREGISTER:
lldbg("usbdev_register(): %04x\n", value);
break;
case TRACE_DEVUNREGISTER:
lldbg("usbdev_unregister(): %04x\n", value);
break;
case TRACE_EPCONFIGURE:
lldbg("Endpoint configure(): %04x\n", value);
break;
case TRACE_EPDISABLE:
lldbg("Endpoint disable(): %04x\n", value);
break;
case TRACE_EPALLOCREQ:
lldbg("Endpoint allocreq(): %04x\n", value);
break;
case TRACE_EPFREEREQ:
lldbg("Endpoint freereq(): %04x\n", value);
break;
case TRACE_EPALLOCBUFFER:
lldbg("Endpoint allocbuffer(): %04x\n", value);
break;
case TRACE_EPFREEBUFFER:
lldbg("Endpoint freebuffer(): %04x\n", value);
break;
case TRACE_EPSUBMIT:
lldbg("Endpoint submit(): %04x\n", value);
break;
case TRACE_EPCANCEL:
lldbg("Endpoint cancel(): %04x\n", value);
break;
case TRACE_EPSTALL:
lldbg("Endpoint stall(TRUE): %04x\n", value);
break;
case TRACE_EPRESUME:
lldbg("Endpoint stall(FALSE): %04x\n", value);
break;
case TRACE_DEVALLOCEP:
lldbg("Device allocep(): %04x\n", value);
break;
/* Just print the data using lib_lowprintf */
case TRACE_DEVFREEEP:
lldbg("Device freeep(): %04x\n", value);
break;
case TRACE_DEVGETFRAME:
lldbg("Device getframe(): %04x\n", value);
break;
case TRACE_DEVWAKEUP:
lldbg("Device wakeup(): %04x\n", value);
break;
case TRACE_DEVSELFPOWERED:
lldbg("Device selfpowered(): %04x\n", value);
break;
case TRACE_DEVPULLUP:
lldbg("Device pullup(): %04x\n", value);
break;
case TRACE_CLASSBIND:
lldbg("Class bind(): %04x\n", value);
break;
case TRACE_CLASSUNBIND:
lldbg("Class unbind(): %04x\n", value);
break;
case TRACE_CLASSDISCONNECT:
lldbg("Class disconnect(): %04x\n", value);
break;
case TRACE_CLASSSETUP:
lldbg("Class setup(): %04x\n", value);
break;
case TRACE_CLASSSUSPEND:
lldbg("Class suspend(): %04x\n", value);
break;
case TRACE_CLASSRESUME:
lldbg("Class resume(): %04x\n", value);
break;
case TRACE_CLASSRDCOMPLETE:
lldbg("Class RD request complete: %04x\n", value);
break;
case TRACE_CLASSWRCOMPLETE:
lldbg("Class WR request complete: %04x\n", value);
break;
default:
switch (TRACE_ID(event))
{
case TRACE_CLASSAPI_ID: /* Other class driver system API calls */
lldbg("Class API call %d: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_CLASSSTATE_ID: /* Track class driver state changes */
lldbg("Class state %d: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_INTENTRY_ID: /* Interrupt handler entry */
lldbg("Interrupt %d entry: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_INTDECODE_ID: /* Decoded interrupt event */
lldbg("Interrrupt decode %d: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_INTEXIT_ID: /* Interrupt handler exit */
lldbg("Interrrupt %d exit: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_OUTREQQUEUED_ID: /* Request queued for OUT endpoint */
lldbg("EP%d OUT request queued: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_INREQQUEUED_ID: /* Request queued for IN endpoint */
lldbg("EP%d IN request queued: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_READ_ID: /* Read (OUT) action */
lldbg("EP%d OUT read: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_WRITE_ID: /* Write (IN) action */
lldbg("EP%d IN write: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_COMPLETE_ID: /* Request completed */
lldbg("EP%d request complete: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_DEVERROR_ID: /* USB controller driver error event */
lldbg("Controller error: %02x:%04x\n", TRACE_DATA(event), value);
break;
case TRACE_CLSERROR_ID: /* USB class driver error event */
lldbg("Class error: %02x:%04x\n", TRACE_DATA(event), value);
break;
default:
lldbg("Unrecognized event: %02x:%02x:%04x\n",
TRACE_ID(event) >> 8, TRACE_DATA(event), value);
break;
}
}
#endif /* CONFIG_USBDEV_TRACE */
usbtrace_trprintf((trprintf_t)lib_lowprintf, event, value);
#endif
}
irqrestore(flags);
}
......
/****************************************************************************
* drivers/usbdev/usbdev_trprintf.c
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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 <debug.h>
#include <nuttx/usbdev_trace.h>
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/*******************************************************************************
* Name: usbtrace_trprintf
*
* Description:
* Print the trace record using the supplied printing function
*
*******************************************************************************/
void usbtrace_trprintf(trprintf_t trprintf, uint16 event, uint16 value)
{
switch (event)
{
case TRACE_DEVINIT:
trprintf("USB controller initialization: %04x\n", value);
break;
case TRACE_DEVUNINIT:
trprintf("USB controller un-initialization: %04x\n", value);
break;
case TRACE_DEVREGISTER:
trprintf("usbdev_register(): %04x\n", value);
break;
case TRACE_DEVUNREGISTER:
trprintf("usbdev_unregister(): %04x\n", value);
break;
case TRACE_EPCONFIGURE:
trprintf("Endpoint configure(): %04x\n", value);
break;
case TRACE_EPDISABLE:
trprintf("Endpoint disable(): %04x\n", value);
break;
case TRACE_EPALLOCREQ:
trprintf("Endpoint allocreq(): %04x\n", value);
break;
case TRACE_EPFREEREQ:
trprintf("Endpoint freereq(): %04x\n", value);
break;
case TRACE_EPALLOCBUFFER:
trprintf("Endpoint allocbuffer(): %04x\n", value);
break;
case TRACE_EPFREEBUFFER:
trprintf("Endpoint freebuffer(): %04x\n", value);
break;
case TRACE_EPSUBMIT:
trprintf("Endpoint submit(): %04x\n", value);
break;
case TRACE_EPCANCEL:
trprintf("Endpoint cancel(): %04x\n", value);
break;
case TRACE_EPSTALL:
trprintf("Endpoint stall(TRUE): %04x\n", value);
break;
case TRACE_EPRESUME:
trprintf("Endpoint stall(FALSE): %04x\n", value);
break;
case TRACE_DEVALLOCEP:
trprintf("Device allocep(): %04x\n", value);
break;
case TRACE_DEVFREEEP:
trprintf("Device freeep(): %04x\n", value);
break;
case TRACE_DEVGETFRAME:
trprintf("Device getframe(): %04x\n", value);
break;
case TRACE_DEVWAKEUP:
trprintf("Device wakeup(): %04x\n", value);
break;
case TRACE_DEVSELFPOWERED:
trprintf("Device selfpowered(): %04x\n", value);
break;
case TRACE_DEVPULLUP:
trprintf("Device pullup(): %04x\n", value);
break;
case TRACE_CLASSBIND:
trprintf("Class bind(): %04x\n", value);
break;
case TRACE_CLASSUNBIND:
trprintf("Class unbind(): %04x\n", value);
break;
case TRACE_CLASSDISCONNECT:
trprintf("Class disconnect(): %04x\n", value);
break;
case TRACE_CLASSSETUP:
trprintf("Class setup(): %04x\n", value);
break;
case TRACE_CLASSSUSPEND:
trprintf("Class suspend(): %04x\n", value);
break;
case TRACE_CLASSRESUME:
trprintf("Class resume(): %04x\n", value);
break;
case TRACE_CLASSRDCOMPLETE:
trprintf("Class RD request complete: %04x\n", value);
break;
case TRACE_CLASSWRCOMPLETE:
trprintf("Class WR request complete: %04x\n", value);
break;
default:
switch (TRACE_ID(event))
{
case TRACE_CLASSAPI_ID: /* Other class driver system API calls */
trprintf("Class API call %d: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_CLASSSTATE_ID: /* Track class driver state changes */
trprintf("Class state %d: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_INTENTRY_ID: /* Interrupt handler entry */
trprintf("Interrupt %d entry: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_INTDECODE_ID: /* Decoded interrupt event */
trprintf("Interrupt decode %d: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_INTEXIT_ID: /* Interrupt handler exit */
trprintf("Interrupt %d exit: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_OUTREQQUEUED_ID: /* Request queued for OUT endpoint */
trprintf("EP%d OUT request queued: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_INREQQUEUED_ID: /* Request queued for IN endpoint */
trprintf("EP%d IN request queued: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_READ_ID: /* Read (OUT) action */
trprintf("EP%d OUT read: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_WRITE_ID: /* Write (IN) action */
trprintf("EP%d IN write: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_COMPLETE_ID: /* Request completed */
trprintf("EP%d request complete: %04x\n", TRACE_DATA(event), value);
break;
case TRACE_DEVERROR_ID: /* USB controller driver error event */
trprintf("Controller error: %02x:%04x\n", TRACE_DATA(event), value);
break;
case TRACE_CLSERROR_ID: /* USB class driver error event */
trprintf("Class error: %02x:%04x\n", TRACE_DATA(event), value);
break;
default:
trprintf("Unrecognized event: %02x:%02x:%04x\n",
TRACE_ID(event) >> 8, TRACE_DATA(event), value);
break;
}
}
}
......@@ -49,6 +49,7 @@
#include <debug.h>
#include <nuttx/usbdev.h>
#include <nuttx/usbdev_trace.h>
/****************************************************************************
* Definitions
......@@ -66,18 +67,57 @@
# define COUNTER_NEEDED 1
# endif
#endif
#ifdef CONFIG_EXAMPLES_USBSERIAL_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_USBSERIAL_TRACECLASS
# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT)
#else
# define TRACE_CLASS_BITS (0)
#endif
#ifdef CONFIG_EXAMPLES_USBSERIAL_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_USBSERIAL_TRACECONTROLLER
# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT)
#else
# define TRACE_CONTROLLER_BITS (0)
#endif
#ifdef CONFIG_EXAMPLES_USBSERIAL_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_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lib_lowprintf(__VA_ARGS__)
# define trmessage lib_lowprintf
# else
# define message(...) printf(__VA_ARGS__)
# define trmessage printf
# endif
#else
# ifdef CONFIG_DEBUG
# define message lib_lowprintf
# define message lib_lowprintf
# define trmessage lib_lowprintf
# else
# define message printf
# define message printf
# define trmessage printf
# endif
#endif
......@@ -124,6 +164,25 @@ static const char g_longmsg[] =
static char g_iobuffer[IOBUFFER_SIZE];
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
#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;
}
static void dumptrace(void)
{
(void)usbtrace_enumerate(trace_callback, NULL);
}
#else
# define dumptrace()
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
......@@ -173,6 +232,17 @@ int user_start(int argc, char *argv[])
}
message("user_start: Successfully registered the serial driver\n");
#ifdef CONFIG_USBDEV_TRACE
#if CONFIG_USBDEV_TRACE_INITIALIDSET != 0
/* If USB tracing is enabled, then dump all collected trace data to stdout */
sleep(5);
dumptrace();
#else
usbtrace_enable(TRACE_BITSET);
#endif
#endif
/* Open the USB serial device for writing (blocking) */
#ifndef CONFIG_EXAMPLES_USBSERIAL_OUTONLY
......@@ -200,6 +270,10 @@ int user_start(int argc, char *argv[])
return 2;
}
}
/* If USB tracing is enabled, then dump all collected trace data to stdout */
dumptrace();
}
while (outfd < 0);
#endif
......@@ -239,6 +313,10 @@ int user_start(int argc, char *argv[])
return 3;
}
}
/* If USB tracing is enabled, then dump all collected trace data to stdout */
dumptrace();
}
while (infd < 0);
#endif
......@@ -250,7 +328,6 @@ int user_start(int argc, char *argv[])
for (;;)
{
/* Test IN (device-to-host) messages */
#ifndef CONFIG_EXAMPLES_USBSERIAL_OUTONLY
......@@ -368,6 +445,10 @@ int user_start(int argc, char *argv[])
message("user_start: Waiting\n");
sleep(5);
#endif /* CONFIG_EXAMPLES_USBSERIAL_INONLY */
/* If USB tracing is enabled, then dump all collected trace data to stdout */
dumptrace();
}
/* Won't get here, but if we did this what we would have to do */
......
......@@ -385,6 +385,10 @@ typedef int (*trace_callback_t)(struct usbtrace_s *trace, void *arg);
typedef uint16 usbtrace_idset_t;
/* Print routine to use for usbdev_trprint() output */
typedef int (*trprintf_t)(const char *fmt, ...);
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
......@@ -455,6 +459,16 @@ EXTERN int usbtrace_enumerate(trace_callback_t callback, void *arg);
# define usbtrace_enumerate(event)
#endif
/*******************************************************************************
* Name: usbtrace_trprint
*
* Description:
* Print the trace record using the supplied printing function
*
*******************************************************************************/
EXTERN void usbtrace_trprintf(trprintf_t trprintf, uint16 event, uint16 value);
#undef EXTERN
#if defined(__cplusplus)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment