Merge pull request #4523 from xiangxistu/master

[fix] the overflow problem of lwip rx thread mailbox.
This commit is contained in:
Bernard Xiong 2021-04-19 13:35:22 +08:00 committed by GitHub
commit 18ccf1d182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 14 deletions

View File

@ -7,3 +7,6 @@ file_path:
dir_path: dir_path:
- tools - tools
- components/net/lwip-1.4.1
- components/net/lwip-2.0.2
- components/net/lwip-2.1.2

View File

@ -27,6 +27,7 @@ struct eth_device
rt_uint16_t flags; rt_uint16_t flags;
rt_uint8_t link_changed; rt_uint8_t link_changed;
rt_uint8_t link_status; rt_uint8_t link_status;
rt_uint8_t rx_notice;
/* eth device interface */ /* eth device interface */
struct pbuf* (*eth_rx)(rt_device_t dev); struct pbuf* (*eth_rx)(rt_device_t dev);

View File

@ -469,6 +469,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
dev->flags = flags; dev->flags = flags;
/* link changed status of device */ /* link changed status of device */
dev->link_changed = 0x00; dev->link_changed = 0x00;
/* avoid send the same mail to mailbox */
dev->rx_notice = 0x00;
dev->parent.type = RT_Device_Class_NetIf; dev->parent.type = RT_Device_Class_NetIf;
/* register to RT-Thread device manager */ /* register to RT-Thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
@ -550,10 +552,18 @@ rt_err_t eth_device_init(struct eth_device * dev, const char *name)
rt_err_t eth_device_ready(struct eth_device* dev) rt_err_t eth_device_ready(struct eth_device* dev)
{ {
if (dev->netif) if (dev->netif)
{
if(dev->rx_notice == RT_FALSE)
{
dev->rx_notice = RT_TRUE;
return rt_mb_send(&eth_rx_thread_mb, (rt_uint32_t)dev);
}
else
return RT_EOK;
/* post message to Ethernet thread */ /* post message to Ethernet thread */
return rt_mb_send(&eth_rx_thread_mb, (rt_uint32_t)dev); }
else else
return ERR_OK; /* netif is not initialized yet, just return. */ return -RT_ERROR; /* netif is not initialized yet, just return. */
} }
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
@ -628,6 +638,7 @@ static void eth_rx_thread_entry(void* parameter)
{ {
if (rt_mb_recv(&eth_rx_thread_mb, (rt_ubase_t*)&device, RT_WAITING_FOREVER) == RT_EOK) if (rt_mb_recv(&eth_rx_thread_mb, (rt_ubase_t*)&device, RT_WAITING_FOREVER) == RT_EOK)
{ {
rt_base_t level;
struct pbuf *p; struct pbuf *p;
/* check link status */ /* check link status */
@ -647,8 +658,13 @@ static void eth_rx_thread_entry(void* parameter)
netifapi_netif_set_link_down(device->netif); netifapi_netif_set_link_down(device->netif);
} }
level = rt_hw_interrupt_disable();
/* 'rx_notice' will be modify in the interrupt or here */
device->rx_notice = RT_FALSE;
rt_hw_interrupt_enable(level);
/* receive all of buffer */ /* receive all of buffer */
while (1) while(1)
{ {
if(device->eth_rx == RT_NULL) break; if(device->eth_rx == RT_NULL) break;

View File

@ -27,6 +27,7 @@ struct eth_device
rt_uint16_t flags; rt_uint16_t flags;
rt_uint8_t link_changed; rt_uint8_t link_changed;
rt_uint8_t link_status; rt_uint8_t link_status;
rt_uint8_t rx_notice;
/* eth device interface */ /* eth device interface */
struct pbuf* (*eth_rx)(rt_device_t dev); struct pbuf* (*eth_rx)(rt_device_t dev);

View File

@ -511,6 +511,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
dev->flags = flags; dev->flags = flags;
/* link changed status of device */ /* link changed status of device */
dev->link_changed = 0x00; dev->link_changed = 0x00;
/* avoid send the same mail to mailbox */
dev->rx_notice = 0x00;
dev->parent.type = RT_Device_Class_NetIf; dev->parent.type = RT_Device_Class_NetIf;
/* register to RT-Thread device manager */ /* register to RT-Thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
@ -599,10 +601,18 @@ void eth_device_deinit(struct eth_device *dev)
rt_err_t eth_device_ready(struct eth_device* dev) rt_err_t eth_device_ready(struct eth_device* dev)
{ {
if (dev->netif) if (dev->netif)
{
if(dev->rx_notice == RT_FALSE)
{
dev->rx_notice = RT_TRUE;
return rt_mb_send(&eth_rx_thread_mb, (rt_uint32_t)dev);
}
else
return RT_EOK;
/* post message to Ethernet thread */ /* post message to Ethernet thread */
return rt_mb_send(&eth_rx_thread_mb, (rt_ubase_t)dev); }
else else
return ERR_OK; /* netif is not initialized yet, just return. */ return -RT_ERROR; /* netif is not initialized yet, just return. */
} }
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
@ -677,6 +687,7 @@ static void eth_rx_thread_entry(void* parameter)
{ {
if (rt_mb_recv(&eth_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) if (rt_mb_recv(&eth_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK)
{ {
rt_base_t level;
struct pbuf *p; struct pbuf *p;
/* check link status */ /* check link status */
@ -696,8 +707,13 @@ static void eth_rx_thread_entry(void* parameter)
netifapi_netif_set_link_down(device->netif); netifapi_netif_set_link_down(device->netif);
} }
level = rt_hw_interrupt_disable();
/* 'rx_notice' will be modify in the interrupt or here */
device->rx_notice = RT_FALSE;
rt_hw_interrupt_enable(level);
/* receive all of buffer */ /* receive all of buffer */
while (1) while(1)
{ {
if(device->eth_rx == RT_NULL) break; if(device->eth_rx == RT_NULL) break;

View File

@ -27,6 +27,7 @@ struct eth_device
rt_uint16_t flags; rt_uint16_t flags;
rt_uint8_t link_changed; rt_uint8_t link_changed;
rt_uint8_t link_status; rt_uint8_t link_status;
rt_uint8_t rx_notice;
/* eth device interface */ /* eth device interface */
struct pbuf* (*eth_rx)(rt_device_t dev); struct pbuf* (*eth_rx)(rt_device_t dev);

View File

@ -514,6 +514,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
dev->flags = flags; dev->flags = flags;
/* link changed status of device */ /* link changed status of device */
dev->link_changed = 0x00; dev->link_changed = 0x00;
/* avoid send the same mail to mailbox */
dev->rx_notice = 0x00;
dev->parent.type = RT_Device_Class_NetIf; dev->parent.type = RT_Device_Class_NetIf;
/* register to RT-Thread device manager */ /* register to RT-Thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
@ -601,10 +603,18 @@ void eth_device_deinit(struct eth_device *dev)
rt_err_t eth_device_ready(struct eth_device* dev) rt_err_t eth_device_ready(struct eth_device* dev)
{ {
if (dev->netif) if (dev->netif)
{
if(dev->rx_notice == RT_FALSE)
{
dev->rx_notice = RT_TRUE;
return rt_mb_send(&eth_rx_thread_mb, (rt_uint32_t)dev);
}
else
return RT_EOK;
/* post message to Ethernet thread */ /* post message to Ethernet thread */
return rt_mb_send(&eth_rx_thread_mb, (rt_uint32_t)dev); }
else else
return ERR_OK; /* netif is not initialized yet, just return. */ return -RT_ERROR; /* netif is not initialized yet, just return. */
} }
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
@ -679,6 +689,7 @@ static void eth_rx_thread_entry(void* parameter)
{ {
if (rt_mb_recv(&eth_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) if (rt_mb_recv(&eth_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK)
{ {
rt_base_t level;
struct pbuf *p; struct pbuf *p;
/* check link status */ /* check link status */
@ -698,6 +709,11 @@ static void eth_rx_thread_entry(void* parameter)
netifapi_netif_set_link_down(device->netif); netifapi_netif_set_link_down(device->netif);
} }
level = rt_hw_interrupt_disable();
/* 'rx_notice' will be modify in the interrupt or here */
device->rx_notice = RT_FALSE;
rt_hw_interrupt_enable(level);
/* receive all of buffer */ /* receive all of buffer */
while (1) while (1)
{ {