Skip to content

Commit f3c6f95

Browse files
committed
USBHOST: USBHOST_OTHER Add timeout on TD (indentation)
1 parent 309b9ae commit f3c6f95

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

features/unsupported/USBHost/USBHost/USBHost.cpp

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,19 @@ USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, ui
11151115
res = addTransfer(ep, buf, len);
11161116

11171117
if ((blocking)&& (res == USB_TYPE_PROCESSING)) {
1118-
1118+
#ifdef USBHOST_OTHER
1119+
osEvent event = ep->ep_queue.get(TD_TIMEOUT);
1120+
if (event.status == osEventTimeout) {
1121+
/* control endpoint is confusing for merge on b */
1122+
disableList(CONTROL_ENDPOINT);
1123+
ep->setState(USB_TYPE_ERROR);
1124+
ep->ep_queue.get(0);
1125+
ep->unqueueTransfer(ep->getProcessedTD());
1126+
enableList(CONTROL_ENDPOINT);
1127+
}
1128+
#else
11191129
ep->ep_queue.get();
1130+
#endif
11201131
res = ep->getState();
11211132

11221133
USB_DBG_TRANSFER("%s TRANSFER res: %s on ep: %p\r\n", type_str, ep->getStateString(), ep);
@@ -1174,9 +1185,21 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,
11741185
control->setNextToken(TD_SETUP);
11751186
res = addTransfer(control, (uint8_t*)setupPacket, 8);
11761187

1177-
if (res == USB_TYPE_PROCESSING) {
1178-
control->ep_queue.get();
1188+
if (res == USB_TYPE_PROCESSING)
1189+
#ifdef USBHOST_OTHER
1190+
{
1191+
osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL);
1192+
if (event.status == osEventTimeout) {
1193+
disableList(CONTROL_ENDPOINT);
1194+
control->setState(USB_TYPE_ERROR);
1195+
control->ep_queue.get(0);
1196+
control->unqueueTransfer(control->getProcessedTD());
1197+
enableList(CONTROL_ENDPOINT);
1198+
}
11791199
}
1200+
#else
1201+
control->ep_queue.get();
1202+
#endif
11801203
res = control->getState();
11811204

11821205
USB_DBG_TRANSFER("CONTROL setup stage %s", control->getStateString());
@@ -1190,9 +1213,21 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,
11901213
control->setNextToken(token);
11911214
res = addTransfer(control, (uint8_t *)buf, length_transfer);
11921215

1193-
if (res == USB_TYPE_PROCESSING) {
1194-
control->ep_queue.get();
1216+
if (res == USB_TYPE_PROCESSING)
1217+
#ifdef USBHOST_OTHER
1218+
{
1219+
osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL);
1220+
if (event.status == osEventTimeout) {
1221+
disableList(CONTROL_ENDPOINT);
1222+
control->setState(USB_TYPE_ERROR);
1223+
control->ep_queue.get(0);
1224+
control->unqueueTransfer(control->getProcessedTD());
1225+
enableList(CONTROL_ENDPOINT);
1226+
}
11951227
}
1228+
#else
1229+
control->ep_queue.get();
1230+
#endif
11961231
res = control->getState();
11971232

11981233
#if DEBUG_TRANSFER
@@ -1220,10 +1255,21 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType,
12201255
token = (write) ? TD_IN : TD_OUT;
12211256
control->setNextToken(token);
12221257
res = addTransfer(control, NULL, 0);
1223-
1224-
if (res == USB_TYPE_PROCESSING) {
1225-
control->ep_queue.get();
1258+
if (res == USB_TYPE_PROCESSING)
1259+
#ifdef USBHOST_OTHER
1260+
{
1261+
osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL);
1262+
if (event.status == osEventTimeout) {
1263+
disableList(CONTROL_ENDPOINT);
1264+
control->setState(USB_TYPE_ERROR);
1265+
control->ep_queue.get(0);
1266+
control->unqueueTransfer(control->getProcessedTD());
1267+
enableList(CONTROL_ENDPOINT);
1268+
}
12261269
}
1270+
#else
1271+
control->ep_queue.get();
1272+
#endif
12271273
res = control->getState();
12281274

12291275
USB_DBG_TRANSFER("CONTROL ack stage %s", control->getStateString());

features/unsupported/USBHost/USBHost/USBHostTypes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ enum ENDPOINT_TYPE {
117117

118118
#else
119119

120+
#define TD_TIMEOUT_CTRL 100
121+
#define TD_TIMEOUT 2000
120122
#define TD_SETUP (uint32_t)(0) // Direction of Setup Packet
121123
#define TD_IN (uint32_t)(0x00100000) // Direction In
122124
#define TD_OUT (uint32_t)(0x00080000) // Direction Out
@@ -152,11 +154,13 @@ enum ENDPOINT_TYPE {
152154
#if defined(USBHOST_OTHER)
153155

154156
typedef struct hcTd {
155-
__IO uint32_t state;
157+
__IO uint32_t state;
156158
__IO uint8_t * currBufPtr; // Physical address of current buffer pointer
157159
__IO hcTd * nextTD; // Physical pointer to next Transfer Descriptor
158160
__IO uint32_t size; // size of buffer
159161
void * ep; // ep address where a td is linked in
162+
__IO uint32_t retry;
163+
__IO uint32_t setup;
160164
} PACKED HCTD;
161165
// ----------- HostController EndPoint Descriptor -------------
162166
typedef struct hcEd {

0 commit comments

Comments
 (0)