diff options
| author | sakumisu <[email protected]> | 2023-11-21 20:20:21 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2023-11-22 19:28:30 +0800 |
| commit | 03db11f4af29ccb0cf02c3eed133f8554de183d8 (patch) | |
| tree | c113ee4bb044cadcb3f0992b0b83ff0f8cd5f4cb /class | |
| parent | d6bd89f274cf84bb1ca0de4bce39a060f5a2db13 (diff) | |
add ecm and rndis thread delete for dynamic netif
Diffstat (limited to 'class')
| -rw-r--r-- | class/cdc/usbh_cdc_ecm.c | 7 | ||||
| -rw-r--r-- | class/cdc/usbh_cdc_ecm.h | 3 | ||||
| -rw-r--r-- | class/wireless/usbh_rndis.c | 14 | ||||
| -rw-r--r-- | class/wireless/usbh_rndis.h | 3 |
4 files changed, 22 insertions, 5 deletions
diff --git a/class/cdc/usbh_cdc_ecm.c b/class/cdc/usbh_cdc_ecm.c index 6ca59a38..4e435f33 100644 --- a/class/cdc/usbh_cdc_ecm.c +++ b/class/cdc/usbh_cdc_ecm.c @@ -304,7 +304,12 @@ err_t usbh_cdc_ecm_linkoutput(struct netif *netif, struct pbuf *p) void usbh_cdc_ecm_lwip_thread_init(struct netif *netif) { - usb_osal_thread_create("usbh_cdc_ecm_rx", 2048, CONFIG_USBHOST_PSC_PRIO + 1, usbh_cdc_ecm_rx_thread, 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); } __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 7d65da0b..27843004 100644 --- a/class/cdc/usbh_cdc_ecm.h +++ b/class/cdc/usbh_cdc_ecm.h @@ -32,6 +32,8 @@ struct usbh_cdc_ecm { ip_addr_t ipaddr; ip_addr_t netmask; ip_addr_t gateway; + + usb_osal_thread_t thread; }; #ifdef __cplusplus @@ -43,6 +45,7 @@ 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 2437da78..daf3d3e7 100644 --- a/class/wireless/usbh_rndis.c +++ b/class/wireless/usbh_rndis.c @@ -507,6 +507,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); @@ -517,9 +518,9 @@ err_t usbh_rndis_linkoutput(struct netif *netif, struct pbuf *p) memcpy(buffer, q->payload, q->len); buffer += q->len; } - /* send */ - if ((hdr->MessageLength & 0x1FF) == 0) { - /* pad a dummy. */ + + /* if message length is the multiple of wMaxPacketSize, we should add a short packet to tell device transfer is over. */ + if (!(hdr->MessageLength % g_rndis_class.bulkout->wMaxPacketSize)) { hdr->MessageLength += 1; } @@ -536,7 +537,12 @@ err_t usbh_rndis_linkoutput(struct netif *netif, struct pbuf *p) void usbh_rndis_lwip_thread_init(struct netif *netif) { - usb_osal_thread_create("usbh_rndis_rx", 2560, CONFIG_USBHOST_PSC_PRIO + 1, usbh_rndis_rx_thread, 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); } __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 c55c113f..95b011dc 100644 --- a/class/wireless/usbh_rndis.h +++ b/class/wireless/usbh_rndis.h @@ -33,6 +33,8 @@ struct usbh_rndis { ip_addr_t ipaddr; ip_addr_t netmask; ip_addr_t gateway; + + usb_osal_thread_t thread; }; #ifdef __cplusplus @@ -46,6 +48,7 @@ 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 } |
