Added RAW sockets.

Fork of WIZnetInterface by WIZnet

Committer:
Dollyparton
Date:
Wed Dec 20 14:32:58 2017 +0000
Revision:
31:e49acd942048
Parent:
30:3b0481541a06
Child:
32:3d4ff7ac16dc
Second Version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Soohwan Kim 0:6f28332c466f 1 /* Copyright (C) 2012 mbed.org, MIT License
Soohwan Kim 0:6f28332c466f 2 *
Soohwan Kim 0:6f28332c466f 3 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Soohwan Kim 0:6f28332c466f 4 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Soohwan Kim 0:6f28332c466f 5 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Soohwan Kim 0:6f28332c466f 6 * furnished to do so, subject to the following conditions:
Soohwan Kim 0:6f28332c466f 7 *
Soohwan Kim 0:6f28332c466f 8 * The above copyright notice and this permission notice shall be included in all copies or
Soohwan Kim 0:6f28332c466f 9 * substantial portions of the Software.
Soohwan Kim 0:6f28332c466f 10 *
Soohwan Kim 0:6f28332c466f 11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Soohwan Kim 0:6f28332c466f 12 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Soohwan Kim 0:6f28332c466f 13 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Soohwan Kim 0:6f28332c466f 14 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Soohwan Kim 0:6f28332c466f 15 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Soohwan Kim 0:6f28332c466f 16 */
embeddist 3:f8c6efc8bf83 17 #include "eth_arch.h"
embeddist 28:200e63e513a8 18 #if defined(TARGET_WIZwiki_W7500) || defined(TARGET_WIZwiki_W7500P) || defined(TARGET_WIZwiki_W7500ECO)
hjjeon 26:d07c80e18b27 19
Soohwan Kim 0:6f28332c466f 20
Soohwan Kim 0:6f28332c466f 21 #include "mbed.h"
Soohwan Kim 0:6f28332c466f 22 #include "mbed_debug.h"
Soohwan Kim 0:6f28332c466f 23 #include "DNSClient.h"
Soohwan Kim 0:6f28332c466f 24
Soohwan Kim 0:6f28332c466f 25
Soohwan Kim 0:6f28332c466f 26 /*
Soohwan Kim 0:6f28332c466f 27 * MDIO via GPIO
Soohwan Kim 0:6f28332c466f 28 * mdio via gpio is supported and related functions as follows.
Soohwan Kim 0:6f28332c466f 29 * - mdio_init(),mdio_read(),mdio_write()
Soohwan Kim 0:6f28332c466f 30 * - input_MDIO(),output_MDIO(),turnaroud_MDIO(),idle_MDIO()
Soohwan Kim 0:6f28332c466f 31 * called by ethernet_link() and ethernet_set_link()
Soohwan Kim 0:6f28332c466f 32 */
hjjeon 26:d07c80e18b27 33
embeddist 28:200e63e513a8 34 #if defined (TARGET_WIZwiki_W7500) || defined(TARGET_WIZwiki_W7500ECO)
hjjeon 26:d07c80e18b27 35
Soohwan Kim 0:6f28332c466f 36 #define MDIO GPIO_Pin_14
Soohwan Kim 0:6f28332c466f 37 #define MDC GPIO_Pin_15
Soohwan Kim 0:6f28332c466f 38 #define GPIO_MDC GPIOB
Soohwan Kim 0:6f28332c466f 39 #define PHY_ADDR_IP101G 0x07
Soohwan Kim 0:6f28332c466f 40 #define PHY_ADDR PHY_ADDR_IP101G
Soohwan Kim 0:6f28332c466f 41 #define SVAL 0x2 //right shift val = 2
Soohwan Kim 0:6f28332c466f 42 #define PHYREG_CONTROL 0x0 //Control Register address (Contorl basic register)
Soohwan Kim 0:6f28332c466f 43 #define PHYREG_STATUS 0x1 //Status Register address (Status basic register)
Soohwan Kim 0:6f28332c466f 44 #define CNTL_DUPLEX (0x01ul<< 7)
Soohwan Kim 0:6f28332c466f 45 #define CNTL_AUTONEGO (0x01ul<<11)
Soohwan Kim 0:6f28332c466f 46 #define CNTL_SPEED (0x01ul<<12)
Soohwan Kim 0:6f28332c466f 47 #define MDC_WAIT (1)
hjjeon 26:d07c80e18b27 48
embeddist 28:200e63e513a8 49 #elif defined (TARGET_WIZwiki_W7500P)
hjjeon 26:d07c80e18b27 50
hjjeon 26:d07c80e18b27 51 #define MDIO GPIO_Pin_15
hjjeon 26:d07c80e18b27 52 #define MDC GPIO_Pin_14
hjjeon 26:d07c80e18b27 53 #define GPIO_MDC GPIOB
hjjeon 26:d07c80e18b27 54 #define PHY_ADDR_IP101G 0x01
hjjeon 26:d07c80e18b27 55 #define PHY_ADDR PHY_ADDR_IP101G
hjjeon 26:d07c80e18b27 56 #define SVAL 0x2 //right shift val = 2
hjjeon 26:d07c80e18b27 57 #define PHYREG_CONTROL 0x0 //Control Register address (Contorl basic register)
hjjeon 26:d07c80e18b27 58 #define PHYREG_STATUS 0x1 //Status Register address (Status basic register)
hjjeon 26:d07c80e18b27 59 #define CNTL_DUPLEX (0x01ul<< 7)
hjjeon 26:d07c80e18b27 60 #define CNTL_AUTONEGO (0x01ul<<11)
hjjeon 26:d07c80e18b27 61 #define CNTL_SPEED (0x01ul<<12)
hjjeon 26:d07c80e18b27 62 #define MDC_WAIT (1)
hjjeon 26:d07c80e18b27 63
hjjeon 26:d07c80e18b27 64 #endif
hjjeon 26:d07c80e18b27 65
Soohwan Kim 0:6f28332c466f 66 void mdio_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin_MDC, uint16_t GPIO_Pin_MDIO);
Soohwan Kim 0:6f28332c466f 67 void mdio_write(GPIO_TypeDef* GPIOx, uint32_t PhyRegAddr, uint32_t val);
Soohwan Kim 0:6f28332c466f 68 uint32_t mdio_read(GPIO_TypeDef* GPIOx, uint32_t PhyRegAddr);
Soohwan Kim 0:6f28332c466f 69
Soohwan Kim 0:6f28332c466f 70 WIZnet_Chip* WIZnet_Chip::inst;
Soohwan Kim 0:6f28332c466f 71
Soohwan Kim 0:6f28332c466f 72 WIZnet_Chip::WIZnet_Chip()
Soohwan Kim 0:6f28332c466f 73 {
Soohwan Kim 0:6f28332c466f 74 inst = this;
Soohwan Kim 0:6f28332c466f 75 }
Soohwan Kim 0:6f28332c466f 76
Soohwan Kim 8:4c02de1dbf3a 77 bool WIZnet_Chip::setmac()
Soohwan Kim 8:4c02de1dbf3a 78 {
embeddist 29:c91884bd2713 79 reg_wr_mac(SHAR, mac);
Soohwan Kim 8:4c02de1dbf3a 80 return true;
Soohwan Kim 8:4c02de1dbf3a 81 }
Soohwan Kim 8:4c02de1dbf3a 82
Soohwan Kim 0:6f28332c466f 83 // Set the IP
Soohwan Kim 0:6f28332c466f 84 bool WIZnet_Chip::setip()
Soohwan Kim 0:6f28332c466f 85 {
Soohwan Kim 0:6f28332c466f 86 reg_wr<uint32_t>(SIPR, ip);
Soohwan Kim 0:6f28332c466f 87 reg_wr<uint32_t>(GAR, gateway);
Soohwan Kim 0:6f28332c466f 88 reg_wr<uint32_t>(SUBR, netmask);
Soohwan Kim 0:6f28332c466f 89 return true;
Soohwan Kim 0:6f28332c466f 90 }
Soohwan Kim 0:6f28332c466f 91
Soohwan Kim 0:6f28332c466f 92 bool WIZnet_Chip::setProtocol(int socket, Protocol p)
Soohwan Kim 0:6f28332c466f 93 {
Soohwan Kim 0:6f28332c466f 94 if (socket < 0) {
Soohwan Kim 0:6f28332c466f 95 return false;
Soohwan Kim 0:6f28332c466f 96 }
Soohwan Kim 0:6f28332c466f 97 sreg<uint8_t>(socket, Sn_MR, p);
Soohwan Kim 0:6f28332c466f 98 return true;
Soohwan Kim 0:6f28332c466f 99 }
Soohwan Kim 0:6f28332c466f 100
Soohwan Kim 0:6f28332c466f 101 bool WIZnet_Chip::connect(int socket, const char * host, int port, int timeout_ms)
Soohwan Kim 0:6f28332c466f 102 {
Soohwan Kim 0:6f28332c466f 103 if (socket < 0) {
Soohwan Kim 0:6f28332c466f 104 return false;
Soohwan Kim 0:6f28332c466f 105 }
Soohwan Kim 0:6f28332c466f 106 sreg<uint8_t>(socket, Sn_MR, TCP);
Soohwan Kim 0:6f28332c466f 107 scmd(socket, OPEN);
Soohwan Kim 0:6f28332c466f 108 sreg_ip(socket, Sn_DIPR, host);
Soohwan Kim 0:6f28332c466f 109 sreg<uint16_t>(socket, Sn_DPORT, port);
Soohwan Kim 0:6f28332c466f 110 sreg<uint16_t>(socket, Sn_PORT, new_port());
Soohwan Kim 0:6f28332c466f 111 scmd(socket, CONNECT);
Soohwan Kim 0:6f28332c466f 112 Timer t;
Soohwan Kim 0:6f28332c466f 113 t.reset();
Soohwan Kim 0:6f28332c466f 114 t.start();
Dollyparton 30:3b0481541a06 115 //timeout_ms=700;
Dollyparton 30:3b0481541a06 116 //printf("waiting %d\r\n", timeout_ms);
Soohwan Kim 0:6f28332c466f 117 while(!is_connected(socket)) {
Soohwan Kim 0:6f28332c466f 118 if (t.read_ms() > timeout_ms) {
Soohwan Kim 0:6f28332c466f 119 return false;
Soohwan Kim 0:6f28332c466f 120 }
Soohwan Kim 0:6f28332c466f 121 }
Soohwan Kim 0:6f28332c466f 122 return true;
Soohwan Kim 0:6f28332c466f 123 }
Soohwan Kim 0:6f28332c466f 124
Soohwan Kim 0:6f28332c466f 125 bool WIZnet_Chip::gethostbyname(const char* host, uint32_t* ip)
Soohwan Kim 0:6f28332c466f 126 {
Soohwan Kim 0:6f28332c466f 127 uint32_t addr = str_to_ip(host);
Soohwan Kim 0:6f28332c466f 128 char buf[17];
Soohwan Kim 0:6f28332c466f 129 snprintf(buf, sizeof(buf), "%d.%d.%d.%d",
Soohwan Kim 0:6f28332c466f 130 (uint8_t)((addr>>24)&0xff),
Soohwan Kim 0:6f28332c466f 131 (uint8_t)((addr>>16)&0xff),
Soohwan Kim 0:6f28332c466f 132 (uint8_t)((addr>>8)&0xff),
Soohwan Kim 0:6f28332c466f 133 (uint8_t)(addr&0xff));
Soohwan Kim 0:6f28332c466f 134 if (strcmp(buf, host) == 0) {
Soohwan Kim 0:6f28332c466f 135 *ip = addr;
Soohwan Kim 0:6f28332c466f 136 return true;
Soohwan Kim 0:6f28332c466f 137 }
Soohwan Kim 0:6f28332c466f 138 DNSClient client;
Soohwan Kim 0:6f28332c466f 139 if(client.lookup(host)) {
Soohwan Kim 0:6f28332c466f 140 *ip = client.ip;
Soohwan Kim 0:6f28332c466f 141 return true;
Soohwan Kim 0:6f28332c466f 142 }
Soohwan Kim 0:6f28332c466f 143 return false;
Soohwan Kim 0:6f28332c466f 144 }
Soohwan Kim 0:6f28332c466f 145
Dollyparton 30:3b0481541a06 146 // Geminate Changes.
Dollyparton 30:3b0481541a06 147 int WIZnet_Chip::get_DHAR0(int socket)
Dollyparton 30:3b0481541a06 148 {
Dollyparton 30:3b0481541a06 149 //sreg<uint32_t>(socket, Sn_RCR, 0x0000000);
Dollyparton 30:3b0481541a06 150 reg_wr<uint32_t>(Sn_RCR, 0x00000008);
Dollyparton 30:3b0481541a06 151
Dollyparton 30:3b0481541a06 152 return( sreg<uint32_t>(socket, Sn_DHAR0));
Dollyparton 30:3b0481541a06 153 }
Dollyparton 30:3b0481541a06 154
Dollyparton 30:3b0481541a06 155
Dollyparton 30:3b0481541a06 156 int WIZnet_Chip::get_DHAR1(int socket)
Dollyparton 30:3b0481541a06 157 {
Dollyparton 30:3b0481541a06 158 return( sreg<uint32_t>(socket, Sn_DHAR1));
Dollyparton 30:3b0481541a06 159 }
Dollyparton 30:3b0481541a06 160
Dollyparton 30:3b0481541a06 161 // End Changes.
Dollyparton 30:3b0481541a06 162
Soohwan Kim 0:6f28332c466f 163
Soohwan Kim 0:6f28332c466f 164 bool WIZnet_Chip::is_connected(int socket)
Soohwan Kim 0:6f28332c466f 165 {
Soohwan Kim 0:6f28332c466f 166 /*
Soohwan Kim 0:6f28332c466f 167 if (sreg<uint8_t>(socket, Sn_SR) == SOCK_ESTABLISHED) {
Soohwan Kim 0:6f28332c466f 168 return true;
Soohwan Kim 0:6f28332c466f 169 }
Soohwan Kim 0:6f28332c466f 170 */
Soohwan Kim 0:6f28332c466f 171 uint8_t tmpSn_SR;
Soohwan Kim 0:6f28332c466f 172 tmpSn_SR = sreg<uint8_t>(socket, Sn_SR);
Soohwan Kim 0:6f28332c466f 173 // packet sending is possible, when state is SOCK_CLOSE_WAIT.
Soohwan Kim 0:6f28332c466f 174 if ((tmpSn_SR == SOCK_ESTABLISHED) || (tmpSn_SR == SOCK_CLOSE_WAIT)) {
Soohwan Kim 0:6f28332c466f 175 return true;
Soohwan Kim 0:6f28332c466f 176 }
Soohwan Kim 0:6f28332c466f 177 return false;
Soohwan Kim 0:6f28332c466f 178 }
Soohwan Kim 0:6f28332c466f 179 // Reset the chip & set the buffer
Soohwan Kim 0:6f28332c466f 180 void WIZnet_Chip::reset()
Soohwan Kim 0:6f28332c466f 181 {
Soohwan Kim 0:6f28332c466f 182 /* S/W Reset PHY */
Soohwan Kim 0:6f28332c466f 183 mdio_write(GPIO_MDC, PHYREG_CONTROL, 0x8000);
Soohwan Kim 0:6f28332c466f 184 wait_ms(10);//for S/W reset
Soohwan Kim 0:6f28332c466f 185 wait_ms(10);//for MDC I/F RDY
Soohwan Kim 0:6f28332c466f 186
embeddist 15:24a9f2df2145 187 mdio_init(GPIO_MDC, MDC, MDIO);
embeddist 15:24a9f2df2145 188
Soohwan Kim 0:6f28332c466f 189 /* S/W Reset WZTOE */
Soohwan Kim 0:6f28332c466f 190 reg_wr<uint8_t>(MR, MR_RST);
Soohwan Kim 0:6f28332c466f 191 // set PAD strengh and pull-up for TXD[3:0] and TXE
Soohwan Kim 0:6f28332c466f 192 #ifdef __DEF_USED_IC101AG__ //For using IC+101AG
hjjeon 26:d07c80e18b27 193
embeddist 28:200e63e513a8 194 #if defined(TARGET_WIZwiki_W7500) || defined(TARGET_WIZwiki_W7500ECO)
hjjeon 26:d07c80e18b27 195
Soohwan Kim 0:6f28332c466f 196 *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0
Soohwan Kim 0:6f28332c466f 197 *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1
Soohwan Kim 0:6f28332c466f 198 *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2
Soohwan Kim 0:6f28332c466f 199 *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3
Soohwan Kim 0:6f28332c466f 200 *(volatile uint32_t *)(0x41003050) = 0x64; //TXE
hjjeon 26:d07c80e18b27 201 #endif
hjjeon 26:d07c80e18b27 202
Soohwan Kim 0:6f28332c466f 203 #endif
hjjeon 26:d07c80e18b27 204
Soohwan Kim 0:6f28332c466f 205 // set ticker counter
Soohwan Kim 0:6f28332c466f 206 reg_wr<uint32_t>(TIC100US, (SystemCoreClock/10000));
Soohwan Kim 0:6f28332c466f 207 // write MAC address inside the WZTOE MAC address register
Soohwan Kim 0:6f28332c466f 208 reg_wr_mac(SHAR, mac);
Soohwan Kim 0:6f28332c466f 209 /*
Dollyparton 31:e49acd942048 210 * set RX and TX buffer size */
Dollyparton 31:e49acd942048 211 //for (int socket = 0; socket < MAX_SOCK_NUM; socket++) {
Dollyparton 31:e49acd942048 212 for (int socket = 0; socket < 4; socket++)
Dollyparton 31:e49acd942048 213 {
Dollyparton 31:e49acd942048 214 sreg<uint8_t>(socket, Sn_RXBUF_SIZE, 2);
Dollyparton 31:e49acd942048 215 sreg<uint8_t>(socket, Sn_TXBUF_SIZE, 2);
Dollyparton 31:e49acd942048 216 }
Dollyparton 31:e49acd942048 217
Dollyparton 31:e49acd942048 218 for (int socket = 4; socket < MAX_SOCK_NUM; socket++)
Dollyparton 31:e49acd942048 219 {
Dollyparton 31:e49acd942048 220 sreg<uint8_t>(socket, Sn_RXBUF_SIZE, 0);
Dollyparton 31:e49acd942048 221 sreg<uint8_t>(socket, Sn_TXBUF_SIZE, 0);
Dollyparton 31:e49acd942048 222 }
Soohwan Kim 0:6f28332c466f 223 }
Soohwan Kim 0:6f28332c466f 224
Soohwan Kim 0:6f28332c466f 225
Soohwan Kim 0:6f28332c466f 226 bool WIZnet_Chip::close(int socket)
Soohwan Kim 0:6f28332c466f 227 {
Soohwan Kim 0:6f28332c466f 228 if (socket < 0) {
Soohwan Kim 0:6f28332c466f 229 return false;
Soohwan Kim 0:6f28332c466f 230 }
Soohwan Kim 0:6f28332c466f 231 // if SOCK_CLOSED, return
Soohwan Kim 0:6f28332c466f 232 if (sreg<uint8_t>(socket, Sn_SR) == SOCK_CLOSED) {
Soohwan Kim 0:6f28332c466f 233 return true;
Soohwan Kim 0:6f28332c466f 234 }
Soohwan Kim 0:6f28332c466f 235 // if SOCK_ESTABLISHED, send FIN-Packet to peer
Soohwan Kim 0:6f28332c466f 236 if (sreg<uint8_t>(socket, Sn_MR) == TCP) {
Soohwan Kim 0:6f28332c466f 237 scmd(socket, DISCON);
Soohwan Kim 0:6f28332c466f 238 }
Soohwan Kim 0:6f28332c466f 239 // close socket
Soohwan Kim 0:6f28332c466f 240 scmd(socket, CLOSE);
Soohwan Kim 0:6f28332c466f 241 // clear Socket Interrupt Register
Soohwan Kim 0:6f28332c466f 242 sreg<uint8_t>(socket, Sn_ICR, 0xff);
Soohwan Kim 0:6f28332c466f 243 return true;
Soohwan Kim 0:6f28332c466f 244 }
Soohwan Kim 0:6f28332c466f 245
Soohwan Kim 0:6f28332c466f 246 int WIZnet_Chip::wait_readable(int socket, int wait_time_ms, int req_size)
Soohwan Kim 0:6f28332c466f 247 {
Soohwan Kim 0:6f28332c466f 248 if (socket < 0) {
Soohwan Kim 0:6f28332c466f 249 return -1;
Soohwan Kim 0:6f28332c466f 250 }
Soohwan Kim 0:6f28332c466f 251 Timer t;
Soohwan Kim 0:6f28332c466f 252 t.reset();
Soohwan Kim 0:6f28332c466f 253 t.start();
Soohwan Kim 0:6f28332c466f 254 while(1) {
Soohwan Kim 0:6f28332c466f 255 int size = sreg<uint16_t>(socket, Sn_RX_RSR);
Soohwan Kim 0:6f28332c466f 256 if (size > req_size) {
Soohwan Kim 0:6f28332c466f 257 return size;
Soohwan Kim 0:6f28332c466f 258 }
Soohwan Kim 0:6f28332c466f 259 if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) {
Soohwan Kim 0:6f28332c466f 260 break;
Soohwan Kim 0:6f28332c466f 261 }
Soohwan Kim 0:6f28332c466f 262 }
Soohwan Kim 0:6f28332c466f 263 return -1;
Soohwan Kim 0:6f28332c466f 264 }
Soohwan Kim 0:6f28332c466f 265
Soohwan Kim 0:6f28332c466f 266 int WIZnet_Chip::wait_writeable(int socket, int wait_time_ms, int req_size)
Soohwan Kim 0:6f28332c466f 267 {
Soohwan Kim 0:6f28332c466f 268 if (socket < 0) {
Soohwan Kim 0:6f28332c466f 269 return -1;
Soohwan Kim 0:6f28332c466f 270 }
Soohwan Kim 0:6f28332c466f 271 Timer t;
Soohwan Kim 0:6f28332c466f 272 t.reset();
Soohwan Kim 0:6f28332c466f 273 t.start();
Soohwan Kim 0:6f28332c466f 274 while(1) {
Soohwan Kim 0:6f28332c466f 275 int size = sreg<uint16_t>(socket, Sn_TX_FSR);
Soohwan Kim 0:6f28332c466f 276 if (size > req_size) {
Soohwan Kim 0:6f28332c466f 277 return size;
Soohwan Kim 0:6f28332c466f 278 }
Soohwan Kim 0:6f28332c466f 279 if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) {
Soohwan Kim 0:6f28332c466f 280 break;
Soohwan Kim 0:6f28332c466f 281 }
Soohwan Kim 0:6f28332c466f 282 }
Soohwan Kim 0:6f28332c466f 283 return -1;
Soohwan Kim 0:6f28332c466f 284 }
Soohwan Kim 0:6f28332c466f 285
Soohwan Kim 0:6f28332c466f 286 int WIZnet_Chip::send(int socket, const char * str, int len)
Dollyparton 30:3b0481541a06 287 {
Soohwan Kim 0:6f28332c466f 288 if (socket < 0) {
Soohwan Kim 0:6f28332c466f 289 return -1;
Soohwan Kim 0:6f28332c466f 290 }
Soohwan Kim 0:6f28332c466f 291
Soohwan Kim 0:6f28332c466f 292 uint16_t ptr = sreg<uint16_t>(socket, Sn_TX_WR);
Soohwan Kim 0:6f28332c466f 293 uint32_t sn_tx_base = W7500x_TXMEM_BASE + (uint32_t)(socket<<18);
Soohwan Kim 0:6f28332c466f 294
Soohwan Kim 0:6f28332c466f 295 for(int i=0; i<len; i++)
Soohwan Kim 0:6f28332c466f 296 *(volatile uint8_t *)(sn_tx_base + ((ptr+i)&0xFFFF)) = str[i];
Soohwan Kim 0:6f28332c466f 297
Soohwan Kim 0:6f28332c466f 298 sreg<uint16_t>(socket, Sn_TX_WR, ptr + len);
Soohwan Kim 0:6f28332c466f 299 scmd(socket, SEND);
Soohwan Kim 0:6f28332c466f 300
Soohwan Kim 0:6f28332c466f 301 uint8_t tmp_Sn_IR;
Soohwan Kim 0:6f28332c466f 302 while (( (tmp_Sn_IR = sreg<uint8_t>(socket, Sn_IR)) & INT_SEND_OK) != INT_SEND_OK) {
Soohwan Kim 0:6f28332c466f 303 // @Jul.10, 2014 fix contant name, and udp sendto function.
Soohwan Kim 0:6f28332c466f 304 switch (sreg<uint8_t>(socket, Sn_SR)) {
Soohwan Kim 0:6f28332c466f 305 case SOCK_CLOSED :
Soohwan Kim 0:6f28332c466f 306 close(socket);
Soohwan Kim 0:6f28332c466f 307 return 0;
Soohwan Kim 0:6f28332c466f 308 //break;
Soohwan Kim 0:6f28332c466f 309 case SOCK_UDP :
Soohwan Kim 0:6f28332c466f 310 // ARP timeout is possible.
Soohwan Kim 0:6f28332c466f 311 if ((tmp_Sn_IR & INT_TIMEOUT) == INT_TIMEOUT) {
Soohwan Kim 0:6f28332c466f 312 sreg<uint8_t>(socket, Sn_ICR, INT_TIMEOUT);
Soohwan Kim 0:6f28332c466f 313 return 0;
Soohwan Kim 0:6f28332c466f 314 }
Soohwan Kim 0:6f28332c466f 315 break;
Soohwan Kim 0:6f28332c466f 316 default :
Soohwan Kim 0:6f28332c466f 317 break;
Soohwan Kim 0:6f28332c466f 318 }
Soohwan Kim 0:6f28332c466f 319 }
Soohwan Kim 0:6f28332c466f 320
Soohwan Kim 0:6f28332c466f 321 sreg<uint8_t>(socket, Sn_ICR, INT_SEND_OK);
Soohwan Kim 0:6f28332c466f 322
Soohwan Kim 0:6f28332c466f 323 return len;
Soohwan Kim 0:6f28332c466f 324 }
Soohwan Kim 0:6f28332c466f 325
Dollyparton 30:3b0481541a06 326
Dollyparton 30:3b0481541a06 327 int WIZnet_Chip::sendRaw(int socket, const char * str, int len)
Dollyparton 30:3b0481541a06 328 {
Dollyparton 30:3b0481541a06 329 if (socket < 0) {
Dollyparton 30:3b0481541a06 330 return -1;
Dollyparton 30:3b0481541a06 331 }
Dollyparton 30:3b0481541a06 332
Dollyparton 30:3b0481541a06 333 uint16_t ptr = sreg<uint16_t>(socket, Sn_TX_WR);
Dollyparton 30:3b0481541a06 334 uint32_t sn_tx_base = W7500x_TXMEM_BASE + (uint32_t)(socket<<18);
Dollyparton 30:3b0481541a06 335
Dollyparton 30:3b0481541a06 336 for(int i=0; i<len; i++)
Dollyparton 30:3b0481541a06 337 *(volatile uint8_t *)(sn_tx_base + ((ptr+i)&0xFFFF)) = str[i];
Dollyparton 30:3b0481541a06 338
Dollyparton 30:3b0481541a06 339 sreg<uint16_t>(socket, Sn_TX_WR, ptr + len);
Dollyparton 30:3b0481541a06 340 scmd(socket, SEND_MAC);
Dollyparton 30:3b0481541a06 341
Dollyparton 30:3b0481541a06 342 uint8_t tmp_Sn_IR;
Dollyparton 30:3b0481541a06 343 while (( (tmp_Sn_IR = sreg<uint8_t>(socket, Sn_IR)) & INT_SEND_OK) != INT_SEND_OK) {
Dollyparton 30:3b0481541a06 344 // @Jul.10, 2014 fix contant name, and udp sendto function.
Dollyparton 30:3b0481541a06 345 switch (sreg<uint8_t>(socket, Sn_SR)) {
Dollyparton 30:3b0481541a06 346 case SOCK_CLOSED :
Dollyparton 30:3b0481541a06 347 close(socket);
Dollyparton 30:3b0481541a06 348 return 0;
Dollyparton 30:3b0481541a06 349 //break;
Dollyparton 30:3b0481541a06 350 case SOCK_UDP :
Dollyparton 30:3b0481541a06 351 // ARP timeout is possible.
Dollyparton 30:3b0481541a06 352 if ((tmp_Sn_IR & INT_TIMEOUT) == INT_TIMEOUT) {
Dollyparton 30:3b0481541a06 353 sreg<uint8_t>(socket, Sn_ICR, INT_TIMEOUT);
Dollyparton 30:3b0481541a06 354 return 0;
Dollyparton 30:3b0481541a06 355 }
Dollyparton 30:3b0481541a06 356 break;
Dollyparton 30:3b0481541a06 357 default :
Dollyparton 30:3b0481541a06 358 break;
Dollyparton 30:3b0481541a06 359 }
Dollyparton 30:3b0481541a06 360 }
Dollyparton 30:3b0481541a06 361
Dollyparton 30:3b0481541a06 362 sreg<uint8_t>(socket, Sn_ICR, INT_SEND_OK);
Dollyparton 30:3b0481541a06 363
Dollyparton 30:3b0481541a06 364 return len;
Dollyparton 30:3b0481541a06 365 }
Dollyparton 30:3b0481541a06 366
Soohwan Kim 0:6f28332c466f 367 int WIZnet_Chip::recv(int socket, char* buf, int len)
Soohwan Kim 0:6f28332c466f 368 {
Soohwan Kim 0:6f28332c466f 369 if (socket < 0) {
Soohwan Kim 0:6f28332c466f 370 return -1;
Soohwan Kim 0:6f28332c466f 371 }
Soohwan Kim 0:6f28332c466f 372 uint16_t ptr = sreg<uint16_t>(socket, Sn_RX_RD);
Soohwan Kim 0:6f28332c466f 373 uint32_t sn_rx_base = W7500x_RXMEM_BASE + (uint32_t)(socket<<18);
Soohwan Kim 0:6f28332c466f 374
Soohwan Kim 0:6f28332c466f 375 for(int i=0; i<len; i++)
Soohwan Kim 0:6f28332c466f 376 buf[i] = *(volatile uint8_t *)(sn_rx_base + ((ptr+i)&0xFFFF));
Soohwan Kim 0:6f28332c466f 377
Soohwan Kim 0:6f28332c466f 378 sreg<uint16_t>(socket, Sn_RX_RD, ptr + len);
Soohwan Kim 0:6f28332c466f 379 scmd(socket, RECV);
Soohwan Kim 0:6f28332c466f 380
Soohwan Kim 0:6f28332c466f 381 return len;
Soohwan Kim 0:6f28332c466f 382 }
Soohwan Kim 0:6f28332c466f 383
Soohwan Kim 0:6f28332c466f 384 int WIZnet_Chip::new_socket()
Soohwan Kim 0:6f28332c466f 385 {
Soohwan Kim 0:6f28332c466f 386 for(int s = 0; s < MAX_SOCK_NUM; s++) {
Soohwan Kim 0:6f28332c466f 387 if (sreg<uint8_t>(s, Sn_SR) == SOCK_CLOSED) {
Soohwan Kim 0:6f28332c466f 388 return s;
Soohwan Kim 0:6f28332c466f 389 }
Soohwan Kim 0:6f28332c466f 390 }
Soohwan Kim 0:6f28332c466f 391 return -1;
Soohwan Kim 0:6f28332c466f 392 }
Soohwan Kim 0:6f28332c466f 393
Soohwan Kim 0:6f28332c466f 394 uint16_t WIZnet_Chip::new_port()
Soohwan Kim 0:6f28332c466f 395 {
Soohwan Kim 0:6f28332c466f 396 uint16_t port = rand();
Soohwan Kim 0:6f28332c466f 397 port |= 49152;
Soohwan Kim 0:6f28332c466f 398 return port;
Soohwan Kim 0:6f28332c466f 399 }
Soohwan Kim 0:6f28332c466f 400
Soohwan Kim 0:6f28332c466f 401 bool WIZnet_Chip::link(int wait_time_ms)
Soohwan Kim 0:6f28332c466f 402 {
Soohwan Kim 0:6f28332c466f 403 Timer t;
Soohwan Kim 0:6f28332c466f 404 t.reset();
Soohwan Kim 0:6f28332c466f 405 t.start();
Soohwan Kim 0:6f28332c466f 406 while(1) {
Soohwan Kim 0:6f28332c466f 407 int is_link = ethernet_link();
hjjeon 19:d8773cd4edc5 408
Soohwan Kim 0:6f28332c466f 409 if (is_link) {
Soohwan Kim 0:6f28332c466f 410 return true;
Soohwan Kim 0:6f28332c466f 411 }
Soohwan Kim 0:6f28332c466f 412 if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) {
Soohwan Kim 0:6f28332c466f 413 break;
Soohwan Kim 0:6f28332c466f 414 }
Soohwan Kim 0:6f28332c466f 415 }
Soohwan Kim 0:6f28332c466f 416 return 0;
Soohwan Kim 0:6f28332c466f 417 }
Soohwan Kim 0:6f28332c466f 418
Soohwan Kim 0:6f28332c466f 419 void WIZnet_Chip::set_link(PHYMode phymode)
Soohwan Kim 0:6f28332c466f 420 {
Soohwan Kim 0:6f28332c466f 421 int speed = -1;
Soohwan Kim 0:6f28332c466f 422 int duplex = 0;
Soohwan Kim 0:6f28332c466f 423
Soohwan Kim 0:6f28332c466f 424 switch(phymode) {
Soohwan Kim 0:6f28332c466f 425 case AutoNegotiate : speed = -1; duplex = 0; break;
Soohwan Kim 0:6f28332c466f 426 case HalfDuplex10 : speed = 0; duplex = 0; break;
Soohwan Kim 0:6f28332c466f 427 case FullDuplex10 : speed = 0; duplex = 1; break;
Soohwan Kim 0:6f28332c466f 428 case HalfDuplex100 : speed = 1; duplex = 0; break;
Soohwan Kim 0:6f28332c466f 429 case FullDuplex100 : speed = 1; duplex = 1; break;
Soohwan Kim 0:6f28332c466f 430 }
Soohwan Kim 0:6f28332c466f 431
Soohwan Kim 0:6f28332c466f 432 ethernet_set_link(speed, duplex);
Soohwan Kim 0:6f28332c466f 433 }
Soohwan Kim 0:6f28332c466f 434
Soohwan Kim 0:6f28332c466f 435 uint32_t str_to_ip(const char* str)
Soohwan Kim 0:6f28332c466f 436 {
Soohwan Kim 0:6f28332c466f 437 uint32_t ip = 0;
Soohwan Kim 0:6f28332c466f 438 char* p = (char*)str;
Soohwan Kim 0:6f28332c466f 439 for(int i = 0; i < 4; i++) {
Soohwan Kim 0:6f28332c466f 440 ip |= atoi(p);
Soohwan Kim 0:6f28332c466f 441 p = strchr(p, '.');
Soohwan Kim 0:6f28332c466f 442 if (p == NULL) {
Soohwan Kim 0:6f28332c466f 443 break;
Soohwan Kim 0:6f28332c466f 444 }
Soohwan Kim 0:6f28332c466f 445 ip <<= 8;
Soohwan Kim 0:6f28332c466f 446 p++;
Soohwan Kim 0:6f28332c466f 447 }
Soohwan Kim 0:6f28332c466f 448 return ip;
Soohwan Kim 0:6f28332c466f 449 }
Soohwan Kim 0:6f28332c466f 450
Soohwan Kim 0:6f28332c466f 451 void printfBytes(char* str, uint8_t* buf, int len)
Soohwan Kim 0:6f28332c466f 452 {
Soohwan Kim 0:6f28332c466f 453 printf("%s %d:", str, len);
Soohwan Kim 0:6f28332c466f 454 for(int i = 0; i < len; i++) {
Soohwan Kim 0:6f28332c466f 455 printf(" %02x", buf[i]);
Soohwan Kim 0:6f28332c466f 456 }
Soohwan Kim 0:6f28332c466f 457 printf("\n");
Soohwan Kim 0:6f28332c466f 458 }
Soohwan Kim 0:6f28332c466f 459
Soohwan Kim 0:6f28332c466f 460 void printHex(uint8_t* buf, int len)
Soohwan Kim 0:6f28332c466f 461 {
Soohwan Kim 0:6f28332c466f 462 for(int i = 0; i < len; i++) {
Soohwan Kim 0:6f28332c466f 463 if ((i%16) == 0) {
Soohwan Kim 0:6f28332c466f 464 printf("%p", buf+i);
Soohwan Kim 0:6f28332c466f 465 }
Soohwan Kim 0:6f28332c466f 466 printf(" %02x", buf[i]);
Soohwan Kim 0:6f28332c466f 467 if ((i%16) == 15) {
Soohwan Kim 0:6f28332c466f 468 printf("\n");
Soohwan Kim 0:6f28332c466f 469 }
Soohwan Kim 0:6f28332c466f 470 }
Soohwan Kim 0:6f28332c466f 471 printf("\n");
Soohwan Kim 0:6f28332c466f 472 }
Soohwan Kim 0:6f28332c466f 473
Soohwan Kim 0:6f28332c466f 474 void debug_hex(uint8_t* buf, int len)
Soohwan Kim 0:6f28332c466f 475 {
Soohwan Kim 0:6f28332c466f 476 for(int i = 0; i < len; i++) {
Soohwan Kim 0:6f28332c466f 477 if ((i%16) == 0) {
Soohwan Kim 0:6f28332c466f 478 debug("%p", buf+i);
Soohwan Kim 0:6f28332c466f 479 }
Soohwan Kim 0:6f28332c466f 480 debug(" %02x", buf[i]);
Soohwan Kim 0:6f28332c466f 481 if ((i%16) == 15) {
Soohwan Kim 0:6f28332c466f 482 debug("\n");
Soohwan Kim 0:6f28332c466f 483 }
Soohwan Kim 0:6f28332c466f 484 }
Soohwan Kim 0:6f28332c466f 485 debug("\n");
Soohwan Kim 0:6f28332c466f 486 }
Soohwan Kim 0:6f28332c466f 487
Soohwan Kim 0:6f28332c466f 488 void WIZnet_Chip::scmd(int socket, Command cmd)
Soohwan Kim 0:6f28332c466f 489 {
Soohwan Kim 0:6f28332c466f 490 sreg<uint8_t>(socket, Sn_CR, cmd);
Soohwan Kim 0:6f28332c466f 491 while(sreg<uint8_t>(socket, Sn_CR));
Soohwan Kim 0:6f28332c466f 492 }
Soohwan Kim 0:6f28332c466f 493
Soohwan Kim 0:6f28332c466f 494
Soohwan Kim 0:6f28332c466f 495 void mdio_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin_MDC, uint16_t GPIO_Pin_MDIO)
Soohwan Kim 0:6f28332c466f 496 {
Soohwan Kim 0:6f28332c466f 497 /* Set GPIOs for MDIO and MDC */
Soohwan Kim 0:6f28332c466f 498 GPIO_InitTypeDef MDIO_InitDef;
Soohwan Kim 0:6f28332c466f 499 HAL_PAD_AFConfig(PAD_PB, GPIO_Pin_MDIO, PAD_AF1);
Soohwan Kim 0:6f28332c466f 500 HAL_PAD_AFConfig(PAD_PB, GPIO_Pin_MDC, PAD_AF1);
Soohwan Kim 0:6f28332c466f 501 MDIO_InitDef.GPIO_Pin = GPIO_Pin_MDC | GPIO_Pin_MDIO;
Soohwan Kim 0:6f28332c466f 502 MDIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
Soohwan Kim 0:6f28332c466f 503 HAL_GPIO_Init(GPIOx, &MDIO_InitDef);
Soohwan Kim 0:6f28332c466f 504 }
Soohwan Kim 0:6f28332c466f 505
Soohwan Kim 0:6f28332c466f 506 void output_MDIO(GPIO_TypeDef* GPIOx, uint32_t val, uint32_t n)
Soohwan Kim 0:6f28332c466f 507 {
Soohwan Kim 0:6f28332c466f 508 for(val <<= (32-n); n; val<<=1, n--)
Soohwan Kim 0:6f28332c466f 509 {
Soohwan Kim 0:6f28332c466f 510 if(val & 0x80000000)
Soohwan Kim 0:6f28332c466f 511 HAL_GPIO_SetBits(GPIOx, MDIO);
Soohwan Kim 0:6f28332c466f 512 else
Soohwan Kim 0:6f28332c466f 513 HAL_GPIO_ResetBits(GPIOx, MDIO);
Soohwan Kim 0:6f28332c466f 514
Soohwan Kim 0:6f28332c466f 515 wait_ms(MDC_WAIT);
Soohwan Kim 0:6f28332c466f 516 HAL_GPIO_SetBits(GPIOx, MDC);
Soohwan Kim 0:6f28332c466f 517 wait_ms(MDC_WAIT);
Soohwan Kim 0:6f28332c466f 518 HAL_GPIO_ResetBits(GPIOx, MDC);
Soohwan Kim 0:6f28332c466f 519 }
Soohwan Kim 0:6f28332c466f 520 }
Soohwan Kim 0:6f28332c466f 521
Soohwan Kim 0:6f28332c466f 522 uint32_t input_MDIO( GPIO_TypeDef* GPIOx )
Soohwan Kim 0:6f28332c466f 523 {
Soohwan Kim 0:6f28332c466f 524 uint32_t i, val=0;
Soohwan Kim 0:6f28332c466f 525 for(i=0; i<16; i++)
Soohwan Kim 0:6f28332c466f 526 {
Soohwan Kim 0:6f28332c466f 527 val <<=1;
Soohwan Kim 0:6f28332c466f 528 HAL_GPIO_SetBits(GPIOx, MDC);
Soohwan Kim 0:6f28332c466f 529 wait_ms(MDC_WAIT);
Soohwan Kim 0:6f28332c466f 530 HAL_GPIO_ResetBits(GPIOx, MDC);
Soohwan Kim 0:6f28332c466f 531 wait_ms(MDC_WAIT);
Soohwan Kim 0:6f28332c466f 532 val |= HAL_GPIO_ReadInputDataBit(GPIOx, MDIO);
Soohwan Kim 0:6f28332c466f 533 }
Soohwan Kim 0:6f28332c466f 534 return (val);
Soohwan Kim 0:6f28332c466f 535 }
Soohwan Kim 0:6f28332c466f 536
Soohwan Kim 0:6f28332c466f 537 void turnaround_MDIO( GPIO_TypeDef* GPIOx)
Soohwan Kim 0:6f28332c466f 538 {
Soohwan Kim 0:6f28332c466f 539 GPIOx->OUTENCLR = MDIO ;
Soohwan Kim 0:6f28332c466f 540 HAL_GPIO_SetBits(GPIOx, MDC);
Soohwan Kim 0:6f28332c466f 541 wait_ms(MDC_WAIT);
Soohwan Kim 0:6f28332c466f 542 HAL_GPIO_ResetBits(GPIOx, MDC);
Soohwan Kim 0:6f28332c466f 543 wait_ms(MDC_WAIT);
Soohwan Kim 0:6f28332c466f 544 }
Soohwan Kim 0:6f28332c466f 545
Soohwan Kim 0:6f28332c466f 546 void idle_MDIO( GPIO_TypeDef* GPIOx )
Soohwan Kim 0:6f28332c466f 547 {
Soohwan Kim 0:6f28332c466f 548 GPIOx->OUTENSET = MDIO ;
Soohwan Kim 0:6f28332c466f 549 HAL_GPIO_SetBits(GPIOx,MDC);
Soohwan Kim 0:6f28332c466f 550 wait_ms(MDC_WAIT);
Soohwan Kim 0:6f28332c466f 551 HAL_GPIO_ResetBits(GPIOx, MDC);
Soohwan Kim 0:6f28332c466f 552 wait_ms(MDC_WAIT);
Soohwan Kim 0:6f28332c466f 553 }
Soohwan Kim 0:6f28332c466f 554
Soohwan Kim 0:6f28332c466f 555 uint32_t mdio_read(GPIO_TypeDef* GPIOx, uint32_t PhyRegAddr)
Soohwan Kim 0:6f28332c466f 556 {
Soohwan Kim 0:6f28332c466f 557 output_MDIO(GPIOx, 0xFFFFFFFF, 32);
Soohwan Kim 0:6f28332c466f 558 output_MDIO(GPIOx, 0x06, 4);
Soohwan Kim 0:6f28332c466f 559 output_MDIO(GPIOx, PHY_ADDR, 5);
Soohwan Kim 0:6f28332c466f 560 output_MDIO(GPIOx, PhyRegAddr, 5);
Soohwan Kim 0:6f28332c466f 561 turnaround_MDIO(GPIOx);
Soohwan Kim 0:6f28332c466f 562 uint32_t val = input_MDIO(GPIOx );
Soohwan Kim 0:6f28332c466f 563 idle_MDIO(GPIOx);
Soohwan Kim 0:6f28332c466f 564 return val;
Soohwan Kim 0:6f28332c466f 565 }
Soohwan Kim 0:6f28332c466f 566
Soohwan Kim 0:6f28332c466f 567 void mdio_write(GPIO_TypeDef* GPIOx, uint32_t PhyRegAddr, uint32_t val)
Soohwan Kim 0:6f28332c466f 568 {
Soohwan Kim 0:6f28332c466f 569 output_MDIO(GPIOx, 0xFFFFFFFF, 32);
Soohwan Kim 0:6f28332c466f 570 output_MDIO(GPIOx, 0x05, 4);
Soohwan Kim 0:6f28332c466f 571 output_MDIO(GPIOx, PHY_ADDR, 5);
Soohwan Kim 0:6f28332c466f 572 output_MDIO(GPIOx, PhyRegAddr, 5);
Soohwan Kim 0:6f28332c466f 573 output_MDIO(GPIOx, 0x02, 2);
Soohwan Kim 0:6f28332c466f 574 output_MDIO(GPIOx, val, 16);
Soohwan Kim 0:6f28332c466f 575 idle_MDIO(GPIOx);
Soohwan Kim 0:6f28332c466f 576 }
Soohwan Kim 0:6f28332c466f 577
embeddist 14:2101ab5ee40f 578 int WIZnet_Chip::ethernet_link(void) {
Soohwan Kim 0:6f28332c466f 579 return ((mdio_read(GPIO_MDC, PHYREG_STATUS)>>SVAL)&0x01);
Soohwan Kim 0:6f28332c466f 580 }
Soohwan Kim 0:6f28332c466f 581
embeddist 14:2101ab5ee40f 582 void WIZnet_Chip::ethernet_set_link(int speed, int duplex) {
Soohwan Kim 0:6f28332c466f 583 uint32_t val=0;
Soohwan Kim 0:6f28332c466f 584 if((speed < 0) || (speed > 1)) {
Soohwan Kim 0:6f28332c466f 585 val = CNTL_AUTONEGO;
Soohwan Kim 0:6f28332c466f 586 } else {
Soohwan Kim 0:6f28332c466f 587 val = ((CNTL_SPEED&(speed<<11))|(CNTL_DUPLEX&(duplex<<7)));
Soohwan Kim 0:6f28332c466f 588 }
Soohwan Kim 0:6f28332c466f 589 mdio_write(GPIO_MDC, PHYREG_CONTROL, val);
Soohwan Kim 0:6f28332c466f 590 }
embeddist 14:2101ab5ee40f 591
embeddist 14:2101ab5ee40f 592 void WIZnet_Chip::reg_rd_mac(uint16_t addr, uint8_t* data)
embeddist 14:2101ab5ee40f 593 {
embeddist 14:2101ab5ee40f 594 data[0] = *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+3));
embeddist 14:2101ab5ee40f 595 data[1] = *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+2));
embeddist 14:2101ab5ee40f 596 data[2] = *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+1));
embeddist 14:2101ab5ee40f 597 data[3] = *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+0));
embeddist 14:2101ab5ee40f 598 data[4] = *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+7));
embeddist 14:2101ab5ee40f 599 data[5] = *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+6));
embeddist 14:2101ab5ee40f 600 }
embeddist 14:2101ab5ee40f 601
embeddist 14:2101ab5ee40f 602 void WIZnet_Chip::reg_wr_ip(uint16_t addr, uint8_t cb, const char* ip)
embeddist 14:2101ab5ee40f 603 {
embeddist 14:2101ab5ee40f 604 uint8_t buf[4]={0,};
embeddist 14:2101ab5ee40f 605 uint32_t wr_ip = 0;
embeddist 14:2101ab5ee40f 606 char* p = (char*)ip;
embeddist 14:2101ab5ee40f 607
embeddist 14:2101ab5ee40f 608 for(int i = 0; i < 4; i++) {
embeddist 14:2101ab5ee40f 609 wr_ip = (wr_ip<<8);
embeddist 14:2101ab5ee40f 610 buf[i] = atoi(p);
embeddist 14:2101ab5ee40f 611 wr_ip |= buf[i];
embeddist 14:2101ab5ee40f 612 p = strchr(p, '.');
embeddist 14:2101ab5ee40f 613 if (p == NULL) break;
embeddist 14:2101ab5ee40f 614 p++;
embeddist 14:2101ab5ee40f 615 }
embeddist 14:2101ab5ee40f 616 *(volatile uint32_t *)(W7500x_WZTOE_BASE + (uint32_t)((cb<<16)+addr)) = wr_ip;
embeddist 14:2101ab5ee40f 617 }
embeddist 14:2101ab5ee40f 618
embeddist 14:2101ab5ee40f 619 void WIZnet_Chip::sreg_ip(int socket, uint16_t addr, const char* ip) {
embeddist 14:2101ab5ee40f 620 reg_wr_ip(addr, (uint8_t)(0x01+(socket<<2)), ip);
embeddist 14:2101ab5ee40f 621 }
embeddist 14:2101ab5ee40f 622
Soohwan Kim 0:6f28332c466f 623 #endif
Soohwan Kim 0:6f28332c466f 624
embeddist 28:200e63e513a8 625