Newer
Older
#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))
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
{
/* 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))
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
{
/* 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
*
*******************************************************************************/
static int lpc214x_epconfigure(FAR struct usbdev_ep_s *ep,
FAR const struct usb_epdesc_s *desc)
{
FAR struct lpc214x_ep_s *privep = (FAR struct lpc214x_ep_s *)ep;
uint32 inten;
int eplog;
int epphy;
usbtrace(TRACE_EPCONFIGURE, privep->epphy);
eplog = desc->addr;
epphy = LPC214X_EP_LOG2PHY(eplog);
/* Realize the endpoint */
lpc214x_eprealize(privep, 1, GETUINT16(desc->mxpacketsize));
/* Enable and reset EP -- twice */
lpc214x_usbcmd(CMD_USB_EP_SETSTATUS | epphy, 0);
lpc214x_usbcmd(CMD_USB_EP_SETSTATUS | epphy, 0);
#ifdef CONFIG_LPC214X_USBDEV_DMA
/* Enable DMA Ep interrupt (WO) */
lpc214x_putreg(1 << epphy, LPC214X_USBDEV_EPDMAEN);
#else
/* Enable Ep interrupt (R/W) */
inten = lpc214x_getreg(LPC214X_USBDEV_EPINTEN);
lpc214x_putreg(inten, LPC214X_USBDEV_EPINTEN);
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
#endif
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);
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
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);
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
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
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);
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), 0);
return -ESHUTDOWN;
}
req->result = -EINPROGRESS;
req->xfrd = 0;
/* Check for NULL packet */
flags = irqsave();
if (req->len == 0 && (LPC214X_EPPHYIN(privep->epphy)))
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_NULLPACKET), 0);
sq_addlast(&privreq->sqe, &privep->reqlist);
goto success_notransfer;
}
/* Has everything been sent? Or are we stalled? */
if (!sq_empty(&privep->reqlist) && !privep->stalled)
{
/* Handle zero-length transfers on EP0 */
if (privep->epphy == 0 && req->len == 0)
{
/* Nothing to transfer -- exit success, zero-bytes transferred */
usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
lpc214x_reqcomplete(privep, OK);
goto success_notransfer;
}
/* Handle IN requests */
{
ret = lpc214x_wrrequest(privep);
}
/* Handle pending OUT requests */
else if (priv->rxpending)
{
ret = lpc214x_rdrequest(privep);
priv->rxpending = 0;
}
else
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADREQUEST), 0);
ret = ERROR;
goto errout;
}
}
/* Add to endpoint's request queue */
if (ret >= 0)
{
usbtrace(TRACE_REQQUEUED(privep->epphy), privreq->req.len);
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
sq_addlast(&privreq->sqe, &privep->reqlist);
}
success_notransfer:
errout:
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);
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
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
2452
2453
2454
2455
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:
* epphy - 7-bit physical endpoint number (without direction bit). Zero means
* that any endpoint matching the other requirements will suffice.
* 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 epphy,
boolean in, ubyte eptype)
{
FAR struct lpc214x_usbdev_s *priv = (FAR struct lpc214x_usbdev_s *)dev;
uint32 epset = LPC214X_EPALLSET;
irqstate_t flags;
int epndx = 0;
usbtrace(TRACE_DEVALLOCEP, 0);
/* epphy=0 means that any endpoint will do */
if (epphy > 0)
{
if (epphy >= LPC214X_NLOGENDPOINTS)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADEPNO), 0);
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
return NULL;
}
epset &= 3 << epphy;
}
/* 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 */
epset &= LPC214X_EPBULKSET;
break;
case USB_EP_ATTR_XFER_CONTROL: /* Control endpoint -- not a valid choice */
default:
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADEPTYPE), 0);
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
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;
if ((epset & bit) == 0)
{
/* Mark the endpoint no longer available */
priv->wravail &= ~bit;
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), 0);
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
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
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->wravail &= ~(1 << privep->epphy);
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;
usbtrace(TRACE_DEVSELFPOWERED, (uint16)selfpowered);
#ifdef CONFIG_DEBUG
if (!dev)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);
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
return -ENODEV;
}
#endif
priv->selfpowered = selfpowered;
return OK;
}
/*******************************************************************************
* Name: lpc214x_pullup
*
* Description:
* Software-controlled connect to/disconnect from USB host
*
*******************************************************************************/
static int lpc214x_pullup(struct usbdev_s *dev, boolean enable)
{
usbtrace(TRACE_DEVPULLUP, (uint16)enable);
/* The USBDEV_DEVSTATUS_CONNECT bit in the CMD_USB_DEV_SETSTATUS command
* controls the LPC214x SoftConnect_N output pin that is used for SoftConnect.
*/
lpc214x_usbcmd(CMD_USB_DEV_SETSTATUS, (enable ? USBDEV_DEVSTATUS_CONNECT : 0));
return OK;
}
/*******************************************************************************
* Public Functions
*******************************************************************************/
/*******************************************************************************
* Name: up_usbinitialize
*
* Description:
* Initialize USB hardware.
*
* Assumptions:
* - This function is called very early in the initialization sequence
* - PLL and GIO pin initialization is not performed here but should been in
* the low-level boot logic: PLL1 must be configured for operation at 48MHz
* and P0.23 and PO.31 in PINSEL1 must be configured for Vbus and USB connect
* LED.
*
*******************************************************************************/
void up_usbinitialize(void)
{
struct lpc214x_usbdev_s *priv = &g_usbdev;
uint32 reg;
usbtrace(TRACE_DEVINIT, 0);
/* Disable USB inerrupts */
lpc214x_putreg(0, LPC214X_USBDEV_INTST);
memset(priv, 0, sizeof(struct lpc214x_usbdev_s));
priv->usbdev.ops = &g_devops;
priv->usbdev.ep0 = &priv->eplist[LPC214X_EP0_IN].ep;
priv->wravail = LPC214X_EPALLSET;
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
/* Initialize the endpoint list */
for (i = 0; i < LPC214X_NPHYSENDPOINTS; i++)
{
uint32 bit = 1 << i;
/* Set endpoint operations, reference to driver structure (not
* really necessary because there is only one controller), and
* the physical endpoint number (which is just the index to the
* endpoint).
*/
priv->eplist[i].ep.ops = &g_epops;
priv->eplist[i].dev = priv;
priv->eplist[i].epphy = i;
/* The maximum packet size may depend on the type of endpoint */
if ((LPC214X_EPCTRLSET & bit) != 0)
{
priv->eplist[i].ep.maxpacket = LPC214X_EP0MAXPACKET;
}
else if ((LPC214X_EPINTRSET & bit) != 0)
{
priv->eplist[i].ep.maxpacket = LPC214X_INTRMAXPACKET;
}
else if ((LPC214X_EPBULKSET & bit) != 0)
{
priv->eplist[i].ep.maxpacket = LPC214X_BULKMAXPACKET;
}
else /* if ((LPC214X_EPISOCSET & bit) != 0) */
{
priv->eplist[i].ep.maxpacket = LPC214X_ISOCMAXPACKET;
}
}
/* Turn on USB power and clocking */
reg = lpc214x_getreg(LPC214X_PCON_PCONP);
lpc214x_putreg(reg, LPC214X_PCON_PCONP);
/* Attach USB controller interrupt handler */
if (irq_attach(LPC214X_USB_IRQ, lpc214x_usbinterrupt) != 0)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_IRQREGISTRATION), 0);
goto errout;
}
/* Enable USB inerrupts */
lpc214x_putreg(USBDEV_INTST_ENUSBINTS, LPC214X_USBDEV_INTST);
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
up_enable_irq(LPC214X_USB_IRQ);
/* Disconnect device */
lpc214x_pullup(&priv->usbdev, FALSE);
/* Enable EP0 for OUT (host-to-device) */
lpc214x_usbcmd(CMD_USB_DEV_SETADDRESS, CMD_USB_SETADDRESS_DEVEN|LPC214X_EP0_OUT);
lpc214x_usbcmd(CMD_USB_DEV_SETADDRESS, CMD_USB_SETADDRESS_DEVEN|LPC214X_EP0_OUT);
/* Reset/Re-initialize the USB hardware */
lpc214x_usbreset(priv);
/* Init Device state structure */
priv->devstatus = lpc214x_usbcmd(CMD_USB_DEV_GETSTATUS, 0);
return;
errout:
up_usbuninitialize();
}
/*******************************************************************************
*******************************************************************************/
{
struct lpc214x_usbdev_s *priv = &g_usbdev;
uint32 reg;
irqstate_t flags;
usbtrace(TRACE_DEVUNINIT, 0);
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_DRIVERREGISTERED), 0);
usbdev_unregister(priv->driver);
}
/* Disconnect device */
flags = irqsave();
lpc214x_pullup(&priv->usbdev, FALSE);
priv->usbdev.speed = USB_SPEED_UNKNOWN;
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 0);
/* Disable and detach IRQs */
up_disable_irq(LPC214X_USB_IRQ);
irq_detach(LPC214X_USB_IRQ);
/* Turn off USB power and clocking */
reg = lpc214x_getreg(LPC214X_PCON_PCONP);
reg &= ~LPC214X_PCONP_PCUSB;
lpc214x_putreg(reg, LPC214X_PCON_PCONP);
irqrestore(flags);
}
/*******************************************************************************
* Name: usbdev_register
*
* Description:
* Register a USB device class driver. The class driver's bind() method will be
* called to bind it to a USB device driver.
*
*******************************************************************************/
int usbdev_register(struct usbdevclass_driver_s *driver)
{
int ret;
usbtrace(TRACE_DEVREGISTER, 0);
if (!driver || !driver->ops->bind || !driver->ops->unbind ||
!driver->ops->disconnect || !driver->ops->setup)
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);
}
if (g_usbdev.driver)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_DRIVER), 0);
return -EBUSY;
}
#endif
/* First hook up the driver */
g_usbdev.driver = driver;
/* Then bind the class driver */
ret = CLASS_BIND(driver, &g_usbdev.usbdev);
if (ret)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BINDFAILED), (uint16)-ret);
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
g_usbdev.driver = NULL;
}
return ret;
}
/*******************************************************************************
* Name: usbdev_unregister
*
* Description:
* Un-register usbdev class driver.If the USB device is connected to a USB host,
* it will first disconnect(). The driver is also requested to unbind() and clean
* up any device state, before this procedure finally returns.
*
*******************************************************************************/
int usbdev_unregister(struct usbdevclass_driver_s *driver)
{
usbtrace(TRACE_DEVUNREGISTER, 0);
#ifdef CONFIG_DEBUG
if (driver != g_usbdev.driver)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDPARMS), 0);