arduino-libraries / Ethernet

Ethernet Library for Arduino
http://arduino.cc/
259 stars 264 forks source link

Potential race condition when toggling with SPI chip select signal #131

Open CONTROLLINO-Support opened 4 years ago

CONTROLLINO-Support commented 4 years ago

Hello,

one of our customers has reported an issue that when he manipulates with Atmega2560 PORTJ in an interrupt service routine, his changes are sometimes lost when it returns from the ISR. And this happens only when there is Ethernet activity in the same time.

Because we have the Ethernet chip select signal also on PORTJ, I am afraid that the problem are your setSS and resetSS functions (in w5100.h).

Would it be possible to change them like this:

inline static void setSS() {
noInterrupts();
*(ss_pin_reg) &= ~ss_pin_mask;
interrupts;
}
inline static void resetSS() {
noInterrupts();
*(ss_pin_reg) |= ss_pin_mask;
interrupts;
}

Please note that we have also RS485 bus direction control signals on the same port as the Ethernet chipselect. And that signals may be also controlled directly fom an ISR - again a big risk of a race condition.

What do you think?

Thanks, Lukas