Newer
Older
/* Fast EP interrupt */
if ((devintstatus & USBDEV_DEVINT_EPFAST) != 0)
{
/* Clear Fast EP interrupt */
lpc214x_putreg(USBDEV_DEVINT_EPFAST, LPC214X_USBDEV_DEVINTCLR);
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EPFAST), 0);
/* Do what? */
}
#endif
#if CONFIG_DEBUG
/* USB engine error interrupt */
if ((devintstatus & USBDEV_DEVINT_EPRINT))
{
ubyte errcode;
/* Clear the error interrupt */
lpc214x_putreg(USBDEV_DEVINT_EPRINT, LPC214X_USBDEV_DEVINTCLR);
/* And show what error occurred */
errcode = (ubyte)lpc214x_usbcmd(CMD_USB_DEV_READERRORSTATUS, 0) & 0x0f;
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EPRINT), (uint16)errcode);
}
#endif
#ifdef CONFIG_LPC214X_USBDEV_FRAME_INTERRUPT
/* Frame interrupt */
if ((devintstatus & USBDEV_DEVINT_FRAME) != 0)
{
/* Clear the frame interrupt */
lpc214x_putreg(USBDEV_DEVINT_FRAME, LPC214X_USBDEV_DEVINTCLR);
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_FRAME), 0);
/* Then read the start of frame value */
priv->sof = (uint16)lpc214x_usbcmd(CMD_USB_DEV_READFRAMENO, 0);
}
#endif
/* Device Status interrupt */
if ((devintstatus & USBDEV_DEVINT_DEVSTAT) != 0)
{
/* Clear Device status interrupt */
lpc214x_putreg(USBDEV_DEVINT_DEVSTAT, LPC214X_USBDEV_DEVINTCLR);
/* Get device status */
g_usbdev.devstatus = (ubyte)lpc214x_usbcmd(CMD_USB_DEV_GETSTATUS, 0);
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_DEVSTAT), (uint16)g_usbdev.devstatus);
/* Device connection status */
if (DEVSTATUS_CONNCHG(g_usbdev.devstatus))
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_CONNECTCHG),
(uint16)g_usbdev.devstatus);
if (DEVSTATUS_CONNECT(g_usbdev.devstatus))
{
/* Host is connected */
if (!priv->attached)
{
/* We have a transition from unattached to attached */
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_CONNECTED),
(uint16)g_usbdev.devstatus);
priv->usbdev.speed = USB_SPEED_UNKNOWN;
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 0);
priv->attached = 1;
}
}
/* Otherwise the host is not attached */
else if (priv->attached)
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_DISCONNECTED),
(uint16)g_usbdev.devstatus);
priv->usbdev.speed = USB_SPEED_UNKNOWN;
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 0);
priv->attached = 0;
priv->paddrset = 0;
}
}
/* Device suspend status */
if (DEVSTATUS_SUSPCHG(g_usbdev.devstatus))
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_SUSPENDCHG),
(uint16)g_usbdev.devstatus);
}
/* Device reset */
if (DEVSTATUS_RESET(g_usbdev.devstatus))
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_DEVRESET),
(uint16)g_usbdev.devstatus);
lpc214x_usbreset(priv);
}
}
/* Slow EP interrupt */
if ((devintstatus & USBDEV_DEVINT_EPSLOW) != 0)
{
/* Clear Slow EP interrupt */
lpc214x_putreg(USBDEV_DEVINT_EPSLOW, LPC214X_USBDEV_DEVINTCLR);
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EPSLOW), 0);
do
{
/* Read the endpoint interrupt status register */
epintstatus = lpc214x_getreg(LPC214X_USBDEV_EPINTST);
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
/* Loop twice: Process software high priority interrupts
* on the first pass and low priority interrupts on the
* second.
*/
softprio = priv->softprio;
for (i = 0; i < 2; i++, softprio = ~softprio)
{
/* On the first time through the loop, pending will be
* the bitset of high priority pending interrupts; on the
* second time throught it will be the bitset of low
* priority interrupts.
*/
pending = epintstatus & softprio;
/* EP0 OUT interrupt indicated by bit0 == 1 */
if ((pending & 1) != 0)
{
/* Clear the endpoint interrupt */
uint32 result = lpc214x_epclrinterrupt(LPC214X_CTRLEP_OUT);
if (result & USBDEV_EPSETUPPACKET)
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EP0SETUP), (uint16)result);
lpc214x_ep0setup(priv);
}
else
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EP0OUT), priv->ep0state);
lpc214x_ep0dataoutinterrupt(priv);
}
break;
}
/* EP0 IN interrupt indicated by bit1 == 1 */
if ((pending & 2) != 0)
{
/* Clear the endpoint interrupt */
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EP0IN), priv->ep0state);
(void)lpc214x_epclrinterrupt(LPC214X_CTRLEP_IN);
lpc214x_ep0dataininterrupt(priv);
}
pending >>= 2;
/* All other endpoints EP 1-31 */
for (epphy = 2; pending; epphy++, pending >>= 1)
{
/* Is the endpoint interrupt pending? */
if ((pending & 1) != 0)
{
/* Yes.. clear the endpoint interrupt */
(void)lpc214x_epclrinterrupt(epphy);
/* Get the endpoint sructure corresponding to the physical
* endpoint number.
*/
privep = &priv->eplist[epphy];
/* Check for complete on IN or OUT endpoint. Odd physical
* endpoint addresses are IN endpoints.
*/
if ((epphy & 1) != 0)
{
/* IN: device-to-host */
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EPOUT), (uint16)epphy);
if (priv->usbdev.speed == USB_SPEED_UNKNOWN)
{
priv->usbdev.speed = USB_SPEED_FULL;
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 1);
}
/* Write host data from the current write request (if any) */
}
else
{
/* OUT: host-to-device */
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EPIN), (uint16)epphy);
/* Read host data into the current read request */
{
lpc214x_rdrequest(privep);
}
else
{
uvdbg("Pending data on OUT endpoint\n");
priv->rxpending = 1;
}
}
}
}
}
}
while (epintstatus);
}
#ifdef CONFIG_LPC214X_USBDEV_DMA
}
/* Check for DMA interrupts */
if ((lpc214x_getreg(LPC214X_USBDEV_INTST) & USBDEV_INTST_REQDMA) != 0)
{
/* First Software High priority and then low priority */
uint32 tmp;
/* Collect the DMA interrupt sources */
dmaintstatus = 0;
tmp = lpc214x_getreg(LPC214X_USBDEV_EOTINTST);
if (lpc214x_getreg(LPC214X_USBDEV_DMAINTEN) & 1)
{
dmaintstatus |= tmp;
}
lpc214x_putreg(tmp, LPC214X_USBDEV_EOTINTCLR);
tmp = lpc214x_getreg(LPC214X_USBDEV_NDDRINTST);
if (lpc214x_getreg(LPC214X_USBDEV_DMAINTEN) & 2)
{
dmaintstatus |= tmp;
}
lpc214x_putreg(tmp, LPC214X_USBDEV_NDDRINTCLR);
tmp = lpc214x_getreg(LPC214X_USBDEV_SYSERRINTST);
if (lpc214x_getreg(LPC214X_USBDEV_DMAINTEN) & 4)
{
dmaintstatus |= tmp;
}
lpc214x_putreg(tmp, LPC214X_USBDEV_SYSERRINTCLR);
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
/* Loop twice: Process software high priority interrupts on the
* first pass and low priority interrupts on the second.
*/
softprio = priv->softprio;
for (i = 0; i < 2; i++, softprio = ~softprio)
{
/* On the first time through the loop, pending will be
* the bitset of high priority pending interrupts; on the
* second time throught it will be the bitset of low
* priority interrupts. Note that EP0 IN and OUT are
* omitted.
*/
pending = (dmaintstatus & softprio) >> 2;
for (epphy = 2; pending; epphy++, pending >>= 1)
{
if ((pending & 1) != 0)
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EPDMA), (uint16)epphy);
#warning DO WHAT?
}
}
}
}
#endif
usbtrace(TRACE_INTEXIT(LPC214X_TRACEINTID_USB), 0);
return OK;
}
/*******************************************************************************
* Name: lpc214x_dmasetup
*
* Description:
* Setup for DMA Transfer
*
*******************************************************************************/
#ifdef CONFIG_LPC214X_USBDEV_DMA
static int lpc214x_dmasetup(struct lpc214x_usbdev_s *priv, ubyte epphy,
uint32 epmaxsize, uint32 nbytes, uint32 *isocpacket,
boolean isochronous);
{
struct lpc214x_dmadesc_s *dmadesc = priv;
uint32 reg;
#ifdef CONFIG_DEBUG
if (!priv || epphy < 2)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);
return -EINVAL;
}
#endif
/* Check if a DMA descriptor has been assigned. If not, than that indicates
* that we will have to do parallel I/O
*/
if (!dmadesc)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_NODMADESC), 0);
return -EBUSY;
}
/* Verify that the DMA descriptor is available */
if ((dmadesc->status & USB_DMADESC_STATUSMASK) == USB_DMADESC_BEINGSERVICED)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_DMABUSY), 0);
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
return -EBUSY; /* Shouldn't happen */
}
/* Init DMA Descriptor */
dmadesc->nexdesc = 0;
dmadesc->config = USB_DMADESC_MODENORMAL |
((epmaxsize << USB_DMADESC_PKTSIZESHIFT) & USB_DMADESC_PKTSIZEMASK) |
((nbytes << USB_DMADESC_BULENSHIFT) & USB_DMADESC_BUFLENMASK);
#ifdef CONFIG_USBDEV_ISOCHRONOUS
if (isochronous)
{
dmadesc->config |= USB_DMADESC_ISCOEP;
}
#endif
dmadesc->start = (uint32)&dmadesc->buffer;
dmadesc->status = 0;
#ifdef CONFIG_USBDEV_ISOCHRONOUS
dmadesc->size = (uint32)packet;
#endif
/* Enable DMA tranfer for this endpoint */
putreq32(1 << epphy, LPC214X_USBDEV_EPDMAEN);
/* Check state of IN/OUT Ep buffer */
reg = lpc214x_usbcmd(CMD_USB_EP_SELECT | epphy, 0);
if ((LPC214X_EPPHYIN(epphy) && (reg & 0x60) == 0) ||
(LPC214X_EPPHYOUT(epphy) && (reg & 0x60) == 0x60))
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
{
/* DMA should be "being serviced" */
if ((dmadesc->status & USB_DMADESC_STATUSMASK) != USB_DMADESC_BEINGSERVICED))
{
/* Re-trigger the DMA Transfer */
putreq21(1 << epphy, LPC214X_USBDEV_DMARCLR);
putreq32(1 << epphy, LPC214X_USBDEV_EPDMAEN);
}
}
return OK;
}
#endif /* CONFIG_LPC214X_USBDEV_DMA */
/*******************************************************************************
* Name: lpc214x_dmarestart
*
* Description:
* Restart DMA Transfer
*
*******************************************************************************/
#ifdef CONFIG_LPC214X_USBDEV_DMA
static void lpc214x_dmarestart(ubyte epphy, uint32 descndx)
{
uint32 reg;
/* Clear DMA descriptor status */
USB_DmaDesc[descndx].status = 0;
/* Enable DMA transfer on the endpoint */
lpc214x_putreg(1 << epph, LPC214X_USBDEV_EPDMAEN);
/* Check the state of IN/OUT EP buffer */
uint32 reg = lpc214x_usbcmd(CMD_USB_EP_SELECT | epphy, 0);
if ((LPC214X_EPPHYIN(epphy) && (reg & 0x60) == 0) ||
(LPC214X_EPPHYIN(epphy) && (reg & 0x60) == 0x60))
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
{
/* Re-trigger the DMA Transfer */
putreq21(1 << epphy, LPC214X_USBDEV_DMARCLR);
putreq32(1 << epphy, LPC214X_USBDEV_EPDMAEN);
}
}
#endif /* CONFIG_LPC214X_USBDEV_DMA */
/*******************************************************************************
* Name: lpc214x_dmadisable
*
* Description:
* Disable DMA transfer for the EP
*
*******************************************************************************/
#ifdef CONFIG_LPC214X_USBDEV_DMA
static void lpc214x_dmadisable(ubyte epphy)
{
EPDMADIS = 1 << epphy;
}
#endif /* CONFIG_LPC214X_USBDEV_DMA */
/*******************************************************************************
* Endpoint operations
*******************************************************************************/
/*******************************************************************************
* Name: lpc214x_epconfigure
*
* Description:
* Configure endpoint, making it usable
*
* Input Parameters:
* ep - the struct usbdev_ep_s instance obtained from allocep()
* desc - A struct usb_epdesc_s instance describing the endpoint
* last - TRUE if this this last endpoint to be configured. Some hardware
* needs to take special action when all of the endpoints have been
* configured.
*
*******************************************************************************/
static int lpc214x_epconfigure(FAR struct usbdev_ep_s *ep,
FAR const struct usb_epdesc_s *desc,
boolean last)
{
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
uint32 inten;
usbtrace(TRACE_EPCONFIGURE, privep->epphy);
DEBUGASSERT(desc->addr == ep->eplog);
/* Realize the endpoint */
lpc214x_eprealize(privep, 1, GETUINT16(desc->mxpacketsize));
/* Enable and reset EP -- twice */
lpc214x_usbcmd(CMD_USB_EP_SETSTATUS | privep->epphy, 0);
lpc214x_usbcmd(CMD_USB_EP_SETSTATUS | privep->epphy, 0);
#ifdef CONFIG_LPC214X_USBDEV_DMA
/* Enable DMA Ep interrupt (WO) */
lpc214x_putreg(1 << privep->epphy, LPC214X_USBDEV_EPDMAEN);
#else
/* Enable Ep interrupt (R/W) */
inten = lpc214x_getreg(LPC214X_USBDEV_EPINTEN);
inten |= (1 << privep->epphy);
lpc214x_putreg(inten, LPC214X_USBDEV_EPINTEN);
/* If all of the endpoints have been configured, then tell the USB controller
* to enabled normal activity on all realized endpoints.
*/
if (last)
{
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 1);
}
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
return OK;
}
/*******************************************************************************
* Name: lpc214x_epdisable
*
* Description:
* The endpoint will no longer be used
*
*******************************************************************************/
static int lpc214x_epdisable(FAR struct usbdev_ep_s *ep)
{
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
irqstate_t flags;
uint32 mask = (1 << privep->epphy);
uint32 reg;
#ifdef CONFIG_DEBUG
if (!ep)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);
return -EINVAL;
}
#endif
usbtrace(TRACE_EPDISABLE, privep->epphy);
/* Cancel any ongoing activity */
flags = irqsave();
lpc214x_cancelrequests(privep);
/* Disable endpoint and interrupt */
reg = lpc214x_getreg(LPC214X_USBDEV_REEP);
lpc214x_putreg(reg, LPC214X_USBDEV_REEP);
lpc214x_putreg(mask, LPC214X_USBDEV_EPDMADIS);
reg = lpc214x_getreg(LPC214X_USBDEV_EPINTEN);
lpc214x_putreg(reg, LPC214X_USBDEV_EPINTEN);
irqrestore(flags);
return OK;
}
/*******************************************************************************
* Name: lpc214x_epallocreq
*
* Description:
* Allocate an I/O request
*
*******************************************************************************/
static FAR struct usbdev_req_s *lpc214x_epallocreq(FAR struct usbdev_ep_s *ep)
{
FAR struct lpc214x_req_s *privreq;
#ifdef CONFIG_DEBUG
if (!ep)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);
return NULL;
}
#endif
usbtrace(TRACE_EPALLOCREQ, ((FAR struct lpc214x_ep_s *)ep)->epphy);
privreq = (FAR struct lpc214x_req_s *)malloc(sizeof(struct lpc214x_req_s));
if (!privreq)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_ALLOCFAIL), 0);
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
return NULL;
}
memset(privreq, 0, sizeof(struct lpc214x_req_s));
return &privreq->req;
}
/*******************************************************************************
* Name: lpc214x_epfreereq
*
* Description:
* Free an I/O request
*
*******************************************************************************/
static void lpc214x_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
{
FAR struct lpc214x_req_s *privreq = (FAR struct lpc214x_req_s *)req;
#ifdef CONFIG_DEBUG
if (!ep || !req)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
return;
}
#endif
usbtrace(TRACE_EPFREEREQ, ((FAR struct lpc214x_ep_s *)ep)->epphy);
free(privreq);
}
/*******************************************************************************
* Name: lpc214x_epallocbuffer
*
* Description:
* Allocate an I/O buffer
*
*******************************************************************************/
#ifdef CONFIG_LPC214X_USBDEV_DMA
static FAR void *lpc214x_epallocbuffer(FAR struct usbdev_ep_s *ep, uint16 nbytes)
{
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
int descndx;
usbtrace(TRACE_EPALLOCBUFFER, privep->epphy);
/* Find a free DMA description */
#error "LOGIC INCOMPLETE"
/* Set UDCA to the allocated DMA descriptor for this endpoint */
USB_UDCA[privep->epphy] = &USB_DDESC[descndx];
return &USB_DDESC[descndx]
}
#endif
/*******************************************************************************
* Name: lpc214x_epfreebuffer
*
* Description:
* Free an I/O buffer
*
*******************************************************************************/
#ifdef CONFIG_LPC214X_USBDEV_DMA
static void lpc214x_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf)
{
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
usbtrace(TRACE_EPFREEBUFFER, privep->epphy);
/* Indicate that there is no DMA descriptor associated with this endpoint */
USB_UDCA[privep->epphy] = NULL;
/* Mark the DMA descriptor as free for re-allocation */
#error "LOGIC INCOMPLETE"
}
#endif
/*******************************************************************************
* Name: lpc214x_epsubmit
*
* Description:
* Submit an I/O request to the endpoint
*
*******************************************************************************/
static int lpc214x_epsubmit(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
{
FAR struct lpc214x_req_s *privreq = (FAR struct lpc214x_req_s *)req;
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
FAR struct lpc214x_usbdev_s *priv;
irqstate_t flags;
int ret = OK;
#ifdef CONFIG_DEBUG
if (!req || !req->callback || !req->buf || !ep)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);
uvdbg("req=%p callback=%p buf=%p ep=%p\n", req, req->callback, req->buf, ep);
return -EINVAL;
}
#endif
usbtrace(TRACE_EPSUBMIT, privep->epphy);
priv = privep->dev;
if (!priv->driver || priv->usbdev.speed == USB_SPEED_UNKNOWN)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_NOTCONFIGURED), priv->usbdev.speed);
return -ESHUTDOWN;
}
/* Handle the request from the class driver */
req->xfrd = 0;
flags = irqsave();
/* If we are stalled, then drop all requests on the floor */
lpc214x_abortrequest(privep, privreq, -EBUSY);
ret = -EBUSY;
/* Handle IN (device-to-host) requests */
else if (LPC214X_EPPHYIN(privep->epphy))
/* Add the new request to the request queue for the IN endpoint */
lpc214x_rqenqueue(privep, privreq);
usbtrace(TRACE_INREQQUEUED(privep->epphy), privreq->req.len);
ret = lpc214x_wrrequest(privep);
}
/* Handle OUT (host-to-device) requests */
/* Add the new request to the request queue for the OUT endpoint */
lpc214x_rqenqueue(privep, privreq);
usbtrace(TRACE_OUTREQQUEUED(privep->epphy), privreq->req.len);
/* This there a incoming data pending the availability of a request? */
if (priv->rxpending)
{
ret = lpc214x_rdrequest(privep);
priv->rxpending = 0;
}
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
}
irqrestore(flags);
return ret;
}
/*******************************************************************************
* Name: lpc214x_epcancel
*
* Description:
* Cancel an I/O request previously sent to an endpoint
*
*******************************************************************************/
static int lpc214x_epcancel(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
{
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
FAR struct lpc214x_usbdev_s *priv;
irqstate_t flags;
#ifdef CONFIG_DEBUG
if (!ep || !req)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
return -EINVAL;
}
#endif
usbtrace(TRACE_EPCANCEL, privep->epphy);
priv = privep->dev;
flags = irqsave();
lpc214x_cancelrequests(privep);
irqrestore(flags);
return OK;
}
/*******************************************************************************
* Name: lpc214x_epstall
*
* Description:
* Stall or resume and endpoint
*
*******************************************************************************/
static int lpc214x_epstall(FAR struct usbdev_ep_s *ep, boolean resume)
{
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
usbtrace(resume ? TRACE_EPRESUME : TRACE_EPSTALL, privep->epphy);
lpc214x_usbcmd(CMD_USB_EP_SETSTATUS | privep->epphy, (resume ? 0 : USBDEV_EPSTALL));
return OK;
}
/*******************************************************************************
* Device operations
*******************************************************************************/
/*******************************************************************************
* Name: lcp214x_allocep
*
* Description:
* Allocate an endpoint matching the parameters.
*
* Input Parameters:
* eplog - 7-bit logical endpoint number (direction bit ignored). Zero means
* that any endpoint matching the other requirements will suffice. The
* assigned endpoint can be found in the eplog field.
* in - TRUE: IN (device-to-host) endpoint requested
* eptype - Endpoint type. One of {USB_EP_ATTR_XFER_ISOC, USB_EP_ATTR_XFER_BULK,
* USB_EP_ATTR_XFER_INT}
*
*******************************************************************************/
static FAR struct usbdev_ep_s *lcp214x_allocep(FAR struct usbdev_s *dev, ubyte eplog,
boolean in, ubyte eptype)
{
FAR struct lpc214x_usbdev_s *priv = (FAR struct lpc214x_usbdev_s *)dev;
uint32 epset = LPC214X_EPALLSET & ~LPC214X_EPCTRLSET;
irqstate_t flags;
int epndx = 0;
usbtrace(TRACE_DEVALLOCEP, (uint16)eplog);
/* Ignore any direction bits in the logical address */
/* A logical address of 0 means that any endpoint will do */
if (eplog > 0)
/* Otherwise, we will return the endpoint structure only for the requested
* 'logical' endpoint. All of the other checks will still be performed.
*
* First, verify that the logical endpoint is in the range supported by
* by the hardware.
*/
if (eplog >= LPC214X_NLOGENDPOINTS)
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADEPNO), (uint16)eplog);
return NULL;
/* Convert the logical address to a physical OUT endpoint address and
* remove all of the candidate endpoints from the bitset except for the
* the IN/OUT pair for this logical address.
*/
epset &= 3 << (eplog << 1);
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
}
/* Get the subset matching the requested direction */
if (in)
{
epset &= LPC214X_EPINSET;
}
else
{
epset &= LPC214X_EPOUTSET;
}
/* Get the subset matching the requested type */
switch (eptype)
{
case USB_EP_ATTR_XFER_INT: /* Interrupt endpoint */
epset &= LPC214X_EPINTRSET;
break;
case USB_EP_ATTR_XFER_BULK: /* Bulk endpoint */
epset &= LPC214X_EPBULKSET;
break;
case USB_EP_ATTR_XFER_ISOC: /* Isochronous endpoint */
break;
case USB_EP_ATTR_XFER_CONTROL: /* Control endpoint -- not a valid choice */
default:
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADEPTYPE), (uint16)eptype);
return NULL;
}
/* Is the resulting endpoint supported by the LPC214x? */
if (epset)
{
/* Yes.. now see if any of the request endpoints are available */
flags = irqsave();
epset &= priv->epavail;
if (epset)
{
/* Select the lowest bit in the set of matching, available endpoints */
for (epndx = 2; epndx < LPC214X_NPHYSENDPOINTS; epndx++)
{
uint32 bit = 1 << epndx;
/* Mark the IN/OUT endpoint no longer available */
priv->epavail &= ~(3 << (bit & ~1));
irqrestore(flags);
/* And return the pointer to the standard endpoint structure */
return &priv->eplist[epndx].ep;
}
}
/* Shouldn't get here */
}
irqrestore(flags);
}
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_NOEP), (uint16)eplog);
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
return NULL;
}
/*******************************************************************************
* Name: lpc214x_freeep
*
* Description:
* Free the previously allocated endpoint
*
*******************************************************************************/
static void lpc214x_freeep(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep)
{
FAR struct lpc214x_usbdev_s *priv = (FAR struct lpc214x_usbdev_s *)dev;
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
irqstate_t flags;
usbtrace(TRACE_DEVFREEEP, (uint16)privep->epphy);
if (priv && privep)
{
/* Mark the endpoint as available */
flags = irqsave();
priv->epavail |= (1 << privep->epphy);
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
irqrestore(flags);
}
}
/*******************************************************************************
* Name: lpc214x_getframe
*
* Description:
* Returns the current frame number
*
*******************************************************************************/
static int lpc214x_getframe(struct usbdev_s *dev)
{
#ifdef CONFIG_LPC214X_USBDEV_FRAME_INTERRUPT
FAR struct lpc214x_usbdev_s *priv = (FAR struct lpc214x_usbdev_s *)dev;
/* Return last valid value of SOF read by the interrupt handler */
usbtrace(TRACE_DEVGETFRAME, (uint16)priv->sof);
return priv->sof;
#else
/* Return the last frame number detected by the hardware */
usbtrace(TRACE_DEVGETFRAME, 0);
return (int)lpc214x_usbcmd(CMD_USB_DEV_READFRAMENO, 0);
#endif
}
/*******************************************************************************
* Name: lpc214x_wakeup
*
* Description:
* Tries to wake up the host connected to this device
*
*******************************************************************************/
static int lpc214x_wakeup(struct usbdev_s *dev)
{
ubyte arg = USBDEV_DEVSTATUS_SUSPEND;
irqstate_t flags;
usbtrace(TRACE_DEVWAKEUP, (uint16)g_usbdev.devstatus);
flags = irqsave();
if (DEVSTATUS_CONNECT(g_usbdev.devstatus))
{
arg |= USBDEV_DEVSTATUS_CONNECT;
}
lpc214x_usbcmd(CMD_USB_DEV_SETSTATUS, arg);
irqrestore(flags);
return OK;
}
/*******************************************************************************
* Name: lpc214x_selfpowered
*
* Description:
* Sets/clears the device selfpowered feature
*
*******************************************************************************/
static int lpc214x_selfpowered(struct usbdev_s *dev, boolean selfpowered)
{
FAR struct lpc214x_usbdev_s *priv = (FAR struct lpc214x_usbdev_s *)dev;