1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 22:35:23 +03:00

Moving boardIdentifier out of config header and into systemConfig (for generic targets)

This commit is contained in:
blckmn 2017-07-23 21:02:27 +10:00
parent da46ef68a9
commit 7a5d1d9b8e
10 changed files with 46 additions and 38 deletions

View file

@ -1197,7 +1197,7 @@ static bool blackboxWriteSysinfo(void)
BLACKBOX_PRINT_HEADER_LINE("Firmware revision", "%s %s (%s) %s", FC_FIRMWARE_NAME, FC_VERSION_STRING, shortGitRevision, targetName); BLACKBOX_PRINT_HEADER_LINE("Firmware revision", "%s %s (%s) %s", FC_FIRMWARE_NAME, FC_VERSION_STRING, shortGitRevision, targetName);
BLACKBOX_PRINT_HEADER_LINE("Firmware date", "%s %s", buildDate, buildTime); BLACKBOX_PRINT_HEADER_LINE("Firmware date", "%s %s", buildDate, buildTime);
BLACKBOX_PRINT_HEADER_LINE("Log start datetime", "%s", blackboxGetStartDateTime()); BLACKBOX_PRINT_HEADER_LINE("Log start datetime", "%s", blackboxGetStartDateTime());
BLACKBOX_PRINT_HEADER_LINE("Craft name", "%s", systemConfig()->name); BLACKBOX_PRINT_HEADER_LINE("Craft name", "%s", pilotConfig()->name);
BLACKBOX_PRINT_HEADER_LINE("I interval", "%d", blackboxIInterval); BLACKBOX_PRINT_HEADER_LINE("I interval", "%d", blackboxIInterval);
BLACKBOX_PRINT_HEADER_LINE("P interval", "%d/%d", blackboxGetRateNum(), blackboxGetRateDenom()); BLACKBOX_PRINT_HEADER_LINE("P interval", "%d/%d", blackboxGetRateNum(), blackboxGetRateDenom());
BLACKBOX_PRINT_HEADER_LINE("P denom", "%d", blackboxConfig()->p_denom); BLACKBOX_PRINT_HEADER_LINE("P denom", "%d", blackboxConfig()->p_denom);

View file

@ -28,6 +28,7 @@
#include "config/config_eeprom.h" #include "config/config_eeprom.h"
#include "config/config_streamer.h" #include "config/config_streamer.h"
#include "config/parameter_group.h" #include "config/parameter_group.h"
#include "fc/config.h"
#include "drivers/system.h" #include "drivers/system.h"
@ -49,7 +50,6 @@ typedef enum {
typedef struct { typedef struct {
uint8_t eepromConfigVersion; uint8_t eepromConfigVersion;
uint8_t magic_be; // magic number, should be 0xBE uint8_t magic_be; // magic number, should be 0xBE
char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER)];
} PG_PACKED configHeader_t; } PG_PACKED configHeader_t;
// Header for each stored PG. // Header for each stored PG.
@ -84,7 +84,6 @@ void initEEPROM(void)
BUILD_BUG_ON(offsetof(packingTest_t, word) != 1); BUILD_BUG_ON(offsetof(packingTest_t, word) != 1);
BUILD_BUG_ON(sizeof(packingTest_t) != 5); BUILD_BUG_ON(sizeof(packingTest_t) != 5);
BUILD_BUG_ON(sizeof(configHeader_t) != 2 + sizeof(TARGET_BOARD_IDENTIFIER));
BUILD_BUG_ON(sizeof(configFooter_t) != 2); BUILD_BUG_ON(sizeof(configFooter_t) != 2);
BUILD_BUG_ON(sizeof(configRecord_t) != 6); BUILD_BUG_ON(sizeof(configRecord_t) != 6);
} }
@ -101,9 +100,6 @@ bool isEEPROMContentValid(void)
if (header->magic_be != 0xBE) { if (header->magic_be != 0xBE) {
return false; return false;
} }
if (strncasecmp(header->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) {
return false;
}
uint16_t crc = CRC_START_VALUE; uint16_t crc = CRC_START_VALUE;
crc = crc16_ccitt_update(crc, header, sizeof(*header)); crc = crc16_ccitt_update(crc, header, sizeof(*header));
@ -138,6 +134,11 @@ bool isEEPROMContentValid(void)
eepromConfigSize = p - &__config_start; eepromConfigSize = p - &__config_start;
/* TODO: Check to be removed when moving to generic targets */
if (strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) {
return false;
}
// CRC has the property that if the CRC itself is included in the calculation the resulting CRC will have constant value // CRC has the property that if the CRC itself is included in the calculation the resulting CRC will have constant value
return crc == CRC_CHECK_VALUE; return crc == CRC_CHECK_VALUE;
} }
@ -196,7 +197,6 @@ static bool writeSettingsToEEPROM(void)
configHeader_t header = { configHeader_t header = {
.eepromConfigVersion = EEPROM_CONF_VERSION, .eepromConfigVersion = EEPROM_CONF_VERSION,
.magic_be = 0xBE, .magic_be = 0xBE,
.boardIdentifier = TARGET_BOARD_IDENTIFIER,
}; };
config_streamer_write(&streamer, (uint8_t *)&header, sizeof(header)); config_streamer_write(&streamer, (uint8_t *)&header, sizeof(header));

