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
00102
00103
00104
00105
00106
00107
00108 #include "board.h"
00109
00110 #include "uip.h"
00111 #include "uip_arp.h"
00112 #include "gmac_tapdev.h"
00113 #include "timer.h"
00114
00115
00116
00117
00118
00119
00120 #define TWCK 400000
00121
00122 #define AT24MAC_SERIAL_NUM_ADD 0x5F
00123
00124 #define PAGE_SIZE 16
00125
00126 #define EEPROM_PAGES 16
00127
00128 #define BOARD_PINS_TWI_EEPROM PINS_TWI0
00129
00130 #define BOARD_ID_TWI_EEPROM ID_TWIHS0
00131
00132 #define BOARD_BASE_TWI_EEPROM TWIHS0
00133
00134
00135 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00136
00137
00138 static Twid twid;
00139
00140
00141 static const Pin twiPins[] = BOARD_PINS_TWI_EEPROM;
00142
00143
00144 static struct uip_eth_addr GMacAddress = {{0x3a, 0x1f, 0x34, 0x08, 0x54, 0x54}};
00145
00146
00147 static uint8_t HostIpAddress[4] = {192, 168, 1, 3 };
00148
00149
00150 static const uint8_t RoutIpAddress[4] = {192, 168, 1, 2 };
00151
00152
00153 static const uint8_t NetMask[4] = {255, 255, 255, 0};
00154
00155
00156
00157
00158
00159
00160
00161
00162 static void _app_init(void)
00163 {
00164 printf("P: telnetd application init\n\r");
00165 telnetd_init();
00166
00167 #ifdef __DHCPC_H__
00168 printf("P: DHCPC Init\n\r");
00169 dhcpc_init(MacAddress.addr, 6);
00170 #endif
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 void uip_log(char *m)
00182 {
00183 TRACE_INFO("-uIP log- %s\n\r", m);
00184 }
00185
00186 #ifdef __DHCPC_H__
00187
00188
00189
00190
00191
00192 void dhcpc_configured(const struct dhcpc_state *s)
00193 {
00194 u8_t *pAddr;
00195
00196 printf("\n\r");
00197 printf("=== DHCP Configurations ===\n\r");
00198 pAddr = (u8_t *)s->ipaddr;
00199 printf("- IP : %d.%d.%d.%d\n\r",
00200 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00201 pAddr = (u8_t *)s->netmask;
00202 printf("- Mask : %d.%d.%d.%d\n\r",
00203 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00204 pAddr = (u8_t *)s->default_router;
00205 printf("- GW : %d.%d.%d.%d\n\r",
00206 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00207 pAddr = (u8_t *)s->dnsaddr;
00208 printf("- DNS : %d.%d.%d.%d\n\r",
00209 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00210 printf("===========================\n\r\n");
00211 uip_sethostaddr(s->ipaddr);
00212 uip_setnetmask(s->netmask);
00213 uip_setdraddr(s->default_router);
00214
00215 #ifdef __RESOLV_H__
00216 resolv_conf(s->dnsaddr);
00217 #else
00218 printf("DNS NOT enabled in the demo\n\r");
00219 #endif
00220 }
00221 #endif
00222
00223
00224
00225
00226
00227
00228 int main(void)
00229 {
00230 uip_ipaddr_t ipaddr;
00231 struct timer periodic_timer, arp_timer;
00232 uint32_t i;
00233 struct uip_eth_addr OrigiGMacAddr;
00234
00235
00236 WDT_Disable(WDT);
00237
00238 SCB_EnableICache();
00239 SCB_EnableDCache();
00240
00241 TimeTick_Configure();
00242 printf("-- GMAC uIP Telnetd Example %s --\n\r", SOFTPACK_VERSION);
00243 printf("-- %s\n\r", BOARD_NAME);
00244 printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
00245 COMPILER_NAME);
00246
00247
00248 TimeTick_Configure();
00249
00250 PIO_Configure(twiPins, PIO_LISTSIZE(twiPins));
00251
00252 PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM);
00253 TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK);
00254 TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM);
00255
00256 TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x9A, 1, OrigiGMacAddr.addr, PAGE_SIZE,
00257 0);
00258
00259 if ((OrigiGMacAddr.addr[0] == 0xFC) && (OrigiGMacAddr.addr[1] == 0xC2)
00260 && (OrigiGMacAddr.addr[2] == 0x3D)) {
00261 for (i = 0; i < 6; i++)
00262 GMacAddress.addr[i] = OrigiGMacAddr.addr[i];
00263 }
00264
00265 printf("-- MAC %x:%x:%x:%x:%x:%x\n\r",
00266 GMacAddress.addr[0], GMacAddress.addr[1], GMacAddress.addr[2],
00267 GMacAddress.addr[3], GMacAddress.addr[4], GMacAddress.addr[5]);
00268
00269 #ifndef __DHCPC_H__
00270 printf(" - Host IP %d.%d.%d.%d\n\r",
00271 HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]);
00272 printf(" - Router IP %d.%d.%d.%d\n\r",
00273 RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]);
00274 printf(" - Net Mask %d.%d.%d.%d\n\r",
00275 NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
00276 #endif
00277
00278
00279 gmac_tapdev_setmac((uint8_t *)GMacAddress.addr);
00280 gmac_tapdev_init();
00281 clock_init();
00282 timer_set(&periodic_timer, CLOCK_SECOND / 2);
00283 timer_set(&arp_timer, CLOCK_SECOND * 10);
00284
00285
00286 uip_init();
00287
00288 #ifdef __DHCPC_H__
00289 printf("P: DHCP Supported\n\r");
00290 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00291 uip_sethostaddr(ipaddr);
00292 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00293 uip_setdraddr(ipaddr);
00294 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00295 uip_setnetmask(ipaddr);
00296 #else
00297
00298 uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1],
00299 HostIpAddress[2], HostIpAddress[3]);
00300 uip_sethostaddr(ipaddr);
00301
00302 uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1],
00303 RoutIpAddress[2], RoutIpAddress[3]);
00304 uip_setdraddr(ipaddr);
00305
00306 uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
00307 uip_setnetmask(ipaddr);
00308 #endif
00309 uip_setethaddr(GMacAddress);
00310 _app_init();
00311
00312 while (1) {
00313 uip_len = gmac_tapdev_read();
00314
00315 if (uip_len > 0) {
00316 if (BUF->type == htons(UIP_ETHTYPE_IP)) {
00317 uip_arp_ipin();
00318 uip_input();
00319
00320
00321
00322
00323 if (uip_len > 0) {
00324 uip_arp_out();
00325 gmac_tapdev_send();
00326 }
00327 } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
00328 uip_arp_arpin();
00329
00330
00331
00332
00333 if (uip_len > 0)
00334 gmac_tapdev_send();
00335 }
00336 } else if (timer_expired(&periodic_timer)) {
00337 timer_reset(&periodic_timer);
00338
00339 for (i = 0; i < UIP_CONNS; i++) {
00340 uip_periodic(i);
00341
00342
00343
00344
00345 if (uip_len > 0) {
00346 uip_arp_out();
00347 gmac_tapdev_send();
00348 }
00349 }
00350
00351 #if UIP_UDP
00352
00353 for (i = 0; i < UIP_UDP_CONNS; i++) {
00354 uip_udp_periodic(i);
00355
00356
00357
00358
00359 if (uip_len > 0) {
00360 uip_arp_out();
00361 gmac_tapdev_send();
00362 }
00363 }
00364
00365 #endif
00366
00367
00368 if (timer_expired(&arp_timer)) {
00369 timer_reset(&arp_timer);
00370 uip_arp_timer();
00371 }
00372 }
00373 }
00374 }
00375