mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-30 06:00:27 +08:00
Merge pull request #2768 from lymzzyh/rndis
[Components][USB][RNDIS/ECM] 修复热插拔鲁棒性和delay linkup 使用硬件定时器时报错的问题
This commit is contained in:
commit
97ea1a3b6e
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user