View file

@ -20,7 +20,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#define EEPROM_CONF_VERSION 159 #define EEPROM_CONF_VERSION 160
bool isEEPROMContentValid(void); bool isEEPROMContentValid(void);
bool loadEEPROM(void); bool loadEEPROM(void);

View file

@ -1913,22 +1913,22 @@ static void cliVtx(char *cmdline)
#endif // VTX_CONTROL #endif // VTX_CONTROL
static void printName(uint8_t dumpMask, const systemConfig_t *systemConfig) static void printName(uint8_t dumpMask, const pilotConfig_t *pilotConfig)
{ {
const bool equalsDefault = strlen(systemConfig->name) == 0; const bool equalsDefault = strlen(pilotConfig->name) == 0;
cliDumpPrintLinef(dumpMask, equalsDefault, "name %s", equalsDefault ? emptyName : systemConfig->name); cliDumpPrintLinef(dumpMask, equalsDefault, "name %s", equalsDefault ? emptyName : pilotConfig->name);
} }
static void cliName(char *cmdline) static void cliName(char *cmdline)
{ {
const uint32_t len = strlen(cmdline); const uint32_t len = strlen(cmdline);
if (len > 0) { if (len > 0) {
memset(systemConfigMutable()->name, 0, ARRAYLEN(systemConfig()->name)); memset(pilotConfigMutable()->name, 0, ARRAYLEN(pilotConfig()->name));
if (strncmp(cmdline, emptyName, len)) { if (strncmp(cmdline, emptyName, len)) {
strncpy(systemConfigMutable()->name, cmdline, MIN(len, MAX_NAME_LENGTH)); strncpy(pilotConfigMutable()->name, cmdline, MIN(len, MAX_NAME_LENGTH));
} }
} }
printName(DUMP_MASTER, systemConfig()); printName(DUMP_MASTER, pilotConfig());
} }
static void printFeature(uint8_t dumpMask, const featureConfig_t *featureConfig, const featureConfig_t *featureConfigDefault) static void printFeature(uint8_t dumpMask, const featureConfig_t *featureConfig, const featureConfig_t *featureConfigDefault)
@ -2267,9 +2267,9 @@ void printEscInfo(const uint8_t *escInfoBytes, uint8_t bytesRead)
escInfoReceived = true; escInfoReceived = true;
if (calculateCrc8(escInfoBytes, frameLength - 1) == escInfoBytes[frameLength - 1]) { if (calculateCrc8(escInfoBytes, frameLength - 1) == escInfoBytes[frameLength - 1]) {
uint8_t firmwareVersion; uint8_t firmwareVersion = 0;
char firmwareSubVersion; char firmwareSubVersion = 0;
uint8_t escType; uint8_t escType = 0;
switch (escInfoVersion) { switch (escInfoVersion) {
case 1: case 1:
firmwareVersion = escInfoBytes[12]; firmwareVersion = escInfoBytes[12];
@ -2289,23 +2289,18 @@ void printEscInfo(const uint8_t *escInfoBytes, uint8_t bytesRead)
switch (escType) { switch (escType) {
case 1: case 1:
cliPrintLine("KISS8A"); cliPrintLine("KISS8A");
break; break;
case 2: case 2:
cliPrintLine("KISS16A"); cliPrintLine("KISS16A");
break; break;
case 3: case 3:
cliPrintLine("KISS24A"); cliPrintLine("KISS24A");
break; break;
case 5: case 5:
cliPrintLine("KISS Ultralite"); cliPrintLine("KISS Ultralite");
break; break;
default: default:
cliPrintLine("unknown"); cliPrintLine("unknown");
break; break;
} }
@ -2506,8 +2501,8 @@ static void cliMotor(char *cmdline)
return; return;
} }
int motorIndex; int motorIndex = 0;
int motorValue; int motorValue = 0;
char *saveptr; char *saveptr;
char *pch = strtok_r(cmdline, " ", &saveptr); char *pch = strtok_r(cmdline, " ", &saveptr);
@ -3325,7 +3320,7 @@ static void printConfig(char *cmdline, bool doDiff)
} }
cliPrintHashLine("name"); cliPrintHashLine("name");
printName(dumpMask, &systemConfig_Copy); printName(dumpMask, &pilotConfig_Copy);
#ifdef USE_RESOURCE_MGMT #ifdef USE_RESOURCE_MGMT
cliPrintHashLine("resources"); cliPrintHashLine("resources");

