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
00101 #include "board.h"
00102
00103 #include "uip.h"
00104 #include "uip_arp.h"
00105 #include "gmac_tapdev.h"
00106 #include "timer.h"
00107
00108
00109
00110
00111
00112
00113 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00114
00115
00116 static const struct uip_eth_addr MacAddress = {{0x3a, 0x1f, 0x34, 0x08, 0x54, 0x54}};
00117
00118
00119 static uint8_t HostIpAddress[4] ={192, 168, 1, 3 };
00120
00121
00122 static const uint8_t RoutIpAddress[4] = {192, 168, 1, 2 };
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: hello-world application init\n\r");
00136 hello_world_init();
00137
00138 #ifdef __DHCPC_H__
00139 printf("P: DHCPC Init\n\r");
00140 dhcpc_init(MacAddress.addr, 6);
00141 #endif
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 void uip_log(char *m)
00153 {
00154 TRACE_INFO("-uIP log- %s\n\r", m);
00155 }
00156
00157 #ifdef __DHCPC_H__
00158
00159
00160
00161
00162
00163 void dhcpc_configured(const struct dhcpc_state *s)
00164 {
00165 u8_t * pAddr;
00166
00167 printf("\n\r");
00168 printf("=== DHCP Configurations ===\n\r");
00169 pAddr = (u8_t *)s->ipaddr;
00170 printf("- IP : %d.%d.%d.%d\n\r",
00171 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00172 pAddr = (u8_t *)s->netmask;
00173 printf("- Mask : %d.%d.%d.%d\n\r",
00174 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00175 pAddr = (u8_t *)s->default_router;
00176 printf("- GW : %d.%d.%d.%d\n\r",
00177 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00178 pAddr = (u8_t *)s->dnsaddr;
00179 printf("- DNS : %d.%d.%d.%d\n\r",
00180 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00181 printf("===========================\n\r\n");
00182 uip_sethostaddr(s->ipaddr);
00183 uip_setnetmask(s->netmask);
00184 uip_setdraddr(s->default_router);
00185
00186 #ifdef __RESOLV_H__
00187 resolv_conf(s->dnsaddr);
00188 #else
00189 printf("DNS NOT enabled in the demo\n\r");
00190 #endif
00191 }
00192 #endif
00193
00194
00195
00196
00197
00198
00199 int main(void)
00200 {
00201 uip_ipaddr_t ipaddr;
00202 struct timer periodic_timer, arp_timer;
00203 uint32_t i;
00204
00205
00206 WDT_Disable( WDT ) ;
00207
00208 SCB_EnableICache();
00209 SCB_EnableDCache();
00210
00211 printf("-- GMAC uIP Hello World Example %s --\n\r", SOFTPACK_VERSION);
00212 printf("-- %s\n\r", BOARD_NAME);
00213 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00214
00215
00216
00217 TimeTick_Configure ();
00218
00219
00220 printf(" - MAC %x:%x:%x:%x:%x:%x\n\r",
00221 MacAddress.addr[0], MacAddress.addr[1], MacAddress.addr[2],
00222 MacAddress.addr[3], MacAddress.addr[4], MacAddress.addr[5]);
00223 #ifndef __DHCPC_H__
00224 printf(" - Host IP %d.%d.%d.%d\n\r",
00225 HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]);
00226 printf(" - Router IP %d.%d.%d.%d\n\r",
00227 RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]);
00228 printf(" - Net Mask %d.%d.%d.%d\n\r",
00229 NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
00230 #endif
00231
00232
00233 gmac_tapdev_setmac((uint8_t *)MacAddress.addr);
00234 gmac_tapdev_init();
00235 clock_init();
00236 timer_set(&periodic_timer, CLOCK_SECOND / 2);
00237 timer_set(&arp_timer, CLOCK_SECOND * 10);
00238
00239
00240 uip_init();
00241
00242 #ifdef __DHCPC_H__
00243 printf("P: DHCP Supported\n\r");
00244 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00245 uip_sethostaddr(ipaddr);
00246 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00247 uip_setdraddr(ipaddr);
00248 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00249 uip_setnetmask(ipaddr);
00250 #else
00251
00252 uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1],
00253 HostIpAddress[2], HostIpAddress[3]);
00254 uip_sethostaddr(ipaddr);
00255
00256 uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1],
00257 RoutIpAddress[2], RoutIpAddress[3]);
00258 uip_setdraddr(ipaddr);
00259
00260 uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
00261 uip_setnetmask(ipaddr);
00262 #endif
00263
00264 uip_setethaddr(MacAddress);
00265
00266 _app_init();
00267
00268 while(1) {
00269 uip_len = gmac_tapdev_read();
00270 if(uip_len > 0) {
00271 if(BUF->type == htons(UIP_ETHTYPE_IP)) {
00272 uip_arp_ipin();
00273 uip_input();
00274
00275
00276
00277 if(uip_len > 0) {
00278 uip_arp_out();
00279 gmac_tapdev_send();
00280 }
00281 } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
00282
00283 uip_arp_arpin();
00284
00285
00286
00287 if(uip_len > 0) {
00288 gmac_tapdev_send();
00289 }
00290 }
00291 } else if(timer_expired(&periodic_timer)) {
00292 timer_reset(&periodic_timer);
00293 for(i = 0; i < UIP_CONNS; i++) {
00294 uip_periodic(i);
00295
00296
00297
00298 if(uip_len > 0) {
00299
00300 uip_arp_out();
00301 gmac_tapdev_send();
00302 }
00303 }
00304 #if UIP_UDP
00305 for(i = 0; i < UIP_UDP_CONNS; i++) {
00306 uip_udp_periodic(i);
00307
00308
00309
00310 if(uip_len > 0) {
00311 uip_arp_out();
00312 gmac_tapdev_send();
00313 }
00314 }
00315 #endif
00316
00317
00318 if(timer_expired(&arp_timer)) {
00319 timer_reset(&arp_timer);
00320 uip_arp_timer();
00321 }
00322 }
00323 }
00324 }
00325