diff --git a/class/cdc/usbh_cdc_ecm.c b/class/cdc/usbh_cdc_ecm.c index af8816b8..cc016491 100644 --- a/class/cdc/usbh_cdc_ecm.c +++ b/class/cdc/usbh_cdc_ecm.c @@ -230,12 +230,13 @@ static void usbh_cdc_ecm_rx_thread(void *argument) struct pbuf *p; struct netif *netif = (struct netif *)argument; + USB_LOG_INFO("Create cdc ecm rx thread\r\n"); // clang-format off find_class: // clang-format on g_cdc_ecm_class.connect_status = false; - while (usbh_find_class_instance("/dev/cdc_ether") == NULL) { - usb_osal_msleep(1000); + if (usbh_find_class_instance("/dev/cdc_ether") == NULL) { + goto delete; } while (g_cdc_ecm_class.connect_status == false) { @@ -275,6 +276,9 @@ find_class: } else { } } +delete: + USB_LOG_INFO("Delete cdc ecm rx thread\r\n"); + usb_osal_thread_delete(NULL); } err_t usbh_cdc_ecm_linkoutput(struct netif *netif, struct pbuf *p) @@ -305,12 +309,7 @@ err_t usbh_cdc_ecm_linkoutput(struct netif *netif, struct pbuf *p) void usbh_cdc_ecm_lwip_thread_init(struct netif *netif) { - g_cdc_ecm_class.thread = usb_osal_thread_create("usbh_cdc_ecm_rx", 2048, CONFIG_USBHOST_PSC_PRIO + 1, usbh_cdc_ecm_rx_thread, netif); -} - -void usbh_cdc_ecm_lwip_thread_deinit(void) -{ - usb_osal_thread_delete(g_cdc_ecm_class.thread); + usb_osal_thread_create("usbh_cdc_ecm_rx", 2048, CONFIG_USBHOST_PSC_PRIO + 1, usbh_cdc_ecm_rx_thread, netif); } __WEAK void usbh_cdc_ecm_run(struct usbh_cdc_ecm *cdc_ecm_class) diff --git a/class/cdc/usbh_cdc_ecm.h b/class/cdc/usbh_cdc_ecm.h index 27843004..7d65da0b 100644 --- a/class/cdc/usbh_cdc_ecm.h +++ b/class/cdc/usbh_cdc_ecm.h @@ -32,8 +32,6 @@ struct usbh_cdc_ecm { ip_addr_t ipaddr; ip_addr_t netmask; ip_addr_t gateway; - - usb_osal_thread_t thread; }; #ifdef __cplusplus @@ -45,7 +43,6 @@ void usbh_cdc_ecm_stop(struct usbh_cdc_ecm *cdc_ecm_class); err_t usbh_cdc_ecm_linkoutput(struct netif *netif, struct pbuf *p); void usbh_cdc_ecm_lwip_thread_init(struct netif *netif); -void usbh_cdc_ecm_lwip_thread_deinit(void); #ifdef __cplusplus } diff --git a/class/wireless/usbh_rndis.c b/class/wireless/usbh_rndis.c index ba458be2..c1c308a1 100644 --- a/class/wireless/usbh_rndis.c +++ b/class/wireless/usbh_rndis.c @@ -434,12 +434,13 @@ static void usbh_rndis_rx_thread(void *argument) rndis_data_packet_t temp; struct netif *netif = (struct netif *)argument; + USB_LOG_INFO("Create rndis rx thread\r\n"); // clang-format off find_class: // clang-format on g_rndis_class.link_status = false; - while (usbh_find_class_instance("/dev/rndis") == NULL) { - usb_osal_msleep(1000); + if (usbh_find_class_instance("/dev/rndis") == NULL) { + goto delete; } while (g_rndis_class.link_status == false) { @@ -494,6 +495,9 @@ find_class: } } } +delete: + USB_LOG_INFO("Delete rndis rx thread\r\n"); + usb_osal_thread_delete(NULL); } err_t usbh_rndis_linkoutput(struct netif *netif, struct pbuf *p) @@ -509,7 +513,7 @@ err_t usbh_rndis_linkoutput(struct netif *netif, struct pbuf *p) hdr = (rndis_data_packet_t *)g_rndis_tx_buffer; memset(hdr, 0, sizeof(rndis_data_packet_t)); - + hdr->MessageType = REMOTE_NDIS_PACKET_MSG; hdr->MessageLength = sizeof(rndis_data_packet_t) + p->tot_len; hdr->DataOffset = sizeof(rndis_data_packet_t) - sizeof(rndis_generic_msg_t); @@ -539,12 +543,7 @@ err_t usbh_rndis_linkoutput(struct netif *netif, struct pbuf *p) void usbh_rndis_lwip_thread_init(struct netif *netif) { - g_rndis_class.thread = usb_osal_thread_create("usbh_rndis_rx", 2560, CONFIG_USBHOST_PSC_PRIO + 1, usbh_rndis_rx_thread, netif); -} - -void usbh_rndis_lwip_thread_deinit(void) -{ - usb_osal_thread_delete(g_rndis_class.thread); + usb_osal_thread_create("usbh_rndis_rx", 2560, CONFIG_USBHOST_PSC_PRIO + 1, usbh_rndis_rx_thread, netif); } __WEAK void usbh_rndis_run(struct usbh_rndis *rndis_class) diff --git a/class/wireless/usbh_rndis.h b/class/wireless/usbh_rndis.h index 95b011dc..c55c113f 100644 --- a/class/wireless/usbh_rndis.h +++ b/class/wireless/usbh_rndis.h @@ -33,8 +33,6 @@ struct usbh_rndis { ip_addr_t ipaddr; ip_addr_t netmask; ip_addr_t gateway; - - usb_osal_thread_t thread; }; #ifdef __cplusplus @@ -48,7 +46,6 @@ void usbh_rndis_stop(struct usbh_rndis *rndis_class); err_t usbh_rndis_linkoutput(struct netif *netif, struct pbuf *p); void usbh_rndis_lwip_thread_init(struct netif *netif); -void usbh_rndis_lwip_thread_deinit(void); #ifdef __cplusplus } diff --git a/demo/usb_host.c b/demo/usb_host.c index 963b13a3..6dc93943 100644 --- a/demo/usb_host.c +++ b/demo/usb_host.c @@ -487,7 +487,6 @@ void usbh_cdc_ecm_stop(struct usbh_cdc_ecm *cdc_ecm_class) netif_set_down(netif); netif_remove(netif); #endif - usbh_cdc_ecm_lwip_thread_deinit(); } #endif @@ -513,7 +512,7 @@ void timer_init(struct usbh_rndis *rndis_class) keep_timer = rt_timer_create("keep", rndis_dev_keepalive_timeout, rndis_class, - 3000, + 5000, RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER); @@ -531,7 +530,7 @@ static void rndis_dev_keepalive_timeout(TimerHandle_t xTimer) void timer_init(struct usbh_rndis *rndis_class) { - timer_handle = xTimerCreate((const char *)NULL, (TickType_t)3000, (UBaseType_t)pdTRUE, (void *const)rndis_class, (TimerCallbackFunction_t)rndis_dev_keepalive_timeout); + timer_handle = xTimerCreate((const char *)NULL, (TickType_t)5000, (UBaseType_t)pdTRUE, (void *const)rndis_class, (TimerCallbackFunction_t)rndis_dev_keepalive_timeout); if (NULL != timer_handle) { xTimerStart(timer_handle, 0); } else { @@ -615,7 +614,6 @@ void usbh_rndis_stop(struct usbh_rndis *rndis_class) xTimerStop(timer_handle, 0); xTimerDelete(timer_handle, 0); #endif - usbh_rndis_lwip_thread_deinit(); } #endif