Rudy Raab / WIZ820ioInterface

Fork of WIZ820ioInterface by ban4jp -

Files at this revision

API Documentation at this revision

Comitter:
ban4jp
Date:
Sun Feb 02 14:20:31 2014 +0000
Parent:
6:c466db1cd20b
Child:
8:6ff41cd782f5
Commit message:
Fixed compatibility.

Changed in this revision

Socket/Socket.h Show annotated file Show diff for this revision Revisions of this file
Socket/UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
WIZ820io/WIZ820io.cpp Show annotated file Show diff for this revision Revisions of this file
WIZ820io/WIZ820io.h Show annotated file Show diff for this revision Revisions of this file
--- a/Socket/Socket.h	Sun Dec 01 18:40:14 2013 +0000
+++ b/Socket/Socket.h	Sun Feb 02 14:20:31 2014 +0000
@@ -20,6 +20,11 @@
 
 #include "WIZ820io.h"
 
+#define htons(x) __REV16(x)
+#define ntohs(x) __REV16(x)
+#define htonl(x) __REV(x)
+#define ntohl(x) __REV(x)
+
 /** Socket file descriptor and select wrapper
   */
 class Socket {
--- a/Socket/UDPSocket.cpp	Sun Dec 01 18:40:14 2013 +0000
+++ b/Socket/UDPSocket.cpp	Sun Feb 02 14:20:31 2014 +0000
@@ -18,6 +18,8 @@
 
 #include "UDPSocket.h"
 
+static int udp_local_port;
+
 UDPSocket::UDPSocket()
 {
 }
@@ -41,7 +43,12 @@
         }
     }
     // set local port
-    eth->sreg<uint16_t>(_sock_fd, Sn_PORT, port);
+    if (port != 0) {
+        eth->sreg<uint16_t>(_sock_fd, Sn_PORT, port);
+    } else {
+        udp_local_port++;
+        eth->sreg<uint16_t>(_sock_fd, Sn_PORT, udp_local_port);
+    }
     // set udp protocol
     eth->setProtocol(_sock_fd, UDP);
     eth->scmd(_sock_fd, OPEN);
--- a/WIZ820io/WIZ820io.cpp	Sun Dec 01 18:40:14 2013 +0000
+++ b/WIZ820io/WIZ820io.cpp	Sun Feb 02 14:20:31 2014 +0000
@@ -137,7 +137,9 @@
     wait_us(2); // 2us
     reset_pin = 1;
     wait_ms(150); // 150ms
+    
     reg_wr<uint8_t>(MR, 1<<7);
+    
 #ifdef TARGET_LPC1114
     uint8_t mac[6] = {0x00,0x02,0xf7,0xf0,0x00,0x00};
 #else
@@ -160,6 +162,7 @@
         scmd(socket, DISCON);
     }
     scmd(socket, CLOSE);
+    sreg<uint8_t>(socket, Sn_IR, 0xff);
     return true;
 }
 
@@ -263,8 +266,7 @@
 void WIZ820io::scmd(int socket, Command cmd)
 {
     sreg<uint8_t>(socket, Sn_CR, cmd);
-    while(sreg<uint8_t>(socket, Sn_CR))
-        ;
+    while(sreg<uint8_t>(socket, Sn_CR));
 }
 
 void WIZ820io::spi_write(uint16_t addr, const uint8_t *buf, uint16_t len)
--- a/WIZ820io/WIZ820io.h	Sun Dec 01 18:40:14 2013 +0000
+++ b/WIZ820io/WIZ820io.h	Sun Feb 02 14:20:31 2014 +0000
@@ -45,6 +45,14 @@
     
 };
 
+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,
@@ -64,16 +72,19 @@
 #define SIPR      0x000f
 #define PHYSTATUS 0x0035
 // socket
-#define Sn_MR     0x4000
-#define Sn_CR     0x4001
-#define Sn_SR     0x4003
-#define Sn_PORT   0x4004
-#define Sn_DIPR   0x400c
-#define Sn_DPORT  0x4010
-#define Sn_TX_FSR 0x4020
-#define Sn_TX_WR  0x4024
-#define Sn_RX_RSR 0x4026
-#define Sn_RX_RD  0x4028
+#define Sn_MR         0x4000
+#define Sn_CR         0x4001
+#define Sn_IR         0x4002
+#define Sn_SR         0x4003
+#define Sn_PORT       0x4004
+#define Sn_DIPR       0x400c
+#define Sn_DPORT      0x4010
+#define Sn_RXBUF_SIZE 0x401e
+#define Sn_TXBUF_SIZE 0x401f
+#define Sn_TX_FSR     0x4020
+#define Sn_TX_WR      0x4024
+#define Sn_RX_RSR     0x4026
+#define Sn_RX_RD      0x4028
 
 class WIZ820io {
 public: