enc28j60 library  1.0
platform agnostic enc28j60 driver with asynchronous IO support and fully compliant with errata
enc28j60.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Dalibor Drgon <dalibor.drgon@gmail.com>
2 // This code is licensed under MIT license (see LICENSE.txt for details)
14 #ifndef __ENC28J60_H
15 #define __ENC28J60_H
16 
17 #include <stdint.h>
18 #include <stdbool.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #define ENC28J60_ERRATA_INFO
25 
26 
27 /************************ enc28j60 registers start ***************************/
28 
29 // Shared registers
30 #define ENC28J60_EIE 0x1B
31 #define ENC28J60_EIR 0x1C
32 #define ENC28J60_ESTAT 0x1D
33 #define ENC28J60_ECON2 0x1E
34 #define ENC28J60_ECON1 0x1F
35 
36 // Bank #0
37 #define ENC28J60_ERDPTL (0x00|0x00)
38 #define ENC28J60_ERDPTH (0x01|0x00)
39 #define ENC28J60_EWRPTL (0x02|0x00)
40 #define ENC28J60_EWRPTH (0x03|0x00)
41 #define ENC28J60_ETXSTL (0x04|0x00)
42 #define ENC28J60_ETXSTH (0x05|0x00)
43 #define ENC28J60_ETXNDL (0x06|0x00)
44 #define ENC28J60_ETXNDH (0x07|0x00)
45 #define ENC28J60_ERXSTL (0x08|0x00)
46 #define ENC28J60_ERXSTH (0x09|0x00)
47 #define ENC28J60_ERXNDL (0x0A|0x00)
48 #define ENC28J60_ERXNDH (0x0B|0x00)
49 #define ENC28J60_ERXRDPTL (0x0C|0x00)
50 #define ENC28J60_ERXRDPTH (0x0D|0x00)
51 #define ENC28J60_ERXWRPTL (0x0E|0x00)
52 #define ENC28J60_ERXWRPTH (0x0F|0x00)
53 #define ENC28J60_EDMASTL (0x10|0x00)
54 #define ENC28J60_EDMASTH (0x11|0x00)
55 #define ENC28J60_EDMANDL (0x12|0x00)
56 #define ENC28J60_EDMANDH (0x13|0x00)
57 #define ENC28J60_EDMADSTL (0x14|0x00)
58 #define ENC28J60_EDMADSTH (0x15|0x00)
59 #define ENC28J60_EDMACSL (0x16|0x00)
60 #define ENC28J60_EDMACSH (0x17|0x00)
61 
62 // Bank #1
63 #define ENC28J60_EHT0 (0x00|0x20)
64 #define ENC28J60_EHT1 (0x01|0x20)
65 #define ENC28J60_EHT2 (0x02|0x20)
66 #define ENC28J60_EHT3 (0x03|0x20)
67 #define ENC28J60_EHT4 (0x04|0x20)
68 #define ENC28J60_EHT5 (0x05|0x20)
69 #define ENC28J60_EHT6 (0x06|0x20)
70 #define ENC28J60_EHT7 (0x07|0x20)
71 #define ENC28J60_EPMM0 (0x08|0x20)
72 #define ENC28J60_EPMM1 (0x09|0x20)
73 #define ENC28J60_EPMM2 (0x0A|0x20)
74 #define ENC28J60_EPMM3 (0x0B|0x20)
75 #define ENC28J60_EPMM4 (0x0C|0x20)
76 #define ENC28J60_EPMM5 (0x0D|0x20)
77 #define ENC28J60_EPMM6 (0x0E|0x20)
78 #define ENC28J60_EPMM7 (0x0F|0x20)
79 #define ENC28J60_EPMCSL (0x10|0x20)
80 #define ENC28J60_EPMCSH (0x11|0x20)
81 #define ENC28J60_EPMOL (0x14|0x20)
82 #define ENC28J60_EPMOH (0x15|0x20)
83 #define ENC28J60_EWOLIE (0x16|0x20)
84 #define ENC28J60_EWOLIR (0x17|0x20)
85 #define ENC28J60_ERXFCON (0x18|0x20)
86 #define ENC28J60_EPKTCNT (0x19|0x20)
87 
88 // Bank #2
89 #define ENC28J60_MACON1 (0x00|0x40|0x80)
90 #define ENC28J60_MACON2 (0x01|0x40|0x80)
91 #define ENC28J60_MACON3 (0x02|0x40|0x80)
92 #define ENC28J60_MACON4 (0x03|0x40|0x80)
93 #define ENC28J60_MABBIPG (0x04|0x40|0x80)
94 #define ENC28J60_MAIPGL (0x06|0x40|0x80)
95 #define ENC28J60_MAIPGH (0x07|0x40|0x80)
96 #define ENC28J60_MACLCON1 (0x08|0x40|0x80)
97 #define ENC28J60_MACLCON2 (0x09|0x40|0x80)
98 #define ENC28J60_MAMXFLL (0x0A|0x40|0x80)
99 #define ENC28J60_MAMXFLH (0x0B|0x40|0x80)
100 #define ENC28J60_MAPHSUP (0x0D|0x40|0x80)
101 #define ENC28J60_MICON (0x11|0x40|0x80)
102 #define ENC28J60_MICMD (0x12|0x40|0x80)
103 #define ENC28J60_MIREGADR (0x14|0x40|0x80)
104 #define ENC28J60_MIWRL (0x16|0x40|0x80)
105 #define ENC28J60_MIWRH (0x17|0x40|0x80)
106 #define ENC28J60_MIRDL (0x18|0x40|0x80)
107 #define ENC28J60_MIRDH (0x19|0x40|0x80)
108 
109 // Bank #3
110 #define ENC28J60_MAADR5 (0x00|0x60|0x80)
111 #define ENC28J60_MAADR6 (0x01|0x60|0x80)
112 #define ENC28J60_MAADR3 (0x02|0x60|0x80)
113 #define ENC28J60_MAADR4 (0x03|0x60|0x80)
114 #define ENC28J60_MAADR1 (0x04|0x60|0x80)
115 #define ENC28J60_MAADR2 (0x05|0x60|0x80)
116 #define ENC28J60_EBSTSD (0x06|0x60)
117 #define ENC28J60_EBSTCON (0x07|0x60)
118 #define ENC28J60_EBSTCSL (0x08|0x60)
119 #define ENC28J60_EBSTCSH (0x09|0x60)
120 #define ENC28J60_MISTAT (0x0A|0x60|0x80)
121 #define ENC28J60_EREVID (0x12|0x60)
122 #define ENC28J60_ECOCON (0x15|0x60)
123 #define ENC28J60_EFLOCON (0x17|0x60)
124 #define ENC28J60_EPAUSL (0x18|0x60)
125 #define ENC28J60_EPAUSH (0x19|0x60)
126 
127 // PHY registers
128 #define ENC28J60_PHCON1 0x00
129 #define ENC28J60_PHSTAT1 0x01
130 #define ENC28J60_PHID1 0x02
131 #define ENC28J60_PHID2 0x03
132 #define ENC28J60_PHCON2 0x10
133 #define ENC28J60_PHSTAT2 0x11
134 #define ENC28J60_PHIE 0x12
135 #define ENC28J60_PHIR 0x13
136 #define ENC28J60_PHLCON 0x14
137 
138 /************************ enc28j60 register flags start **********************/
139 
140 // enc28j60 EIE Register flags
141 #define ENC28J60_EIE_INTIE 0x80
142 #define ENC28J60_EIE_PKTIE 0x40
143 #define ENC28J60_EIE_DMAIE 0x20
144 #define ENC28J60_EIE_LINKIE 0x10
145 #define ENC28J60_EIE_TXIE 0x08
146 #define ENC28J60_EIE_WOLIE 0x04
147 #define ENC28J60_EIE_TXERIE 0x02
148 #define ENC28J60_EIE_RXERIE 0x01
149 
150 // enc28j60 EIR Register flags
151 #define ENC28J60_EIR_PKTIF 0x40
152 #define ENC28J60_EIR_DMAIF 0x20
153 #define ENC28J60_EIR_LINKIF 0x10
154 #define ENC28J60_EIR_TXIF 0x08
155 #define ENC28J60_EIR_WOLIF 0x04
156 #define ENC28J60_EIR_TXERIF 0x02
157 #define ENC28J60_EIR_RXERIF 0x01
158 
159 // enc28j60 ESTAT Register flags
160 #define ENC28J60_ESTAT_INT 0x80
161 #define ENC28J60_ESTAT_LATECOL 0x10
162 #define ENC28J60_ESTAT_RXBUSY 0x04
163 #define ENC28J60_ESTAT_TXABRT 0x02
164 #define ENC28J60_ESTAT_CLKRDY 0x01
165 
166 // enc28j60 ECON2 Register flags
167 #define ENC28J60_ECON2_AUTOINC 0x80
168 #define ENC28J60_ECON2_PKTDEC 0x40
169 #define ENC28J60_ECON2_PWRSV 0x20
170 #define ENC28J60_ECON2_VRPS 0x08
171 
172 // enc28j60 ECON1 Register flags
173 #define ENC28J60_ECON1_TXRST 0x80
174 #define ENC28J60_ECON1_RXRST 0x40
175 #define ENC28J60_ECON1_DMAST 0x20
176 #define ENC28J60_ECON1_CSUMEN 0x10
177 #define ENC28J60_ECON1_TXRTS 0x08
178 #define ENC28J60_ECON1_RXEN 0x04
179 #define ENC28J60_ECON1_BSEL1 0x02
180 #define ENC28J60_ECON1_BSEL0 0x01
181 
182 // enc28j60 ERXFCON Register flags
183 #define ENC28J60_ERXFCON_UCEN 0x80
184 #define ENC28J60_ERXFCON_ANDOR 0x40
185 #define ENC28J60_ERXFCON_CRCEN 0x20
186 #define ENC28J60_ERXFCON_PMEN 0x10
187 #define ENC28J60_ERXFCON_MPEN 0x08
188 #define ENC28J60_ERXFCON_HTEN 0x04
189 #define ENC28J60_ERXFCON_MCEN 0x02
190 #define ENC28J60_ERXFCON_BCEN 0x01
191 
192 // enc28j60 MACON1 Register flags
193 #define ENC28J60_MACON1_LOOPBK 0x10
194 #define ENC28J60_MACON1_TXPAUS 0x08
195 #define ENC28J60_MACON1_RXPAUS 0x04
196 #define ENC28J60_MACON1_PASSALL 0x02
197 #define ENC28J60_MACON1_MARXEN 0x01
198 
199 // enc28j60 MACON3 Register flags
200 #define ENC28J60_MACON3_PADCFG2 0x80
201 #define ENC28J60_MACON3_PADCFG1 0x40
202 #define ENC28J60_MACON3_PADCFG0 0x20
203 #define ENC28J60_MACON3_TXCRCEN 0x10
204 #define ENC28J60_MACON3_PHDRLEN 0x08
205 #define ENC28J60_MACON3_HFRMLEN 0x04
206 #define ENC28J60_MACON3_FRMLNEN 0x02
207 #define ENC28J60_MACON3_FULDPX 0x01
208 
209 // EMC28J60 MACON4 Register flags
210 #define ENC28J60_MACON4_DEFER 0x40
211 #define ENC28J60_MACON4_BPEN 0x20
212 #define ENC28J60_MACON4_NOBKOFF 0x10
213 
214 // enc28j60 MICMD Register flags
215 #define ENC28J60_MICMD_MIISCAN 0x02
216 #define ENC28J60_MICMD_MIIRD 0x01
217 
218 // enc28j60 MISTAT Register flags
219 #define ENC28J60_MISTAT_NVALID 0x04
220 #define ENC28J60_MISTAT_SCAN 0x02
221 #define ENC28J60_MISTAT_BUSY 0x01
222 
223 // enc28j60 PHY PHCON1 Register flags
224 #define ENC28J60_PHCON1_PRST 0x8000
225 #define ENC28J60_PHCON1_PLOOPBK 0x4000
226 #define ENC28J60_PHCON1_PPWRSV 0x0800
227 #define ENC28J60_PHCON1_PDPXMD 0x0100
228 
229 // enc28j60 PHY PHSTAT1 Register flags
230 #define ENC28J60_PHSTAT1_PFDPX 0x1000
231 #define ENC28J60_PHSTAT1_PHDPX 0x0800
232 #define ENC28J60_PHSTAT1_LLSTAT 0x0004
233 #define ENC28J60_PHSTAT1_JBSTAT 0x0002
234 
235 // enc28j60 PHY PHCON2 Register flags
236 #define ENC28J60_PHCON2_FRCLINK 0x4000
237 #define ENC28J60_PHCON2_TXDIS 0x2000
238 #define ENC28J60_PHCON2_JABBER 0x0400
239 #define ENC28J60_PHCON2_HDLDIS 0x0100
240 
241 // enc28j60 PHY PHSTAT2 Register flags
242 #define ENC28J60_PHSTAT2_TXSTAT 0x2000
243 #define ENC28J60_PHSTAT2_RXSTAT 0x1000
244 #define ENC28J60_PHSTAT2_COLSTAT 0x0800
245 #define ENC28J60_PHSTAT2_LSTAT 0x0400
246 #define ENC28J60_PHSTAT2_DPXSTAT 0x0200
247 #define ENC28J60_PHSTAT2_PLRITY 0x0020
248 
249 /************************ enc28j60 rxstatus flags start **********************/
250 
251 // enc28j60 RX Buffer Status (enc28_60.rxstatus after enc28j60_readframe())
252 #define ENC28J60_RXSTATUS_LONGDROP_EVENT (1<<0)
253 #define ENC28J60_RXSTATUS_CARRIER_EVENT (1<<2)
254 #define ENC28J60_RXSTATUS_CRC_ERROR (1<<4)
255 #define ENC28J60_RXSTATUS_LENGTH_CHECK_ERROR (1<<5)
256 #define ENC28J60_RXSTATUS_LENGTH_OUT_OF_RANGE (1<<6)
257 #define ENC28J60_RXSTATUS_RECEIVE_OK (1<<7)
258 
259 #define ENC28J60_RXSTATUS_RECEIVE_MULTICAST (1<<8)
260 #define ENC28J60_RXSTATUS_RECEIVE_BROADCAST (1<<9)
261 #define ENC28J60_RXSTATUS_DRIBBLE_NIBBLE (1<<10)
262 #define ENC28J60_RXSTATUS_RECEIVE_CONTROL_FRAME (1<<11)
263 #define ENC28J60_RXSTATUS_RECEIVE_PAUSE_CONTROL_FRAME (1<<12)
264 #define ENC28J60_RXSTATUS_RECEIVE_UNKNOWN_OPCODE (1<<13)
265 #define ENC28J60_RXSTATUS_RECEIVE_VLAN_TYPE (1<<14)
266 // Custom code added to indicate that the frame length exceeded max_length and thus got trimmed.
267 #define ENC28J60_RXSTATUS_TRIMMED (1<<15)
268 
269 /************************ enc28j60 rxstatus flags start **********************/
270 
271 // enc28j60 TX Buffer Status (shifted bit positions, stored in
272 // enc28j60_txstatus.status)
273 #define ENC28J60_TXSTATUS_GET_COLLISION_COUNT(status) (status & 0xf)
274 #define ENC28J60_TXSTATUS_CRC_ERROR (1<<4)
275 #define ENC28J60_TXSTATUS_LENGTH_CHECK_ERROR (1<<5)
276 #define ENC28J60_TXSTATUS_LENGTH_OUT_OF_RANGE (1<<6)
277 #define ENC28J60_TXSTATUS_DONE (1<<7)
278 #define ENC28J60_TXSTATUS_MULTICAST (1<<8)
279 #define ENC28J60_TXSTATUS_BROADCAST (1<<9)
280 #define ENC28J60_TXSTATUS_PACKET_DEFER (1<<10)
281 #define ENC28J60_TXSTATUS_EXCESSIVE_DEFER (1<<11)
282 #define ENC28J60_TXSTATUS_EXCESSIVE_COLLISION (1<<12)
283 #define ENC28J60_TXSTATUS_LATE_COLLISION (1<<13)
284 #define ENC28J60_TXSTATUS_GIANT (1<<14)
285 #define ENC28J60_TXSTATUS_UNDERRUN (1<<15)
286 
287 #define ENC28J60_TXSTATUS_CONTROL_FRAME (1<<16)
288 #define ENC28J60_TXSTATUS_PAUSE_CONTROL_FRAME (1<<17)
289 #define ENC28J60_TXSTATUS_BACKPRESSURE_APPLIED (1<<18)
290 #define ENC28J60_TXSTATUS_VLAN_TAGGED_FRAME (1<<19)
291 
292 // enc28j60 TX Packet Control Byte flags
293 #define ENC28J60_PKTCTRL_PHUGEEN 0x08
294 #define ENC28J60_PKTCTRL_PPADEN 0x04
295 #define ENC28J60_PKTCTRL_PCRCEN 0x02
296 #define ENC28J60_PKTCTRL_POVERRIDE 0x01
297 
298 // SPI operation codes
299 #define ENC28J60_OP_READ_CTRL_REG 0x00
300 #define ENC28J60_OP_READ_BUF_MEM 0x3A
301 #define ENC28J60_OP_WRITE_CTRL_REG 0x40
302 #define ENC28J60_OP_WRITE_BUF_MEM 0x7A
303 #define ENC28J60_OP_BIT_FIELD_SET 0x80
304 #define ENC28J60_OP_BIT_FIELD_CLR 0xA0
305 #define ENC28J60_OP_SOFT_RESET 0xFF
306 
307 /************************ enc28j60 macros start ******************************/
308 
311 #define ENC28J60_MAX_FRAMELEN 1500
312 #define ENC28J60_MAX_FRAMELEN_ETH 1518
314 
316 #define ENC28J60_MEMORY_SIZE 0x2000
317 
318 
319 /************************ enc28j60 structs start *****************************/
320 
321 struct enc28j60;
322 typedef struct enc28j60 enc28j60;
323 
340 typedef struct __attribute__((__packed__)) enc28j60_header {
342  uint8_t opcode;
344 
348 typedef struct __attribute__((__packed__)) enc28j60_ethernet_header {
349  char dest[6];
350  char src[6];
351  uint16_t type;
352  char data[0];
354 
359 typedef struct enc28j60_txstatus {
361  uint32_t status;
368 
372 typedef void (*enc28j60_spi_callback)(
373  enc28j60 *instance,
374  int custom_error_code
375 );
376 
380 typedef struct enc28j60_init_struct {
382  char mac_address[6];
388 
389 /************************ enc28j60 current action start **********************/
390 
391 #define ENC28J60_ACTION_TX (0b00)
392 #define ENC28J60_ACTION_TX_REG (0b10)
393 #define ENC28J60_ACTION_RX (0b01)
394 #define ENC28J60_ACTION_RX_REG (0b11)
395 #define ENC28J60_ACTION_IS_RX(action) ((action) & 0b01)
396 #define ENC28J60_ACTION_IS_REG(action) ((action) & 0b10)
397 #define ENC28J60_ACTION_SET_RX_POINTER (0b100)
398 
399 #ifdef __DOXYGEN__
400 #include "enc28j60-struct.example.h"
401 #else
402 #include "enc28j60-struct.h"
403 #endif
404 
405 /************************ enc28j60 functions start ***************************/
406 
421 int enc28j60_blockingio(enc28j60 *ins, const char *tx, char *rx, unsigned length);
422 
430 int enc28j60_ensurebank(enc28j60 *ins, uint8_t bank);
431 
443 int enc28j60_io8(enc28j60 *ins, uint8_t op, uint8_t reg, uint8_t val, uint8_t *out);
444 
456 int enc28j60_io16(enc28j60 *ins, uint8_t op, uint8_t reg, uint16_t val, uint16_t *out);
457 
458 #if 0
459 
474 int enc28j60_o8asynctry(enc28j60 *ins, uint8_t op, uint8_t reg, uint8_t val, enc28j60_spi_callback on_finish);
475 
491 int enc28j60_o16asynctry(enc28j60 *ins, uint8_t op, uint8_t reg, uint16_t val, enc28j60_spi_callback on_finish);
492 #endif
493 
503 int enc28j60_read8bitreg(enc28j60 *ins, uint8_t reg, uint8_t *content);
504 
513 int enc28j60_write8bitreg(enc28j60 *ins, uint8_t reg, uint8_t content);
514 
523 int enc28j60_clear8bitreg(enc28j60 *ins, uint8_t reg, uint8_t content);
524 
533 int enc28j60_set8bitreg(enc28j60 *ins, uint8_t reg, uint8_t content);
534 
544 int enc28j60_read16bitreg(enc28j60 *ins, uint8_t reg, uint16_t *content);
545 
554 int enc28j60_write16bitreg(enc28j60 *ins, uint8_t reg, uint16_t content);
555 
564 int enc28j60_clear16bitreg(enc28j60 *ins, uint8_t reg, uint16_t content);
565 
574 int enc28j60_set16bitreg(enc28j60 *ins, uint8_t reg, uint16_t content);
575 
584 int enc28j60_readphyreg(enc28j60 *ins, uint8_t reg, uint16_t *content);
585 
594 int enc28j60_writephyreg(enc28j60 *ins, uint8_t reg, uint16_t content);
595 
603 int enc28j60_readrevision(enc28j60 *ins, uint8_t *rev);
604 
613 int enc28j60_softreset(enc28j60 *ins);
614 
625 
632 int enc28j60_init_bank(enc28j60 *ins);
633 
641 int enc28j60_init_mac(enc28j60 *ins, char mac_addr[6]);
642 
650 int enc28j60_writewritepointer(enc28j60 *ins, uint16_t ptr);
651 
661 int enc28j60_readwritepointer(enc28j60 *ins, uint16_t *ptr);
662 
670 int enc28j60_writereadpointer(enc28j60 *ins, uint16_t ptr);
671 
681 int enc28j60_readreadpointer(enc28j60 *ins, uint16_t *ptr);
682 
696 int enc28j60_init_txbuffer(enc28j60 *ins, uint16_t start, uint16_t length);
697 
698 #ifdef ENC28J60_HAS_ADVANCED_DRIVER
699 
717 int enc28j60_write(enc28j60 *ins,
718  uint16_t start_ptr, char *frame, uint16_t length,
719  enc28j60_spi_callback on_finish);
720 #else
721 
740 int enc28j60_write(enc28j60 *ins,
741  uint16_t start_ptr, enc28j60_header *frame, uint16_t length,
742  enc28j60_spi_callback on_finish);
743 #endif
744 
745 #ifdef ENC28J60_HAS_ADVANCED_DRIVER
746 
766 int enc28j60_writeframe(enc28j60 *ins, uint8_t control,
767  uint16_t start_ptr, char *frame, uint16_t length,
768  enc28j60_spi_callback on_finish);
769 #else
770 
791 int enc28j60_writeframe(enc28j60 *ins, uint8_t control,
792  uint16_t start_ptr, enc28j60_header *frame, uint16_t length,
793  enc28j60_spi_callback on_finish);
794 #endif
795 
808 int enc28j60_istx(enc28j60 *ins, bool *status);
809 
821 int enc28j60_jointx(enc28j60 *ins);
822 
833 
873 
908 int enc28j60_aftertx(enc28j60 *ins);
909 
924 int enc28j60_readtxstatus(enc28j60 *ins, uint16_t tx_start, uint16_t tx_length, enc28j60_txstatus *status);
925 
933 void enc28j60_decrementretries(unsigned *remaining_tries);
934 
949 bool enc28j60_shouldretransmit(enc28j60_txstatus *status, unsigned remaining_tries);
950 
994  uint16_t start_ptr, uint16_t length);
995 
996 #ifdef ENC28J60_HAS_ADVANCED_DRIVER
997 
1018 int enc28j60_read_try(enc28j60 *ins, char *frame, uint16_t length, enc28j60_spi_callback on_finish);
1019 #else
1020 
1041 int enc28j60_read_try(enc28j60 *ins, enc28j60_header *frame, uint16_t length, enc28j60_spi_callback on_finish);
1042 #endif
1043 
1044 #ifdef ENC28J60_HAS_ADVANCED_DRIVER
1045 
1063 int enc28j60_read(enc28j60 *ins, uint16_t ptr, char *rx, uint16_t length, enc28j60_spi_callback on_finish);
1064 #else
1065 
1083 int enc28j60_read(enc28j60 *ins, uint16_t ptr, enc28j60_header *frame, uint16_t length, enc28j60_spi_callback on_finish);
1084 #endif
1085 
1096 int enc28j60_readrxframescount(enc28j60 *ins, uint8_t *cnt);
1097 
1109 int enc28j60_init_rxbuffer(enc28j60 *ins, uint16_t start, uint16_t end);
1110 
1111 #ifdef ENC28J60_HAS_ADVANCED_DRIVER
1112 
1137 int enc28j60_readframe(enc28j60 *ins, char *frame, uint16_t max_length, enc28j60_spi_callback on_finish);
1138 #else
1139 
1164 int enc28j60_readframe(enc28j60 *ins, enc28j60_header *frame, uint16_t max_length, enc28j60_spi_callback on_finish);
1165 #endif
1166 
1177 
1194 
1195 #ifdef ENC28J60_HAS_ADVANCED_DRIVER
1196 
1232 int enc28j60_receiveframeblocking(enc28j60 *ins, char *frame, uint16_t max_length, enc28j60_tick timeout);
1233 #else
1234 
1270 int enc28j60_receiveframeblocking(enc28j60 *ins, enc28j60_header *frame, uint16_t max_length, enc28j60_tick timeout);
1271 #endif
1272 
1285 int enc28j60_enablerx(enc28j60 *ins);
1286 
1296 int enc28j60_disablerx(enc28j60 *ins);
1297 
1305 int enc28j60_discardcrcerrors(enc28j60 *ins, bool discard);
1306 
1315 int enc28j60_enablemulticast(enc28j60 *ins, bool enable);
1316 
1325 int enc28j60_enablebroadcast(enc28j60 *ins, bool enable);
1326 
1327 #ifdef __cplusplus
1328 }
1329 #endif
1330 
1331 #endif /* __ENC28J60_H */
int enc28j60_writephyreg(enc28j60 *ins, uint8_t reg, uint16_t content)
Write into PHY register.
Definition: enc28j60.c:212
int enc28j60_receiveframeblocking(enc28j60 *ins, char *frame, uint16_t max_length, enc28j60_tick timeout)
Wait until there is frame available in the buffer, read it into local memory, do cleanup and return...
Definition: enc28j60.c:1094
int enc28j60_readtxstatus(enc28j60 *ins, uint16_t tx_start, uint16_t tx_length, enc28j60_txstatus *status)
Reads the seven-byte-long status vector written after TXed frame.
Definition: enc28j60.c:835
int enc28j60_init_txbuffer(enc28j60 *ins, uint16_t start, uint16_t length)
Writes the ETXSTL:ETXSTH and ETXNDL:ETXNDH pointers.
Definition: enc28j60.c:370
int enc28j60_istx(enc28j60 *ins, bool *status)
Checks whenever the enc28j60 still transmits a frame and writes the corresponding status into *status...
Definition: enc28j60.c:753
int enc28j60_readframe(enc28j60 *ins, char *frame, uint16_t max_length, enc28j60_spi_callback on_finish)
Reads six-bytes-long header and then reads the frame of given max length into memory location pointed...
Definition: enc28j60.c:975
int enc28j60_writeframe(enc28j60 *ins, uint8_t control, uint16_t start_ptr, char *frame, uint16_t length, enc28j60_spi_callback on_finish)
Writes control byte and entire frame into enc28j60&#39;s memory.
Definition: enc28j60.c:661
uint16_t enc28j60_tick
TODO: Change it to uint32_t or uint8_t, depending on the timer resolution.
Definition: enc28j60-struct.example.h:42
int enc28j60_read16bitreg(enc28j60 *ins, uint8_t reg, uint16_t *content)
Read value of given 16-bit register and store it in *content if not content is not null...
Definition: enc28j60.c:169
void(* enc28j60_spi_callback)(enc28j60 *instance, int custom_error_code)
Callback used internally and externally.
Definition: enc28j60.h:372
int enc28j60_readrxframescount(enc28j60 *ins, uint8_t *cnt)
Reads the number of received frames waiting to be processed in the buffer memory (reds the EPKTCNT re...
Definition: enc28j60.c:1070
int enc28j60_readphyreg(enc28j60 *ins, uint8_t reg, uint16_t *content)
Read from PHY register.
Definition: enc28j60.c:194
struct enc28j60_init_struct enc28j60_init_struct
Structure used for initialization of the enc28j60.
void enc28j60_decrementretries(unsigned *remaining_tries)
Decrements *remaining_tries (if the pointer is not null) by one.
Definition: enc28j60.c:822
int enc28j60_jointx(enc28j60 *ins)
Waits until the transmission (if any in progress) finishes and then returns (or in case of unrepairab...
Definition: enc28j60.c:763
int enc28j60_io16(enc28j60 *ins, uint8_t op, uint8_t reg, uint16_t val, uint16_t *out)
Performs given IO operation on given register 16bit until it succeeds or fails with unrepairable erro...
Definition: enc28j60.c:108
int enc28j60_readwritepointer(enc28j60 *ins, uint16_t *ptr)
Reads the content of EWRPTL:EWRPTH register into *ptr if ptr is not null.
Definition: enc28j60.c:429
int enc28j60_init_bank(enc28j60 *ins)
Reads the currently selected bank into ins->bank.
Definition: enc28j60.c:365
int enc28j60_enablebroadcast(enc28j60 *ins, bool enable)
Enable reception of frames with broadcast destination address.
Definition: enc28j60.c:289
int enc28j60_set16bitreg(enc28j60 *ins, uint8_t reg, uint16_t content)
Sets bits given by content in given 16-bit register.
Definition: enc28j60.c:190
Structure that contains data parsed from status footer appended by enc28j60 after frame that was tran...
Definition: enc28j60.h:359
int enc28j60_blockingio(enc28j60 *ins, const char *tx, char *rx, unsigned length)
Performs IO on enc28j60.
Definition: enc28j60.c:38
Structure that has to prefix any variable length data when not using advanced SPI driver (that is whe...
Definition: enc28j60.h:340
Part of enc28j60 driver.
int enc28j60_readrevision(enc28j60 *ins, uint8_t *rev)
Reads the revision number into *rev.
Definition: enc28j60.c:224
int enc28j60_ensurebank(enc28j60 *ins, uint8_t bank)
Ensures that correct bank is currently selected.
Definition: enc28j60.c:72
int enc28j60_init(enc28j60 *ins, enc28j60_init_struct *init)
Initializes the enc28j60.
Definition: enc28j60.c:304
bool is_full_duplex
Support full duplex?
Definition: enc28j60.h:384
int enc28j60_read8bitreg(enc28j60 *ins, uint8_t reg, uint8_t *content)
Read value of given 8-bit register and store it in *content if not content is not null...
Definition: enc28j60.c:153
int enc28j60_softreset(enc28j60 *ins)
Sends soft-reset and waits until the enc28j60 is operational again.
Definition: enc28j60.c:236
bool discard_crc_errors
Discard frames with invalid CRC?
Definition: enc28j60.h:386
int enc28j60_writewritepointer(enc28j60 *ins, uint16_t ptr)
Writes the EWRPTL:EWRPTH registers with given value.
Definition: enc28j60.c:425
int enc28j60_advancerxreadpointer(enc28j60 *ins)
Writes the ERXRDPTL:ERXRDPTH registers-pointer with appropriate value to free up space in the buffer...
Definition: enc28j60.c:1074
struct enc28j60_header enc28j60_header
Structure that has to prefix any variable length data when not using advanced SPI driver (that is whe...
int enc28j60_disablerx(enc28j60 *ins)
Disable reception of frames.
Definition: enc28j60.c:1167
int enc28j60_write(enc28j60 *ins, uint16_t start_ptr, char *frame, uint16_t length, enc28j60_spi_callback on_finish)
Writes entire frame into enc28j60&#39;s memory.
Definition: enc28j60.c:592
int enc28j60_finishreadframe(enc28j60 *ins)
Writes the ERXRDPTL:ERXRDPTH registers-pointer with appropriate value to free up space in the buffer ...
Definition: enc28j60.c:1061
int enc28j60_readreadpointer(enc28j60 *ins, uint16_t *ptr)
Reads the content of ERDPTL:ERDPTH register into *ptr if ptr is not null.
Definition: enc28j60.c:437
int enc28j60_writereadpointer(enc28j60 *ins, uint16_t ptr)
Writes the ERDPTL:ERDPTH registers with given value.
Definition: enc28j60.c:433
int enc28j60_transmitframeblocking(enc28j60 *ins, uint16_t start_ptr, uint16_t length)
Writes an ethernet frame of given length into enc28j60&#39;s memory starting at given pointer and transmi...
Definition: enc28j60.c:856
int enc28j60_set8bitreg(enc28j60 *ins, uint8_t reg, uint8_t content)
Sets bits given by content in given 8-bit register.
Definition: enc28j60.c:165
int enc28j60_read(enc28j60 *ins, uint16_t ptr, char *rx, uint16_t length, enc28j60_spi_callback on_finish)
Try to read from enc28j60&#39;s memory.
Definition: enc28j60.c:916
int enc28j60_clear16bitreg(enc28j60 *ins, uint8_t reg, uint16_t content)
Clears bits given by content from given 16-bit register.
Definition: enc28j60.c:186
int enc28j60_discardcrcerrors(enc28j60 *ins, bool discard)
Discard frames that have invalid CRC checksum present.
Definition: enc28j60.c:297
int enc28j60_enablemulticast(enc28j60 *ins, bool enable)
Enable reception of frames with multicast destination address.
Definition: enc28j60.c:281
uint16_t total_bytes_transmitted
Total bytes in frame not counting collided bytes.
Definition: enc28j60.h:366
struct enc28j60_txstatus enc28j60_txstatus
Structure that contains data parsed from status footer appended by enc28j60 after frame that was tran...
bool enc28j60_shouldretransmit(enc28j60_txstatus *status, unsigned remaining_tries)
Checks for late collision and returns true if late collision happened and remaining_tries is not zero...
Definition: enc28j60.c:828
int enc28j60_write8bitreg(enc28j60 *ins, uint8_t reg, uint8_t content)
Write given value content into given 8-bit register.
Definition: enc28j60.c:157
int enc28j60_read_try(enc28j60 *ins, char *frame, uint16_t length, enc28j60_spi_callback on_finish)
Try to read from enc28j60&#39;s memory.
Definition: enc28j60.c:900
uint8_t opcode
Opcode.
Definition: enc28j60.h:342
int enc28j60_write16bitreg(enc28j60 *ins, uint8_t reg, uint16_t content)
Write given value content into given 16-bit register.
Definition: enc28j60.c:182
int enc28j60_init_mac(enc28j60 *ins, char mac_addr[6])
Initializes the MAC address.
Definition: enc28j60.c:401
int enc28j60_io8(enc28j60 *ins, uint8_t op, uint8_t reg, uint8_t val, uint8_t *out)
Performs given IO operation on given 8-bit register until it succeeds or fails with unrepairable erro...
Definition: enc28j60.c:93
int enc28j60_clear8bitreg(enc28j60 *ins, uint8_t reg, uint8_t content)
Clears bits given by content from given 8-bit register.
Definition: enc28j60.c:161
Ethernet header.
Definition: enc28j60.h:348
Structure used for initialization of the enc28j60.
Definition: enc28j60.h:380
struct enc28j60_ethernet_header enc28j60_ethernet_header
Ethernet header.
int enc28j60_init_rxbuffer(enc28j60 *ins, uint16_t start, uint16_t end)
Claims space for RX buffer.
Definition: enc28j60.c:384
int enc28j60_aftertx(enc28j60 *ins)
Should be called when transmission finishes in order to avoid bug described in errata #12...
Definition: enc28j60.c:803
int enc28j60_cleartxflags(enc28j60 *ins)
Clears EIR.TXIF and EIR.TXERIF flags.
Definition: enc28j60.c:793
uint32_t status
Status vector. Use ENC28J60_TXSTATUS_* flags for check.
Definition: enc28j60.h:361
Structure holding important informations about enc28j60 and about the latest transmission performed...
Definition: enc28j60-struct.example.h:60
uint16_t transmit_byte_count
Total bytes transmitted on the wire for the current packet, including all bytes from collided attempt...
Definition: enc28j60.h:364
int enc28j60_enablerx(enc28j60 *ins)
Enable reception of frames.
Definition: enc28j60.c:1163
int enc28j60_transmitframe(enc28j60 *ins)
Sets the ECON1.TXRTS flag in order to start transmission.
Definition: enc28j60.c:798