xref: /nrf52832-nimble/rt-thread/components/net/uip/doc/example-mainloop-without-arp.c (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 #include "uip.h"
2 #include "uip_arp.h"
3 #include "network-device.h"
4 #include "httpd.h"
5 #include "timer.h"
6 
7 /*---------------------------------------------------------------------------*/
8 int
9 main(void)
10 {
11   int i;
12   uip_ipaddr_t ipaddr;
13   struct timer periodic_timer;
14 
15   timer_set(&periodic_timer, CLOCK_SECOND / 2);
16 
17   network_device_init();
18   uip_init();
19 
20   uip_ipaddr(ipaddr, 192,168,0,2);
21   uip_sethostaddr(ipaddr);
22 
23   httpd_init();
24 
25   while(1) {
26     uip_len = network_device_read();
27     if(uip_len > 0) {
28       uip_input();
29       /* If the above function invocation resulted in data that
30 	 should be sent out on the network, the global variable
31 	 uip_len is set to a value > 0. */
32       if(uip_len > 0) {
33 	network_device_send();
34       }
35     } else if(timer_expired(&periodic_timer)) {
36       timer_reset(&periodic_timer);
37       for(i = 0; i < UIP_CONNS; i++) {
38 	uip_periodic(i);
39 	/* If the above function invocation resulted in data that
40 	   should be sent out on the network, the global variable
41 	   uip_len is set to a value > 0. */
42 	if(uip_len > 0) {
43 	  network_device_send();
44 	}
45       }
46 
47 #if UIP_UDP
48       for(i = 0; i < UIP_UDP_CONNS; i++) {
49 	uip_udp_periodic(i);
50 	/* If the above function invocation resulted in data that
51 	   should be sent out on the network, the global variable
52 	   uip_len is set to a value > 0. */
53 	if(uip_len > 0) {
54 	  network_device_send();
55 	}
56       }
57 #endif /* UIP_UDP */
58     }
59   }
60   return 0;
61 }
62 /*---------------------------------------------------------------------------*/
63