enc28j60_driver.h
Go to the documentation of this file.
1 /**
2  * @file enc28j60_driver.h
3  * @brief ENC28J60 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 _ENC28J60_DRIVER_H
32 #define _ENC28J60_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Full-duplex support
38 #ifndef ENC28J60_FULL_DUPLEX_SUPPORT
39  #define ENC28J60_FULL_DUPLEX_SUPPORT ENABLED
40 #elif (ENC28J60_FULL_DUPLEX_SUPPORT != ENABLED && ENC28J60_FULL_DUPLEX_SUPPORT != DISABLED)
41  #error ENC28J60_FULL_DUPLEX_SUPPORT parameter is not valid
42 #endif
43 
44 //RX buffer size
45 #ifndef ENC28J60_ETH_RX_BUFFER_SIZE
46  #define ENC28J60_ETH_RX_BUFFER_SIZE 1536
47 #elif (ENC28J60_ETH_RX_BUFFER_SIZE != 1536)
48  #error ENC28J60_ETH_RX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Receive and transmit buffers
52 #define ENC28J60_RX_BUFFER_START 0x0000
53 #define ENC28J60_RX_BUFFER_STOP 0x17FF
54 #define ENC28J60_TX_BUFFER_START 0x1800
55 #define ENC28J60_TX_BUFFER_STOP 0x1FFF
56 
57 //SPI command set
58 #define ENC28J60_CMD_RCR 0x00
59 #define ENC28J60_CMD_RBM 0x3A
60 #define ENC28J60_CMD_WCR 0x40
61 #define ENC28J60_CMD_WBM 0x7A
62 #define ENC28J60_CMD_BFS 0x80
63 #define ENC28J60_CMD_BFC 0xA0
64 #define ENC28J60_CMD_SRC 0xFF
65 
66 //ENC28J60 register types
67 #define ETH_REG_TYPE 0x0000
68 #define MAC_REG_TYPE 0x1000
69 #define MII_REG_TYPE 0x2000
70 #define PHY_REG_TYPE 0x3000
71 
72 //ENC28J60 banks
73 #define BANK_0 0x0000
74 #define BANK_1 0x0100
75 #define BANK_2 0x0200
76 #define BANK_3 0x0300
77 
78 //Related masks
79 #define REG_TYPE_MASK 0xF000
80 #define REG_BANK_MASK 0x0F00
81 #define REG_ADDR_MASK 0x001F
82 
83 //ENC28J60 registers
84 #define ENC28J60_ERDPTL (ETH_REG_TYPE | BANK_0 | 0x00)
85 #define ENC28J60_ERDPTH (ETH_REG_TYPE | BANK_0 | 0x01)
86 #define ENC28J60_EWRPTL (ETH_REG_TYPE | BANK_0 | 0x02)
87 #define ENC28J60_EWRPTH (ETH_REG_TYPE | BANK_0 | 0x03)
88 #define ENC28J60_ETXSTL (ETH_REG_TYPE | BANK_0 | 0x04)
89 #define ENC28J60_ETXSTH (ETH_REG_TYPE | BANK_0 | 0x05)
90 #define ENC28J60_ETXNDL (ETH_REG_TYPE | BANK_0 | 0x06)
91 #define ENC28J60_ETXNDH (ETH_REG_TYPE | BANK_0 | 0x07)
92 #define ENC28J60_ERXSTL (ETH_REG_TYPE | BANK_0 | 0x08)
93 #define ENC28J60_ERXSTH (ETH_REG_TYPE | BANK_0 | 0x09)
94 #define ENC28J60_ERXNDL (ETH_REG_TYPE | BANK_0 | 0x0A)
95 #define ENC28J60_ERXNDH (ETH_REG_TYPE | BANK_0 | 0x0B)
96 #define ENC28J60_ERXRDPTL (ETH_REG_TYPE | BANK_0 | 0x0C)
97 #define ENC28J60_ERXRDPTH (ETH_REG_TYPE | BANK_0 | 0x0D)
98 #define ENC28J60_ERXWRPTL (ETH_REG_TYPE | BANK_0 | 0x0E)
99 #define ENC28J60_ERXWRPTH (ETH_REG_TYPE | BANK_0 | 0x0F)
100 #define ENC28J60_EDMASTL (ETH_REG_TYPE | BANK_0 | 0x10)
101 #define ENC28J60_EDMASTH (ETH_REG_TYPE | BANK_0 | 0x11)
102 #define ENC28J60_EDMANDL (ETH_REG_TYPE | BANK_0 | 0x12)
103 #define ENC28J60_EDMANDH (ETH_REG_TYPE | BANK_0 | 0x13)
104 #define ENC28J60_EDMADSTL (ETH_REG_TYPE | BANK_0 | 0x14)
105 #define ENC28J60_EDMADSTH (ETH_REG_TYPE | BANK_0 | 0x15)
106 #define ENC28J60_EDMACSL (ETH_REG_TYPE | BANK_0 | 0x16)
107 #define ENC28J60_EDMACSH (ETH_REG_TYPE | BANK_0 | 0x17)
108 #define ENC28J60_EIE (ETH_REG_TYPE | BANK_0 | 0x1B)
109 #define ENC28J60_EIR (ETH_REG_TYPE | BANK_0 | 0x1C)
110 #define ENC28J60_ESTAT (ETH_REG_TYPE | BANK_0 | 0x1D)
111 #define ENC28J60_ECON2 (ETH_REG_TYPE | BANK_0 | 0x1E)
112 #define ENC28J60_ECON1 (ETH_REG_TYPE | BANK_0 | 0x1F)
113 #define ENC28J60_EHT0 (ETH_REG_TYPE | BANK_1 | 0x00)
114 #define ENC28J60_EHT1 (ETH_REG_TYPE | BANK_1 | 0x01)
115 #define ENC28J60_EHT2 (ETH_REG_TYPE | BANK_1 | 0x02)
116 #define ENC28J60_EHT3 (ETH_REG_TYPE | BANK_1 | 0x03)
117 #define ENC28J60_EHT4 (ETH_REG_TYPE | BANK_1 | 0x04)
118 #define ENC28J60_EHT5 (ETH_REG_TYPE | BANK_1 | 0x05)
119 #define ENC28J60_EHT6 (ETH_REG_TYPE | BANK_1 | 0x06)
120 #define ENC28J60_EHT7 (ETH_REG_TYPE | BANK_1 | 0x07)
121 #define ENC28J60_EPMM0 (ETH_REG_TYPE | BANK_1 | 0x08)
122 #define ENC28J60_EPMM1 (ETH_REG_TYPE | BANK_1 | 0x09)
123 #define ENC28J60_EPMM2 (ETH_REG_TYPE | BANK_1 | 0x0A)
124 #define ENC28J60_EPMM3 (ETH_REG_TYPE | BANK_1 | 0x0B)
125 #define ENC28J60_EPMM4 (ETH_REG_TYPE | BANK_1 | 0x0C)
126 #define ENC28J60_EPMM5 (ETH_REG_TYPE | BANK_1 | 0x0D)
127 #define ENC28J60_EPMM6 (ETH_REG_TYPE | BANK_1 | 0x0E)
128 #define ENC28J60_EPMM7 (ETH_REG_TYPE | BANK_1 | 0x0F)
129 #define ENC28J60_EPMCSL (ETH_REG_TYPE | BANK_1 | 0x10)
130 #define ENC28J60_EPMCSH (ETH_REG_TYPE | BANK_1 | 0x11)
131 #define ENC28J60_EPMOL (ETH_REG_TYPE | BANK_1 | 0x14)
132 #define ENC28J60_EPMOH (ETH_REG_TYPE | BANK_1 | 0x15)
133 #define ENC28J60_EWOLIE (ETH_REG_TYPE | BANK_1 | 0x16)
134 #define ENC28J60_EWOLIR (ETH_REG_TYPE | BANK_1 | 0x17)
135 #define ENC28J60_ERXFCON (ETH_REG_TYPE | BANK_1 | 0x18)
136 #define ENC28J60_EPKTCNT (ETH_REG_TYPE | BANK_1 | 0x19)
137 #define ENC28J60_MACON1 (MAC_REG_TYPE | BANK_2 | 0x00)
138 #define ENC28J60_MACON2 (MAC_REG_TYPE | BANK_2 | 0x01)
139 #define ENC28J60_MACON3 (MAC_REG_TYPE | BANK_2 | 0x02)
140 #define ENC28J60_MACON4 (MAC_REG_TYPE | BANK_2 | 0x03)
141 #define ENC28J60_MABBIPG (MAC_REG_TYPE | BANK_2 | 0x04)
142 #define ENC28J60_MAIPGL (MAC_REG_TYPE | BANK_2 | 0x06)
143 #define ENC28J60_MAIPGH (MAC_REG_TYPE | BANK_2 | 0x07)
144 #define ENC28J60_MACLCON1 (MAC_REG_TYPE | BANK_2 | 0x08)
145 #define ENC28J60_MACLCON2 (MAC_REG_TYPE | BANK_2 | 0x09)
146 #define ENC28J60_MAMXFLL (MAC_REG_TYPE | BANK_2 | 0x0A)
147 #define ENC28J60_MAMXFLH (MAC_REG_TYPE | BANK_2 | 0x0B)
148 #define ENC28J60_MAPHSUP (MAC_REG_TYPE | BANK_2 | 0x0D)
149 #define ENC28J60_MICON (MII_REG_TYPE | BANK_2 | 0x11)
150 #define ENC28J60_MICMD (MII_REG_TYPE | BANK_2 | 0x12)
151 #define ENC28J60_MIREGADR (MII_REG_TYPE | BANK_2 | 0x14)
152 #define ENC28J60_MIWRL (MII_REG_TYPE | BANK_2 | 0x16)
153 #define ENC28J60_MIWRH (MII_REG_TYPE | BANK_2 | 0x17)
154 #define ENC28J60_MIRDL (MII_REG_TYPE | BANK_2 | 0x18)
155 #define ENC28J60_MIRDH (MII_REG_TYPE | BANK_2 | 0x19)
156 #define ENC28J60_MAADR1 (MAC_REG_TYPE | BANK_3 | 0x00)
157 #define ENC28J60_MAADR0 (MAC_REG_TYPE | BANK_3 | 0x01)
158 #define ENC28J60_MAADR3 (MAC_REG_TYPE | BANK_3 | 0x02)
159 #define ENC28J60_MAADR2 (MAC_REG_TYPE | BANK_3 | 0x03)
160 #define ENC28J60_MAADR5 (MAC_REG_TYPE | BANK_3 | 0x04)
161 #define ENC28J60_MAADR4 (MAC_REG_TYPE | BANK_3 | 0x05)
162 #define ENC28J60_EBSTSD (ETH_REG_TYPE | BANK_3 | 0x06)
163 #define ENC28J60_EBSTCON (ETH_REG_TYPE | BANK_3 | 0x07)
164 #define ENC28J60_EBSTCSL (ETH_REG_TYPE | BANK_3 | 0x08)
165 #define ENC28J60_EBSTCSH (ETH_REG_TYPE | BANK_3 | 0x09)
166 #define ENC28J60_MISTAT (MII_REG_TYPE | BANK_3 | 0x0A)
167 #define ENC28J60_EREVID (ETH_REG_TYPE | BANK_3 | 0x12)
168 #define ENC28J60_ECOCON (ETH_REG_TYPE | BANK_3 | 0x15)
169 #define ENC28J60_EFLOCON (ETH_REG_TYPE | BANK_3 | 0x17)
170 #define ENC28J60_EPAUSL (ETH_REG_TYPE | BANK_3 | 0x18)
171 #define ENC28J60_EPAUSH (ETH_REG_TYPE | BANK_3 | 0x19)
172 
173 //ENC28J60 PHY registers
174 #define ENC28J60_PHCON1 (PHY_REG_TYPE | 0x00)
175 #define ENC28J60_PHSTAT1 (PHY_REG_TYPE | 0x01)
176 #define ENC28J60_PHID1 (PHY_REG_TYPE | 0x02)
177 #define ENC28J60_PHID2 (PHY_REG_TYPE | 0x03)
178 #define ENC28J60_PHCON2 (PHY_REG_TYPE | 0x10)
179 #define ENC28J60_PHSTAT2 (PHY_REG_TYPE | 0x11)
180 #define ENC28J60_PHIE (PHY_REG_TYPE | 0x12)
181 #define ENC28J60_PHIR (PHY_REG_TYPE | 0x13)
182 #define ENC28J60_PHLCON (PHY_REG_TYPE | 0x14)
183 
184 //Ethernet Interrupt Enable register
185 #define ENC28J60_EIE_INTIE 0x80
186 #define ENC28J60_EIE_PKTIE 0x40
187 #define ENC28J60_EIE_DMAIE 0x20
188 #define ENC28J60_EIE_LINKIE 0x10
189 #define ENC28J60_EIE_TXIE 0x08
190 #define ENC28J60_EIE_WOLIE 0x04
191 #define ENC28J60_EIE_TXERIE 0x02
192 #define ENC28J60_EIE_RXERIE 0x01
193 
194 //Ethernet Interrupt Request register
195 #define ENC28J60_EIR_PKTIF 0x40
196 #define ENC28J60_EIR_DMAIF 0x20
197 #define ENC28J60_EIR_LINKIF 0x10
198 #define ENC28J60_EIR_TXIF 0x08
199 #define ENC28J60_EIR_WOLIF 0x04
200 #define ENC28J60_EIR_TXERIF 0x02
201 #define ENC28J60_EIR_RXERIF 0x01
202 
203 //Ethernet Status register
204 #define ENC28J60_ESTAT_INT 0x80
205 #define ENC28J60_ESTAT_R6 0x40
206 #define ENC28J60_ESTAT_R5 0x20
207 #define ENC28J60_ESTAT_LATECOL 0x10
208 #define ENC28J60_ESTAT_RXBUSY 0x04
209 #define ENC28J60_ESTAT_TXABRT 0x02
210 #define ENC28J60_ESTAT_CLKRDY 0x01
211 
212 //Ethernet Control 2 register
213 #define ENC28J60_ECON2_AUTOINC 0x80
214 #define ENC28J60_ECON2_PKTDEC 0x40
215 #define ENC28J60_ECON2_PWRSV 0x20
216 #define ENC28J60_ECON2_VRPS 0x08
217 
218 //Ethernet Control 1 register
219 #define ENC28J60_ECON1_TXRST 0x80
220 #define ENC28J60_ECON1_RXRST 0x40
221 #define ENC28J60_ECON1_DMAST 0x20
222 #define ENC28J60_ECON1_CSUMEN 0x10
223 #define ENC28J60_ECON1_TXRTS 0x08
224 #define ENC28J60_ECON1_RXEN 0x04
225 #define ENC28J60_ECON1_BSEL1 0x02
226 #define ENC28J60_ECON1_BSEL0 0x01
227 
228 //Ethernet Wake-Up On LAN Interrupt Enable register
229 #define ENC28J60_EWOLIE_UCWOLIE 0x80
230 #define ENC28J60_EWOLIE_AWOLIE 0x40
231 #define ENC28J60_EWOLIE_PMWOLIE 0x10
232 #define ENC28J60_EWOLIE_MPWOLIE 0x08
233 #define ENC28J60_EWOLIE_HTWOLIE 0x04
234 #define ENC28J60_EWOLIE_MCWOLIE 0x02
235 #define ENC28J60_EWOLIE_BCWOLIE 0x01
236 
237 //Ethernet Wake-Up On LAN Interrupt Request register
238 #define ENC28J60_EWOLIR_UCWOLIF 0x80
239 #define ENC28J60_EWOLIR_AWOLIF 0x40
240 #define ENC28J60_EWOLIR_PMWOLIF 0x10
241 #define ENC28J60_EWOLIR_MPWOLIF 0x08
242 #define ENC28J60_EWOLIR_HTWOLIF 0x04
243 #define ENC28J60_EWOLIR_MCWOLIF 0x02
244 #define ENC28J60_EWOLIR_BCWOLIF 0x01
245 
246 //Receive Filter Control register
247 #define ENC28J60_ERXFCON_UCEN 0x80
248 #define ENC28J60_ERXFCON_ANDOR 0x40
249 #define ENC28J60_ERXFCON_CRCEN 0x20
250 #define ENC28J60_ERXFCON_PMEN 0x10
251 #define ENC28J60_ERXFCON_MPEN 0x08
252 #define ENC28J60_ERXFCON_HTEN 0x04
253 #define ENC28J60_ERXFCON_MCEN 0x02
254 #define ENC28J60_ERXFCON_BCEN 0x01
255 
256 //MAC Control 1 register
257 #define ENC28J60_MACON1_LOOPBK 0x10
258 #define ENC28J60_MACON1_TXPAUS 0x08
259 #define ENC28J60_MACON1_RXPAUS 0x04
260 #define ENC28J60_MACON1_PASSALL 0x02
261 #define ENC28J60_MACON1_MARXEN 0x01
262 
263 //MAC Control 2 register
264 #define ENC28J60_MACON2_MARST 0x80
265 #define ENC28J60_MACON2_RNDRST 0x40
266 #define ENC28J60_MACON2_MARXRST 0x08
267 #define ENC28J60_MACON2_RFUNRST 0x04
268 #define ENC28J60_MACON2_MATXRST 0x02
269 #define ENC28J60_MACON2_TFUNRST 0x01
270 
271 //MAC Control 3 register
272 #define ENC28J60_MACON3_PADCFG 0xE0
273 #define ENC28J60_MACON3_PADCFG_NO 0x00
274 #define ENC28J60_MACON3_PADCFG_60_BYTES 0x20
275 #define ENC28J60_MACON3_PADCFG_64_BYTES 0x60
276 #define ENC28J60_MACON3_PADCFG_AUTO 0xA0
277 #define ENC28J60_MACON3_TXCRCEN 0x10
278 #define ENC28J60_MACON3_PHDRLEN 0x08
279 #define ENC28J60_MACON3_HFRMEN 0x04
280 #define ENC28J60_MACON3_FRMLNEN 0x02
281 #define ENC28J60_MACON3_FULDPX 0x01
282 
283 //MAC Control 4 register
284 #define ENC28J60_MACON4_DEFER 0x40
285 #define ENC28J60_MACON4_BPEN 0x20
286 #define ENC28J60_MACON4_NOBKOFF 0x10
287 #define ENC28J60_MACON4_LONGPRE 0x02
288 #define ENC28J60_MACON4_PUREPRE 0x01
289 
290 //Back-to-Back Inter-Packet Gap register
291 #define ENC28J60_MABBIPG_DEFAULT_HD 0x12
292 #define ENC28J60_MABBIPG_DEFAULT_FD 0x15
293 
294 //Non-Back-to-Back Inter-Packet Gap Low Byte register
295 #define ENC28J60_MAIPGL_DEFAULT 0x12
296 
297 //Non-Back-to-Back Inter-Packet Gap High Byte register
298 #define ENC28J60_MAIPGH_DEFAULT 0x0C
299 
300 //Retransmission Maximum register
301 #define ENC28J60_MACLCON1_RETMAX 0x0F
302 
303 //Collision Window register
304 #define ENC28J60_MACLCON2_COLWIN 0x3F
305 #define ENC28J60_MACLCON2_COLWIN_DEFAULT 0x37
306 
307 //MAC-PHY Support register
308 #define ENC28J60_MAPHSUP_RSTINTFC 0x80
309 #define ENC28J60_MAPHSUP_R4 0x10
310 #define ENC28J60_MAPHSUP_RSTRMII 0x08
311 #define ENC28J60_MAPHSUP_R0 0x01
312 
313 //MII Control register
314 #define ENC28J60_MICON_RSTMII 0x80
315 
316 //MII Command register
317 #define ENC28J60_MICMD_MIISCAN 0x02
318 #define ENC28J60_MICMD_MIIRD 0x01
319 
320 //MII Register Address register
321 #define ENC28J60_MIREGADR_VAL 0x1F
322 
323 //Self-Test Control register
324 #define ENC28J60_EBSTCON_PSV 0xE0
325 #define ENC28J60_EBSTCON_PSEL 0x10
326 #define ENC28J60_EBSTCON_TMSEL 0x0C
327 #define ENC28J60_EBSTCON_TMSEL_RANDOM 0x00
328 #define ENC28J60_EBSTCON_TMSEL_ADDR 0x04
329 #define ENC28J60_EBSTCON_TMSEL_PATTERN_SHIFT 0x08
330 #define ENC28J60_EBSTCON_TMSEL_RACE_MODE 0x0C
331 #define ENC28J60_EBSTCON_TME 0x02
332 #define ENC28J60_EBSTCON_BISTST 0x01
333 
334 //MII Status register
335 #define ENC28J60_MISTAT_R3 0x08
336 #define ENC28J60_MISTAT_NVALID 0x04
337 #define ENC28J60_MISTAT_SCAN 0x02
338 #define ENC28J60_MISTAT_BUSY 0x01
339 
340 //Ethernet Revision ID register
341 #define ENC28J60_EREVID_REV 0x1F
342 #define ENC28J60_EREVID_REV_B1 0x02
343 #define ENC28J60_EREVID_REV_B4 0x04
344 #define ENC28J60_EREVID_REV_B5 0x05
345 #define ENC28J60_EREVID_REV_B7 0x06
346 
347 //Clock Output Control register
348 #define ENC28J60_ECOCON_COCON 0x07
349 #define ENC28J60_ECOCON_COCON_DISABLED 0x00
350 #define ENC28J60_ECOCON_COCON_DIV1 0x01
351 #define ENC28J60_ECOCON_COCON_DIV2 0x02
352 #define ENC28J60_ECOCON_COCON_DIV3 0x03
353 #define ENC28J60_ECOCON_COCON_DIV4 0x04
354 #define ENC28J60_ECOCON_COCON_DIV8 0x05
355 
356 //Ethernet Flow Control register
357 #define ENC28J60_EFLOCON_FULDPXS 0x04
358 #define ENC28J60_EFLOCON_FCEN 0x03
359 #define ENC28J60_EFLOCON_FCEN_OFF 0x00
360 #define ENC28J60_EFLOCON_FCEN_ON_HD 0x01
361 #define ENC28J60_EFLOCON_FCEN_ON_FD 0x02
362 #define ENC28J60_EFLOCON_FCEN_SEND_PAUSE 0x03
363 
364 //PHY Control 1 register
365 #define ENC28J60_PHCON1_PRST 0x8000
366 #define ENC28J60_PHCON1_PLOOPBK 0x4000
367 #define ENC28J60_PHCON1_PPWRSV 0x0800
368 #define ENC28J60_PHCON1_PDPXMD 0x0100
369 
370 //Physical Layer Status 1 register
371 #define ENC28J60_PHSTAT1_PFDPX 0x1000
372 #define ENC28J60_PHSTAT1_PHDPX 0x0800
373 #define ENC28J60_PHSTAT1_LLSTAT 0x0004
374 #define ENC28J60_PHSTAT1_JBRSTAT 0x0002
375 
376 //PHY Identifier 1 register
377 #define ENC28J60_PHID1_PIDH 0xFFFF
378 #define ENC28J60_PHID1_PIDH_DEFAULT 0x0083
379 
380 //PHY Identifier 2 register
381 #define ENC28J60_PHID2_PIDL 0xFC00
382 #define ENC28J60_PHID2_PIDL_DEFAULT 0x1400
383 #define ENC28J60_PHID2_PPN 0x03F0
384 #define ENC28J60_PHID2_PPN_DEFAULT 0x0000
385 #define ENC28J60_PHID2_PREV 0x000F
386 
387 //PHY Control 2 register
388 #define ENC28J60_PHCON2_FRCLNK 0x4000
389 #define ENC28J60_PHCON2_TXDIS 0x2000
390 #define ENC28J60_PHCON2_JABBER 0x0400
391 #define ENC28J60_PHCON2_HDLDIS 0x0100
392 
393 //Physical Layer Status 2 register
394 #define ENC28J60_PHSTAT2_TXSTAT 0x2000
395 #define ENC28J60_PHSTAT2_RXSTAT 0x1000
396 #define ENC28J60_PHSTAT2_COLSTAT 0x0800
397 #define ENC28J60_PHSTAT2_LSTAT 0x0400
398 #define ENC28J60_PHSTAT2_DPXSTAT 0x0200
399 #define ENC28J60_PHSTAT2_PLRITY 0x0010
400 
401 //PHY Interrupt Enable register
402 #define ENC28J60_PHIE_PLNKIE 0x0010
403 #define ENC28J60_PHIE_PGEIE 0x0002
404 
405 //PHY Interrupt Request register
406 #define ENC28J60_PHIR_PLNKIF 0x0010
407 #define ENC28J60_PHIR_PGIF 0x0004
408 
409 //PHY Module LED Control register
410 #define ENC28J60_PHLCON_LACFG 0x0F00
411 #define ENC28J60_PHLCON_LACFG_TX 0x0100
412 #define ENC28J60_PHLCON_LACFG_RX 0x0200
413 #define ENC28J60_PHLCON_LACFG_COL 0x0300
414 #define ENC28J60_PHLCON_LACFG_LINK 0x0400
415 #define ENC28J60_PHLCON_LACFG_DUPLEX 0x0500
416 #define ENC28J60_PHLCON_LACFG_TX_RX 0x0700
417 #define ENC28J60_PHLCON_LACFG_ON 0x0800
418 #define ENC28J60_PHLCON_LACFG_OFF 0x0900
419 #define ENC28J60_PHLCON_LACFG_BLINK_FAST 0x0A00
420 #define ENC28J60_PHLCON_LACFG_BLINK_SLOW 0x0B00
421 #define ENC28J60_PHLCON_LACFG_LINK_RX 0x0C00
422 #define ENC28J60_PHLCON_LACFG_LINK_TX_RX 0x0D00
423 #define ENC28J60_PHLCON_LACFG_DUPLEX_COL 0x0E00
424 #define ENC28J60_PHLCON_LBCFG 0x00F0
425 #define ENC28J60_PHLCON_LBCFG_TX 0x0010
426 #define ENC28J60_PHLCON_LBCFG_RX 0x0020
427 #define ENC28J60_PHLCON_LBCFG_COL 0x0030
428 #define ENC28J60_PHLCON_LBCFG_LINK 0x0040
429 #define ENC28J60_PHLCON_LBCFG_DUPLEX 0x0050
430 #define ENC28J60_PHLCON_LBCFG_TX_RX 0x0070
431 #define ENC28J60_PHLCON_LBCFG_ON 0x0080
432 #define ENC28J60_PHLCON_LBCFG_OFF 0x0090
433 #define ENC28J60_PHLCON_LBCFG_BLINK_FAST 0x00A0
434 #define ENC28J60_PHLCON_LBCFG_BLINK_SLOW 0x00B0
435 #define ENC28J60_PHLCON_LBCFG_LINK_RX 0x00C0
436 #define ENC28J60_PHLCON_LBCFG_LINK_TX_RX 0x00D0
437 #define ENC28J60_PHLCON_LBCFG_DUPLEX_COL 0x00E0
438 #define ENC28J60_PHLCON_LFRQ 0x000C
439 #define ENC28J60_PHLCON_LFRQ_40_MS 0x0000
440 #define ENC28J60_PHLCON_LFRQ_73_MS 0x0004
441 #define ENC28J60_PHLCON_LFRQ_139_MS 0x0008
442 #define ENC28J60_PHLCON_STRCH 0x0002
443 
444 //Per-packet control byte
445 #define ENC28J60_TX_CTRL_PHUGEEN 0x08
446 #define ENC28J60_TX_CTRL_PPADEN 0x04
447 #define ENC28J60_TX_CTRL_PCRCEN 0x02
448 #define ENC28J60_TX_CTRL_POVERRIDE 0x01
449 
450 //Receive status vector
451 #define ENC28J60_RSV_VLAN_TYPE 0x4000
452 #define ENC28J60_RSV_UNKNOWN_OPCODE 0x2000
453 #define ENC28J60_RSV_PAUSE_CONTROL_FRAME 0x1000
454 #define ENC28J60_RSV_CONTROL_FRAME 0x0800
455 #define ENC28J60_RSV_DRIBBLE_NIBBLE 0x0400
456 #define ENC28J60_RSV_BROADCAST_PACKET 0x0200
457 #define ENC28J60_RSV_MULTICAST_PACKET 0x0100
458 #define ENC28J60_RSV_RECEIVED_OK 0x0080
459 #define ENC28J60_RSV_LENGTH_OUT_OF_RANGE 0x0040
460 #define ENC28J60_RSV_LENGTH_CHECK_ERROR 0x0020
461 #define ENC28J60_RSV_CRC_ERROR 0x0010
462 #define ENC28J60_RSV_CARRIER_EVENT 0x0004
463 #define ENC28J60_RSV_DROP_EVENT 0x0001
464 
465 //C++ guard
466 #ifdef __cplusplus
467 extern "C" {
468 #endif
469 
470 
471 /**
472  * @brief ENC28J60 driver context
473  **/
474 
475 typedef struct
476 {
477  uint16_t currentBank; ///<Current bank
478  uint16_t nextPacket; ///<Next packet in the receive buffer
480 
481 
482 //ENC28J60 driver
483 extern const NicDriver enc28j60Driver;
484 
485 //ENC28J60 related functions
486 error_t enc28j60Init(NetInterface *interface);
487 void enc28j60InitHook(NetInterface *interface);
488 
489 void enc28j60Tick(NetInterface *interface);
490 
491 void enc28j60EnableIrq(NetInterface *interface);
492 void enc28j60DisableIrq(NetInterface *interface);
494 void enc28j60EventHandler(NetInterface *interface);
495 
497  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
498 
500 
502 
503 void enc28j60SoftReset(NetInterface *interface);
504 void enc28j60SelectBank(NetInterface *interface, uint16_t address);
505 
506 void enc28j60WriteReg(NetInterface *interface, uint16_t address, uint8_t data);
507 uint8_t enc28j60ReadReg(NetInterface *interface, uint16_t address);
508 
509 void enc28j60WritePhyReg(NetInterface *interface, uint16_t address,
510  uint16_t data);
511 
512 uint16_t enc28j60ReadPhyReg(NetInterface *interface, uint16_t address);
513 
514 void enc28j60WriteBuffer(NetInterface *interface,
515  const NetBuffer *buffer, size_t offset);
516 
517 void enc28j60ReadBuffer(NetInterface *interface,
518  uint8_t *data, size_t length);
519 
520 void enc28j60SetBit(NetInterface *interface, uint16_t address, uint16_t mask);
521 void enc28j60ClearBit(NetInterface *interface, uint16_t address, uint16_t mask);
522 
523 uint32_t enc28j60CalcCrc(const void *data, size_t length);
524 
525 void enc28j60DumpReg(NetInterface *interface);
526 void enc28j60DumpPhyReg(NetInterface *interface);
527 
528 //C++ guard
529 #ifdef __cplusplus
530 }
531 #endif
532 
533 #endif
int bool_t
Definition: compiler_port.h:53
void enc28j60SoftReset(NetInterface *interface)
ENC28J60 controller reset.
error_t enc28j60Init(NetInterface *interface)
ENC28J60 controller initialization.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint16_t enc28j60ReadPhyReg(NetInterface *interface, uint16_t address)
Read PHY register.
uint8_t data[]
Definition: ethernet.h:222
void enc28j60InitHook(NetInterface *interface)
ENC28J60 custom configuration.
void enc28j60ReadBuffer(NetInterface *interface, uint8_t *data, size_t length)
Read SRAM buffer.
void enc28j60WriteReg(NetInterface *interface, uint16_t address, uint8_t data)
Write ENC28J60 register.
void enc28j60DumpReg(NetInterface *interface)
Dump registers for debugging purpose.
void enc28j60EnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t nextPacket
Next packet in the receive buffer.
error_t
Error codes.
Definition: error.h:43
uint8_t enc28j60ReadReg(NetInterface *interface, uint16_t address)
Read ENC28J60 register.
void enc28j60SetBit(NetInterface *interface, uint16_t address, uint16_t mask)
Set bit field.
#define NetInterface
Definition: net.h:36
uint16_t currentBank
Current bank.
#define NetTxAncillary
Definition: net_misc.h:36
uint8_t mask
Definition: web_socket.h:319
uint8_t length
Definition: tcp.h:368
bool_t enc28j60IrqHandler(NetInterface *interface)
ENC28J60 interrupt service routine.
void enc28j60Tick(NetInterface *interface)
ENC28J60 timer handler.
ENC28J60 driver context.
uint32_t enc28j60CalcCrc(const void *data, size_t length)
CRC calculation using the polynomial 0x4C11DB7.
error_t enc28j60UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
Ipv6Addr address[]
Definition: ipv6.h:325
Network interface controller abstraction layer.
error_t enc28j60SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
void enc28j60EventHandler(NetInterface *interface)
ENC28J60 event handler.
void enc28j60SelectBank(NetInterface *interface, uint16_t address)
Bank selection.
void enc28j60WriteBuffer(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Write SRAM buffer.
void enc28j60DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void enc28j60WritePhyReg(NetInterface *interface, uint16_t address, uint16_t data)
Write PHY register.
const NicDriver enc28j60Driver
ENC28J60 driver.
error_t enc28j60ReceivePacket(NetInterface *interface)
Receive a packet.
NIC driver.
Definition: nic.h:286
void enc28j60ClearBit(NetInterface *interface, uint16_t address, uint16_t mask)
Clear bit field.
void enc28j60DisableIrq(NetInterface *interface)
Disable interrupts.