WIZlib Library API  ver 1.0
WIZlib Library API User Menual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
w5200.h
Go to the documentation of this file.
1 
13 #ifndef _W5200_H
14 #define _W5200_H
15 
16 //#include "common/common.h"
17 
18 #define WIZ_COMMON_BASE 0x0000
19 #define __DEF_IINCHIP_MAP_BASE__ 0x0000
20 #define __DEF_IINCHIP_MAP_TXBUF__ (WIZ_COMMON_BASE + 0x8000) /* Internal Tx buffer address of the iinchip */
21 #define __DEF_IINCHIP_MAP_RXBUF__ (WIZ_COMMON_BASE + 0xC000) /* Internal Rx buffer address of the iinchip */
22 
23 #define IINCHIP_ISR_DISABLE()
24 #define IINCHIP_ISR_ENABLE()
25 
26 //----------------------------- W5200 Common Registers -----------------------------
27 #define WIZC_MR (WIZ_COMMON_BASE + 0x0000) // Mode
28 #define WIZC_GAR0 (WIZ_COMMON_BASE + 0x0001) // GW Address
29 #define WIZC_GAR1 (WIZ_COMMON_BASE + 0x0002)
30 #define WIZC_GAR2 (WIZ_COMMON_BASE + 0x0003)
31 #define WIZC_GAR3 (WIZ_COMMON_BASE + 0x0004)
32 #define WIZC_SUBR0 (WIZ_COMMON_BASE + 0x0005) // SN Mask Address
33 #define WIZC_SUBR1 (WIZ_COMMON_BASE + 0x0006)
34 #define WIZC_SUBR2 (WIZ_COMMON_BASE + 0x0007)
35 #define WIZC_SUBR3 (WIZ_COMMON_BASE + 0x0008)
36 #define WIZC_SHAR0 (WIZ_COMMON_BASE + 0x0009) // Source Hardware Address
37 #define WIZC_SHAR1 (WIZ_COMMON_BASE + 0x000A)
38 #define WIZC_SHAR2 (WIZ_COMMON_BASE + 0x000B)
39 #define WIZC_SHAR3 (WIZ_COMMON_BASE + 0x000C)
40 #define WIZC_SHAR4 (WIZ_COMMON_BASE + 0x000D)
41 #define WIZC_SHAR5 (WIZ_COMMON_BASE + 0x000E)
42 #define WIZC_SIPR0 (WIZ_COMMON_BASE + 0x000F) // Source IP Address
43 #define WIZC_SIPR1 (WIZ_COMMON_BASE + 0x0010)
44 #define WIZC_SIPR2 (WIZ_COMMON_BASE + 0x0011)
45 #define WIZC_SIPR3 (WIZ_COMMON_BASE + 0x0012)
46 // Reserved (WIZ_COMMON_BASE + 0x0013)
47 // Reserved (WIZ_COMMON_BASE + 0x0014)
48 #define WIZC_IR (WIZ_COMMON_BASE + 0x0015) // Interrupt
49 #define WIZC_IMR2 (WIZ_COMMON_BASE + 0x0016) // Socket Interrupt Mask
50 #define WIZC_RTR0 (WIZ_COMMON_BASE + 0x0017) // Retry Time
51 #define WIZC_RTR1 (WIZ_COMMON_BASE + 0x0018)
52 #define WIZC_RCR (WIZ_COMMON_BASE + 0x0019) // Retry Count
53 // Reserved (WIZ_COMMON_BASE + 0x001A)
54 // Reserved (WIZ_COMMON_BASE + 0x001B)
55 #define WIZC_PATR0 (WIZ_COMMON_BASE + 0x001C) // Authentication Type in PPPoE
56 #define WIZC_PATR1 (WIZ_COMMON_BASE + 0x001D)
57 #define WIZC_PPPALGO (WIZ_COMMON_BASE + 0x001E) // Authentication Algorithm in PPPoE
58 #define WIZC_VERSIONR (WIZ_COMMON_BASE + 0x001F) // Chip version
59 // Reserved (WIZ_COMMON_BASE + 0x0020)
60 // Reserved (WIZ_COMMON_BASE + 0x0021)
61 // Reserved (WIZ_COMMON_BASE + 0x0022)
62 // Reserved (WIZ_COMMON_BASE + 0x0023)
63 // Reserved (WIZ_COMMON_BASE + 0x0024)
64 // Reserved (WIZ_COMMON_BASE + 0x0025)
65 // Reserved (WIZ_COMMON_BASE + 0x0026)
66 // Reserved (WIZ_COMMON_BASE + 0x0027)
67 #define WIZC_PTIMER (WIZ_COMMON_BASE + 0x0028) // PPP LCP RequestTimer
68 #define WIZC_PMAGIC (WIZ_COMMON_BASE + 0x0029) // PPP LCP Magic number
69 // Reserved (WIZ_COMMON_BASE + 0x002A)
70 // Reserved (WIZ_COMMON_BASE + 0x002B)
71 // Reserved (WIZ_COMMON_BASE + 0x002C)
72 // Reserved (WIZ_COMMON_BASE + 0x002D)
73 // Reserved (WIZ_COMMON_BASE + 0x002E)
74 // Reserved (WIZ_COMMON_BASE + 0x002F)
75 #define WIZC_INTLEVEL0 (WIZ_COMMON_BASE + 0x0030) // Interrupt Low Level Timer
76 #define WIZC_INTLEVEL1 (WIZ_COMMON_BASE + 0x0031)
77 // Reserved (WIZ_COMMON_BASE + 0x0032)
78 // Reserved (WIZ_COMMON_BASE + 0x0033)
79 #define WIZC_IR2 (WIZ_COMMON_BASE + 0x0034) // Socket Interrupt
80 #define WIZC_PSTATUS (WIZ_COMMON_BASE + 0x0035) // PHY Status
81 #define WIZC_IMR (WIZ_COMMON_BASE + 0x0036) // Interrupt Mask
82 
83 
84 //----------------------------- W5200 Socket Registers -----------------------------
85 #define WIZ_SOCK_REG(ch_v, reg_offset_v) \
86  WIZ_COMMON_BASE + 0x4000 + (ch_v * 0x0100) + reg_offset_v
87 //----------------- Offset -----------------
88 #define WIZS_MR 0x00 // Mode
89 #define WIZS_CR 0x01 // Command
90 #define WIZS_IR 0x02 // Interrupt
91 #define WIZS_SR 0x03 // Status
92 #define WIZS_PORT0 0x04 // Source Port
93 #define WIZS_PORT1 0x05
94 #define WIZS_DHAR0 0x06 // Destination Hardware Address
95 #define WIZS_DHAR1 0x07
96 #define WIZS_DHAR2 0x08
97 #define WIZS_DHAR3 0x09
98 #define WIZS_DHAR4 0x0A
99 #define WIZS_DHAR5 0x0B
100 #define WIZS_DIPR0 0x0C // Destination IP Address
101 #define WIZS_DIPR1 0x0D
102 #define WIZS_DIPR2 0x0E
103 #define WIZS_DIPR3 0x0F
104 #define WIZS_DPORT0 0x10 // Destination Port
105 #define WIZS_DPORT1 0x11
106 #define WIZS_MSSR0 0x12 // Maximum Segment Size
107 #define WIZS_MSSR1 0x13
108 #define WIZS_PROTO 0x14 // Protocol in IP Raw mode
109 #define WIZS_TOS 0x15 // IP TOS
110 #define WIZS_TTL 0x16 // IP TTL
111 // Reserved 0x17
112 // Reserved 0x18
113 // Reserved 0x19
114 // Reserved 0x1A
115 // Reserved 0x1B
116 // Reserved 0x1C
117 // Reserved 0x1D
118 #define WIZS_RXMEM_SIZE 0x1E // Receive Memory Size
119 #define WIZS_TXMEM_SIZE 0x1F // Transmit Memory Size
120 #define WIZS_TX_FSR0 0x20 // TX Free Size
121 #define WIZS_TX_FSR1 0x21
122 #define WIZS_TX_RD0 0x22 // TX Read Pointer
123 #define WIZS_TX_RD1 0x23
124 #define WIZS_TX_WR0 0x24 // TX Write Pointer
125 #define WIZS_TX_WR1 0x25
126 #define WIZS_RX_RSR0 0x26 // RX Received Size
127 #define WIZS_RX_RSR1 0x27
128 #define WIZS_RX_RD0 0x28 // RX Read Pointer
129 #define WIZS_RX_RD1 0x29
130 #define WIZS_RX_WR0 0x2A // RX Write Pointer
131 #define WIZS_RX_WR1 0x2B
132 #define WIZS_IMR 0x2C // Interrupt Mask
133 #define WIZS_FRAG0 0x2D // Fragment Offset in IP header
134 #define WIZS_FRAG1 0x2E
135 
136 //--------------------------- For Backward Compatibility ---------------------------
137 #define WIZ_CH_BASE (WIZ_COMMON_BASE + 0x4000)
138 #define WIZ_CH_SIZE 0x0100
139 #define Sn_MR(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0000) // socket Mode register
140 #define Sn_CR(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0001) // channel Sn_CR register
141 #define Sn_IR(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0002) // channel interrupt register
142 #define Sn_SR(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0003) // channel status register
143 #define Sn_PORT0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0004) // source port register
144 #define Sn_DHAR0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0006) // Peer MAC register address
145 #define Sn_DIPR0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x000C) // Peer IP register address
146 #define Sn_DPORT0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0010) // Peer port register address
147 #define Sn_MSSR0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0012) // Maximum Segment Size(Sn_MSSR0) register address
148 #define Sn_PROTO(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0014) // Protocol of IP Header field register in IP raw mode
149 #define Sn_TOS(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0015) // IP Type of Service(TOS) Register
150 #define Sn_TTL(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0016) // IP Time to live(TTL) Register
151 #define Sn_RXMEM_SIZE(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x001E) // Receive memory size reigster
152 #define Sn_TXMEM_SIZE(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x001F) // Transmit memory size reigster
153 #define Sn_TX_FSR0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0020) // Transmit free memory size register
154 #define Sn_TX_RD0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0022) // Transmit memory read pointer register address
155 #define Sn_TX_WR0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0024) // Transmit memory write pointer register address
156 #define Sn_RX_RSR0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0026) // Received data size register
157 #define Sn_RX_RD0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x0028) // Read point of Receive memory
158 #define Sn_RX_WR0(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x002A) // Write point of Receive memory
159 #define Sn_IMR(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x002C) // socket interrupt mask register
160 #define Sn_FRAG(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x002D) // frag field value in IP header register
161 #define Sn_KEEP_TIMER(ch) (WIZ_CH_BASE + ch * WIZ_CH_SIZE + 0x002F) // Keep Timer register
162 
163 // MODE register values
164 #define MR_RST 0x80 //< reset
165 #define MR_WOL 0x20 //< Wake on Lan
166 #define MR_PB 0x10 //< ping block
167 #define MR_PPPOE 0x08 //< enable pppoe
168 #define MR_LB 0x04 //< little or big endian selector in indirect mode
169 #define MR_AI 0x02 //< auto-increment in indirect mode
170 #define MR_IND 0x01 //< enable indirect mode
171 
172 // IR register values
173 #define IR_CONFLICT 0x80 //< check ip confict
174 #define IR_UNREACH 0x40 //< get the destination unreachable message in UDP sending
175 #define IR_PPPoE 0x20 //< get the PPPoE close message
176 #define IR_MAGIC 0x10 //< get the magic packet interrupt
177 #define IR_SOCK(ch) (0x01 << ch) //< check socket interrupt
178 
179 // Sn_MR values
180 #define Sn_MR_CLOSE 0x00 //< unused socket
181 #define Sn_MR_TCP 0x01 //< TCP
182 #define Sn_MR_UDP 0x02 //< UDP
183 #define Sn_MR_IPRAW 0x03 //< IP LAYER RAW SOCK
184 #define Sn_MR_MACRAW 0x04 //< MAC LAYER RAW SOCK
185 #define Sn_MR_PPPOE 0x05 //< PPPoE
186 #define Sn_MR_ND 0x20 //< No Delayed Ack(TCP) flag
187 #define Sn_MR_MULTI 0x80 //< support multicating
188 
189 // Sn_CR values
190 #define Sn_CR_OPEN 0x01 //< initialize or open socket
191 #define Sn_CR_LISTEN 0x02 //< wait connection request in tcp mode(Server mode)
192 #define Sn_CR_CONNECT 0x04 //< send connection request in tcp mode(Client mode)
193 #define Sn_CR_DISCON 0x08 //< send closing reqeuset in tcp mode
194 #define Sn_CR_CLOSE 0x10 //< close socket
195 #define Sn_CR_SEND 0x20 //< update txbuf pointer, send data
196 #define Sn_CR_SEND_MAC 0x21 //< send data with MAC address, so without ARP process
197 #define Sn_CR_SEND_KEEP 0x22 //< send keep alive message
198 #define Sn_CR_RECV 0x40 //< update rxbuf pointer, recv data
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 
205 // Sn_IR values
206 #define Sn_IR_PRECV 0x80
207 #define Sn_IR_PFAIL 0x40
208 #define Sn_IR_PNEXT 0x20
209 #define Sn_IR_SEND_OK 0x10 //< complete sending
210 #define Sn_IR_TIMEOUT 0x08 //< assert timeout
211 #define Sn_IR_RECV 0x04 //< receiving data
212 #define Sn_IR_DISCON 0x02 //< closed socket
213 #define Sn_IR_CON 0x01 //< established connection
214 
215 // Sn_SR values
216 #define SOCK_CLOSED 0x00 //< closed
217 #define SOCK_INIT 0x13 //< init state
218 #define SOCK_LISTEN 0x14 //< listen state
219 #define SOCK_SYNSENT 0x15 //< connection state
220 #define SOCK_SYNRECV 0x16 //< connection state
221 #define SOCK_ESTABLISHED 0x17 //< success to connect
222 #define SOCK_FIN_WAIT 0x18 //< closing state
223 #define SOCK_CLOSING 0x1A //< closing state
224 #define SOCK_TIME_WAIT 0x1B //< closing state
225 #define SOCK_CLOSE_WAIT 0x1C //< closing state
226 #define SOCK_LAST_ACK 0x1D //< closing state
227 #define SOCK_UDP 0x22 //< udp socket
228 #define SOCK_IPRAW 0x32 //< ip raw mode socket
229 #define SOCK_MACRAW 0x42 //< mac raw mode socket
230 #define SOCK_PPPOE 0x5F //< pppoe socket
231 
232 // IP PROTOCOL
233 #define IPPROTO_IP 0 //< Dummy for IP
234 #define IPPROTO_ICMP 1 //< Control message protocol
235 #define IPPROTO_IGMP 2 //< Internet group management protocol
236 #define IPPROTO_GGP 3 //< GW^2 (deprecated)
237 #define IPPROTO_TCP 6 //< TCP
238 #define IPPROTO_PUP 12 //< PUP
239 #define IPPROTO_UDP 17 //< UDP
240 #define IPPROTO_IDP 22 //< XNS idp
241 #define IPPROTO_ND 77 //< UNOFFICIAL net disk protocol
242 #define IPPROTO_RAW 255 //< Raw IP packet
243 
244 #define WINDOWFULL_FLAG_ON 1
245 #define WINDOWFULL_FLAG_OFF 0
246 #define WINDOWFULL_MAX_RETRY_NUM 3
247 #define WINDOWFULL_WAIT_TIME 1000
248 
249 /*********************************************************
250 * iinchip access functions
251 *********************************************************/
252 uint8 IINCHIP_READ(uint16 addr);
253 uint8 IINCHIP_WRITE(uint16 addr,uint8 data);
254 
255 uint8 getISR(uint8 s);
256 void putISR(uint8 s, uint8 val);
257 uint16 getIINCHIP_RxMAX(uint8 s);
258 uint16 getIINCHIP_TxMAX(uint8 s);
259 uint16 getIINCHIP_RxMASK(uint8 s);
260 uint16 getIINCHIP_TxMASK(uint8 s);
261 uint16 getIINCHIP_RxBASE(uint8 s);
262 uint16 getIINCHIP_TxBASE(uint8 s);
263 
264 void setMR(uint8 val);
265 void setRTR(uint16 timeout); // set retry duration for data transmission, connection, closing ...
266 void setRCR(uint8 retry); // set retry count (above the value, assert timeout interrupt)
267 void setIMR(uint8 mask); // set interrupt mask.
268 uint8 getIR( void );
269 void setSn_MSS(uint8 s, uint16 Sn_MSSR0); // set maximum segment size
270 void setSn_PROTO(uint8 s, uint8 proto); // set IP Protocol value using IP-Raw mode
271 uint8 getSn_IR(uint8 s); // get socket interrupt status
272 uint8 getSn_SR(uint8 s); // get socket status
273 uint16 getSn_TX_FSR(uint8 s); // get socket TX free buf size
274 uint16 getSn_RX_RSR(uint8 s); // get socket RX recv buf size
275 void setSn_TTL(uint8 s, uint8 ttl);
276 
277 void send_data_processing(uint8 s, uint8 *data, uint16 len);
278 void recv_data_processing(uint8 s, uint8 *data, uint16 len);
279 void recv_data_ignore(uint8 s, uint16 len);
280 
281 void setGAR(uint8 * addr); // set gateway address
282 void setSUBR(uint8 * addr); // set subnet mask address
283 void setSHAR(uint8 * addr); // set local MAC address
284 void setSIPR(uint8 * addr); // set local IP address
285 void getGAR(uint8 * addr);
286 void getSUBR(uint8 * addr);
287 void getSHAR(uint8 * addr);
288 void getSIPR(uint8 * addr);
289 void getDIPR(uint8 s, uint8 *addr);
290 void getDPORT(uint8 s, uint16 *port);
291 
292 uint8 incr_windowfull_retry_cnt(uint8 s);
293 void init_windowfull_retry_cnt(uint8 s);
294 
295 uint32 GetDestAddr(uint8 s); /* Output destination IP address of appropriate channel */
296 uint32 GetDestPort(uint8 s); /* Output destination port number of appropriate channel */
297 uint8 CheckDestInLocal(uint32 destip); /* Check Destination in local or remote */
298 uint8 getSocket(uint8 status, uint8 start); /* Get handle of socket which status is same to 'status' */
299 
300 #endif //_W5200_H
301 
302 
303