summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-08-06 02:41:59 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-08-06 02:41:59 +0000
commit958240f1221c7457a12a55223c0e59295ee309c2 (patch)
tree990dbd18af84e3522fd05a90632e0b705f03c627 /nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c
parent805d4ee67e550bdcbacc91bc02089071fa727f34 (diff)
downloadpx4-nuttx-958240f1221c7457a12a55223c0e59295ee309c2.tar.gz
px4-nuttx-958240f1221c7457a12a55223c0e59295ee309c2.tar.bz2
px4-nuttx-958240f1221c7457a12a55223c0e59295ee309c2.zip
lpc17xxx USB debug
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2823 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c')
-rwxr-xr-xnuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c145
1 files changed, 98 insertions, 47 deletions
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c b/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c
index f7094755d..c5389813a 100755
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c
@@ -86,12 +86,6 @@
# define USB_FAST_INT 0
#endif
-/* Extremely detailed register debug that you would normally never want
- * enabled.
- */
-
-#undef CONFIG_LPC17_USBDEV_REGDEBUG
-
/* Enable reading SOF from interrupt handler vs. simply reading on demand. Probably
* a bad idea... Unless there is some issue with sampling the SOF from hardware
* asynchronously.
@@ -106,9 +100,23 @@
#ifdef CONFIG_DEBUG
# define USB_ERROR_INT USBDEV_INT_ERRINT
#else
+# undef CONFIG_LPC17_USBDEV_REGDEBUG
# define USB_ERROR_INT 0
#endif
+/* Dump GPIO registers */
+
+#if defined(CONFIG_LPC17_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_GPIO)
+# define usbdev_dumpgpio() \
+ do { \
+ lpc17_dumpgpio(GPIO_USB_DP, "D+ P0.29; D- P0.30"); \
+ lpc17_dumpgpio(GPIO_USB_VBUS, "LED P1:18; VBUS P1:30"); \
+ lpc17_dumpgpio(GPIO_USB_CONNECT, "CONNECT P2:9"); \
+ } while (0);
+#else
+# define usbdev_dumpgpio()
+#endif
+
/* Number of DMA descriptors */
#ifdef CONFIG_LPC17_USBDEV_DMA
@@ -356,7 +364,9 @@ struct lpc17_usbdev_s
/* Register operations ********************************************************/
-#if defined(CONFIG_LPC17_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG)
+#ifdef CONFIG_LPC17_USBDEV_REGDEBUG
+static void lpc17_printreg(uint32_t addr, uint32_t val, bool iswrite);
+static void lpc17_checkreg(uint32_t addr, uint32_t val, bool iswrite);
static uint32_t lpc17_getreg(uint32_t addr);
static void lpc17_putreg(uint32_t val, uint32_t addr);
#else
@@ -505,63 +515,102 @@ static struct lpc17_dmadesc_s g_usbddesc[CONFIG_LPC17_USBDEV_NDMADESCRIPTORS];
*******************************************************************************/
/*******************************************************************************
- * Name: lpc17_getreg
+ * Name: lpc17_printreg
+ *
+ * Description:
+ * Print the contents of an LPC17xx register operation
+ *
+ *******************************************************************************/
+
+#ifdef CONFIG_LPC17_USBDEV_REGDEBUG
+static void lpc17_printreg(uint32_t addr, uint32_t val, bool iswrite)
+{
+ lldbg("%08x%s%08x\n", addr, iswrite ? "<-" : "->", val);
+}
+#endif
+
+/*******************************************************************************
+ * Name: lpc17_checkreg
*
* Description:
* Get the contents of an LPC17xx register
*
*******************************************************************************/
-#if defined(CONFIG_LPC17_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG)
-static uint32_t lpc17_getreg(uint32_t addr)
+#ifdef CONFIG_LPC17_USBDEV_REGDEBUG
+static void lpc17_checkreg(uint32_t addr, uint32_t val, bool iswrite)
{
static uint32_t prevaddr = 0;
static uint32_t preval = 0;
static uint32_t count = 0;
+ static bool prevwrite = false;
- /* Read the value from the register */
-
- uint32_t val = getreg32(addr);
-
- /* Is this the same value that we read from the same registe last time? Are
- * we polling the register? If so, suppress some of the output.
+ /* Is this the same value that we read from/wrote to the same register last time?
+ * Are we polling the register? If so, suppress the output.
*/
- if (addr == prevaddr && val == preval)
+ if (addr == prevaddr && val == preval && prevwrite == iswrite)
{
- if (count == 0xffffffff || ++count > 3)
- {
- if (count == 4)
- {
- lldbg("...\n");
- }
- return val;
- }
- }
-
- /* No this is a new address or value */
+ /* Yes.. Just increment the count */
+ count++;
+ }
else
{
- /* Did we print "..." for the previous value? */
+ /* No this is a new address or value or operation. Were there any
+ * duplicate accesses before this one?
+ */
- if (count > 3)
- {
- /* Yes.. then show how many times the value repeated */
+ if (count > 0)
+ {
+ /* Yes.. Just one? */
+
+ if (count == 1)
+ {
+ /* Yes.. Just one */
+
+ lpc17_printreg(prevaddr, preval, prevwrite);
+ }
+ else
+ {
+ /* No.. More than one. */
- lldbg("[repeats %d more times]\n", count-3);
- }
+ lldbg("[repeats %d more times]\n", count);
+ }
+ }
+
+ /* Save the new address, value, count, and operation for next time */
+
+ prevaddr = addr;
+ preval = val;
+ count = 0;
+ prevwrite = iswrite;
- /* Save the new address, value, and count */
+ /* Show the new regisgter access */
- prevaddr = addr;
- preval = val;
- count = 1;
+ lpc17_printreg(addr, val, iswrite);
}
+}
+#endif
+
+/*******************************************************************************
+ * Name: lpc17_getreg
+ *
+ * Description:
+ * Get the contents of an LPC17xx register
+ *
+ *******************************************************************************/
- /* Show the register value read */
+#ifdef CONFIG_LPC17_USBDEV_REGDEBUG
+static uint32_t lpc17_getreg(uint32_t addr)
+{
+ /* Read the value from the register */
- lldbg("%08x->%08x\n", addr, val);
+ uint32_t val = getreg32(addr);
+
+ /* Check if we need to print this value */
+
+ lpc17_checkreg(addr, val, false);
return val;
}
#endif
@@ -574,12 +623,12 @@ static uint32_t lpc17_getreg(uint32_t addr)
*
*******************************************************************************/
-#if defined(CONFIG_LPC17_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG)
+#ifdef CONFIG_LPC17_USBDEV_REGDEBUG
static void lpc17_putreg(uint32_t val, uint32_t addr)
{
- /* Show the register value being written */
+ /* Check if we need to print this value */
- lldbg("%08x<-%08x\n", addr, val);
+ lpc17_checkreg(addr, val, true);
/* Write the value */
@@ -1394,7 +1443,7 @@ static void lpc17_usbreset(struct lpc17_usbdev_s *priv)
/* Frame is Hp interrupt */
- lpc17_putreg(1, LPC17_USBDEV_INTPRI);
+ lpc17_putreg(USBDEV_INT_FRAME, LPC17_USBDEV_INTPRI);
/* Clear all pending interrupts */
@@ -1425,7 +1474,7 @@ static void lpc17_usbreset(struct lpc17_usbdev_s *priv)
/* Enable Device interrupts */
lpc17_putreg(USB_SLOW_INT|USB_DEVSTATUS_INT|USB_FAST_INT|USB_FRAME_INT|USB_ERROR_INT,
- LPC17_USBDEV_INTEN);
+ LPC17_USBDEV_INTEN);
}
/*******************************************************************************
@@ -3086,9 +3135,9 @@ void up_usbinitialize(void)
/* Step 1: Enable power by setting PCUSB in the PCONP register */
flags = irqsave();
- regval = getreg32(LPC17_SYSCON_PCONP);
+ regval = lpc17_getreg(LPC17_SYSCON_PCONP);
regval |= SYSCON_PCONP_PCUSB;
- putreg32(regval, LPC17_SYSCON_PCONP);
+ lpc17_putreg(regval, LPC17_SYSCON_PCONP);
/* Step 2: Enable clocking on USB (USB clocking was initialized in very
* low-level clock setup logic (see lpc17_clockconfig.c)
@@ -3096,11 +3145,13 @@ void up_usbinitialize(void)
/* Step 3: Configure I/O pins */
+ usbdev_dumpgpio();
lpc17_configgpio(GPIO_USB_VBUS); /* VBUS status input */
lpc17_configgpio(GPIO_USB_CONNECT); /* SoftConnect control signal */
lpc17_configgpio(GPIO_USB_UPLED); /* GoodLink LED control signal */
lpc17_configgpio(GPIO_USB_DP); /* Positive differential data */
lpc17_configgpio(GPIO_USB_DM); /* Negative differential data */
+ usbdev_dumpgpio();
/* Disable USB interrupts */