mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Restructure flashfs MSC to prevent device timeout on MacOS (#9252)
Restructure flashfs MSC to prevent device timeout on MacOS
This commit is contained in:
parent
1595fbe00b
commit
e5015a6b81
5 changed files with 51 additions and 38 deletions
|
@ -76,8 +76,6 @@ void mscInit(void)
|
||||||
|
|
||||||
uint8_t mscStart(void)
|
uint8_t mscStart(void)
|
||||||
{
|
{
|
||||||
ledInit(statusLedConfig());
|
|
||||||
|
|
||||||
//Start USB
|
//Start USB
|
||||||
usbGenerateDisconnectPulse();
|
usbGenerateDisconnectPulse();
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,6 @@ void mscInit(void)
|
||||||
|
|
||||||
uint8_t mscStart(void)
|
uint8_t mscStart(void)
|
||||||
{
|
{
|
||||||
ledInit(statusLedConfig());
|
|
||||||
|
|
||||||
//Start USB
|
//Start USB
|
||||||
usbGenerateDisconnectPulse();
|
usbGenerateDisconnectPulse();
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,7 @@
|
||||||
#include "io/vtx_smartaudio.h"
|
#include "io/vtx_smartaudio.h"
|
||||||
#include "io/vtx_tramp.h"
|
#include "io/vtx_tramp.h"
|
||||||
|
|
||||||
|
#include "msc/emfat_file.h"
|
||||||
#ifdef USE_PERSISTENT_MSC_RTC
|
#ifdef USE_PERSISTENT_MSC_RTC
|
||||||
#include "msc/usbd_storage.h"
|
#include "msc/usbd_storage.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -611,6 +612,16 @@ void init(void)
|
||||||
* so there is no bottleneck in reading and writing data */
|
* so there is no bottleneck in reading and writing data */
|
||||||
mscInit();
|
mscInit();
|
||||||
if (mscCheckBoot() || mscCheckButton()) {
|
if (mscCheckBoot() || mscCheckButton()) {
|
||||||
|
ledInit(statusLedConfig());
|
||||||
|
|
||||||
|
#if defined(USE_FLASHFS) && defined(USE_FLASH_CHIP)
|
||||||
|
// If the blackbox device is onboard flash, then initialize and scan
|
||||||
|
// it to identify the log files *before* starting the USB device to
|
||||||
|
// prevent timeouts of the mass storage device.
|
||||||
|
if (blackboxConfig()->device == BLACKBOX_DEVICE_FLASH) {
|
||||||
|
emfat_init_files();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (mscStart() == 0) {
|
if (mscStart() == 0) {
|
||||||
mscWaitForButton();
|
mscWaitForButton();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,8 +31,14 @@
|
||||||
#include "common/time.h"
|
#include "common/time.h"
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
|
|
||||||
|
#include "drivers/flash.h"
|
||||||
|
#include "drivers/light_led.h"
|
||||||
|
#include "drivers/time.h"
|
||||||
|
|
||||||
#include "io/flashfs.h"
|
#include "io/flashfs.h"
|
||||||
|
|
||||||
|
#include "pg/flash.h"
|
||||||
|
|
||||||
#include "msc/usbd_storage.h"
|
#include "msc/usbd_storage.h"
|
||||||
|
|
||||||
#define FILESYSTEM_SIZE_MB 256
|
#define FILESYSTEM_SIZE_MB 256
|
||||||
|
@ -300,9 +306,18 @@ static void emfat_add_log(emfat_entry_t *entry, int number, uint32_t offset, uin
|
||||||
entry->cma_time[2] = entry->cma_time[0];
|
entry->cma_time[2] = entry->cma_time[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int emfat_find_log(emfat_entry_t *entry, int maxCount)
|
static void blinkStatusLed(void)
|
||||||
|
{
|
||||||
|
static timeMs_t nextToggleMs = 0;
|
||||||
|
const timeMs_t nowMs = millis();
|
||||||
|
if (nowMs > nextToggleMs) {
|
||||||
|
LED0_TOGGLE;
|
||||||
|
nextToggleMs = nowMs + 50; // toggle the status LED every 50ms
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int emfat_find_log(emfat_entry_t *entry, int maxCount, int flashfsUsedSpace)
|
||||||
{
|
{
|
||||||
int limit = flashfsIdentifyStartOfFreeSpace();
|
|
||||||
int lastOffset = 0;
|
int lastOffset = 0;
|
||||||
int currOffset = 0;
|
int currOffset = 0;
|
||||||
int buffOffset;
|
int buffOffset;
|
||||||
|
@ -316,8 +331,9 @@ static int emfat_find_log(emfat_entry_t *entry, int maxCount)
|
||||||
int lenTimeHeader = strlen(timeHeader);
|
int lenTimeHeader = strlen(timeHeader);
|
||||||
int timeHeaderMatched = 0;
|
int timeHeaderMatched = 0;
|
||||||
|
|
||||||
for ( ; currOffset < limit ; currOffset += 2048) { // XXX 2048 = FREE_BLOCK_SIZE in io/flashfs.c
|
for ( ; currOffset < flashfsUsedSpace ; currOffset += 2048) { // XXX 2048 = FREE_BLOCK_SIZE in io/flashfs.c
|
||||||
|
|
||||||
|
blinkStatusLed();
|
||||||
flashfsReadAbs(currOffset, buffer, HDR_BUF_SIZE);
|
flashfsReadAbs(currOffset, buffer, HDR_BUF_SIZE);
|
||||||
|
|
||||||
if (strncmp((char *)buffer, logHeader, lenLogHeader)) {
|
if (strncmp((char *)buffer, logHeader, lenLogHeader)) {
|
||||||
|
@ -373,7 +389,7 @@ static int emfat_find_log(emfat_entry_t *entry, int maxCount)
|
||||||
hdrOffset += HDR_BUF_SIZE;
|
hdrOffset += HDR_BUF_SIZE;
|
||||||
|
|
||||||
// Check for flash overflow
|
// Check for flash overflow
|
||||||
if (hdrOffset > limit) {
|
if (hdrOffset > flashfsUsedSpace) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,6 +427,12 @@ void emfat_init_files(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
flashInit(flashConfig());
|
||||||
|
flashfsInit();
|
||||||
|
LED0_OFF;
|
||||||
|
|
||||||
|
const int flashfsUsedSpace = flashfsIdentifyStartOfFreeSpace();
|
||||||
|
|
||||||
for (size_t i = 0 ; i < PREDEFINED_ENTRY_COUNT ; i++) {
|
for (size_t i = 0 ; i < PREDEFINED_ENTRY_COUNT ; i++) {
|
||||||
entries[i] = entriesPredefined[i];
|
entries[i] = entriesPredefined[i];
|
||||||
// These entries have timestamps corresponding to when the filesystem is mounted
|
// These entries have timestamps corresponding to when the filesystem is mounted
|
||||||
|
@ -418,7 +440,7 @@ void emfat_init_files(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect and create entries for each individual log
|
// Detect and create entries for each individual log
|
||||||
const int logCount = emfat_find_log(&entries[PREDEFINED_ENTRY_COUNT], EMFAT_MAX_LOG_ENTRY);
|
const int logCount = emfat_find_log(&entries[PREDEFINED_ENTRY_COUNT], EMFAT_MAX_LOG_ENTRY, flashfsUsedSpace);
|
||||||
|
|
||||||
int entryIndex = PREDEFINED_ENTRY_COUNT + logCount;
|
int entryIndex = PREDEFINED_ENTRY_COUNT + logCount;
|
||||||
|
|
||||||
|
@ -427,7 +449,7 @@ void emfat_init_files(void)
|
||||||
// allow downloading the entire log in one file
|
// allow downloading the entire log in one file
|
||||||
entries[entryIndex] = entriesPredefined[PREDEFINED_ENTRY_COUNT];
|
entries[entryIndex] = entriesPredefined[PREDEFINED_ENTRY_COUNT];
|
||||||
entry = &entries[entryIndex];
|
entry = &entries[entryIndex];
|
||||||
entry->curr_size = flashfsIdentifyStartOfFreeSpace();
|
entry->curr_size = flashfsUsedSpace;
|
||||||
entry->max_size = entry->curr_size;
|
entry->max_size = entry->curr_size;
|
||||||
// This entry has timestamps corresponding to when the filesystem is mounted
|
// This entry has timestamps corresponding to when the filesystem is mounted
|
||||||
emfat_set_entry_cma(entry);
|
emfat_set_entry_cma(entry);
|
||||||
|
@ -435,13 +457,16 @@ void emfat_init_files(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Padding file to fill out the filesystem size to FILESYSTEM_SIZE_MB
|
// Padding file to fill out the filesystem size to FILESYSTEM_SIZE_MB
|
||||||
entries[entryIndex] = entriesPredefined[PREDEFINED_ENTRY_COUNT + 1];
|
if (flashfsUsedSpace * 2 < FILESYSTEM_SIZE_MB * 1024 * 1024) {
|
||||||
entry = &entries[entryIndex];
|
entries[entryIndex] = entriesPredefined[PREDEFINED_ENTRY_COUNT + 1];
|
||||||
// used space is doubled because of the individual files plus the single complete file
|
entry = &entries[entryIndex];
|
||||||
entry->curr_size = (FILESYSTEM_SIZE_MB * 1024 * 1024) - (flashfsIdentifyStartOfFreeSpace() * 2);
|
// used space is doubled because of the individual files plus the single complete file
|
||||||
entry->max_size = entry->curr_size;
|
entry->curr_size = (FILESYSTEM_SIZE_MB * 1024 * 1024) - (flashfsUsedSpace * 2);
|
||||||
// This entry has timestamps corresponding to when the filesystem is mounted
|
entry->max_size = entry->curr_size;
|
||||||
emfat_set_entry_cma(entry);
|
// This entry has timestamps corresponding to when the filesystem is mounted
|
||||||
|
emfat_set_entry_cma(entry);
|
||||||
|
}
|
||||||
|
|
||||||
emfat_init(&emfat, "BETAFLT", entries);
|
emfat_init(&emfat, "BETAFLT", entries);
|
||||||
|
LED0_OFF;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,16 +33,9 @@
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
|
|
||||||
#include "drivers/light_led.h"
|
#include "drivers/light_led.h"
|
||||||
#include "drivers/time.h"
|
|
||||||
#include "drivers/flash.h"
|
|
||||||
|
|
||||||
#include "io/flashfs.h"
|
#include "msc/usbd_storage.h"
|
||||||
|
#include "msc/usbd_storage_emfat.h"
|
||||||
#include "pg/flash.h"
|
|
||||||
|
|
||||||
#include "usbd_storage.h"
|
|
||||||
#include "usbd_storage_emfat.h"
|
|
||||||
#include "emfat_file.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define STORAGE_LUN_NBR 1
|
#define STORAGE_LUN_NBR 1
|
||||||
|
@ -66,18 +59,6 @@ static int8_t STORAGE_Init(uint8_t lun)
|
||||||
{
|
{
|
||||||
UNUSED(lun);
|
UNUSED(lun);
|
||||||
|
|
||||||
LED0_ON;
|
|
||||||
|
|
||||||
#ifdef USE_FLASHFS
|
|
||||||
#ifdef USE_FLASH_CHIP
|
|
||||||
flashInit(flashConfig());
|
|
||||||
#endif
|
|
||||||
flashfsInit();
|
|
||||||
#endif
|
|
||||||
emfat_init_files();
|
|
||||||
|
|
||||||
delay(1000);
|
|
||||||
|
|
||||||
LED0_OFF;
|
LED0_OFF;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue