提交 7a75e449 编写于 作者: lymzzyh's avatar lymzzyh

[Components][USB][ECM] fix hotplug

上级 cc9ce52b
...@@ -6,17 +6,16 @@ ...@@ -6,17 +6,16 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2017-11-19 ZYH first version * 2017-11-19 ZYH first version
* 2019-06-10 ZYH fix hotplug
*/ */
#include <rtdevice.h> #include <rtdevice.h>
#ifdef RT_USB_DEVICE_ECM
#include "cdc.h" #include "cdc.h"
#define DBG_LEVEL DBG_WARNING
#ifdef ECM_DEBUG #define DBG_SECTION_NAME "ECM"
#define ECM_PRINTF rt_kprintf("[ECM] "); rt_kprintf #include <rtdbg.h>
#else
#define ECM_PRINTF(...)
#endif /* ECM_DEBUG */
/* RT-Thread LWIP ethernet interface */ /* RT-Thread LWIP ethernet interface */
#include <netif/ethernetif.h> #include <netif/ethernetif.h>
...@@ -216,15 +215,21 @@ static rt_err_t _cdc_send_notifi(ufunction_t func,ucdc_notification_code_t notif ...@@ -216,15 +215,21 @@ static rt_err_t _cdc_send_notifi(ufunction_t func,ucdc_notification_code_t notif
return RT_EOK; return RT_EOK;
} }
static rt_err_t _ecm_set_eth_packet_filter(ufunction_t func, ureq_t setup) static rt_err_t _ecm_set_eth_packet_filter(ufunction_t func, ureq_t setup)
{ {
rt_ecm_eth_t _ecm_eth = (rt_ecm_eth_t)func->user_data; rt_ecm_eth_t _ecm_eth = (rt_ecm_eth_t)func->user_data;
dcd_ep0_send_status(func->device->dcd); dcd_ep0_send_status(func->device->dcd);
/* send link up. */ /* send link up. */
eth_device_linkchange(&_ecm_eth->parent, RT_TRUE); eth_device_linkchange(&_ecm_eth->parent, RT_TRUE);
_cdc_send_notifi(func,UCDC_NOTIFI_NETWORK_CONNECTION,1,0); _cdc_send_notifi(func, UCDC_NOTIFI_NETWORK_CONNECTION, 1, 0);
#ifdef LWIP_USING_DHCPD
extern void dhcpd_start(const char *netif_name);
dhcpd_start("u0");
#endif
return RT_EOK; return RT_EOK;
} }
/** /**
...@@ -243,10 +248,11 @@ static rt_err_t _interface_handler(ufunction_t func, ureq_t setup) ...@@ -243,10 +248,11 @@ static rt_err_t _interface_handler(ufunction_t func, ureq_t setup)
switch(setup->bRequest) switch(setup->bRequest)
{ {
case CDC_SET_ETH_PACKET_FILTER: case CDC_SET_ETH_PACKET_FILTER:
LOG_D("CDC_SET_ETH_PACKET_FILTER");
_ecm_set_eth_packet_filter(func, setup); _ecm_set_eth_packet_filter(func, setup);
break; break;
default: default:
rt_kprintf("setup->bRequest:0x%02X",setup->bRequest); LOG_E("Unknow setup->bRequest: 0x%02X", setup->bRequest);
break; break;
} }
return RT_EOK; return RT_EOK;
...@@ -402,14 +408,13 @@ rt_err_t rt_ecm_eth_tx(rt_device_t dev, struct pbuf* p) ...@@ -402,14 +408,13 @@ rt_err_t rt_ecm_eth_tx(rt_device_t dev, struct pbuf* p)
if(!ecm_eth_dev->parent.link_status) if(!ecm_eth_dev->parent.link_status)
{ {
ECM_PRINTF("linkdown, drop pkg\r\n"); LOG_D("linkdown, drop pkg");
return RT_EOK; return RT_EOK;
} }
// RT_ASSERT(p->tot_len < USB_ETH_MTU);
if(p->tot_len > USB_ETH_MTU) if(p->tot_len > USB_ETH_MTU)
{ {
ECM_PRINTF("RNDIS MTU is:%d, but the send packet size is %d\r\n", LOG_W("ECM MTU is:%d, but the send packet size is %d",
USB_ETH_MTU, p->tot_len); USB_ETH_MTU, p->tot_len);
p->tot_len = USB_ETH_MTU; p->tot_len = USB_ETH_MTU;
} }
...@@ -461,10 +466,17 @@ static rt_err_t _function_enable(ufunction_t func) ...@@ -461,10 +466,17 @@ static rt_err_t _function_enable(ufunction_t func)
{ {
cdc_eps_t eps; cdc_eps_t eps;
rt_ecm_eth_t ecm_device = (rt_ecm_eth_t)func->user_data; rt_ecm_eth_t ecm_device = (rt_ecm_eth_t)func->user_data;
LOG_D("plugged in");
eps = (cdc_eps_t)&ecm_device->eps; eps = (cdc_eps_t)&ecm_device->eps;
eps->ep_out->buffer = ecm_device->rx_pool; eps->ep_out->buffer = ecm_device->rx_pool;
/* reset eth rx tx */
rt_sem_release(&ecm_device->tx_buffer_free);
ecm_device->rx_size = 0; ecm_device->rx_size = 0;
ecm_device->rx_offset = 0; ecm_device->rx_offset = 0;
eth_device_ready(&ecm_device->parent);
eps->ep_out->request.buffer = (void *)eps->ep_out->buffer; eps->ep_out->request.buffer = (void *)eps->ep_out->buffer;
eps->ep_out->request.size = EP_MAXPACKET(eps->ep_out); eps->ep_out->request.size = EP_MAXPACKET(eps->ep_out);
...@@ -482,7 +494,16 @@ static rt_err_t _function_enable(ufunction_t func) ...@@ -482,7 +494,16 @@ static rt_err_t _function_enable(ufunction_t func)
*/ */
static rt_err_t _function_disable(ufunction_t func) static rt_err_t _function_disable(ufunction_t func)
{ {
LOG_D("plugged out");
eth_device_linkchange(&((rt_ecm_eth_t)func->user_data)->parent, RT_FALSE); eth_device_linkchange(&((rt_ecm_eth_t)func->user_data)->parent, RT_FALSE);
/* reset eth rx tx */
rt_sem_release(&((rt_ecm_eth_t)func->user_data)->tx_buffer_free);
((rt_ecm_eth_t)func->user_data)->rx_size = 0;
((rt_ecm_eth_t)func->user_data)->rx_offset = 0;
eth_device_ready(&((rt_ecm_eth_t)func->user_data)->parent);
return RT_EOK; return RT_EOK;
} }
...@@ -643,3 +664,5 @@ int rt_usbd_ecm_class_register(void) ...@@ -643,3 +664,5 @@ int rt_usbd_ecm_class_register(void)
return 0; return 0;
} }
INIT_PREV_EXPORT(rt_usbd_ecm_class_register); INIT_PREV_EXPORT(rt_usbd_ecm_class_register);
#endif /* RT_USB_DEVICE_ECM */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册