Skip to content

Commit

Permalink
Precise delay broken whenever beyond precise duration. (#264)
Browse files Browse the repository at this point in the history
* Precise delay broken whenever beyond precise duration.
* Fix lazy delay for interrupt sensitive applications
  • Loading branch information
dok-net authored Dec 10, 2022
1 parent 8d9d01e commit 12f8480
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EspSoftwareSerial",
"version": "6.17.0",
"version": "6.17.1",
"description": "Implementation of the Arduino software serial for ESP8266/ESP32.",
"keywords": [
"serial", "io", "softwareserial"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EspSoftwareSerial
version=6.17.0
version=6.17.1
author=Dirk Kaar, Peter Lerup
maintainer=Dirk Kaar <dok@dok-net.net>
sentence=Implementation of the Arduino software serial for ESP8266/ESP32.
Expand Down
7 changes: 5 additions & 2 deletions src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,19 @@ void SoftwareSerial::lazyDelay() {
{
optimistic_yield(10000UL);
}
// Assure that below-ms part of delays are not elided
preciseDelay();
// Disable interrupts again if applicable
if (!m_intTxEnabled) { disableInterrupts(); }
preciseDelay();
}

void IRAM_ATTR SoftwareSerial::preciseDelay() {
uint32_t ticks;
uint32_t expired;
do {
ticks = microsToTicks(micros());
} while ((ticks - m_periodStart) < m_periodDuration);
expired = ticks - m_periodStart;
} while (static_cast<int32_t>(m_periodDuration - expired) > 0);
m_periodDuration = 0;
m_periodStart = ticks;
}
Expand Down

0 comments on commit 12f8480

Please sign in to comment.