diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-12-21 11:44:51 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-12-21 11:44:51 +0000 |
commit | ab9b589790ef288009ca0b6c16f8a341e42b1c30 (patch) | |
tree | aec33f4d8f824c5bc60a4a57dbca71d7b256fdad /nuttx/arch/arm | |
parent | e276f17ab5f7c64e50bbf4bf88fd17d8718096e3 (diff) | |
download | px4-nuttx-ab9b589790ef288009ca0b6c16f8a341e42b1c30.tar.gz px4-nuttx-ab9b589790ef288009ca0b6c16f8a341e42b1c30.tar.bz2 px4-nuttx-ab9b589790ef288009ca0b6c16f8a341e42b1c30.zip |
Correct some initialization sequence issues
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3208 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm')
-rwxr-xr-x | nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h | 37 | ||||
-rwxr-xr-x | nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c | 58 |
2 files changed, 52 insertions, 43 deletions
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h b/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h index 5607e35d6..eb159785d 100755 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h @@ -132,11 +132,11 @@ /* Configurable number of descriptor buffer (TDBUFFER) */
#ifndef CONFIG_USBHOST_TDBUFFERS
-# define CONFIG_USBHOST_TDBUFFERS 1
+# define CONFIG_USBHOST_TDBUFFERS 2
#endif
-#if CONFIG_USBHOST_TDBUFFERS < 1
-# error "At least one TD buffer is required"
+#if CONFIG_USBHOST_TDBUFFERS < 2
+# error "At least two TD buffers are required"
#endif
/* Configurable size of a TD buffer */
@@ -170,36 +170,35 @@ * LPC17_BANK1_SIZE 16384
*
* Configuration:
- * CONFIG_USBHOST_OHCIRAM_SIZE 1024
- * CONFIG_USBHOST_NTDS 1
+ * CONFIG_USBHOST_OHCIRAM_SIZE 1280
+ * CONFIG_USBHOST_NTDS 2
* CONFIG_USBHOST_NEDS 2
* CONFIG_USBHOST_TDBUFFERS 1
* CONFIG_USBHOST_TDBUFSIZE 128
* CONFIG_USBHOST_IOBUFSIZE 512
*
* Sizes of things
- * CONFIG_USBHOST_NEDS 2
* LPC17_EDFREE_SIZE 48
- * LPC17_TDFREE_SIZE 128
+ * LPC17_TDFREE_SIZE 256
* LPC17_IOFREE_SIZE 512
*
* Memory Layout
* LPC17_OHCIRAM_END (0x20008000 + 16384) = 0x2000c000
- * LPC17_OHCIRAM_BASE (0x2000c000 - 1024) = 0x2000bc00
- * LPC17_OHCIRAM_SIZE 1024
+ * LPC17_OHCIRAM_BASE (0x2000c000 - 1280) = 0x2000bb00
+ * LPC17_OHCIRAM_SIZE 1280
* LPC17_BANK1_HEAPBASE 0x20008000
- * LPC17_BANK1_HEAPSIZE (16384 - 1024) = 15360
+ * LPC17_BANK1_HEAPSIZE (16384 - 1280) = 15104
*
- * LPC17_HCCA_BASE 0x2000bc00
- * LPC17_TDHEAD_ADDR 0x2000bd00
- * LPC17_TDTAIL_ADDR 0x2000bd10
- * LPC17_EDCTRL_ADDR 0x2000bd20
- * LPC17_EDFREE_BASE 0x2000bd30
- * LPC17_TDFREE_BASE 0x2000bd50
- * LPC17_IOFREE_BASE 0x2000bdd0
- * LPC17_IOBUFFERS (0x2000c000 + 0x2000bdd0) / 512 = 560/512 = 1
+ * LPC17_HCCA_BASE 0x2000bb00
+ * LPC17_TDHEAD_ADDR 0x2000bc00
+ * LPC17_TDTAIL_ADDR 0x2000bc10
+ * LPC17_EDCTRL_ADDR 0x2000bc20
+ * LPC17_EDFREE_BASE 0x2000bc30
+ * LPC17_TDFREE_BASE 0x2000bc50
+ * LPC17_IOFREE_BASE 0x2000bd50
+ * LPC17_IOBUFFERS (0x2000c000 - 0x2000bd50) / 512 = 688/512 = 1
*
- * Wasted memory: 560-512 = 48 bytes
+ * Wasted memory: 688-512 = 176 bytes
*/
#define LPC17_HCCA_BASE (LPC17_OHCIRAM_BASE)
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c b/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c index d739f9c2e..6e47753c6 100755 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c @@ -1014,7 +1014,7 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr) struct lpc17_usbhost_s *priv = (struct lpc17_usbhost_s *)drvr; struct usb_ctrlreq_s *ctrlreq; unsigned int len; - uint8_t *td; + uint8_t *buffer; int ret; /* Are we connected to a device? The caller should have called the wait() @@ -1029,14 +1029,22 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr) } ulldbg("Enumerate the device\n"); - /* Allocate a TD buffer for use in this function */ + /* Allocate TD buffers for use in this function. We will need two: + * One for the request and one for the data buffer. + */ - td = lpc17_tdalloc(priv); - if (!td) + ctrlreq = (struct usb_ctrlreq_s *)lpc17_tdalloc(priv); + if (!ctrlreq) { return -ENOMEM; } - ctrlreq = (struct usb_ctrlreq_s *)td; + + buffer = lpc17_tdalloc(priv); + if (!buffer) + { + ret = -ENOMEM; + goto errout_nobuffer; + } /* USB 2.0 spec says at least 50ms delay before port reset */ @@ -1067,7 +1075,7 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr) lpc17_putle16(ctrlreq->index, 0); lpc17_putle16(ctrlreq->len, 8); - ret = lpc17_ctrlin(drvr, ctrlreq, td); + ret = lpc17_ctrlin(drvr, ctrlreq, buffer); if (ret != OK) { ulldbg("ERROR: lpc17_ctrlin returned %d\n", ret); @@ -1076,7 +1084,7 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr) /* Extract the max packetsize for endpoint 0 */ - EDCTRL->ctrl = (uint32_t)(((struct usb_devdesc_s *)td)->mxpacketsize) << ED_CONTROL_MPS_SHIFT; + EDCTRL->ctrl = (uint32_t)(((struct usb_devdesc_s *)buffer)->mxpacketsize) << ED_CONTROL_MPS_SHIFT; /* Set the device address to 1 */ @@ -1106,7 +1114,7 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr) lpc17_putle16(ctrlreq->index, 0); lpc17_putle16(ctrlreq->len, USB_SIZEOF_CFGDESC); - ret = lpc17_ctrlin(drvr, ctrlreq, td); + ret = lpc17_ctrlin(drvr, ctrlreq, buffer); if (ret != OK) { ulldbg("ERROR: lpc17_ctrlin returned %d\n", ret); @@ -1115,7 +1123,7 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr) /* Extract the full size of the configuration data */ - len = ((struct usb_cfgdesc_s *)td)->len; + len = ((struct usb_cfgdesc_s *)buffer)->len; /* Get all of the configuration data */ @@ -1125,24 +1133,13 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr) lpc17_putle16(ctrlreq->index, 0); lpc17_putle16(ctrlreq->len, len); - ret = lpc17_ctrlin(drvr, ctrlreq, td); + ret = lpc17_ctrlin(drvr, ctrlreq, buffer); if (ret != OK) { ulldbg("ERROR: lpc17_ctrlin returned %d\n", ret); goto errout; } - /* Parse the configuration descriptor and bind to the class instance for the - * device. - */ - - ret = lpc17_classbind(priv, td, len); - if (ret != OK) - { - ulldbg("ERROR: MS_ParseConfiguration returned %d\n", ret); - goto errout; - } - /* Select device configuration 1 */ ctrlreq->type = USB_REQ_DIR_OUT|USB_REQ_RECIPIENT_DEVICE; @@ -1154,16 +1151,29 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr) ret = lpc17_ctrlout(drvr, ctrlreq, NULL); if (ret != OK) { - ulldbg("ERROR: lpc17_ctrlout returned %d\n", ret); + ulldbg("ERROR: uint16 returned %d\n", ret); goto errout; } - /* Some devices may require this delay */ + /* Some devices may require this delay before initialization */ up_mdelay(100); + /* Parse the configuration descriptor and bind to the class instance for the + * device. This needs to be the last thing done because the class driver + * will begin configuring the device. + */ + + ret = lpc17_classbind(priv, buffer, len); + if (ret != OK) + { + ulldbg("ERROR: MS_ParseConfiguration returned %d\n", ret); + } + errout: - lpc17_tdfree(priv, td); + lpc17_tdfree(priv, buffer); +errout_nobuffer: + lpc17_tdfree(priv, (uint8_t*)ctrlreq); return ret; } |