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(); } }
WIZ820ioNetIf.h@1:22b9052d864d, 2013-03-24 (annotated)
- Committer:
- va009039
- Date:
- Sun Mar 24 11:25:31 2013 +0000
- Revision:
- 1:22b9052d864d
- Parent:
- 0:bdeec5f86894
WIZ820io(W8200) ethernet interface, EthernetNetIf compatible.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 1:22b9052d864d | 1 | // WIZ820ioNetIf.h 2013/3/24 |
va009039 | 0:bdeec5f86894 | 2 | |
va009039 | 0:bdeec5f86894 | 3 | /** \file |
va009039 | 0:bdeec5f86894 | 4 | WIZ820io network interface header file |
va009039 | 0:bdeec5f86894 | 5 | */ |
va009039 | 1:22b9052d864d | 6 | #pragma once |
va009039 | 1:22b9052d864d | 7 | #include "MyNetIf.h" |
va009039 | 1:22b9052d864d | 8 | |
va009039 | 1:22b9052d864d | 9 | ///W5200 network interface return codes |
va009039 | 1:22b9052d864d | 10 | enum W5200Err |
va009039 | 1:22b9052d864d | 11 | { |
va009039 | 1:22b9052d864d | 12 | __W5200_MIN = -0xFFFF, |
va009039 | 1:22b9052d864d | 13 | W5200_TIMEOUT, ///<Timeout during setup |
va009039 | 1:22b9052d864d | 14 | W5200_SETUP_ERR, |
va009039 | 1:22b9052d864d | 15 | W5200_SETUP_ERR_LINK_DOWN, |
va009039 | 1:22b9052d864d | 16 | W5200_OK = 0 ///<Success |
va009039 | 1:22b9052d864d | 17 | }; |
va009039 | 0:bdeec5f86894 | 18 | |
va009039 | 0:bdeec5f86894 | 19 | ///WIZ820io network interface |
va009039 | 1:22b9052d864d | 20 | class WIZ820ioNetIf : public MyNetIf { |
va009039 | 0:bdeec5f86894 | 21 | public: |
va009039 | 1:22b9052d864d | 22 | /** Create a WIZ820io ethernet interface |
va009039 | 1:22b9052d864d | 23 | * |
va009039 | 1:22b9052d864d | 24 | * @param mosi SPI mosi pin connected to WIZ820io |
va009039 | 1:22b9052d864d | 25 | * @param miso SPI miso pin conencted to WIZ820io |
va009039 | 1:22b9052d864d | 26 | * @param sclk SPI sclk pin connected to WIZ820io |
va009039 | 1:22b9052d864d | 27 | * @param cs DigitalOut pin used as WIZ820io select |
va009039 | 1:22b9052d864d | 28 | * @param reset DigitalOut pin WIZ820io hardware reset |
va009039 | 1:22b9052d864d | 29 | */ |
va009039 | 1:22b9052d864d | 30 | WIZ820ioNetIf(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); |
va009039 | 1:22b9052d864d | 31 | void config(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns); //W/o DHCP |
va009039 | 0:bdeec5f86894 | 32 | ///Brings the interface up |
va009039 | 0:bdeec5f86894 | 33 | /** |
va009039 | 0:bdeec5f86894 | 34 | Uses DHCP if necessary |
va009039 | 0:bdeec5f86894 | 35 | @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s |
va009039 | 0:bdeec5f86894 | 36 | @return : 0 on success or -1 on timeout |
va009039 | 0:bdeec5f86894 | 37 | */ |
va009039 | 0:bdeec5f86894 | 38 | int setup(int timeout_ms = 15000); |
va009039 | 1:22b9052d864d | 39 | W5200Err IPrenew(int timeout_ms = 15000); |
va009039 | 1:22b9052d864d | 40 | W5200Err IPrelease(int timeout_ms = 15000); |
va009039 | 1:22b9052d864d | 41 | IpAddr m_dns; |
va009039 | 1:22b9052d864d | 42 | private: |
va009039 | 1:22b9052d864d | 43 | void pin_assign(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); |
va009039 | 1:22b9052d864d | 44 | bool m_useDhcp; |
va009039 | 1:22b9052d864d | 45 | IpAddr m_netmask; |
va009039 | 1:22b9052d864d | 46 | IpAddr m_gateway; |
va009039 | 1:22b9052d864d | 47 | const char* m_hostname; |
va009039 | 0:bdeec5f86894 | 48 | }; |