W5500-Ethernet-Interface Makers / EthernetInterfaceW5500

Fork of EthernetInterfaceW5500 by Bongjun Hur

Revision:
14:a089e591e530
Parent:
10:cadac6bcd169
--- a/WIZnet/W5500.cpp	Mon Jul 21 05:29:03 2014 +0000
+++ b/WIZnet/W5500.cpp	Tue Aug 19 23:32:48 2014 +0000
@@ -169,6 +169,7 @@
 
 int WIZnet_Chip::wait_readable(int socket, int wait_time_ms, int req_size)
 {
+    int size, size2;
     if (socket < 0) {
         return -1;
     }
@@ -176,7 +177,15 @@
     t.reset();
     t.start();
     while(1) {
-        int size = sreg<uint16_t>(socket, Sn_RX_RSR);
+        //int size = sreg<uint16_t>(socket, Sn_RX_RSR);
+        // during the reading Sn_RX_RXR, it has the possible change of this register.
+        // so read twice and get same value then use size information.
+        do {
+            size = sreg<uint16_t>(socket, Sn_RX_RSR);
+            size2 = sreg<uint16_t>(socket, Sn_RX_RSR);
+        } while (size != size2);
+
+
         if (size > req_size) {
             return size;
         }
@@ -189,6 +198,7 @@
 
 int WIZnet_Chip::wait_writeable(int socket, int wait_time_ms, int req_size)
 {
+    int size, size2;
     if (socket < 0) {
         return -1;
     }
@@ -196,7 +206,13 @@
     t.reset();
     t.start();
     while(1) {
-        int size = sreg<uint16_t>(socket, Sn_TX_FSR);
+        //int size = sreg<uint16_t>(socket, Sn_TX_FSR);
+        // during the reading Sn_TX_FSR, it has the possible change of this register.
+        // so read twice and get same value then use size information.
+        do {
+            size = sreg<uint16_t>(socket, Sn_TX_FSR);
+            size2 = sreg<uint16_t>(socket, Sn_TX_FSR);
+        } while (size != size2);
         if (size > req_size) {
             return size;
         }