diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index a0e3579308..d471258213 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -644,6 +644,9 @@ void startBlackbox(void) } } +/** + * Begin Blackbox shutdown. + */ void finishBlackbox(void) { if (blackboxState == BLACKBOX_STATE_RUNNING) { @@ -1123,7 +1126,7 @@ void handleBlackbox(void) * * Don't wait longer than it could possibly take if something funky happens. */ - if (millis() > xmitState.u.startTime + 200 || isBlackboxDeviceIdle()) { + if (millis() > xmitState.u.startTime + 200 || blackboxDeviceFlush()) { blackboxDeviceClose(); blackboxSetState(BLACKBOX_STATE_STOPPED); } diff --git a/src/main/blackbox/blackbox_io.c b/src/main/blackbox/blackbox_io.c index d5eefc9c1e..acaf0f4f85 100644 --- a/src/main/blackbox/blackbox_io.c +++ b/src/main/blackbox/blackbox_io.c @@ -405,19 +405,24 @@ void blackboxWriteTag8_8SVB(int32_t *values, int valueCount) } /** - * If there is data waiting to be written to the blackbox device, attempt to write that now. + * If there is data waiting to be written to the blackbox device, attempt to write (a portion of) that now. + * + * Returns true if all data has been flushed to the device. */ -void blackboxDeviceFlush(void) +bool blackboxDeviceFlush(void) { switch (masterConfig.blackbox_device) { case BLACKBOX_DEVICE_SERIAL: - //Presently a no-op on serial, as serial is continuously being drained out of its buffer - break; + //Nothing to speed up flushing on serial, as serial is continuously being drained out of its buffer + return isSerialTransmitBufferEmpty(blackboxPort); + #ifdef USE_FLASHFS case BLACKBOX_DEVICE_FLASH: - flashfsFlushAsync(); - break; + return flashfsFlushAsync(); #endif + + default: + return false; } } @@ -470,6 +475,9 @@ bool blackboxDeviceOpen(void) } } +/** + * Close the Blackbox logging device immediately without attempting to flush any remaining data. + */ void blackboxDeviceClose(void) { switch (masterConfig.blackbox_device) { @@ -487,27 +495,6 @@ void blackboxDeviceClose(void) mspAllocateSerialPorts(&masterConfig.serialConfig); } break; -#ifdef USE_FLASHFS - case BLACKBOX_DEVICE_FLASH: - flashfsFlushSync(); - break; -#endif - } -} - -bool isBlackboxDeviceIdle(void) -{ - switch (masterConfig.blackbox_device) { - case BLACKBOX_DEVICE_SERIAL: - return isSerialTransmitBufferEmpty(blackboxPort); - -#ifdef USE_FLASHFS - case BLACKBOX_DEVICE_FLASH: - return flashfsFlushAsync(); -#endif - - default: - return false; } } diff --git a/src/main/blackbox/blackbox_io.h b/src/main/blackbox/blackbox_io.h index 8fca16d72e..62d5909986 100644 --- a/src/main/blackbox/blackbox_io.h +++ b/src/main/blackbox/blackbox_io.h @@ -46,9 +46,8 @@ void blackboxWriteTag2_3S32(int32_t *values); void blackboxWriteTag8_4S16(int32_t *values); void blackboxWriteTag8_8SVB(int32_t *values, int valueCount); -void blackboxDeviceFlush(void); +bool blackboxDeviceFlush(void); bool blackboxDeviceOpen(void); void blackboxDeviceClose(void); -bool isBlackboxDeviceIdle(void); bool isBlackboxDeviceFull(void); diff --git a/src/main/drivers/flash_m25p16.c b/src/main/drivers/flash_m25p16.c index e977f257ef..a6bd7b22fa 100644 --- a/src/main/drivers/flash_m25p16.c +++ b/src/main/drivers/flash_m25p16.c @@ -278,6 +278,11 @@ int m25p16_readBytes(uint32_t address, uint8_t *buffer, int length) return length; } +/** + * Fetch information about the detected flash chip layout. + * + * Can be called before calling m25p16_init() (the result would have totalSize = 0). + */ const flashGeometry_t* m25p16_getGeometry() { return &geometry; diff --git a/src/main/io/flashfs.c b/src/main/io/flashfs.c index e1de9fca6c..b271cec3ee 100644 --- a/src/main/io/flashfs.c +++ b/src/main/io/flashfs.c @@ -555,6 +555,7 @@ bool flashfsIsEOF() { */ void flashfsInit() { + // If we have a flash chip present at all if (flashfsGetSize() > 0) { // Start the file pointer off at the beginning of free space so caller can start writing immediately flashfsSeekAbs(flashfsIdentifyStartOfFreeSpace());