Correct some initialization sequence issues
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3208 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
ec80cc2e27
commit
30f1331d9d
@ -132,11 +132,11 @@
|
|||||||
/* Configurable number of descriptor buffer (TDBUFFER) */
|
/* Configurable number of descriptor buffer (TDBUFFER) */
|
||||||
|
|
||||||
#ifndef CONFIG_USBHOST_TDBUFFERS
|
#ifndef CONFIG_USBHOST_TDBUFFERS
|
||||||
# define CONFIG_USBHOST_TDBUFFERS 1
|
# define CONFIG_USBHOST_TDBUFFERS 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_USBHOST_TDBUFFERS < 1
|
#if CONFIG_USBHOST_TDBUFFERS < 2
|
||||||
# error "At least one TD buffer is required"
|
# error "At least two TD buffers are required"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Configurable size of a TD buffer */
|
/* Configurable size of a TD buffer */
|
||||||
@ -170,36 +170,35 @@
|
|||||||
* LPC17_BANK1_SIZE 16384
|
* LPC17_BANK1_SIZE 16384
|
||||||
*
|
*
|
||||||
* Configuration:
|
* Configuration:
|
||||||
* CONFIG_USBHOST_OHCIRAM_SIZE 1024
|
* CONFIG_USBHOST_OHCIRAM_SIZE 1280
|
||||||
* CONFIG_USBHOST_NTDS 1
|
* CONFIG_USBHOST_NTDS 2
|
||||||
* CONFIG_USBHOST_NEDS 2
|
* CONFIG_USBHOST_NEDS 2
|
||||||
* CONFIG_USBHOST_TDBUFFERS 1
|
* CONFIG_USBHOST_TDBUFFERS 1
|
||||||
* CONFIG_USBHOST_TDBUFSIZE 128
|
* CONFIG_USBHOST_TDBUFSIZE 128
|
||||||
* CONFIG_USBHOST_IOBUFSIZE 512
|
* CONFIG_USBHOST_IOBUFSIZE 512
|
||||||
*
|
*
|
||||||
* Sizes of things
|
* Sizes of things
|
||||||
* CONFIG_USBHOST_NEDS 2
|
|
||||||
* LPC17_EDFREE_SIZE 48
|
* LPC17_EDFREE_SIZE 48
|
||||||
* LPC17_TDFREE_SIZE 128
|
* LPC17_TDFREE_SIZE 256
|
||||||
* LPC17_IOFREE_SIZE 512
|
* LPC17_IOFREE_SIZE 512
|
||||||
*
|
*
|
||||||
* Memory Layout
|
* Memory Layout
|
||||||
* LPC17_OHCIRAM_END (0x20008000 + 16384) = 0x2000c000
|
* LPC17_OHCIRAM_END (0x20008000 + 16384) = 0x2000c000
|
||||||
* LPC17_OHCIRAM_BASE (0x2000c000 - 1024) = 0x2000bc00
|
* LPC17_OHCIRAM_BASE (0x2000c000 - 1280) = 0x2000bb00
|
||||||
* LPC17_OHCIRAM_SIZE 1024
|
* LPC17_OHCIRAM_SIZE 1280
|
||||||
* LPC17_BANK1_HEAPBASE 0x20008000
|
* LPC17_BANK1_HEAPBASE 0x20008000
|
||||||
* LPC17_BANK1_HEAPSIZE (16384 - 1024) = 15360
|
* LPC17_BANK1_HEAPSIZE (16384 - 1280) = 15104
|
||||||
*
|
*
|
||||||
* LPC17_HCCA_BASE 0x2000bc00
|
* LPC17_HCCA_BASE 0x2000bb00
|
||||||
* LPC17_TDHEAD_ADDR 0x2000bd00
|
* LPC17_TDHEAD_ADDR 0x2000bc00
|
||||||
* LPC17_TDTAIL_ADDR 0x2000bd10
|
* LPC17_TDTAIL_ADDR 0x2000bc10
|
||||||
* LPC17_EDCTRL_ADDR 0x2000bd20
|
* LPC17_EDCTRL_ADDR 0x2000bc20
|
||||||
* LPC17_EDFREE_BASE 0x2000bd30
|
* LPC17_EDFREE_BASE 0x2000bc30
|
||||||
* LPC17_TDFREE_BASE 0x2000bd50
|
* LPC17_TDFREE_BASE 0x2000bc50
|
||||||
* LPC17_IOFREE_BASE 0x2000bdd0
|
* LPC17_IOFREE_BASE 0x2000bd50
|
||||||
* LPC17_IOBUFFERS (0x2000c000 + 0x2000bdd0) / 512 = 560/512 = 1
|
* 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)
|
#define LPC17_HCCA_BASE (LPC17_OHCIRAM_BASE)
|
||||||
|
@ -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 lpc17_usbhost_s *priv = (struct lpc17_usbhost_s *)drvr;
|
||||||
struct usb_ctrlreq_s *ctrlreq;
|
struct usb_ctrlreq_s *ctrlreq;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
uint8_t *td;
|
uint8_t *buffer;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Are we connected to a device? The caller should have called the wait()
|
/* 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");
|
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);
|
ctrlreq = (struct usb_ctrlreq_s *)lpc17_tdalloc(priv);
|
||||||
if (!td)
|
if (!ctrlreq)
|
||||||
{
|
{
|
||||||
return -ENOMEM;
|
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 */
|
/* 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->index, 0);
|
||||||
lpc17_putle16(ctrlreq->len, 8);
|
lpc17_putle16(ctrlreq->len, 8);
|
||||||
|
|
||||||
ret = lpc17_ctrlin(drvr, ctrlreq, td);
|
ret = lpc17_ctrlin(drvr, ctrlreq, buffer);
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
{
|
{
|
||||||
ulldbg("ERROR: lpc17_ctrlin returned %d\n", ret);
|
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 */
|
/* 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 */
|
/* 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->index, 0);
|
||||||
lpc17_putle16(ctrlreq->len, USB_SIZEOF_CFGDESC);
|
lpc17_putle16(ctrlreq->len, USB_SIZEOF_CFGDESC);
|
||||||
|
|
||||||
ret = lpc17_ctrlin(drvr, ctrlreq, td);
|
ret = lpc17_ctrlin(drvr, ctrlreq, buffer);
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
{
|
{
|
||||||
ulldbg("ERROR: lpc17_ctrlin returned %d\n", ret);
|
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 */
|
/* 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 */
|
/* 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->index, 0);
|
||||||
lpc17_putle16(ctrlreq->len, len);
|
lpc17_putle16(ctrlreq->len, len);
|
||||||
|
|
||||||
ret = lpc17_ctrlin(drvr, ctrlreq, td);
|
ret = lpc17_ctrlin(drvr, ctrlreq, buffer);
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
{
|
{
|
||||||
ulldbg("ERROR: lpc17_ctrlin returned %d\n", ret);
|
ulldbg("ERROR: lpc17_ctrlin returned %d\n", ret);
|
||||||
goto errout;
|
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 */
|
/* Select device configuration 1 */
|
||||||
|
|
||||||
ctrlreq->type = USB_REQ_DIR_OUT|USB_REQ_RECIPIENT_DEVICE;
|
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);
|
ret = lpc17_ctrlout(drvr, ctrlreq, NULL);
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
{
|
{
|
||||||
ulldbg("ERROR: lpc17_ctrlout returned %d\n", ret);
|
ulldbg("ERROR: uint16 returned %d\n", ret);
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Some devices may require this delay */
|
/* Some devices may require this delay before initialization */
|
||||||
|
|
||||||
up_mdelay(100);
|
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:
|
errout:
|
||||||
lpc17_tdfree(priv, td);
|
lpc17_tdfree(priv, buffer);
|
||||||
|
errout_nobuffer:
|
||||||
|
lpc17_tdfree(priv, (uint8_t*)ctrlreq);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user