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
WIZ550ioInterface.cpp
00001 // WIZ550ioInterface.cpp 2013/4/5 00002 #include "WIZ550ioInterface.h" 00003 #include "DHCPClient.h" 00004 00005 WIZ550ioInterface::WIZ550ioInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset) : 00006 WIZ820io(mosi, miso, sclk, cs, reset) 00007 { 00008 ip_set = false; 00009 } 00010 00011 WIZ550ioInterface::WIZ550ioInterface(SPI* spi, PinName cs, PinName reset) : 00012 WIZ820io(spi, cs, reset) 00013 { 00014 ip_set = false; 00015 } 00016 00017 int WIZ550ioInterface::init() 00018 { 00019 dhcp = true; 00020 reset(); 00021 return 0; 00022 } 00023 00024 int WIZ550ioInterface::init(const char* ip, const char* mask, const char* gateway) 00025 { 00026 dhcp = false; 00027 this->ip = str_to_ip(ip); 00028 strcpy(ip_string, ip); 00029 ip_set = true; 00030 this->netmask = str_to_ip(mask); 00031 this->gateway = str_to_ip(gateway); 00032 reset(); 00033 return 0; 00034 } 00035 00036 int WIZ550ioInterface::init(uint32_t ip, uint32_t mask, uint32_t gateway) 00037 { 00038 dhcp = false; 00039 reset(); 00040 ip_set = true; 00041 join(ip, gateway, mask); 00042 return 0; 00043 } 00044 00045 int WIZ550ioInterface::connect() 00046 { 00047 if (dhcp) { 00048 int r = IPrenew(); 00049 if (r < 0) { 00050 return r; 00051 } 00052 } 00053 if (WIZ820io::join() == false) return -1; 00054 return 0; 00055 } 00056 00057 int WIZ550ioInterface::disconnect() 00058 { 00059 if (WIZ820io::disconnect() == false) return -1; 00060 return 0; 00061 } 00062 00063 char* WIZ550ioInterface::getIPAddress() 00064 { 00065 uint32_t ip = reg_rd<uint32_t>(SIPR); 00066 snprintf(ip_string, sizeof(ip_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); 00067 return ip_string; 00068 } 00069 00070 char* WIZ550ioInterface::getNetworkMask() 00071 { 00072 uint32_t ip = reg_rd<uint32_t>(SUBR); 00073 snprintf(mask_string, sizeof(mask_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); 00074 return mask_string; 00075 } 00076 00077 char* WIZ550ioInterface::getGateway() 00078 { 00079 uint32_t ip = reg_rd<uint32_t>(GAR); 00080 snprintf(gw_string, sizeof(gw_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); 00081 return gw_string; 00082 } 00083 00084 char* WIZ550ioInterface::getMACAddress() 00085 { 00086 uint8_t mac[6]; 00087 reg_rd_mac(SHAR, mac); 00088 snprintf(mac_string, sizeof(mac_string), "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 00089 return mac_string; 00090 } 00091 00092 int WIZ550ioInterface::IPrenew(int timeout_ms) 00093 { 00094 // printf("DHCP Started, waiting for IP...\n"); 00095 DHCPClient dhcp; 00096 int err = dhcp.setup(timeout_ms); 00097 if (err == (-1)) { 00098 // printf("Timeout.\n"); 00099 return -1; 00100 } 00101 // printf("Connected, IP: %d.%d.%d.%d\n", dhcp.yiaddr[0], dhcp.yiaddr[1], dhcp.yiaddr[2], dhcp.yiaddr[3]); 00102 ip = (dhcp.yiaddr[0] <<24) | (dhcp.yiaddr[1] <<16) | (dhcp.yiaddr[2] <<8) | dhcp.yiaddr[3]; 00103 gateway = (dhcp.gateway[0]<<24) | (dhcp.gateway[1]<<16) | (dhcp.gateway[2]<<8) | dhcp.gateway[3]; 00104 netmask = (dhcp.netmask[0]<<24) | (dhcp.netmask[1]<<16) | (dhcp.netmask[2]<<8) | dhcp.netmask[3]; 00105 dnsaddr = (dhcp.dnsaddr[0]<<24) | (dhcp.dnsaddr[1]<<16) | (dhcp.dnsaddr[2]<<8) | dhcp.dnsaddr[3]; 00106 return 0; 00107 }
Generated on Tue Aug 2 2022 08:01:52 by 1.7.2