From a183213ca37c8b9d4a4a89be6bbce997cc2e81ba Mon Sep 17 00:00:00 2001 From: jflyper Date: Wed, 23 Oct 2019 09:16:42 +0900 Subject: [PATCH] Check TX buffer space before calling serialWrite - Check TX buffer space before calling serialWrite (which unconditionally manipulates buffer management variables). - Added available TX buffer space as one of debug variables. - Use blackboxWrite() instead of serialWrite in blackboxWriteString(). --- src/main/blackbox/blackbox_io.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/blackbox/blackbox_io.c b/src/main/blackbox/blackbox_io.c index 6297063b92..43f1e41194 100644 --- a/src/main/blackbox/blackbox_io.c +++ b/src/main/blackbox/blackbox_io.c @@ -127,15 +127,23 @@ void blackboxWrite(uint8_t value) #endif case BLACKBOX_DEVICE_SERIAL: default: + { + int txBytesFree = serialTxBytesFree(blackboxPort); + #ifdef DEBUG_BB_OUTPUT - bbBits += 2; - if (serialTxBytesFree(blackboxPort) == 0) { - ++bbDrops; - DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 2, bbDrops); - return; - } + bbBits += 2; + DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 3, txBytesFree); #endif - serialWrite(blackboxPort, value); + + if (txBytesFree == 0) { +#ifdef DEBUG_BB_OUTPUT + ++bbDrops; + DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 2, bbDrops); +#endif + return; + } + serialWrite(blackboxPort, value); + } break; } @@ -181,7 +189,7 @@ int blackboxWriteString(const char *s) default: pos = (uint8_t*) s; while (*pos) { - serialWrite(blackboxPort, *pos); + blackboxWrite(*pos); pos++; }