From 4ef0466578f84f6ba3e67204e450606d65ef88d0 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Tue, 29 Dec 2015 12:05:15 -0500 Subject: [PATCH] Don't trip the WDT if interrupts are disabled during write() or flush(). Prior to this change, if interrupts were disabled during a call to HardwareSerial::write() when the circular buffer was full, or HardwareSerial::flush() when the circular buffer was non-empty, we would loop forever and trip a watchdog timeout. --- cores/esp8266/HardwareSerial.cpp | 6 ++++++ cores/esp8266/interrupts.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 3fd5af48b..b0f6861d2 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -636,6 +636,9 @@ void HardwareSerial::flush() { if(_tx_buffer->getSize() == 0 && UART_GET_TX_FIFO_ROOM(uart_nr) >= UART_TX_FIFO_SIZE) { break; + } else if(il.savedInterruptLevel() > 0) { + _tx_empty_irq(); + continue; } } yield(); @@ -663,6 +666,9 @@ size_t HardwareSerial::write(uint8_t c) { break; } else if(_tx_buffer->write(c)) { break; + } else if(il.savedInterruptLevel() > 0) { + _tx_empty_irq(); + continue; } } yield(); diff --git a/cores/esp8266/interrupts.h b/cores/esp8266/interrupts.h index 813997447..b4a2ed44b 100644 --- a/cores/esp8266/interrupts.h +++ b/cores/esp8266/interrupts.h @@ -31,6 +31,10 @@ public: xt_wsr_ps(_state); } + uint32_t savedInterruptLevel() const { + return _state & 0x0f; + } + protected: uint32_t _state; };