misc resource utilization fixes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3212 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2010-12-21 15:57:40 +00:00
parent 1af49ff4bd
commit 523fa94525
7 changed files with 120 additions and 74 deletions
+1 -2
View File
@@ -171,9 +171,8 @@
* *
* Configuration: * Configuration:
* CONFIG_USBHOST_OHCIRAM_SIZE 1280 * CONFIG_USBHOST_OHCIRAM_SIZE 1280
* CONFIG_USBHOST_NTDS 2
* CONFIG_USBHOST_NEDS 2 * CONFIG_USBHOST_NEDS 2
* CONFIG_USBHOST_TDBUFFERS 1 * CONFIG_USBHOST_TDBUFFERS 2
* CONFIG_USBHOST_TDBUFSIZE 128 * CONFIG_USBHOST_TDBUFSIZE 128
* CONFIG_USBHOST_IOBUFSIZE 512 * CONFIG_USBHOST_IOBUFSIZE 512
* *
+33 -8
View File
@@ -552,8 +552,16 @@ static uint8_t *lpc17_tdalloc(struct lpc17_usbhost_s *priv)
static void lpc17_tdfree(struct lpc17_usbhost_s *priv, uint8_t *buffer) static void lpc17_tdfree(struct lpc17_usbhost_s *priv, uint8_t *buffer)
{ {
struct lpc17_buflist_s *tdfree = (struct lpc17_buflist_s *)buffer; struct lpc17_buflist_s *tdfree = (struct lpc17_buflist_s *)buffer;
tdfree->flink = g_tdfree;
g_tdfree = tdfree; /* This may get called with a NULL buffer pointer on certain error handling
* paths.
*/
if (tdfree)
{
tdfree->flink = g_tdfree;
g_tdfree = tdfree;
}
} }
/******************************************************************************* /*******************************************************************************
@@ -581,7 +589,7 @@ static uint8_t *lpc17_ioalloc(struct lpc17_usbhost_s *priv)
#endif #endif
/******************************************************************************* /*******************************************************************************
* Name: lpc17_tdfree * Name: lpc17_iofree
* *
* Description: * Description:
* Return an TD buffer to the free list * Return an TD buffer to the free list
@@ -1045,7 +1053,7 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr)
if (!buffer) if (!buffer)
{ {
ret = -ENOMEM; ret = -ENOMEM;
goto errout_nobuffer; goto errout;
} }
/* USB 2.0 spec says at least 50ms delay before port reset */ /* USB 2.0 spec says at least 50ms delay before port reset */
@@ -1088,6 +1096,14 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr)
EDCTRL->ctrl = (uint32_t)(((struct usb_devdesc_s *)buffer)->mxpacketsize) << ED_CONTROL_MPS_SHIFT; EDCTRL->ctrl = (uint32_t)(((struct usb_devdesc_s *)buffer)->mxpacketsize) << ED_CONTROL_MPS_SHIFT;
/* NOTE: Additional logic is needed here. The device descriptor contains
* the class, subclass, protocol, and VID/PID. However, here we have assumed
* for the time being that class == USB_CLASS_PER_INTERFACE. This is not
* generally a good assumption and will need to get fixed someday.
*/
DEBUGASSERT(((struct usb_devdesc_s *)buffer)->class == USB_CLASS_PER_INTERFACE);
/* Set the device address to 1 */ /* Set the device address to 1 */
ctrlreq->type = USB_REQ_DIR_OUT|USB_REQ_RECIPIENT_DEVICE; ctrlreq->type = USB_REQ_DIR_OUT|USB_REQ_RECIPIENT_DEVICE;
@@ -1157,6 +1173,14 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr)
goto errout; goto errout;
} }
/* Free the TD that we were using for the request buffer. It is not needed
* further here but it may be needed by the class driver during its connection
* operations. NOTE: lpc17_tdfree() can be called with a NULL pointer later.
*/
lpc17_tdfree(priv, (uint8_t*)ctrlreq);
ctrlreq = NULL;
/* Some devices may require this delay before initialization */ /* Some devices may require this delay before initialization */
up_mdelay(100); up_mdelay(100);
@@ -1174,7 +1198,6 @@ static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr)
errout: errout:
lpc17_tdfree(priv, buffer); lpc17_tdfree(priv, buffer);
errout_nobuffer:
lpc17_tdfree(priv, (uint8_t*)ctrlreq); lpc17_tdfree(priv, (uint8_t*)ctrlreq);
return ret; return ret;
} }
@@ -1268,13 +1291,15 @@ static int lpc17_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
* Input Parameters: * Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to * drvr - The USB host driver instance obtained as a parameter from the call to
* the class create() method. * the class create() method.
* req - Describes the request to be sent. This data will be copied from the * req - Describes the request to be sent. This request must lie in memory
* user provided memory. Therefore, the req buffer may be declared on the * created by DRVR_ALLOC.
* stack.
* buffer - A buffer used for sending the request and for returning any * buffer - A buffer used for sending the request and for returning any
* responses. This buffer must be large enough to hold the length value * responses. This buffer must be large enough to hold the length value
* in the request description. buffer must have been allocated using DRVR_ALLOC * in the request description. buffer must have been allocated using DRVR_ALLOC
* *
* NOTE: On an IN transaction, req and buffer may refer to the same allocated
* memory.
*
* Returned Values: * Returned Values:
* On success, zero (OK) is returned. On a failure, a negated errno value is * On success, zero (OK) is returned. On a failure, a negated errno value is
* returned indicating the nature of the failure * returned indicating the nature of the failure
+33 -1
View File
@@ -593,7 +593,18 @@ CONFIG_USBDEV_TRACE=n
CONFIG_USBDEV_TRACE_NRECORDS=128 CONFIG_USBDEV_TRACE_NRECORDS=128
# #
# LPC17xx USB Configuration # USB Host Configuration
#
# CONFIG_USBHOST
# Enables USB host support
# CONFIG_USBHOST_NPREALLOC
# Number of pre-allocated class instances
#
CONFIG_USBHOST=n
CONFIG_USBHOST_NPREALLOC=0
#
# LPC17xx USB Device Configuration
# #
# CONFIG_LPC17_USBDEV_FRAME_INTERRUPT # CONFIG_LPC17_USBDEV_FRAME_INTERRUPT
# Handle USB Start-Of-Frame events. # Handle USB Start-Of-Frame events.
@@ -614,6 +625,27 @@ CONFIG_LPC17_USBDEV_DMA=n
CONFIG_LPC17_USBDEV_NDMADESCRIPTORS=0 CONFIG_LPC17_USBDEV_NDMADESCRIPTORS=0
CONFIG_LPC17_USBDEV_DMAINTMASK=0 CONFIG_LPC17_USBDEV_DMAINTMASK=0
#
# LPC17xx USB Host Configuration
#
# OHCI RAM layout:
# CONFIG_USBHOST_OHCIRAM_SIZE
# Total size of OHCI RAM (in AHB SRAM Bank 1)
# CONFIG_USBHOST_NEDS
# Number of endpoint descriptors
# CONFIG_USBHOST_TDBUFFERS
# Number of transfer descriptor buffers
# CONFIG_USBHOST_TDBUFSIZE
# Size of one transfer descriptor buffer
# CONFIG_USBHOST_IOBUFSIZE
# Size of one end-user I/O buffer
#
CONFIG_USBHOST_OHCIRAM_SIZE=1280
CONFIG_USBHOST_NEDS=2
CONFIG_USBHOST_TDBUFFERS=3
CONFIG_USBHOST_TDBUFSIZE=128
CONFIG_USBHOST_IOBUFSIZE=512
# #
# USB Serial Device Configuration # USB Serial Device Configuration
# #
+1 -1
View File
@@ -1763,7 +1763,7 @@ int dm9x_initialize(void)
if (vid != DM9X_DAVICOMVID || (pid != DM9X_DM9000PID && pid != DM9X_DM9010PID)) if (vid != DM9X_DAVICOMVID || (pid != DM9X_DM9000PID && pid != DM9X_DM9010PID))
{ {
nlldbg("DM90x0 vender/product ID not found at this base address\n"); nlldbg("DM90x0 vendor/product ID not found at this base address\n");
return -ENODEV; return -ENODEV;
} }
+45 -57
View File
@@ -190,8 +190,8 @@ static void usbhost_putbe32(uint8_t *dest, uint32_t val);
/* Transfer descriptor memory management */ /* Transfer descriptor memory management */
static int usbhost_tdalloc(FAR struct usbhost_state_s *priv); static inline int usbhost_tdalloc(FAR struct usbhost_state_s *priv);
static int usbhost_tdfree(FAR struct usbhost_state_s *priv); static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv);
static FAR struct usbstrg_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *priv); static FAR struct usbstrg_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *priv);
/* struct usbhost_registry_s methods */ /* struct usbhost_registry_s methods */
@@ -578,25 +578,20 @@ usbhost_writecbw(size_t startsector, uint16_t blocksize,
static inline int usbhost_maxlunreq(FAR struct usbhost_state_s *priv) static inline int usbhost_maxlunreq(FAR struct usbhost_state_s *priv)
{ {
struct usb_ctrlreq_s req; FAR struct usb_ctrlreq_s *req = (FAR struct usb_ctrlreq_s *)priv->tdbuffer;
int result; DEBUGASSERT(priv && priv->tdbuffer);
/* Make sure that we have a buffer allocated */
result = usbhost_tdalloc(priv); /* Request maximum logical unit number. NOTE: On an IN transaction, The
if (result == OK) * req and buffer pointers passed to DRVR_CTRLIN may refer to the same
{ * allocated memory.
/* Request maximum logical unit number */ */
uvdbg("Request maximum logical unit number\n"); uvdbg("Request maximum logical unit number\n");
memset(&req, 0, sizeof(struct usb_ctrlreq_s)); memset(req, 0, sizeof(struct usb_ctrlreq_s));
req.type = USB_DIR_IN|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE; req->type = USB_DIR_IN|USB_REQ_TYPE_CLASS|USB_REQ_RECIPIENT_INTERFACE;
req.req = USBSTRG_REQ_GETMAXLUN; req->req = USBSTRG_REQ_GETMAXLUN;
usbhost_putle16(req.len, 1); usbhost_putle16(req->len, 1);
return DRVR_CTRLIN(priv->drvr, req, priv->tdbuffer);
result = DRVR_CTRLIN(priv->drvr, &req, priv->tdbuffer);
}
return result;
} }
static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv) static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv)
@@ -604,7 +599,7 @@ static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv)
FAR struct usbstrg_cbw_s *cbw; FAR struct usbstrg_cbw_s *cbw;
int result = -ENOMEM; int result = -ENOMEM;
/* Initialize a CBW (allocating it if necessary) */ /* Initialize a CBW (re-using the allocated transfer buffer) */
cbw = usbhost_cbwalloc(priv); cbw = usbhost_cbwalloc(priv);
if (cbw) if (cbw)
@@ -630,7 +625,7 @@ static inline int usbhost_requestsense(FAR struct usbhost_state_s *priv)
FAR struct usbstrg_cbw_s *cbw; FAR struct usbstrg_cbw_s *cbw;
int result = -ENOMEM; int result = -ENOMEM;
/* Initialize a CBW (allocating it if necessary) */ /* Initialize a CBW (re-using the allocated transfer buffer) */
cbw = usbhost_cbwalloc(priv); cbw = usbhost_cbwalloc(priv);
if (cbw) if (cbw)
@@ -664,7 +659,7 @@ static inline int usbhost_readcapacity(FAR struct usbhost_state_s *priv)
FAR struct scsiresp_readcapacity10_s *resp; FAR struct scsiresp_readcapacity10_s *resp;
int result = -ENOMEM; int result = -ENOMEM;
/* Initialize a CBW (allocating it if necessary) */ /* Initialize a CBW (re-using the allocated transfer buffer) */
cbw = usbhost_cbwalloc(priv); cbw = usbhost_cbwalloc(priv);
if (cbw) if (cbw)
@@ -704,7 +699,7 @@ static inline int usbhost_inquiry(FAR struct usbhost_state_s *priv)
FAR struct scsiresp_inquiry_s *resp; FAR struct scsiresp_inquiry_s *resp;
int result = -ENOMEM; int result = -ENOMEM;
/* Initialize a CBW (allocating it if necessary) */ /* Initialize a CBW (re-using the allocated transfer buffer) */
cbw = usbhost_cbwalloc(priv); cbw = usbhost_cbwalloc(priv);
if (cbw) if (cbw)
@@ -812,6 +807,15 @@ static void usbhost_initvolume(FAR void *arg)
DEBUGASSERT(priv != NULL); DEBUGASSERT(priv != NULL);
/* Set aside a transfer buffer for exclusive use by the mass storage driver */
result = usbhost_tdalloc(priv);
if (result != OK)
{
udbg("Failed to allocate transfer buffer\n");
return;
}
/* Request the maximum logical unit number */ /* Request the maximum logical unit number */
uvdbg("Get max LUN\n"); uvdbg("Get max LUN\n");
@@ -1120,17 +1124,10 @@ static void usbhost_putbe32(uint8_t *dest, uint32_t val)
* *
****************************************************************************/ ****************************************************************************/
static int usbhost_tdalloc(FAR struct usbhost_state_s *priv) static inline int usbhost_tdalloc(FAR struct usbhost_state_s *priv)
{ {
int result = OK; DEBUGASSERT(priv && priv->tdbuffer == NULL);
return DRVR_ALLOC(priv->drvr, &priv->tdbuffer, &priv->tdbuflen);
/* Is a descriptor already allocated? */
if (!priv->tdbuffer)
{
result = DRVR_ALLOC(priv->drvr, &priv->tdbuffer, &priv->tdbuflen);
}
return result;
} }
/**************************************************************************** /****************************************************************************
@@ -1148,18 +1145,14 @@ static int usbhost_tdalloc(FAR struct usbhost_state_s *priv)
* *
****************************************************************************/ ****************************************************************************/
static int usbhost_tdfree(FAR struct usbhost_state_s *priv) static inline int usbhost_tdfree(FAR struct usbhost_state_s *priv)
{ {
int result = OK; int result;
DEBUGASSERT(priv && priv->tdbuffer != NULL);
/* Is a descriptor already allocated? */ result = DRVR_FREE(priv->drvr, priv->tdbuffer);
priv->tdbuffer = NULL;
if (!priv->tdbuffer) priv->tdbuflen = 0;
{
result = DRVR_FREE(priv->drvr, priv->tdbuffer);
priv->tdbuffer = NULL;
priv->tdbuflen = 0;
}
return result; return result;
} }
@@ -1167,8 +1160,8 @@ static int usbhost_tdfree(FAR struct usbhost_state_s *priv)
* Name: usbhost_cbwalloc * Name: usbhost_cbwalloc
* *
* Description: * Description:
* Allocate and initialize a CBW. Upon successful return, the CBW is cleared * Initialize a CBW (re-using the allocated transfer buffer). Upon
* and has the CBW signature in place. * successful return, the CBW is cleared and has the CBW signature in place.
* *
* Input Parameters: * Input Parameters:
* priv - A reference to the class instance. * priv - A reference to the class instance.
@@ -1181,19 +1174,14 @@ static int usbhost_tdfree(FAR struct usbhost_state_s *priv)
static FAR struct usbstrg_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *priv) static FAR struct usbstrg_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *priv)
{ {
FAR struct usbstrg_cbw_s *cbw = NULL; FAR struct usbstrg_cbw_s *cbw = NULL;
int result;
/* Allocate any special memory that the the driver may have for us */ DEBUGASSERT(priv->tdbuffer && priv->tdbuflen >= sizeof(struct usbstrg_cbw_s))
result = usbhost_tdalloc(priv); /* Intialize the CBW sructure */
if (result == OK && priv->tdbuflen >= sizeof(struct usbstrg_cbw_s))
{
/* Intialize the CBW sructure */
cbw = (FAR struct usbstrg_cbw_s *)priv->tdbuffer; cbw = (FAR struct usbstrg_cbw_s *)priv->tdbuffer;
memset(cbw, 0, sizeof(struct usbstrg_cbw_s)); memset(cbw, 0, sizeof(struct usbstrg_cbw_s));
usbhost_putle32(cbw->signature, USBSTRG_CBW_SIGNATURE); usbhost_putle32(cbw->signature, USBSTRG_CBW_SIGNATURE);
}
return cbw; return cbw;
} }
@@ -1635,7 +1623,7 @@ static ssize_t usbhost_read(FAR struct inode *inode, unsigned char *buffer,
ret = -ENOMEM; ret = -ENOMEM;
/* Initialize a CBW (allocating it if necessary) */ /* Initialize a CBW (re-using the allocated transfer buffer) */
cbw = usbhost_cbwalloc(priv); cbw = usbhost_cbwalloc(priv);
if (cbw) if (cbw)
@@ -1727,7 +1715,7 @@ static ssize_t usbhost_write(FAR struct inode *inode, const unsigned char *buffe
ret = -ENOMEM; ret = -ENOMEM;
/* Initialize a CBW (allocating it if necessary) */ /* Initialize a CBW (re-using the allocated transfer buffer) */
cbw = usbhost_cbwalloc(priv); cbw = usbhost_cbwalloc(priv);
if (cbw) if (cbw)
+1 -1
View File
@@ -230,7 +230,7 @@ struct usb_devdesc_s
uint8_t subclass; /* Device sub-class */ uint8_t subclass; /* Device sub-class */
uint8_t protocol; /* Device protocol */ uint8_t protocol; /* Device protocol */
uint8_t mxpacketsize; /* Max packet size (ep0) */ uint8_t mxpacketsize; /* Max packet size (ep0) */
uint8_t vender[2]; /* Vendor ID */ uint8_t vendor[2]; /* Vendor ID */
uint8_t product[2]; /* Product ID */ uint8_t product[2]; /* Product ID */
uint8_t device[2]; /* Device ID */ uint8_t device[2]; /* Device ID */
uint8_t imfgr; /* Manufacturer */ uint8_t imfgr; /* Manufacturer */
+6 -4
View File
@@ -263,12 +263,14 @@
* Input Parameters: * Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to * drvr - The USB host driver instance obtained as a parameter from the call to
* the class create() method. * the class create() method.
* req - Describes the request to be sent. This data will be copied from the * req - Describes the request to be sent. This request must lie in memory
* user provided memory. Therefore, the req buffer may be declared on the * created by DRVR_ALLOC.
* stack.
* buffer - A buffer used for sending the request and for returning any * buffer - A buffer used for sending the request and for returning any
* responses. This buffer must be large enough to hold the length value * responses. This buffer must be large enough to hold the length value
* in the request description. buffer must have been allocated using DRVR_ALLOC * in the request description. buffer must have been allocated using DRVR_ALLOC.
*
* NOTE: On an IN transaction, req and buffer may refer to the same allocated
* memory.
* *
* Returned Values: * Returned Values:
* On success, zero (OK) is returned. On a failure, a negated errno value is * On success, zero (OK) is returned. On a failure, a negated errno value is