Library for ethernet
Dependents: VC0706_FTP_Client_Ethernet_MQTT
Fork of WIZnetInterface by
Revision 3:f8c6efc8bf83, committed 2015-06-15
- Comitter:
- embeddist
- Date:
- Mon Jun 15 12:55:19 2015 +0000
- Parent:
- 2:26df0dc6e227
- Child:
- 4:4930f81bbe98
- Commit message:
- on debugging: fixed some bugs
Changed in this revision
--- a/EthernetInterface.cpp Mon Jun 15 13:33:39 2015 +0900 +++ b/EthernetInterface.cpp Mon Jun 15 12:55:19 2015 +0000 @@ -18,6 +18,18 @@ #include "EthernetInterface.h" #include "DHCPClient.h" +EthernetInterface::EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset) : + WIZnet_Chip(mosi, miso, sclk, cs, reset) +{ + ip_set = false; +} + +EthernetInterface::EthernetInterface(SPI* spi, PinName cs, PinName reset) : + WIZnet_Chip(spi, cs, reset) +{ + ip_set = false; +} + int EthernetInterface::init(uint8_t * mac) { @@ -42,6 +54,8 @@ this->netmask = str_to_ip(mask); this->gateway = str_to_ip(gateway); reset(); + + if (WIZnet_Chip::setip() == false) return -1; return 0; }
--- a/EthernetInterface.h Mon Jun 15 13:33:39 2015 +0900 +++ b/EthernetInterface.h Mon Jun 15 12:55:19 2015 +0000 @@ -24,6 +24,8 @@ class EthernetInterface: public WIZnet_Chip { public: + EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); + EthernetInterface(SPI* spi, PinName cs, PinName reset); /** Initialize the interface with DHCP. * Initialize the interface and configure it to use DHCP (no connection at this point).
--- a/arch/ext/W5500.cpp Mon Jun 15 13:33:39 2015 +0900 +++ b/arch/ext/W5500.cpp Mon Jun 15 12:55:19 2015 +0000 @@ -15,13 +15,14 @@ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "eth_arch.h" +#ifdef USE_W5500 #include "mbed.h" #include "mbed_debug.h" -#include "eth_arch.h" #include "DNSClient.h" -#ifdef USE_W5500 + //Debug is disabled by default #if 0 #define DBG(...) do{debug("%p %d %s ", this,__LINE__,__PRETTY_FUNCTION__); debug(__VA_ARGS__); } while(0); @@ -143,15 +144,19 @@ // Reset the chip & set the buffer void WIZnet_Chip::reset() { - // sw reset +#if defined(USE_WIZ550IO_MAC) + // hw reset reset_pin = 1; reset_pin = 0; wait_us(500); // 500us (w5500) reset_pin = 1; wait_ms(400); // 400ms (w5500) -#if defined(USE_WIZ550IO_MAC) - reg_rd_mac(SHAR, mac); // read the MAC address inside the module + reg_rd_mac(SHAR, mac); // read the MAC address inside the modulea +#else + // hw reset + reg_wr(MR, 0x80); + wait_us(500); // 500us (w5500) #endif // write MAC address inside the WZTOE MAC address register @@ -423,3 +428,4 @@ } #endif +
--- a/arch/ext/W5500.h Mon Jun 15 13:33:39 2015 +0900 +++ b/arch/ext/W5500.h Mon Jun 15 12:55:19 2015 +0000 @@ -26,42 +26,8 @@ #define DEFAULT_WAIT_RESP_TIMEOUT 500 -enum Protocol { - CLOSED = 0, - TCP = 1, - UDP = 2, -}; -enum Command { - OPEN = 0x01, - LISTEN = 0x02, - CONNECT = 0x04, - DISCON = 0x08, - CLOSE = 0x10, - SEND = 0x20, - SEND_MAC = 0x21, - SEND_KEEP = 0x22, - RECV = 0x40, - -}; -enum Interrupt { - INT_CON = 0x01, - INT_DISCON = 0x02, - INT_RECV = 0x04, - INT_TIMEOUT = 0x08, - INT_SEND_OK = 0x10, -}; - -enum Status { - SOCK_CLOSED = 0x00, - SOCK_INIT = 0x13, - SOCK_LISTEN = 0x14, - SOCK_SYNSENT = 0x15, - SOCK_ESTABLISHED = 0x17, - SOCK_CLOSE_WAIT = 0x1c, - SOCK_UDP = 0x22, -}; #define MAX_SOCK_NUM 8 @@ -89,6 +55,42 @@ class WIZnet_Chip { public: +enum Protocol { + CLOSED = 0, + TCP = 1, + UDP = 2, +}; + +enum Command { + OPEN = 0x01, + LISTEN = 0x02, + CONNECT = 0x04, + DISCON = 0x08, + CLOSE = 0x10, + SEND = 0x20, + SEND_MAC = 0x21, + SEND_KEEP = 0x22, + RECV = 0x40, + +}; + +enum Interrupt { + INT_CON = 0x01, + INT_DISCON = 0x02, + INT_RECV = 0x04, + INT_TIMEOUT = 0x08, + INT_SEND_OK = 0x10, +}; + +enum Status { + SOCK_CLOSED = 0x00, + SOCK_INIT = 0x13, + SOCK_LISTEN = 0x14, + SOCK_SYNSENT = 0x15, + SOCK_ESTABLISHED = 0x17, + SOCK_CLOSE_WAIT = 0x1c, + SOCK_UDP = 0x22, +}; /* * Constructor *
--- a/arch/int/W7500x_toe.cpp Mon Jun 15 13:33:39 2015 +0900 +++ b/arch/int/W7500x_toe.cpp Mon Jun 15 12:55:19 2015 +0000 @@ -14,13 +14,13 @@ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "eth_arch.h" +#ifdef USE_W7500 #include "mbed.h" #include "mbed_debug.h" -#include "W7500x_toe.h" #include "DNSClient.h" -#ifdef USE_W7500 /* * MDIO via GPIO @@ -488,3 +488,4 @@ } #endif +
--- a/eth_arch.h Mon Jun 15 13:33:39 2015 +0900 +++ b/eth_arch.h Mon Jun 15 12:55:19 2015 +0000 @@ -16,24 +16,22 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ -#ifndef _ETH_ARCH_H_ -#define _ETH_ARCH_H_ + #pragma once -#include "mbed.h" -#include "mbed_debug.h" +//#define USE_W7500 // used WIZwiki_W7500 +#define USE_W5500 // used W5500 Ethernet Shield & WIZ550io + -#define USE_W7500 // used WIZwiki_W7500 -//#define USE_W5500 // used W5500 Ethernet Shield & WIZ550io +#if defined(USE_W5500) +#include "W5500.h" +//#define USE_WIZ550IO_MAC // using the MAC address stored in the WIZ550io +#endif #if defined(USE_W7500) #include "W7500x_toe.h" #define __DEF_USED_IC101AG__ //For using IC+101AG@WIZwiki-W7500 #endif -#if defined(USE_W5500) -#include "W5500.h" -//#define USE_WIZ550IO_MAC // using the MAC address stored in the WIZ550io -#endif -#endif //#ifdef _ETH_ARCH_H_ +