diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index d0588a7b65..861d8cf118 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -644,6 +644,7 @@ menu "Using USB" if RT_USB_DEVICE_RNDIS config RNDIS_DELAY_LINK_UP bool "Delay linkup media connection" + select RT_USING_TIMER_SOFT default n endif diff --git a/components/drivers/usb/usbdevice/class/ecm.c b/components/drivers/usb/usbdevice/class/ecm.c index 9103493f2c..b98b5007f4 100644 --- a/components/drivers/usb/usbdevice/class/ecm.c +++ b/components/drivers/usb/usbdevice/class/ecm.c @@ -418,11 +418,16 @@ rt_err_t rt_ecm_eth_tx(rt_device_t dev, struct pbuf* p) USB_ETH_MTU, p->tot_len); p->tot_len = USB_ETH_MTU; } - result = rt_sem_take(&ecm_eth_dev->tx_buffer_free, RT_WAITING_FOREVER); + + result = rt_sem_take(&device->tx_buffer_free, rt_tick_from_millisecond(1000)); if(result != RT_EOK) { + LOG_W("wait for buffer free timeout"); + /* if cost 1s to wait send done it said that connection is close . drop it */ + rt_sem_release(&device->tx_buffer_free); return result; } + pbuffer = (char *)&ecm_eth_dev->tx_buffer; for (q = p; q != NULL; q = q->next) { @@ -473,10 +478,8 @@ static rt_err_t _function_enable(ufunction_t func) 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_offset = 0; - eth_device_ready(&ecm_device->parent); eps->ep_out->request.buffer = (void *)eps->ep_out->buffer; eps->ep_out->request.size = EP_MAXPACKET(eps->ep_out); @@ -499,10 +502,8 @@ static rt_err_t _function_disable(ufunction_t func) 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; } diff --git a/components/drivers/usb/usbdevice/class/rndis.c b/components/drivers/usb/usbdevice/class/rndis.c index c025f4ef6f..ec61234947 100644 --- a/components/drivers/usb/usbdevice/class/rndis.c +++ b/components/drivers/usb/usbdevice/class/rndis.c @@ -644,8 +644,6 @@ static rt_err_t _rndis_reset_response(ufunction_t func,rndis_set_msg_t msg) /* reset eth rx tx */ ((rt_rndis_eth_t)func->user_data)->rx_frist = RT_TRUE; ((rt_rndis_eth_t)func->user_data)->rx_flag = RT_FALSE; - rt_sem_release(&((rt_rndis_eth_t)func->user_data)->tx_buffer_free); - eth_device_ready(&(((rt_rndis_eth_t)func->user_data)->parent)); resp->MessageType = REMOTE_NDIS_RESET_CMPLT; @@ -719,9 +717,6 @@ static rt_err_t _rndis_msg_parser(ufunction_t func, rt_uint8_t *msg) /* reset eth rx tx */ ((rt_rndis_eth_t)func->user_data)->rx_frist = RT_TRUE; ((rt_rndis_eth_t)func->user_data)->rx_flag = RT_FALSE; - rt_sem_release(&((rt_rndis_eth_t)func->user_data)->tx_buffer_free); - eth_device_ready(&(((rt_rndis_eth_t)func->user_data)->parent)); - break; case REMOTE_NDIS_QUERY_MSG: @@ -964,7 +959,7 @@ static rt_err_t _function_enable(ufunction_t func) ((rt_rndis_eth_t)func->user_data)->rx_flag = RT_FALSE; ((rt_rndis_eth_t)func->user_data)->rx_frist = RT_TRUE; - eth_device_ready(&(((rt_rndis_eth_t)func->user_data)->parent)); + // eth_device_ready(&(((rt_rndis_eth_t)func->user_data)->parent)); #ifdef RNDIS_DELAY_LINK_UP /* stop link up timer. */ @@ -1034,8 +1029,6 @@ static rt_err_t _function_disable(ufunction_t func) /* reset eth rx tx */ ((rt_rndis_eth_t)func->user_data)->rx_frist = RT_TRUE; ((rt_rndis_eth_t)func->user_data)->rx_flag = RT_FALSE; - rt_sem_release(&((rt_rndis_eth_t)func->user_data)->tx_buffer_free); - eth_device_ready(&(((rt_rndis_eth_t)func->user_data)->parent)); return RT_EOK; } @@ -1173,7 +1166,7 @@ rt_err_t rt_rndis_eth_tx(rt_device_t dev, struct pbuf* p) return RT_EOK; } - RT_ASSERT(p->tot_len < sizeof(device->tx_buffer)); + //RT_ASSERT(p->tot_len < sizeof(device->tx_buffer)); if(p->tot_len > sizeof(device->tx_buffer)) { LOG_W("RNDIS MTU is:%d, but the send packet size is %d", @@ -1182,9 +1175,12 @@ rt_err_t rt_rndis_eth_tx(rt_device_t dev, struct pbuf* p) } /* wait for buffer free. */ - result = rt_sem_take(&device->tx_buffer_free, RT_WAITING_FOREVER); + result = rt_sem_take(&device->tx_buffer_free, rt_tick_from_millisecond(1000)); if(result != RT_EOK) { + LOG_W("wait for buffer free timeout"); + /* if cost 1s to wait send done it said that connection is close . drop it */ + rt_sem_release(&device->tx_buffer_free); return result; } @@ -1395,7 +1391,7 @@ ufunction_t rt_usbd_function_rndis_create(udevice_t device) timer_timeout, _rndis, RT_TICK_PER_SECOND * 2, - RT_TIMER_FLAG_ONE_SHOT); + RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); #endif /* RNDIS_DELAY_LINK_UP */ /* OUI 00-00-00, only for test. */