From 4bf0e126af2d0f9e9cc403f0f5590dc50e3e4e20 Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Fri, 3 May 2024 18:00:59 +0800 Subject: [PATCH] move usbh_hubport_release api to core --- class/hub/usbh_hub.c | 26 ++++++++------------------ core/usbh_core.c | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index 55a1e29d..116492dd 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -22,8 +22,8 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_buf[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(32, CONFIG_USB_ALIGN_SIZE)]; USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_intbuf[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_MAX_EXTHUBS + 1][USB_ALIGN_UP(1, CONFIG_USB_ALIGN_SIZE)]; -extern int usbh_free_devaddr(struct usbh_hubport *hport); extern int usbh_enumerate(struct usbh_hubport *hport); +extern void usbh_hubport_release(struct usbh_hubport *hport); static const char *speed_table[] = { "error-speed", "low-speed", "full-speed", "high-speed", "wireless-speed", "super-speed", "superplus-speed" }; @@ -280,22 +280,6 @@ static int usbh_hub_set_depth(struct usbh_hub *hub, uint16_t depth) } } -static void usbh_hubport_release(struct usbh_hubport *child) -{ - if (child->connected) { - child->connected = false; - usbh_free_devaddr(child); - for (uint8_t i = 0; i < child->config.config_desc.bNumInterfaces; i++) { - if (child->config.intf[i].class_driver && child->config.intf[i].class_driver->disconnect) { - CLASS_DISCONNECT(child, i); - } - } - child->config.config_desc.bNumInterfaces = 0; - usbh_kill_urb(&child->ep0_urb); - usb_osal_mutex_delete(child->mutex); - } -} - #if CONFIG_USBHOST_MAX_EXTHUBS > 0 static void hub_int_complete_callback(void *arg, int nbytes) { @@ -396,6 +380,10 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf) hub->int_buffer = g_hub_intbuf[hub->bus->busid][hub->index - 1]; hub->int_timer = usb_osal_timer_create("hubint_tim", USBH_GET_URB_INTERVAL(hub->intin->bInterval, hport->speed), hub_int_timeout, hub, 0); + if (hub->int_timer == NULL) { + USB_LOG_ERR("No memory to alloc int_timer\r\n"); + return -USB_ERR_NOMEM; + } usb_osal_timer_start(hub->int_timer); return 0; } @@ -412,7 +400,9 @@ static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf) usbh_kill_urb(&hub->intin_urb); } - usb_osal_timer_delete(hub->int_timer); + if (hub->int_timer) { + usb_osal_timer_delete(hub->int_timer); + } for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) { child = &hub->child[port]; diff --git a/core/usbh_core.c b/core/usbh_core.c index d451a572..521ea451 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -325,7 +325,7 @@ static int usbh_get_default_mps(int speed) } } -int usbh_free_devaddr(struct usbh_hubport *hport) +static int usbh_free_devaddr(struct usbh_hubport *hport) { #ifndef CONFIG_USBHOST_XHCI if (hport->dev_addr > 0) { @@ -641,6 +641,24 @@ errout: return ret; } +void usbh_hubport_release(struct usbh_hubport *hport) +{ + if (hport->connected) { + hport->connected = false; + usbh_free_devaddr(hport); + for (uint8_t i = 0; i < hport->config.config_desc.bNumInterfaces; i++) { + if (hport->config.intf[i].class_driver && hport->config.intf[i].class_driver->disconnect) { + CLASS_DISCONNECT(hport, i); + } + } + hport->config.config_desc.bNumInterfaces = 0; + usbh_kill_urb(&hport->ep0_urb); + if (hport->mutex) { + usb_osal_mutex_delete(hport->mutex); + } + } +} + static void usbh_bus_init(struct usbh_bus *bus, uint8_t busid, uint32_t reg_base) { struct usbh_hub *hub;