diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 0e8e1c798..2d73c7c9b 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -18,6 +18,12 @@ NoopPrint noopPrint; #if HAS_WIFI || HAS_ETHERNET extern Syslog syslog; #endif +void RedirectablePrint::rpInit() +{ +#ifdef HAS_FREE_RTOS + inDebugPrint = xSemaphoreCreateMutexStatic(&this->_MutexStorageSpace); +#endif +} void RedirectablePrint::setDestination(Print *_dest) { @@ -66,9 +72,12 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) return 0; } size_t r = 0; - +#ifdef HAS_FREE_RTOS + if (inDebugPrint != nullptr && xSemaphoreTake(inDebugPrint, portMAX_DELAY) == pdTRUE) { +#else if (!inDebugPrint) { inDebugPrint = true; +#endif va_list arg; va_start(arg, format); @@ -141,7 +150,11 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) va_end(arg); isContinuationMessage = !hasNewline; +#ifdef HAS_FREE_RTOS + xSemaphoreGive(inDebugPrint); +#else inDebugPrint = false; +#endif } return r; diff --git a/src/RedirectablePrint.h b/src/RedirectablePrint.h index 560021972..31cc1b6ef 100644 --- a/src/RedirectablePrint.h +++ b/src/RedirectablePrint.h @@ -1,5 +1,6 @@ #pragma once +#include "../freertosinc.h" #include #include #include @@ -16,14 +17,19 @@ class RedirectablePrint : public Print /// Used to allow multiple logDebug messages to appear on a single log line bool isContinuationMessage = false; +#ifdef HAS_FREE_RTOS + SemaphoreHandle_t inDebugPrint = nullptr; + StaticSemaphore_t _MutexStorageSpace; +#else volatile bool inDebugPrint = false; - +#endif public: explicit RedirectablePrint(Print *_dest) : dest(_dest) {} /** * Set a new destination */ + void rpInit(); void setDestination(Print *dest); virtual size_t write(uint8_t c); @@ -54,4 +60,4 @@ class NoopPrint : public Print /** * A printer that doesn't go anywhere */ -extern NoopPrint noopPrint; +extern NoopPrint noopPrint; \ No newline at end of file diff --git a/src/SerialConsole.cpp b/src/SerialConsole.cpp index e827dcf3b..ed217c3ed 100644 --- a/src/SerialConsole.cpp +++ b/src/SerialConsole.cpp @@ -12,6 +12,7 @@ SerialConsole *console; void consoleInit() { new SerialConsole(); // Must be dynamically allocated because we are now inheriting from thread + DEBUG_PORT.rpInit(); // Simply sets up semaphore } void consolePrintf(const char *format, ...)