Skip to content

Commit 12f8480

Browse files
authored
Precise delay broken whenever beyond precise duration. (plerup#264)
* Precise delay broken whenever beyond precise duration. * Fix lazy delay for interrupt sensitive applications
1 parent 8d9d01e commit 12f8480

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "EspSoftwareSerial",
3-
"version": "6.17.0",
3+
"version": "6.17.1",
44
"description": "Implementation of the Arduino software serial for ESP8266/ESP32.",
55
"keywords": [
66
"serial", "io", "softwareserial"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=EspSoftwareSerial
2-
version=6.17.0
2+
version=6.17.1
33
author=Dirk Kaar, Peter Lerup
44
maintainer=Dirk Kaar <dok@dok-net.net>
55
sentence=Implementation of the Arduino software serial for ESP8266/ESP32.

src/SoftwareSerial.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,19 @@ void SoftwareSerial::lazyDelay() {
351351
{
352352
optimistic_yield(10000UL);
353353
}
354+
// Assure that below-ms part of delays are not elided
355+
preciseDelay();
354356
// Disable interrupts again if applicable
355357
if (!m_intTxEnabled) { disableInterrupts(); }
356-
preciseDelay();
357358
}
358359

359360
void IRAM_ATTR SoftwareSerial::preciseDelay() {
360361
uint32_t ticks;
362+
uint32_t expired;
361363
do {
362364
ticks = microsToTicks(micros());
363-
} while ((ticks - m_periodStart) < m_periodDuration);
365+
expired = ticks - m_periodStart;
366+
} while (static_cast<int32_t>(m_periodDuration - expired) > 0);
364367
m_periodDuration = 0;
365368
m_periodStart = ticks;
366369
}

0 commit comments

Comments
 (0)