w5500_driver.h
Go to the documentation of this file.
1 /**
2  * @file w5500_driver.h
3  * @brief WIZnet W5500 Ethernet controller
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
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
314 extern "C" {
315 #endif
316 
317 //W5500 driver
318 extern const NicDriver w5500Driver;
319 
320 //W5500 related functions
321 error_t w5500Init(NetInterface *interface);
322 void w5500InitHook(NetInterface *interface);
323 
324 void w5500Tick(NetInterface *interface);
325 
326 void w5500EnableIrq(NetInterface *interface);
327 void w5500DisableIrq(NetInterface *interface);
329 void w5500EventHandler(NetInterface *interface);
330 
332  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
333 
335 
337 
338 void w5500WriteReg8(NetInterface *interface, uint8_t control,
339  uint16_t address, uint8_t data);
340 
341 uint8_t w5500ReadReg8(NetInterface *interface, uint8_t control,
342  uint16_t address);
343 
344 void w5500WriteReg16(NetInterface *interface, uint8_t control,
345  uint16_t address, uint16_t data);
346 
347 uint16_t w5500ReadReg16(NetInterface *interface, uint8_t control,
348  uint16_t address);
349 
350 void w5500WriteBuffer(NetInterface *interface, uint8_t control,
351  uint16_t address, const uint8_t *data, size_t length);
352 
353 void w5500ReadBuffer(NetInterface *interface, uint8_t control,
354  uint16_t address, uint8_t *data, size_t length);
355 
356 void w5500DumpReg(NetInterface *interface);
357 
358 //C++ guard
359 #ifdef __cplusplus
360 }
361 #endif
362 
363 #endif
int bool_t
Definition: compiler_port.h:53
error_t w5500UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
Definition: w5500_driver.c:511
error_t w5500ReceivePacket(NetInterface *interface)
Receive a packet.
Definition: w5500_driver.c:433
uint8_t control
Definition: ethernet.h:234
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
void w5500EnableIrq(NetInterface *interface)
Enable interrupts.
Definition: w5500_driver.c:250
uint8_t data[]
Definition: ethernet.h:222
error_t w5500SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
Definition: w5500_driver.c:368
bool_t w5500IrqHandler(NetInterface *interface)
W5500 interrupt service routine.
Definition: w5500_driver.c:281
void w5500EventHandler(NetInterface *interface)
W5500 event handler.
Definition: w5500_driver.c:343
const NicDriver w5500Driver
W5500 driver.
Definition: w5500_driver.c:44
void w5500InitHook(NetInterface *interface)
W5500 custom configuration.
Definition: w5500_driver.c:183
void w5500WriteBuffer(NetInterface *interface, uint8_t control, uint16_t address, const uint8_t *data, size_t length)
Write TX buffer.
Definition: w5500_driver.c:659
void w5500WriteReg8(NetInterface *interface, uint8_t control, uint16_t address, uint8_t data)
Write 8-bit register.
Definition: w5500_driver.c:526
void w5500Tick(NetInterface *interface)
W5500 timer handler.
Definition: w5500_driver.c:193
error_t
Error codes.
Definition: error.h:43
void w5500WriteReg16(NetInterface *interface, uint8_t control, uint16_t address, uint16_t data)
Write 16-bit register.
Definition: w5500_driver.c:591
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
uint8_t length
Definition: tcp.h:368
uint16_t w5500ReadReg16(NetInterface *interface, uint8_t control, uint16_t address)
Read 16-bit register.
Definition: w5500_driver.c:622
void w5500ReadBuffer(NetInterface *interface, uint8_t control, uint16_t address, uint8_t *data, size_t length)
Read RX buffer.
Definition: w5500_driver.c:695
uint8_t w5500ReadReg8(NetInterface *interface, uint8_t control, uint16_t address)
Read 8-bit register.
Definition: w5500_driver.c:556
Ipv6Addr address[]
Definition: ipv6.h:325
error_t w5500Init(NetInterface *interface)
W5500 controller initialization.
Definition: w5500_driver.c:71
Network interface controller abstraction layer.
void w5500DumpReg(NetInterface *interface)
Dump registers for debugging purpose.
Definition: w5500_driver.c:727
void w5500DisableIrq(NetInterface *interface)
Disable interrupts.
Definition: w5500_driver.c:265
NIC driver.
Definition: nic.h:286