Several more bug fixes for STM32 OTG FS host driver

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5044 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-08-21 20:14:42 +00:00
parent eefe1c3d02
commit 4b07f8fb49
2 changed files with 35 additions and 15 deletions

View File

@ -1,9 +1,9 @@
/*******************************************************************************
* arch/arm/src/lpc17xx/lpc17_usbhost.c
*
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2010-2012 Gregory Nutt. All rights reserved.
* Authors: Rafael Noronha <rafael@pdsolucoes.com.br>
* Gregory Nutt <spudmonkey@racsa.co.cr>
* Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -1898,7 +1898,7 @@ static int lpc17_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
* Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc.
* such "special" memory, this functions may simply map to kmalloc.
*
* This interface was optimized under a particular assumption. It was assumed
* that the driver maintains a pool of small, pre-allocated buffers for descriptor
@ -1952,7 +1952,7 @@ static int lpc17_alloc(FAR struct usbhost_driver_s *drvr,
* Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to free that
* request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to free().
* such "special" memory, this functions may simply map to kfree().
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
@ -1988,7 +1988,7 @@ static int lpc17_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
* Some hardware supports special memory in which larger IO buffers can
* be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc.
* such "special" memory, this functions may simply map to kmalloc.
*
* This interface differs from DRVR_ALLOC in that the buffers are variable-sized.
*
@ -2036,7 +2036,7 @@ static int lpc17_ioalloc(FAR struct usbhost_driver_s *drvr,
* Some hardware supports special memory in which IO data can be accessed more
* efficiently. This method provides a mechanism to free that IO buffer
* memory. If the underlying hardware does not support such "special" memory,
* this functions may simply map to free().
* this functions may simply map to kfree().
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to

View File

@ -49,6 +49,7 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <nuttx/usb/usb.h>
#include <nuttx/usb/usbhost.h>
@ -89,6 +90,8 @@
* want to do that?
* CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access
* debug. Depends on CONFIG_DEBUG.
* CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
* packets. Depends on CONFIG_DEBUG.
*/
/* Pre-requistites (partial) */
@ -119,6 +122,7 @@
#ifndef CONFIG_DEBUG
# undef CONFIG_STM32_USBHOST_REGDEBUG
# undef CONFIG_STM32_USBHOST_PKTDUMP
#endif
/* HCD Setup *******************************************************************/
@ -253,6 +257,12 @@ static void stm32_putreg(uint32_t addr, uint32_t value);
static inline void stm32_modifyreg(uint32_t addr, uint32_t clrbits,
uint32_t setbits);
#ifdef CONFIG_STM32_USBHOST_PKTDUMP
# define stm32_pktdump(m,b,n) lib_dumpbuffer(m,b,n)
#else
# define stm32_pktdump(m,b,n)
#endif
/* Semaphores ******************************************************************/
static void stm32_takesem(sem_t *sem);
@ -1298,6 +1308,8 @@ static void stm32_gint_wrpacket(FAR struct stm32_usbhost_s *priv,
uint32_t fifo;
int buflen32;
stm32_pktdump("Sending", buffer, buflen);
/* Get the number of 32-byte words associated with this byte size */
buflen32 = (buflen + 3) >> 2;
@ -1958,6 +1970,8 @@ static inline void stm32_gint_rxflvlisr(FAR struct stm32_usbhost_s *priv)
*dest++ = stm32_getreg(fifo);
}
stm32_pktdump("Received", priv->chan[chidx].buffer, bcnt);
/* Manage multiple packet transfers */
priv->chan[chidx].buffer += bcnt;
@ -2924,7 +2938,7 @@ static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
* Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc.
* such "special" memory, this functions may simply map to kmalloc.
*
* This interface was optimized under a particular assumption. It was assumed
* that the driver maintains a pool of small, pre-allocated buffers for descriptor
@ -2958,12 +2972,15 @@ static int stm32_alloc(FAR struct usbhost_driver_s *drvr,
/* There is no special memory requirement */
alloc = (FAR uint8_t *)malloc(*maxlen);
alloc = (FAR uint8_t *)kmalloc(*maxlen);
if (!alloc)
{
return -ENOMEM;
}
/* Return the allocated buffer */
*buffer = alloc;
return OK;
}
@ -2974,7 +2991,7 @@ static int stm32_alloc(FAR struct usbhost_driver_s *drvr,
* Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to free that
* request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to free().
* such "special" memory, this functions may simply map to kfree().
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
@ -2995,7 +3012,7 @@ static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
/* There is no special memory requirement */
DEBUGASSERT(drvr && buffer);
free(buffer);
kfree(buffer);
return OK;
}
@ -3006,7 +3023,7 @@ static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
* Some hardware supports special memory in which larger IO buffers can
* be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc.
* such "special" memory, this functions may simply map to kmalloc.
*
* This interface differs from DRVR_ALLOC in that the buffers are variable-sized.
*
@ -3035,12 +3052,15 @@ static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr,
/* There is no special memory requirement */
alloc = (FAR uint8_t *)malloc(buflen);
alloc = (FAR uint8_t *)kmalloc(buflen);
if (!alloc)
{
return -ENOMEM;
}
/* Return the allocated buffer */
*buffer = alloc;
return OK;
}
@ -3051,7 +3071,7 @@ static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr,
* Some hardware supports special memory in which IO data can be accessed more
* efficiently. This method provides a mechanism to free that IO buffer
* memory. If the underlying hardware does not support such "special" memory,
* this functions may simply map to free().
* this functions may simply map to kfree().
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
@ -3072,7 +3092,7 @@ static int stm32_iofree(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
/* There is no special memory requirement */
DEBUGASSERT(drvr && buffer);
free(buffer);
kfree(buffer);
return OK;
}
@ -3161,7 +3181,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr,
/* Handle the status OUT phase */
priv->chan[priv->ep0out].outdata1 ^= true;
ret = stm32_ctrl_senddata(priv, buffer, buflen);
ret = stm32_ctrl_senddata(priv, NULL, 0);
if (ret == OK)
{
break;