Preparing for AVR USB driver

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3725 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-06-20 02:35:20 +00:00
parent 0944879e67
commit b1ff704c75
3 changed files with 223 additions and 195 deletions

View File

@ -356,7 +356,8 @@ static bool lpc31_rqenqueue(FAR struct lpc31_ep_s *privep,
/* Low level data transfers and request operations *****************************/ /* Low level data transfers and request operations *****************************/
static inline void lpc31_writedtd(struct lpc31_dtd_s *dtd, const uint8_t *data, uint32_t nbytes); static inline void lpc31_writedtd(struct lpc31_dtd_s *dtd, const uint8_t *data,
uint32_t nbytes);
static inline void lpc31_queuedtd(uint8_t epphy, struct lpc31_dtd_s *dtd); static inline void lpc31_queuedtd(uint8_t epphy, struct lpc31_dtd_s *dtd);
static inline void lpc31_ep0xfer(uint8_t epphy, uint8_t *data, uint32_t nbytes); static inline void lpc31_ep0xfer(uint8_t epphy, uint8_t *data, uint32_t nbytes);
static void lpc31_readsetup(uint8_t epphy, struct usb_ctrlreq_s *ctrl); static void lpc31_readsetup(uint8_t epphy, struct usb_ctrlreq_s *ctrl);
@ -368,13 +369,16 @@ static void lpc31_flushep(struct lpc31_ep_s *privep);
static int lpc31_progressep(struct lpc31_ep_s *privep); static int lpc31_progressep(struct lpc31_ep_s *privep);
static inline void lpc31_abortrequest(struct lpc31_ep_s *privep, static inline void lpc31_abortrequest(struct lpc31_ep_s *privep,
struct lpc31_req_s *privreq, int16_t result); struct lpc31_req_s *privreq, int16_t result);
static void lpc31_reqcomplete(struct lpc31_ep_s *privep, struct lpc31_req_s *privreq, int16_t result); static void lpc31_reqcomplete(struct lpc31_ep_s *privep,
struct lpc31_req_s *privreq, int16_t result);
static void lpc31_cancelrequests(struct lpc31_ep_s *privep, int16_t status); static void lpc31_cancelrequests(struct lpc31_ep_s *privep, int16_t status);
/* Interrupt handling **********************************************************/ /* Interrupt handling **********************************************************/
static struct lpc31_ep_s *lpc31_epfindbyaddr(struct lpc31_usbdev_s *priv, uint16_t eplog); static struct lpc31_ep_s *lpc31_epfindbyaddr(struct lpc31_usbdev_s *priv,
static void lpc31_dispatchrequest(struct lpc31_usbdev_s *priv, const struct usb_ctrlreq_s *ctrl); uint16_t eplog);
static void lpc31_dispatchrequest(struct lpc31_usbdev_s *priv,
const struct usb_ctrlreq_s *ctrl);
static void lpc31_ep0configure(struct lpc31_usbdev_s *priv); static void lpc31_ep0configure(struct lpc31_usbdev_s *priv);
static void lpc31_usbreset(struct lpc31_usbdev_s *priv); static void lpc31_usbreset(struct lpc31_usbdev_s *priv);
@ -399,7 +403,7 @@ static void lpc31_epfreereq(FAR struct usbdev_ep_s *ep,
FAR struct usbdev_req_s *); FAR struct usbdev_req_s *);
#ifdef CONFIG_ARCH_USBDEV_DMA #ifdef CONFIG_ARCH_USBDEV_DMA
static void *lpc31_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes); static void *lpc31_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes);
static void lpc313_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf); static void lpc31_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf);
#endif #endif
static int lpc31_epsubmit(FAR struct usbdev_ep_s *ep, static int lpc31_epsubmit(FAR struct usbdev_ep_s *ep,
struct usbdev_req_s *req); struct usbdev_req_s *req);
@ -407,7 +411,7 @@ static int lpc31_epcancel(FAR struct usbdev_ep_s *ep,
struct usbdev_req_s *req); struct usbdev_req_s *req);
static int lpc31_epstall(FAR struct usbdev_ep_s *ep, bool resume); static int lpc31_epstall(FAR struct usbdev_ep_s *ep, bool resume);
static FAR struct usbdev_ep_s *lcp313x_allocep(FAR struct usbdev_s *dev, static FAR struct usbdev_ep_s *lpc31_allocep(FAR struct usbdev_s *dev,
uint8_t epno, bool in, uint8_t eptype); uint8_t epno, bool in, uint8_t eptype);
static void lpc31_freeep(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep); static void lpc31_freeep(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep);
static int lpc31_getframe(struct usbdev_s *dev); static int lpc31_getframe(struct usbdev_s *dev);
@ -445,7 +449,7 @@ static const struct usbdev_epops_s g_epops =
static const struct usbdev_ops_s g_devops = static const struct usbdev_ops_s g_devops =
{ {
.allocep = lcp313x_allocep, .allocep = lpc31_allocep,
.freeep = lpc31_freeep, .freeep = lpc31_freeep,
.getframe = lpc31_getframe, .getframe = lpc31_getframe,
.wakeup = lpc31_wakeup, .wakeup = lpc31_wakeup,
@ -720,7 +724,7 @@ static void lpc31_readsetup(uint8_t epphy, struct usb_ctrlreq_s *ctrl)
/* Set the trip wire */ /* Set the trip wire */
lpc31_setbits(USBDEV_USBCMD_SUTW, LPC31_USBDEV_USBCMD); lpc31_setbits(USBDEV_USBCMD_SUTW, LPC31_USBDEV_USBCMD);
// copy the request... /* copy the request... */
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
((uint8_t *) ctrl)[i] = ((uint8_t *) dqh->setup)[i]; ((uint8_t *) ctrl)[i] = ((uint8_t *) dqh->setup)[i];
@ -761,11 +765,13 @@ static inline void lpc31_set_address(struct lpc31_usbdev_s *priv, uint16_t addre
static void lpc31_flushep(struct lpc31_ep_s *privep) static void lpc31_flushep(struct lpc31_ep_s *privep)
{ {
uint32_t mask = LPC31_ENDPTMASK(privep->epphy); uint32_t mask = LPC31_ENDPTMASK(privep->epphy);
do { do
{
lpc31_putreg (mask, LPC31_USBDEV_ENDPTFLUSH); lpc31_putreg (mask, LPC31_USBDEV_ENDPTFLUSH);
while ((lpc31_getreg(LPC31_USBDEV_ENDPTFLUSH) & mask) != 0) while ((lpc31_getreg(LPC31_USBDEV_ENDPTFLUSH) & mask) != 0)
; ;
} while ((lpc31_getreg(LPC31_USBDEV_ENDPTSTATUS) & mask) != 0); }
while ((lpc31_getreg(LPC31_USBDEV_ENDPTSTATUS) & mask) != 0);
} }
@ -865,7 +871,8 @@ static inline void lpc31_abortrequest(struct lpc31_ep_s *privep,
* *
*******************************************************************************/ *******************************************************************************/
static void lpc31_reqcomplete(struct lpc31_ep_s *privep, struct lpc31_req_s *privreq, int16_t result) static void lpc31_reqcomplete(struct lpc31_ep_s *privep,
struct lpc31_req_s *privreq, int16_t result)
{ {
/* If endpoint 0, temporarily reflect the state of protocol stalled /* If endpoint 0, temporarily reflect the state of protocol stalled
* in the callback. * in the callback.
@ -1263,7 +1270,6 @@ static inline void lpc31_ep0setup(struct lpc31_usbdev_s *priv)
(privep = lpc31_epfindbyaddr(priv, index)) != NULL) (privep = lpc31_epfindbyaddr(priv, index)) != NULL)
{ {
lpc31_epstall(&privep->ep, true); lpc31_epstall(&privep->ep, true);
lpc31_ep0state (priv, EP0STATE_WAIT_NAK_IN); lpc31_ep0state (priv, EP0STATE_WAIT_NAK_IN);
} }
else else
@ -1296,7 +1302,6 @@ static inline void lpc31_ep0setup(struct lpc31_usbdev_s *priv)
(privep = lpc31_epfindbyaddr(priv, index)) != NULL) (privep = lpc31_epfindbyaddr(priv, index)) != NULL)
{ {
lpc31_epstall(&privep->ep, false); lpc31_epstall(&privep->ep, false);
lpc31_ep0state (priv, EP0STATE_WAIT_NAK_IN); lpc31_ep0state (priv, EP0STATE_WAIT_NAK_IN);
} }
else else
@ -1323,7 +1328,6 @@ static inline void lpc31_ep0setup(struct lpc31_usbdev_s *priv)
priv->paddr = ctrl.value[0]; priv->paddr = ctrl.value[0];
priv->paddrset = false; priv->paddrset = false;
lpc31_ep0state (priv, EP0STATE_WAIT_NAK_IN); lpc31_ep0state (priv, EP0STATE_WAIT_NAK_IN);
} }
else else
@ -1550,6 +1554,7 @@ static void lpc31_ep0nak(struct lpc31_usbdev_s *priv, uint8_t epphy)
priv->stalled = true; priv->stalled = true;
break; break;
} }
if (priv->stalled) if (priv->stalled)
{ {
usbtrace(TRACE_DEVERROR(LPC31_TRACEERR_EP0SETUPSTALLED), priv->ep0state); usbtrace(TRACE_DEVERROR(LPC31_TRACEERR_EP0SETUPSTALLED), priv->ep0state);
@ -1567,8 +1572,7 @@ static void lpc31_ep0nak(struct lpc31_usbdev_s *priv, uint8_t epphy)
* *
*******************************************************************************/ *******************************************************************************/
bool bool lpc31_epcomplete(struct lpc31_usbdev_s *priv, uint8_t epphy)
lpc31_epcomplete(struct lpc31_usbdev_s *priv, uint8_t epphy)
{ {
struct lpc31_ep_s *privep = &priv->eplist[epphy]; struct lpc31_ep_s *privep = &priv->eplist[epphy];
struct lpc31_req_s *privreq = privep->head; struct lpc31_req_s *privreq = privep->head;
@ -1707,7 +1711,7 @@ static int lpc31_usbinterrupt(int irq, FAR void *context)
if (mask) if (mask)
{ {
// Clear any NAK interrupt and completion interrupts /* Clear any NAK interrupt and completion interrupts */
lpc31_putreg (mask, LPC31_USBDEV_ENDPTNAK); lpc31_putreg (mask, LPC31_USBDEV_ENDPTNAK);
lpc31_putreg (mask, LPC31_USBDEV_ENDPTCOMPLETE); lpc31_putreg (mask, LPC31_USBDEV_ENDPTCOMPLETE);
@ -1753,9 +1757,10 @@ static int lpc31_usbinterrupt(int irq, FAR void *context)
lpc31_ep0nak(priv, 1); lpc31_ep0nak(priv, 1);
} }
// clear the interrupts /* Clear the interrupts */
lpc31_putreg(pending, LPC31_USBDEV_ENDPTNAK); lpc31_putreg(pending, LPC31_USBDEV_ENDPTNAK);
} }
usbtrace(TRACE_INTEXIT(LPC31_TRACEINTID_USB), 0); usbtrace(TRACE_INTEXIT(LPC31_TRACEINTID_USB), 0);
return OK; return OK;
} }
@ -1788,7 +1793,7 @@ static int lpc31_epconfigure(FAR struct usbdev_ep_s *ep,
usbtrace(TRACE_EPCONFIGURE, privep->epphy); usbtrace(TRACE_EPCONFIGURE, privep->epphy);
DEBUGASSERT(desc->addr == ep->eplog); DEBUGASSERT(desc->addr == ep->eplog);
// Initialise EP capabilities /* Initialise EP capabilities */
uint16_t maxsize = GETUINT16(desc->mxpacketsize); uint16_t maxsize = GETUINT16(desc->mxpacketsize);
if ((desc->attr & USB_EP_ATTR_XFERTYPE_MASK) == USB_EP_ATTR_XFER_ISOC) if ((desc->attr & USB_EP_ATTR_XFERTYPE_MASK) == USB_EP_ATTR_XFER_ISOC)
@ -1915,7 +1920,6 @@ static FAR struct usbdev_req_s *lpc31_epallocreq(FAR struct usbdev_ep_s *ep)
} }
memset(privreq, 0, sizeof(struct lpc31_req_s)); memset(privreq, 0, sizeof(struct lpc31_req_s));
return &privreq->req; return &privreq->req;
} }
@ -1940,7 +1944,6 @@ static void lpc31_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s
#endif #endif
usbtrace(TRACE_EPFREEREQ, ((FAR struct lpc31_ep_s *)ep)->epphy); usbtrace(TRACE_EPFREEREQ, ((FAR struct lpc31_ep_s *)ep)->epphy);
free(privreq); free(privreq);
} }
@ -2128,7 +2131,7 @@ static int lpc31_epstall(FAR struct usbdev_ep_s *ep, bool resume)
*******************************************************************************/ *******************************************************************************/
/******************************************************************************* /*******************************************************************************
* Name: lcp313x_allocep * Name: lpc31_allocep
* *
* Description: * Description:
* Allocate an endpoint matching the parameters. * Allocate an endpoint matching the parameters.
@ -2143,7 +2146,7 @@ static int lpc31_epstall(FAR struct usbdev_ep_s *ep, bool resume)
* *
*******************************************************************************/ *******************************************************************************/
static FAR struct usbdev_ep_s *lcp313x_allocep(FAR struct usbdev_s *dev, uint8_t eplog, static FAR struct usbdev_ep_s *lpc31_allocep(FAR struct usbdev_s *dev, uint8_t eplog,
bool in, uint8_t eptype) bool in, uint8_t eptype)
{ {
FAR struct lpc31_usbdev_s *priv = (FAR struct lpc31_usbdev_s *)dev; FAR struct lpc31_usbdev_s *priv = (FAR struct lpc31_usbdev_s *)dev;
@ -2653,4 +2656,3 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
g_usbdev.driver = NULL; g_usbdev.driver = NULL;
return OK; return OK;
} }

