lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Init - how to deal with static IP ?


From: address@hidden
Subject: Re: [lwip-users] Init - how to deal with static IP ?
Date: Thu, 07 Jan 2010 11:03:01 +0100
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0

Micael (abc) wrote:
Hi Guys,

I have a problem with init of lwip, in conjunction with FreeRTOS.

The thing is that the example startup looks similar to this;

-------8<-------8<-------8<-------8<-------8<----
tcpip_init(NULL, NULL);

IP4_ADDR(&ip_address, 192,168,1,47 );
IP4_ADDR(&net_mask,255,255,255,0 );
IP4_ADDR(&gateway, 192,168,1,151 );

netif_add(&ether_if,&ip_address,&net_mask,&gateway, NULL, ethernetif_init, 
tcpip_input );
netif_set_default(&ether_if );
netif_set_up(&ether_if );
-------8<-------8<-------8<-------8<-------8<----
The above example violates threading constraints: the netif_*() functions may only be called from the tcpip_thread. To do this, create a new functions that calls netif_add/_set_default/_set_up and pass a pointer to this function to tcpip_init. See the win32 example port for how to do this (I'm currently at fixing the unix port, which violates threading, too).
This is all (in the example code) done prior to OS has started.
Now the problem I have, is that if I want to get hold of the IP address 
(instead of hard coded
as above) of this node, I need to have the OS up and running.

So therefore, can I simply move the three netif_* lines later on, when the OS 
has started?
If so, what happens if a thread tries to open a connection (socket layer)? Will 
the stack give
appropriate (error) return codes on e.g. socket() and brothers.
OR do I need to protect the whole socket layer with some mutex or similar, 
until I have set-up
netif?
You can either call tcpip_init from one of your threads (so it gets called after the OS has started) or call netif_add (etc.) later. For that latter, you have to create a function that can be called in tcpip_thread via tcpip_callback() to prevent threading issues.

In both cases, sockets will not work before netif_add has been called: in the first case, you will get an error (as none of the lwip init functions have been called, yet), in the second case, you can create a socket but cannot bind it to a specific (ANY will work) and cannot send/connect before netif_add has been called.

Simon




reply via email to

[Prev in Thread] Current Thread [Next in Thread]