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 Eric Jung

Revision:
3:6b4536e1962f
Parent:
2:0c4e3edf2918
Child:
4:1e04850ce835
--- 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;