00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 #include "board.h"
00101
00102 #include "uip.h"
00103 #include "uip_arp.h"
00104 #include "gmac_tapdev.h"
00105 #include "timer.h"
00106
00107
00108
00109
00110
00111
00112 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00113
00114
00115 static const struct uip_eth_addr MacAddress = {{0x3a, 0x1f, 0x34, 0x09, 0x54, 0x54}};
00116
00117
00118 static const uint8_t HostIpAddress[4] = {10, 217, 12, 223};
00119
00120
00121 static const uint8_t RoutIpAddress[4] = {10, 217, 12, 1};
00122
00123
00124 static const uint8_t NetMask[4] = {255, 255, 255, 0};
00125
00126
00127
00128
00129
00130
00131
00132
00133 static void _app_init(void)
00134 {
00135 printf("P: webserver application init\n\r");
00136 httpd_init();
00137 printf ("Type the IP address of the device in a web browser, \
00138 http://%d.%d.%d.%d \n\r",
00139 HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]);
00140
00141 #ifdef __DHCPC_H__
00142 printf("P: DHCPC Init\n\r");
00143 dhcpc_init(MacAddress.addr, 6);
00144 #endif
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 void uip_log(char *m)
00156 {
00157 TRACE_INFO("-uIP log- %s\n\r", m);
00158 }
00159
00160 #ifdef __DHCPC_H__
00161
00162
00163
00164
00165
00166 void dhcpc_configured(const struct dhcpc_state *s)
00167 {
00168 u8_t * pAddr;
00169
00170 printf("\n\r");
00171 printf("=== DHCP Configurations ===\n\r");
00172 pAddr = (u8_t *)s->ipaddr;
00173 printf("- IP : %d.%d.%d.%d\n\r",
00174 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00175 pAddr = (u8_t *)s->netmask;
00176 printf("- Mask : %d.%d.%d.%d\n\r",
00177 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00178 pAddr = (u8_t *)s->default_router;
00179 printf("- GW : %d.%d.%d.%d\n\r",
00180 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00181 pAddr = (u8_t *)s->dnsaddr;
00182 printf("- DNS : %d.%d.%d.%d\n\r",
00183 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00184 printf("===========================\n\r\n");
00185 uip_sethostaddr(s->ipaddr);
00186 uip_setnetmask(s->netmask);
00187 uip_setdraddr(s->default_router);
00188
00189 #ifdef __RESOLV_H__
00190 resolv_conf(s->dnsaddr);
00191 #else
00192 printf("DNS NOT enabled in the demo\n\r");
00193 #endif
00194 }
00195 #endif
00196
00197
00198
00199
00200
00201
00202 int main(void)
00203 {
00204 uip_ipaddr_t ipaddr;
00205 struct timer periodic_timer, arp_timer;
00206 uint32_t i;
00207
00208
00209 WDT_Disable( WDT ) ;
00210
00211 SCB_EnableICache();
00212 SCB_EnableDCache();
00213 TimeTick_Configure();
00214 printf("-- GMAC uIP Web Server Example %s --\n\r", SOFTPACK_VERSION);
00215 printf("-- %s\n\r", BOARD_NAME);
00216 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00217
00218
00219 printf(" - MAC %x:%x:%x:%x:%x:%x\n\r",
00220 MacAddress.addr[0], MacAddress.addr[1], MacAddress.addr[2],
00221 MacAddress.addr[3], MacAddress.addr[4], MacAddress.addr[5]);
00222 #ifndef __DHCPC_H__
00223 printf(" - Host IP %d.%d.%d.%d\n\r",
00224 HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]);
00225 printf(" - Router IP %d.%d.%d.%d\n\r",
00226 RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]);
00227 printf(" - Net Mask %d.%d.%d.%d\n\r",
00228 NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
00229 #endif
00230
00231
00232 gmac_tapdev_setmac((uint8_t *)MacAddress.addr);
00233 gmac_tapdev_init();
00234 clock_init();
00235 timer_set(&periodic_timer, CLOCK_SECOND / 2);
00236 timer_set(&arp_timer, CLOCK_SECOND * 10);
00237
00238
00239 uip_init();
00240
00241 #ifdef __DHCPC_H__
00242 printf("P: DHCP Supported\n\r");
00243 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00244 uip_sethostaddr(ipaddr);
00245 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00246 uip_setdraddr(ipaddr);
00247 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00248 uip_setnetmask(ipaddr);
00249 #else
00250
00251 uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1],
00252 HostIpAddress[2], HostIpAddress[3]);
00253 uip_sethostaddr(ipaddr);
00254
00255 uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1],
00256 RoutIpAddress[2], RoutIpAddress[3]);
00257 uip_setdraddr(ipaddr);
00258
00259 uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
00260 uip_setnetmask(ipaddr);
00261 #endif
00262
00263 uip_setethaddr(MacAddress);
00264
00265 _app_init();
00266
00267 while(1) {
00268 uip_len = gmac_tapdev_read();
00269 if(uip_len > 0) {
00270 if(BUF->type == htons(UIP_ETHTYPE_IP)) {
00271 uip_arp_ipin();
00272 uip_input();
00273
00274
00275
00276 if(uip_len > 0) {
00277 uip_arp_out();
00278 gmac_tapdev_send();
00279 }
00280 } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
00281 uip_arp_arpin();
00282
00283
00284
00285 if(uip_len > 0) {
00286 gmac_tapdev_send();
00287 }
00288 }
00289 } else if(timer_expired(&periodic_timer)) {
00290 timer_reset(&periodic_timer);
00291 for(i = 0; i < UIP_CONNS; i++) {
00292 uip_periodic(i);
00293 SCB_CleanInvalidateDCache();
00294
00295
00296
00297 if(uip_len > 0) {
00298 uip_arp_out();
00299 SCB_CleanInvalidateDCache();
00300 gmac_tapdev_send();
00301 }
00302 }
00303 #if UIP_UDP
00304 for(i = 0; i < UIP_UDP_CONNS; i++) {
00305 uip_udp_periodic(i);
00306 memory_sync();
00307
00308
00309
00310 if(uip_len > 0) {
00311 uip_arp_out();
00312 SCB_CleanInvalidateDCache();
00313 gmac_tapdev_send();
00314 }
00315 }
00316 #endif
00317
00318
00319 if(timer_expired(&arp_timer)) {
00320 timer_reset(&arp_timer);
00321 uip_arp_timer();
00322 }
00323 }
00324 }
00325 }
00326