Skip to content

Commit e26876b

Browse files
author
virusbrain
committed
Introduced two new methods:
powerOff(): This will put the enc28j60 module into the sleep mode. powerOn(): This will wake up the enc28j60 module back from sleep mode. Usage: void loop() { Ethernet.maintain(); [...] Ethernet.getNetwork().powerOff(); }
1 parent de71184 commit e26876b

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

UIPEthernet.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ UIPEthernetClass::upper_layer_chksum(uint8_t proto)
410410
return (sum == 0) ? 0xffff : htons(sum);
411411
}
412412

413+
Enc28J60Network
414+
UIPEthernetClass::getNetwork()
415+
{
416+
return network;
417+
}
418+
413419
uint16_t
414420
uip_ipchksum(void)
415421
{

UIPEthernet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class UIPEthernetClass
8181
IPAddress gatewayIP();
8282
IPAddress dnsServerIP();
8383

84+
Enc28J60Network getNetwork();
85+
8486
private:
8587
IPAddress _dnsServerAddress;
8688
DhcpClass* _dhcp;

utility/Enc28J60Network.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,22 @@ Enc28J60Network::chksum(uint16_t sum, memhandle handle, memaddress pos, uint16_t
552552
/* Return sum in host byte order. */
553553
return sum;
554554
}
555+
556+
void
557+
Enc28J60Network::powerOff()
558+
{
559+
writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_RXEN);
560+
delay(50);
561+
writeOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_VRPS);
562+
delay(50);
563+
writeOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_PWRSV);
564+
}
565+
566+
void
567+
Enc28J60Network::powerOn()
568+
{
569+
writeOp(ENC28J60_BIT_FIELD_CLR, ECON2, ECON2_PWRSV);
570+
delay(50);
571+
writeOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_RXEN);
572+
delay(50);
573+
}

utility/Enc28J60Network.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class Enc28J60Network : public MemoryPool
8181
uint16_t writePacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len);
8282
void copyPacket(memhandle dest, memaddress dest_pos, memhandle src, memaddress src_pos, uint16_t len);
8383
uint16_t chksum(uint16_t sum, memhandle handle, memaddress pos, uint16_t len);
84+
void powerOn();
85+
void powerOff();
8486
};
8587

8688
#endif /* ENC28J60NETWORK_H_ */

0 commit comments

Comments
 (0)