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();
    }
}
Committer:
va009039
Date:
Fri Mar 22 11:51:24 2013 +0000
Revision:
0:bdeec5f86894
[mbed] converted /w5200NetIf/w5200NetIf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:bdeec5f86894 1 // W5200NetIf.h 2012/4/19
va009039 0:bdeec5f86894 2 /** \file
va009039 0:bdeec5f86894 3 W5200 network interface header file
va009039 0:bdeec5f86894 4 */
va009039 0:bdeec5f86894 5 #ifndef W5200_NETIF_H
va009039 0:bdeec5f86894 6 #define W5200_NETIF_H
va009039 0:bdeec5f86894 7 #include "MyNetIf.h"
va009039 0:bdeec5f86894 8
va009039 0:bdeec5f86894 9 ///W5200 network interface return codes
va009039 0:bdeec5f86894 10 enum W5200Err
va009039 0:bdeec5f86894 11 {
va009039 0:bdeec5f86894 12 __W5200_MIN = -0xFFFF,
va009039 0:bdeec5f86894 13 W5200_TIMEOUT, ///<Timeout during setup
va009039 0:bdeec5f86894 14 W5200_SETUP_ERR,
va009039 0:bdeec5f86894 15 W5200_OK = 0 ///<Success
va009039 0:bdeec5f86894 16 };
va009039 0:bdeec5f86894 17
va009039 0:bdeec5f86894 18 ///W5200 network interface
va009039 0:bdeec5f86894 19 class W5200NetIf : public MyNetIf {
va009039 0:bdeec5f86894 20 public:
va009039 0:bdeec5f86894 21 ///Instantiates the Interface and register it against the stack, DHCP will be used
va009039 0:bdeec5f86894 22 W5200NetIf(); //W/ DHCP
va009039 0:bdeec5f86894 23 ///Instantiates the Interface and register it against the stack, DHCP will not be used
va009039 0:bdeec5f86894 24 /**
va009039 0:bdeec5f86894 25 IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address.
va009039 0:bdeec5f86894 26 */
va009039 0:bdeec5f86894 27 W5200NetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns); //W/o DHCP
va009039 0:bdeec5f86894 28 W5200Err IPrenew(int timeout_ms = 15000);
va009039 0:bdeec5f86894 29 W5200Err IPrelease(int timeout_ms = 15000);
va009039 0:bdeec5f86894 30 ///Brings the interface up
va009039 0:bdeec5f86894 31 /**
va009039 0:bdeec5f86894 32 Uses DHCP if necessary
va009039 0:bdeec5f86894 33 @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s
va009039 0:bdeec5f86894 34 @return : W5200_OK on success or W5200_TIMEOUT on timeout
va009039 0:bdeec5f86894 35 */
va009039 0:bdeec5f86894 36 W5200Err setup(int timeout_ms = 15000);
va009039 0:bdeec5f86894 37 SPI* attachSPI(SPI* spi);
va009039 0:bdeec5f86894 38 DigitalOut* attachCS(DigitalOut* cs);
va009039 0:bdeec5f86894 39 IpAddr m_dns;
va009039 0:bdeec5f86894 40 private:
va009039 0:bdeec5f86894 41 bool m_useDhcp;
va009039 0:bdeec5f86894 42 IpAddr m_netmask;
va009039 0:bdeec5f86894 43 IpAddr m_gateway;
va009039 0:bdeec5f86894 44 const char* m_hostname;
va009039 0:bdeec5f86894 45 };
va009039 0:bdeec5f86894 46 #endif //W5200_NETIF_H