mikroSDK Reference Manual
w5500_driver.h
Go to the documentation of this file.
1
31#ifndef _W5500_DRIVER_H
32#define _W5500_DRIVER_H
33
34//Dependencies
35#include "core/nic.h"
36
37//TX buffer size
38#ifndef W5500_ETH_TX_BUFFER_SIZE
39 #define W5500_ETH_TX_BUFFER_SIZE 1536
40#elif (W5500_ETH_TX_BUFFER_SIZE != 1536)
41 #error W5500_ETH_TX_BUFFER_SIZE parameter is not valid
42#endif
43
44//RX buffer size
45#ifndef W5500_ETH_RX_BUFFER_SIZE
46 #define W5500_ETH_RX_BUFFER_SIZE 1536
47#elif (W5500_ETH_RX_BUFFER_SIZE != 1536)
48 #error W5500_ETH_RX_BUFFER_SIZE parameter is not valid
49#endif
50
51//Control byte
52#define W5500_CTRL_BSB 0xF8
53#define W5500_CTRL_BSB_COMMON_REG 0x00
54#define W5500_CTRL_BSB_S0_REG 0x08
55#define W5500_CTRL_BSB_S0_TX_BUFFER 0x10
56#define W5500_CTRL_BSB_S0_RX_BUFFER 0x18
57#define W5500_CTRL_BSB_S1_REG 0x28
58#define W5500_CTRL_BSB_S1_TX_BUFFER 0x30
59#define W5500_CTRL_BSB_S1_RX_BUFFER 0x38
60#define W5500_CTRL_BSB_S2_REG 0x48
61#define W5500_CTRL_BSB_S2_TX_BUFFER 0x50
62#define W5500_CTRL_BSB_S2_RX_BUFFER 0x58
63#define W5500_CTRL_BSB_S3_REG 0x68
64#define W5500_CTRL_BSB_S3_TX_BUFFER 0x70
65#define W5500_CTRL_BSB_S3_RX_BUFFER 0x78
66#define W5500_CTRL_BSB_S4_REG 0x88
67#define W5500_CTRL_BSB_S4_TX_BUFFER 0x90
68#define W5500_CTRL_BSB_S4_RX_BUFFER 0x98
69#define W5500_CTRL_BSB_S5_REG 0xA8
70#define W5500_CTRL_BSB_S5_TX_BUFFER 0xB0
71#define W5500_CTRL_BSB_S5_RX_BUFFER 0xB8
72#define W5500_CTRL_BSB_S6_REG 0xC8
73#define W5500_CTRL_BSB_S6_TX_BUFFER 0xD0
74#define W5500_CTRL_BSB_S6_RX_BUFFER 0xD8
75#define W5500_CTRL_BSB_S7_REG 0xE8
76#define W5500_CTRL_BSB_S7_TX_BUFFER 0xF0
77#define W5500_CTRL_BSB_S7_RX_BUFFER 0xF8
78#define W5500_CTRL_RWB 0x04
79#define W5500_CTRL_RWB_READ 0x00
80#define W5500_CTRL_RWB_WRITE 0x04
81#define W5500_CTRL_OM 0x03
82#define W5500_CTRL_OM_VDM 0x00
83#define W5500_CTRL_OM_FDM1 0x01
84#define W5500_CTRL_OM_FDM2 0x02
85#define W5500_CTRL_OM_FDM4 0x03
86
87//Common register block
88#define W5500_MR 0x00
89#define W5500_GAR0 0x01
90#define W5500_GAR1 0x01
91#define W5500_GAR2 0x02
92#define W5500_GAR3 0x03
93#define W5500_SUBR0 0x05
94#define W5500_SUBR1 0x06
95#define W5500_SUBR2 0x07
96#define W5500_SUBR3 0x08
97#define W5500_SHAR0 0x09
98#define W5500_SHAR1 0x0A
99#define W5500_SHAR2 0x0B
100#define W5500_SHAR3 0x0C
101#define W5500_SHAR4 0x0D
102#define W5500_SHAR5 0x0E
103#define W5500_SIPR0 0x0F
104#define W5500_SIPR1 0x10
105#define W5500_SIPR2 0x11
106#define W5500_SIPR3 0x12
107#define W5500_INTLEVEL0 0x13
108#define W5500_INTLEVEL1 0x14
109#define W5500_IR 0x15
110#define W5500_IMR 0x16
111#define W5500_SIR 0x17
112#define W5500_SIMR 0x18
113#define W5500_RTR0 0x19
114#define W5500_RTR1 0x1A
115#define W5500_RCR 0x1B
116#define W5500_PTIMER 0x1C
117#define W5500_PMAGIC 0x1D
118#define W5500_PHAR0 0x1E
119#define W5500_PHAR1 0x1F
120#define W5500_PHAR2 0x20
121#define W5500_PHAR3 0x21
122#define W5500_PHAR4 0x22
123#define W5500_PHAR5 0x23
124#define W5500_PSID0 0x24
125#define W5500_PSID1 0x25
126#define W5500_PMRU0 0x26
127#define W5500_PMRU1 0x27
128#define W5500_UIPR0 0x28
129#define W5500_UIPR1 0x29
130#define W5500_UIPR2 0x2A
131#define W5500_UIPR3 0x2B
132#define W5500_UPORTR0 0x2C
133#define W5500_UPORTR1 0x2D
134#define W5500_PHYCFGR 0x2E
135#define W5500_VERSIONR 0x39
136
137//Socket register block
138#define W5500_Sn_MR 0x00
139#define W5500_Sn_CR 0x01
140#define W5500_Sn_IR 0x02
141#define W5500_Sn_SR 0x03
142#define W5500_Sn_PORT0 0x04
143#define W5500_Sn_PORT1 0x05
144#define W5500_Sn_DHAR0 0x06
145#define W5500_Sn_DHAR1 0x07
146#define W5500_Sn_DHAR2 0x08
147#define W5500_Sn_DHAR3 0x09
148#define W5500_Sn_DHAR4 0x0A
149#define W5500_Sn_DHAR5 0x0B
150#define W5500_Sn_DIPR0 0x0C
151#define W5500_Sn_DIPR1 0x0D
152#define W5500_Sn_DIPR2 0x0E
153#define W5500_Sn_DIPR3 0x0F
154#define W5500_Sn_DPORT0 0x10
155#define W5500_Sn_DPORT1 0x11
156#define W5500_Sn_MSSR0 0x12
157#define W5500_Sn_MSSR1 0x13
158#define W5500_Sn_TOS 0x15
159#define W5500_Sn_TTL 0x16
160#define W5500_Sn_RXBUF_SIZE 0x1E
161#define W5500_Sn_TXBUF_SIZE 0x1F
162#define W5500_Sn_TX_FSR0 0x20
163#define W5500_Sn_TX_FSR1 0x21
164#define W5500_Sn_TX_RD0 0x22
165#define W5500_Sn_TX_RD1 0x23
166#define W5500_Sn_TX_WR0 0x24
167#define W5500_Sn_TX_WR1 0x25
168#define W5500_Sn_RX_RSR0 0x26
169#define W5500_Sn_RX_RSR1 0x27
170#define W5500_Sn_RX_RD0 0x28
171#define W5500_Sn_RX_RD1 0x29
172#define W5500_Sn_RX_WR0 0x2A
173#define W5500_Sn_RX_WR1 0x2B
174#define W5500_Sn_IMR 0x2C
175#define W5500_Sn_FRAG0 0x2D
176#define W5500_Sn_FRAG1 0x2E
177#define W5500_Sn_KPALVTR 0x2F
178
179//Mode register
180#define W5500_MR_RST 0x80
181#define W5500_MR_WOL 0x20
182#define W5500_MR_PB 0x10
183#define W5500_MR_PPPOE 0x08
184#define W5500_MR_FARP 0x02
185
186//Interrupt register
187#define W5500_IR_CONFLICT 0x80
188#define W5500_IR_UNREACH 0x40
189#define W5500_IR_PPPOE 0x20
190#define W5500_IR_MP 0x10
191
192//Interrupt Mask register
193#define W5500_IMR_CONFLICT 0x80
194#define W5500_IMR_UNREACH 0x40
195#define W5500_IMR_PPPOE 0x20
196#define W5500_IMR_MP 0x10
197
198//Socket Interrupt register
199#define W5500_SIR_S7_INT 0x80
200#define W5500_SIR_S6_INT 0x40
201#define W5500_SIR_S5_INT 0x20
202#define W5500_SIR_S4_INT 0x10
203#define W5500_SIR_S3_INT 0x08
204#define W5500_SIR_S2_INT 0x04
205#define W5500_SIR_S1_INT 0x02
206#define W5500_SIR_S0_INT 0x01
207
208//Socket Interrupt Mask register
209#define W5500_SIMR_S7_IMR 0x80
210#define W5500_SIMR_S6_IMR 0x40
211#define W5500_SIMR_S5_IMR 0x20
212#define W5500_SIMR_S4_IMR 0x10
213#define W5500_SIMR_S3_IMR 0x08
214#define W5500_SIMR_S2_IMR 0x04
215#define W5500_SIMR_S1_IMR 0x02
216#define W5500_SIMR_S0_IMR 0x01
217
218//PHY Configuration register
219#define W5500_PHYCFGR_RST 0x80
220#define W5500_PHYCFGR_OPMD 0x40
221#define W5500_PHYCFGR_OPMDC 0x38
222#define W5500_PHYCFGR_OPMDC_10BT_HD 0x00
223#define W5500_PHYCFGR_OPMDC_10BT_FD 0x08
224#define W5500_PHYCFGR_OPMDC_100BT_HD 0x10
225#define W5500_PHYCFGR_OPMDC_100BT_FD 0x18
226#define W5500_PHYCFGR_OPMDC_100BT_HD_AN 0x20
227#define W5500_PHYCFGR_OPMDC_PD 0x30
228#define W5500_PHYCFGR_OPMDC_ALL_AN 0x38
229#define W5500_PHYCFGR_DPX 0x04
230#define W5500_PHYCFGR_SPD 0x02
231#define W5500_PHYCFGR_LNK 0x01
232
233//Chip Version register
234#define W5500_VERSIONR_DEFAULT 0x04
235
236//Socket n Mode register
237#define W5500_Sn_MR_MULTI 0x80
238#define W5500_Sn_MR_MFEN 0x80
239#define W5500_Sn_MR_BCASTB 0x40
240#define W5500_Sn_MR_ND 0x20
241#define W5500_Sn_MR_MC 0x20
242#define W5500_Sn_MR_MMB 0x20
243#define W5500_Sn_MR_UCASTB 0x10
244#define W5500_Sn_MR_MIP6B 0x10
245#define W5500_Sn_MR_PROTOCOL 0x0F
246#define W5500_Sn_MR_PROTOCOL_CLOSED 0x00
247#define W5500_Sn_MR_PROTOCOL_TCP 0x01
248#define W5500_Sn_MR_PROTOCOL_UDP 0x02
249#define W5500_Sn_MR_PROTOCOL_MACRAW 0x04
250
251//Socket n Command register
252#define W5500_Sn_CR_OPEN 0x01
253#define W5500_Sn_CR_LISTEN 0x02
254#define W5500_Sn_CR_CONNECT 0x04
255#define W5500_Sn_CR_DISCON 0x08
256#define W5500_Sn_CR_CLOSE 0x10
257#define W5500_Sn_CR_SEND 0x20
258#define W5500_Sn_CR_SEND_MAC 0x21
259#define W5500_Sn_CR_SEND_KEEP 0x22
260#define W5500_Sn_CR_RECV 0x40
261
262//Socket n Interrupt register
263#define W5500_Sn_IR_SEND_OK 0x10
264#define W5500_Sn_IR_TIMEOUT 0x08
265#define W5500_Sn_IR_RECV 0x04
266#define W5500_Sn_IR_DISCON 0x02
267#define W5500_Sn_IR_CON 0x01
268
269//Socket n Status register
270#define W5500_Sn_SR_SOCK_CLOSED 0x00
271#define W5500_Sn_SR_SOCK_INIT 0x13
272#define W5500_Sn_SR_SOCK_LISTEN 0x14
273#define W5500_Sn_SR_SOCK_SYNSENT 0x15
274#define W5500_Sn_SR_SOCK_SYNRECV 0x16
275#define W5500_Sn_SR_SOCK_ESTABLISHED 0x17
276#define W5500_Sn_SR_SOCK_FIN_WAIT 0x18
277#define W5500_Sn_SR_SOCK_CLOSING 0x1A
278#define W5500_Sn_SR_SOCK_TIME_WAIT 0x1B
279#define W5500_Sn_SR_SOCK_CLOSE_WAIT 0x1C
280#define W5500_Sn_SR_SOCK_LAST_ACK 0x1D
281#define W5500_Sn_SR_SOCK_UDP 0x22
282#define W5500_Sn_SR_SOCK_MACRAW 0x42
283
284//Socket n Receive Buffer Size register
285#define W5500_Sn_RXBUF_SIZE_0KB 0x00
286#define W5500_Sn_RXBUF_SIZE_1KB 0x01
287#define W5500_Sn_RXBUF_SIZE_2KB 0x02
288#define W5500_Sn_RXBUF_SIZE_4KB 0x04
289#define W5500_Sn_RXBUF_SIZE_8KB 0x08
290#define W5500_Sn_RXBUF_SIZE_16KB 0x10
291
292//Socket n Transmit Buffer Size register
293#define W5500_Sn_TXBUF_SIZE_0KB 0x00
294#define W5500_Sn_TXBUF_SIZE_1KB 0x01
295#define W5500_Sn_TXBUF_SIZE_2KB 0x02
296#define W5500_Sn_TXBUF_SIZE_4KB 0x04
297#define W5500_Sn_TXBUF_SIZE_8KB 0x08
298#define W5500_Sn_TXBUF_SIZE_16KB 0x10
299
300//Socket n Interrupt Mask register
301#define W5500_Sn_IMR_SEND_OK 0x10
302#define W5500_Sn_IMR_TIMEOUT 0x08
303#define W5500_Sn_IMR_RECV 0x04
304#define W5500_Sn_IMR_DISCON 0x02
305#define W5500_Sn_IMR_CON 0x01
306
307//Block Select Bits
308#define W5500_CTRL_BSB_Sn_REG(n) (0x08 + (n) * 0x20)
309#define W5500_CTRL_BSB_Sn_TX_BUFFER(n) (0x10 + (n) * 0x20)
310#define W5500_CTRL_BSB_Sn_RX_BUFFER(n) (0x18 + (n) * 0x20)
311
312//C++ guard
313#ifdef __cplusplus
314extern "C" {
315#endif
316
317//W5500 driver
318extern const NicDriver w5500Driver;
319
320//W5500 related functions
321error_t w5500Init(NetInterface *interface);
322
323void w5500Tick(NetInterface *interface);
324
325void w5500EnableIrq(NetInterface *interface);
326void w5500DisableIrq(NetInterface *interface);
327bool_t w5500IrqHandler(NetInterface *interface);
328void w5500EventHandler(NetInterface *interface);
329
330error_t w5500SendPacket(NetInterface *interface,
331 const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
332
333error_t w5500ReceivePacket(NetInterface *interface);
334
335error_t w5500UpdateMacAddrFilter(NetInterface *interface);
336
337void w5500WriteReg8(NetInterface *interface, uint8_t control,
338 uint16_t address, uint8_t data);
339
340uint8_t w5500ReadReg8(NetInterface *interface, uint8_t control,
341 uint16_t address);
342
343void w5500WriteReg16(NetInterface *interface, uint8_t control,
344 uint16_t address, uint16_t data);
345
346uint16_t w5500ReadReg16(NetInterface *interface, uint8_t control,
347 uint16_t address);
348
349void w5500WriteBuffer(NetInterface *interface, uint8_t control,
350 uint16_t address, const uint8_t *data, size_t length);
351
352void w5500ReadBuffer(NetInterface *interface, uint8_t control,
353 uint16_t address, uint8_t *data, size_t length);
354
355void w5500DumpReg(NetInterface *interface);
356
357//C++ guard
358#ifdef __cplusplus
359}
360#endif
361
362#endif
error_t
Error codes.
Definition error.h:43
Network interface controller abstraction layer.
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89
NIC driver.
Definition nic.h:283