no upgrade or change at this. move to new Library for WIZ550io, W5500 -> http://mbed.org/teams/EthernetInterfaceW5500-makers/code/W5500Interface/
Dependents: LPC11U68_NTPClient_HelloWorld_WIZ550io
Fork of WIZ550ioInterface by
please get the new Library for WIZ550io, W5500 (WIZnet) http://mbed.org/teams/EthernetInterfaceW5500-makers/code/W5500Interface/
Import libraryW5500Interface
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.
WIZ820ioInterface.cpp@6:c466db1cd20b, 2013-12-01 (annotated)
- Committer:
- ban4jp
- Date:
- Sun Dec 01 18:40:14 2013 +0000
- Revision:
- 6:c466db1cd20b
- Parent:
- 5:fb15c35d1e28
Fix: connect() and disconnect() return value; Fix: Debug code disabled; Add: get IPAddress and MACAddress functions;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 5:fb15c35d1e28 | 1 | // WIZ820ioInterface.cpp 2013/4/5 |
va009039 | 5:fb15c35d1e28 | 2 | #include "WIZ820ioInterface.h" |
va009039 | 5:fb15c35d1e28 | 3 | #include "DHCPClient.h" |
samux | 1:fb4494783863 | 4 | |
va009039 | 5:fb15c35d1e28 | 5 | WIZ820ioInterface::WIZ820ioInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset) : |
va009039 | 5:fb15c35d1e28 | 6 | WIZ820io(mosi, miso, sclk, cs, reset) |
va009039 | 5:fb15c35d1e28 | 7 | { |
va009039 | 5:fb15c35d1e28 | 8 | ip_set = false; |
va009039 | 5:fb15c35d1e28 | 9 | } |
va009039 | 5:fb15c35d1e28 | 10 | |
va009039 | 5:fb15c35d1e28 | 11 | WIZ820ioInterface::WIZ820ioInterface(SPI* spi, PinName cs, PinName reset) : |
va009039 | 5:fb15c35d1e28 | 12 | WIZ820io(spi, cs, reset) |
samux | 1:fb4494783863 | 13 | { |
samux | 1:fb4494783863 | 14 | ip_set = false; |
samux | 1:fb4494783863 | 15 | } |
samux | 1:fb4494783863 | 16 | |
va009039 | 5:fb15c35d1e28 | 17 | int WIZ820ioInterface::init() |
samux | 1:fb4494783863 | 18 | { |
va009039 | 5:fb15c35d1e28 | 19 | dhcp = true; |
va009039 | 5:fb15c35d1e28 | 20 | reset(); |
va009039 | 5:fb15c35d1e28 | 21 | return 0; |
va009039 | 5:fb15c35d1e28 | 22 | } |
va009039 | 5:fb15c35d1e28 | 23 | |
va009039 | 5:fb15c35d1e28 | 24 | int WIZ820ioInterface::init(const char* ip, const char* mask, const char* gateway) |
va009039 | 5:fb15c35d1e28 | 25 | { |
va009039 | 5:fb15c35d1e28 | 26 | dhcp = false; |
va009039 | 5:fb15c35d1e28 | 27 | this->ip = str_to_ip(ip); |
va009039 | 5:fb15c35d1e28 | 28 | strcpy(ip_string, ip); |
va009039 | 5:fb15c35d1e28 | 29 | ip_set = true; |
va009039 | 5:fb15c35d1e28 | 30 | this->netmask = str_to_ip(mask); |
va009039 | 5:fb15c35d1e28 | 31 | this->gateway = str_to_ip(gateway); |
samux | 1:fb4494783863 | 32 | reset(); |
samux | 1:fb4494783863 | 33 | return 0; |
samux | 1:fb4494783863 | 34 | } |
samux | 1:fb4494783863 | 35 | |
va009039 | 5:fb15c35d1e28 | 36 | int WIZ820ioInterface::connect() |
samux | 1:fb4494783863 | 37 | { |
va009039 | 5:fb15c35d1e28 | 38 | if (dhcp) { |
va009039 | 5:fb15c35d1e28 | 39 | int r = IPrenew(); |
va009039 | 5:fb15c35d1e28 | 40 | if (r < 0) { |
va009039 | 5:fb15c35d1e28 | 41 | return r; |
va009039 | 5:fb15c35d1e28 | 42 | } |
va009039 | 5:fb15c35d1e28 | 43 | } |
ban4jp | 6:c466db1cd20b | 44 | if (WIZ820io::join() == false) return -1; |
ban4jp | 6:c466db1cd20b | 45 | return 0; |
samux | 1:fb4494783863 | 46 | } |
samux | 1:fb4494783863 | 47 | |
va009039 | 5:fb15c35d1e28 | 48 | int WIZ820ioInterface::disconnect() |
samux | 1:fb4494783863 | 49 | { |
ban4jp | 6:c466db1cd20b | 50 | if (WIZ820io::disconnect() == false) return -1; |
ban4jp | 6:c466db1cd20b | 51 | return 0; |
va009039 | 5:fb15c35d1e28 | 52 | } |
va009039 | 5:fb15c35d1e28 | 53 | |
va009039 | 5:fb15c35d1e28 | 54 | char* WIZ820ioInterface::getIPAddress() |
va009039 | 5:fb15c35d1e28 | 55 | { |
va009039 | 5:fb15c35d1e28 | 56 | uint32_t ip = reg_rd<uint32_t>(SIPR); |
ban4jp | 6:c466db1cd20b | 57 | snprintf(ip_string, sizeof(ip_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); |
va009039 | 5:fb15c35d1e28 | 58 | return ip_string; |
samux | 1:fb4494783863 | 59 | } |
samux | 1:fb4494783863 | 60 | |
ban4jp | 6:c466db1cd20b | 61 | char* WIZ820ioInterface::getNetworkMask() |
ban4jp | 6:c466db1cd20b | 62 | { |
ban4jp | 6:c466db1cd20b | 63 | uint32_t ip = reg_rd<uint32_t>(SUBR); |
ban4jp | 6:c466db1cd20b | 64 | snprintf(mask_string, sizeof(mask_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); |
ban4jp | 6:c466db1cd20b | 65 | return mask_string; |
ban4jp | 6:c466db1cd20b | 66 | } |
ban4jp | 6:c466db1cd20b | 67 | |
ban4jp | 6:c466db1cd20b | 68 | char* WIZ820ioInterface::getGateway() |
ban4jp | 6:c466db1cd20b | 69 | { |
ban4jp | 6:c466db1cd20b | 70 | uint32_t ip = reg_rd<uint32_t>(GAR); |
ban4jp | 6:c466db1cd20b | 71 | snprintf(gw_string, sizeof(gw_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); |
ban4jp | 6:c466db1cd20b | 72 | return gw_string; |
ban4jp | 6:c466db1cd20b | 73 | } |
ban4jp | 6:c466db1cd20b | 74 | |
ban4jp | 6:c466db1cd20b | 75 | char* WIZ820ioInterface::getMACAddress() |
ban4jp | 6:c466db1cd20b | 76 | { |
ban4jp | 6:c466db1cd20b | 77 | uint8_t mac[6]; |
ban4jp | 6:c466db1cd20b | 78 | reg_rd_mac(SHAR, mac); |
ban4jp | 6:c466db1cd20b | 79 | snprintf(mac_string, sizeof(mac_string), "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
ban4jp | 6:c466db1cd20b | 80 | return mac_string; |
ban4jp | 6:c466db1cd20b | 81 | } |
ban4jp | 6:c466db1cd20b | 82 | |
va009039 | 5:fb15c35d1e28 | 83 | int WIZ820ioInterface::IPrenew(int timeout_ms) |
samux | 1:fb4494783863 | 84 | { |
ban4jp | 6:c466db1cd20b | 85 | // printf("DHCP Started, waiting for IP...\n"); |
va009039 | 5:fb15c35d1e28 | 86 | DHCPClient dhcp; |
va009039 | 5:fb15c35d1e28 | 87 | int err = dhcp.setup(timeout_ms); |
va009039 | 5:fb15c35d1e28 | 88 | if (err == (-1)) { |
ban4jp | 6:c466db1cd20b | 89 | // printf("Timeout.\n"); |
va009039 | 5:fb15c35d1e28 | 90 | return -1; |
samux | 1:fb4494783863 | 91 | } |
ban4jp | 6:c466db1cd20b | 92 | // printf("Connected, IP: %d.%d.%d.%d\n", dhcp.yiaddr[0], dhcp.yiaddr[1], dhcp.yiaddr[2], dhcp.yiaddr[3]); |
ban4jp | 6:c466db1cd20b | 93 | ip = (dhcp.yiaddr[0] <<24) | (dhcp.yiaddr[1] <<16) | (dhcp.yiaddr[2] <<8) | dhcp.yiaddr[3]; |
va009039 | 5:fb15c35d1e28 | 94 | gateway = (dhcp.gateway[0]<<24) | (dhcp.gateway[1]<<16) | (dhcp.gateway[2]<<8) | dhcp.gateway[3]; |
va009039 | 5:fb15c35d1e28 | 95 | netmask = (dhcp.netmask[0]<<24) | (dhcp.netmask[1]<<16) | (dhcp.netmask[2]<<8) | dhcp.netmask[3]; |
va009039 | 5:fb15c35d1e28 | 96 | dnsaddr = (dhcp.dnsaddr[0]<<24) | (dhcp.dnsaddr[1]<<16) | (dhcp.dnsaddr[2]<<8) | dhcp.dnsaddr[3]; |
va009039 | 5:fb15c35d1e28 | 97 | return 0; |
va009039 | 5:fb15c35d1e28 | 98 | } |