add eth_device_linkchange function on ethnet interface.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1669 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
5a825fd81a
commit
2bc131f3a9
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue