Newer
Older
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_NULLREQUEST), 0);
/* Ignore any attempt to send a zero length packet */
if (privreq->req.len == 0)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_NULLPACKET), 0);
lpc214x_reqcomplete(privep, OK);
return OK;
}
/* Otherwise send the data in the packet (in the DMA on case, we
* may be resuming transfer already in progress.
*/
/* Get the number of bytes left to be sent in the packet */
bytesleft = privreq->req.len - privreq->req.xfrd;
/* Send the next packet if (1) there are more bytes to be sent, or
* (2) the last packet sent was exactly maxpacketsize (bytesleft == 0)
*/
usbtrace(TRACE_WRITE(privep->epphy), privreq->req.xfrd);
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
{
/* Try to send maxpacketsize -- unless we don't have that many
* bytes to send.
*/
nbytes = privep->ep.maxpacket;
if (nbytes > bytesleft)
{
nbytes = bytesleft;
}
/* Send the largest number of bytes that we can in this packet */
buf = privreq->req.buf + privreq->req.xfrd;
lpc214x_epwrite(privep->epphy, buf, nbytes);
/* Update for the next time through the loop */
privreq->req.xfrd += nbytes;
}
/* If all of the bytes were sent (including any final null packet)
* then we are finished with the transfer
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
{
usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
lpc214x_reqcomplete(privep, OK);
return OK;
}
}
return OK; /* Won't get here */
}
/*******************************************************************************
* Name: lpc214x_rdrequest
*
* Description:
* Receive to the next queued read request
*
*******************************************************************************/
static int lpc214x_rdrequest(struct lpc214x_ep_s *privep)
{
struct lpc214x_req_s *privreq;
ubyte *buf;
int nbytesread;
/* Check the request from the head of the endpoint request queue */
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_NULLREQUEST), 0);
/* Ignore any attempt to receive a zero length packet */
if (privreq->req.len == 0)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_NULLPACKET), 0);
lpc214x_reqcomplete(privep, OK);
return OK;
}
usbtrace(TRACE_READ(privep->epphy), privreq->req.xfrd);
for (;;)
{
/* Receive the next packet if (1) there are more bytes to be receive, or
* (2) the last packet was exactly maxpacketsize.
*/
buf = privreq->req.buf + privreq->req.xfrd;
nbytesread = lpc214x_epread(privep->epphy, buf, privep->ep.maxpacket);
if (nbytesread < 0)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_EPREAD), nbytesread);
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
return ERROR;
}
/* If the receive buffer is full or if the last packet was not full
* then we are finished with the transfer.
*/
privreq->req.xfrd += nbytesread;
if (privreq->req.len < privreq->req.xfrd || nbytesread < privep->ep.maxpacket)
{
usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
lpc214x_reqcomplete(privep, OK);
return OK;
}
}
return OK; /* Won't get here */
}
/*******************************************************************************
* Name: lpc214x_cancelrequests
*
* Description:
* Cancel all pending requests for an endpoint
*
*******************************************************************************/
static void lpc214x_cancelrequests(struct lpc214x_ep_s *privep)
{
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
lpc214x_reqcomplete(privep, -ESHUTDOWN);
}
}
/*******************************************************************************
* Name: lpc214x_eprealize
*
* Description:
* Enable or disable an endpoint
*
*******************************************************************************/
static void lpc214x_eprealize(struct lpc214x_ep_s *privep, boolean prio, uint32 packetsize)
{
struct lpc214x_usbdev_s *priv = privep->dev;
uint32 mask;
uint32 reg;
/* Initialize endpoint software priority */
mask = 1 << privep->epphy;
if (prio)
{
priv->softprio = priv->softprio | mask;
}
else
{
priv->softprio = priv->softprio & ~mask;
}
/* Clear realize interrupt bit */
lpc214x_putreg(USBDEV_DEVINT_EPRLZED, LPC214X_USBDEV_DEVINTCLR);
/* Realize the endpoint */
reg = lpc214x_getreg(LPC214X_USBDEV_REEP);
reg |= (1 << privep->epphy);
lpc214x_putreg(reg, LPC214X_USBDEV_REEP);
/* Set endpoint maximum packet size */
lpc214x_putreg(privep->epphy, LPC214X_USBDEV_EPIND);
lpc214x_putreg(packetsize, LPC214X_USBDEV_MAXPSIZE);
/* Wait for Realize complete */
while ((lpc214x_getreg(LPC214X_USBDEV_DEVINTST) & USBDEV_DEVINT_EPRLZED) == 0);
/* Clear realize interrupt bit */
lpc214x_putreg(USBDEV_DEVINT_EPRLZED,LPC214X_USBDEV_DEVINTCLR);
}
/*******************************************************************************
* Name: lpc214x_epclrinterrupt
*
* Description:
* Clear the EP interrupt flag and return the current EP status
*
*******************************************************************************/
static ubyte lpc214x_epclrinterrupt(ubyte epphy)
{
/* Clear the endpoint interrupt */
lpc214x_putreg(1 << epphy, LPC214X_USBDEV_EPINTCLR);
/* Wait for data in the command data register */
while ((lpc214x_getreg(LPC214X_USBDEV_DEVINTST) & USBDEV_DEVINT_CDFULL) == 0);
/* Return the value of the command data register */
return lpc214x_getreg(LPC214X_USBDEV_CMDDATA);
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
}
/*******************************************************************************
* Name: lpc214x_ep0configure
*
* Description:
* Configure endpoint 0
*
*******************************************************************************/
static inline void lpc214x_ep0configure(struct lpc214x_usbdev_s *priv)
{
uint32 inten;
/* EndPoint 0 initialization */
lpc214x_eprealize(&priv->eplist[LPC214X_CTRLEP_OUT], 0, CONFIG_USBDEV_EP0_MAXSIZE);
lpc214x_eprealize(&priv->eplist[LPC214X_CTRLEP_IN], 1, CONFIG_USBDEV_EP0_MAXSIZE);
/* Enable EP0 interrupts (not DMA) */
inten = lpc214x_getreg(LPC214X_USBDEV_EPINTEN);
inten |= 3; /* EP0 Rx and Tx */
lpc214x_putreg(inten, LPC214X_USBDEV_EPINTEN);
}
/*******************************************************************************
* Name: lpc214x_dmareset
*
* Description: Reset USB DMA
*
*******************************************************************************/
#ifdef CONFIG_LPC214X_USBDEV_DMA
static inline void lpc214x_dmareset(uint32 enable)
{
int i;
/* Disable All DMA interrupts */
lpc214x_putreg(0, LPC214X_USBDEV_DMAINTEN);
lpc214x_putreg(0xffffffff, LPC214X_USBDEV_EPDMADIS);
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
/* DMA Request clear */
putreq32(0xffffffff, LPC214X_USBDEV_DMARCLR);
/* End of Transfer Interrupt Clear */
putreq32(0xffffffff, LPC214X_USBDEV_EOTINTCLR);
/* New DD Request Interrupt Clear */
putreq32(0xffffffff, LPC214X_USBDEV_NDDRINTCLR);
/* System Error Interrupt Clear */
putreq32(0xffffffff, LPC214X_USBDEV_SYSERRINTCLR);
/* Nullify all pointers in the UDCA */
for (i = 0; i < LPC214X_NPHYSENDPOINTS; ++i)
{
USB_UDCA[i] = NULL;
}
/* Set USB UDCA Head register */
lpc214x_putreg((uint32)USB_UDCA, LPC214X_USBDEV_UDCAH);
/* Invalidate all DMA descriptors */
for (i = 0; i < CONFIG_LPC214X_USBDEV_NDMADESCRIPTORS; ++i)
{
memset(&USB_DDESC[i], 0, USB_DDESCSIZE);
}
/* Enable DMA interrupts */
lpc214x_putreg(enable, LPC214X_USBDEV_DMAINTEN);
}
#endif
/*******************************************************************************
* Name: lpc214x_usbreset
*
* Description:
* Reset Usb engine
*
*******************************************************************************/
static void lpc214x_usbreset(struct lpc214x_usbdev_s *priv)
{
/* Disable all endpoint interrupts */
lpc214x_putreg(0, LPC214X_USBDEV_EPINTEN);
/* Frame is Hp interrupt */
lpc214x_putreg(1, LPC214X_USBDEV_DEVINTPRI);
/* Clear all pending interrupts */
lpc214x_putreg(0xffffffff, LPC214X_USBDEV_EPINTCLR);
lpc214x_putreg(0xffffffff, LPC214X_USBDEV_DEVINTCLR);
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
/* Periperhal address is needed */
priv->paddrset = 0;
/* Endpoints not yet configured */
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 0);
/* EndPoint 0 initialization */
lpc214x_ep0configure(priv);
#ifdef CONFIG_LPC214X_USBDEV_DMA
/* Enable End_of_Transfer_Interrupt and System_Error_Interrupt USB DMA
* interrupts
*/
lpc214x_dmareset(CONFIG_LPC214X_USBDEV_DMAINTMASK);
#endif
/* Enable Device interrupts */
lpc214x_putreg(USB_SLOW_INT|USB_DEVSTATUS_INT|USB_FAST_INT|USB_FRAME_INT|USB_ERROR_INT,
LPC214X_USBDEV_DEVINTEN);
}
/*******************************************************************************
* Name: lpc214x_dispatchrequest
*
* Description:
* Provide unhandled setup actions to the class driver. This is logically part
* of the USB interrupt handler.
*
*******************************************************************************/
static void lpc214x_dispatchrequest(struct lpc214x_usbdev_s *priv,
{
int ret;
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_DISPATCH), 0);
if (priv && priv->driver)
{
ret = CLASS_SETUP(priv->driver, &priv->usbdev, ctrl);
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
if (ret < 0)
{
/* Stall on failure */
priv->stalled = 1;
}
else
{
lpc214x_epwrite(LPC214X_EP0_IN, NULL, 0);
priv->ep0state = LPC214X_EP0SHORTWRITE;
}
}
}
/*******************************************************************************
* Name: lpc214x_ep0setup
*
* Description:
* USB Ctrl EP Setup Event. This is logically part of the USB interrupt
* handler.
*
*******************************************************************************/
static inline void lpc214x_ep0setup(struct lpc214x_usbdev_s *priv)
{
struct lpc214x_ep_s *ep0 = &priv->eplist[LPC214X_EP0_OUT];
struct lpc214x_req_s *privreq = lpc214x_rqpeek(ep0);
uint16 index;
ubyte epphy;
ubyte response[2];
int ret;
/* Starting a control request? */
if (priv->usbdev.speed == USB_SPEED_UNKNOWN)
{
priv->usbdev.speed = USB_SPEED_FULL;
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 1);
}
/* Terminate any pending requests */
{
sint16 result = OK;
if (privreq->req.xfrd != privreq->req.len)
{
result = -EPROTO;
}
usbtrace(TRACE_COMPLETE(ep0->epphy), privreq->req.xfrd);
lpc214x_reqcomplete(ep0, result);
}
/* Assume NOT stalled */
ep0->stalled = 0;
priv->stalled = 0;
/* Read EP0 data */
ret = lpc214x_epread(LPC214X_EP0_OUT, (ubyte*)&ctrl, USB_SIZEOF_CTRLREQ);
if (ret <= 0)
{
return;
}
uvdbg("type=%02x req=%02x value=%04x index=%04x len=%04x\n",
GETUINT16(ctrl.value), GETUINT16(ctrl.index), GETUINT16(ctrl.len));
/* Dispatch any non-standard requests */
if ((ctrl.type & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD)
return;
}
/* Handle standard request. Pick off the things of interest to the
* USB device controller driver; pass what is left to the class driver
*/
{
case USB_REQ_GETSTATUS:
{
/* type: device-to-host; recipient = device, interface, endpoint
* value: 0
* index: zero interface endpoint
* len: 2; data = status
*/
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_GETSTATUS), 0);
if (!priv->paddrset || GETUINT16(ctrl.len) != 2 ||
(ctrl.type & USB_REQ_DIR_IN) == 0 || GETUINT16(ctrl.value) != 0)
{
priv->stalled = 1;
}
else
{
{
case USB_REQ_RECIPIENT_ENDPOINT:
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_EPGETSTATUS), 0);
if (epphy < LPC214X_NPHYSENDPOINTS)
{
if ((lpc214x_usbcmd(CMD_USB_EP_SELECT|epphy, 0) & CMD_USB_EPSELECT_ST) != 0)
{
response[0] = 1; /* Stalled */
}
else
{
response[0] = 0; /* Not stalled */
}
response[1] = 0;
lpc214x_epwrite(LPC214X_EP0_IN, response, 2);
priv->ep0state = LPC214X_EP0SHORTWRITE;
}
else
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADEPGETSTATUS), 0);
priv->stalled = 1;
}
}
break;
case USB_REQ_RECIPIENT_DEVICE:
{
if (index == 0)
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_DEVGETSTATUS), 0);
/* Features: Remote Wakeup=YES; selfpowered=? */
response[0] = (priv->selfpowered << USB_FEATURE_SELFPOWERED) |
(1 << USB_FEATURE_REMOTEWAKEUP);
response[1] = 0;
lpc214x_epwrite(LPC214X_EP0_IN, response, 2);
priv->ep0state = LPC214X_EP0SHORTWRITE;
}
else
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADDEVGETSTATUS), 0);
priv->stalled = 1;
}
}
break;
case USB_REQ_RECIPIENT_INTERFACE:
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_IFGETSTATUS), 0);
response[0] = 0;
response[1] = 0;
lpc214x_epwrite(LPC214X_EP0_IN, response, 2);
priv->ep0state = LPC214X_EP0SHORTWRITE;
}
break;
default:
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADGETSTATUS), 0);
priv->stalled = 1;
}
break;
}
}
}
break;
case USB_REQ_CLEARFEATURE:
{
/* type: host-to-device; recipient = device, interface or endpoint
* value: feature selector
* index: zero interface endpoint;
* len: zero, data = none
*/
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_CLEARFEATURE), 0);
if ((ctrl.type & USB_REQ_RECIPIENT_MASK) != USB_REQ_RECIPIENT_ENDPOINT)
else if (priv->paddrset && GETUINT16(ctrl.value) == USB_FEATURE_ENDPOINTHALT &&
GETUINT16(ctrl.index) < LPC214X_NLOGENDPOINTS && GETUINT16(ctrl.len) == 0)
ubyte epphys = LPC214X_EP_LOG2PHY(GETUINT16(ctrl.index));
priv->eplist[epphys].halted = 0;
lpc214x_epwrite(LPC214X_EP0_IN, NULL, 0);
priv->ep0state = LPC214X_EP0STATUSIN;
}
else
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADCLEARFEATURE), 0);
priv->stalled = 1;
}
}
break;
case USB_REQ_SETFEATURE:
{
/* type: host-to-device; recipient = device, interface, endpoint
* value: feature selector
* index: zero interface endpoint;
* len: 0; data = none
*/
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_SETFEATURE), 0);
if (((ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE) &&
uvdbg("test mode: %d\n", GETUINT16(ctrl.index));
else if ((ctrl.type & USB_REQ_RECIPIENT_MASK) != USB_REQ_RECIPIENT_ENDPOINT)
else if (priv->paddrset && GETUINT16(ctrl.value) == USB_FEATURE_ENDPOINTHALT &&
GETUINT16(ctrl.index) < LPC214X_NLOGENDPOINTS && GETUINT16(ctrl.len) == 0)
ubyte epphys = LPC214X_EP_LOG2PHY(GETUINT16(ctrl.index));
priv->eplist[epphys].halted = 1;
lpc214x_epwrite(LPC214X_EP0_IN, NULL, 0);
priv->ep0state = LPC214X_EP0STATUSIN;
}
else
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADSETFEATURE), 0);
priv->stalled = 1;
}
}
break;
case USB_REQ_SETADDRESS:
{
/* type: host-to-device; recipient = device
* value: device address
* index: 0
* len: 0; data = none
*/
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_SETADDRESS), 0);
if ((ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
GETUINT16(ctrl.index) == 0 && GETUINT16(ctrl.len) == 0 &&
GETUINT16(ctrl.value) < 128)
{
lpc214x_epwrite(LPC214X_EP0_IN, NULL, 0);
priv->eplist[LPC214X_EP0_OUT].eplog = ctrl.value[0];
priv->eplist[LPC214X_EP0_IN].eplog = ctrl.value[0];
priv->ep0state = LPC214X_EP0SETADDRESS;
}
else
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADSETADDRESS), 0);
priv->stalled = 1;
}
}
break;
case USB_REQ_GETDESCRIPTOR:
/* type: device-to-host; recipient = device
* value: descriptor type and index
* index: 0 or language ID;
* len: descriptor len; data = descriptor
*/
/* type: host-to-device; recipient = device
* value: descriptor type and index
* index: 0 or language ID;
* len: descriptor len; data = descriptor
*/
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_GETSETDESC), 0);
if ((ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE)
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADGETSETDESC), 0);
priv->stalled = 1;
}
}
break;
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
case USB_REQ_GETCONFIGURATION:
/* type: device-to-host; recipient = device
* value: 0;
* index: 0;
* len: 1; data = configuration value
*/
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_GETCONFIG), 0);
if (priv->paddrset && (ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
GETUINT16(ctrl.value) == 0 && GETUINT16(ctrl.index) == 0 &&
GETUINT16(ctrl.len) == 1)
{
lpc214x_dispatchrequest(priv, &ctrl);
}
else
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADGETCONFIG), 0);
priv->stalled = 1;
}
}
break;
case USB_REQ_SETCONFIGURATION:
/* type: host-to-device; recipient = device
* value: configuration value
* index: 0;
* len: 0; data = none
*/
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_SETCONFIG), 0);
if ((ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
GETUINT16(ctrl.index) == 0 && GETUINT16(ctrl.len) == 0)
{
lpc214x_dispatchrequest(priv, &ctrl);
}
else
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_BADSETCONFIG), 0);
priv->stalled = 1;
}
}
break;
/* type: device-to-host; recipient = interface
* value: 0
* index: interface;
* len: 1; data = alt interface
*/
/* type: host-to-device; recipient = interface
* value: alternate setting
* index: interface;
* len: 0; data = none
*/
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_GETSETIF), 0);
lpc214x_dispatchrequest(priv, &ctrl);
}
break;
case USB_REQ_SYNCHFRAME:
/* type: device-to-host; recipient = endpoint
* value: 0
* index: endpoint;
* len: 2; data = frame number
*/
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_SYNCHFRAME), 0);
}
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_INVALIDCTRLREQ), 0);
priv->stalled = 1;
}
break;
}
if (priv->stalled)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_STALLED), priv->ep0state);
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
lpc214x_epstall(&ep0->ep, FALSE);
lpc214x_epstall(&ep0->ep, FALSE);
}
}
/*******************************************************************************
* Name: lpc214x_ep0dataoutinterrupt
*
* Description:
* USB Ctrl EP Data OUT Event. This is logically part of the USB interrupt
* handler.
*
*******************************************************************************/
static inline void lpc214x_ep0dataoutinterrupt(struct lpc214x_usbdev_s *priv)
{
struct lpc214x_ep_s *ep0;
uint32 pktlen;
/* Copy new setup packet int setup buffer */
switch (priv->ep0state)
{
case LPC214X_EP0SHORTWRITE:
{
priv->ep0state = LPC214X_EP0STATUSOUT;
pktlen = lpc214x_epread(LPC214X_EP0_OUT, NULL, CONFIG_USBDEV_EP0_MAXSIZE);
if (LPC214X_READOVERRUN(pktlen))
{
lpc214x_ep0setup(priv);
}
}
break;
case LPC214X_EP0SHORTWRSENT:
{
priv->ep0state = LPC214X_EP0IDLE;
pktlen = lpc214x_epread(LPC214X_EP0_OUT, NULL, CONFIG_USBDEV_EP0_MAXSIZE);
if (LPC214X_READOVERRUN(pktlen))
{
lpc214x_ep0setup(priv);
}
}
break;
case LPC214X_EP0IDLE:
{
ep0 = &priv->eplist[LPC214X_EP0_OUT];
{
lpc214x_wrrequest(ep0);
}
}
break;
default:
priv->stalled = 1;
break;
}
if (priv->stalled)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_STALLED), priv->ep0state);
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
ep0 = &priv->eplist[LPC214X_EP0_OUT];
lpc214x_epstall(&ep0->ep, FALSE);
lpc214x_epstall(&ep0->ep, FALSE);
}
return;
}
/*******************************************************************************
* Name: lpc214x_ep0dataininterrupt
*
* Description:
* USB Ctrl EP Data IN Event. This is logically part of the USB interrupt
* handler.
*
*******************************************************************************/
static inline void lpc214x_ep0dataininterrupt(struct lpc214x_usbdev_s *priv)
{
struct lpc214x_ep_s *ep0;
switch (priv->ep0state)
{
case LPC214X_EP0STATUSOUT:
case LPC214X_EP0STATUSIN:
priv->ep0state = LPC214X_EP0IDLE;
break;
case LPC214X_EP0SHORTWRITE:
priv->ep0state = LPC214X_EP0SHORTWRSENT;
break;
case LPC214X_EP0SETADDRESS:
{
usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_SETADDRESS), 0);
/* Set EP0 logical address */
ubyte eplog = priv->eplist[LPC214X_EP0_OUT].eplog;
lpc214x_usbcmd(CMD_USB_DEV_SETADDRESS, CMD_USB_SETADDRESS_DEVEN | eplog);
lpc214x_usbcmd(CMD_USB_DEV_SETADDRESS, CMD_USB_SETADDRESS_DEVEN | eplog);
/* Not yet fully configured */
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 0);
if (eplog)
{
priv->paddrset = 1;
priv->ep0state = LPC214X_EP0IDLE;
}
}
break;
default:
priv->stalled = 1;
break;
}
if (priv->stalled)
{
usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_STALLED), priv->ep0state);
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
ep0 = &priv->eplist[LPC214X_EP0_IN];
lpc214x_epstall(&ep0->ep, FALSE);
lpc214x_epstall(&ep0->ep, FALSE);
}
}
/*******************************************************************************
* Name: lpc214x_usbinterrupt
*
* Description:
* USB interrupt handler
*
*******************************************************************************/
static int lpc214x_usbinterrupt(int irq, FAR void *context)
{
struct lpc214x_usbdev_s *priv = &g_usbdev;
struct lpc214x_ep_s *privep ;
uint32 devintstatus; /* Sampled state of the device interrupt status register */
uint32 epintstatus; /* Sampled state of the endpoint interrupt status register */
#ifdef CONFIG_LPC214X_USBDEV_DMA
uint32 dmaintstatus; /* Sampled state of dma interrupt status register */
#endif
uint32 softprio; /* Current priority interrupt bitset */
uint32 pending; /* Pending subset of priority interrupt bitset */
ubyte epphy; /* Physical endpoint number being processed */
int i;
usbtrace(TRACE_INTENTRY(LPC214X_TRACEINTID_USB), 0);
/* Read the device interrupt status register */
devintstatus = lpc214x_getreg(LPC214X_USBDEV_DEVINTST);
#ifdef CONFIG_LPC214X_USBDEV_DMA
/* Check for low priority and high priority (non-DMA) interrupts */
if ((lpc214x_getreg(LPC214X_USBDEV_INTST) & (USBDEV_INTST_REQLP|USBDEV_INTST_REQHP)) != 0)
{
#endif
#ifdef CONFIG_LPC214X_USBDEV_EPFAST_INTERRUPT
/* 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);
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
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), 0);
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), 0);
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), 0);
priv->usbdev.speed = USB_SPEED_UNKNOWN;
lpc214x_usbcmd(CMD_USB_DEV_CONFIG, 0);
priv->attached = 0;
priv->paddrset = 0;
}