diff --git a/tests/test/host/ehci/test_ehci_usbh_hcd_integration.c b/tests/test/host/ehci/test_ehci_usbh_hcd_integration.c index a830f9509..db44746d3 100644 --- a/tests/test/host/ehci/test_ehci_usbh_hcd_integration.c +++ b/tests/test/host/ehci/test_ehci_usbh_hcd_integration.c @@ -184,12 +184,10 @@ void test_device_unplugged_status(void) { ehci_controller_device_unplug(hostid); hcd_isr(hostid); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_REMOVING, usbh_device_info_pool[dev_addr].status); regs->usb_sts_bit.async_advance = 1; hcd_isr(hostid); // async advance - //------------- Code Under Test -------------// - - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_REMOVING, usbh_device_info_pool[dev_addr].status); - + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_UNPLUG, usbh_device_info_pool[dev_addr].status); } diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 92c439ff8..e94793254 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -183,6 +183,9 @@ void async_advance_isr(ehci_qhd_t * const async_head) p_control_qhd->is_removing = 0; p_control_qhd->used = 0; p_control_qhd->p_qtd_list_head = p_control_qhd->p_qtd_list_tail = NULL; + + // TODO abstract: Host Controller has cleaned up its data for this device, notify usbh + usbh_device_hcd_data_cleaned_up_cb(relative_dev_addr+1); } // check if any other endpoints in pool is removing diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index a70ba28bd..f871d8979 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -225,11 +225,15 @@ void usbh_device_unplugged_isr(uint8_t hostid) usbh_pipe_control_close(dev_addr); - // set to REMOVING to prevent allocate to other new device - // need to set to UNPLUGGED by HCD after freeing all resources + // set to REMOVING to end wait for HCD to clean up its cached data for this device usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_REMOVING; } +// HCD cleaned up cached data for this device +void usbh_device_hcd_data_cleaned_up_cb(uint8_t dev_addr) +{ + usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_UNPLUG; +} //--------------------------------------------------------------------+ // ENUMERATION TASK diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h index bbcad3611..47f1b32d4 100644 --- a/tinyusb/host/usbh_hcd.h +++ b/tinyusb/host/usbh_hcd.h @@ -103,7 +103,7 @@ extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; // void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code); void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed); void usbh_device_unplugged_isr(uint8_t hostid); - +void usbh_device_hcd_data_cleaned_up_cb(uint8_t dev_addr); // hcd called this function when it cleaned all its cached data for this device #ifdef __cplusplus }