This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
enc28j60.cpp
752 lines (614 loc) · 16.7 KB
/
enc28j60.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/**
* @file enc28j60.cpp
*
* Definitions for the ENC28J60 class
*/
#include <enc28j60.h>
/* Macros for accessing registers.
* These macros should be used instead of calling the functions directly.
* They simply pass the register's bank as an argument, so the caller
* doesn't have to deal with that.
*/
#define READ_REG(reg) this->ReadRegister(reg, reg ## _BANK)
#define WRITE_REG(reg, value) this->WriteRegister(reg, reg ## _BANK, value)
#define READ_MREG(reg) this->ReadMIIRegister(reg, reg ## _BANK)
#define SET_REG_BITS(reg, mask) this->BitsFieldSet(reg, reg ## _BANK, mask)
#define CLEAR_REG_BITS(reg, mask) this->BitsFieldClear(reg, reg ## _BANK, mask)
// uIP library's buffer
#define BUF ((struct uip_eth_hdr *)uip_buf)
// Beginning/end of the TX/RX space
#define TX_START (0x1FFF - 0x600)
#define RX_END (TX_START-1)
namespace ENCJ_STELLARIS
{
ENC28J60::ENC28J60
( const uint8_t *mac
, uint32_t CSport
, uint32_t CSpin
, uint32_t CSperiph
, uint32_t INTport
, uint32_t INTpin
, uint32_t INTperiph
, uint32_t INTassign
, uint32_t RESETport
, uint32_t RESETpin
, uint32_t RESETperiph
, uint32_t SSIbase
, uint32_t SSIperiph
, uint32_t SSIGPIOperiph
, uint32_t SSIGPIOport
, uint32_t SSIGPIOpins
, uint32_t SSICLK
, uint32_t SSIRX
, uint32_t SSITX
)
{
this->InitSPI
( SSIbase
, SSIperiph
, SSIGPIOperiph
, SSIGPIOport
, SSIGPIOpins
, SSICLK
, SSIRX
, SSITX
);
this->InitPort
( CSport
, CSpin
, CSperiph
, INTport
, INTpin
, INTperiph
, RESETport
, RESETpin
, RESETperiph
);
this->InitConfig(mac);
this->InitInterrupt
( INTport
, INTpin
, INTassign
);
}
/**
* Config the ENCJ chip's registers.
*/
void ENC28J60::InitConfig(const uint8_t *mac)
{
// Config
this->nextPacket = 0x0000;
this->Reset();
// Check the ESTAT read bit from the chip
uint8_t reg;
do {
reg = READ_REG(ENC_ESTAT);
MAP_SysCtlDelay(3333200);
#ifdef _DEBUG
printf("ENC_ESTAT value: %x\n", reg);
#endif
}
while ((reg & ENC_ESTAT_CLKRDY) == 0);
// Chip has stated it's clock is stabilized, ready to continue
this->SwitchBank(0);
#ifdef _DEBUG
printf("Econ: %x\n", READ_REG(ENC_ECON1));
printf("Silicon Revision: %d\n", READ_REG(ENC_EREVID));
#endif
// Reset transmit logic
SET_REG_BITS(ENC_ECON1, ENC_ECON1_TXRST);
// Clear packet recieve bit
CLEAR_REG_BITS(ENC_ECON1, ENC_ECON1_RXEN);
// Enable automatic buffer pointer increment
SET_REG_BITS(ENC_ECON2, ENC_ECON2_AUTOINC);
this->SetRXMemoryArea(0x000, RX_END);
// Configure DPXSTAT for full-duplex operation
uint16_t phyreg = this->ReadPHY(ENC_PHSTAT2);
phyreg &= ~ENC_PHSTAT2_DPXSTAT;
this->WritePHY(ENC_PHSTAT2, phyreg);
// Configure PDPXMD for full-duplex operation
phyreg = this->ReadPHY(ENC_PHCON1);
phyreg &= ~ENC_PHCON_PDPXMD;
this->WritePHY(ENC_PHCON1, phyreg);
/* Section 6.5, MAC initialization steps */
#ifdef _DEBUG
printf("Setting MAC: %x:%x:%x:%x:%x:%x\n", mac[0], mac[1], mac[2],
mac[3], mac[4], mac[5]);
#endif
this->SetMACAddress(mac);
// Set up recieve filter
// Allow broadcasts, multicast, unicast, and invalid CRCs are dumped
WRITE_REG
( ENC_ERXFCON
, ENC_ERXFCON_UCEN
| ENC_ERXFCON_CRCEN
| ENC_ERXFCON_BCEN
| ENC_ERXFCON_MCEN
);
// Allow MAC to use TX/RX pause frames, enable MAC packet receive.
WRITE_REG
( ENC_MACON1
, ENC_MACON1_TXPAUS | ENC_MACON1_RXPAUS | ENC_MACON1_MARXEN
);
// All short frames are zero-padded to 60 bytes and CRC'ed
// MAC will append a CRC
// Frame length checking enabled
WRITE_REG
( ENC_MACON3
, (0x1 << ENC_MACON3_PADCFG_SHIFT)
| ENC_MACON3_TXRCEN
| ENC_MACON3_FRMLNEN
);
// Max frame length set to 0x05EE
WRITE_REG(ENC_MAMXFLL, 1518 & 0xFF); // Low 0xEE
WRITE_REG(ENC_MAMXFLH, (1518 >> 8) & 0xFF); // High 0x05
// MAC initialization, section 6.5 steps 5-7
WRITE_REG(ENC_MABBIPG, 0x12); // Back-to-back packet gap
WRITE_REG(ENC_MAIPGL, 0x12); // Non-btb inter-packet gap low
WRITE_REG(ENC_MAIPGH, 0x0C); // Non-btb inter-packet gap high
// Enable interrupts, and enable packet recieve pending
SET_REG_BITS(ENC_EIE, ENC_EIE_INTIE | ENC_EIE_PKTIE);
// Clear the reset status on TX/RX logic
CLEAR_REG_BITS(ENC_ECON1, ENC_ECON1_TXRST | ENC_ECON1_RXRST);
// Enable receiving packets
SET_REG_BITS(ENC_ECON1, ENC_ECON1_RXEN);
#ifdef _DEBUG
uint8_t mc[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
enc_get_mac_addr(mc);
printf("Mac addr set to: %x:%x:%x:%x:%x:%x\n", mc[0], mc[1], mc[2],
mc[3], mc[4], mc[5]);
#endif
}
/**
* Enable the SSI connection for SPI to the ENC chip
*
* @param SSIbase is the only value we care about after this initialization
* and as such it is stored in the object for later use in the SPISend
* function.
*/
void ENC28J60::InitSPI
( uint32_t SSIbase
, uint32_t SSIperiph
, uint32_t SSIGPIOperiph
, uint32_t SSIGPIOport
, uint32_t SSIGPIOpins
, uint32_t SSICLK
, uint32_t SSIRX
, uint32_t SSITX
)
{
MAP_SysCtlPeripheralEnable(SSIGPIOperiph);
MAP_SysCtlPeripheralEnable(SSIperiph);
MAP_GPIOPinConfigure(SSICLK);
MAP_GPIOPinConfigure(SSIRX);
MAP_GPIOPinConfigure(SSITX);
MAP_GPIOPinTypeSSI(SSIGPIOport, SSIGPIOpins);
MAP_SSIConfigSetExpClk
( SSIbase
, MAP_SysCtlClockGet()
, SSI_FRF_MOTO_MODE_0
, SSI_MODE_MASTER
, 1000000
, 8
);
MAP_SSIEnable(SSIbase);
this->SSIbase = SSIbase;
// Make sure the SSI FIFO is empty?
unsigned long b;
while(MAP_SSIDataGetNonBlocking(this->SSIbase, &b)) {}
}
/**
* Initialize all of the ports and pins that the ENC will use
*
* We care about the ports and pins for each one so that we may call them
* later on, so those are stored for later use
*/
void ENC28J60::InitPort
( uint32_t CSport
, uint32_t CSpin
, uint32_t CSperiph
, uint32_t INTport
, uint32_t INTpin
, uint32_t INTperiph
, uint32_t RESETport
, uint32_t RESETpin
, uint32_t RESETperiph
)
{
// CSport/pin
MAP_SysCtlPeripheralEnable(CSport);
MAP_GPIOPinTypeGPIOOutput(CSport, CSpin);
this->CSpin = CSpin;
this->CSport = CSport;
// INTport/pin
MAP_SysCtlPeripheralEnable(INTperiph);
MAP_GPIOPinTypeGPIOOutput(INTport, INTpin);
this->INTpin = INTpin;
this->INTport = INTport;
// RESETport/pin
MAP_SysCtlPeripheralEnable(RESETperiph);
MAP_GPIOPinTypeGPIOOutput(RESETport, RESETpin);
this->INTpin = RESETpin;
this->RESETport = RESETport;
// Bring CS high
MAP_GPIOPinWrite(this->CSport, this->CSpin, this->CSpin);
}
/**
* Enable the processor interrupt for the INT pin
*
*/
void ENC28J60::InitInterrupt
( uint32_t INTport
, uint32_t INTpin
, uint32_t INTassign
)
{
MAP_IntEnable(INTassign);
MAP_IntMasterEnable();
// Disable sleep interrupts (power saving?)
MAP_SysCtlPeripheralClockGating(false);
MAP_GPIOIntTypeSet(INTport, INTpin, GPIO_FALLING_EDGE);
MAP_GPIOPinIntClear(INTport, INTpin);
MAP_GPIOPinIntEnable(INTport, INTpin);
}
/**
* Handle a packet recieved interrupt request from the ENC
*/
void ENC28J60::Interrupt()
{
uint8_t reg = READ_REG(ENC_EIR);
if (reg & ENC_EIR_PKTIF)
{
while (READ_REG(ENC_EPKTCNT) > 0)
{
this->Receive();
}
}
}
/**
* Recieve a single packet. Contents will be placed in uip_buf, and uIP is
* called as appropriate
*
* @todo: Decouple this from uIP, the IP stack should be elsewhere.
* Possibly have this return a struct with the appropriate data? Difficult
* as it needs to actively read the information
*/
void ENC28J60::Receive()
{
uint8_t header[6];
uint8_t *status = header + 2;
// Set the read pointer to the next packet location
WRITE_REG(ENC_ERDPTL, this->nextPacket & 0xFF); // Low byte
WRITE_REG(ENC_ERDPTH, (this->nextPacket >> 8) & 0xFF); // High byte
this->RBM(header, 6);
// Update next packet pointer
this->nextPacket = header[0] | (header[1] << 8);
// TODO: figure out what this does and comment as such
uint16_t data_count = status[0] | (status[1] << 8);
if (status[2] & (1 << 7))
{
uip_len = data_count;
this->RBM(uip_buf, data_count);
if (BUF->type == htons(UIP_ETHTYPE_IP))
{
uip_arp_ipin();
uip_input();
if (uip_len > 0)
{
uip_arp_out();
this->Send(uip_buf, uip_len);
uip_len = 0;
}
}
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
{
uip_arp_arpin();
if(uip_len > 0)
{
this->Send(uip_buf, uip_len);
uip_len = 0;
}
}
}
uint16_t erxst = READ_REG(ENC_ERXSTL) | (READ_REG(ENC_ERXSTH) << 8);
// Mark packets as read
if (this->nextPacket == erxst)
{
WRITE_REG(ENC_ERXRDPTL, READ_REG(ENC_ERXNDL));
WRITE_REG(ENC_ERXRDPTH, READ_REG(ENC_ERXNDH));
}
else
{
WRITE_REG(ENC_ERXRDPTL, (this->nextPacket - 1) & 0xFF);
WRITE_REG(ENC_ERXRDPTH, ((this->nextPacket - 1) >> 8) & 0xFF);
}
SET_REG_BITS(ENC_ECON2, ENC_ECON2_PKTDEC);
}
/**
* Send a packet. Function will block until transmission is complete.
* Returns true if transmission was successful, false otherwise.
*/
bool ENC28J60::Send(const uint8_t *buf, uint16_t count)
{
WRITE_REG(ENC_ETXSTL, TX_START & 0xFF);
WRITE_REG(ENC_ETXSTH, TX_START >> 8);
WRITE_REG(ENC_EWRPTL, TX_START & 0xFF);
WRITE_REG(ENC_EWRPTH, TX_START >> 8);
#ifdef _DEBUG
printf("dest: %X:%X:%X:%X:%X:%X\n", BUF->dest.addr[0], BUF->dest.addr[1],
BUF->dest.addr[2], BUF->dest.addr[3], BUF->dest.addr[4],
BUF->dest.addr[5]);
printf("src : %X:%X:%X:%X:%X:%X\n", BUF->src.addr[0], BUF->src.addr[1],
BUF->src.addr[2], BUF->src.addr[3], BUF->src.addr[4],
BUF->src.addr[5]);
printf("Type: %X\n", htons(BUF->type));
#endif
uint8_t control = 0x00;
this->WBM(&control, 1);
this->WBM(buf, count);
uint16_t txEnd = TX_START + count;
WRITE_REG(ENC_ETXNDL, txEnd & 0xFF);
WRITE_REG(ENC_ETXNDH, txEnd >> 8);
// Eratta 12
SET_REG_BITS(ENC_ECON1, ENC_ECON1_TXRST);
CLEAR_REG_BITS(ENC_ECON1, ENC_ECON1_TXRST);
CLEAR_REG_BITS(ENC_EIR, ENC_EIR_TXIF);
SET_REG_BITS(ENC_ECON1, ENC_ECON1_TXRTS);
// Wait for busy signal to clear
uint8_t r;
do
{
r = READ_REG(ENC_ECON1);
}
while ((r & ENC_ECON1_TXRTS) == 0);
// Read status bits
uint8_t status[7];
txEnd++;
WRITE_REG(ENC_ERDPTL, txEnd & 0xFF);
WRITE_REG(ENC_ERDPTH, txEnd >> 8);
this->RBM(status, 7);
//uint16_t transmit_count = status[0] | (status[1] << 8);
bool retStatus = false;
if (status[2] & 0x80)
{
// Transmit OK
retStatus = true;
#ifdef _DEBUG
printf("Transmit OK\n");
#endif
}
return retStatus;
}
/**
* Perform a soft reset of the ENC chip
*/
void ENC28J60::Reset()
{
MAP_GPIOPinWrite(this->RESETport, this->RESETpin, 0);
this->SPISend(0xFF);
MAP_GPIOPinWrite(this->RESETport, this->RESETpin, this->RESETpin);
}
/**
* Send an SPI value and return the result
*/
uint8_t ENC28J60::SPISend(uint8_t msg)
{
unsigned long val;
MAP_SSIDataPut(this->SSIbase, msg);
MAP_SSIDataGet(this->SSIbase, &val);
return (uint8_t)val;
}
// Read Control Register
uint8_t ENC28J60::RCR(uint8_t reg)
{
MAP_GPIOPinWrite(this->CSport, this->CSpin, 0);
this->SPISend(reg);
uint8_t b = SPISend(0xFF);
MAP_GPIOPinWrite(this->CSport, this->CSpin, this->CSpin);
return b;
}
/**
* Read Control Register for MAC and MII registers.
* Reading MAC and MII registers produces an initial dummy
* byte. Presumably because it takes longer to fetch the values
* of those registers.
*/
uint8_t ENC28J60::RCRM(uint8_t reg)
{
MAP_GPIOPinWrite(this->CSport, this->CSpin, 0);
this->SPISend(reg);
this->SPISend(0xFF);
uint8_t b = this->SPISend(0xFF);
MAP_GPIOPinWrite(this->CSport, this->CSpin, this->CSpin);
return b;
}
// Write Control Register
void ENC28J60::WCR(uint8_t reg, uint8_t val)
{
MAP_GPIOPinWrite(this->CSport, this->CSpin, 0);
this->SPISend(0x40 | reg);
this->SPISend(val);
MAP_GPIOPinWrite(this->CSport, this->CSpin, this->CSpin);
}
// Read Buffer Memory
void ENC28J60::RBM(uint8_t *buf, uint16_t len)
{
MAP_GPIOPinWrite(this->CSport, this->CSpin, 0);
this->SPISend(0x20 | 0x1A);
for (int i = 0; i < len; ++i)
{
*buf = this->SPISend(0xFF);
++buf;
}
MAP_GPIOPinWrite(this->CSport, this->CSpin, this->CSpin);
}
// Write Buffer Memory
void ENC28J60::WBM(const uint8_t *buf, uint16_t len)
{
MAP_GPIOPinWrite(this->CSport, this->CSpin, 0);
this->SPISend(0x60 | 0x1A);
for (int i = 0; i < len; ++i)
{
this->SPISend(*buf);
++buf;
}
MAP_GPIOPinWrite(this->CSport, this->CSpin, this->CSpin);
}
/**
* Bit Field Set.
* Set the bits of argument 'mask' in the register 'reg'.
* Not valid for MAC and MII registers.
*/
void ENC28J60::BFS(uint8_t reg, uint8_t mask)
{
MAP_GPIOPinWrite(this->CSport, this->CSpin, 0);
this->SPISend(0x80 | reg);
this->SPISend(mask);
MAP_GPIOPinWrite(this->CSport, this->CSpin, this->CSpin);
}
// Bit Field Clear
void ENC28J60::BFC(uint8_t reg, uint8_t mask)
{
MAP_GPIOPinWrite(this->CSport, this->CSpin, 0);
this->SPISend(0xA0 | reg);
this->SPISend(mask);
MAP_GPIOPinWrite(this->CSport, this->CSpin, this->CSpin);
}
// Switch active memory bank
void ENC28J60::SwitchBank(uint8_t new_bank)
{
if (new_bank == this->activeBank || new_bank == ANY_BANK)
{
return;
}
uint8_t econ1 = this->RCR(ENC_ECON1);
econ1 &= ~ENC_ECON1_BSEL_MASK;
econ1 |= (new_bank & ENC_ECON1_BSEL_MASK) << ENC_ECON1_BSEL_SHIFT;
this->WCR(ENC_ECON1, econ1);
this->activeBank = new_bank;
}
// Read a register's contents
uint8_t ENC28J60::ReadRegister(uint8_t reg, uint8_t bank)
{
if (bank != this->activeBank)
{
this->SwitchBank(bank);
}
return this->RCR(reg);
}
// Read a MII register's contents
uint8_t ENC28J60::ReadMIIRegister(uint8_t reg, uint8_t bank)
{
if (bank != this->activeBank)
{
this->SwitchBank(bank);
}
return this->RCRM(reg);
}
// Write to a register
void ENC28J60::WriteRegister(uint8_t reg, uint8_t bank, uint8_t value)
{
if (bank != this->activeBank)
{
this->SwitchBank(bank);
}
this->WCR(reg, value);
}
// Batch bit field set
void ENC28J60::BitsFieldSet(uint8_t reg, uint8_t bank, uint8_t mask)
{
if (bank != this->activeBank)
{
this->SwitchBank(bank);
}
this->BFS(reg, mask);
}
// Batch bit field clear
void ENC28J60::BitsFieldClear(uint8_t reg, uint8_t bank, uint8_t mask)
{
if (bank != this->activeBank)
{
this->SwitchBank(bank);
}
this->BFC(reg, mask);
}
/**
* Read value from PHY address.
* Reading procedure is described in ENC28J60 datasheet
* section 3.3.
*/
uint16_t ENC28J60::ReadPHY(uint8_t address)
{
/*Write the address of the PHY register to read from into the
MMIREGADR register. */
WRITE_REG(ENC_MIREGADR, address);
/* Set the MICMD.MIIRD bit. The read operation begins and the
MISTAT.BUSY bit is set. */
WRITE_REG(ENC_MICMD, 0x1);
/* wait 10.24 us. Poll the MISTAT.BUSY bit to be certain that the
operation is complete. While busy, the host controller should not
start any MIISCAN operations or write to the MIWRH register.
When the MAC has obtained the register contents, the BUSY bit will
clear itself. */
MAP_SysCtlDelay(((MAP_SysCtlClockGet()/3)/1000));
uint8_t stat;
do
{
stat = READ_MREG(ENC_MISTAT);
}
while (stat & ENC_MISTAT_BUSY);
/* Clear the MICMD.MIIRD bit. */
WRITE_REG(ENC_MICMD, 0x00);
/* Read the desired data from the MIRDL and MIRDH registers. The order
that these bytes are accessed is unimportant. */
uint16_t reg;
reg = READ_MREG(ENC_MIRDL) & 0xFF;
reg |= READ_MREG(ENC_MIRDH) << 8;
return reg;
}
// PHY memory write
void ENC28J60::WritePHY(uint8_t address, uint16_t value)
{
WRITE_REG(ENC_MIREGADR, address);
WRITE_REG(ENC_MIWRL, value & 0xFF);
WRITE_REG(ENC_MIWRH, value >> 8);
MAP_SysCtlDelay(((MAP_SysCtlClockGet()/3)/1000));
// Wait for busy status to be clear before continuing
uint8_t stat;
do
{
stat = READ_MREG(ENC_MISTAT);
}
while (stat & ENC_MISTAT_BUSY);
}
// Set recieve memory area
void ENC28J60::SetRXMemoryArea(uint16_t startAddr, uint16_t endAddr)
{
WRITE_REG(ENC_ERXSTL, startAddr & 0xFF);
WRITE_REG(ENC_ERXSTH, (startAddr >> 8) & 0xFFF);
WRITE_REG(ENC_ERXNDL, endAddr & 0xFF);
WRITE_REG(ENC_ERXNDH, (endAddr >> 8) & 0xFFF);
WRITE_REG(ENC_ERXRDPTL, startAddr & 0xFF);
WRITE_REG(ENC_ERXRDPTH, (startAddr >> 8) & 0xFFF);
}
// Set MAC address
void ENC28J60::SetMACAddress(const uint8_t *macAddr)
{
WRITE_REG(ENC_MAADR1, macAddr[0]);
WRITE_REG(ENC_MAADR2, macAddr[1]);
WRITE_REG(ENC_MAADR3, macAddr[2]);
WRITE_REG(ENC_MAADR4, macAddr[3]);
WRITE_REG(ENC_MAADR5, macAddr[4]);
WRITE_REG(ENC_MAADR6, macAddr[5]);
}
// Get MAC address
void ENC28J60::GetMACAddress(uint8_t *macAddr)
{
macAddr[0] = READ_REG(ENC_MAADR1);
macAddr[1] = READ_REG(ENC_MAADR2);
macAddr[2] = READ_REG(ENC_MAADR3);
macAddr[3] = READ_REG(ENC_MAADR4);
macAddr[4] = READ_REG(ENC_MAADR5);
macAddr[5] = READ_REG(ENC_MAADR6);
}
} // ENCJ_STELLARIS