WIZ820io(W5200) network interface、EthernetNetIf compatible.

/media/uploads/va009039/wiz820ionetif.jpg

example

#include "WIZ820ioNetIf.h"
#include "HTTPClient.h"
#include "HTTPServer.h"

#if defined(TARGET_KL25Z)
WIZ820ioNetIf eth(PTD2,PTD3,PTD1,PTD0,PTD5);
#endif
HTTPClient http;
HTTPStream stream;

void callback(HTTPResult r){
    printf("callback %d %s\n", r, HTTPClient::ResultStr(r));
}

int main() {
    int err = eth.setup();
    if (err < 0) {
        printf("setup error %d\n", err);
        exit(-1);
    }    

    HTTPServer svr;
    svr.addHandler<SimpleHandler>("/");
    svr.bind(80);

    const char* uri = "http://va009039-mbed.appspot.com/kl25z/";
    http.get(uri, &stream, callback);
    uint8_t buf[256];
    int total = 0;
    stream.readNext(buf, sizeof(buf));
    while(1) {
        if(stream.readable()) {
            int len = stream.readLen();
            total += len;
            printf("%d %d\n", total, len);
            stream.readNext(buf, sizeof(buf));
        }
        Net::poll();
    }
}
Revision:
1:22b9052d864d
Parent:
0:bdeec5f86894
diff -r bdeec5f86894 -r 22b9052d864d MyNetUdpSocket.cpp
--- a/MyNetUdpSocket.cpp	Fri Mar 22 11:51:24 2013 +0000
+++ b/MyNetUdpSocket.cpp	Sun Mar 24 11:25:31 2013 +0000
@@ -1,7 +1,7 @@
 // MyNetUdpSocket.cpp 2012/4/16
 #include "mbed.h"
 #include "MyNetUdpSocket.h"
-#include "w5100.h"
+#include "w5200.h"
 
 //#define DEBUG
 
@@ -20,7 +20,7 @@
         _socket = w5200_new_socket();
     }
     if (_socket != (-1)) {
-        W5100.writeSnMR(_socket, SnMR::UDP); // set UDP mode
+        W5200.writeSnMR(_socket, SnMR::UDP); // set UDP mode
     }
 }
 
@@ -28,7 +28,7 @@
     PRINT_FUNC();
     close();
     if (_socket != (-1)) {
-        W5100.writeSnMR(_socket, SnMR::CLOSE);
+        W5200.writeSnMR(_socket, SnMR::CLOSE);
     }
 }
 
@@ -38,8 +38,8 @@
         return NETUDPSOCKET_MEM;
     }
     int port = me.getPort();
-    W5100.writeSnPORT(_socket, port);
-    W5100.execCmdSn( _socket, Sock_OPEN); // set OPEN command
+    W5200.writeSnPORT(_socket, port);
+    W5200.execCmdSn( _socket, Sock_OPEN); // set OPEN command
     return NETUDPSOCKET_OK;
 }
 
@@ -54,16 +54,16 @@
     ip[2] = pHost->getIp()[2];
     ip[3] = pHost->getIp()[3];
     int port = pHost->getPort();
-    W5100.writeSnDIPR(_socket, ip);
-    W5100.writeSnDPORT(_socket, port);
-    W5100.send_data_processing(_socket, (uint8_t*)buf, len);
-    W5100.execCmdSn(_socket, Sock_SEND);
+    W5200.writeSnDIPR(_socket, ip);
+    W5200.writeSnDPORT(_socket, port);
+    W5200.send_data_processing(_socket, (uint8_t*)buf, len);
+    W5200.execCmdSn(_socket, Sock_SEND);
 #ifdef DEBUG
     printHex((u8*)buf, len);
-    W5100.getIPAddress(ip);
-    printf("SIPR: %d.%d.%d.%d Sn_PORT:%d\n", ip[0], ip[1], ip[2], ip[3], W5100.readSnPORT(_socket));
-    W5100.readSnDIPR(_socket, ip);
-    printf("Sn_DIPR: %d.%d.%d.%d Sn_DPORT:%d\n", ip[0], ip[1], ip[2], ip[3], W5100.readSnDPORT(_socket));
+    W5200.getIPAddress(ip);
+    printf("SIPR: %d.%d.%d.%d Sn_PORT:%d\n", ip[0], ip[1], ip[2], ip[3], W5200.readSnPORT(_socket));
+    W5200.readSnDIPR(_socket, ip);
+    printf("Sn_DIPR: %d.%d.%d.%d Sn_DPORT:%d\n", ip[0], ip[1], ip[2], ip[3], W5200.readSnDPORT(_socket));
 #endif //DEBUG
     return len;
 }