View file

@ -117,6 +117,12 @@ PG_RESET_TEMPLATE(featureConfig_t, featureConfig,
.enabledFeatures = DEFAULT_FEATURES | DEFAULT_RX_FEATURE .enabledFeatures = DEFAULT_FEATURES | DEFAULT_RX_FEATURE
); );
PG_REGISTER_WITH_RESET_TEMPLATE(pilotConfig_t, pilotConfig, PG_PILOT_CONFIG, 0);
PG_RESET_TEMPLATE(pilotConfig_t, pilotConfig,
.name = { 0 }
);
PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0); PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0);
#ifndef USE_OSD_SLAVE #ifndef USE_OSD_SLAVE
@ -127,7 +133,7 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
.debug_mode = DEBUG_MODE, .debug_mode = DEBUG_MODE,
.task_statistics = true, .task_statistics = true,
.cpu_overclock = false, .cpu_overclock = false,
.name = { 0 } // FIXME misplaced, see PG_PILOT_CONFIG in CF v1.x .boardIdentifier = TARGET_BOARD_IDENTIFIER
); );
#else #else
PG_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
@ -135,7 +141,7 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
.activeRateProfile = 0, .activeRateProfile = 0,
.debug_mode = DEBUG_MODE, .debug_mode = DEBUG_MODE,
.task_statistics = true, .task_statistics = true,
.name = { 0 } // FIXME misplaced, see PG_PILOT_CONFIG in CF v1.x .boardIdentifier = TARGET_BOARD_IDENTIFIER
); );
#endif #endif
#endif #endif
@ -143,7 +149,8 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
#ifdef USE_OSD_SLAVE #ifdef USE_OSD_SLAVE
PG_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
.debug_mode = DEBUG_MODE, .debug_mode = DEBUG_MODE,
.task_statistics = true .task_statistics = true,
.boardIdentifier = TARGET_BOARD_IDENTIFIER
); );
#endif #endif

View file

@ -59,6 +59,9 @@ typedef enum {
} features_e; } features_e;
#define MAX_NAME_LENGTH 16 #define MAX_NAME_LENGTH 16
typedef struct pilotConfig_s {
char name[MAX_NAME_LENGTH + 1];
} pilotConfig_t;
#ifndef USE_OSD_SLAVE #ifndef USE_OSD_SLAVE
typedef struct systemConfig_s { typedef struct systemConfig_s {
@ -69,7 +72,7 @@ typedef struct systemConfig_s {
#if defined(STM32F4) && !defined(DISABLE_OVERCLOCK) #if defined(STM32F4) && !defined(DISABLE_OVERCLOCK)
uint8_t cpu_overclock; uint8_t cpu_overclock;
#endif #endif
char name[MAX_NAME_LENGTH + 1]; // FIXME misplaced, see PG_PILOT_CONFIG in CF v1.x char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER) + 1];
} systemConfig_t; } systemConfig_t;
#endif #endif
@ -77,9 +80,11 @@ typedef struct systemConfig_s {
typedef struct systemConfig_s { typedef struct systemConfig_s {
uint8_t debug_mode; uint8_t debug_mode;
uint8_t task_statistics; uint8_t task_statistics;
char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER) + 1];
} systemConfig_t; } systemConfig_t;
#endif #endif
PG_DECLARE(pilotConfig_t, pilotConfig);
PG_DECLARE(systemConfig_t, systemConfig); PG_DECLARE(systemConfig_t, systemConfig);
PG_DECLARE(adcConfig_t, adcConfig); PG_DECLARE(adcConfig_t, adcConfig);
PG_DECLARE(beeperDevConfig_t, beeperDevConfig); PG_DECLARE(beeperDevConfig_t, beeperDevConfig);

View file

@ -115,7 +115,6 @@
#endif #endif
static const char * const flightControllerIdentifier = BETAFLIGHT_IDENTIFIER; // 4 UPPER CASE alpha numeric characters that identify the flight controller. static const char * const flightControllerIdentifier = BETAFLIGHT_IDENTIFIER; // 4 UPPER CASE alpha numeric characters that identify the flight controller.
static const char * const boardIdentifier = TARGET_BOARD_IDENTIFIER;
#ifndef USE_OSD_SLAVE #ifndef USE_OSD_SLAVE
@ -346,7 +345,7 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
break; break;
case MSP_BOARD_INFO: case MSP_BOARD_INFO:
sbufWriteData(dst, boardIdentifier, BOARD_IDENTIFIER_LENGTH); sbufWriteData(dst, systemConfig()->boardIdentifier, BOARD_IDENTIFIER_LENGTH);
#ifdef USE_HARDWARE_REVISION_DETECTION #ifdef USE_HARDWARE_REVISION_DETECTION
sbufWriteU16(dst, hardwareRevision); sbufWriteU16(dst, hardwareRevision);
#else #else
@ -695,9 +694,9 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
case MSP_NAME: case MSP_NAME:
{ {
const int nameLen = strlen(systemConfig()->name); const int nameLen = strlen(pilotConfig()->name);
for (int i = 0; i < nameLen; i++) { for (int i = 0; i < nameLen; i++) {
sbufWriteU8(dst, systemConfig()->name[i]); sbufWriteU8(dst, pilotConfig()->name[i]);
} }
} }
break; break;
@ -1806,9 +1805,9 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
#endif #endif
case MSP_SET_NAME: case MSP_SET_NAME:
memset(systemConfigMutable()->name, 0, ARRAYLEN(systemConfig()->name)); memset(pilotConfigMutable()->name, 0, ARRAYLEN(pilotConfig()->name));
for (unsigned int i = 0; i < MIN(MAX_NAME_LENGTH, dataSize); i++) { for (unsigned int i = 0; i < MIN(MAX_NAME_LENGTH, dataSize); i++) {
systemConfigMutable()->name[i] = sbufReadU8(src); pilotConfigMutable()->name[i] = sbufReadU8(src);
} }
break; break;

View file

@ -442,12 +442,12 @@ static void osdDrawSingleElement(uint8_t item)
} }
case OSD_CRAFT_NAME: case OSD_CRAFT_NAME:
if (strlen(systemConfig()->name) == 0) if (strlen(pilotConfig()->name) == 0)
strcpy(buff, "CRAFT_NAME"); strcpy(buff, "CRAFT_NAME");
else { else {
for (int i = 0; i < MAX_NAME_LENGTH; i++) { for (int i = 0; i < MAX_NAME_LENGTH; i++) {
buff[i] = toupper((unsigned char)systemConfig()->name[i]); buff[i] = toupper((unsigned char)pilotConfig()->name[i]);
if (systemConfig()->name[i] == 0) if (pilotConfig()->name[i] == 0)
break; break;
} }
} }

View file

@ -66,6 +66,7 @@ extern "C" {
PG_REGISTER(batteryConfig_t, batteryConfig, PG_BATTERY_CONFIG, 0); PG_REGISTER(batteryConfig_t, batteryConfig, PG_BATTERY_CONFIG, 0);
PG_REGISTER(ledStripConfig_t, ledStripConfig, PG_LED_STRIP_CONFIG, 0); PG_REGISTER(ledStripConfig_t, ledStripConfig, PG_LED_STRIP_CONFIG, 0);
PG_REGISTER(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0); PG_REGISTER(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0);
PG_REGISTER(pilotConfig_t, pilotConfig, PG_PILOT_CONFIG, 0);
PG_REGISTER_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges, PG_ADJUSTMENT_RANGE_CONFIG, 0); PG_REGISTER_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges, PG_ADJUSTMENT_RANGE_CONFIG, 0);
PG_REGISTER_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions, PG_MODE_ACTIVATION_PROFILE, 0); PG_REGISTER_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions, PG_MODE_ACTIVATION_PROFILE, 0);
PG_REGISTER(mixerConfig_t, mixerConfig, PG_MIXER_CONFIG, 0); PG_REGISTER(mixerConfig_t, mixerConfig, PG_MIXER_CONFIG, 0);

View file

@ -64,6 +64,7 @@ extern "C" {
PG_REGISTER(batteryConfig_t, batteryConfig, PG_BATTERY_CONFIG, 0); PG_REGISTER(batteryConfig_t, batteryConfig, PG_BATTERY_CONFIG, 0);
PG_REGISTER(blackboxConfig_t, blackboxConfig, PG_BLACKBOX_CONFIG, 0); PG_REGISTER(blackboxConfig_t, blackboxConfig, PG_BLACKBOX_CONFIG, 0);
PG_REGISTER(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0); PG_REGISTER(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0);
PG_REGISTER(pilotConfig_t, pilotConfig, PG_PILOT_CONFIG, 0);
timeUs_t simulationTime = 0; timeUs_t simulationTime = 0;
batteryState_e simulationBatteryState; batteryState_e simulationBatteryState;