.

Fork of WIZnet_Library by WIZnet

Files at this revision

API Documentation at this revision

Comitter:
jbkim
Date:
Fri May 09 01:17:51 2014 +0000
Parent:
0:b72d22e10709
Child:
2:c2eb7a08d7e6
Commit message:
Wiznet Ethernet library 1st release

Changed in this revision

WIZnetInterface/WIZnet/W5100.cpp Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface/WIZnet/W5100.h Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface/WIZnet/W5200.cpp Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface/WIZnet/W5200.h Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface/WIZnet/W5500.cpp Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface/WIZnet/W5500.h Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface/WIZnetInterface.cpp Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface/WIZnetInterface.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/WIZnetInterface/WIZnet/W5100.cpp	Thu May 08 03:57:58 2014 +0000
+++ b/WIZnetInterface/WIZnet/W5100.cpp	Fri May 09 01:17:51 2014 +0000
@@ -150,12 +150,6 @@
     
     reg_wr<uint8_t>(MR, 1<<7);
     
-#if defined (TARGET_LPC1768)
-    uint8_t mac[6];
-    mbed_mac_address((char*)mac);
-#else
-    uint8_t mac[6] = {0x00,0x08,0xDC,0x00,0x00,0x00};
-#endif
     reg_wr_mac(SHAR, mac);
 }
 
--- a/WIZnetInterface/WIZnet/W5100.h	Thu May 08 03:57:58 2014 +0000
+++ b/WIZnetInterface/WIZnet/W5100.h	Fri May 09 01:17:51 2014 +0000
@@ -236,6 +236,7 @@
     }
 
 protected:
+    uint8_t mac[6];
     uint32_t ip;
     uint32_t netmask;
     uint32_t gateway;
--- a/WIZnetInterface/WIZnet/W5200.cpp	Thu May 08 03:57:58 2014 +0000
+++ b/WIZnetInterface/WIZnet/W5200.cpp	Fri May 09 01:17:51 2014 +0000
@@ -142,14 +142,6 @@
     
     reg_wr<uint8_t>(MR, 1<<7);
 
-
-#if defined (TARGET_LPC1768)
-    uint8_t mac[6];
-    mbed_mac_address((char*)mac);
-#else
-    uint8_t mac[6] = {0x00,0x08,0xDC,0x00,0x00,0x00};
-#endif
-
     reg_wr_mac(SHAR, mac);
 }
 
--- a/WIZnetInterface/WIZnet/W5200.h	Thu May 08 03:57:58 2014 +0000
+++ b/WIZnetInterface/WIZnet/W5200.h	Fri May 09 01:17:51 2014 +0000
@@ -238,6 +238,7 @@
     }
 
 protected:
+    uint8_t mac[6];
     uint32_t ip;
     uint32_t netmask;
     uint32_t gateway;
--- a/WIZnetInterface/WIZnet/W5500.cpp	Thu May 08 03:57:58 2014 +0000
+++ b/WIZnetInterface/WIZnet/W5500.cpp	Fri May 09 01:17:51 2014 +0000
@@ -141,13 +141,6 @@
     reset_pin = 1;
     wait_ms(400); // 400ms (w5500)
 
-#if defined (TARGET_LPC1768) || (TARGET_LPC11U24)
-    uint8_t mac[6];
-    mbed_mac_address((char*)mac);
-#else
-    uint8_t mac[6] = {0x00,0x08,0xDC,0x00,0x00,0x00};
-#endif
-
 #if defined(USE_WIZ550IO_MAC)
     reg_rd_mac(SHAR, mac); // read the MAC address inside the module
 #endif
--- a/WIZnetInterface/WIZnet/W5500.h	Thu May 08 03:57:58 2014 +0000
+++ b/WIZnetInterface/WIZnet/W5500.h	Fri May 09 01:17:51 2014 +0000
@@ -247,6 +247,7 @@
     }
 
 protected:
+    uint8_t mac[6];
     uint32_t ip;
     uint32_t netmask;
     uint32_t gateway;
--- a/WIZnetInterface/WIZnetInterface.cpp	Thu May 08 03:57:58 2014 +0000
+++ b/WIZnetInterface/WIZnetInterface.cpp	Fri May 09 01:17:51 2014 +0000
@@ -31,16 +31,22 @@
     ip_set = false;
 }
 