@@ -73,21 +73,21 @@
     if (_socket == (-1)) {
         return NETUDPSOCKET_MEM;
     }
-    int size = W5100.getRXReceivedSize(_socket);
+    int size = W5200.getRXReceivedSize(_socket);
     if (size < 8) {
         return -1;
     }
     uint8_t info[8];
-    W5100.recv_data_processing(_socket, info, 8);
-    W5100.execCmdSn(_socket, Sock_RECV);
+    W5200.recv_data_processing(_socket, info, 8);
+    W5200.execCmdSn(_socket, Sock_RECV);
     pHost->setIp(IpAddr(info[0],info[1],info[2],info[3]));
     pHost->setPort(info[4]<<8|info[5]);
     size -= 8;
     if (size > len) {
         size = len;
     }    
-    W5100.recv_data_processing(_socket, (uint8_t*)buf, size);
-    W5100.execCmdSn(_socket, Sock_RECV);
+    W5200.recv_data_processing(_socket, (uint8_t*)buf, size);
+    W5200.execCmdSn(_socket, Sock_RECV);
 #ifdef DEBUG
     printfBytes("UDP PACKET-INFO", (u8*)info, 8);
     printHex((u8*)buf, size);
@@ -105,7 +105,7 @@
     }
     m_closed = true;
     cleanUp();
-    W5100.writeSnMR(_socket, SnMR::CLOSE);
+    W5200.writeSnMR(_socket, SnMR::CLOSE);
     return NETUDPSOCKET_OK;
 }
 
@@ -116,22 +116,22 @@
     printf("%p socket:%d\n", this,_socket); 
     if (_socket != (-1)) {
         printf("SnMR:%02x SnIR:%02x SnSR:%02x\n",  
-            W5100.readSnMR(_socket), W5100.readSnIR(_socket), W5100.readSnSR(_socket));
+            W5200.readSnMR(_socket), W5200.readSnIR(_socket), W5200.readSnSR(_socket));
         uint8_t ip[4];
-        W5100.readSnDIPR(_socket, ip);
-        printf("Sn_DIPR: %d.%d.%d.%d Sn_DPORT: %d\n", ip[0], ip[1], ip[2], ip[3], W5100.readSnDPORT(_socket));
+        W5200.readSnDIPR(_socket, ip);
+        printf("Sn_DIPR: %d.%d.%d.%d Sn_DPORT: %d\n", ip[0], ip[1], ip[2], ip[3], W5200.readSnDPORT(_socket));
         uint8_t mac[6];
-        W5100.readSnDHAR(_socket, mac);
+        W5200.readSnDHAR(_socket, mac);
         printf("Sn_DHAR: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
         printf("Sn_RX_RSR:%5d, Sn_RX_RD:%5d, Sn_RX_WR:%5d\n",
-                W5100.readSnRX_RSR(_socket), W5100.readSnRX_RD(_socket), W5100.readSnRX_WR(_socket));
+                W5200.readSnRX_RSR(_socket), W5200.readSnRX_RD(_socket), W5200.readSnRX_WR(_socket));
         printf("Sn_TX_FSR:%5d, Sn_TX_RD:%5d, Sn_TX_WR:%5d\n",
-                W5100.readSnTX_FSR(_socket), W5100.readSnTX_RD(_socket), W5100.readSnTX_WR(_socket));
+                W5200.readSnTX_FSR(_socket), W5200.readSnTX_RD(_socket), W5200.readSnTX_WR(_socket));
     }
     wait_ms(200);    
 #endif //DEBUG
     if (_socket != (-1)) {
-        if (W5100.getRXReceivedSize(_socket) > 0) {
+        if (W5200.getRXReceivedSize(_socket) > 0) {
             queueEvent(NETUDPSOCKET_READABLE);
         }
     }
@@ -144,9 +144,9 @@
     if (_socket == (-1)) {
         return;
     }
-    while(W5100.getRXReceivedSize(_socket) > 0) {
+    while(W5200.getRXReceivedSize(_socket) > 0) {
         uint8_t temp[1];
-        W5100.recv_data_processing(_socket, temp, 1);
-        W5100.execCmdSn(_socket, Sock_RECV);
+        W5200.recv_data_processing(_socket, temp, 1);
+        W5200.execCmdSn(_socket, Sock_RECV);
     }    
 }