WIZ820io(W5200) network interface、EthernetNetIf compatible.
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(); } }
Diff: DHCPClient.cpp
- Revision:
- 1:22b9052d864d
- Parent:
- 0:bdeec5f86894
--- a/DHCPClient.cpp Fri Mar 22 11:51:24 2013 +0000 +++ b/DHCPClient.cpp Sun Mar 24 11:25:31 2013 +0000 @@ -1,8 +1,8 @@ // DHCPClient.cpp 2012/4/21 // DHCP Client for WIZ820io(W5200) #include "mbed.h" -#include "w5100.h" -#include "UDPSocket.h" +#include "w5200.h" +//#include "UDPSocket.h" #include "DHCPClient.h" //#define __DEBUG #include "dbg/dbg.h" @@ -33,13 +33,13 @@ xid[2] = t<<8; xid[3] = t; memcpy(buf+DHCP_OFFSET_XID, xid, 4); - W5100.getMACAddress(buf+DHCP_OFFSET_CHADDR); + W5200.getMACAddress(buf+DHCP_OFFSET_CHADDR); const uint8_t options[] = {0x63,0x82,0x53,0x63, // magic cookie 0x35,0x01,0x01, // DHCP DISCOVER 0xff}; memcpy(buf+DHCP_OFFSET_MAGIC_COOKIE, options, sizeof(options)); uint8_t ip[4] = {0,0,0,0}; - W5100.setIPAddress(ip); + W5200.setIPAddress(ip); return DHCP_OFFSET_MAGIC_COOKIE + sizeof(options); } @@ -50,7 +50,7 @@ memcpy(buf, headers, sizeof(headers)); memcpy(buf+DHCP_OFFSET_XID, xid, 4); memcpy(buf+DHCP_OFFSET_YIADDR, yiaddr, 4); - W5100.getMACAddress(buf+DHCP_OFFSET_CHADDR); + W5200.getMACAddress(buf+DHCP_OFFSET_CHADDR); const uint8_t options[] = {0x63,0x82,0x53,0x63, // magic cookie 0x35,0x01,0x03, // DHCP REQUEST 0x32,0x04,0x00,0x00,0x00,0x00, // request IP