diff options
| author | sakumisu <[email protected]> | 2026-04-16 22:02:56 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2026-04-17 10:56:13 +0800 |
| commit | 3bd79e23648ac522ebfe9b17768bce7ea359b4a5 (patch) | |
| tree | 2a09437f513d0e30dd26c3803758584026ba6d85 | |
| parent | 963a01f2ee0807650092f9fed382a0e6aa1306a4 (diff) | |
fix(class/hub): remove bus mutex, replace with mq to exit thread
Signed-off-by: sakumisu <[email protected]>
| -rw-r--r-- | class/hub/usbh_hub.c | 46 | ||||
| -rw-r--r-- | core/usbh_core.c | 1 | ||||
| -rw-r--r-- | core/usbh_core.h | 2 |
3 files changed, 26 insertions, 23 deletions
diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index cef8d55b..bce8fd82 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -677,6 +677,7 @@ static void usbh_hub_events(struct usbh_hub *hub) static void usbh_hub_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { struct usbh_hub *hub; + struct usbh_hubport *hport; int ret = 0; struct usbh_bus *bus = (struct usbh_bus *)CONFIG_USB_OSAL_THREAD_GET_ARGV; @@ -689,10 +690,23 @@ static void usbh_hub_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) if (ret < 0) { continue; } - usb_osal_mutex_take(bus->mutex); + if (hub == NULL) { + break; + } usbh_hub_events(hub); - usb_osal_mutex_give(bus->mutex); } + + hub = &bus->hcd.roothub; + for (uint8_t port = 0; port < hub->nports; port++) { + hport = &hub->child[port]; + + usbh_hubport_release(hport); + } + usb_hc_deinit(bus); + usb_osal_mq_delete(bus->hub_mq); + bus->hub_mq = NULL; + usb_osal_sem_give(bus->hub_sem); + usb_osal_thread_delete(NULL); } void usbh_hub_thread_wakeup(struct usbh_hub *hub) @@ -721,9 +735,9 @@ int usbh_hub_initialize(struct usbh_bus *bus) return -1; } - bus->mutex = usb_osal_mutex_create(); - if (bus->mutex == NULL) { - USB_LOG_ERR("Failed to create bus mutex\r\n"); + bus->hub_sem = usb_osal_sem_create(0); + if (bus->hub_sem == NULL) { + USB_LOG_ERR("Failed to create hub sem\r\n"); return -1; } @@ -738,24 +752,14 @@ int usbh_hub_initialize(struct usbh_bus *bus) int usbh_hub_deinitialize(struct usbh_bus *bus) { - struct usbh_hubport *hport; - struct usbh_hub *hub; - - usb_osal_mutex_take(bus->mutex); - hub = &bus->hcd.roothub; - for (uint8_t port = 0; port < hub->nports; port++) { - hport = &hub->child[port]; - - usbh_hubport_release(hport); + if (!bus->hub_mq || !bus->hub_sem) { + return -USB_ERR_INVAL; } + usb_osal_mq_send(bus->hub_mq, (uintptr_t)NULL); + usb_osal_sem_take(bus->hub_sem, USB_OSAL_WAITING_FOREVER); + usb_osal_sem_delete(bus->hub_sem); + bus->event_handler(bus->busid, USB_HUB_INDEX_ANY, USB_HUB_PORT_ANY, USB_INTERFACE_ANY, USBH_EVENT_DEINIT); - usb_hc_deinit(bus); - - usb_osal_thread_delete(bus->hub_thread); - usb_osal_mq_delete(bus->hub_mq); - - usb_osal_mutex_give(bus->mutex); - usb_osal_mutex_delete(bus->mutex); return 0; } diff --git a/core/usbh_core.c b/core/usbh_core.c index 966bafa5..34f2ab05 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -667,7 +667,6 @@ int usbh_deinitialize(uint8_t busid) bus = &g_usbhost_bus[busid]; usbh_hub_deinitialize(bus); - bus->event_handler(bus->busid, USB_HUB_INDEX_ANY, USB_HUB_PORT_ANY, USB_INTERFACE_ANY, USBH_EVENT_DEINIT); usb_slist_remove(&g_bus_head, &bus->list); diff --git a/core/usbh_core.h b/core/usbh_core.h index bc8eab8f..abd193df 100644 --- a/core/usbh_core.h +++ b/core/usbh_core.h @@ -203,7 +203,7 @@ struct usbh_bus { struct usbh_devaddr_map devgen; usb_osal_thread_t hub_thread; usb_osal_mq_t hub_mq; - usb_osal_mutex_t mutex; + usb_osal_sem_t hub_sem; usbh_event_handler_t event_handler; }; |