View File

@ -69,8 +69,7 @@ CHIP_CSRCS = at90usb_lowconsole.c at90usb_lowinit.c at90usb_serial.c at90usb_tim
# Configuration-dependent aT90USB files # Configuration-dependent aT90USB files
ifeq ($(CONFIG_AVR_GPIOIRQ),y) ifeq ($(CONFIG_AVR_USBDEV),y)
CHIP_CSRCS += CHIP_CSRCS += at90usb_usbdev.c
endif endif

View File

@ -48,7 +48,34 @@
/* Define features for supported chip in the ATMEGA family */ /* Define features for supported chip in the ATMEGA family */
#if 1 #if defined(CONFIG_ARCH_CHIP_AT90USB646)
# define AVR_FLASH_SIZE (64*1024)
# define AVR_SRAM_SIZE (4*1024)
# define AVR_EEPROM_SIZE (2*1024)
# define HAVE_USBDEV 1
# undef HAVE_USBHOST
# undef HAVE_RAMPZ
#elif defined(CONFIG_ARCH_CHIP_AT90USB647)
# define AVR_FLASH_SIZE (64*1024)
# define AVR_SRAM_SIZE (4*1024)
# define AVR_EEPROM_SIZE (2*1024)
# define HAVE_USBDEV 1
# define HAVE_USBHOST 1
# undef HAVE_RAMPZ
#elif defined(CONFIG_ARCH_CHIP_AT90USB1286)
# define AVR_FLASH_SIZE (128*1024)
# define AVR_SRAM_SIZE (8*1024)
# define AVR_EEPROM_SIZE (4*1024)
# define HAVE_USBDEV 1
# undef HAVE_USBHOST
# define HAVE_RAMPZ 1
#elif defined(CONFIG_ARCH_CHIP_AT90USB1287)
# define AVR_FLASH_SIZE (128*1024)
# define AVR_SRAM_SIZE (8*1024)
# define AVR_EEPROM_SIZE (4*1024)
# define HAVE_USBDEV 1
# define HAVE_USBHOST 1
# define HAVE_RAMPZ 1
#else #else
# error "Unsupported AVR chip" # error "Unsupported AVR chip"
#endif #endif