-int WIZnetInterface::init()
+int WIZnetInterface::init(uint8_t * mac)
 {
     dhcp = true;
+    //
+    for (int i =0; i < 6; i++) this->mac[i] = mac[i];
+    //
     reset();
     return 0;
 }
 
-int WIZnetInterface::init(const char* ip, const char* mask, const char* gateway)
+int WIZnetInterface::init(uint8_t * mac, const char* ip, const char* mask, const char* gateway)
 {
     dhcp = false;
+    //
+    for (int i =0; i < 6; i++) this->mac[i] = mac[i];
+    //
     this->ip = str_to_ip(ip);
     strcpy(ip_string, ip);
     ip_set = true;
@@ -97,7 +103,8 @@
     uint8_t mac[6];
     reg_rd_mac(SHAR, mac);
     snprintf(mac_string, sizeof(mac_string), "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
-    return mac_string;
+    return mac_string; 
+    
 }
 
 int WIZnetInterface::IPrenew(int timeout_ms)
--- a/WIZnetInterface/WIZnetInterface.h	Thu May 08 03:57:58 2014 +0000
+++ b/WIZnetInterface/WIZnetInterface.h	Fri May 09 01:17:51 2014 +0000
@@ -17,7 +17,6 @@
  */
 
 #pragma once
-
 #include "wiznet.h"
 
  /** Interface using Wiznet chip to connect to an IP-based network
@@ -42,7 +41,7 @@
   * Initialize the interface and configure it to use DHCP (no connection at this point).
   * \return 0 on success, a negative number on failure
   */
-  int init(); //With DHCP
+  int init(uint8_t * mac); //With DHCP
 
   /** Initialize the interface with a static IP address.
   * Initialize the interface and configure it with the following static configuration (no connection at this point).
@@ -51,7 +50,7 @@
   * \param gateway the gateway to use
   * \return 0 on success, a negative number on failure
   */
-  int init(const char* ip, const char* mask, const char* gateway);
+  int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway);
 
   /** Connect
   * Bring the interface up, start DHCP if needed.
--- a/main.cpp	Thu May 08 03:57:58 2014 +0000
+++ b/main.cpp	Fri May 09 01:17:51 2014 +0000
@@ -7,54 +7,70 @@
 #include "WIZnetInterface.h"
 
 #define ECHO_SERVER_PORT   5000
-const char* ECHO_SERVER_ADDRESS = "192.168.1.229";
+const char* ECHO_SERVER_ADDRESS = "192.168.1.229";  // Server IP address
 
+/** 
+* Setting DHCP or static
+*/
+//#define USE_DHCP
+
+/** 
+* Setting the platform to test
+*/
 #define LPC
 //#define ST_NUCLEO
-
-// Setting Seial setting
-//Serial pc(P1_13, P1_14); // tx, rx
-//Serial pc(PA_2, PA_3); // tx, rx
-
-#define TCP_Server
-//#define TCP_Client
-//#define UDP_Server
-//#define UDP_Client
+//#define FRDM_KL25Z
+//#define Seeeduino_Arch
 
 #ifdef LPC
 // LPC1768 & LPC11U24
 SPI spi(p5, p6, p7); // mosi, miso, sclk
 WIZnetInterface eth(&spi, p8, p9); // spi, cs, reset
-Serial pc(USBTX,USBRX);
 #endif
 
 #ifdef ST_NUCLEO
 // ST Nucleo
 SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
 WIZnetInterface eth(&spi, PB_6, PA_10); // spi, cs, reset
-Serial pc(USBTX,USBRX);
+#endif
+
+#ifdef FRDM_KL25Z
+// Freescale FRDM KL25Z
+SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk
+WIZnetInterface eth(&spi, PTD0, PTA20); // spi, cs, reset
 #endif
 
+#ifdef Seeeduino_Arch
 // Seeedstudio Arch
-//SPI spi(P1_22, P1_21, P1_20); // mosi, miso, sclk
-//WIZnetInterface eth(&spi, P0_2, P0_0); // spi, cs, reset
+SPI spi(P1_22, P1_21, P1_20); // mosi, miso, sclk
+WIZnetInterface eth(&spi, P0_2, P0_0); // spi, cs, reset
+    Serial pc(P1_13, P1_14); // tx, rx
+#else
+    Serial pc(USBTX,USBRX);
+#endif
 
-// Freescale FRDM KL25Z
-//SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk
-//WIZnetInterface eth(&spi, PTD0, PTA20); // spi, cs, reset
-//Serial pc(USBTX,USBRX);
-
+#ifndef USE_DHCP
+// for static IP setting
 const char * IP_Addr    = "192.168.1.120";
 const char * IP_Subnet  = "255.255.255.0";
 const char * IP_Gateway = "192.168.1.111";
+#endif
 
 
 int main()
 {
+    uint8_t mac[6];
+    
+    mbed_mac_address((char *)mac);     // using the MAC address in LPC11U24 or LPC1178
+//    mac[0] = 0x00; mac[1] = 0x08; mac[2] = 0xDC; mac[3] = 0x00; mac[4] = 0x00; mac[5] = 0x00; 
+// you can alo use WIZ550io's MAC address by enabling "USE_WIZ550IO_MAC" in wiznet.h
+    
     pc.printf("Start\n");
-
-//    int ret = eth.init(); //Use DHCP
-    int ret = eth.init(IP_Addr, IP_Subnet, IP_Gateway); // static
+    #ifdef USE_DHCP
+      int ret = eth.init(mac); //Use DHCP
+    #else
+      int ret = eth.init(mac, IP_Addr, IP_Subnet, IP_Gateway); // static
+    #endif
 
     if (!ret) {
         pc.printf("Initialized, MAC: %s\n", eth.getMACAddress());
@@ -72,8 +88,6 @@
         return -1;
     }
 
-
-#ifdef TCP_Server
     TCPSocketServer server;
     server.bind(ECHO_SERVER_PORT);
     server.listen();
@@ -96,100 +110,4 @@
 
         client.close();
     }
-#endif
-
-#ifdef TCP_Client
-    TCPSocketConnection socket;
-    while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) {
-        printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
-        wait(1);
-    }
-
-    char hello[] = "Hello World\n";
-    socket.send_all(hello, sizeof(hello) - 1);
-
-    char buf[256];
-    int n = socket.receive(buf, 256);
-    buf[n] = '\0';
-    printf("%s", buf);
-
-    socket.close();
-    eth.disconnect();
-
-    while(true) {}
-#endif
-
-
-#ifdef UDP_Server
-    UDPSocket server;
-    ret = server.bind(ECHO_SERVER_PORT);
-    printf("sock.bind = %d\n", ret);
-
-    Endpoint client;
-    char buffer[256];
-    while (true) {
-        printf("\nWait for packet...\n");
-        int n = server.receiveFrom(client, buffer, sizeof(buffer));
-
-        printf("Received packet from: %s\n", client.get_address());
-        server.sendTo(client, buffer, n);
-    }
-#endif
-
-#ifdef UDP_Client
-    UDPSocket sock;
-    ret = sock.init();
-    sock.bind(0);
-    printf("sock.bind = %d\n", ret);
-    if (ret == -1) printf("Socket creation Fail\n");
-
-    Endpoint echo_server;
-    echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
-
-    printf("\nSend UDP data\n");
-
-    char out_buffer[] = "Hello World\n";
-    ret = sock.sendTo(echo_server, out_buffer, sizeof(out_buffer));
-    if (ret < 0) printf("UDP Send Error\n");
-    else printf("UDP Send: %d\n", ret);
-
-    char in_buffer[256];
-    int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer));
-
-    in_buffer[n] = '\0';
-    printf("%s\n", in_buffer);
-
-    sock.close();
-
-    eth.disconnect();
-    while(1) {}
-#endif
-
-#ifdef NTP
-// NTP
-    time_t ctTime;
-    ctTime = time(NULL);
-    printf("1. Current Time is: %s\r\n", ctime(&ctTime));
-
-    printf("Trying to update time...\r\n");
-    if (ntp.setTime("0.pool.ntp.org") == 0) {
-        ctTime = time(NULL);
-        printf("2. Current Time is: %s\r\n", ctime(&ctTime));
-
-        // resetting GMT+9
-        set_time( time(NULL) + 32400 ); // 9x60x60
-        //
-        printf("Set time successfully\r\n");
-        //time_t ctTime;
-        ctTime = time(NULL);
-        printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
-    } else {
-        printf("Error\r\n");
-    }
-
-    eth.disconnect();
-
-    while(1) {
-    }
-#endif
 }