summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-03-20 10:56:30 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-03-20 10:56:30 -0600
commitf8c6f5c5181f02eeb969c501ef0b5fef363a2fb1 (patch)
tree67f5f710b13ac0d5524e366866763e2b1b106e8f /nuttx
parent35392d553c92ad96c944800bbb50defb4ca66f13 (diff)
downloadnuttx-f8c6f5c5181f02eeb969c501ef0b5fef363a2fb1.tar.gz
nuttx-f8c6f5c5181f02eeb969c501ef0b5fef363a2fb1.tar.bz2
nuttx-f8c6f5c5181f02eeb969c501ef0b5fef363a2fb1.zip
Add option to dump buffered USB trace data on an assertion
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/ChangeLog3
-rw-r--r--nuttx/arch/8051/src/up_assert.c31
-rw-r--r--nuttx/arch/Kconfig7
-rw-r--r--nuttx/arch/arm/src/arm/up_assert.c27
-rw-r--r--nuttx/arch/arm/src/armv6-m/up_assert.c27
-rw-r--r--nuttx/arch/arm/src/armv7-a/arm_assert.c28
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_assert.c27
-rw-r--r--nuttx/arch/arm/src/sam34/sam_udp.c268
-rw-r--r--nuttx/arch/avr/src/common/up_assert.c28
-rw-r--r--nuttx/arch/hc/src/m9s12/m9s12_assert.c27
-rw-r--r--nuttx/arch/mips/src/mips32/up_assert.c28
-rw-r--r--nuttx/arch/sh/src/common/up_assert.c29
-rw-r--r--nuttx/arch/x86/src/common/up_assert.c29
-rw-r--r--nuttx/arch/z16/src/common/up_assert.c32
-rw-r--r--nuttx/arch/z80/src/common/up_assert.c31
15 files changed, 511 insertions, 111 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index f824247a8..2e3b67ecb 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -7012,5 +7012,6 @@
* arch/arm/Kconfig: Improved documentation of the use of the
BASEPRI register from Vijay Kumar (2014-3-19).
* include/nuttx/i2c.h: More typo fixes from Vijay Kumar (2014-3-19).
-
+ * arch/Kconfig and *_assert.h: Add a configuration option to enable
+ dumping of the USB trace buffer on assertion (2014-3-19).
diff --git a/nuttx/arch/8051/src/up_assert.c b/nuttx/arch/8051/src/up_assert.c
index c25fb81d4..2b9cf7759 100644
--- a/nuttx/arch/8051/src/up_assert.c
+++ b/nuttx/arch/8051/src/up_assert.c
@@ -1,7 +1,7 @@
/************************************************************************
* up_assert.c
*
- * Copyright (C) 2007, 2009, 2012-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2009, 2012-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -44,14 +44,22 @@
#include <sched.h>
#include <debug.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <8052.h>
+
#include "os_internal.h"
#include "up_internal.h"
#include "up_mem.h"
/************************************************************************
- * Definitions
+ * Pre-processor Definitions
************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/************************************************************************
* Private Data
@@ -89,6 +97,18 @@ static void _up_assert(int errorcode)
}
}
+/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
/************************************************************************
* Public Functions
************************************************************************/
@@ -114,5 +134,12 @@ void up_assert(const uint8_t *filename, int lineno)
#endif
up_dumpstack();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
+
_up_assert(EXIT_FAILURE);
}
diff --git a/nuttx/arch/Kconfig b/nuttx/arch/Kconfig
index f84817f94..deee2d69d 100644
--- a/nuttx/arch/Kconfig
+++ b/nuttx/arch/Kconfig
@@ -292,6 +292,13 @@ config ARCH_STACKDUMP
---help---
Enable to do stack dumps after assertions
+config ARCH_USBDUMP
+ bool "Dump USB trace data"
+ default n
+ depends on USBDEV_TRACE
+ ---help---
+ Enable to do USB trace after assertions
+
config ENDIAN_BIG
bool "Big Endian Architecture"
default n
diff --git a/nuttx/arch/arm/src/arm/up_assert.c b/nuttx/arch/arm/src/arm/up_assert.c
index c754f226a..2d90313da 100644
--- a/nuttx/arch/arm/src/arm/up_assert.c
+++ b/nuttx/arch/arm/src/arm/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/arm/up_assert.c
*
- * Copyright (C) 2007-2010, 2012-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2010, 2012-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "up_arch.h"
@@ -55,6 +57,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -155,6 +162,18 @@ static inline void up_registerdump(void)
#endif
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Name: up_dumpstate
****************************************************************************/
@@ -243,6 +262,12 @@ static void up_dumpstate(void)
/* Then dump the registers (if available) */
up_registerdump();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
}
#else
# define up_dumpstate()
diff --git a/nuttx/arch/arm/src/armv6-m/up_assert.c b/nuttx/arch/arm/src/armv6-m/up_assert.c
index 8161d18c5..bee569cce 100644
--- a/nuttx/arch/arm/src/armv6-m/up_assert.c
+++ b/nuttx/arch/arm/src/armv6-m/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/armv6-m/up_assert.c
*
- * Copyright (C) 2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "up_arch.h"
@@ -55,6 +57,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -162,6 +169,18 @@ static inline void up_registerdump(void)
#endif
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Name: up_dumpstate
****************************************************************************/
@@ -259,6 +278,12 @@ static void up_dumpstate(void)
/* Then dump the registers (if available) */
up_registerdump();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
}
#else
# define up_dumpstate()
diff --git a/nuttx/arch/arm/src/armv7-a/arm_assert.c b/nuttx/arch/arm/src/armv7-a/arm_assert.c
index 09ed223f2..2085b7050 100644
--- a/nuttx/arch/arm/src/armv7-a/arm_assert.c
+++ b/nuttx/arch/arm/src/armv7-a/arm_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/armv7-a/arm_assert.c
*
- * Copyright (C) 2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "up_arch.h"
@@ -55,6 +57,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -155,6 +162,18 @@ static inline void up_registerdump(void)
#endif
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Name: up_dumpstate
****************************************************************************/
@@ -207,6 +226,7 @@ static void up_dumpstate(void)
lldbg("ERROR: Stack pointer is not within interrupt stack\n");
}
}
+
if (sp <= istackbase && sp > istackbase - istacksize)
{
/* Yes.. dump the interrupt stack */
@@ -253,6 +273,12 @@ static void up_dumpstate(void)
/* Then dump the registers (if available) */
up_registerdump();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
}
#else
# define up_dumpstate()
diff --git a/nuttx/arch/arm/src/armv7-m/up_assert.c b/nuttx/arch/arm/src/armv7-m/up_assert.c
index 26b3eda1f..fd29259e9 100644
--- a/nuttx/arch/arm/src/armv7-m/up_assert.c
+++ b/nuttx/arch/arm/src/armv7-m/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/armv7-m/up_assert.c
*
- * Copyright (C) 2009-2010, 2012-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009-2010, 2012-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "up_arch.h"
@@ -55,6 +57,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -168,6 +175,18 @@ static inline void up_registerdump(void)
#endif
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Name: up_dumpstate
****************************************************************************/
@@ -270,6 +289,12 @@ static void up_dumpstate(void)
/* Then dump the registers (if available) */
up_registerdump();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
}
#else
# define up_dumpstate()
diff --git a/nuttx/arch/arm/src/sam34/sam_udp.c b/nuttx/arch/arm/src/sam34/sam_udp.c
index b2546687c..17aee4385 100644
--- a/nuttx/arch/arm/src/sam34/sam_udp.c
+++ b/nuttx/arch/arm/src/sam34/sam_udp.c
@@ -298,6 +298,7 @@ struct sam_ep_s
struct sam_rqhead_s reqq; /* Read/write request queue */
volatile uint8_t epstate; /* State of the endpoint (see enum sam_epstate_e) */
uint8_t stalled:1; /* true: Endpoint is stalled */
+ uint8_t pending:1; /* true: IN Endpoint stall is pending */
uint8_t halted:1; /* true: Endpoint feature halted */
uint8_t zlpneeded:1; /* Zero length packet needed at end of transfer */
uint8_t zlpsent:1; /* Zero length packet has been sent */
@@ -400,6 +401,8 @@ static int sam_udp_interrupt(int irq, void *context);
static void sam_ep_reset(struct sam_usbdev_s *priv, uint8_t epno);
static void sam_epset_reset(struct sam_usbdev_s *priv, uint16_t epset);
+static int sam_ep_stall(struct sam_ep_s *privep);
+static int sam_ep_resume(struct sam_ep_s *privep);
static inline struct sam_ep_s *
sam_ep_reserve(struct sam_usbdev_s *priv, uint8_t epset);
static inline void
@@ -427,7 +430,7 @@ static int sam_ep_submit(struct usbdev_ep_s *ep,
struct usbdev_req_s *req);
static int sam_ep_cancel(struct usbdev_ep_s *ep,
struct usbdev_req_s *req);
-static int sam_ep_stall(struct usbdev_ep_s *ep, bool resume);
+static int sam_ep_stallresume(struct usbdev_ep_s *ep, bool resume);
/* USB device controller operations *****************************************/
@@ -472,7 +475,7 @@ static const struct usbdev_epops_s g_epops =
#endif
.submit = sam_ep_submit,
.cancel = sam_ep_cancel,
- .stall = sam_ep_stall,
+ .stall = sam_ep_stallresume,
};
static const struct usbdev_ops_s g_devops =
@@ -990,6 +993,16 @@ static int sam_req_write(struct sam_usbdev_s *priv, struct sam_ep_s *privep)
/* Clear any pending the TXCOMP interrupt */
sam_csr_clrbits(epno, UDPEP_CSR_TXCOMP);
+
+ /* Was there a pending endpoint stall? */
+
+ if (privep->pending)
+ {
+ /* Yes... stall the endpoint now */
+
+ (void)sam_ep_stall(privep);
+ }
+
return -ENOENT;
}
@@ -1080,9 +1093,12 @@ static int sam_req_write(struct sam_usbdev_s *priv, struct sam_ep_s *privep)
* TXCOMP was set by the USB device when it has received an ACK
* PID signal for the Data IN packet. An interrupt is pending
* while TXCOMP is set.
+ *
+ * REVISIT: This function might be called before TXCOMP is
+ * actually received.
*/
- sam_csr_clrbits(epno, UDPEP_CSR_TXCOMP);
+ //sam_csr_clrbits(epno, UDPEP_CSR_TXCOMP);
/* Return the write request to the class driver */
@@ -1336,7 +1352,7 @@ static void sam_ep0_dispatch(struct sam_usbdev_s *priv)
/* Stall on failure */
usbtrace(TRACE_DEVERROR(SAM_TRACEERR_DISPATCHSTALL), 0);
- (void)sam_ep_stall(&priv->eplist[EP0].ep, false);
+ (void)sam_ep_stall(&priv->eplist[EP0]);
}
}
}
@@ -1408,6 +1424,7 @@ static void sam_ep0_setup(struct sam_usbdev_s *priv)
/* Assume NOT stalled; no TX in progress */
ep0->stalled = false;
+ ep0->pending = false;
ep0->epstate = UDP_EPSTATE_IDLE;
/* And extract the little-endian 16-bit values to host order */
@@ -1551,7 +1568,7 @@ static void sam_ep0_setup(struct sam_usbdev_s *priv)
privep = &priv->eplist[epno];
privep->halted = false;
- ret = sam_ep_stall(&privep->ep, true);
+ ret = sam_ep_resume(privep);
if (ret < 0)
{
ep0result = UDP_EP0SETUP_STALL;
@@ -1600,7 +1617,7 @@ static void sam_ep0_setup(struct sam_usbdev_s *priv)
privep = &priv->eplist[epno];
privep->halted = true;
- ret = sam_ep_stall(&privep->ep, false);
+ ret = sam_ep_stall(privep);
if (ret < 0)
{
ep0result = UDP_EP0SETUP_STALL;
@@ -1834,7 +1851,7 @@ static void sam_ep0_setup(struct sam_usbdev_s *priv)
usbtrace(TRACE_DEVERROR(SAM_TRACEERR_EP0SETUPSTALLED),
priv->ctrl.req);
- (void)sam_ep_stall(&priv->eplist[EP0].ep, false);
+ (void)sam_ep_stall(&priv->eplist[EP0]);
}
break;
@@ -1909,7 +1926,7 @@ static void sam_ep_bankinterrupt(struct sam_usbdev_s *priv,
else
{
usbtrace(TRACE_DEVERROR(SAM_TRACEERR_EP0SETUPOUTSIZE), pktsize);
- (void)sam_ep_stall(&privep->ep, false);
+ (void)sam_ep_stall(privep);
}
}
@@ -2485,6 +2502,7 @@ static void sam_ep_reset(struct sam_usbdev_s *priv, uint8_t epno)
privep->epstate = UDP_EPSTATE_DISABLED;
privep->stalled = false;
+ privep->pending = false;
privep->halted = false;
privep->zlpneeded = false;
privep->zlpsent = false;
@@ -2522,6 +2540,122 @@ static void sam_epset_reset(struct sam_usbdev_s *priv, uint16_t epset)
}
/****************************************************************************
+ * Name: sam_ep_stall
+ ****************************************************************************/
+
+static int sam_ep_stall(struct sam_ep_s *privep)
+{
+ irqstate_t flags;
+ uint8_t epno;
+
+ /* Check that endpoint is in Idle state */
+
+ DEBUGASSERT(/* privep->epstate == UDP_EPSTATE_IDLE && */ privep->dev);
+
+ /* Check that endpoint is enabled and not already in Halt state */
+
+ flags = irqsave();
+ if ((privep->epstate != UDP_EPSTATE_DISABLED) &&
+ (privep->epstate != UDP_EPSTATE_STALLED))
+ {
+ epno = USB_EPNO(privep->ep.eplog);
+ usbtrace(TRACE_EPSTALL, epno);
+
+ /* If this is an IN endpoint (or endpoint 0), then cancel all
+ * of the pending write requests.
+ */
+
+ if (epno == 0 || USB_ISEPIN(privep->ep.eplog))
+ {
+ sam_req_cancel(privep, -EPERM);
+ }
+
+ /* Otherwise, it is an OUT endpoint. Complete any read request
+ * currently in progress (they will get requeued immediately).
+ */
+
+ else if (privep->epstate == UDP_EPSTATE_RECEIVING)
+ {
+ sam_req_complete(privep, -EPERM);
+ }
+
+ /* Put endpoint into stalled state */
+
+ privep->epstate = UDP_EPSTATE_STALLED;
+ privep->stalled = true;
+ privep->pending = false;
+
+ sam_csr_setbits(epno, UDPEP_CSR_FORCESTALL);
+ }
+
+ irqrestore(flags);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: sam_ep_resume
+ ****************************************************************************/
+
+static int sam_ep_resume(struct sam_ep_s *privep)
+{
+ struct sam_usbdev_s *priv;
+ irqstate_t flags;
+ uint8_t epno;
+
+ /* Check that endpoint is in Idle state */
+
+ DEBUGASSERT(/* privep->epstate == UDP_EPSTATE_IDLE && */ privep->dev);
+
+ flags = irqsave();
+
+ /* Check if the endpoint is stalled */
+
+ if (privep->epstate == UDP_EPSTATE_STALLED)
+ {
+ epno = USB_EPNO(privep->ep.eplog);
+ usbtrace(TRACE_EPRESUME, epno);
+
+ priv = (struct sam_usbdev_s *)privep->dev;
+
+ /* Return endpoint to Idle state */
+
+ privep->stalled = false;
+ privep->pending = false;
+ privep->epstate = UDP_EPSTATE_IDLE;
+
+ /* Clear FORCESTALL request
+ * REVISIT: Data sheet says to reset toggle to DATA0 only on OUT
+ * endpoints.
+ */
+
+ sam_csr_clrbits(epno, UDPEP_CSR_DTGLE | UDPEP_CSR_FORCESTALL);
+
+ /* Reset the endpoint FIFO */
+
+ sam_putreg(UDP_RSTEP(epno), SAM_UDP_RSTEP);
+ sam_putreg(0, SAM_UDP_RSTEP);
+
+ /* Resuming any blocked data transfers on the endpoint */
+
+ if (epno == 0 || USB_ISEPIN(privep->ep.eplog))
+ {
+ /* IN endpoint (or EP0). Restart any queued write requests */
+
+ (void)sam_req_write(priv, privep);
+ }
+ else
+ {
+ /* OUT endpoint. Restart any queued read requests. */
+
+ (void)sam_req_read(priv, privep, 0);
+ }
+ }
+
+ irqrestore(flags);
+ return OK;
+}
+
+/****************************************************************************
* Name: sam_ep_reserve
*
* Description:
@@ -2965,11 +3099,11 @@ static int sam_ep_submit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
if (USB_ISEPIN(ep->eplog) || epno == EP0)
{
- /* If the endpoint is stalled, then fail any attempts to write
- * through the endpoint.
+ /* If the endpoint is stalled (or there is a stall pending), then fail
+ * any attempts to write through the endpoint.
*/
- if (privep->stalled)
+ if (privep->stalled || privep->pending)
{
sam_req_abort(privep, privreq, -EBUSY);
ulldbg("ERROR: stalled\n");
@@ -3037,15 +3171,15 @@ static int sam_ep_cancel(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
}
/****************************************************************************
- * Name: sam_ep_stall
+ * Name: sam_ep_stallresume
****************************************************************************/
-static int sam_ep_stall(struct usbdev_ep_s *ep, bool resume)
+static int sam_ep_stallresume(struct usbdev_ep_s *ep, bool resume)
{
struct sam_ep_s *privep;
- struct sam_usbdev_s *priv;
- uint8_t epno = USB_EPNO(ep->eplog);
+ uint8_t epno;
irqstate_t flags;
+ int ret;
#ifdef CONFIG_DEBUG
if (!ep)
@@ -3055,103 +3189,52 @@ static int sam_ep_stall(struct usbdev_ep_s *ep, bool resume)
}
#endif
- /* Check that endpoint is in Idle state */
-
- privep = (struct sam_ep_s *)ep;
- DEBUGASSERT(/* privep->epstate == UDP_EPSTATE_IDLE && */ privep->dev);
-
- priv = (struct sam_usbdev_s *)privep->dev;
- epno = USB_EPNO(ep->eplog);
-
- /* STALL or RESUME the endpoint */
-
- flags = irqsave();
- usbtrace(resume ? TRACE_EPRESUME : TRACE_EPSTALL, USB_EPNO(ep->eplog));
-
/* Handle the resume condition */
+ privep = (struct sam_ep_s *)ep;
if (resume)
{
- /* Check if the endpoint is halted */
-
- if (privep->epstate == UDP_EPSTATE_STALLED)
- {
- usbtrace(TRACE_EPRESUME, epno);
- privep->stalled = false;
-
- /* Return endpoint to Idle state */
-
- privep->epstate = UDP_EPSTATE_IDLE;
-
- /* Clear FORCESTALL request
- * REVISIT: Data sheet says to reset toggle to DATA0 only on OUT
- * endpoints.
- */
-
- sam_csr_clrbits(epno, UDPEP_CSR_DTGLE | UDPEP_CSR_FORCESTALL);
-
- /* Reset the endpoint FIFO */
-
- sam_putreg(UDP_RSTEP(epno), SAM_UDP_RSTEP);
- sam_putreg(0, SAM_UDP_RSTEP);
-
- /* Resuming any blocked data transfers on the endpoint */
-
- if (epno == 0 || USB_ISEPIN(ep->eplog))
- {
- /* IN endpoint (or EP0). Restart any queued write requests */
-
- (void)sam_req_write(priv, privep);
- }
- else
- {
- /* OUT endpoint. Restart any queued read requests. */
-
- (void)sam_req_read(priv, privep, 0);
- }
- }
+ ret = sam_ep_resume(privep);
}
/* Handle the stall condition */
else
{
- /* Check that endpoint is enabled and not already in Halt state */
+ /* If this is an IN endpoint (and not EP0) and if there are queued
+ * write requests, then we cannot stall now. Perhaps this is a
+ * protocol stall. In that case, we will need to drain the write
+ * requests before sending the stall.
+ */
- if ((privep->epstate != UDP_EPSTATE_DISABLED) &&
- (privep->epstate != UDP_EPSTATE_STALLED))
+ flags = irqsave();
+ epno = USB_EPNO(ep->eplog);
+ if (epno != 0 && USB_ISEPIN(ep->eplog))
{
- usbtrace(TRACE_EPSTALL, epno);
-
- /* If this is an IN endpoint (or endpoint 0), then cancel all
- * of the pending write requests.
- */
+ /* Are there any unfinished write requests in the request queue? */
- if (epno == 0 || USB_ISEPIN(ep->eplog))
+ if (!sam_rqempty(&privep->reqq)))
{
- sam_req_cancel(privep, -EPERM);
- }
-
- /* Otherwise, it is an OUT endpoint. Complete any read request
- * currently in progress (it will get requeued immediately).
- */
+ /* Just set a flag to indicate that the endpoint must be
+ * stalled on the next TXCOMP interrupt when the requeust
+ * queue becomes empty.
+ */
- else if (privep->epstate == UDP_EPSTATE_RECEIVING)
- {
- sam_req_complete(privep, -EPERM);
+ privep->pending = true;
+ irqrestore(flags);
+ return OK;
}
+ }
- /* Put endpoint into stalled state */
-
- privep->epstate = UDP_EPSTATE_STALLED;
- privep->stalled = true;
+ /* Not an IN endpoint, endpoint 0, or no pending write requests.
+ * Stall the endpoint now.
+ */
- sam_csr_setbits(epno, UDPEP_CSR_FORCESTALL);
- }
+ ret = sam_ep_stall(privep);
+ irqrestore(flags);
}
- irqrestore(flags);
- return OK;
+ return ret;
}
/****************************************************************************
@@ -3479,6 +3562,7 @@ static void sam_reset(struct sam_usbdev_s *priv)
/* Reset endpoint status */
privep->stalled = false;
+ privep->pending = false;
privep->halted = false;
privep->zlpneeded = false;
privep->zlpsent = false;
diff --git a/nuttx/arch/avr/src/common/up_assert.c b/nuttx/arch/avr/src/common/up_assert.c
index 59001cd43..c66ce0fca 100644
--- a/nuttx/arch/avr/src/common/up_assert.c
+++ b/nuttx/arch/avr/src/common/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/avr/src/common/up_assert.c
*
- * Copyright (C) 2010-2011, 2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2010-2011, 2013-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "up_arch.h"
@@ -55,6 +57,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* The following is just intended to keep some ugliness out of the mainline
* code. We are going to print the task name if:
@@ -115,6 +122,18 @@ static void _up_assert(int errorcode)
}
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -139,5 +158,12 @@ void up_assert(const uint8_t *filename, int lineno)
#endif
up_dumpstate();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
+
_up_assert(EXIT_FAILURE);
}
diff --git a/nuttx/arch/hc/src/m9s12/m9s12_assert.c b/nuttx/arch/hc/src/m9s12/m9s12_assert.c
index d94f97b6c..e62bdd5f6 100644
--- a/nuttx/arch/hc/src/m9s12/m9s12_assert.c
+++ b/nuttx/arch/hc/src/m9s12/m9s12_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/hc/src/m9s12/m9s12_assert.c
*
- * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "up_arch.h"
@@ -55,6 +57,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -150,6 +157,18 @@ static inline void up_registerdump(void)
#endif
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Name: up_dumpstate
****************************************************************************/
@@ -238,6 +257,12 @@ static void up_dumpstate(void)
/* Then dump the registers (if available) */
up_registerdump();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
}
#else
# define up_dumpstate()
diff --git a/nuttx/arch/mips/src/mips32/up_assert.c b/nuttx/arch/mips/src/mips32/up_assert.c
index bd59bbc2c..767393667 100644
--- a/nuttx/arch/mips/src/mips32/up_assert.c
+++ b/nuttx/arch/mips/src/mips32/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/src/mips32/up_assert.c
*
- * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "up_arch.h"
@@ -55,6 +57,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if debug is not
* selected.
@@ -115,6 +122,18 @@ static void _up_assert(int errorcode)
}
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -139,5 +158,12 @@ void up_assert(const uint8_t *filename, int lineno)
#endif
up_dumpstate();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
+
_up_assert(EXIT_FAILURE);
}
diff --git a/nuttx/arch/sh/src/common/up_assert.c b/nuttx/arch/sh/src/common/up_assert.c
index 372282804..12f177e8f 100644
--- a/nuttx/arch/sh/src/common/up_assert.c
+++ b/nuttx/arch/sh/src/common/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/sh/src/common/up_assert.c
*
- * Copyright (C) 2008-2009, 2012-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2008-2009, 2012-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,9 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
+#include <nuttx/usb/usbdev_trace.h>
#include "up_arch.h"
#include "os_internal.h"
@@ -54,6 +57,11 @@
/****************************************************************************
* Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -101,6 +109,18 @@ static void _up_assert(int errorcode)
}
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -125,5 +145,12 @@ void up_assert(const uint8_t *filename, int lineno)
#endif
up_dumpstate();
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
+
_up_assert(EXIT_FAILURE);
}
diff --git a/nuttx/arch/x86/src/common/up_assert.c b/nuttx/arch/x86/src/common/up_assert.c
index 1cb2d682f..b67db487b 100644
--- a/nuttx/arch/x86/src/common/up_assert.c
+++ b/nuttx/arch/x86/src/common/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/x86/src/common/up_assert.c
*
- * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <arch/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "up_arch.h"
@@ -56,6 +58,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -109,6 +116,18 @@ static void up_stackdump(uint32_t sp, uint32_t stack_base)
#endif
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Name: up_dumpstate
****************************************************************************/
@@ -199,7 +218,13 @@ static void up_dumpstate(void)
if (current_regs != NULL)
{
up_registerdump((uint32_t*)current_regs);
- }
+ }
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
}
#else
# define up_dumpstate()
diff --git a/nuttx/arch/z16/src/common/up_assert.c b/nuttx/arch/z16/src/common/up_assert.c
index 454df8023..bc63f9b6c 100644
--- a/nuttx/arch/z16/src/common/up_assert.c
+++ b/nuttx/arch/z16/src/common/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* common/up_assert.c
*
- * Copyright (C) 2008-2009, 2012-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2008-2009, 2012-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
+
#include <arch/board/board.h>
#include "chip/chip.h"
@@ -53,8 +55,13 @@
#include "up_internal.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -101,6 +108,18 @@ static void _up_assert(int errorcode) /* noreturn_function */
}
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -138,5 +157,12 @@ void up_assert(void)
up_stackdump();
up_registerdump();
- _up_assert(EXIT_FAILURE);
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
+
+ _up_assert(EXIT_FAILURE);
}
diff --git a/nuttx/arch/z80/src/common/up_assert.c b/nuttx/arch/z80/src/common/up_assert.c
index 317b5a05b..40907991b 100644
--- a/nuttx/arch/z80/src/common/up_assert.c
+++ b/nuttx/arch/z80/src/common/up_assert.c
@@ -1,7 +1,7 @@
/****************************************************************************
* common/up_assert.c
*
- * Copyright (C) 2007-2009, 2012-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2012-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
+#include <nuttx/usb/usbdev_trace.h>
#include "chip/chip.h"
#include "up_arch.h"
@@ -53,8 +54,13 @@
#include "up_internal.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
+/* USB trace dumping */
+
+#ifndef CONFIG_USBDEV_TRACE
+# undef CONFIG_ARCH_USBDUMP
+#endif
/* Output debug info if stack dump is selected -- even if
* debug is not selected.
@@ -101,6 +107,18 @@ static void _up_assert(int errorcode) /* noreturn_function */
}
/****************************************************************************
+ * Name: assert_tracecallback
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDUMP
+static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value);
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -138,5 +156,12 @@ void up_assert(void)
up_stackdump();
REGISTER_DUMP();
- _up_assert(EXIT_FAILURE);
+
+#ifdef CONFIG_ARCH_USBDUMP
+ /* Dump USB trace data */
+
+ (void)usbtrace_enumerate(assert_tracecallback, NULL);
+#endif
+
+ _up_assert(EXIT_FAILURE);
}