SAMV71 Xplained Ultra Software Package 1.4

example-mainloop-with-arp.c

00001 #include "uip.h"
00002 #include "uip_arp.h"
00003 #include "network-device.h"
00004 #include "httpd.h"
00005 #include "timer.h"
00006 
00007 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00008 
00009 /*---------------------------------------------------------------------------*/
00010 int
00011 main(void)
00012 {
00013   int i;
00014   uip_ipaddr_t ipaddr;
00015   struct timer periodic_timer, arp_timer;
00016   
00017   timer_set(&periodic_timer, CLOCK_SECOND / 2);
00018   timer_set(&arp_timer, CLOCK_SECOND * 10);
00019   
00020   network_device_init();
00021   uip_init();
00022 
00023   uip_ipaddr(ipaddr, 192,168,0,2);
00024   uip_sethostaddr(ipaddr);
00025 
00026   httpd_init();
00027   
00028   while(1) {
00029     uip_len = network_device_read();
00030     if(uip_len > 0) {
00031       if(BUF->type == htons(UIP_ETHTYPE_IP)) {
00032     uip_arp_ipin();
00033     uip_input();
00034     /* If the above function invocation resulted in data that
00035        should be sent out on the network, the global variable
00036        uip_len is set to a value > 0. */
00037     if(uip_len > 0) {
00038       uip_arp_out();
00039       network_device_send();
00040     }
00041       } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
00042     uip_arp_arpin();
00043     /* If the above function invocation resulted in data that
00044        should be sent out on the network, the global variable
00045        uip_len is set to a value > 0. */
00046     if(uip_len > 0) {
00047       network_device_send();
00048     }
00049       }
00050 
00051     } else if(timer_expired(&periodic_timer)) {
00052       timer_reset(&periodic_timer);
00053       for(i = 0; i < UIP_CONNS; i++) {
00054     uip_periodic(i);
00055     /* If the above function invocation resulted in data that
00056        should be sent out on the network, the global variable
00057        uip_len is set to a value > 0. */
00058     if(uip_len > 0) {
00059       uip_arp_out();
00060       network_device_send();
00061     }
00062       }
00063 
00064 #if UIP_UDP
00065       for(i = 0; i < UIP_UDP_CONNS; i++) {
00066     uip_udp_periodic(i);
00067     /* If the above function invocation resulted in data that
00068        should be sent out on the network, the global variable
00069        uip_len is set to a value > 0. */
00070     if(uip_len > 0) {
00071       uip_arp_out();
00072       network_device_send();
00073     }
00074       }
00075 #endif /* UIP_UDP */
00076       
00077       /* Call the ARP timer function every 10 seconds. */
00078       if(timer_expired(&arp_timer)) {
00079     timer_reset(&arp_timer);
00080     uip_arp_timer();
00081       }
00082     }
00083   }
00084   return 0;
00085 }
00086 /*---------------------------------------------------------------------------*/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines