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