keep more compatible with RT-Thread driver.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2039 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com
2012-04-13 15:11:02 +00:00
parent 8fd4704141
commit 12b5decaa9
4 changed files with 480 additions and 378 deletions
+145 -163
View File
@@ -6,20 +6,156 @@
#include "lwip/err.h"
#include "arch/sys_arch.h"
#include "lwip/debug.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "netif/ethernetif.h"
#include <string.h>
#define LWIP_THREAD_MAGIC 0x1919
/* introduce from kservice.c */
#define rt_list_entry(node, type, member) \
((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
static err_t netif_device_init(struct netif *netif)
{
struct eth_device *ethif;
ethif = (struct eth_device*)netif->state;
if (ethif != RT_NULL)
{
rt_device_t device;
/* get device object */
device = (rt_device_t) ethif;
if (rt_device_init(device) != RT_EOK)
{
return ERR_IF;
}
/* copy device flags to netif flags */
netif->flags = ethif->flags;
return ERR_OK;
}
return ERR_IF;
}
static void tcpip_init_done_callback(void *arg)
{
rt_device_t device;
struct eth_device *ethif;
struct ip_addr ipaddr, netmask, gw;
struct rt_list_node* node;
struct rt_object* object;
struct rt_object_information *information;
extern struct rt_object_information rt_object_container[];
LWIP_ASSERT("invalid arg.\n",arg);
IP4_ADDR(&gw, 0,0,0,0);
IP4_ADDR(&ipaddr, 0,0,0,0);
IP4_ADDR(&netmask, 0,0,0,0);
/* enter critical */
rt_enter_critical();
/* for each network interfaces */
information = &rt_object_container[RT_Object_Class_Device];
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
{
object = rt_list_entry(node, struct rt_object, list);
device = (rt_device_t) object;
if (device->type == RT_Device_Class_NetIf)
{
ethif = (struct eth_device*)device;
/* leave critical */
rt_exit_critical();
netif_add(ethif->netif, &ipaddr, &netmask, &gw,
ethif, netif_device_init, tcpip_input);
if (netif_default == RT_NULL)
netif_set_default(ethif->netif);
#if LWIP_DHCP
if (ethif->flags & NETIF_FLAG_DHCP)
{
/* if this interface uses DHCP, start the DHCP client */
dhcp_start(ethif->netif);
}
else
#endif
{
/* set interface up */
netif_set_up(ethif->netif);
}
#ifdef LWIP_NETIF_LINK_CALLBACK
netif_set_link_up(ethif->netif);
#endif
/* enter critical */
rt_enter_critical();
}
}
/* leave critical */
rt_exit_critical();
rt_sem_release((rt_sem_t)arg);
}
/**
* LwIP system initialization
*/
void lwip_system_init(void)
{
rt_err_t rc;
struct rt_semaphore done_sem;
rc = rt_sem_init(&done_sem, "done", 0, RT_IPC_FLAG_FIFO);
if(rc != RT_EOK)
{
LWIP_ASSERT("Failed to create semaphore", 0);
return;
}
tcpip_init(tcpip_init_done_callback,(void *)&done_sem);
/* waiting for initialization done */
if (rt_sem_take(&done_sem, RT_WAITING_FOREVER) != RT_EOK)
{
rt_sem_detach(&done_sem);
return;
}
rt_sem_detach(&done_sem);
/* set default ip address */
#if !LWIP_DHCP
{
struct ip_addr ipaddr, netmask, gw;
IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3);
IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3);
netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw);
}
#endif
}
void sys_init(void)
{
/* nothing to do in RT-Thread */
return;
/* nothing on RT-Thread porting */
}
/* ====================== Semaphore ====================== */
void lwip_sys_init(void)
{
lwip_system_init();
}
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{
@@ -30,16 +166,6 @@ err_t sys_sem_new(sys_sem_t *sem, u8_t count)
RT_DEBUG_NOT_IN_INTERRUPT;
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
counter++;
tmpsem = rt_sem_create(tname, count, RT_IPC_FLAG_FIFO);
@@ -56,36 +182,13 @@ err_t sys_sem_new(sys_sem_t *sem, u8_t count)
void sys_sem_free(sys_sem_t *sem)
{
RT_DEBUG_NOT_IN_INTERRUPT;
#if SYS_DEBUG
{
struct rt_thread *thread;
thread = rt_thread_self();
LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete sem: %s \n",thread->name,
(*sem)->parent.parent.name));
}
#endif
rt_sem_delete(*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,
(*sem)->parent.parent.name, (*sem)->value));
}
#endif
rt_sem_release(*sem);
}
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
@@ -98,21 +201,10 @@ 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,
(*sem)->parent.parent.name, (*sem)->value));
}
#endif
if(timeout == 0)
t = RT_WAITING_FOREVER;
if(timeout == 0) t = RT_WAITING_FOREVER;
else
{
/* convirt msecond to os tick */
/* convert msecond to os tick */
if (timeout < (1000/RT_TICK_PER_SECOND))
t = 1;
else
@@ -141,7 +233,7 @@ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
}
#ifndef sys_sem_valid
/** Check if a sempahore is valid/allocated: return 1 for valid, 0 for invalid */
/** Check if a semaphore is valid/allocated: return 1 for valid, 0 for invalid */
int sys_sem_valid(sys_sem_t *sem)
{
return (int)(*sem);
@@ -170,16 +262,6 @@ err_t sys_mutex_new(sys_mutex_t *mutex)
RT_DEBUG_NOT_IN_INTERRUPT;
rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MUTEX_NAME, counter);
#if SYS_DEBUG
{
struct rt_thread *thread;
thread = rt_thread_self();
LWIP_DEBUGF(SYS_DEBUG, ("%s, Create mutex: %s \n",thread->name, tname));
}
#endif
counter++;
tmpmutex = rt_mutex_create(tname, RT_IPC_FLAG_FIFO);
@@ -196,19 +278,7 @@ err_t sys_mutex_new(sys_mutex_t *mutex)
* @param mutex the mutex to lock */
void sys_mutex_lock(sys_mutex_t *mutex)
{
RT_DEBUG_NOT_IN_INTERRUPT;
#if SYS_DEBUG
{
struct rt_thread *thread;
thread = rt_thread_self();
LWIP_DEBUGF(SYS_DEBUG, ("%s, Wait mutex: %s , %d\n",thread->name,
(*mutex)->parent.parent.name, (*mutex)->value));
}
#endif
rt_mutex_take(*mutex, RT_WAITING_FOREVER);
return;
@@ -219,16 +289,6 @@ void sys_mutex_lock(sys_mutex_t *mutex)
* @param mutex the mutex to unlock */
void sys_mutex_unlock(sys_mutex_t *mutex)
{
#if SYS_DEBUG
{
struct rt_thread *thread;
thread = rt_thread_self();
LWIP_DEBUGF(SYS_DEBUG, ("%s, Release signal: %s , %d\n",thread->name,
(*mutex)->parent.parent.name, (*mutex)->value));
}
#endif
rt_mutex_release(*mutex);
}
@@ -238,16 +298,6 @@ void sys_mutex_free(sys_mutex_t *mutex)
{
RT_DEBUG_NOT_IN_INTERRUPT;
#if SYS_DEBUG
{
struct rt_thread *thread;
thread = rt_thread_self();
LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete sem: %s \n",thread->name,
(*mutex)->parent.parent.name));
}
#endif
rt_mutex_delete(*mutex);
}
@@ -278,15 +328,6 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size)
RT_DEBUG_NOT_IN_INTERRUPT;
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
counter++;
tmpmbox = rt_mb_create(tname, size, RT_IPC_FLAG_FIFO);
@@ -295,25 +336,14 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size)
*mbox = tmpmbox;
return ERR_OK;
}
else
return ERR_MEM;
return ERR_MEM;
}
void sys_mbox_free(sys_mbox_t *mbox)
{
RT_DEBUG_NOT_IN_INTERRUPT;
#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
rt_mb_delete(*mbox);
return;
@@ -327,16 +357,6 @@ void sys_mbox_post(sys_mbox_t *mbox, void *msg)
{
RT_DEBUG_NOT_IN_INTERRUPT;
#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
rt_mb_send_wait(*mbox, (rt_uint32_t)msg,RT_WAITING_FOREVER);
return;
@@ -344,16 +364,6 @@ void sys_mbox_post(sys_mbox_t *mbox, void *msg)
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
if (rt_mb_send(*mbox, (rt_uint32_t)msg) == RT_EOK)
return ERR_OK;
@@ -398,16 +408,6 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
LWIP_ASSERT("rt_mb_recv returned with error!", ret == RT_EOK);
}
#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
/* get elapse msecond */
tick = rt_tick_get() - tick;
@@ -439,16 +439,6 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
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
return ret;
}
@@ -494,18 +484,11 @@ sys_prot_t sys_arch_protect(void)
/* disable interrupt */
level = rt_hw_interrupt_disable();
/* must also lock scheduler */
rt_enter_critical();
return level;
}
void sys_arch_unprotect(sys_prot_t pval)
{
/* unlock scheduler */
rt_exit_critical();
/* enable interrupt */
rt_hw_interrupt_enable(pval);
@@ -518,4 +501,3 @@ void sys_arch_assert(const char* file, int line)
rt_thread_self()->name);
RT_ASSERT(0);
}
@@ -7,21 +7,29 @@
#define NIOCTL_GADDR 0x01
#define ETHERNET_MTU 1500
struct eth_device
{
/* inherit from rt_device */
struct rt_device parent;
/* network interface for lwip */
struct netif *netif;
struct rt_semaphore tx_ack;
rt_uint8_t flags;
rt_uint8_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_init(struct eth_device * dev, char *name);
rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flag);
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up);
void eth_system_device_init(void);
#endif /* __NETIF_ETHERNETIF_H__ */
+20 -22
View File
@@ -3,9 +3,7 @@
#include <rtconfig.h>
#if defined(RT_USING_NEWLIB) || defined(RT_USING_MINILIBC)
#define ERRNO 1
#endif
#define ERRNO 1
#define NO_SYS 0
#define LWIP_SOCKET 1
@@ -32,16 +30,16 @@
#ifdef RT_LWIP_DNS
#define LWIP_DNS 1
#else
#define LWIP_DNS 0
#define LWIP_DNS 0
#endif
#define LWIP_HAVE_LOOPIF 1
#define LWIP_HAVE_LOOPIF 0
#define LWIP_PLATFORM_BYTESWAP 0
#define BYTE_ORDER LITTLE_ENDIAN
/* Enable SO_RCVTIMEO processing. */
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_RCVTIMEO 1
/* #define RT_LWIP_DEBUG */
@@ -52,7 +50,7 @@
/* ---------- Debug options ---------- */
#ifdef LWIP_DEBUG
#define SYS_DEBUG LWIP_DBG_OFF
#define ETHARP_DEBUG LWIP_DBG_OFF
#define ETHARP_DEBUG LWIP_DBG_OFF
#define PPP_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
@@ -92,15 +90,15 @@
#define mem_calloc rt_calloc
#ifdef RT_LWIP_USING_RT_MEM
#define MEMP_MEM_MALLOC 1
#define MEMP_MEM_MALLOC 1
#else
#define MEMP_MEM_MALLOC 0
#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
should be set high. */
#define MEMP_NUM_PBUF 32
#define MEMP_NUM_PBUF 16
/* the number of UDP protocol control blocks. One per active RAW "connection". */
#ifdef RT_LWIP_RAW_PCB_NUM
@@ -124,14 +122,14 @@
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
timeouts. */
#define MEMP_NUM_SYS_TIMEOUT 8
#define MEMP_NUM_SYS_TIMEOUT 3
/* The following four are used only with the sequential API and can be
set to 0 if the application only will use the raw API. */
/* MEMP_NUM_NETBUF: the number of struct netbufs. */
#define MEMP_NUM_NETBUF 2
/* MEMP_NUM_NETCONN: the number of struct netconns. */
#define MEMP_NUM_NETCONN 10
#define MEMP_NUM_NETCONN 4
/* MEMP_NUM_TCPIP_MSG_*: the number of struct tcpip_msg, which is used
for sequential API communication and incoming packets. Used in
src/api/tcpip.c. */
@@ -152,7 +150,7 @@
#define PBUF_LINK_HLEN 16
#ifdef RT_LWIP_ETH_PAD_SIZE
#define ETH_PAD_SIZE RT_LWIP_ETH_PAD_SIZE
#define ETH_PAD_SIZE RT_LWIP_ETH_PAD_SIZE
#endif
/** SYS_LIGHTWEIGHT_PROT
@@ -176,13 +174,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 *
@@ -196,9 +194,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. */
@@ -233,10 +231,10 @@
/* IP reassembly and segmentation.These are orthogonal even
* if they both deal with IP fragments */
#define IP_REASSEMBLY 1
#define IP_REASSEMBLY 0
#define IP_REASS_MAX_PBUFS 10
#define MEMP_NUM_REASSDATA 10
#define IP_FRAG 1
#define IP_FRAG 0
/* ---------- ICMP options ---------- */
#define ICMP_TTL 255
@@ -265,7 +263,7 @@
#define LWIP_UDP 0
#endif
#define LWIP_UDPLITE 1
#define LWIP_UDPLITE 0
#define UDP_TTL 255
#define DEFAULT_UDP_RECVMBOX_SIZE 1
@@ -323,7 +321,7 @@
#endif /* PPP_SUPPORT */
/* no read/write/close for socket */
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
#define LWIP_NETIF_API 1
#endif /* __LWIPOPTS_H__ */
File diff suppressed because it is too large Load Diff