Minor fix for flushing behaviour on dataflash

This commit is contained in:
Nicholas Sherlock 2015-02-16 22:20:53 +13:00
parent d628bc6dcd
commit 5f29eed017
5 changed files with 25 additions and 30 deletions

View File

@ -644,6 +644,9 @@ void startBlackbox(void)
} }
} }
/**
* Begin Blackbox shutdown.
*/
void finishBlackbox(void) void finishBlackbox(void)
{ {
if (blackboxState == BLACKBOX_STATE_RUNNING) { 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. * 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(); blackboxDeviceClose();
blackboxSetState(BLACKBOX_STATE_STOPPED); blackboxSetState(BLACKBOX_STATE_STOPPED);
} }

View File

@ -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) { switch (masterConfig.blackbox_device) {
case BLACKBOX_DEVICE_SERIAL: case BLACKBOX_DEVICE_SERIAL:
//Presently a no-op on serial, as serial is continuously being drained out of its buffer //Nothing to speed up flushing on serial, as serial is continuously being drained out of its buffer
break; return isSerialTransmitBufferEmpty(blackboxPort);
#ifdef USE_FLASHFS #ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH: case BLACKBOX_DEVICE_FLASH:
flashfsFlushAsync(); return flashfsFlushAsync();
break;
#endif #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) void blackboxDeviceClose(void)
{ {
switch (masterConfig.blackbox_device) { switch (masterConfig.blackbox_device) {
@ -487,27 +495,6 @@ void blackboxDeviceClose(void)
mspAllocateSerialPorts(&masterConfig.serialConfig); mspAllocateSerialPorts(&masterConfig.serialConfig);
} }
break; 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;
} }
} }

View File

@ -46,9 +46,8 @@ void blackboxWriteTag2_3S32(int32_t *values);
void blackboxWriteTag8_4S16(int32_t *values); void blackboxWriteTag8_4S16(int32_t *values);
void blackboxWriteTag8_8SVB(int32_t *values, int valueCount); void blackboxWriteTag8_8SVB(int32_t *values, int valueCount);
void blackboxDeviceFlush(void); bool blackboxDeviceFlush(void);
bool blackboxDeviceOpen(void); bool blackboxDeviceOpen(void);
void blackboxDeviceClose(void); void blackboxDeviceClose(void);
bool isBlackboxDeviceIdle(void);
bool isBlackboxDeviceFull(void); bool isBlackboxDeviceFull(void);

View File

@ -278,6 +278,11 @@ int m25p16_readBytes(uint32_t address, uint8_t *buffer, int length)
return 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() const flashGeometry_t* m25p16_getGeometry()
{ {
return &geometry; return &geometry;

View File

@ -555,6 +555,7 @@ bool flashfsIsEOF() {
*/ */
void flashfsInit() void flashfsInit()
{ {
// If we have a flash chip present at all
if (flashfsGetSize() > 0) { if (flashfsGetSize() > 0) {
// Start the file pointer off at the beginning of free space so caller can start writing immediately // Start the file pointer off at the beginning of free space so caller can start writing immediately
flashfsSeekAbs(flashfsIdentifyStartOfFreeSpace()); flashfsSeekAbs(flashfsIdentifyStartOfFreeSpace());