example-mainloop-without-arp.c 1.5 KB

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