1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 21:05:35 +03:00

Merge branch 'blackbox-flash' of https://github.com/sherlockflight/cleanflight-dev into sherlockflight-blackbox-flash

This commit is contained in:
Dominic Clifton 2015-02-22 17:24:39 +00:00
commit 2f09b7d1d9
20 changed files with 1417 additions and 119 deletions

View file

@ -50,6 +50,7 @@
#include "io/gimbal.h"
#include "io/serial.h"
#include "io/ledstrip.h"
#include "io/flashfs.h"
#include "telemetry/telemetry.h"
@ -232,6 +233,10 @@ const char *boardIdentifier = TARGET_BOARD_IDENTIFIER;
// DEPRECATED - Use MSP_BUILD_INFO instead
#define MSP_BF_BUILD_INFO 69 //out message build date as well as some space for future expansion
#define MSP_DATAFLASH_SUMMARY 70 //out message - get description of dataflash chip
#define MSP_DATAFLASH_READ 71 //out message - get content of dataflash chip
#define MSP_DATAFLASH_ERASE 72 //in message - erase dataflash chip
//
// Multwii original MSP commands
//
@ -434,24 +439,24 @@ static uint32_t read32(void)
return t;
}
static void headSerialResponse(uint8_t err, uint8_t s)
static void headSerialResponse(uint8_t err, uint8_t responseBodySize)
{
serialize8('$');
serialize8('M');
serialize8(err ? '!' : '>');
currentPort->checksum = 0; // start calculating a new checksum
serialize8(s);
serialize8(responseBodySize);
serialize8(currentPort->cmdMSP);
}
static void headSerialReply(uint8_t s)
static void headSerialReply(uint8_t responseBodySize)
{
headSerialResponse(0, s);
headSerialResponse(0, responseBodySize);
}
static void headSerialError(uint8_t s)
static void headSerialError(uint8_t responseBodySize)
{
headSerialResponse(1, s);
headSerialResponse(1, responseBodySize);
}
static void tailSerialReply(void)
@ -531,6 +536,46 @@ reset:
}
}
static void serializeDataflashSummaryReply(void)
{
headSerialReply(1 + 3 * 4);
#ifdef USE_FLASHFS
const flashGeometry_t *geometry = flashfsGetGeometry();
serialize8(flashfsIsReady() ? 1 : 0);
serialize32(geometry->sectors);
serialize32(geometry->totalSize);
serialize32(flashfsGetOffset()); // Effectively the current number of bytes stored on the volume
#else
serialize8(0);
serialize32(0);
serialize32(0);
serialize32(0);
#endif
}
#ifdef USE_FLASHFS
static void serializeDataflashReadReply(uint32_t address, uint8_t size)
{
uint8_t buffer[128];
int bytesRead;
if (size > sizeof(buffer)) {
size = sizeof(buffer);
}
headSerialReply(4 + size);
serialize32(address);
// bytesRead will be lower than that requested if we reach end of volume
bytesRead = flashfsReadAbs(address, buffer, size);
for (int i = 0; i < bytesRead; i++) {
serialize8(buffer[i]);
}
}
#endif
static void resetMspPort(mspPort_t *mspPortToReset, serialPort_t *serialPort, mspPortUsage_e usage)
{
memset(mspPortToReset, 0, sizeof(mspPort_t));
@ -1158,6 +1203,21 @@ static bool processOutCommand(uint8_t cmdMSP)
}
break;
#endif
case MSP_DATAFLASH_SUMMARY:
serializeDataflashSummaryReply();
break;
#ifdef USE_FLASHFS
case MSP_DATAFLASH_READ:
{
uint32_t readAddress = read32();
serializeDataflashReadReply(readAddress, 128);
}
break;
#endif
case MSP_BF_BUILD_INFO:
headSerialReply(11 + 4 + 4);
for (i = 0; i < 11; i++)
@ -1371,6 +1431,13 @@ static bool processInCommand(void)
writeEEPROM();
readEEPROM();
break;
#ifdef USE_FLASHFS
case MSP_DATAFLASH_ERASE:
flashfsEraseCompletely();
break;
#endif
#ifdef GPS
case MSP_SET_RAW_GPS:
if (read8()) {