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/int/W7500x_toe.h@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 | */ |
justinkim | 0:d4c8fe4d9b29 | 19 | #pragma once |
justinkim | 0:d4c8fe4d9b29 | 20 | |
justinkim | 0:d4c8fe4d9b29 | 21 | #include "mbed.h" |
justinkim | 0:d4c8fe4d9b29 | 22 | #include "mbed_debug.h" |
justinkim | 0:d4c8fe4d9b29 | 23 | |
justinkim | 0:d4c8fe4d9b29 | 24 | #define TEST_ASSERT(A) while(!(A)){debug("\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; |
justinkim | 0:d4c8fe4d9b29 | 25 | |
justinkim | 0:d4c8fe4d9b29 | 26 | #define DEFAULT_WAIT_RESP_TIMEOUT 500 |
justinkim | 0:d4c8fe4d9b29 | 27 | |
justinkim | 0:d4c8fe4d9b29 | 28 | |
justinkim | 0:d4c8fe4d9b29 | 29 | #define MAX_SOCK_NUM 8 |
justinkim | 0:d4c8fe4d9b29 | 30 | |
justinkim | 0:d4c8fe4d9b29 | 31 | // Peripheral base address |
justinkim | 0:d4c8fe4d9b29 | 32 | #define W7500x_WZTOE_BASE (0x46000000) |
justinkim | 0:d4c8fe4d9b29 | 33 | #define W7500x_TXMEM_BASE (W7500x_WZTOE_BASE + 0x00020000) |
justinkim | 0:d4c8fe4d9b29 | 34 | #define W7500x_RXMEM_BASE (W7500x_WZTOE_BASE + 0x00030000) |
justinkim | 0:d4c8fe4d9b29 | 35 | // Common register |
justinkim | 0:d4c8fe4d9b29 | 36 | #define MR (0x2300) |
justinkim | 0:d4c8fe4d9b29 | 37 | #define GAR (0x6008) |
justinkim | 0:d4c8fe4d9b29 | 38 | #define SUBR (0x600C) |
justinkim | 0:d4c8fe4d9b29 | 39 | #define SHAR (0x6000) |
justinkim | 0:d4c8fe4d9b29 | 40 | #define SIPR (0x6010) |
justinkim | 0:d4c8fe4d9b29 | 41 | |
justinkim | 0:d4c8fe4d9b29 | 42 | // Added Common register @W7500 |
justinkim | 0:d4c8fe4d9b29 | 43 | #define TIC100US (0x2000) |
justinkim | 0:d4c8fe4d9b29 | 44 | |
justinkim | 0:d4c8fe4d9b29 | 45 | // Socket register |
justinkim | 0:d4c8fe4d9b29 | 46 | #define Sn_MR (0x0000) |
justinkim | 0:d4c8fe4d9b29 | 47 | #define Sn_CR (0x0010) |
justinkim | 0:d4c8fe4d9b29 | 48 | #define Sn_IR (0x0020) //--Sn_ISR |
justinkim | 0:d4c8fe4d9b29 | 49 | #define Sn_SR (0x0030) |
justinkim | 0:d4c8fe4d9b29 | 50 | #define Sn_PORT (0x0114) |
justinkim | 0:d4c8fe4d9b29 | 51 | #define Sn_DIPR (0x0124) |
justinkim | 0:d4c8fe4d9b29 | 52 | #define Sn_DPORT (0x0120) |
justinkim | 0:d4c8fe4d9b29 | 53 | #define Sn_RXBUF_SIZE (0x0200) |
justinkim | 0:d4c8fe4d9b29 | 54 | #define Sn_TXBUF_SIZE (0x0220) |
justinkim | 0:d4c8fe4d9b29 | 55 | #define Sn_TX_FSR (0x0204) |
justinkim | 0:d4c8fe4d9b29 | 56 | #define Sn_TX_WR (0x020C) |
justinkim | 0:d4c8fe4d9b29 | 57 | #define Sn_RX_RSR (0x0224) |
justinkim | 0:d4c8fe4d9b29 | 58 | #define Sn_RX_RD (0x0228) |
justinkim | 0:d4c8fe4d9b29 | 59 | // added Socket register @W7500 |
justinkim | 0:d4c8fe4d9b29 | 60 | #define Sn_ICR (0x0028) |
justinkim | 0:d4c8fe4d9b29 | 61 | enum PHYMode { |
justinkim | 0:d4c8fe4d9b29 | 62 | AutoNegotiate = 0, |
justinkim | 0:d4c8fe4d9b29 | 63 | HalfDuplex10 = 1, |
justinkim | 0:d4c8fe4d9b29 | 64 | FullDuplex10 = 2, |
justinkim | 0:d4c8fe4d9b29 | 65 | HalfDuplex100 = 3, |
justinkim | 0:d4c8fe4d9b29 | 66 | FullDuplex100 = 4, |
justinkim | 0:d4c8fe4d9b29 | 67 | }; |
justinkim | 0:d4c8fe4d9b29 | 68 | |
justinkim | 0:d4c8fe4d9b29 | 69 | //bool plink(int wait_time_ms= 3*1000); |
justinkim | 0:d4c8fe4d9b29 | 70 | |
justinkim | 0:d4c8fe4d9b29 | 71 | class WIZnet_Chip { |
justinkim | 0:d4c8fe4d9b29 | 72 | public: |
justinkim | 0:d4c8fe4d9b29 | 73 | enum Protocol { |
justinkim | 0:d4c8fe4d9b29 | 74 | CLOSED = 0, |
justinkim | 0:d4c8fe4d9b29 | 75 | TCP = 1, |
justinkim | 0:d4c8fe4d9b29 | 76 | UDP = 2, |
justinkim | 0:d4c8fe4d9b29 | 77 | }; |
justinkim | 0:d4c8fe4d9b29 | 78 | |
justinkim | 0:d4c8fe4d9b29 | 79 | enum Command { |
justinkim | 0:d4c8fe4d9b29 | 80 | OPEN = 0x01, |
justinkim | 0:d4c8fe4d9b29 | 81 | LISTEN = 0x02, |
justinkim | 0:d4c8fe4d9b29 | 82 | CONNECT = 0x04, |
justinkim | 0:d4c8fe4d9b29 | 83 | DISCON = 0x08, |
justinkim | 0:d4c8fe4d9b29 | 84 | CLOSE = 0x10, |
justinkim | 0:d4c8fe4d9b29 | 85 | SEND = 0x20, |
justinkim | 0:d4c8fe4d9b29 | 86 | SEND_MAC = 0x21, |
justinkim | 0:d4c8fe4d9b29 | 87 | SEND_KEEP = 0x22, |
justinkim | 0:d4c8fe4d9b29 | 88 | RECV = 0x40, |
justinkim | 0:d4c8fe4d9b29 | 89 | |
justinkim | 0:d4c8fe4d9b29 | 90 | }; |
justinkim | 0:d4c8fe4d9b29 | 91 | |
justinkim | 0:d4c8fe4d9b29 | 92 | enum Interrupt { |
justinkim | 0:d4c8fe4d9b29 | 93 | INT_CON = 0x01, |
justinkim | 0:d4c8fe4d9b29 | 94 | INT_DISCON = 0x02, |
justinkim | 0:d4c8fe4d9b29 | 95 | INT_RECV = 0x04, |
justinkim | 0:d4c8fe4d9b29 | 96 | INT_TIMEOUT = 0x08, |
justinkim | 0:d4c8fe4d9b29 | 97 | INT_SEND_OK = 0x10, |
justinkim | 0:d4c8fe4d9b29 | 98 | }; |
justinkim | 0:d4c8fe4d9b29 | 99 | enum Status { |
justinkim | 0:d4c8fe4d9b29 | 100 | SOCK_CLOSED = 0x00, |
justinkim | 0:d4c8fe4d9b29 | 101 | SOCK_INIT = 0x13, |
justinkim | 0:d4c8fe4d9b29 | 102 | SOCK_LISTEN = 0x14, |
justinkim | 0:d4c8fe4d9b29 | 103 | SOCK_SYNSENT = 0x15, |
justinkim | 0:d4c8fe4d9b29 | 104 | SOCK_ESTABLISHED = 0x17, |
justinkim | 0:d4c8fe4d9b29 | 105 | SOCK_CLOSE_WAIT = 0x1c, |
justinkim | 0:d4c8fe4d9b29 | 106 | SOCK_UDP = 0x22, |
justinkim | 0:d4c8fe4d9b29 | 107 | }; |
justinkim | 0:d4c8fe4d9b29 | 108 | enum Mode { |
justinkim | 0:d4c8fe4d9b29 | 109 | MR_RST = 0x80, |
justinkim | 0:d4c8fe4d9b29 | 110 | MR_WOL = 0x20, |
justinkim | 0:d4c8fe4d9b29 | 111 | MR_PB = 0x10, |
justinkim | 0:d4c8fe4d9b29 | 112 | MR_FARP = 0x02, |
justinkim | 0:d4c8fe4d9b29 | 113 | }; |
justinkim | 0:d4c8fe4d9b29 | 114 | |
justinkim | 0:d4c8fe4d9b29 | 115 | WIZnet_Chip(); |
justinkim | 0:d4c8fe4d9b29 | 116 | |
justinkim | 0:d4c8fe4d9b29 | 117 | /* |
justinkim | 0:d4c8fe4d9b29 | 118 | * Set MAC Address to W7500x_TOE |
justinkim | 0:d4c8fe4d9b29 | 119 | * |
justinkim | 0:d4c8fe4d9b29 | 120 | * @return true if connected, false otherwise |
justinkim | 0:d4c8fe4d9b29 | 121 | */ |
justinkim | 0:d4c8fe4d9b29 | 122 | bool setmac(); |
justinkim | 0:d4c8fe4d9b29 | 123 | |
justinkim | 0:d4c8fe4d9b29 | 124 | /* |
justinkim | 0:d4c8fe4d9b29 | 125 | * Connect the W7500 WZTOE to the ssid contained in the constructor. |
justinkim | 0:d4c8fe4d9b29 | 126 | * |
justinkim | 0:d4c8fe4d9b29 | 127 | * @return true if connected, false otherwise |
justinkim | 0:d4c8fe4d9b29 | 128 | */ |
justinkim | 0:d4c8fe4d9b29 | 129 | bool setip(); |
justinkim | 0:d4c8fe4d9b29 | 130 | |
justinkim | 0:d4c8fe4d9b29 | 131 | |
justinkim | 0:d4c8fe4d9b29 | 132 | /* |
justinkim | 0:d4c8fe4d9b29 | 133 | * Open a tcp connection with the specified host on the specified port |
justinkim | 0:d4c8fe4d9b29 | 134 | * |
justinkim | 0:d4c8fe4d9b29 | 135 | * @param host host (can be either an ip address or a name. If a name is provided, a dns request will be established) |
justinkim | 0:d4c8fe4d9b29 | 136 | * @param port port |
justinkim | 0:d4c8fe4d9b29 | 137 | * @ returns true if successful |
justinkim | 0:d4c8fe4d9b29 | 138 | */ |
justinkim | 0:d4c8fe4d9b29 | 139 | bool connect(int socket, const char * host, int port, int timeout_ms = 10*1000); |
justinkim | 0:d4c8fe4d9b29 | 140 | |
justinkim | 0:d4c8fe4d9b29 | 141 | /* |
justinkim | 0:d4c8fe4d9b29 | 142 | * Set the protocol (UDP or TCP) |
justinkim | 0:d4c8fe4d9b29 | 143 | * |
justinkim | 0:d4c8fe4d9b29 | 144 | * @param p protocol |
justinkim | 0:d4c8fe4d9b29 | 145 | * @ returns true if successful |
justinkim | 0:d4c8fe4d9b29 | 146 | */ |
justinkim | 0:d4c8fe4d9b29 | 147 | bool setProtocol(int socket, Protocol p); |
justinkim | 0:d4c8fe4d9b29 | 148 | |
justinkim | 0:d4c8fe4d9b29 | 149 | /* |
justinkim | 0:d4c8fe4d9b29 | 150 | * Reset the W7500 WZTOE |
justinkim | 0:d4c8fe4d9b29 | 151 | */ |
justinkim | 0:d4c8fe4d9b29 | 152 | void reset(); |
justinkim | 0:d4c8fe4d9b29 | 153 | |
justinkim | 0:d4c8fe4d9b29 | 154 | int wait_readable(int socket, int wait_time_ms, int req_size = 0); |
justinkim | 0:d4c8fe4d9b29 | 155 | |
justinkim | 0:d4c8fe4d9b29 | 156 | int wait_writeable(int socket, int wait_time_ms, int req_size = 0); |
justinkim | 0:d4c8fe4d9b29 | 157 | |
justinkim | 0:d4c8fe4d9b29 | 158 | /* |
justinkim | 0:d4c8fe4d9b29 | 159 | * Check if an ethernet link is pressent or not. |
justinkim | 0:d4c8fe4d9b29 | 160 | * |
justinkim | 0:d4c8fe4d9b29 | 161 | * @returns true if successful |
justinkim | 0:d4c8fe4d9b29 | 162 | */ |
justinkim | 0:d4c8fe4d9b29 | 163 | bool link(int wait_time_ms= 3*1000); |
justinkim | 0:d4c8fe4d9b29 | 164 | |
justinkim | 0:d4c8fe4d9b29 | 165 | /* |
justinkim | 0:d4c8fe4d9b29 | 166 | * Sets the speed and duplex parameters of an ethernet link. |
justinkim | 0:d4c8fe4d9b29 | 167 | * |
justinkim | 0:d4c8fe4d9b29 | 168 | * @returns true if successful |
justinkim | 0:d4c8fe4d9b29 | 169 | */ |
justinkim | 0:d4c8fe4d9b29 | 170 | void set_link(PHYMode phymode); |
justinkim | 0:d4c8fe4d9b29 | 171 | |
justinkim | 0:d4c8fe4d9b29 | 172 | /* |
justinkim | 0:d4c8fe4d9b29 | 173 | * Check if a tcp link is active |
justinkim | 0:d4c8fe4d9b29 | 174 | * |
justinkim | 0:d4c8fe4d9b29 | 175 | * @returns true if successful |
justinkim | 0:d4c8fe4d9b29 | 176 | */ |
justinkim | 0:d4c8fe4d9b29 | 177 | bool is_connected(int socket); |
justinkim | 0:d4c8fe4d9b29 | 178 | |
justinkim | 0:d4c8fe4d9b29 | 179 | /* |
justinkim | 0:d4c8fe4d9b29 | 180 | * Close a tcp connection |
justinkim | 0:d4c8fe4d9b29 | 181 | * |
justinkim | 0:d4c8fe4d9b29 | 182 | * @ returns true if successful |
justinkim | 0:d4c8fe4d9b29 | 183 | */ |
justinkim | 0:d4c8fe4d9b29 | 184 | bool close(int socket); |
justinkim | 0:d4c8fe4d9b29 | 185 | |
justinkim | 0:d4c8fe4d9b29 | 186 | /* |
justinkim | 0:d4c8fe4d9b29 | 187 | * @param str string to be sent |
justinkim | 0:d4c8fe4d9b29 | 188 | * @param len string length |
justinkim | 0:d4c8fe4d9b29 | 189 | */ |
justinkim | 0:d4c8fe4d9b29 | 190 | int send(int socket, const char * str, int len); |
justinkim | 0:d4c8fe4d9b29 | 191 | |
justinkim | 0:d4c8fe4d9b29 | 192 | int recv(int socket, char* buf, int len); |
justinkim | 0:d4c8fe4d9b29 | 193 | |
justinkim | 0:d4c8fe4d9b29 | 194 | /* |
justinkim | 0:d4c8fe4d9b29 | 195 | * Return true if the module is using dhcp |
justinkim | 0:d4c8fe4d9b29 | 196 | * |
justinkim | 0:d4c8fe4d9b29 | 197 | * @returns true if the module is using dhcp |
justinkim | 0:d4c8fe4d9b29 | 198 | */ |
justinkim | 0:d4c8fe4d9b29 | 199 | bool isDHCP() { |
justinkim | 0:d4c8fe4d9b29 | 200 | return dhcp; |
justinkim | 0:d4c8fe4d9b29 | 201 | } |
justinkim | 0:d4c8fe4d9b29 | 202 | |
justinkim | 0:d4c8fe4d9b29 | 203 | bool gethostbyname(const char* host, uint32_t* ip); |
justinkim | 0:d4c8fe4d9b29 | 204 | |
justinkim | 0:d4c8fe4d9b29 | 205 | static WIZnet_Chip * getInstance() { |
justinkim | 0:d4c8fe4d9b29 | 206 | return inst; |
justinkim | 0:d4c8fe4d9b29 | 207 | }; |
justinkim | 0:d4c8fe4d9b29 | 208 | |
justinkim | 0:d4c8fe4d9b29 | 209 | int new_socket(); |
justinkim | 0:d4c8fe4d9b29 | 210 | uint16_t new_port(); |
justinkim | 0:d4c8fe4d9b29 | 211 | |
justinkim | 0:d4c8fe4d9b29 | 212 | void scmd(int socket, Command cmd); |
justinkim | 0:d4c8fe4d9b29 | 213 | |
justinkim | 0:d4c8fe4d9b29 | 214 | template<typename T> |
justinkim | 0:d4c8fe4d9b29 | 215 | void sreg(int socket, uint16_t addr, T data) { |
justinkim | 0:d4c8fe4d9b29 | 216 | reg_wr<T>(addr, (uint8_t)(0x01+(socket<<2)), data); |
justinkim | 0:d4c8fe4d9b29 | 217 | } |
justinkim | 0:d4c8fe4d9b29 | 218 | |
justinkim | 0:d4c8fe4d9b29 | 219 | template<typename T> |
justinkim | 0:d4c8fe4d9b29 | 220 | T sreg(int socket, uint16_t addr) { |
justinkim | 0:d4c8fe4d9b29 | 221 | return reg_rd<T>(addr, (uint8_t)(0x01+(socket<<2))); |
justinkim | 0:d4c8fe4d9b29 | 222 | } |
justinkim | 0:d4c8fe4d9b29 | 223 | |
justinkim | 0:d4c8fe4d9b29 | 224 | template<typename T> |
justinkim | 0:d4c8fe4d9b29 | 225 | void reg_wr(uint16_t addr, T data) { |
justinkim | 0:d4c8fe4d9b29 | 226 | return reg_wr(addr, 0x00, data); |
justinkim | 0:d4c8fe4d9b29 | 227 | } |
justinkim | 0:d4c8fe4d9b29 | 228 | |
justinkim | 0:d4c8fe4d9b29 | 229 | template<typename T> |
justinkim | 0:d4c8fe4d9b29 | 230 | void reg_wr(uint16_t addr, uint8_t cb, T data) { |
justinkim | 0:d4c8fe4d9b29 | 231 | uint8_t buf[sizeof(T)]; |
justinkim | 0:d4c8fe4d9b29 | 232 | *reinterpret_cast<T*>(buf) = data; |
justinkim | 0:d4c8fe4d9b29 | 233 | /* |
justinkim | 0:d4c8fe4d9b29 | 234 | for(int i = 0; i < sizeof(buf)/2; i++) { // Little Endian to Big Endian |
justinkim | 0:d4c8fe4d9b29 | 235 | uint8_t t = buf[i]; |
justinkim | 0:d4c8fe4d9b29 | 236 | buf[i] = buf[sizeof(buf)-1-i]; |
justinkim | 0:d4c8fe4d9b29 | 237 | buf[sizeof(buf)-1-i] = t; |
justinkim | 0:d4c8fe4d9b29 | 238 | } |
justinkim | 0:d4c8fe4d9b29 | 239 | */ |
justinkim | 0:d4c8fe4d9b29 | 240 | for(int i = 0; i < sizeof(buf); i++) { // Little Endian to Big Endian |
justinkim | 0:d4c8fe4d9b29 | 241 | *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)((cb<<16)+addr)+i) = buf[i]; |
justinkim | 0:d4c8fe4d9b29 | 242 | } |
justinkim | 0:d4c8fe4d9b29 | 243 | } |
justinkim | 0:d4c8fe4d9b29 | 244 | |
justinkim | 0:d4c8fe4d9b29 | 245 | template<typename T> |
justinkim | 0:d4c8fe4d9b29 | 246 | T reg_rd(uint16_t addr) { |
justinkim | 0:d4c8fe4d9b29 | 247 | return reg_rd<T>(addr, (uint8_t)(0x00)); |
justinkim | 0:d4c8fe4d9b29 | 248 | } |
justinkim | 0:d4c8fe4d9b29 | 249 | |
justinkim | 0:d4c8fe4d9b29 | 250 | template<typename T> |
justinkim | 0:d4c8fe4d9b29 | 251 | T reg_rd(uint16_t addr, uint8_t cb) { |
justinkim | 0:d4c8fe4d9b29 | 252 | uint8_t buf[sizeof(T)] = {0,}; |
justinkim | 0:d4c8fe4d9b29 | 253 | for(int i = 0; i < sizeof(buf); i++) { // Little Endian to Big Endian |
justinkim | 0:d4c8fe4d9b29 | 254 | buf[i] = *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)((cb<<16)+addr)+i); |
justinkim | 0:d4c8fe4d9b29 | 255 | } |
justinkim | 0:d4c8fe4d9b29 | 256 | /* |
justinkim | 0:d4c8fe4d9b29 | 257 | for(int i = 0; i < sizeof(buf)/2; i++) { // Big Endian to Little Endian |
justinkim | 0:d4c8fe4d9b29 | 258 | uint8_t t = buf[i]; |
justinkim | 0:d4c8fe4d9b29 | 259 | buf[i] = buf[sizeof(buf)-1-i]; |
justinkim | 0:d4c8fe4d9b29 | 260 | buf[sizeof(buf)-1-i] = t; |
justinkim | 0:d4c8fe4d9b29 | 261 | } |
justinkim | 0:d4c8fe4d9b29 | 262 | */ |
justinkim | 0:d4c8fe4d9b29 | 263 | return *reinterpret_cast<T*>(buf); |
justinkim | 0:d4c8fe4d9b29 | 264 | } |
justinkim | 0:d4c8fe4d9b29 | 265 | |
justinkim | 0:d4c8fe4d9b29 | 266 | void reg_rd_mac(uint16_t addr, uint8_t* data); |
justinkim | 0:d4c8fe4d9b29 | 267 | |
justinkim | 0:d4c8fe4d9b29 | 268 | void reg_wr_ip(uint16_t addr, uint8_t cb, const char* ip); |
justinkim | 0:d4c8fe4d9b29 | 269 | |
justinkim | 0:d4c8fe4d9b29 | 270 | void sreg_ip(int socket, uint16_t addr, const char* ip); |
justinkim | 0:d4c8fe4d9b29 | 271 | |
justinkim | 0:d4c8fe4d9b29 | 272 | int ethernet_link(void); |
justinkim | 0:d4c8fe4d9b29 | 273 | |
justinkim | 0:d4c8fe4d9b29 | 274 | void ethernet_set_link(int speed, int duplex); |
justinkim | 0:d4c8fe4d9b29 | 275 | |
justinkim | 0:d4c8fe4d9b29 | 276 | |
justinkim | 0:d4c8fe4d9b29 | 277 | protected: |
justinkim | 0:d4c8fe4d9b29 | 278 | uint8_t mac[6]; |
justinkim | 0:d4c8fe4d9b29 | 279 | uint32_t ip; |
justinkim | 0:d4c8fe4d9b29 | 280 | uint32_t netmask; |
justinkim | 0:d4c8fe4d9b29 | 281 | uint32_t gateway; |
justinkim | 0:d4c8fe4d9b29 | 282 | uint32_t dnsaddr; |
justinkim | 0:d4c8fe4d9b29 | 283 | bool dhcp; |
justinkim | 0:d4c8fe4d9b29 | 284 | |
justinkim | 0:d4c8fe4d9b29 | 285 | static WIZnet_Chip* inst; |
justinkim | 0:d4c8fe4d9b29 | 286 | |
justinkim | 0:d4c8fe4d9b29 | 287 | void reg_wr_mac(uint16_t addr, uint8_t* data) { |
justinkim | 0:d4c8fe4d9b29 | 288 | *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+3)) = data[0] ; |
justinkim | 0:d4c8fe4d9b29 | 289 | *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+2)) = data[1] ; |
justinkim | 0:d4c8fe4d9b29 | 290 | *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+1)) = data[2] ; |
justinkim | 0:d4c8fe4d9b29 | 291 | *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+0)) = data[3] ; |
justinkim | 0:d4c8fe4d9b29 | 292 | *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+7)) = data[4] ; |
justinkim | 0:d4c8fe4d9b29 | 293 | *(volatile uint8_t *)(W7500x_WZTOE_BASE + (uint32_t)(addr+6)) = data[5] ; |
justinkim | 0:d4c8fe4d9b29 | 294 | } |
justinkim | 0:d4c8fe4d9b29 | 295 | }; |
justinkim | 0:d4c8fe4d9b29 | 296 | |
justinkim | 0:d4c8fe4d9b29 | 297 | extern uint32_t str_to_ip(const char* str); |
justinkim | 0:d4c8fe4d9b29 | 298 | extern void printfBytes(char* str, uint8_t* buf, int len); |
justinkim | 0:d4c8fe4d9b29 | 299 | extern void printHex(uint8_t* buf, int len); |
justinkim | 0:d4c8fe4d9b29 | 300 | extern void debug_hex(uint8_t* buf, int len); |