Skip to content

Commit ddc029c

Browse files
authored
Merge pull request hathach#2016 from ipopov/master
Even when we get an empty "status change" interrupt from the hub, schedule another interrupt poll
2 parents 069e1ef + 20ef6c4 commit ddc029c

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/host/hub.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -327,34 +327,35 @@ static void connection_clear_conn_change_complete (tuh_xfer_t* xfer);
327327
static void connection_port_reset_complete (tuh_xfer_t* xfer);
328328

329329
// callback as response of interrupt endpoint polling
330-
bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
331-
{
330+
bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
332331
(void) xferred_bytes; // TODO can be more than 1 for hub with lots of ports
333332
(void) ep_addr;
334333
TU_ASSERT(result == XFER_RESULT_SUCCESS);
335334

336335
hub_interface_t* p_hub = get_itf(dev_addr);
337336

338-
TU_LOG2(" Hub Status Change = 0x%02X\r\n", p_hub->status_change);
337+
uint8_t const status_change = p_hub->status_change;
338+
TU_LOG2(" Hub Status Change = 0x%02X\r\n", status_change);
339339

340-
// Hub bit 0 is for the hub device events
341-
if (tu_bit_test(p_hub->status_change, 0))
342-
{
343-
if (hub_port_get_status(dev_addr, 0, &p_hub->hub_status, hub_get_status_complete, 0) == false)
344-
{
340+
if ( status_change == 0 ) {
341+
// The status change event was neither for the hub, nor for any of its ports.
342+
// This shouldn't happen, but it does with some devices.
343+
// Initiate the next interrupt poll here.
344+
return hub_edpt_status_xfer(dev_addr);
345+
}
346+
347+
if (tu_bit_test(status_change, 0)) {
348+
// Hub bit 0 is for the hub device events
349+
if (hub_port_get_status(dev_addr, 0, &p_hub->hub_status, hub_get_status_complete, 0) == false) {
345350
//Hub status control transfer failed, retry
346351
hub_edpt_status_xfer(dev_addr);
347352
}
348353
}
349-
else
350-
{
354+
else {
351355
// Hub bits 1 to n are hub port events
352-
for (uint8_t port=1; port <= p_hub->port_count; port++)
353-
{
354-
if ( tu_bit_test(p_hub->status_change, port) )
355-
{
356-
if (hub_port_get_status(dev_addr, port, &p_hub->port_status, hub_port_get_status_complete, 0) == false)
357-
{
356+
for (uint8_t port=1; port <= p_hub->port_count; port++) {
357+
if ( tu_bit_test(status_change, port) ) {
358+
if (hub_port_get_status(dev_addr, port, &p_hub->port_status, hub_port_get_status_complete, 0) == false) {
358359
//Hub status control transfer failed, retry
359360
hub_edpt_status_xfer(dev_addr);
360361
}
@@ -364,7 +365,6 @@ bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32
364365
}
365366

366367
// NOTE: next status transfer is queued by usbh.c after handling this request
367-
368368
return true;
369369
}
370370

0 commit comments

Comments
 (0)