1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 04:15:44 +03:00

Only write to FLASH once 64 bytes are buffered

This commit is contained in:
Steve Evans 2022-06-26 22:31:00 +01:00
parent 9f2cd64100
commit 5a30d9f5a0
3 changed files with 10 additions and 7 deletions

View file

@ -214,7 +214,7 @@ void blackboxDeviceFlush(void)
* devices will progressively write in the background without Blackbox calling anything.
*/
case BLACKBOX_DEVICE_FLASH:
flashfsFlushAsync();
flashfsFlushAsync(false);
break;
#endif // USE_FLASHFS
@ -237,7 +237,7 @@ bool blackboxDeviceFlushForce(void)
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
return flashfsFlushAsync();
return flashfsFlushAsync(true);
#endif // USE_FLASHFS
#ifdef USE_SDCARD
@ -735,7 +735,7 @@ blackboxBufferReserveStatus_e blackboxDeviceReserveBufferSpace(int32_t bytes)
* that the Blackbox header writing code doesn't have to guess about the best time to ask flashfs to
* flush, and doesn't stall waiting for a flush that would otherwise not automatically be called.
*/
flashfsFlushAsync();
flashfsFlushAsync(true);
}
return BLACKBOX_RESERVE_TEMPORARY_FAILURE;
#endif // USE_FLASHFS

View file

@ -38,6 +38,7 @@
#include "platform.h"
#include "build/debug.h"
#include "common/printf.h"
#include "drivers/flash.h"
@ -343,7 +344,7 @@ uint32_t flashfsGetOffset(void)
* Returns true if all data in the buffer has been flushed to the device, or false if
* there is still data to be written (call flush again later).
*/
bool flashfsFlushAsync(void)
bool flashfsFlushAsync(bool force)
{
uint8_t const * buffers[2];
uint32_t bufferSizes[2];
@ -373,7 +374,9 @@ bool flashfsFlushAsync(void)
#endif
bufCount = flashfsGetDirtyDataBuffers(buffers, bufferSizes);
if (bufCount) {
uint32_t bufferedBytes = bufferSizes[0] + bufferSizes[1];
if (bufCount && (force || (bufferedBytes >= FLASHFS_WRITE_BUFFER_AUTO_FLUSH_LEN))) {
flashfsWriteBuffers(buffers, bufferSizes, bufCount, false);
}
@ -427,7 +430,7 @@ void flashfsWriteByte(uint8_t byte)
}
if (flashfsTransmitBufferUsed() >= FLASHFS_WRITE_BUFFER_AUTO_FLUSH_LEN) {
flashfsFlushAsync();
flashfsFlushAsync(false);
}
}

View file

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