Integrate USB tracing

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1091 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-10-28 01:18:37 +00:00
parent 2098fcf3e8
commit eb2b208d71
5 changed files with 217 additions and 5 deletions

View File

@ -376,7 +376,7 @@ CONFIG_USBDEV_DUALSPEED=n
CONFIG_USBDEV_SELFPOWERED=y
CONFIG_USBDEV_REMOTEWAKEUP=n
CONFIG_USBDEV_MAXPOWER=100
CONFIG_USBDEV_TRACE=n
CONFIG_USBDEV_TRACE=y
CONFIG_USBDEV_TRACE_NRECORDS=128
#

View File

@ -143,7 +143,7 @@ void usbtrace(uint16 event, uint16 value)
if ((g_maskedidset & TRACE_ID2BIT(event)) != 0)
{
#ifdef CONFIG_USBDEV_TRACE
/* Yes... save the new trace data at the nead */
/* Yes... save the new trace data at the head */
g_trace[g_head].event = event;
g_trace[g_tail].event = value;
@ -354,16 +354,17 @@ void usbtrace(uint16 event, uint16 value)
#ifdef CONFIG_USBDEV_TRACE
int usbtrace_enumerate(trace_callback_t callback, void *arg)
{
uint16 ndx = g_tail;
uint16 ndx;
uint32 idset;
int ret = OK;
/* Temporarily disable tracing */
usbtrace_enable(FALSE);
idset = usbtrace_enable(0);
/* Visit every entry, starting with the tail */
while (g_tail != g_head)
for (ndx = g_tail; ndx != g_head; )
{
/* Call the user provided callback */
@ -383,6 +384,13 @@ int usbtrace_enumerate(trace_callback_t callback, void *arg)
}
}
/* Discard the trace data after it has been reported */
g_tail = g_head;
/* Restore tracing state */
(void)usbtrace_enable(idset);
return ret;
}
#endif /* CONFIG_USBDEV_TRACE */

View File

@ -83,14 +83,18 @@
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lib_lowprintf(__VA_ARGS__)
# define msgflush()
# else
# define message(...) printf(__VA_ARGS__)
# define msgflush() fflush(stdout)
# endif
#else
# ifdef CONFIG_DEBUG
# define message lib_lowprintf
# define msgflush()
# else
# define message printf
# define msgflush() fflush(stdout)
# endif
#endif

View File

@ -57,6 +57,192 @@
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: usbstrg_enumerate
****************************************************************************/
#ifdef CONFIG_USBDEV_TRACE
static int usbstrg_enumerate(struct usbtrace_s *trace, void *arg)
{
switch (trace->event)
{
case TRACE_DEVINIT:
message("USB controller initialization: %04x\n", trace->value);
break;
case TRACE_DEVUNINIT:
message("USB controller un-initialization: %04x\n", trace->value);
break;
case TRACE_DEVREGISTER:
message("usbdev_register(): %04x\n", trace->value);
break;
case TRACE_DEVUNREGISTER:
message("usbdev_unregister(): %04x\n", trace->value);
break;
case TRACE_EPCONFIGURE:
message("Endpoint configure(): %04x\n", trace->value);
break;
case TRACE_EPDISABLE:
message("Endpoint disable(): %04x\n", trace->value);
break;
case TRACE_EPALLOCREQ:
message("Endpoint allocreq(): %04x\n", trace->value);
break;
case TRACE_EPFREEREQ:
message("Endpoint freereq(): %04x\n", trace->value);
break;
case TRACE_EPALLOCBUFFER:
message("Endpoint allocbuffer(): %04x\n", trace->value);
break;
case TRACE_EPFREEBUFFER:
message("Endpoint freebuffer(): %04x\n", trace->value);
break;
case TRACE_EPSUBMIT:
message("Endpoint submit(): %04x\n", trace->value);
break;
case TRACE_EPCANCEL:
message("Endpoint cancel(): %04x\n", trace->value);
break;
case TRACE_EPSTALL:
message("Endpoint stall(TRUE): %04x\n", trace->value);
break;
case TRACE_EPRESUME:
message("Endpoint stall(FALSE): %04x\n", trace->value);
break;
case TRACE_DEVALLOCEP:
message("Device allocep(): %04x\n", trace->value);
break;
case TRACE_DEVFREEEP:
message("Device freeep(): %04x\n", trace->value);
break;
case TRACE_DEVGETFRAME:
message("Device getframe(): %04x\n", trace->value);
break;
case TRACE_DEVWAKEUP:
message("Device wakeup(): %04x\n", trace->value);
break;
case TRACE_DEVSELFPOWERED:
message("Device selfpowered(): %04x\n", trace->value);
break;
case TRACE_DEVPULLUP:
message("Device pullup(): %04x\n", trace->value);
break;
case TRACE_CLASSBIND:
message("Class bind(): %04x\n", trace->value);
break;
case TRACE_CLASSUNBIND:
message("Class unbind(): %04x\n", trace->value);
break;
case TRACE_CLASSDISCONNECT:
message("Class disconnect(): %04x\n", trace->value);
break;
case TRACE_CLASSSETUP:
message("Class setup(): %04x\n", trace->value);
break;
case TRACE_CLASSSUSPEND:
message("Class suspend(): %04x\n", trace->value);
break;
case TRACE_CLASSRESUME:
message("Class resume(): %04x\n", trace->value);
break;
case TRACE_CLASSRDCOMPLETE:
message("Class RD request complete: %04x\n", trace->value);
break;
case TRACE_CLASSWRCOMPLETE:
message("Class WR request complete: %04x\n", trace->value);
break;
default:
switch (TRACE_ID(trace->event))
{
case TRACE_CLASSAPI_ID: /* Other class driver system API calls */
message("Class API call %d: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_CLASSSTATE_ID: /* Track class driver state changes */
message("Class state %d: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_INTENTRY_ID: /* Interrupt handler entry */
message("Interrrupt %d entry: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_INTDECODE_ID: /* Decoded interrupt trace->event */
message("Interrrupt decode %d: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_INTEXIT_ID: /* Interrupt handler exit */
message("Interrrupt %d exit: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_OUTREQQUEUED_ID: /* Request queued for OUT endpoint */
message("EP%d OUT request queued: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_INREQQUEUED_ID: /* Request queued for IN endpoint */
message("EP%d IN request queued: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_READ_ID: /* Read (OUT) action */
message("EP%d OUT read: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_WRITE_ID: /* Write (IN) action */
message("EP%d IN write: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_COMPLETE_ID: /* Request completed */
message("EP%d request complete: %04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_DEVERROR_ID: /* USB controller driver error event */
message("Controller error: %02x:%04x\n", TRACE_DATA(trace->event), trace->value);
break;
case TRACE_CLSERROR_ID: /* USB class driver error event */
message("Class error: %02x:%04x\n", TRACE_DATA(trace->event), trace->value);
break;
default:
message("Unrecognized event: %02x:%02x:%04x\n",
TRACE_ID(trace->event) >> 8, TRACE_DATA(trace->event), trace->value);
break;
}
}
return OK;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -173,8 +359,21 @@ int user_start(int argc, char *argv[])
#ifndef CONFIG_DISABLE_SIGNALS
for (;;)
{
msgflush();
sleep(5);
#ifdef CONFIG_USBDEV_TRACE
message("\nuser_start: USB TRACE DATA:\n");
ret = usbtrace_enumerate(usbstrg_enumerate, NULL);
if (ret < 0)
{
message("user_start: usbtrace_enumerate failed: %d\n", -ret);
usbstrg_uninitialize(handle);
return 6;
}
#else
message("user_start: Still alive\n");
#endif
}
#else
message("user_start: Exiting\n");

View File

@ -451,6 +451,7 @@ EXTERN void usbtrace(uint16 event, uint16 value);
#ifdef CONFIG_USBDEV_TRACE
EXTERN int usbtrace_enumerate(trace_callback_t callback, void *arg);
#else
# define usbtrace_enumerate(event)
#endif