http://interactive.freertos.org/entries/20290712-freertos-win32-project-with-lwip-web-server
If so, look at the command interpreter rather than the web server. It
uses sockets, and although it is structure to only process one
connection at a time, I think converting it to allow multiple
connections should be simple (?).
> * checks for incoming data (nonblocking)
> * checks a Queue for outgoing data (nonblocking)
> * wait 1 ms (to prevent 100% cpu usage)
> * repeat :-)
This does not sound like a good solution, unless you are running at the
lowest (idle) task priority. At any other priority, you are still going
to be using most of the CPU time even when there is no processing to
perform. A better solution would be to block the TCP/IP processing
until a TCP/IP related event occurs - a semaphore or queue can be used
to signal the event, so the task blocks on the queue. An event can be
external, like a packet arriving, or internal, like a buffer becoming
free, or an ARP timer event, or data to be sent, etc.
Regards,
Richard.
+ http://www.FreeRTOS.org
Designed for Microcontrollers.
More than 7000 downloads per month.
On 28/08/2011 17:48, Christoph Kronen wrote:
> Hi all,
>
> I am using FreeRTOS 7.0.1 on a Sam7X512 and upgraded the contributed
> port lwIP 1.3.0 to 1.3.2.
>
> The "lwIP Embedded Webserver Demo" is what I took as a starting point. I
> removed the webserver functionality, now I have a task that
>
> * checks for incoming data (nonblocking)
> * checks a Queue for outgoing data (nonblocking)
> * wait 1 ms (to prevent 100% cpu usage)
> * repeat :-)
>
>
> This works pretty well, I get around 1400 kbyte/s RX and TX.
> Now to my question: Is it possible/difficult/easy to transform this
> functionality to accept multiple connections on the same port ? At the
> moment I am using the netconn API, so I guess I have to switch to the
> Socket API ?
>
> I read through Richards thread on his "FreeRTOS/lwip Win32 simulator"
> project and it sounds as if it is quite difficult to have multiple
> connections in a multithreaded environment. Unfortunately I could not
> find other helpful topics or contributed examples.
>
> I am rather new to FreeRTOS and lwIP, so please excuse me if I am
> missing something obvious :-)
>
> Please give me some comments / suggestions / tips / pushes into the
> right direction.
>
> Thank you very much !
>
> Christoph
>
>
> _______________________________________________
> lwip-users mailing list
> lwip-...@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
Thanks & Regards,
Yugal Kishore Gupta
CYBER G. INDIA PVT. LTD, (A Unit of CYBER GROUP, INC)
Logix Technopark
Tower B, 5th Floor
Sector 127, NOIDA, U.P., INDIA 201301
OT 91-120-4643106/ Cell: 91-9818566224
ygu...@cygrp.com / www.cygrp.com
Hi Chistoph:
The "lwIP Embedded Webserver Demo" is what I took as a starting point. I removed the webserver functionality, now I have a task that
the LwIP webserver demo code is following, I don’t know how do you infer it is noblocking for incoming data and outgoing ….
Where to wait 1 ms .
void WebServer_Handler(void *pdata)
{
struct netconn *__pstConn, *__pstNewConn;
__pstConn = netconn_new(NETCONN_TCP);
netconn_bind(__pstConn, NULL,80);
netconn_listen(__pstConn);
for(;;)
{
__pstNewConn = netconn_accept(__pstConn);
if(__pstNewConn != NULL)
{
vHandler_HTTP(__pstNewConn);
while(netconn_delete(__pstNewConn) != ERR_OK)
{
vTaskDelay(10);
}
}
}
}
Vincent Cui
Sr.Firmware Engineer
Mobile: +8613482482211
Tel: +86 21 34612525x6104
Fax: +86 21 34619770
E-Mail: vince...@enlogic.com
Shanghai EnLogic Electric Technology Co., Ltd.
Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, Shanghai, 200233
http://www.enlogic.com
-------- Original-Nachricht --------
Datum: Tue, 30 Aug 2011 03:28:07 +0000
Von: vincent cui <vince...@enlogic.com>
An: Mailing list for lwIP users <lwip-...@nongnu.org>
Betreff: Re: [lwip-users] FreeRTOS / lwip multiple connections
Hi Christoph:
Indeed, I write the web server with socket api in lwIP. It responses http request with a dynamic web page ( fetch interval 1 second).
After it run, I open 10 IE to access the web serve (I make sure 10 clients could access the web server at same time )r, and keep that in pressure testing…
it had works in 3 days now , but I don’t think it is enough.
Christoph:
Deal with mult-connection correctly, there is 3 way.
1. Using raw api
2. Using netconn API, but you have to create a task to handle the HTTP request, then back to main thread to start accept next request.
3. Using socket, you must set it with non-blocking and select it
I use the 3th method. The following code must be add to listen socket.
Int arg = 0x1;
lwip_ioctl(listhensocket, FIONBIO, &arg);
but I found that the listen socket cann’t work once it is set with nonblocking…
now, I remove it, it works … hope someone explain why
other, you also need call lwIP_shutdown and lowip_close to terminate socket in order to be avoid to CLOSE_WAIT .
There are lots of ways!
> 3. Using socket, you must set it with non-blocking and select it
>
> I use the 3th method. The following code must be add to listen socket.
>
>
> Int arg = 0x1;
>
> lwip_ioctl(listhensocket, FIONBIO, &arg);
I'm not sure why you need your listening socket to be non-blocking.
> but I found that the listen socket cann’t work once it is set with
> nonblocking…
> now, I remove it, it works … hope someone explain why
I'm not sure if lwIP supports non-blocking listening sockets. I'd have
to check the source to be sure and I'm short on time.
> other, you also need call lwIP_shutdown and lowip_close to terminate
> socket in order to be avoid to CLOSE_WAIT .
No, either should be fine if you use them correctly. There are some
small differences between lwIP's shutdown and close and standard
shutdown and close, but we're working towards getting them more
standardised where possible.
Kieran
H chiston:
I redesign my webserver to support mult-connection. I create a new task to deal with HTTP request, it will delete it by itself.
The main task will go to accept new connection.
> K:
> You mean I need make accept socket to be non-blocking , right ?
No, I'm not sure why you need any of your sockets to be non-blocking.
| From: | vincent cui <vince...@enlogic.com> |
| To: | Mailing list for lwIP users <lwip-...@nongnu.org> |
| Date: | 2011-09-02 07:27 |
| Subject: | [lwip-users] how lwip know internet cable is unplug |
| Sent by: | lwip-users-bounces+ake.forslund=nib...@nongnu.org |
Dear:
I define a semaphore used to send signal to tell upper app….the semaphore is controlled by ethernet driver..
Vincent Cui
Sr.Firmware Engineer
Mobile: +8613482482211
Tel: +86 21 34612525x6104
Fax: +86 21 34619770
E-Mail: vince...@enlogic.com
Shanghai EnLogic Electric Technology Co., Ltd.
Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, Shanghai, 200233
http://www.enlogic.com
Nearly: it should call netif_set_link_up/down (watch out for threading issues!), which in turn calls user-specified callbacks. This has to be enabled using a define (I think it's turned off by default).
Simon
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone
Yes. http://www.freertos.org/CreateCounting.html
Regards,
Richard.
+ http://www.FreeRTOS.org
Designed for Microcontrollers.
More than 7000 downloads per month.
>
> ï»?Vincent Cui
Hi,
Here's what I do (NOSYS=0)
In my PHY driver init:
bfphy_msg = tcpip_callbackmsg_new(bfphy_interrupt_callback, netif);
In the interrupt:
tcpip_trycallback(bfphy_msg);
In the callback, executing in the tcpip_thread context:
void bfphy_interrupt_callback(void* ctx)
{
struct netif* netif = (struct netif*) ctx;
Read PHY registers (simple function with mutex protection in my
case)
Set Full-duplex, RMII 10/100 parameters, etc...
// Link state
if (stat & PHY_MODESTAT_AUTONEG_COMPLETE)
netif_set_link_up(netif);
else
netif_set_link_down(netif);
}
Now you can either:
- use the netif callbacks to get the information
- regularly poll with netif_is_link_up(netif);
It doesn't. Whether the link is up or not is of no real interest to a
TCP/IP stack. It will just try to send packets, and the lower layers
(e.g. the driver you're using) have to deal with the link status.
> On Fri, 2011-09-02 at 05:26 +0000, vincent cui wrote:
> > When unplug internet cable, how lwip deal it ?
>
> It doesn't. Whether the link is up or not is of no real interest to a
> TCP/IP stack. It will just try to send packets, and the lower layers
> (e.g. the driver you're using) have to deal with the link status.
That's only half the truth. At least dhcp/AutoIP use this information: they restart address negotiation after the link status has been changed to 'up' (using netif_set_link_up()). After all, this is a feature which should be implemented when using dhcp/AutoIP or the lwIP device will continue to use an address of one subnet when plugged into another subnet until the original lease would expire.
Simon
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
| From: | "Simon Goldschmidt" <gold...@gmx.de> |
| To: | Mailing list for lwIP users <lwip-...@nongnu.org> |
| Date: | 2011-09-02 09:55 |
| Subject: | Re: [lwip-users] how lwip know internet cable is unplug |
| Sent by: | lwip-users-bounces+ake.forslund=nib...@nongnu.org |
Even if it is now, it is only so by chance and you shouldn't rely on it. Such mixed threading code is a no-go, you only risk producing bugs that are *very* hard to track down later. Just do it right now and be safe: it's just the lwIP principle that things like this are not protected from concurrent access by the lwIP core code.
Simon
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
| From: | "Simon Goldschmidt" <gold...@gmx.de> |
| To: | Mailing list for lwIP users <lwip-...@nongnu.org> |
| Date: | 2011-09-02 14:15 |
| Subject: | Re: [lwip-users] how lwip know internet cable is unplug |
| Sent by: | lwip-users-bounces+ake.forslund=nib...@nongnu.org |
I'm just repeating the mantra that lwIP core code is not thread protected (with very little exceptions, mostly regarding memory management functions) and either all code using lwIP functions/variables must be used from one thread only or you have to protect it yourself (e.g. by using a semaphore or something like that).
E.g. if you have RX in one thread and TX in another thread, you can be most sure that you will get problems at some point (e.g. corrupted state, corrupted pbuf-ref or corrupted lists).
I have to point this out to prevent other users reading this list from making such a mistake (that can be hard to debug). And your statement "set_link_up/down looks pretty safe to use from my rx-thread" can sound like these functions are thread-safe to new users (as it did, to me).
| From: | "Simon Goldschmidt" <gold...@gmx.de> |
| To: | Mailing list for lwIP users <lwip-...@nongnu.org> |
| Date: | 2011-09-02 14:32 |
| Subject: | Re: [lwip-users] how lwip know internet cable is unplug |
| Sent by: | lwip-users-bounces+ake.forslund=nib...@nongnu.org |
By using tcpip_input() as the input function. This passes received packets into the tcpip_thread before actually feeding them into the stack.
> OK I see now that there is an input-pointer in the netif-structure as well
> but it's not referenced in the driver-template (ethernetif.c) so I
> invented something on my own...I'll have to dig through the examples one
> more time and look how they have done it...
It *is*: it's not set there but it is used. The code that sets it is in netif.c (the function being set as netif->input has to be passed to netif_add()).
Simon
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
| From: | "Simon Goldschmidt" <gold...@gmx.de> |
| To: | Mailing list for lwIP users <lwip-...@nongnu.org> |
| Date: | 2011-09-02 15:29 |
| Subject: | Re: [lwip-users] how lwip know internet cable is unplug |
| Sent by: | lwip-users-bounces+ake.forslund=nib...@nongnu.org |
HI Ake and Simon:
I set callback function as following, but have to call netif_set_link_up/down to trigger the callback function.
Once cable is unplugged / plugged, the netif_set_link_down/up should be called by one times. I don’t know how to do this…
I can use the ETH_GetNetifUporDown function to get the Ethernet link status (not lwIP link status), but where to put it ?
Would you help me
static uint32_t ETH_GetNetifUporDown (void)
{
return (ETH_ReadPHYRegister(PHY_ADDRESS, PHY_BSR) & PHY_Linked_Status) ? 1:0;
}
------------------------------------------------------------------------------------------------------------------------
void lwip_link_callback(struct netif *netif )
{
if (netif_is_link_up(netif))
{
printf ("link status go to up \r\n");
dhcp_start(netif);
netif_set_up(netif);
}
else
{
printf ("link status go to down \r\n");
dhcp_stop(netif);
netif_set_down(netif);
}
}
Set the call back function in lnit_lwip()
…
netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
netif_set_default(&netif);
netif_set_link_callback(&netif, lwip_link_callback);
…
------------------------------------------------------------------------------------------------------------------------
Vincent Cui
Sr.Firmware Engineer
Mobile: +8613482482211
Tel: +86 21 34612525x6104
Fax: +86 21 34619770
E-Mail: vince...@enlogic.com
Shanghai EnLogic Electric Technology Co., Ltd.
Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, Shanghai, 200233
http://www.enlogic.com
>>>> My approach is to send a signal to a separate task to handle the cable-plug/unplug events
Ake:
For your approach, who send a signal to the task ? the driver ? my driver can get the link status by polling, not interrupt, so it takes more cpu time..I stop using it
And try to find another one to replace… maybe it need HW sensor support.
Vincent Cui
Sr.Firmware Engineer
Mobile: +8613482482211
Tel: +86 21 34612525x6104
Fax: +86 21 34619770
E-Mail: vince...@enlogic.com
Shanghai EnLogic Electric Technology Co., Ltd.
Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, Shanghai, 200233
http://www.enlogic.com
| From: | vincent cui <vince...@enlogic.com> |
| To: |
| Mailing list for lwIP users <lwip-...@nongnu.org> |
| Date: | 2011-09-07 01:15 |
| Subject: |
| Re: [lwip-users] how lwip know internet cable is unplug |
| Sent by: | lwip-users-bounces+ake.forslund=nib...@nongnu.org |
https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
Alk
Thank you for your reply …. Now, I know your method to deal with ….but it is not a good idea with polling …
I ask my HW guys support LED_LINK pin with interrupt. So I can receive the event at real time
https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
I use STM32F107 board, Cortex M3…
DP83848c,,,,
https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
The normal IRQ is Ethernet_IRQ ?
I agree that polling for RXframes isn't optimal, but link-change events shouldn't be too high-priority, so you could check/process them in a very low-priority task (which is what I did before having the interrupt).
Simon
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
I just check the Ethernet driver,,, it doesn’t enable the link_status in INT CTRL register… so , I never get it
You don't need to do that: lwIP handles calling dhcp itself if you just call netif_set_link_up/down.
> The link status from loss to recover will happen one time at boot
> time...so the dhcp enable will put the task too ?
No, I initialized it once after booting so that change didn't happen after botting.
Vincent,
I have to poll the link state as well on 2 platforms but it’s a simple PHY I/O read and it takes very little time. I do that as part of my incoming packet check when there are no packets to process. If there are packets to process obviously the link is up. J
Bill
Bill
Would you tell me where to check the incoming package ?
Vincent Cui
Sr.Firmware Engineer
Mobile: +8613482482211
Tel: +86 21 34612525x6104
Fax: +86 21 34619770
E-Mail: vince...@enlogic.com
Shanghai EnLogic Electric Technology Co., Ltd.
Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, Shanghai, 200233
http://www.enlogic.com