lwIP Wiki
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 54: Line 54:
 
For older versions of lwIP, A simple main loop for a single-threaded system might look like this:
 
For older versions of lwIP, A simple main loop for a single-threaded system might look like this:
   
while(1) {
+
while(1) {
if(poll_driver(netif) == PACKET_READY) {
+
if(poll_driver(netif) == PACKET_READY) {
pbuf = get_packet(netif);
+
pbuf = get_packet(netif);
ip_input(pbuf, netif);
+
ip_input(pbuf, netif);
}
+
}
if (clock() - last_arp_time >= ARP_TMR_INTERVAL * CLOCKTICKS_PER_MS)
+
if (clock() - last_arp_time >= ARP_TMR_INTERVAL * CLOCKTICKS_PER_MS)
{
+
{
etharp_tmr();
+
etharp_tmr();
last_arp_time = clock();
+
last_arp_time = clock();
}
+
}
if(clock() - last_time >= TCP_TMR_INTERVAL * CLOCKTICKS_PER_MS) {
+
if(clock() - last_time >= TCP_TMR_INTERVAL * CLOCKTICKS_PER_MS) {
tcp_tmr();
+
tcp_tmr();
last_time = clock();
+
last_time = clock();
}
+
}
 
}
 
}
   
ATTENTION: Note that CLOCKTICKS_PER_MS is only valid for a hardware timer with at least one tick per millisecond. If you want to use an OS-tick-counter (e.g. one that is incremented every 10ms), you have to adjust the code to:
+
ATTENTION: Note that CLOCKTICKS_PER_MS is only valid for a hardware timer with at least one tick per seconds. I you want to use an OS-tick-counter (e.g. one that is incremented every 10ms), you have to adjust the code to:
   
 
clock() - last_time >= TCP_TMR_INTERVAL / MS_PER_TICK
 
clock() - last_time >= TCP_TMR_INTERVAL / MS_PER_TICK
Please note that all contributions to the lwIP Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)