Skip to content

Commit 67ce592

Browse files
committed
Guaranteed optimistic_yield for non-sync preciseDelay, in hypthetical case consistent overshoot prevents
delay/yield completely and leads to WDT.
1 parent f5990c9 commit 67ce592

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/SoftwareSerial.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,20 @@ void ICACHE_RAM_ATTR SoftwareSerial::preciseDelay(bool sync) {
233233
{
234234
// Reenable interrupts while delaying to avoid other tasks piling up
235235
if (!m_intTxEnabled) { xt_wsr_ps(m_savedPS); }
236-
auto expired = ESP.getCycleCount() - m_periodStart;
237-
if (expired < m_periodDuration)
236+
const auto expired = ESP.getCycleCount() - m_periodStart;
237+
const auto ms = (m_periodDuration - expired) / ESP.getCpuFreqMHz() / 1000UL;
238+
if (ms)
238239
{
239-
auto ms = (m_periodDuration - expired) / ESP.getCpuFreqMHz() / 1000UL;
240-
if (ms) delay(ms);
240+
delay(ms);
241+
}
242+
else
243+
{
244+
do
245+
{
246+
optimistic_yield(10000UL);
247+
}
248+
while ((ESP.getCycleCount() - m_periodStart) < m_periodDuration);
241249
}
242-
while ((ESP.getCycleCount() - m_periodStart) < m_periodDuration) { optimistic_yield(10000UL); }
243250
// Disable interrupts again
244251
if (!m_intTxEnabled) { m_savedPS = xt_rsil(15); }
245252
}

0 commit comments

Comments
 (0)