Extract common code for all F1 devices (#162)

* main: acctually call InitConfiguration()

* f1_rev2: enable EFL and MFS (Managed Flash Storate)

* f1_dual: enable EFL and MFS (Managed Flash Storate)

* f1 boards: extract common code

* port.h: add LoadDefaults() method to Configuration class

* f1 boards: store Configuration to MFS

* f1 boards: common getTsSignature() for all f1 boards
This commit is contained in:
Andrey G 2022-09-20 02:31:30 +03:00 committed by GitHub
parent 0a4a609db9
commit adae19db09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 110 additions and 146 deletions

View File

@ -0,0 +1,87 @@
#include "port.h"
#include "wideband_config.h"
#include "hal.h"
#include "hal_mfs.h"
// Storage
static const MFSConfig mfscfg1 = {
.flashp = (BaseFlash *)&EFLD1,
.erased = 0xFFFFFFFFU,
.bank_size = 4096U,
.bank0_start = 120U,
.bank0_sectors = 4U,
.bank1_start = 124U,
.bank1_sectors = 4U
};
static MFSDriver mfs1;
// Settings
static Configuration cfg;
#define MFS_CONFIGURATION_RECORD_ID 1
// Configuration defaults
void Configuration::LoadDefaults()
{
CanIndexOffset = 0;
/* Finaly */
Tag = ExpectedTag;
}
int InitConfiguration()
{
size_t size = GetConfiguratiuonSize();
/* Starting EFL driver.*/
eflStart(&EFLD1, NULL);
mfsObjectInit(&mfs1);
mfsStart(&mfs1, &mfscfg1);
mfs_error_t err = mfsReadRecord(&mfs1, MFS_CONFIGURATION_RECORD_ID, &size, GetConfiguratiuonPtr());
if ((err != MFS_NO_ERROR) || (size != GetConfiguratiuonSize() || !cfg.IsValid())) {
/* load defaults */
cfg.LoadDefaults();
}
return 0;
}
static Configuration c;
Configuration& GetConfiguration()
{
return cfg;
}
void SetConfiguration(const Configuration& newConfig)
{
cfg = newConfig;
SaveConfiguration();
}
/* TS stuff */
void SaveConfiguration() {
/* TODO: handle error */
mfsWriteRecord(&mfs1, MFS_CONFIGURATION_RECORD_ID, GetConfiguratiuonSize(), GetConfiguratiuonPtr());
}
uint8_t *GetConfiguratiuonPtr()
{
return (uint8_t *)&cfg;
}
size_t GetConfiguratiuonSize()
{
return sizeof(cfg);
}
const char *getTsSignature() {
return TS_SIGNATURE;
}

View File

@ -2,6 +2,8 @@ USE_BOOTLOADER = no
MCU = cortex-m3
ALLCPPSRC += $(BOARDDIR)/../f1_common/f1_port.cpp
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f1xx.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F1xx/platform.mk
include $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/mk/port.mk

View File

@ -72,7 +72,7 @@
* @brief Enables the EFlash subsystem.
*/
#if !defined(HAL_USE_EFL) || defined(__DOXYGEN__)
#define HAL_USE_EFL FALSE
#define HAL_USE_EFL TRUE
#endif
/**

View File

@ -112,41 +112,3 @@ AnalogResult AnalogSample()
.VirtualGroundVoltageInt = HALF_VCC,
};
}
static struct {
uint8_t pad[128];
} config;
static Configuration c;
Configuration& GetConfiguration()
{
// TODO: implement me!
return c;
}
void SetConfiguration(const Configuration& newConfig)
{
// TODO: implement me!
}
/* TS stuff */
void SaveConfiguration() {
// TODO: implement me!
}
uint8_t *GetConfiguratiuonPtr()
{
return (uint8_t *)&config;
}
size_t GetConfiguratiuonSize()
{
return sizeof(config);
}
#define TS_SIGNATURE "rusEFI 2022.05.29.wideband_dual"
const char *getTsSignature() {
return TS_SIGNATURE;
}

View File

@ -1,5 +1,8 @@
#pragma once
// TS settings
#define TS_SIGNATURE "rusEFI 2022.05.29.wideband_dual"
// This board implements two channels
#define AFR_CHANNELS 2
#define EGT_CHANNELS 2

View File

@ -2,6 +2,8 @@ USE_BOOTLOADER = no
MCU = cortex-m3
ALLCPPSRC += $(BOARDDIR)/../f1_common/f1_port.cpp
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f1xx.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F1xx/platform.mk
include $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/mk/port.mk

View File

@ -72,7 +72,7 @@
* @brief Enables the EFlash subsystem.
*/
#if !defined(HAL_USE_EFL) || defined(__DOXYGEN__)
#define HAL_USE_EFL FALSE
#define HAL_USE_EFL TRUE
#endif
/**

View File

@ -76,41 +76,3 @@ AnalogResult AnalogSample()
.VirtualGroundVoltageInt = HALF_VCC,
};
}
static struct {
uint8_t pad[128];
} config;
static Configuration c;
Configuration& GetConfiguration()
{
// TODO: implement me!
return c;
}
void SetConfiguration(const Configuration& newConfig)
{
// TODO: implement me!
}
/* TS stuff */
void SaveConfiguration() {
// TODO: implement me!
}
uint8_t *GetConfiguratiuonPtr()
{
return (uint8_t *)&config;
}
size_t GetConfiguratiuonSize()
{
return sizeof(config);
}
#define TS_SIGNATURE "rusEFI 2022.05.29.wideband_f1"
const char *getTsSignature() {
return TS_SIGNATURE;
}

View File

@ -1,5 +1,8 @@
#pragma once
// TS settings
#define TS_SIGNATURE "rusEFI 2022.05.29.wideband_f1"
// Fundamental board constants
#define VCC_VOLTS (3.3f)
#define HALF_VCC (VCC_VOLTS / 2)

View File

@ -2,6 +2,8 @@ USE_BOOTLOADER = no
MCU = cortex-m3
ALLCPPSRC += $(BOARDDIR)/../f1_common/f1_port.cpp
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f1xx.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F1xx/platform.mk
include $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/mk/port.mk

View File

@ -1,11 +1,7 @@
#include "port.h"
#include "wideband_config.h"
#include "hal.h"
#include "hal_mfs.h"
#define ADC_CHANNEL_COUNT 5
#define ADC_SAMPLE ADC_SAMPLE_7P5
@ -77,67 +73,3 @@ AnalogResult AnalogSample()
.VirtualGroundVoltageInt = HALF_VCC,
};
}
// Settings
static struct {
uint8_t pad[128];
} config;
const MFSConfig mfscfg1 = {
.flashp = (BaseFlash *)&EFLD1,
.erased = 0xFFFFFFFFU,
.bank_size = 4096U,
.bank0_start = 120U,
.bank0_sectors = 4U,
.bank1_start = 124U,
.bank1_sectors = 4U
};
MFSDriver mfs1;
int InitConfiguration()
{
/* Starting EFL driver.*/
eflStart(&EFLD1, NULL);
mfsObjectInit(&mfs1);
mfsStart(&mfs1, &mfscfg1);
return 0;
}
static Configuration c;
Configuration& GetConfiguration()
{
// TODO: implement me!
return c;
}
void SetConfiguration(const Configuration& newConfig)
{
// TODO: implement me!
}
/* TS stuff */
void SaveConfiguration() {
// TODO: implement me!
}
uint8_t *GetConfiguratiuonPtr()
{
return (uint8_t *)&config;
}
size_t GetConfiguratiuonSize()
{
return sizeof(config);
}
#define TS_SIGNATURE "rusEFI 2022.05.29.wideband_f1"
const char *getTsSignature() {
return TS_SIGNATURE;
}

View File

@ -1,5 +1,8 @@
#pragma once
// TS settings
#define TS_SIGNATURE "rusEFI 2022.05.29.wideband_f1"
// Fundamental board constants
#define VCC_VOLTS (3.3f)
#define HALF_VCC (VCC_VOLTS / 2)

View File

@ -30,6 +30,7 @@ public:
{
return this->Tag == ExpectedTag;
}
void LoadDefaults();
// Actual configuration data
uint8_t CanIndexOffset = 0;
@ -38,6 +39,7 @@ public:
uint8_t pad[128 - 1 - 4];
};
int InitConfiguration();
Configuration& GetConfiguration();
void SetConfiguration(const Configuration& newConfig);

View File

@ -11,6 +11,7 @@
#include "io_pins.h"
#include "auxout.h"
#include "max31855.h"
#include "port.h"
#include "wideband_config.h"
@ -23,6 +24,9 @@ int main() {
halInit();
chSysInit();
// Load configuration
InitConfiguration();
// Fire up all of our threads
StartSampling();
InitPumpDac();