diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-02-17 20:19:49 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-02-17 20:19:49 +0300 |
commit | 5d254801ead587ce0e987db6d80b0eda2fb97fd1 (patch) | |
tree | 60e6a30eaef8cee19156fe3a458066fdff5cc097 /src | |
parent | 63f3d0b723ee819191e55a3712e787c24bf66755 (diff) |
Changed Duet 3 Mini WiFi transfer wait-until-finished code
Diffstat (limited to 'src')
-rw-r--r-- | src/Networking/ESP8266WiFi/WiFiInterface.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/Networking/ESP8266WiFi/WiFiInterface.cpp b/src/Networking/ESP8266WiFi/WiFiInterface.cpp index d3271395..d540f01f 100644 --- a/src/Networking/ESP8266WiFi/WiFiInterface.cpp +++ b/src/Networking/ESP8266WiFi/WiFiInterface.cpp @@ -94,7 +94,7 @@ constexpr SSPChannel ESP_SPI = SSP0; #endif const uint32_t WiFiResponseTimeoutMillis = 200; // SPI timeout when when the ESP does not have to write to flash memory -const uint32_t WiFiTransferTimeoutMillis = 60; // Christian measured this at 29 to 31ms when the ESP has to write to flag memory +const uint32_t WiFiTransferTimeoutMillis = 60; // Christian measured this at 29 to 31ms when the ESP has to write to flash memory const uint32_t WiFiWaitReadyMillis = 100; const uint32_t WiFiStartupMillis = 300; const uint32_t WiFiStableMillis = 100; @@ -1830,21 +1830,25 @@ int32_t WiFiInterface::SendCommand(NetworkCommand cmd, SocketNumber socketNum, u #if SAME5x { - // We don't get and end-of-transfer interrupt, just a start-of-transfer one. So wait until SS is high, then disable the SPI. - // The max block time is about 2K * 8/spi_clock_speed plus any pauses that the ESP takes, which at 26.7MHz clock rate is 620us plus pause time - // However, when we send a command that involves writing to flash memory, then the flash write occurs between sending the header and the body + // We don't get an end-of-transfer interrupt, just a start-of-transfer one. So wait until SS is high, then disable the SPI. + // The normal maximum block time is about 2K * 8/spi_clock_speed plus any pauses that the ESP takes, which at 26.7MHz clock rate is 620us plus pause time + // However, when we send a command that involves writing to flash memory, then the flash write occurs between sending the header and the body, so it takes much longer const uint32_t startedWaitingAt = millis(); const bool writingFlash = ( cmd == NetworkCommand::networkAddSsid || cmd == NetworkCommand::networkConfigureAccessPoint || cmd == NetworkCommand::networkDeleteSsid || cmd == NetworkCommand::networkFactoryReset); while (!digitalRead(EspSSPin)) { - if (writingFlash) + const uint32_t millisWaiting = millis() - startedWaitingAt; + if (millisWaiting >= WiFiTransferTimeoutMillis) { - delay(2); // we sent a command that writes to flash memory. It may take a while and we're not trying to minimise latency, so give up the CPU + return ResponseTimeout; } - if (millis() - startedWaitingAt >= WiFiTransferTimeoutMillis) + + // The new RTOS SDK for the ESP8266 often interrupts out transfer task for long periods of time. So if the transfer is taking a while to complete, give up the CPU. + // Also give up the CPU if we are writing to flash memory, because we know that takes a long time. + if (writingFlash || millisWaiting >= 2) { - return ResponseTimeout; + delay(2); } } if (WiFiSpiSercom->SPI.STATUS.bit.BUFOVF) |