From 217c6d88f5b40d007227bf182c359919713a6137 Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Fri, 1 Jul 2011 12:53:21 +0000 Subject: [PATCH] open LWIP_NETIF_LINK_CALLBACK definitions git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1573 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/net/lwip/src/arch/sys_arch.c | 104 ++++----------------- components/net/lwip/src/lwipopts.h | 14 +-- components/net/lwip/src/netif/ethernetif.c | 16 ++++ 3 files changed, 41 insertions(+), 93 deletions(-) diff --git a/components/net/lwip/src/arch/sys_arch.c b/components/net/lwip/src/arch/sys_arch.c index 8dec97328e..e878a70e30 100644 --- a/components/net/lwip/src/arch/sys_arch.c +++ b/components/net/lwip/src/arch/sys_arch.c @@ -9,6 +9,7 @@ #include #define LWIP_THREAD_MAGIC 0x1919 +#define LWIP_THREAD_NAME (rt_thread_self()->name) struct lwip_thread { rt_uint32_t magic; @@ -31,14 +32,7 @@ sys_sem_t sys_sem_new(u8_t count) rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_SEM_NAME, counter); -#if SYS_DEBUG - { - struct rt_thread *thread; - - thread = rt_thread_self(); - LWIP_DEBUGF(SYS_DEBUG, ("%s, Create sem: %s \n",thread->name, tname)); - } -#endif + LWIP_DEBUGF(SYS_DEBUG, ("%s, Create sem: %s \n", LWIP_THREAD_NAME, tname)); counter++; @@ -47,15 +41,8 @@ sys_sem_t sys_sem_new(u8_t count) void sys_sem_free(sys_sem_t sem) { -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); - - LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete sem: %s \n",thread->name, + LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete sem: %s \n", LWIP_THREAD_NAME, sem->parent.parent.name)); - } -#endif rt_sem_delete(sem); @@ -64,15 +51,8 @@ void sys_sem_free(sys_sem_t sem) void sys_sem_signal(sys_sem_t sem) { -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); - - LWIP_DEBUGF(SYS_DEBUG, ("%s, Release signal: %s , %d\n",thread->name, + LWIP_DEBUGF(SYS_DEBUG, ("%s, Release signal: %s , %d\n", LWIP_THREAD_NAME, sem->parent.parent.name, sem->value)); - } -#endif rt_sem_release(sem); @@ -87,15 +67,8 @@ u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout) /* get the begin tick */ tick = rt_tick_get(); -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); - - LWIP_DEBUGF(SYS_DEBUG, ("%s, Wait sem: %s , %d\n",thread->name, + LWIP_DEBUGF(SYS_DEBUG, ("%s, Wait sem: %s , %d\n", LWIP_THREAD_NAME, sem->parent.parent.name, sem->value)); - } -#endif if(timeout == 0) t = RT_WAITING_FOREVER; @@ -127,15 +100,7 @@ sys_mbox_t sys_mbox_new(int size) char tname[RT_NAME_MAX]; rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MBOX_NAME, counter); - -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); - - LWIP_DEBUGF(SYS_DEBUG, ("%s, Create mbox: %s \n",thread->name, tname)); - } -#endif + LWIP_DEBUGF(SYS_DEBUG, ("%s, Create mbox: %s \n", LWIP_THREAD_NAME, tname)); counter++; @@ -144,15 +109,8 @@ sys_mbox_t sys_mbox_new(int size) void sys_mbox_free(sys_mbox_t mbox) { -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); - - LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete mbox: %s\n",thread->name, - mbox->parent.parent.name)); - } -#endif + LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete mbox: %s\n", LWIP_THREAD_NAME, + mbox->mb->parent.parent.name)); rt_mb_delete(mbox); @@ -161,32 +119,18 @@ void sys_mbox_free(sys_mbox_t mbox) void sys_mbox_post(sys_mbox_t mbox, void *msg) { -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); + LWIP_DEBUGF(SYS_DEBUG, ("%s, Post mail: %s ,0x%x\n", LWIP_THREAD_NAME, + mbox->mb->parent.parent.name, (rt_uint32_t)msg)); - LWIP_DEBUGF(SYS_DEBUG, ("%s, Post mail: %s ,0x%x\n",thread->name, - mbox->parent.parent.name, (rt_uint32_t)msg)); - } -#endif - - rt_mb_send(mbox, (rt_uint32_t)msg); + rt_mb_send_wait(mbox, (rt_uint32_t)msg, RT_WAITING_FOREVER); return; } err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg) { -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); - - LWIP_DEBUGF(SYS_DEBUG, ("%s, Post mail: %s ,0x%x\n",thread->name, - mbox->parent.parent.name, (rt_uint32_t)msg)); - } -#endif + LWIP_DEBUGF(SYS_DEBUG, ("%s, Try post mail: %s ,0x%x\n", LWIP_THREAD_NAME, + mbox->mb->parent.parent.name, (rt_uint32_t)msg)); if (rt_mb_send(mbox, (rt_uint32_t)msg) == RT_EOK) return ERR_OK; @@ -216,15 +160,8 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout) if(ret == -RT_ETIMEOUT) return SYS_ARCH_TIMEOUT; else if (ret == RT_EOK) ret = 1; -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); - - LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n",thread->name, - mbox->parent.parent.name, *(rt_uint32_t **)msg)); - } -#endif + LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n", LWIP_THREAD_NAME, + mbox->mb->parent.parent.name, *(rt_uint32_t **)msg)); /* get elapse msecond */ tick = rt_tick_get() - tick; @@ -245,15 +182,8 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg) if(ret == -RT_ETIMEOUT) return SYS_ARCH_TIMEOUT; else if (ret == RT_EOK) ret = 1; -#if SYS_DEBUG - { - struct rt_thread *thread; - thread = rt_thread_self(); - - LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n",thread->name, - mbox->parent.parent.name, *(rt_uint32_t **)msg)); - } -#endif + LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n", LWIP_THREAD_NAME, + mbox->mb->parent.parent.name, *(rt_uint32_t **)msg)); return ret; } diff --git a/components/net/lwip/src/lwipopts.h b/components/net/lwip/src/lwipopts.h index 65979d751d..e9978321e1 100644 --- a/components/net/lwip/src/lwipopts.h +++ b/components/net/lwip/src/lwipopts.h @@ -89,13 +89,13 @@ #define MEM_LIBC_MALLOC 1 #define mem_malloc rt_malloc #define mem_free rt_free -#define mem_calloc rt_calloc - +#define mem_calloc rt_calloc + #ifdef RT_LWIP_USING_RT_MEM -#define MEMP_MEM_MALLOC 1 -#else -#define MEMP_MEM_MALLOC 0 -#endif +#define MEMP_MEM_MALLOC 1 +#else +#define MEMP_MEM_MALLOC 0 +#endif /* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application sends a lot of data out of ROM (or other static memory), this @@ -155,6 +155,8 @@ #define ETH_PAD_SIZE RT_LWIP_ETH_PAD_SIZE #endif +#define LWIP_NETIF_LINK_CALLBACK 1 + /** SYS_LIGHTWEIGHT_PROT * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection * for certain critical regions during buffer allocation, deallocation and memory diff --git a/components/net/lwip/src/netif/ethernetif.c b/components/net/lwip/src/netif/ethernetif.c index a23c89c3a7..45364971b8 100644 --- a/components/net/lwip/src/netif/ethernetif.c +++ b/components/net/lwip/src/netif/ethernetif.c @@ -352,7 +352,23 @@ FINSH_FUNCTION_EXPORT(set_dns, set DNS server address); void list_if() { + rt_ubase_t index; + rt_kprintf("Default network interface: %c%c\n", netif_default->name[0], netif_default->name[1]); + rt_kprintf("MTU: %d\n", netif_default->mtu); + rt_kprintf("MAC: "); + for (index = 0; index < netif_default->hwaddr_len; index ++) + rt_kprintf("%02x ", netif_default->hwaddr[index]); + rt_kprintf("\nFLAGS:"); + if (netif_default->flags & NETIF_FLAG_UP) rt_kprintf(" UP"); + else rt_kprintf(" DOWN"); + if (netif_default->flags & NETIF_FLAG_LINK_UP) rt_kprintf(" LINK_UP"); + else rt_kprintf(" LINK_DOWN"); + if (netif_default->flags & NETIF_FLAG_DHCP) rt_kprintf(" DHCP"); + if (netif_default->flags & NETIF_FLAG_POINTTOPOINT) rt_kprintf(" PPP"); + if (netif_default->flags & NETIF_FLAG_ETHARP) rt_kprintf(" ETHARP"); + if (netif_default->flags & NETIF_FLAG_IGMP) rt_kprintf(" IGMP"); + rt_kprintf("\n"); rt_kprintf("ip address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->ip_addr)))); rt_kprintf("gw address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->gw)))); rt_kprintf("net mask : %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->netmask))));