mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 00:05:33 +03:00
Flashfs: Add support for asynchronous complete erase
This commit is contained in:
parent
ea7807c5f5
commit
f3464d90cc
3 changed files with 41 additions and 13 deletions
|
@ -61,6 +61,7 @@
|
||||||
#include "io/asyncfatfs/asyncfatfs.h"
|
#include "io/asyncfatfs/asyncfatfs.h"
|
||||||
#include "io/beeper.h"
|
#include "io/beeper.h"
|
||||||
#include "io/dashboard.h"
|
#include "io/dashboard.h"
|
||||||
|
#include "io/flashfs.h"
|
||||||
#include "io/gps.h"
|
#include "io/gps.h"
|
||||||
#include "io/ledstrip.h"
|
#include "io/ledstrip.h"
|
||||||
#include "io/piniobox.h"
|
#include "io/piniobox.h"
|
||||||
|
@ -126,6 +127,10 @@ static void taskMain(timeUs_t currentTimeUs)
|
||||||
#ifdef USE_SDCARD
|
#ifdef USE_SDCARD
|
||||||
afatfs_poll();
|
afatfs_poll();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_FLASHFS
|
||||||
|
flashfsEraseAsync();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taskHandleSerial(timeUs_t currentTimeUs)
|
static void taskHandleSerial(timeUs_t currentTimeUs)
|
||||||
|
|
|
@ -41,12 +41,20 @@
|
||||||
#include "build/debug.h"
|
#include "build/debug.h"
|
||||||
#include "common/printf.h"
|
#include "common/printf.h"
|
||||||
#include "drivers/flash.h"
|
#include "drivers/flash.h"
|
||||||
|
#include "drivers/light_led.h"
|
||||||
|
|
||||||
#include "io/flashfs.h"
|
#include "io/flashfs.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
FLASHFS_IDLE,
|
||||||
|
FLASHFS_ERASING,
|
||||||
|
} flashfsState_e;
|
||||||
|
|
||||||
static const flashPartition_t *flashPartition = NULL;
|
static const flashPartition_t *flashPartition = NULL;
|
||||||
static const flashGeometry_t *flashGeometry = NULL;
|
static const flashGeometry_t *flashGeometry = NULL;
|
||||||
static uint32_t flashfsSize = 0;
|
static uint32_t flashfsSize = 0;
|
||||||
|
static flashfsState_e flashfsState = FLASHFS_IDLE;
|
||||||
|
static flashSector_t eraseSectorCurrent = 0;
|
||||||
|
|
||||||
static DMA_DATA_ZERO_INIT uint8_t flashWriteBuffer[FLASHFS_WRITE_BUFFER_SIZE];
|
static DMA_DATA_ZERO_INIT uint8_t flashWriteBuffer[FLASHFS_WRITE_BUFFER_SIZE];
|
||||||
|
|
||||||
|
@ -110,17 +118,9 @@ void flashfsEraseCompletely(void)
|
||||||
if (doFullErase) {
|
if (doFullErase) {
|
||||||
flashEraseCompletely();
|
flashEraseCompletely();
|
||||||
} else {
|
} else {
|
||||||
|
// start asynchronous erase of all sectors
|
||||||
// TODO - the partial sector-based erase needs to be completely reworked.
|
eraseSectorCurrent = flashPartition->startSector;
|
||||||
// All calls to flashfsEraseCompletely() currently expect the erase to run
|
flashfsState = FLASHFS_ERASING;
|
||||||
// asynchronously and return immediately. The current implementation performs
|
|
||||||
// the erase synchronously and doesn't return until complete. This breaks calls
|
|
||||||
// from MSP and runtime mode-switched erasing.
|
|
||||||
|
|
||||||
for (flashSector_t sectorIndex = flashPartition->startSector; sectorIndex <= flashPartition->endSector; sectorIndex++) {
|
|
||||||
uint32_t sectorAddress = sectorIndex * flashGeometry->sectorSize;
|
|
||||||
flashEraseSector(sectorAddress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,9 +160,9 @@ void flashfsEraseRange(uint32_t start, uint32_t end)
|
||||||
*/
|
*/
|
||||||
bool flashfsIsReady(void)
|
bool flashfsIsReady(void)
|
||||||
{
|
{
|
||||||
// Check for flash chip existence first, then check if ready.
|
// Check for flash chip existence first, then check if idle and ready.
|
||||||
|
|
||||||
return (flashfsIsSupported() && flashIsReady());
|
return (flashfsIsSupported() && (flashfsState == FLASHFS_IDLE) && flashIsReady());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool flashfsIsSupported(void)
|
bool flashfsIsSupported(void)
|
||||||
|
@ -407,6 +407,28 @@ void flashfsFlushSync(void)
|
||||||
while (!flashIsReady());
|
while (!flashIsReady());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously erase the flash: Check if ready and then erase sector.
|
||||||
|
*/
|
||||||
|
void flashfsEraseAsync(void)
|
||||||
|
{
|
||||||
|
if (flashfsState == FLASHFS_ERASING) {
|
||||||
|
if ((flashfsIsSupported() && flashIsReady())) {
|
||||||
|
if (eraseSectorCurrent <= flashPartition->endSector) {
|
||||||
|
// Erase sector
|
||||||
|
uint32_t sectorAddress = eraseSectorCurrent * flashGeometry->sectorSize;
|
||||||
|
flashEraseSector(sectorAddress);
|
||||||
|
eraseSectorCurrent++;
|
||||||
|
LED1_TOGGLE;
|
||||||
|
} else {
|
||||||
|
// Done erasing
|
||||||
|
flashfsState = FLASHFS_IDLE;
|
||||||
|
LED1_OFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void flashfsSeekAbs(uint32_t offset)
|
void flashfsSeekAbs(uint32_t offset)
|
||||||
{
|
{
|
||||||
flashfsFlushSync();
|
flashfsFlushSync();
|
||||||
|
|
|
@ -46,6 +46,7 @@ int flashfsReadAbs(uint32_t offset, uint8_t *data, unsigned int len);
|
||||||
|
|
||||||
bool flashfsFlushAsync(bool force);
|
bool flashfsFlushAsync(bool force);
|
||||||
void flashfsFlushSync(void);
|
void flashfsFlushSync(void);
|
||||||
|
void flashfsEraseAsync(void);
|
||||||
|
|
||||||
void flashfsClose(void);
|
void flashfsClose(void);
|
||||||
void flashfsInit(void);
|
void flashfsInit(void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue