This is the Interface library for WIZnet W5500 chip which forked of EthernetInterfaceW5500, WIZnetInterface and WIZ550ioInterface. This library has simple name as "W5500Interface". and can be used for Wiz550io users also.

Dependents:   EvrythngApi Websocket_Ethernet_HelloWorld_W5500 Websocket_Ethernet_W5500 CurrentWeatherData_W5500 ... more

Information

It has EthernetInterface class like official EthernetInterface , but uses Wiznet chip driver codes.

So this library can use only the WIZnet W5500 or WIZ550io users.

This library has referred to many project such as WIZ550ioInterface, WiflyInterface and WIZnet Library.

Thanks all.

Files at this revision

API Documentation at this revision

Comitter:
kaizen
Date:
Fri Sep 26 08:05:41 2014 +0000
Parent:
4:af0ed4fbca02
Child:
6:677dfa3984d1
Commit message:
Modified for using MQTT protocol ( IBMIoTClient )

Changed in this revision

EthernetInterface.cpp Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.h Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketServer.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
WIZnet/W5500.cpp Show annotated file Show diff for this revision Revisions of this file
WIZnet/W5500.h Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.cpp	Mon Sep 01 01:54:29 2014 +0000
+++ b/EthernetInterface.cpp	Fri Sep 26 08:05:41 2014 +0000
@@ -41,6 +41,14 @@
     ip_set = false;
 }
 
+////#if define(TARGET_KL25Z)
+//EthernetInterface::EthernetInterface() : WIZnet_Chip(D11, D12, D13, D10, D9) 
+//{
+//    wait(1); // 1 second for stable state
+//
+//    ip_set = false;
+//}
+
 int EthernetInterface::init()
 {
     dhcp = true;
--- a/EthernetInterface.h	Mon Sep 01 01:54:29 2014 +0000
+++ b/EthernetInterface.h	Fri Sep 26 08:05:41 2014 +0000
@@ -20,6 +20,7 @@
     */
     EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset);
     EthernetInterface(SPI* spi, PinName cs, PinName reset);
+//    EthernetInterface();
 
   /** Initialize the interface with DHCP w/o MAC address
   * Initialize the interface and configure it to use DHCP (no connection at this point).
--- a/Socket/TCPSocketServer.cpp	Mon Sep 01 01:54:29 2014 +0000
+++ b/Socket/TCPSocketServer.cpp	Fri Sep 26 08:05:41 2014 +0000
@@ -31,11 +31,11 @@
         }
     }
     // set TCP protocol
-    eth->setProtocol(_sock_fd, TCP);
+    eth->setProtocol(_sock_fd, WIZnet_Chip::TCP);
     // set local port
     eth->sreg<uint16_t>(_sock_fd, Sn_PORT, port);
     // connect the network
-    eth->scmd(_sock_fd, OPEN);
+    eth->scmd(_sock_fd, WIZnet_Chip::OPEN);
     return 0;
 }
 
@@ -47,7 +47,7 @@
     if (backlog != 1) {
         return -1;
     }
-    eth->scmd(_sock_fd, LISTEN);
+    eth->scmd(_sock_fd, WIZnet_Chip::LISTEN);
     return 0;
 }
 
@@ -64,7 +64,7 @@
         if (t.read_ms() > _timeout && _blocking == false) {
             return -1;
         }
-        if (eth->sreg<uint8_t>(_sock_fd, Sn_SR) == SOCK_ESTABLISHED) {
+        if (eth->sreg<uint8_t>(_sock_fd, Sn_SR) == WIZnet_Chip::SOCK_ESTABLISHED) {
             break;
         }
     }
--- a/Socket/UDPSocket.cpp	Mon Sep 01 01:54:29 2014 +0000
+++ b/Socket/UDPSocket.cpp	Fri Sep 26 08:05:41 2014 +0000
@@ -29,7 +29,7 @@
     if (_sock_fd < 0) {
         _sock_fd = eth->new_socket();
     }
-    if (eth->setProtocol(_sock_fd, UDP) == false) return -1;
+    if (eth->setProtocol(_sock_fd, WIZnet_Chip::UDP) == false) return -1;
     return 0;
 }
 
@@ -50,8 +50,8 @@
         eth->sreg<uint16_t>(_sock_fd, Sn_PORT, udp_local_port);
     }
     // set udp protocol
-    eth->setProtocol(_sock_fd, UDP);
-    eth->scmd(_sock_fd, OPEN);
+    eth->setProtocol(_sock_fd, WIZnet_Chip::UDP);
+    eth->scmd(_sock_fd, WIZnet_Chip::OPEN);
     return 0;
 }
 
--- a/WIZnet/W5500.cpp	Mon Sep 01 01:54:29 2014 +0000
+++ b/WIZnet/W5500.cpp	Fri Sep 26 08:05:41 2014 +0000
@@ -7,7 +7,7 @@
 #ifdef USE_W5500
 
 //Debug is disabled by default
-#if 0
+#if 1
 #define DBG(...) do{debug("%p %d %s ", this,__LINE__,__PRETTY_FUNCTION__); debug(__VA_ARGS__); } while(0);
 //#define DBG(x, ...) debug("[W5500:DBG]"x"\r\n", ##__VA_ARGS__);
 #define WARN(x, ...) debug("[W5500:WARN]"x"\r\n", ##__VA_ARGS__);
@@ -63,6 +63,15 @@
     return true;
 }
 
+bool WIZnet_Chip::linkstatus()
+{
+    if ( (reg_rd<uint8_t>(PHYCFGR) & 0x01) != 0x01 )
+        return false;
+
+    return true;
+}
+
+
 bool WIZnet_Chip::setProtocol(int socket, Protocol p)
 {
     if (socket < 0) {
--- a/WIZnet/W5500.h	Mon Sep 01 01:54:29 2014 +0000
+++ b/WIZnet/W5500.h	Fri Sep 26 08:05:41 2014 +0000
@@ -1,4 +1,3 @@
-
 #pragma once
 
 #include "mbed.h"
@@ -8,42 +7,6 @@
 
 #define DEFAULT_WAIT_RESP_TIMEOUT 500
 
-enum Protocol {
-    CLOSED = 0,
-    TCP    = 1,
-    UDP    = 2,
-};
-
-enum Command {
-    OPEN      = 0x01,
-    LISTEN    = 0x02,
-    CONNECT   = 0x04,
-    DISCON    = 0x08,
-    CLOSE     = 0x10,
-    SEND      = 0x20,
-    SEND_MAC  = 0x21, 
-    SEND_KEEP = 0x22,
-    RECV      = 0x40,
-    
-};
-
-enum Interrupt {
-    INT_CON     = 0x01,
-    INT_DISCON  = 0x02,
-    INT_RECV    = 0x04,
-    INT_TIMEOUT = 0x08,
-    INT_SEND_OK = 0x10,
-};
-
-enum Status {
-    SOCK_CLOSED      = 0x00,
-    SOCK_INIT        = 0x13,
-    SOCK_LISTEN      = 0x14,
-    SOCK_SYNSENT     = 0x15,
-    SOCK_ESTABLISHED = 0x17,
-    SOCK_CLOSE_WAIT  = 0x1c,
-    SOCK_UDP         = 0x22,
-};
 
 #define MAX_SOCK_NUM 8
 
@@ -52,7 +15,7 @@
 #define SUBR      0x0005
 #define SHAR      0x0009
 #define SIPR      0x000f
-#define PHYSTATUS 0x0035
+#define PHYCFGR   0x002e
 
 // W5500 socket register
 #define Sn_MR         0x0000
@@ -71,6 +34,15 @@
 
 class WIZnet_Chip {
 public:
+
+    enum Protocol   { CLOSED = 0, TCP = 1, UDP = 2,};
+    enum Command    { OPEN = 0x01, LISTEN = 0x02, CONNECT = 0x04, DISCON = 0x08, CLOSE = 0x10, SEND = 0x20, \
+                        SEND_MAC = 0x21, SEND_KEEP = 0x22, RECV = 0x40, };
+    enum Interrupt  { INT_CON = 0x01, INT_DISCON = 0x02, INT_RECV = 0x04, INT_TIMEOUT = 0x08, INT_SEND_OK = 0x10,};
+
+    enum Status     { SOCK_CLOSED = 0x00, SOCK_INIT = 0x13, SOCK_LISTEN = 0x14, SOCK_SYNSENT = 0x15, SOCK_ESTABLISHED = 0x17, \
+                         SOCK_CLOSE_WAIT = 0x1c, SOCK_UDP   = 0x22, };
+
     /*
     * Constructor
     *
@@ -96,6 +68,13 @@
     bool setip();
 
     /*
+    * Get Link Status
+    *
+    * @return true if Link up, false Link down
+    */
+    bool linkstatus();
+
+    /*
     * Disconnect the connection
     *
     * @ returns true