Modified for W5500 Ethernet initialize
Fork of GMMP_mbed by
Revision 3:6b4536e1962f, committed 2015-08-12
- Comitter:
- hkjung
- Date:
- Wed Aug 12 02:13:34 2015 +0000
- Parent:
- 2:0c4e3edf2918
- Commit message:
- Modified for W5500 Ethernet initialize
Changed in this revision
--- a/Define/Define.h Sun Aug 09 15:02:18 2015 +0000 +++ b/Define/Define.h Wed Aug 12 02:13:34 2015 +0000 @@ -113,7 +113,7 @@ extern char g_szGWID[LEN_GW_ID]; extern char g_szDeviceID[LEN_DEVICE_ID]; -#define LOG_LEVEL 2 +#define LOG_LEVEL 0 #define LOG_LEVEL_NONE 6 #define LOG_LEVEL_FATAL 5 #define LOG_LEVEL_ERROR 4
--- a/GMMP.cpp Sun Aug 09 15:02:18 2015 +0000 +++ b/GMMP.cpp Wed Aug 12 02:13:34 2015 +0000 @@ -30,7 +30,8 @@ //#define USE_WIZNET_W5500 **/ -#if defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE) +// Added the code for LPC1768 platform +#if defined(TARGET_LPC1768) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE) #ifdef USE_SNIC_WIFI #include "SNIC_WifiInterface.h" @@ -52,11 +53,7 @@ #endif//USE_SNIC_WIFI #ifdef USE_WIZNET_W5500 - #include "WIZnetInterface.h" - SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk - char g_memory_guard_before[16]; - WIZnetInterface ethernet(&spi, PB_6, PA_9);//scs(PB_6), nRESET(PA_9); // reset pin is dummy, don't affect any pin of WIZ550io - char g_memory_guard_after[16]; + #include "WIZnetInterface.h" #endif//USE_WIZNET_W5500 #endif @@ -106,10 +103,10 @@ InitMemory(); - //delay(2000); -//NTPClient ntp; - - infoln("Getting IP..."); + //delay(2000); + //NTPClient ntp; + + infoln("Getting IP..."); #ifdef USE_SNIC_WIFI wifi.init(); @@ -141,7 +138,27 @@ #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 + //mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres + + #if defined(TARGET_NUCLEO_F411RE) + wait(0.5); + //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); + #endif + printf("input MAC Address is %02x:%02x:%02x:%02x:%02x:%02x\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -188,13 +205,14 @@ { printf("Error\r\n"); } - + g_pClient = new Client; //lesmin if(SetServerInfo(serverIp, nPort, pszGWAuthID, pszDomainCode) != 0) { return LIB_PARAM_ERROR; } + SetTID(0); return GMMP_SUCCESS;
--- a/Network/Network.cpp Sun Aug 09 15:02:18 2015 +0000 +++ b/Network/Network.cpp Wed Aug 12 02:13:34 2015 +0000 @@ -29,8 +29,8 @@ } int Connect() -{ - int ret = GMMP_SUCCESS; +{ + int ret = GMMP_SUCCESS; //delay(2000); infoln("Connecting..."); @@ -45,12 +45,30 @@ } // if (client.connect((char *)szServerIp, g_nServerPort)) { - if (g_pClient->connect((char *)szServerIp, g_nServerPort)) { - infoln("Connected!!"); - } else { - infoln("connection failed!"); - ret = SERVER_CONNECT_ERROR; - } + /* + if (g_pClient->connect((char *)szServerIp, g_nServerPort)) { + infoln("Connected!!"); + } else { + infoln("connection failed!"); + ret = SERVER_CONNECT_ERROR; + } + */ + int retry = 30; + do + { + if(retry <= 0) { + ret = SERVER_CONNECT_ERROR; + break; + } + + infoln("Trying to connect to Server..."); + if (g_pClient->connect((char *)szServerIp, g_nServerPort)) { + infoln("Connected!"); + break; + } + + infoln("Connection failed!"); + } while(retry--); return ret; } @@ -66,7 +84,7 @@ return LIB_PARAM_ERROR; } // client.write(pBuf, nLen); - g_pClient->write(pBuf, nLen); + g_pClient->write(pBuf, nLen); return GMMP_SUCCESS; }