| 1 | /* |
|---|
| 2 | |
|---|
| 3 | @file w5100.h |
|---|
| 4 | |
|---|
| 5 | Original Author: |
|---|
| 6 | |
|---|
| 7 | WIZnet Inc. |
|---|
| 8 | |
|---|
| 9 | Modifications by: |
|---|
| 10 | |
|---|
| 11 | Philip Lindsay <follower@rancidbacon.com> |
|---|
| 12 | |
|---|
| 13 | Modifications license: |
|---|
| 14 | |
|---|
| 15 | Copyright 2007-2008 // LGPL |
|---|
| 16 | |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #ifndef _W5100_H_ |
|---|
| 20 | #define _W5100_H_ |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #define MR __DEF_IINCHIP_MAP_BASE__ |
|---|
| 24 | #define IDM_OR ((__DEF_IINCHIP_MAP_BASE__ + 0x00)) |
|---|
| 25 | #define IDM_AR0 ((__DEF_IINCHIP_MAP_BASE__ + 0x01)) |
|---|
| 26 | #define IDM_AR1 ((__DEF_IINCHIP_MAP_BASE__ + 0x02)) |
|---|
| 27 | #define IDM_DR ((__DEF_IINCHIP_MAP_BASE__ + 0x03)) |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | @brief Gateway IP Register address |
|---|
| 32 | */ |
|---|
| 33 | #define GAR0 (COMMON_BASE + 0x0001) |
|---|
| 34 | /** |
|---|
| 35 | @brief Subnet mask Register address |
|---|
| 36 | */ |
|---|
| 37 | #define SUBR0 (COMMON_BASE + 0x0005) |
|---|
| 38 | /** |
|---|
| 39 | @brief Source MAC Register address |
|---|
| 40 | */ |
|---|
| 41 | #define SHAR0 (COMMON_BASE + 0x0009) |
|---|
| 42 | /** |
|---|
| 43 | @brief Source IP Register address |
|---|
| 44 | */ |
|---|
| 45 | #define SIPR0 (COMMON_BASE + 0x000F) |
|---|
| 46 | /** |
|---|
| 47 | @brief Interrupt Register |
|---|
| 48 | */ |
|---|
| 49 | #define IR (COMMON_BASE + 0x0015) |
|---|
| 50 | /** |
|---|
| 51 | @brief Interrupt mask register |
|---|
| 52 | */ |
|---|
| 53 | #define IMR (COMMON_BASE + 0x0016) |
|---|
| 54 | /** |
|---|
| 55 | @brief Timeout register address( 1 is 100us ) |
|---|
| 56 | */ |
|---|
| 57 | #define RTR0 (COMMON_BASE + 0x0017) |
|---|
| 58 | /** |
|---|
| 59 | @brief Retry count reigster |
|---|
| 60 | */ |
|---|
| 61 | #define RCR (COMMON_BASE + 0x0019) |
|---|
| 62 | /** |
|---|
| 63 | @brief Receive memory size reigster |
|---|
| 64 | */ |
|---|
| 65 | #define RMSR (COMMON_BASE + 0x001A) |
|---|
| 66 | /** |
|---|
| 67 | @brief Transmit memory size reigster |
|---|
| 68 | */ |
|---|
| 69 | #define TMSR (COMMON_BASE + 0x001B) |
|---|
| 70 | /** |
|---|
| 71 | @brief Authentication type register address in PPPoE mode |
|---|
| 72 | */ |
|---|
| 73 | #define PATR0 (COMMON_BASE + 0x001C) |
|---|
| 74 | //#define PPPALGO (COMMON_BASE + 0x001D) |
|---|
| 75 | #define PTIMER (COMMON_BASE + 0x0028) |
|---|
| 76 | #define PMAGIC (COMMON_BASE + 0x0029) |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | @brief Unreachable IP register address in UDP mode |
|---|
| 80 | */ |
|---|
| 81 | #define UIPR0 (COMMON_BASE + 0x002A) |
|---|
| 82 | /** |
|---|
| 83 | @brief Unreachable Port register address in UDP mode |
|---|
| 84 | */ |
|---|
| 85 | #define UPORT0 (COMMON_BASE + 0x002E) |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | @brief socket register |
|---|
| 89 | */ |
|---|
| 90 | #define CH_BASE (COMMON_BASE + 0x0400) |
|---|
| 91 | /** |
|---|
| 92 | @brief size of each channel register map |
|---|
| 93 | */ |
|---|
| 94 | #define CH_SIZE 0x0100 |
|---|
| 95 | /** |
|---|
| 96 | @brief socket Mode register |
|---|
| 97 | */ |
|---|
| 98 | #define Sn_MR(ch) (CH_BASE + ch * CH_SIZE + 0x0000) |
|---|
| 99 | /** |
|---|
| 100 | @brief channel Sn_CR register |
|---|
| 101 | */ |
|---|
| 102 | #define Sn_CR(ch) (CH_BASE + ch * CH_SIZE + 0x0001) |
|---|
| 103 | /** |
|---|
| 104 | @brief channel interrupt register |
|---|
| 105 | */ |
|---|
| 106 | #define Sn_IR(ch) (CH_BASE + ch * CH_SIZE + 0x0002) |
|---|
| 107 | /** |
|---|
| 108 | @brief channel status register |
|---|
| 109 | */ |
|---|
| 110 | #define Sn_SR(ch) (CH_BASE + ch * CH_SIZE + 0x0003) |
|---|
| 111 | /** |
|---|
| 112 | @brief source port register |
|---|
| 113 | */ |
|---|
| 114 | #define Sn_PORT0(ch) (CH_BASE + ch * CH_SIZE + 0x0004) |
|---|
| 115 | /** |
|---|
| 116 | @brief Peer MAC register address |
|---|
| 117 | */ |
|---|
| 118 | #define Sn_DHAR0(ch) (CH_BASE + ch * CH_SIZE + 0x0006) |
|---|
| 119 | /** |
|---|
| 120 | @brief Peer IP register address |
|---|
| 121 | */ |
|---|
| 122 | #define Sn_DIPR0(ch) (CH_BASE + ch * CH_SIZE + 0x000C) |
|---|
| 123 | /** |
|---|
| 124 | @brief Peer port register address |
|---|
| 125 | */ |
|---|
| 126 | #define Sn_DPORT0(ch) (CH_BASE + ch * CH_SIZE + 0x0010) |
|---|
| 127 | /** |
|---|
| 128 | @brief Maximum Segment Size(Sn_MSSR0) register address |
|---|
| 129 | */ |
|---|
| 130 | #define Sn_MSSR0(ch) (CH_BASE + ch * CH_SIZE + 0x0012) |
|---|
| 131 | /** |
|---|
| 132 | @brief Protocol of IP Header field register in IP raw mode |
|---|
| 133 | */ |
|---|
| 134 | #define Sn_PROTO(ch) (CH_BASE + ch * CH_SIZE + 0x0014) |
|---|
| 135 | |
|---|
| 136 | /** |
|---|
| 137 | @brief IP Type of Service(TOS) Register |
|---|
| 138 | */ |
|---|
| 139 | #define Sn_TOS(ch) (CH_BASE + ch * CH_SIZE + 0x0015) |
|---|
| 140 | /** |
|---|
| 141 | @brief IP Time to live(TTL) Register |
|---|
| 142 | */ |
|---|
| 143 | #define Sn_TTL(ch) (CH_BASE + ch * CH_SIZE + 0x0016) |
|---|
| 144 | |
|---|
| 145 | //not support |
|---|
| 146 | //#define RX_CH_DMEM_SIZE (COMMON_BASE + 0x001E) |
|---|
| 147 | //#define TX_CH_DMEM_SIZE (COMMON_BASE + 0x001F) |
|---|
| 148 | |
|---|
| 149 | /** |
|---|
| 150 | @brief Transmit free memory size register |
|---|
| 151 | */ |
|---|
| 152 | #define Sn_TX_FSR0(ch) (CH_BASE + ch * CH_SIZE + 0x0020) |
|---|
| 153 | /** |
|---|
| 154 | @brief Transmit memory read pointer register address |
|---|
| 155 | */ |
|---|
| 156 | #define Sn_TX_RD0(ch) (CH_BASE + ch * CH_SIZE + 0x0022) |
|---|
| 157 | /** |
|---|
| 158 | @brief Transmit memory write pointer register address |
|---|
| 159 | */ |
|---|
| 160 | #define Sn_TX_WR0(ch) (CH_BASE + ch * CH_SIZE + 0x0024) |
|---|
| 161 | /** |
|---|
| 162 | @brief Received data size register |
|---|
| 163 | */ |
|---|
| 164 | #define Sn_RX_RSR0(ch) (CH_BASE + ch * CH_SIZE + 0x0026) |
|---|
| 165 | /** |
|---|
| 166 | @brief Read point of Receive memory |
|---|
| 167 | */ |
|---|
| 168 | #define Sn_RX_RD0(ch) (CH_BASE + ch * CH_SIZE + 0x0028) |
|---|
| 169 | /** |
|---|
| 170 | @brief Write point of Receive memory |
|---|
| 171 | */ |
|---|
| 172 | #define Sn_RX_WR0(ch) (CH_BASE + ch * CH_SIZE + 0x002A) |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | /* MODE register values */ |
|---|
| 177 | #define MR_RST 0x80 /**< reset */ |
|---|
| 178 | #define MR_PB 0x10 /**< ping block */ |
|---|
| 179 | #define MR_PPPOE 0x08 /**< enable pppoe */ |
|---|
| 180 | #define MR_LB 0x04 /**< little or big endian selector in indirect mode */ |
|---|
| 181 | #define MR_AI 0x02 /**< auto-increment in indirect mode */ |
|---|
| 182 | #define MR_IND 0x01 /**< enable indirect mode */ |
|---|
| 183 | |
|---|
| 184 | /* IR register values */ |
|---|
| 185 | #define IR_CONFLICT 0x80 /**< check ip confict */ |
|---|
| 186 | #define IR_UNREACH 0x40 /**< get the destination unreachable message in UDP sending */ |
|---|
| 187 | #define IR_PPPoE 0x20 /**< get the PPPoE close message */ |
|---|
| 188 | #define IR_SOCK(ch) (0x01 << ch) /**< check socket interrupt */ |
|---|
| 189 | |
|---|
| 190 | /* Sn_MR values */ |
|---|
| 191 | #define Sn_MR_CLOSE 0x00 /**< unused socket */ |
|---|
| 192 | #define Sn_MR_TCP 0x01 /**< TCP */ |
|---|
| 193 | #define Sn_MR_UDP 0x02 /**< UDP */ |
|---|
| 194 | #define Sn_MR_IPRAW 0x03 /**< IP LAYER RAW SOCK */ |
|---|
| 195 | #define Sn_MR_MACRAW 0x04 /**< MAC LAYER RAW SOCK */ |
|---|
| 196 | #define Sn_MR_PPPOE 0x05 /**< PPPoE */ |
|---|
| 197 | #define Sn_MR_ND 0x20 /**< No Delayed Ack(TCP) flag */ |
|---|
| 198 | #define Sn_MR_MULTI 0x80 /**< support multicating */ |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | /* Sn_CR values */ |
|---|
| 202 | #define Sn_CR_OPEN 0x01 /**< initialize or open socket */ |
|---|
| 203 | #define Sn_CR_LISTEN 0x02 /**< wait connection request in tcp mode(Server mode) */ |
|---|
| 204 | #define Sn_CR_CONNECT 0x04 /**< send connection request in tcp mode(Client mode) */ |
|---|
| 205 | #define Sn_CR_DISCON 0x08 /**< send closing reqeuset in tcp mode */ |
|---|
| 206 | #define Sn_CR_CLOSE 0x10 /**< close socket */ |
|---|
| 207 | #define Sn_CR_SEND 0x20 /**< updata txbuf pointer, send data */ |
|---|
| 208 | #define Sn_CR_SEND_MAC 0x21 /**< send data with MAC address, so without ARP process */ |
|---|
| 209 | #define Sn_CR_SEND_KEEP 0x22 /**< send keep alive message */ |
|---|
| 210 | #define Sn_CR_RECV 0x40 /**< update rxbuf pointer, recv data */ |
|---|
| 211 | |
|---|
| 212 | #ifdef __DEF_IINCHIP_PPP__ |
|---|
| 213 | #define Sn_CR_PCON 0x23 |
|---|
| 214 | #define Sn_CR_PDISCON 0x24 |
|---|
| 215 | #define Sn_CR_PCR 0x25 |
|---|
| 216 | #define Sn_CR_PCN 0x26 |
|---|
| 217 | #define Sn_CR_PCJ 0x27 |
|---|
| 218 | #endif |
|---|
| 219 | |
|---|
| 220 | /* Sn_IR values */ |
|---|
| 221 | #ifdef __DEF_IINCHIP_PPP__ |
|---|
| 222 | #define Sn_IR_PRECV 0x80 |
|---|
| 223 | #define Sn_IR_PFAIL 0x40 |
|---|
| 224 | #define Sn_IR_PNEXT 0x20 |
|---|
| 225 | #endif |
|---|
| 226 | #define Sn_IR_SEND_OK 0x10 /**< complete sending */ |
|---|
| 227 | #define Sn_IR_TIMEOUT 0x08 /**< assert timeout */ |
|---|
| 228 | #define Sn_IR_RECV 0x04 /**< receiving data */ |
|---|
| 229 | #define Sn_IR_DISCON 0x02 /**< closed socket */ |
|---|
| 230 | #define Sn_IR_CON 0x01 /**< established connection */ |
|---|
| 231 | |
|---|
| 232 | /* Sn_SR values */ |
|---|
| 233 | #define SOCK_CLOSED 0x00 /**< closed */ |
|---|
| 234 | #define SOCK_INIT 0x13 /**< init state */ |
|---|
| 235 | #define SOCK_LISTEN 0x14 /**< listen state */ |
|---|
| 236 | #define SOCK_SYNSENT 0x15 /**< connection state */ |
|---|
| 237 | #define SOCK_SYNRECV 0x16 /**< connection state */ |
|---|
| 238 | #define SOCK_ESTABLISHED 0x17 /**< success to connect */ |
|---|
| 239 | #define SOCK_FIN_WAIT 0x18 /**< closing state */ |
|---|
| 240 | #define SOCK_CLOSING 0x1A /**< closing state */ |
|---|
| 241 | #define SOCK_TIME_WAIT 0x1B /**< closing state */ |
|---|
| 242 | #define SOCK_CLOSE_WAIT 0x1C /**< closing state */ |
|---|
| 243 | #define SOCK_LAST_ACK 0x1D /**< closing state */ |
|---|
| 244 | #define SOCK_UDP 0x22 /**< udp socket */ |
|---|
| 245 | #define SOCK_IPRAW 0x32 /**< ip raw mode socket */ |
|---|
| 246 | #define SOCK_MACRAW 0x42 /**< mac raw mode socket */ |
|---|
| 247 | #define SOCK_PPPOE 0x5F /**< pppoe socket */ |
|---|
| 248 | |
|---|
| 249 | /* IP PROTOCOL */ |
|---|
| 250 | #define IPPROTO_IP 0 /**< Dummy for IP */ |
|---|
| 251 | #define IPPROTO_ICMP 1 /**< Control message protocol */ |
|---|
| 252 | #define IPPROTO_IGMP 2 /**< Internet group management protocol */ |
|---|
| 253 | #define IPPROTO_GGP 3 /**< Gateway^2 (deprecated) */ |
|---|
| 254 | #define IPPROTO_TCP 6 /**< TCP */ |
|---|
| 255 | #define IPPROTO_PUP 12 /**< PUP */ |
|---|
| 256 | #define IPPROTO_UDP 17 /**< UDP */ |
|---|
| 257 | #define IPPROTO_IDP 22 /**< XNS idp */ |
|---|
| 258 | #define IPPROTO_ND 77 /**< UNOFFICIAL net disk protocol */ |
|---|
| 259 | #define IPPROTO_RAW 255 /**< Raw IP packet */ |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | /********************************************************* |
|---|
| 263 | * iinchip access function |
|---|
| 264 | *********************************************************/ |
|---|
| 265 | |
|---|
| 266 | #ifdef __cplusplus |
|---|
| 267 | extern "C" { |
|---|
| 268 | #endif |
|---|
| 269 | |
|---|
| 270 | extern uint8 IINCHIP_READ(uint16 addr); |
|---|
| 271 | extern uint8 IINCHIP_WRITE(uint16 addr,uint8 data); |
|---|
| 272 | extern uint16 wiz_read_buf(uint16 addr, uint8* buf,uint16 len); |
|---|
| 273 | extern uint16 wiz_write_buf(uint16 addr,uint8* buf,uint16 len); |
|---|
| 274 | |
|---|
| 275 | extern void iinchip_init(void); // reset iinchip |
|---|
| 276 | extern void sysinit(uint8 tx_size, uint8 rx_size); // setting tx/rx buf size |
|---|
| 277 | extern uint8 getISR(uint8 s); |
|---|
| 278 | extern void putISR(uint8 s, uint8 val); |
|---|
| 279 | extern uint16 getIINCHIP_RxMAX(uint8 s); |
|---|
| 280 | extern uint16 getIINCHIP_TxMAX(uint8 s); |
|---|
| 281 | extern uint16 getIINCHIP_RxMASK(uint8 s); |
|---|
| 282 | extern uint16 getIINCHIP_TxMASK(uint8 s); |
|---|
| 283 | extern uint16 getIINCHIP_RxBASE(uint8 s); |
|---|
| 284 | extern uint16 getIINCHIP_TxBASE(uint8 s); |
|---|
| 285 | extern void setGAR(uint8 * addr); // set gateway address |
|---|
| 286 | extern void setSUBR(uint8 * addr); // set subnet mask address |
|---|
| 287 | extern void setSHAR(uint8 * addr); // set local MAC address |
|---|
| 288 | extern void setSIPR(uint8 * addr); // set local IP address |
|---|
| 289 | extern void setRTR(uint16 timeout); // set retry duration for data transmission, connection, closing ... |
|---|
| 290 | extern void setRCR(uint8 retry); // set retry count (above the value, assert timeout interrupt) |
|---|
| 291 | extern void setIMR(uint8 mask); // set interrupt mask. |
|---|
| 292 | extern void getGAR(uint8 * addr); |
|---|
| 293 | extern void getSUBR(uint8 * addr); |
|---|
| 294 | extern void getSHAR(uint8 * addr); |
|---|
| 295 | extern void getSIPR(uint8 * addr); |
|---|
| 296 | extern uint8 getIR( void ); |
|---|
| 297 | extern void setSn_MSS(SOCKET s, uint16 Sn_MSSR0); // set maximum segment size |
|---|
| 298 | extern void setSn_PROTO(SOCKET s, uint8 proto); // set IP Protocol value using IP-Raw mode |
|---|
| 299 | extern uint8 getSn_IR(SOCKET s); // get socket interrupt status |
|---|
| 300 | extern uint8 getSn_SR(SOCKET s); // get socket status |
|---|
| 301 | extern uint16 getSn_TX_FSR(SOCKET s); // get socket TX free buf size |
|---|
| 302 | extern uint16 getSn_RX_RSR(SOCKET s); // get socket RX recv buf size |
|---|
| 303 | extern void setSn_DHAR(SOCKET s, uint8 * addr); |
|---|
| 304 | extern void setSn_DIPR(SOCKET s, uint8 * addr); |
|---|
| 305 | extern void setSn_DPORT(SOCKET s, uint8 * addr); |
|---|
| 306 | extern void getSn_DHAR(SOCKET s, uint8 * addr); |
|---|
| 307 | extern void getSn_DIPR(SOCKET s, uint8 * addr); |
|---|
| 308 | extern void getSn_DPORT(SOCKET s, uint8 * addr); |
|---|
| 309 | extern void setSn_TTL(SOCKET s, uint8 ttl); |
|---|
| 310 | extern void setMR(uint8 val); |
|---|
| 311 | |
|---|
| 312 | #ifdef __DEF_IINCHIP_PPP__ |
|---|
| 313 | extern uint8 pppinit(uint8 *id, uint8 idlen, uint8 *passwd, uint8 passwdlen); |
|---|
| 314 | extern uint8 pppterm(uint8 *mac,uint8 *sessionid); |
|---|
| 315 | #endif |
|---|
| 316 | |
|---|
| 317 | extern void send_data_processing(SOCKET s, uint8 *data, uint16 len); |
|---|
| 318 | extern void recv_data_processing(SOCKET s, uint8 *data, uint16 len); |
|---|
| 319 | extern void read_data(SOCKET s, vuint8 * src, vuint8 * dst, uint16 len); |
|---|
| 320 | extern void write_data(SOCKET s, vuint8 * src, vuint8 * dst, uint16 len); |
|---|
| 321 | |
|---|
| 322 | #ifdef __cplusplus |
|---|
| 323 | } // extern "C" |
|---|
| 324 | #endif |
|---|
| 325 | |
|---|
| 326 | #endif |
|---|