Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WIZnet_Library by
Revision 9:f390679a0468, committed 2018-06-04
- Comitter:
- zhangyx
- Date:
- Mon Jun 04 14:31:13 2018 +0000
- Parent:
- 8:cb8808b47e69
- Commit message:
- allow NC for reset pin
Changed in this revision
--- a/WIZnetInterface/DHCPClient/DHCPClient.cpp	Sun May 31 10:25:40 2015 +0000
+++ b/WIZnetInterface/DHCPClient/DHCPClient.cpp	Mon Jun 04 14:31:13 2018 +0000
@@ -7,8 +7,9 @@
 #define DBG_DHCP 0
 
 #if DBG_DHCP
-#define DBG(...) do{debug("[%s:%d]", __PRETTY_FUNCTION__,__LINE__);debug(__VA_ARGS__);} while(0);
-#define DBG_HEX(A,B) do{debug("[%s:%d]\r\n", __PRETTY_FUNCTION__,__LINE__);debug_hex(A,B);} while(0);
+extern Serial pc;
+#define DBG(...) do{pc.printf("[%s:%d]", __PRETTY_FUNCTION__,__LINE__);pc.printf(__VA_ARGS__);} while(0);
+#define DBG_HEX(A,B) do{pc.printf("[%s:%d]\r\n", __PRETTY_FUNCTION__,__LINE__);pc.printf("%x %x\r\n",A,B);} while(0);
 #else
 #define DBG(...) while(0);
 #define DBG_HEX(A,B) while(0);
@@ -19,7 +20,7 @@
     m_pos = 0;
     const uint8_t header[] = {0x01,0x01,0x06,0x00};
     add_buf((uint8_t*)header, sizeof(header));
-    uint32_t x = time(NULL) + rand();
+    uint32_t x = rand();
     xid[0] = x>>24; xid[1] = x>>16; xid[2] = x>>8; xid[3] = x;
     add_buf(xid, 4);
     fill_buf(20, 0x00);
@@ -112,6 +113,7 @@
 {
     Endpoint host;
     int recv_len = m_udp->receiveFrom(host, (char*)m_buf, sizeof(m_buf));
+    DBG("%d\r\n",recv_len);
     if (recv_len < 0) {
         return;
     }
@@ -168,7 +170,7 @@
     }
     m_udp = new UDPSocket;
     m_udp->init();
-    m_udp->set_blocking(false);
+    m_udp->set_blocking(false,5000);
     eth->reg_wr<uint32_t>(SIPR, 0x00000000); // local ip "0.0.0.0"
     m_udp->bind(68); // local port
     m_server.set_address("255.255.255.255", 67); // DHCP broadcast
@@ -184,7 +186,9 @@
                 break;
             case 1:
                 send_size = discover();
+                DBG("sendTo\r\n");
                 m_udp->sendTo(m_server, (char*)m_buf, send_size);
+                DBG("after sendTo\r\n");
                 m_interval.reset();
                 m_interval.start();
                 seq++;
--- a/WIZnetInterface/WIZnet/W5500.cpp	Sun May 31 10:25:40 2015 +0000
+++ b/WIZnetInterface/WIZnet/W5500.cpp	Mon Jun 04 14:31:13 2018 +0000
@@ -45,20 +45,28 @@
 WIZnet_Chip* WIZnet_Chip::inst;
 
 WIZnet_Chip::WIZnet_Chip(PinName mosi, PinName miso, PinName sclk, PinName _cs, PinName _reset):
-    cs(_cs), reset_pin(_reset)
+    cs(_cs)
 {
     spi = new SPI(mosi, miso, sclk);
     cs = 1;
-    reset_pin = 1;
+    if(_reset != NC){
+        reset_pin = new DigitalOut(_reset);
+        *reset_pin = 1;
+    }else
+        reset_pin = NULL;
     inst = this;
 }
 
 WIZnet_Chip::WIZnet_Chip(SPI* spi, PinName _cs, PinName _reset):
-    cs(_cs), reset_pin(_reset)
+    cs(_cs)
 {
     this->spi = spi;
     cs = 1;
-    reset_pin = 1;
+    if(_reset != NC){
+        reset_pin = new DigitalOut(_reset);
+        *reset_pin = 1;
+    }else
+        reset_pin = NULL;
     inst = this;
 }
 
@@ -149,12 +157,13 @@
 // Reset the chip & set the buffer
 void WIZnet_Chip::reset()
 {
-    reset_pin = 1;
-    reset_pin = 0;
-    wait_us(500); // 500us (w5500)
-    reset_pin = 1;
-    wait_ms(400); // 400ms (w5500)
-
+    if(reset_pin != NULL){
+        *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
 #endif
--- a/WIZnetInterface/WIZnet/W5500.h	Sun May 31 10:25:40 2015 +0000
+++ b/WIZnetInterface/WIZnet/W5500.h	Mon Jun 04 14:31:13 2018 +0000
@@ -271,7 +271,7 @@
     void spi_read(uint16_t addr, uint8_t cb, uint8_t *buf, uint16_t len);
     SPI* spi;
     DigitalOut cs;
-    DigitalOut reset_pin;
+    DigitalOut *reset_pin;
 };
 
 extern uint32_t str_to_ip(const char* str);
    