For mbed OS-5 version for WIZnet Ethernet Interface, this is Library using Hardware TCP/IP chip, W5500 and TCP/IP Offload Engine, W7500.
Warning
- If you want to use existing codes, you need to change the class used as EthernetInterface to WIZnetInterface.
This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500 and TCP/IP Offload Engine, W7500.
- WIZwiki_W7500 : /platforms/WIZwiki-W7500/
- WIZwiki_W7500P : /platforms/WIZwiki-W7500P/
- WIZwiki_W7500ECO : /platforms/WIZwiki-W7500ECO/
- W5500 Ethernet Shield : /components/W5500-Ethernet-Kit-for-IoT/
This library is an Ethernet Interface library port-based on [EthernetInterface](https://developer.mbed.org/users/mbed_official/code/EthernetInterface/docs/tip/).
For more detail, visit http://embeddist.blogspot.kr/2015/06/wiznetinterface-for-armmbed.html
arch/ext/W5500.cpp@0:d4c8fe4d9b29, 2017-09-04 (annotated)
- Committer:
- justinkim
- Date:
- Mon Sep 04 00:23:04 2017 +0000
- Revision:
- 0:d4c8fe4d9b29
mbed OS 5 version migration...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
justinkim | 0:d4c8fe4d9b29 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
justinkim | 0:d4c8fe4d9b29 | 2 | * |
justinkim | 0:d4c8fe4d9b29 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
justinkim | 0:d4c8fe4d9b29 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
justinkim | 0:d4c8fe4d9b29 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
justinkim | 0:d4c8fe4d9b29 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
justinkim | 0:d4c8fe4d9b29 | 7 | * furnished to do so, subject to the following conditions: |
justinkim | 0:d4c8fe4d9b29 | 8 | * |
justinkim | 0:d4c8fe4d9b29 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
justinkim | 0:d4c8fe4d9b29 | 10 | * substantial portions of the Software. |
justinkim | 0:d4c8fe4d9b29 | 11 | * |
justinkim | 0:d4c8fe4d9b29 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
justinkim | 0:d4c8fe4d9b29 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
justinkim | 0:d4c8fe4d9b29 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
justinkim | 0:d4c8fe4d9b29 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
justinkim | 0:d4c8fe4d9b29 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
justinkim | 0:d4c8fe4d9b29 | 17 | */ |
justinkim | 0:d4c8fe4d9b29 | 18 | #include "eth_arch.h" |
justinkim | 0:d4c8fe4d9b29 | 19 | #if (not defined TARGET_WIZwiki_W7500) && (not defined TARGET_WIZwiki_W7500P) && (not defined TARGET_WIZwiki_W7500ECO) |
justinkim | 0:d4c8fe4d9b29 | 20 | |
justinkim | 0:d4c8fe4d9b29 | 21 | |
justinkim | 0:d4c8fe4d9b29 | 22 | |
justinkim | 0:d4c8fe4d9b29 | 23 | #include "mbed.h" |
justinkim | 0:d4c8fe4d9b29 | 24 | #include "mbed_debug.h" |
justinkim | 0:d4c8fe4d9b29 | 25 | #include "DNSClient.h" |
justinkim | 0:d4c8fe4d9b29 | 26 | |
justinkim | 0:d4c8fe4d9b29 | 27 | |
justinkim | 0:d4c8fe4d9b29 | 28 | //Debug is disabled by default |
justinkim | 0:d4c8fe4d9b29 | 29 | #if 0 |
justinkim | 0:d4c8fe4d9b29 | 30 | #define DBG(...) do{debug("%p %d %s ", this,__LINE__,__PRETTY_FUNCTION__); debug(__VA_ARGS__); } while(0); |
justinkim | 0:d4c8fe4d9b29 | 31 | //#define DBG(x, ...) debug("[W5500:DBG]"x"\r\n", ##__VA_ARGS__); |
justinkim | 0:d4c8fe4d9b29 | 32 | #define WARN(x, ...) debug("[W5500:WARN]"x"\r\n", ##__VA_ARGS__); |
justinkim | 0:d4c8fe4d9b29 | 33 | #define ERR(x, ...) debug("[W5500:ERR]"x"\r\n", ##__VA_ARGS__); |
justinkim | 0:d4c8fe4d9b29 | 34 | #else |
justinkim | 0:d4c8fe4d9b29 | 35 | #define DBG(x, ...) |
justinkim | 0:d4c8fe4d9b29 | 36 | #define WARN(x, ...) |
justinkim | 0:d4c8fe4d9b29 | 37 | #define ERR(x, ...) |
justinkim | 0:d4c8fe4d9b29 | 38 | #endif |
justinkim | 0:d4c8fe4d9b29 | 39 | |
justinkim | 0:d4c8fe4d9b29 | 40 | #if 1 |
justinkim | 0:d4c8fe4d9b29 | 41 | #define INFO(x, ...) debug("[W5500:INFO]"x"\r\n", ##__VA_ARGS__); |
justinkim | 0:d4c8fe4d9b29 | 42 | #else |
justinkim | 0:d4c8fe4d9b29 | 43 | #define INFO(x, ...) |
justinkim | 0:d4c8fe4d9b29 | 44 | #endif |
justinkim | 0:d4c8fe4d9b29 | 45 | |
justinkim | 0:d4c8fe4d9b29 | 46 | #define DBG_SPI 0 |
justinkim | 0:d4c8fe4d9b29 | 47 | |
justinkim | 0:d4c8fe4d9b29 | 48 | WIZnet_Chip* WIZnet_Chip::inst; |
justinkim | 0:d4c8fe4d9b29 | 49 | |
justinkim | 0:d4c8fe4d9b29 | 50 | WIZnet_Chip::WIZnet_Chip(PinName mosi, PinName miso, PinName sclk, PinName _cs, PinName _reset): |
justinkim | 0:d4c8fe4d9b29 | 51 | cs(_cs), reset_pin(_reset) |
justinkim | 0:d4c8fe4d9b29 | 52 | { |
justinkim | 0:d4c8fe4d9b29 | 53 | spi = new SPI(mosi, miso, sclk); |
justinkim | 0:d4c8fe4d9b29 | 54 | cs = 1; |
justinkim | 0:d4c8fe4d9b29 | 55 | reset_pin = 1; |
justinkim | 0:d4c8fe4d9b29 | 56 | inst = this; |
justinkim | 0:d4c8fe4d9b29 | 57 | sock_any_port = SOCK_ANY_PORT_NUM; |
justinkim | 0:d4c8fe4d9b29 | 58 | } |
justinkim | 0:d4c8fe4d9b29 | 59 | |
justinkim | 0:d4c8fe4d9b29 | 60 | WIZnet_Chip::WIZnet_Chip(SPI* spi, PinName _cs, PinName _reset): |
justinkim | 0:d4c8fe4d9b29 | 61 | cs(_cs), reset_pin(_reset) |
justinkim | 0:d4c8fe4d9b29 | 62 | { |
justinkim | 0:d4c8fe4d9b29 | 63 | this->spi = spi; |
justinkim | 0:d4c8fe4d9b29 | 64 | cs = 1; |
justinkim | 0:d4c8fe4d9b29 | 65 | reset_pin = 1; |
justinkim | 0:d4c8fe4d9b29 | 66 | inst = this; |
justinkim | 0:d4c8fe4d9b29 | 67 | sock_any_port = SOCK_ANY_PORT_NUM; |
justinkim | 0:d4c8fe4d9b29 | 68 | } |
justinkim | 0:d4c8fe4d9b29 | 69 | |
justinkim | 0:d4c8fe4d9b29 | 70 | bool WIZnet_Chip::setmac() |
justinkim | 0:d4c8fe4d9b29 | 71 | { |
justinkim | 0:d4c8fe4d9b29 | 72 | |
justinkim | 0:d4c8fe4d9b29 | 73 | for (int i =0; i < 6; i++) reg_wr<uint8_t>(SHAR+i, mac[i]); |
justinkim | 0:d4c8fe4d9b29 | 74 | |
justinkim | 0:d4c8fe4d9b29 | 75 | return true; |
justinkim | 0:d4c8fe4d9b29 | 76 | } |
justinkim | 0:d4c8fe4d9b29 | 77 | |
justinkim | 0:d4c8fe4d9b29 | 78 | // Set the IP |
justinkim | 0:d4c8fe4d9b29 | 79 | bool WIZnet_Chip::setip() |
justinkim | 0:d4c8fe4d9b29 | 80 | { |
justinkim | 0:d4c8fe4d9b29 | 81 | reg_wr<uint32_t>(SIPR, ip); |
justinkim | 0:d4c8fe4d9b29 | 82 | reg_wr<uint32_t>(GAR, gateway); |
justinkim | 0:d4c8fe4d9b29 | 83 | reg_wr<uint32_t>(SUBR, netmask); |
justinkim | 0:d4c8fe4d9b29 | 84 | return true; |
justinkim | 0:d4c8fe4d9b29 | 85 | } |
justinkim | 0:d4c8fe4d9b29 | 86 | |
justinkim | 0:d4c8fe4d9b29 | 87 | bool WIZnet_Chip::setProtocol(int socket, Protocol p) |
justinkim | 0:d4c8fe4d9b29 | 88 | { |
justinkim | 0:d4c8fe4d9b29 | 89 | if (socket < 0) { |
justinkim | 0:d4c8fe4d9b29 | 90 | return false; |
justinkim | 0:d4c8fe4d9b29 | 91 | } |
justinkim | 0:d4c8fe4d9b29 | 92 | sreg<uint8_t>(socket, Sn_MR, p); |
justinkim | 0:d4c8fe4d9b29 | 93 | return true; |
justinkim | 0:d4c8fe4d9b29 | 94 | } |
justinkim | 0:d4c8fe4d9b29 | 95 | |
justinkim | 0:d4c8fe4d9b29 | 96 | bool WIZnet_Chip::connect(int socket, const char * host, int port, int timeout_ms) |
justinkim | 0:d4c8fe4d9b29 | 97 | { |
justinkim | 0:d4c8fe4d9b29 | 98 | if (socket < 0) { |
justinkim | 0:d4c8fe4d9b29 | 99 | return false; |
justinkim | 0:d4c8fe4d9b29 | 100 | } |
justinkim | 0:d4c8fe4d9b29 | 101 | sreg<uint8_t>(socket, Sn_MR, TCP); |
justinkim | 0:d4c8fe4d9b29 | 102 | scmd(socket, OPEN); |
justinkim | 0:d4c8fe4d9b29 | 103 | sreg_ip(socket, Sn_DIPR, host); |
justinkim | 0:d4c8fe4d9b29 | 104 | sreg<uint16_t>(socket, Sn_DPORT, port); |
justinkim | 0:d4c8fe4d9b29 | 105 | sreg<uint16_t>(socket, Sn_PORT, new_port()); |
justinkim | 0:d4c8fe4d9b29 | 106 | scmd(socket, CONNECT); |
justinkim | 0:d4c8fe4d9b29 | 107 | Timer t; |
justinkim | 0:d4c8fe4d9b29 | 108 | t.reset(); |
justinkim | 0:d4c8fe4d9b29 | 109 | t.start(); |
justinkim | 0:d4c8fe4d9b29 | 110 | while(!is_connected(socket)) { |
justinkim | 0:d4c8fe4d9b29 | 111 | if (t.read_ms() > timeout_ms) { |
justinkim | 0:d4c8fe4d9b29 | 112 | return false; |
justinkim | 0:d4c8fe4d9b29 | 113 | } |
justinkim | 0:d4c8fe4d9b29 | 114 | } |
justinkim | 0:d4c8fe4d9b29 | 115 | return true; |
justinkim | 0:d4c8fe4d9b29 | 116 | } |
justinkim | 0:d4c8fe4d9b29 | 117 | |
justinkim | 0:d4c8fe4d9b29 | 118 | bool WIZnet_Chip::gethostbyname(const char* host, uint32_t* ip) |
justinkim | 0:d4c8fe4d9b29 | 119 | { |
justinkim | 0:d4c8fe4d9b29 | 120 | uint32_t addr = str_to_ip(host); |
justinkim | 0:d4c8fe4d9b29 | 121 | char buf[17]; |
justinkim | 0:d4c8fe4d9b29 | 122 | snprintf(buf, sizeof(buf), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff); |
justinkim | 0:d4c8fe4d9b29 | 123 | if (strcmp(buf, host) == 0) { |
justinkim | 0:d4c8fe4d9b29 | 124 | *ip = addr; |
justinkim | 0:d4c8fe4d9b29 | 125 | return true; |
justinkim | 0:d4c8fe4d9b29 | 126 | } |
justinkim | 0:d4c8fe4d9b29 | 127 | DNSClient client; |
justinkim | 0:d4c8fe4d9b29 | 128 | if(client.lookup(host)) { |
justinkim | 0:d4c8fe4d9b29 | 129 | *ip = client.ip; |
justinkim | 0:d4c8fe4d9b29 | 130 | return true; |
justinkim | 0:d4c8fe4d9b29 | 131 | } |
justinkim | 0:d4c8fe4d9b29 | 132 | return false; |
justinkim | 0:d4c8fe4d9b29 | 133 | } |
justinkim | 0:d4c8fe4d9b29 | 134 | |
justinkim | 0:d4c8fe4d9b29 | 135 | bool WIZnet_Chip::disconnect() |
justinkim | 0:d4c8fe4d9b29 | 136 | { |
justinkim | 0:d4c8fe4d9b29 | 137 | return true; |
justinkim | 0:d4c8fe4d9b29 | 138 | } |
justinkim | 0:d4c8fe4d9b29 | 139 | |
justinkim | 0:d4c8fe4d9b29 | 140 | bool WIZnet_Chip::is_connected(int socket) |
justinkim | 0:d4c8fe4d9b29 | 141 | { |
justinkim | 0:d4c8fe4d9b29 | 142 | /* |
justinkim | 0:d4c8fe4d9b29 | 143 | if (sreg<uint8_t>(socket, Sn_SR) == SOCK_ESTABLISHED) { |
justinkim | 0:d4c8fe4d9b29 | 144 | return true; |
justinkim | 0:d4c8fe4d9b29 | 145 | } |
justinkim | 0:d4c8fe4d9b29 | 146 | */ |
justinkim | 0:d4c8fe4d9b29 | 147 | uint8_t tmpSn_SR; |
justinkim | 0:d4c8fe4d9b29 | 148 | tmpSn_SR = sreg<uint8_t>(socket, Sn_SR); |
justinkim | 0:d4c8fe4d9b29 | 149 | // packet sending is possible, when state is SOCK_CLOSE_WAIT. |
justinkim | 0:d4c8fe4d9b29 | 150 | if ((tmpSn_SR == SOCK_ESTABLISHED) || (tmpSn_SR == SOCK_CLOSE_WAIT)) { |
justinkim | 0:d4c8fe4d9b29 | 151 | return true; |
justinkim | 0:d4c8fe4d9b29 | 152 | } |
justinkim | 0:d4c8fe4d9b29 | 153 | return false; |
justinkim | 0:d4c8fe4d9b29 | 154 | } |
justinkim | 0:d4c8fe4d9b29 | 155 | |
justinkim | 0:d4c8fe4d9b29 | 156 | // Reset the chip & set the buffer |
justinkim | 0:d4c8fe4d9b29 | 157 | void WIZnet_Chip::reset() |
justinkim | 0:d4c8fe4d9b29 | 158 | { |
justinkim | 0:d4c8fe4d9b29 | 159 | #if defined(USE_WIZ550IO_MAC) |
justinkim | 0:d4c8fe4d9b29 | 160 | //read the MAC address inside the module |
justinkim | 0:d4c8fe4d9b29 | 161 | reg_rd_mac(SHAR, mac); |
justinkim | 0:d4c8fe4d9b29 | 162 | #endif |
justinkim | 0:d4c8fe4d9b29 | 163 | // hw reset |
justinkim | 0:d4c8fe4d9b29 | 164 | reset_pin = 1; |
justinkim | 0:d4c8fe4d9b29 | 165 | reset_pin = 0; |
justinkim | 0:d4c8fe4d9b29 | 166 | wait_us(500); // 500us (w5500) |
justinkim | 0:d4c8fe4d9b29 | 167 | reset_pin = 1; |
justinkim | 0:d4c8fe4d9b29 | 168 | wait_ms(400); // 400ms (w5500) |
justinkim | 0:d4c8fe4d9b29 | 169 | #if defined(USE_WIZ550IO_MAC) |
justinkim | 0:d4c8fe4d9b29 | 170 | // write MAC address inside the WZTOE MAC address register |
justinkim | 0:d4c8fe4d9b29 | 171 | reg_wr_mac(SHAR, mac); |
justinkim | 0:d4c8fe4d9b29 | 172 | #endif |
justinkim | 0:d4c8fe4d9b29 | 173 | // set RX and TX buffer size |
justinkim | 0:d4c8fe4d9b29 | 174 | #if 0 |
justinkim | 0:d4c8fe4d9b29 | 175 | for (int socket = 0; socket < MAX_SOCK_NUM; socket++) { |
justinkim | 0:d4c8fe4d9b29 | 176 | sreg<uint8_t>(socket, Sn_RXBUF_SIZE, 2); |
justinkim | 0:d4c8fe4d9b29 | 177 | sreg<uint8_t>(socket, Sn_TXBUF_SIZE, 2); |
justinkim | 0:d4c8fe4d9b29 | 178 | } |
justinkim | 0:d4c8fe4d9b29 | 179 | #endif |
justinkim | 0:d4c8fe4d9b29 | 180 | } |
justinkim | 0:d4c8fe4d9b29 | 181 | |
justinkim | 0:d4c8fe4d9b29 | 182 | |
justinkim | 0:d4c8fe4d9b29 | 183 | bool WIZnet_Chip::close(int socket) |
justinkim | 0:d4c8fe4d9b29 | 184 | { |
justinkim | 0:d4c8fe4d9b29 | 185 | if (socket < 0) { |
justinkim | 0:d4c8fe4d9b29 | 186 | return false; |
justinkim | 0:d4c8fe4d9b29 | 187 | } |
justinkim | 0:d4c8fe4d9b29 | 188 | // if not connected, return |
justinkim | 0:d4c8fe4d9b29 | 189 | if (sreg<uint8_t>(socket, Sn_SR) == SOCK_CLOSED) { |
justinkim | 0:d4c8fe4d9b29 | 190 | return true; |
justinkim | 0:d4c8fe4d9b29 | 191 | } |
justinkim | 0:d4c8fe4d9b29 | 192 | if (sreg<uint8_t>(socket, Sn_MR) == TCP) { |
justinkim | 0:d4c8fe4d9b29 | 193 | scmd(socket, DISCON); |
justinkim | 0:d4c8fe4d9b29 | 194 | } |
justinkim | 0:d4c8fe4d9b29 | 195 | scmd(socket, CLOSE); |
justinkim | 0:d4c8fe4d9b29 | 196 | sreg<uint8_t>(socket, Sn_IR, 0xff); |
justinkim | 0:d4c8fe4d9b29 | 197 | return true; |
justinkim | 0:d4c8fe4d9b29 | 198 | } |
justinkim | 0:d4c8fe4d9b29 | 199 | |
justinkim | 0:d4c8fe4d9b29 | 200 | int WIZnet_Chip::wait_readable(int socket, int wait_time_ms, int req_size) |
justinkim | 0:d4c8fe4d9b29 | 201 | { |
justinkim | 0:d4c8fe4d9b29 | 202 | if (socket < 0) { |
justinkim | 0:d4c8fe4d9b29 | 203 | return -1; |
justinkim | 0:d4c8fe4d9b29 | 204 | } |
justinkim | 0:d4c8fe4d9b29 | 205 | Timer t; |
justinkim | 0:d4c8fe4d9b29 | 206 | t.reset(); |
justinkim | 0:d4c8fe4d9b29 | 207 | t.start(); |
justinkim | 0:d4c8fe4d9b29 | 208 | while(1) { |
justinkim | 0:d4c8fe4d9b29 | 209 | //int size = sreg<uint16_t>(socket, Sn_RX_RSR); |
justinkim | 0:d4c8fe4d9b29 | 210 | // during the reading Sn_RX_RXR, it has the possible change of this register. |
justinkim | 0:d4c8fe4d9b29 | 211 | // so read twice and get same value then use size information. |
justinkim | 0:d4c8fe4d9b29 | 212 | int size, size2; |
justinkim | 0:d4c8fe4d9b29 | 213 | do { |
justinkim | 0:d4c8fe4d9b29 | 214 | size = sreg<uint16_t>(socket, Sn_RX_RSR); |
justinkim | 0:d4c8fe4d9b29 | 215 | size2 = sreg<uint16_t>(socket, Sn_RX_RSR); |
justinkim | 0:d4c8fe4d9b29 | 216 | } while (size != size2); |
justinkim | 0:d4c8fe4d9b29 | 217 | |
justinkim | 0:d4c8fe4d9b29 | 218 | if (size > req_size) { |
justinkim | 0:d4c8fe4d9b29 | 219 | return size; |
justinkim | 0:d4c8fe4d9b29 | 220 | } |
justinkim | 0:d4c8fe4d9b29 | 221 | if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) { |
justinkim | 0:d4c8fe4d9b29 | 222 | break; |
justinkim | 0:d4c8fe4d9b29 | 223 | } |
justinkim | 0:d4c8fe4d9b29 | 224 | } |
justinkim | 0:d4c8fe4d9b29 | 225 | return -1; |
justinkim | 0:d4c8fe4d9b29 | 226 | } |
justinkim | 0:d4c8fe4d9b29 | 227 | |
justinkim | 0:d4c8fe4d9b29 | 228 | int WIZnet_Chip::wait_writeable(int socket, int wait_time_ms, int req_size) |
justinkim | 0:d4c8fe4d9b29 | 229 | { |
justinkim | 0:d4c8fe4d9b29 | 230 | if (socket < 0) { |
justinkim | 0:d4c8fe4d9b29 | 231 | return -1; |
justinkim | 0:d4c8fe4d9b29 | 232 | } |
justinkim | 0:d4c8fe4d9b29 | 233 | Timer t; |
justinkim | 0:d4c8fe4d9b29 | 234 | t.reset(); |
justinkim | 0:d4c8fe4d9b29 | 235 | t.start(); |
justinkim | 0:d4c8fe4d9b29 | 236 | while(1) { |
justinkim | 0:d4c8fe4d9b29 | 237 | //int size = sreg<uint16_t>(socket, Sn_TX_FSR); |
justinkim | 0:d4c8fe4d9b29 | 238 | // during the reading Sn_TX_FSR, it has the possible change of this register. |
justinkim | 0:d4c8fe4d9b29 | 239 | // so read twice and get same value then use size information. |
justinkim | 0:d4c8fe4d9b29 | 240 | int size, size2; |
justinkim | 0:d4c8fe4d9b29 | 241 | do { |
justinkim | 0:d4c8fe4d9b29 | 242 | size = sreg<uint16_t>(socket, Sn_TX_FSR); |
justinkim | 0:d4c8fe4d9b29 | 243 | size2 = sreg<uint16_t>(socket, Sn_TX_FSR); |
justinkim | 0:d4c8fe4d9b29 | 244 | } while (size != size2); |
justinkim | 0:d4c8fe4d9b29 | 245 | |
justinkim | 0:d4c8fe4d9b29 | 246 | if (size > req_size) { |
justinkim | 0:d4c8fe4d9b29 | 247 | return size; |
justinkim | 0:d4c8fe4d9b29 | 248 | } |
justinkim | 0:d4c8fe4d9b29 | 249 | if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) { |
justinkim | 0:d4c8fe4d9b29 | 250 | break; |
justinkim | 0:d4c8fe4d9b29 | 251 | } |
justinkim | 0:d4c8fe4d9b29 | 252 | } |
justinkim | 0:d4c8fe4d9b29 | 253 | return -1; |
justinkim | 0:d4c8fe4d9b29 | 254 | } |
justinkim | 0:d4c8fe4d9b29 | 255 | |
justinkim | 0:d4c8fe4d9b29 | 256 | int WIZnet_Chip::send(int socket, const char * str, int len) |
justinkim | 0:d4c8fe4d9b29 | 257 | { |
justinkim | 0:d4c8fe4d9b29 | 258 | if (socket < 0) { |
justinkim | 0:d4c8fe4d9b29 | 259 | return -1; |
justinkim | 0:d4c8fe4d9b29 | 260 | } |
justinkim | 0:d4c8fe4d9b29 | 261 | uint16_t ptr = sreg<uint16_t>(socket, Sn_TX_WR); |
justinkim | 0:d4c8fe4d9b29 | 262 | uint8_t cntl_byte = (0x14 + (socket << 5)); |
justinkim | 0:d4c8fe4d9b29 | 263 | spi_write(ptr, cntl_byte, (uint8_t*)str, len); |
justinkim | 0:d4c8fe4d9b29 | 264 | sreg<uint16_t>(socket, Sn_TX_WR, ptr + len); |
justinkim | 0:d4c8fe4d9b29 | 265 | scmd(socket, SEND); |
justinkim | 0:d4c8fe4d9b29 | 266 | uint8_t tmp_Sn_IR; |
justinkim | 0:d4c8fe4d9b29 | 267 | while (( (tmp_Sn_IR = sreg<uint8_t>(socket, Sn_IR)) & INT_SEND_OK) != INT_SEND_OK) { |
justinkim | 0:d4c8fe4d9b29 | 268 | // @Jul.10, 2014 fix contant name, and udp sendto function. |
justinkim | 0:d4c8fe4d9b29 | 269 | switch (sreg<uint8_t>(socket, Sn_SR)) { |
justinkim | 0:d4c8fe4d9b29 | 270 | case SOCK_CLOSED : |
justinkim | 0:d4c8fe4d9b29 | 271 | close(socket); |
justinkim | 0:d4c8fe4d9b29 | 272 | return 0; |
justinkim | 0:d4c8fe4d9b29 | 273 | //break; |
justinkim | 0:d4c8fe4d9b29 | 274 | case SOCK_UDP : |
justinkim | 0:d4c8fe4d9b29 | 275 | // ARP timeout is possible. |
justinkim | 0:d4c8fe4d9b29 | 276 | if ((tmp_Sn_IR & INT_TIMEOUT) == INT_TIMEOUT) { |
justinkim | 0:d4c8fe4d9b29 | 277 | sreg<uint8_t>(socket, Sn_IR, INT_TIMEOUT); |
justinkim | 0:d4c8fe4d9b29 | 278 | return 0; |
justinkim | 0:d4c8fe4d9b29 | 279 | } |
justinkim | 0:d4c8fe4d9b29 | 280 | break; |
justinkim | 0:d4c8fe4d9b29 | 281 | default : |
justinkim | 0:d4c8fe4d9b29 | 282 | break; |
justinkim | 0:d4c8fe4d9b29 | 283 | } |
justinkim | 0:d4c8fe4d9b29 | 284 | } |
justinkim | 0:d4c8fe4d9b29 | 285 | /* |
justinkim | 0:d4c8fe4d9b29 | 286 | while ((sreg<uint8_t>(socket, Sn_IR) & INT_SEND_OK) != INT_SEND_OK) { |
justinkim | 0:d4c8fe4d9b29 | 287 | if (sreg<uint8_t>(socket, Sn_SR) == CLOSED) { |
justinkim | 0:d4c8fe4d9b29 | 288 | close(socket); |
justinkim | 0:d4c8fe4d9b29 | 289 | return 0; |
justinkim | 0:d4c8fe4d9b29 | 290 | } |
justinkim | 0:d4c8fe4d9b29 | 291 | } |
justinkim | 0:d4c8fe4d9b29 | 292 | */ |
justinkim | 0:d4c8fe4d9b29 | 293 | sreg<uint8_t>(socket, Sn_IR, INT_SEND_OK); |
justinkim | 0:d4c8fe4d9b29 | 294 | |
justinkim | 0:d4c8fe4d9b29 | 295 | return len; |
justinkim | 0:d4c8fe4d9b29 | 296 | } |
justinkim | 0:d4c8fe4d9b29 | 297 | |
justinkim | 0:d4c8fe4d9b29 | 298 | int WIZnet_Chip::recv(int socket, char* buf, int len) |
justinkim | 0:d4c8fe4d9b29 | 299 | { |
justinkim | 0:d4c8fe4d9b29 | 300 | if (socket < 0) { |
justinkim | 0:d4c8fe4d9b29 | 301 | return -1; |
justinkim | 0:d4c8fe4d9b29 | 302 | } |
justinkim | 0:d4c8fe4d9b29 | 303 | uint16_t ptr = sreg<uint16_t>(socket, Sn_RX_RD); |
justinkim | 0:d4c8fe4d9b29 | 304 | uint8_t cntl_byte = (0x18 + (socket << 5)); |
justinkim | 0:d4c8fe4d9b29 | 305 | spi_read(ptr, cntl_byte, (uint8_t*)buf, len); |
justinkim | 0:d4c8fe4d9b29 | 306 | sreg<uint16_t>(socket, Sn_RX_RD, ptr + len); |
justinkim | 0:d4c8fe4d9b29 | 307 | scmd(socket, RECV); |
justinkim | 0:d4c8fe4d9b29 | 308 | return len; |
justinkim | 0:d4c8fe4d9b29 | 309 | } |
justinkim | 0:d4c8fe4d9b29 | 310 | |
justinkim | 0:d4c8fe4d9b29 | 311 | int WIZnet_Chip::new_socket() |
justinkim | 0:d4c8fe4d9b29 | 312 | { |
justinkim | 0:d4c8fe4d9b29 | 313 | for(int s = 0; s < MAX_SOCK_NUM; s++) { |
justinkim | 0:d4c8fe4d9b29 | 314 | if (sreg<uint8_t>(s, Sn_SR) == SOCK_CLOSED) { |
justinkim | 0:d4c8fe4d9b29 | 315 | return s; |
justinkim | 0:d4c8fe4d9b29 | 316 | } |
justinkim | 0:d4c8fe4d9b29 | 317 | } |
justinkim | 0:d4c8fe4d9b29 | 318 | return -1; |
justinkim | 0:d4c8fe4d9b29 | 319 | } |
justinkim | 0:d4c8fe4d9b29 | 320 | |
justinkim | 0:d4c8fe4d9b29 | 321 | uint16_t WIZnet_Chip::new_port() |
justinkim | 0:d4c8fe4d9b29 | 322 | { |
justinkim | 0:d4c8fe4d9b29 | 323 | uint16_t port = rand(); |
justinkim | 0:d4c8fe4d9b29 | 324 | port |= 49152; |
justinkim | 0:d4c8fe4d9b29 | 325 | return port; |
justinkim | 0:d4c8fe4d9b29 | 326 | } |
justinkim | 0:d4c8fe4d9b29 | 327 | |
justinkim | 0:d4c8fe4d9b29 | 328 | bool WIZnet_Chip::link(int wait_time_ms) |
justinkim | 0:d4c8fe4d9b29 | 329 | { |
justinkim | 0:d4c8fe4d9b29 | 330 | Timer t; |
justinkim | 0:d4c8fe4d9b29 | 331 | t.reset(); |
justinkim | 0:d4c8fe4d9b29 | 332 | t.start(); |
justinkim | 0:d4c8fe4d9b29 | 333 | while(1) { |
justinkim | 0:d4c8fe4d9b29 | 334 | int is_link = ethernet_link(); |
justinkim | 0:d4c8fe4d9b29 | 335 | |
justinkim | 0:d4c8fe4d9b29 | 336 | if (is_link) { |
justinkim | 0:d4c8fe4d9b29 | 337 | return true; |
justinkim | 0:d4c8fe4d9b29 | 338 | } |
justinkim | 0:d4c8fe4d9b29 | 339 | if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) { |
justinkim | 0:d4c8fe4d9b29 | 340 | break; |
justinkim | 0:d4c8fe4d9b29 | 341 | } |
justinkim | 0:d4c8fe4d9b29 | 342 | } |
justinkim | 0:d4c8fe4d9b29 | 343 | return 0; |
justinkim | 0:d4c8fe4d9b29 | 344 | } |
justinkim | 0:d4c8fe4d9b29 | 345 | |
justinkim | 0:d4c8fe4d9b29 | 346 | void WIZnet_Chip::set_link(PHYMode phymode) |
justinkim | 0:d4c8fe4d9b29 | 347 | { |
justinkim | 0:d4c8fe4d9b29 | 348 | int speed = -1; |
justinkim | 0:d4c8fe4d9b29 | 349 | int duplex = 0; |
justinkim | 0:d4c8fe4d9b29 | 350 | |
justinkim | 0:d4c8fe4d9b29 | 351 | switch(phymode) { |
justinkim | 0:d4c8fe4d9b29 | 352 | case AutoNegotiate : speed = -1; duplex = 0; break; |
justinkim | 0:d4c8fe4d9b29 | 353 | case HalfDuplex10 : speed = 0; duplex = 0; break; |
justinkim | 0:d4c8fe4d9b29 | 354 | case FullDuplex10 : speed = 0; duplex = 1; break; |
justinkim | 0:d4c8fe4d9b29 | 355 | case HalfDuplex100 : speed = 1; duplex = 0; break; |
justinkim | 0:d4c8fe4d9b29 | 356 | case FullDuplex100 : speed = 1; duplex = 1; break; |
justinkim | 0:d4c8fe4d9b29 | 357 | } |
justinkim | 0:d4c8fe4d9b29 | 358 | |
justinkim | 0:d4c8fe4d9b29 | 359 | ethernet_set_link(speed, duplex); |
justinkim | 0:d4c8fe4d9b29 | 360 | } |
justinkim | 0:d4c8fe4d9b29 | 361 | |
justinkim | 0:d4c8fe4d9b29 | 362 | void WIZnet_Chip::scmd(int socket, Command cmd) |
justinkim | 0:d4c8fe4d9b29 | 363 | { |
justinkim | 0:d4c8fe4d9b29 | 364 | sreg<uint8_t>(socket, Sn_CR, cmd); |
justinkim | 0:d4c8fe4d9b29 | 365 | while(sreg<uint8_t>(socket, Sn_CR)); |
justinkim | 0:d4c8fe4d9b29 | 366 | } |
justinkim | 0:d4c8fe4d9b29 | 367 | |
justinkim | 0:d4c8fe4d9b29 | 368 | void WIZnet_Chip::spi_write(uint16_t addr, uint8_t cb, const uint8_t *buf, uint16_t len) |
justinkim | 0:d4c8fe4d9b29 | 369 | { |
justinkim | 0:d4c8fe4d9b29 | 370 | cs = 0; |
justinkim | 0:d4c8fe4d9b29 | 371 | spi->write(addr >> 8); |
justinkim | 0:d4c8fe4d9b29 | 372 | spi->write(addr & 0xff); |
justinkim | 0:d4c8fe4d9b29 | 373 | spi->write(cb); |
justinkim | 0:d4c8fe4d9b29 | 374 | for(int i = 0; i < len; i++) { |
justinkim | 0:d4c8fe4d9b29 | 375 | spi->write(buf[i]); |
justinkim | 0:d4c8fe4d9b29 | 376 | } |
justinkim | 0:d4c8fe4d9b29 | 377 | cs = 1; |
justinkim | 0:d4c8fe4d9b29 | 378 | |
justinkim | 0:d4c8fe4d9b29 | 379 | #if DBG_SPI |
justinkim | 0:d4c8fe4d9b29 | 380 | debug("[SPI]W %04x(%02x %d)", addr, cb, len); |
justinkim | 0:d4c8fe4d9b29 | 381 | for(int i = 0; i < len; i++) { |
justinkim | 0:d4c8fe4d9b29 | 382 | debug(" %02x", buf[i]); |
justinkim | 0:d4c8fe4d9b29 | 383 | if (i > 16) { |
justinkim | 0:d4c8fe4d9b29 | 384 | debug(" ..."); |
justinkim | 0:d4c8fe4d9b29 | 385 | break; |
justinkim | 0:d4c8fe4d9b29 | 386 | } |
justinkim | 0:d4c8fe4d9b29 | 387 | } |
justinkim | 0:d4c8fe4d9b29 | 388 | debug("\r\n"); |
justinkim | 0:d4c8fe4d9b29 | 389 | #endif |
justinkim | 0:d4c8fe4d9b29 | 390 | } |
justinkim | 0:d4c8fe4d9b29 | 391 | |
justinkim | 0:d4c8fe4d9b29 | 392 | void WIZnet_Chip::spi_read(uint16_t addr, uint8_t cb, uint8_t *buf, uint16_t len) |
justinkim | 0:d4c8fe4d9b29 | 393 | { |
justinkim | 0:d4c8fe4d9b29 | 394 | cs = 0; |
justinkim | 0:d4c8fe4d9b29 | 395 | spi->write(addr >> 8); |
justinkim | 0:d4c8fe4d9b29 | 396 | spi->write(addr & 0xff); |
justinkim | 0:d4c8fe4d9b29 | 397 | spi->write(cb); |
justinkim | 0:d4c8fe4d9b29 | 398 | for(int i = 0; i < len; i++) { |
justinkim | 0:d4c8fe4d9b29 | 399 | buf[i] = spi->write(0); |
justinkim | 0:d4c8fe4d9b29 | 400 | } |
justinkim | 0:d4c8fe4d9b29 | 401 | cs = 1; |
justinkim | 0:d4c8fe4d9b29 | 402 | |
justinkim | 0:d4c8fe4d9b29 | 403 | #if DBG_SPI |
justinkim | 0:d4c8fe4d9b29 | 404 | debug("[SPI]R %04x(%02x %d)", addr, cb, len); |
justinkim | 0:d4c8fe4d9b29 | 405 | for(int i = 0; i < len; i++) { |
justinkim | 0:d4c8fe4d9b29 | 406 | debug(" %02x", buf[i]); |
justinkim | 0:d4c8fe4d9b29 | 407 | if (i > 16) { |
justinkim | 0:d4c8fe4d9b29 | 408 | debug(" ..."); |
justinkim | 0:d4c8fe4d9b29 | 409 | break; |
justinkim | 0:d4c8fe4d9b29 | 410 | } |
justinkim | 0:d4c8fe4d9b29 | 411 | } |
justinkim | 0:d4c8fe4d9b29 | 412 | debug("\r\n"); |
justinkim | 0:d4c8fe4d9b29 | 413 | if ((addr&0xf0ff)==0x4026 || (addr&0xf0ff)==0x4003) { |
justinkim | 0:d4c8fe4d9b29 | 414 | wait_ms(200); |
justinkim | 0:d4c8fe4d9b29 | 415 | } |
justinkim | 0:d4c8fe4d9b29 | 416 | #endif |
justinkim | 0:d4c8fe4d9b29 | 417 | } |
justinkim | 0:d4c8fe4d9b29 | 418 | |
justinkim | 0:d4c8fe4d9b29 | 419 | uint32_t str_to_ip(const char* str) |
justinkim | 0:d4c8fe4d9b29 | 420 | { |
justinkim | 0:d4c8fe4d9b29 | 421 | uint32_t ip = 0; |
justinkim | 0:d4c8fe4d9b29 | 422 | char* p = (char*)str; |
justinkim | 0:d4c8fe4d9b29 | 423 | for(int i = 0; i < 4; i++) { |
justinkim | 0:d4c8fe4d9b29 | 424 | ip |= atoi(p); |
justinkim | 0:d4c8fe4d9b29 | 425 | p = strchr(p, '.'); |
justinkim | 0:d4c8fe4d9b29 | 426 | if (p == NULL) { |
justinkim | 0:d4c8fe4d9b29 | 427 | break; |
justinkim | 0:d4c8fe4d9b29 | 428 | } |
justinkim | 0:d4c8fe4d9b29 | 429 | ip <<= 8; |
justinkim | 0:d4c8fe4d9b29 | 430 | p++; |
justinkim | 0:d4c8fe4d9b29 | 431 | } |
justinkim | 0:d4c8fe4d9b29 | 432 | return ip; |
justinkim | 0:d4c8fe4d9b29 | 433 | } |
justinkim | 0:d4c8fe4d9b29 | 434 | |
justinkim | 0:d4c8fe4d9b29 | 435 | void printfBytes(char* str, uint8_t* buf, int len) |
justinkim | 0:d4c8fe4d9b29 | 436 | { |
justinkim | 0:d4c8fe4d9b29 | 437 | printf("%s %d:", str, len); |
justinkim | 0:d4c8fe4d9b29 | 438 | for(int i = 0; i < len; i++) { |
justinkim | 0:d4c8fe4d9b29 | 439 | printf(" %02x", buf[i]); |
justinkim | 0:d4c8fe4d9b29 | 440 | } |
justinkim | 0:d4c8fe4d9b29 | 441 | printf("\n"); |
justinkim | 0:d4c8fe4d9b29 | 442 | } |
justinkim | 0:d4c8fe4d9b29 | 443 | |
justinkim | 0:d4c8fe4d9b29 | 444 | void printHex(uint8_t* buf, int len) |
justinkim | 0:d4c8fe4d9b29 | 445 | { |
justinkim | 0:d4c8fe4d9b29 | 446 | for(int i = 0; i < len; i++) { |
justinkim | 0:d4c8fe4d9b29 | 447 | if ((i%16) == 0) { |
justinkim | 0:d4c8fe4d9b29 | 448 | printf("%p", buf+i); |
justinkim | 0:d4c8fe4d9b29 | 449 | } |
justinkim | 0:d4c8fe4d9b29 | 450 | printf(" %02x", buf[i]); |
justinkim | 0:d4c8fe4d9b29 | 451 | if ((i%16) == 15) { |
justinkim | 0:d4c8fe4d9b29 | 452 | printf("\n"); |
justinkim | 0:d4c8fe4d9b29 | 453 | } |
justinkim | 0:d4c8fe4d9b29 | 454 | } |
justinkim | 0:d4c8fe4d9b29 | 455 | printf("\n"); |
justinkim | 0:d4c8fe4d9b29 | 456 | } |
justinkim | 0:d4c8fe4d9b29 | 457 | |
justinkim | 0:d4c8fe4d9b29 | 458 | void debug_hex(uint8_t* buf, int len) |
justinkim | 0:d4c8fe4d9b29 | 459 | { |
justinkim | 0:d4c8fe4d9b29 | 460 | for(int i = 0; i < len; i++) { |
justinkim | 0:d4c8fe4d9b29 | 461 | if ((i%16) == 0) { |
justinkim | 0:d4c8fe4d9b29 | 462 | debug("%p", buf+i); |
justinkim | 0:d4c8fe4d9b29 | 463 | } |
justinkim | 0:d4c8fe4d9b29 | 464 | debug(" %02x", buf[i]); |
justinkim | 0:d4c8fe4d9b29 | 465 | if ((i%16) == 15) { |
justinkim | 0:d4c8fe4d9b29 | 466 | debug("\n"); |
justinkim | 0:d4c8fe4d9b29 | 467 | } |
justinkim | 0:d4c8fe4d9b29 | 468 | } |
justinkim | 0:d4c8fe4d9b29 | 469 | debug("\n"); |
justinkim | 0:d4c8fe4d9b29 | 470 | } |
justinkim | 0:d4c8fe4d9b29 | 471 | |
justinkim | 0:d4c8fe4d9b29 | 472 | int WIZnet_Chip::ethernet_link(void) { |
justinkim | 0:d4c8fe4d9b29 | 473 | int val = getPHYCFGR(); |
justinkim | 0:d4c8fe4d9b29 | 474 | return (val&0x01); |
justinkim | 0:d4c8fe4d9b29 | 475 | } |
justinkim | 0:d4c8fe4d9b29 | 476 | |
justinkim | 0:d4c8fe4d9b29 | 477 | void WIZnet_Chip::ethernet_set_link(int speed, int duplex) { |
justinkim | 0:d4c8fe4d9b29 | 478 | uint32_t val=0; |
justinkim | 0:d4c8fe4d9b29 | 479 | if((speed < 0) || (speed > 1)) { |
justinkim | 0:d4c8fe4d9b29 | 480 | val = (PHYCFGR_OPMDC_ALLA)<<3; |
justinkim | 0:d4c8fe4d9b29 | 481 | } else { |
justinkim | 0:d4c8fe4d9b29 | 482 | val = (((speed&0x01)<<1)+ (duplex&0x01))<<3; |
justinkim | 0:d4c8fe4d9b29 | 483 | } |
justinkim | 0:d4c8fe4d9b29 | 484 | setPHYCFGR((uint8_t)(PHYCFGR_RST&(PHYCFGR_OPMD|val))); |
justinkim | 0:d4c8fe4d9b29 | 485 | wait(0.2); |
justinkim | 0:d4c8fe4d9b29 | 486 | setPHYCFGR((uint8_t)((~PHYCFGR_RST)|(PHYCFGR_OPMD|val))); |
justinkim | 0:d4c8fe4d9b29 | 487 | wait(0.2); |
justinkim | 0:d4c8fe4d9b29 | 488 | } |
justinkim | 0:d4c8fe4d9b29 | 489 | |
justinkim | 0:d4c8fe4d9b29 | 490 | void WIZnet_Chip::reg_rd_mac(uint16_t addr, uint8_t* data) { |
justinkim | 0:d4c8fe4d9b29 | 491 | spi_read(addr, 0x00, data, 6); |
justinkim | 0:d4c8fe4d9b29 | 492 | } |
justinkim | 0:d4c8fe4d9b29 | 493 | |
justinkim | 0:d4c8fe4d9b29 | 494 | void WIZnet_Chip::reg_wr_ip(uint16_t addr, uint8_t cb, const char* ip) { |
justinkim | 0:d4c8fe4d9b29 | 495 | uint8_t buf[4]; |
justinkim | 0:d4c8fe4d9b29 | 496 | char* p = (char*)ip; |
justinkim | 0:d4c8fe4d9b29 | 497 | for(int i = 0; i < 4; i++) { |
justinkim | 0:d4c8fe4d9b29 | 498 | buf[i] = atoi(p); |
justinkim | 0:d4c8fe4d9b29 | 499 | p = strchr(p, '.'); |
justinkim | 0:d4c8fe4d9b29 | 500 | if (p == NULL) { |
justinkim | 0:d4c8fe4d9b29 | 501 | break; |
justinkim | 0:d4c8fe4d9b29 | 502 | } |
justinkim | 0:d4c8fe4d9b29 | 503 | p++; |
justinkim | 0:d4c8fe4d9b29 | 504 | } |
justinkim | 0:d4c8fe4d9b29 | 505 | spi_write(addr, cb, buf, sizeof(buf)); |
justinkim | 0:d4c8fe4d9b29 | 506 | } |
justinkim | 0:d4c8fe4d9b29 | 507 | |
justinkim | 0:d4c8fe4d9b29 | 508 | void WIZnet_Chip::sreg_ip(int socket, uint16_t addr, const char* ip) { |
justinkim | 0:d4c8fe4d9b29 | 509 | reg_wr_ip(addr, (0x0C + (socket << 5)), ip); |
justinkim | 0:d4c8fe4d9b29 | 510 | } |
justinkim | 0:d4c8fe4d9b29 | 511 | |
justinkim | 0:d4c8fe4d9b29 | 512 | void WIZnet_Chip::reg_rd_ip_byte(uint16_t addr, uint8_t* data) { |
justinkim | 0:d4c8fe4d9b29 | 513 | spi_read(addr, 0x00, data, 4); |
justinkim | 0:d4c8fe4d9b29 | 514 | } |
justinkim | 0:d4c8fe4d9b29 | 515 | |
justinkim | 0:d4c8fe4d9b29 | 516 | void WIZnet_Chip::reg_wr_ip_byte(uint16_t addr, uint8_t* data) { |
justinkim | 0:d4c8fe4d9b29 | 517 | spi_write(addr, 0x04, data, 4); |
justinkim | 0:d4c8fe4d9b29 | 518 | } |
justinkim | 0:d4c8fe4d9b29 | 519 | |
justinkim | 0:d4c8fe4d9b29 | 520 | |
justinkim | 0:d4c8fe4d9b29 | 521 | #endif |
justinkim | 0:d4c8fe4d9b29 | 522 |