Avoid synchronous flushes to flash during Blackbox shutdown

This commit is contained in:
Nicholas Sherlock 2015-02-15 23:23:53 +13:00
parent acd4745a4e
commit d6911e8b86
5 changed files with 15 additions and 8 deletions

View File

@ -415,7 +415,7 @@ void blackboxDeviceFlush(void)
break; break;
#ifdef USE_FLASHFS #ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH: case BLACKBOX_DEVICE_FLASH:
flashfsFlushSync(); flashfsFlushAsync();
break; break;
#endif #endif
} }
@ -503,8 +503,7 @@ bool isBlackboxDeviceIdle(void)
#ifdef USE_FLASHFS #ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH: case BLACKBOX_DEVICE_FLASH:
flashfsFlushSync(); return flashfsFlushAsync();
return true;
#endif #endif
default: default:

View File

@ -295,12 +295,14 @@ static void flashfsAdvanceTailInBuffer(uint32_t delta)
/** /**
* If the flash is ready to accept writes, flush the buffer to it, otherwise schedule * If the flash is ready to accept writes, flush the buffer to it, otherwise schedule
* a flush for later and return immediately. * a flush for later and return immediately.
*
* Returns true if all data in the buffer has been flushed to the device.
*/ */
void flashfsFlushAsync() bool flashfsFlushAsync()
{ {
if (flashfsBufferIsEmpty()) { if (flashfsBufferIsEmpty()) {
shouldFlush = false; shouldFlush = false;
return; // Nothing to flush return true; // Nothing to flush
} }
uint8_t const * buffers[2]; uint8_t const * buffers[2];
@ -312,6 +314,8 @@ void flashfsFlushAsync()
flashfsAdvanceTailInBuffer(bytesWritten); flashfsAdvanceTailInBuffer(bytesWritten);
shouldFlush = !flashfsBufferIsEmpty(); shouldFlush = !flashfsBufferIsEmpty();
return flashfsBufferIsEmpty();
} }
/** /**

View File

@ -43,7 +43,7 @@ void flashfsWrite(const uint8_t *data, unsigned int len, bool sync);
int flashfsReadAbs(uint32_t offset, uint8_t *data, unsigned int len); int flashfsReadAbs(uint32_t offset, uint8_t *data, unsigned int len);
void flashfsFlushAsync(); bool flashfsFlushAsync();
void flashfsFlushSync(); void flashfsFlushSync();
void flashfsInit(); void flashfsInit();

View File

@ -772,7 +772,12 @@ static void cliFlashErase(char *cmdline)
printf("Erasing, please wait...\r\n"); printf("Erasing, please wait...\r\n");
flashfsEraseCompletely(); flashfsEraseCompletely();
printf("Erased flash chip.\r\n");
while (!flashfsIsReady()) {
delay(100);
}
printf("Done.\r\n");
} }
static void cliFlashWrite(char *cmdline) static void cliFlashWrite(char *cmdline)

View File

@ -52,7 +52,6 @@
#include "io/serial.h" #include "io/serial.h"
#include "io/flashfs.h" #include "io/flashfs.h"
#include "io/gps.h" #include "io/gps.h"
#include "io/escservo.h" #include "io/escservo.h"
#include "io/rc_controls.h" #include "io/rc_controls.h"