/* #include "lpc17xx.h" #include <stdio.h> #include <string.h> #include "lpc17xx_emac.h" #include "timer.h" #include "uip.h" #include "uip_arp.h" #include "tapdev.h" struct uip_eth_addr mymac = { {MYMAC_1, MYMAC_2, MYMAC_3, MYMAC_4, MYMAC_5, MYMAC_6} } ; char ipstring [20]; #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) unsigned char *Key; char buf[512]; /*--------------------------- uip_log ---------------------------------*/ void uip_log(char *m) { //printf("uIP log message: %s\n", m); } /*--------------------------- main ---------------------------------*/ int main(void) { unsigned int i; uip_ipaddr_t ipaddr;/* local IP address */ struct timer periodic_timer, arp_timer; GPIO4->FIODIR |= 1 << 29; GPIO1->FIODIR = (1 << 25); // system init SystemInit(); /* setup core clocks */ // clock init clock_init(); // two timers for tcp/ip timer_set(&periodic_timer, CLOCK_SECOND / 2); /* 0.5s */ timer_set(&arp_timer, CLOCK_SECOND * 10);/* 10s */ // ethernet init tapdev_init(); // Initialize the uIP TCP/IP stack. uip_init(); uip_setethaddr (mymac);//--->> here the code does not return and the led does not toggle below GPIO1->FIOPIN ^=(1<< 25);// led does not toggle // Start DHCP to get IP address dhcpc_init(&mymac,6 ); dhcpc_request(); // Initialize the HTTP server, listen to port 80. httpd_init(); GPIO1->FIOPIN ^=(1<< 25); while(1) { /* receive packet and put in uip_buf */ uip_len = tapdev_read(uip_buf); if(uip_len > 0)/* received packet */ { if(BUF->type == htons(UIP_ETHTYPE_IP))/* IP packet */ { uip_arp_ipin(); uip_input(); if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); //GPIO1->FIOPIN ^=(1<< 25); } } /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ else if(BUF->type == htons(UIP_ETHTYPE_ARP))/*ARP packet */ { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { tapdev_send(uip_buf,uip_len);/* ARP ack*/ } } } else if(timer_expired(&periodic_timer))/* no packet but periodic_timer time out (0.5s)*/ { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } } |