From 2bc131f3a9a9802196e3ba9f13113db0bb4200d1 Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Sun, 14 Aug 2011 12:56:30 +0000 Subject: [PATCH] add eth_device_linkchange function on ethnet interface. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1669 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/net/lwip/src/core/netif.c | 3 ++ .../net/lwip/src/include/lwip/netifapi.h | 3 ++ .../net/lwip/src/include/netif/ethernetif.h | 5 +++ components/net/lwip/src/lwipopts.h | 8 ++--- components/net/lwip/src/netif/ethernetif.c | 35 +++++++++++++++++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/components/net/lwip/src/core/netif.c b/components/net/lwip/src/core/netif.c index 48c69bcde9..df6b6faf38 100644 --- a/components/net/lwip/src/core/netif.c +++ b/components/net/lwip/src/core/netif.c @@ -471,6 +471,9 @@ void netif_set_status_callback(struct netif *netif, void (* status_callback)(str */ void netif_set_link_up(struct netif *netif ) { + /* not notify link up anymore */ + if (netif->flags & NETIF_FLAG_LINK_UP) return; + netif->flags |= NETIF_FLAG_LINK_UP; #if LWIP_DHCP diff --git a/components/net/lwip/src/include/lwip/netifapi.h b/components/net/lwip/src/include/lwip/netifapi.h index 4145dd740a..a9f63651c6 100644 --- a/components/net/lwip/src/include/lwip/netifapi.h +++ b/components/net/lwip/src/include/lwip/netifapi.h @@ -96,6 +96,9 @@ err_t netifapi_netif_common ( struct netif *netif, #define netifapi_autoip_start(n) netifapi_netif_common(n, NULL, autoip_start) #define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL, autoip_stop) +#define netifapi_netif_set_link_up(n) netifapi_netif_common(n, netif_set_link_up, NULL) +#define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL) + #ifdef __cplusplus } #endif diff --git a/components/net/lwip/src/include/netif/ethernetif.h b/components/net/lwip/src/include/netif/ethernetif.h index 2681de5605..87b38497d8 100644 --- a/components/net/lwip/src/include/netif/ethernetif.h +++ b/components/net/lwip/src/include/netif/ethernetif.h @@ -16,12 +16,17 @@ struct eth_device struct netif *netif; struct rt_semaphore tx_ack; + rt_uint16_t link_changed; + rt_uint16_t link_status; + /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p); }; +rt_err_t eth_rx_ready(struct eth_device* dev); rt_err_t eth_device_ready(struct eth_device* dev); +rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up); rt_err_t eth_device_init(struct eth_device* dev, const char* name); diff --git a/components/net/lwip/src/lwipopts.h b/components/net/lwip/src/lwipopts.h index c02c665088..a706d386ab 100644 --- a/components/net/lwip/src/lwipopts.h +++ b/components/net/lwip/src/lwipopts.h @@ -178,13 +178,13 @@ #define TCP_QUEUE_OOSEQ 1 /* TCP Maximum segment size. */ -#define TCP_MSS 1024 +#define TCP_MSS 1460 /* TCP sender buffer space (bytes). */ #ifdef RT_LWIP_TCP_SND_BUF #define TCP_SND_BUF RT_LWIP_TCP_SND_BUF #else -#define TCP_SND_BUF 2048 +#define TCP_SND_BUF (TCP_MSS * 2) #endif /* TCP sender buffer space (pbufs). This must be at least = 2 * @@ -198,9 +198,9 @@ /* TCP receive window. */ #ifdef RT_LWIP_TCP_WND -#define TCP_WND RT_LWIP_TCP_WND +#define TCP_WND RT_LWIP_TCP_WND #else -#define TCP_WND 1500 +#define TCP_WND (TCP_MSS * 2) #endif /* Maximum number of retransmissions of data segments. */ diff --git a/components/net/lwip/src/netif/ethernetif.c b/components/net/lwip/src/netif/ethernetif.c index 0eab86a36e..76660b04e7 100644 --- a/components/net/lwip/src/netif/ethernetif.c +++ b/components/net/lwip/src/netif/ethernetif.c @@ -188,6 +188,23 @@ void eth_rx_thread_entry(void* parameter) { struct pbuf *p; + /* check link status */ + if (device->link_changed) + { + int status; + rt_uint32_t level; + + level = rt_hw_interrupt_disable(); + status = device->link_status; + device->link_changed = 0x00; + rt_hw_interrupt_enable(level); + + if (status) + netifapi_netif_set_link_up(device->netif); + else + netifapi_netif_set_link_down(device->netif); + } + /* receive all of buffer */ while (1) { @@ -219,6 +236,24 @@ rt_err_t eth_device_ready(struct eth_device* dev) return eth_rx_ready(dev); } +rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) +{ + rt_uint32_t level; + + RT_ASSERT(dev != RT_NULL); + + level = rt_hw_interrupt_disable(); + dev->link_changed = 0x01; + if (up == RT_TRUE) + dev->link_status = 0x01; + else + dev->link_status = 0x00; + rt_hw_interrupt_enable(level); + + /* post message to ethernet thread */ + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); +} + rt_err_t eth_system_device_init() { rt_err_t result = RT_EOK;