Modified for W5500 Ethernet initialize Added the Ethernet interface re-initialize code Added the connection retry
Dependents: ThingPlug_Ethernet_Example
Fork of GMMP_mbed by
Diff: GMMP.cpp
- Revision:
- 4:1e04850ce835
- Parent:
- 3:6b4536e1962f
- Child:
- 5:9bbb6933559b
--- a/GMMP.cpp Wed Aug 12 02:13:34 2015 +0000 +++ b/GMMP.cpp Wed Aug 12 08:49:45 2015 +0000 @@ -53,8 +53,25 @@ #endif//USE_SNIC_WIFI #ifdef USE_WIZNET_W5500 - #include "WIZnetInterface.h" + #include "WIZnetInterface.h" + //#include "EthernetInterface.h" // WIZnet Ethernet library replacement(W5100/W5200/W5500 -> W5500/W7500) + + #if defined(TARGET_LPC1768) + SPI spi(p5, p6, p7); // mosi, miso, sclk + WIZnetInterface ethernet(&spi, p8, p11); + #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE) + //char tmpbuffer1[16] = {0, }; + SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk + WIZnetInterface ethernet(&spi, PB_6, PA_9);//scs(PB_6), nRESET(PA_9); // reset pin is dummy, don't affect any pin of WIZ550io + //WIZnetInterface ethernet(PA_7, PA_6, PA_5, PB_6, PA_9);//scs(PB_6), nRESET(PA_9); + //char tmpbuffer2[16] = {0, }; + #else + // Ethernet interface initialization code for additional platforms will be added later. + #endif #endif//USE_WIZNET_W5500 +#elif defined(TARGET_WIZwiki_W7500) + #include "EthernetInterface.h" + EthernetInterface ethernet; #endif #include "NTPClient.h" @@ -91,8 +108,6 @@ CloseSocket(); } - - int Initialize(byte* serverIp, const int nPort, const char* pszDomainCode, @@ -137,26 +152,15 @@ printf("IP Address is %s\r\n", wifi.getIPAddress()); #endif//USE_SNIC_WIFI - #ifdef USE_WIZNET_W5500 - - #if defined(TARGET_LPC1768) - SPI spi(p5, p6, p7); // mosi, miso, sclk - WIZnetInterface ethernet(&spi, p8, p11); - #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE) - SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk - WIZnetInterface ethernet(&spi, PB_6, PA_9);//scs(PB_6), nRESET(PA_9); // reset pin is dummy, don't affect any pin of WIZ550io - #else - // Ethernet interface initialization code for additional platforms will be added later. - #endif - + #ifdef USE_WIZNET_W5500 + //SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk + //EthernetInterface ethernet(&spi, PB_6, PA_9);//scs(PB_6), nRESET(PA_9); // reset pin is dummy, don't affect any pin of WIZ550io //mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres - #if defined(TARGET_NUCLEO_F411RE) - wait(0.5); + #if defined(TARGET_NUCLEO_F411RE) //spi.format(8,3); // Setup: bit data, high steady state clock, 2nd edge capture //spi.frequency(25000000); // SPI Clock; 25MHz (default: 1MHz) - spi.frequency(12000000); // SPI Clock; 12.5MHz (default: 1MHz) - wait(0.5); + //spi.frequency(12000000); // SPI Clock; 12.5MHz (default: 1MHz) #endif printf("input MAC Address is %02x:%02x:%02x:%02x:%02x:%02x\r\n", @@ -169,15 +173,34 @@ printf("W5500 Networking Started \r\n"); //wait(1); // 1 second for stable state - if (!ret) { - printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); - ret = ethernet.connect(); + if (!ret) { + ret = ethernet.connect(); if (!ret) { + printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); printf("IP: %s, MASK: %s, GW: %s\r\n", ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); } else { printf("Error ethernet.connect() - ret = %d\r\n", ret); //exit(0); + + // ## 20150812 Eric added, Ethernet interface re-initialize code + /////////////////////////////////////////////////////////////////////////// + do{ + //printf("Ethernet Interface Re-initialize\r\n"); + #if defined(TARGET_LPC1768) + SPI spi(p5, p6, p7); // mosi, miso, sclk + #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE) + SPI spi(PA_7, PA_6, PA_5); + #endif + //wait(0.5); + + ethernet.init(mac); + ret = ethernet.connect(); + printf("Re-initialized, MAC: %s\r\n", ethernet.getMACAddress()); + printf("IP: %s, MASK: %s, GW: %s\r\n", + ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); + } while(ret); + /////////////////////////////////////////////////////////////////////////// } } else { printf("Error ethernet.init() - ret = %d\r\n", ret); @@ -211,7 +234,7 @@ if(SetServerInfo(serverIp, nPort, pszGWAuthID, pszDomainCode) != 0) { return LIB_PARAM_ERROR; - } + } SetTID(0); @@ -268,10 +291,13 @@ int GO_Reg(const char* pszGWID, const char* pszManufactureID) -{ +{ + //CloseSocket(); + //SetIntiSocket(); + debugln("GO_Reg()"); SetTID(GetTID()+1); - + int nRet = GMMP_SetReg(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszManufactureID); debugln("GO_SetReg() Done");