Skip to content

Commit 0e6348e

Browse files
committed
Ethernet: initialized flag
1 parent 1cf083c commit 0e6348e

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/Ethernet.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C"
3030

3131
#define ETH_HDR ((struct uip_eth_hdr *)&uip_buf[0])
3232

33+
bool UIPEthernetClass::initialized = false;
3334
memhandle UIPEthernetClass::in_packet(NOBLOCK);
3435
memhandle UIPEthernetClass::uip_packet(NOBLOCK);
3536
uint8_t UIPEthernetClass::uip_hdrlen(0);
@@ -131,13 +132,14 @@ int UIPEthernetClass::maintain(){
131132

132133
EthernetLinkStatus UIPEthernetClass::linkStatus()
133134
{
134-
if (!Enc28J60Network::getrev())
135+
if (!(initialized && Enc28J60Network::getrev()))
135136
return Unknown;
136137
return Enc28J60Network::linkStatus() ? LinkON : LinkOFF;
137138
}
138139

139-
EthernetHardwareStatus UIPEthernetClass::hardwareStatus() {
140-
if (!Enc28J60Network::getrev())
140+
EthernetHardwareStatus UIPEthernetClass::hardwareStatus()
141+
{
142+
if (!(initialized && Enc28J60Network::getrev()))
141143
return EthernetNoHardware;
142144
return EthernetENC28J60;
143145
}
@@ -174,6 +176,8 @@ IPAddress UIPEthernetClass::dnsServerIP()
174176
void
175177
UIPEthernetClass::tick()
176178
{
179+
if (!initialized)
180+
return;
177181
if (in_packet == NOBLOCK)
178182
{
179183
in_packet = Enc28J60Network::receivePacket();
@@ -331,7 +335,7 @@ boolean UIPEthernetClass::network_send()
331335
void UIPEthernetClass::init(const uint8_t* mac) {
332336
periodic_timer = millis() + UIP_PERIODIC_TIMER;
333337

334-
Enc28J60Network::init((uint8_t*)mac);
338+
initialized = Enc28J60Network::init((uint8_t*)mac);
335339
uip_seteth_addr(mac);
336340

337341
uip_init();
@@ -353,9 +357,6 @@ void UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway,
353357
_dnsServerAddress = dns;
354358
}
355359

356-
UIPEthernetClass Ethernet;
357-
#define UIPEthernet Ethernet
358-
359360
/*---------------------------------------------------------------------------*/
360361
uint16_t
361362
UIPEthernetClass::chksum(uint16_t sum, const uint8_t *data, uint16_t len)
@@ -480,21 +481,23 @@ uip_tcpchksum(void)
480481
uint16_t
481482
uip_ipchksum(void)
482483
{
483-
return UIPEthernet.ipchksum();
484+
return UIPEthernetClass::ipchksum();
484485
}
485486

486487
#if UIP_UDP
487488
uint16_t
488489
uip_tcpchksum(void)
489490
{
490-
uint16_t sum = UIPEthernet.upper_layer_chksum(UIP_PROTO_TCP);
491+
uint16_t sum = UIPEthernetClass::upper_layer_chksum(UIP_PROTO_TCP);
491492
return sum;
492493
}
493494

494495
uint16_t
495496
uip_udpchksum(void)
496497
{
497-
uint16_t sum = UIPEthernet.upper_layer_chksum(UIP_PROTO_UDP);
498+
uint16_t sum = UIPEthernetClass::upper_layer_chksum(UIP_PROTO_UDP);
498499
return sum;
499500
}
500501
#endif
502+
503+
UIPEthernetClass Ethernet;

src/Ethernet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class UIPEthernetClass
9999
IPAddress dnsServerIP();
100100

101101
private:
102+
static bool initialized;
102103
static memhandle in_packet;
103104
static memhandle uip_packet;
104105
static uint8_t uip_hdrlen;

src/utility/Enc28J60Network.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ uint8_t Enc28J60Network::bank=0xff;
4444

4545
struct memblock Enc28J60Network::receivePkt;
4646

47-
void Enc28J60Network::init(uint8_t* macaddr)
47+
bool Enc28J60Network::init(uint8_t* macaddr)
4848
{
4949

5050
MemoryPool::init(); // 1 byte in between RX_STOP_INIT and pool to allow prepending of controlbyte
@@ -126,6 +126,8 @@ void Enc28J60Network::init(uint8_t* macaddr)
126126
phyWrite(PHLCON,0x476);
127127

128128
SPI.endTransaction();
129+
130+
return getrev();
129131
}
130132

131133
memhandle

src/utility/Enc28J60Network.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Enc28J60Network : public MemoryPool
7878
static bool linkStatus();
7979

8080
static void setCsPin(uint8_t _csPin) {csPin = _csPin;}
81-
static void init(uint8_t* macaddr);
81+
static bool init(uint8_t* macaddr);
8282
static memhandle receivePacket();
8383
static void freePacket();
8484
static memaddress blockSize(memhandle handle);

0 commit comments

Comments
 (0)