Description
While investigating puzzling differences between transmit and receive throughput I found the following design flaw.
socketSend()
writes the data to be transmitted to one of the W5x00's circular socket buffers, then waits for the W5x00 to finish transmitting the data before returning. Waiting is unnecessary because the next socketSend()
call checks for available space in the socket's circular buffer before sending more data, and it eliminates the advantage of the W5x00 being able to send the data without interacting with the processor.
Removing the wait by deleting the following lines increases W5500 transmit throughput by a whopping 4X on my Adafruit Metro M4/W5500 Shield webserver with no impact on reliability. I don't have W5100 or W5200 devices to test with but based on documentation review I see no reason this improvement won't work on them too.
/* +2008.01 bj */
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK ) {
/* m2008.01 [bj] : reduce code */
if ( W5100.readSnSR(s) == SnSR::CLOSED ) {
EthernetClass::spi()->endTransaction();
return 0;
}
EthernetClass::spi()->endTransaction();
yield();
EthernetClass::spi()->beginTransaction(SPI_ETHERNET_SETTINGS);
}
/* +2008.01 bj */
W5100.writeSnIR(s, SnIR::SEND_OK);