simulator reads/writes configuration (#4605)
* simulator reads/writes configuration * c_str * include order
This commit is contained in:
parent
6ef99de79b
commit
91566b86d3
|
@ -64,12 +64,15 @@ extern bool main_loop_started;
|
||||||
#include "HD44780.h"
|
#include "HD44780.h"
|
||||||
#include "rusefi.h"
|
#include "rusefi.h"
|
||||||
#include "pin_repository.h"
|
#include "pin_repository.h"
|
||||||
#include "flash_main.h"
|
|
||||||
#include "max31855.h"
|
#include "max31855.h"
|
||||||
#include "single_timer_executor.h"
|
#include "single_timer_executor.h"
|
||||||
#include "periodic_task.h"
|
#include "periodic_task.h"
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
|
|
||||||
|
#if EFI_INTERNAL_FLASH
|
||||||
|
#include "flash_main.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if EFI_CJ125
|
#if EFI_CJ125
|
||||||
#include "cj125.h"
|
#include "cj125.h"
|
||||||
#endif /* EFI_CJ125 */
|
#endif /* EFI_CJ125 */
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#if EFI_INTERNAL_FLASH
|
#if EFI_INTERNAL_FLASH
|
||||||
|
|
||||||
|
#include "mpu_util.h"
|
||||||
#include "flash_main.h"
|
#include "flash_main.h"
|
||||||
#include "eficonsole.h"
|
#include "eficonsole.h"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
flash*.bin
|
|
@ -18,6 +18,11 @@
|
||||||
#include "chprintf.h"
|
#include "chprintf.h"
|
||||||
#include "rusEfiFunctionalTest.h"
|
#include "rusEfiFunctionalTest.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#define CONSOLE_WA_SIZE THD_WORKING_AREA_SIZE(4096)
|
#define CONSOLE_WA_SIZE THD_WORKING_AREA_SIZE(4096)
|
||||||
|
|
||||||
bool main_loop_started = false;
|
bool main_loop_started = false;
|
||||||
|
@ -188,3 +193,76 @@ int main(int argc, char** argv) {
|
||||||
chEvtUnregister(chnGetEventSource(&SD2), &sd2fel);
|
chEvtUnregister(chnGetEventSource(&SD2), &sd2fel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uintptr_t getFlashAddrFirstCopy() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uintptr_t getFlashAddrSecondCopy() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "flash_int.h"
|
||||||
|
|
||||||
|
static std::string makeFileName(flashaddr_t addr) {
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << "flash" << addr << ".bin";
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
int intFlashErase(flashaddr_t address, size_t size) {
|
||||||
|
// Try to delete the file, swallow any errors (we can overwrite it anyway)
|
||||||
|
try {
|
||||||
|
std::filesystem::remove(makeFileName(address));
|
||||||
|
} catch (...) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
int intFlashRead(flashaddr_t address, char* buffer, size_t size) {
|
||||||
|
auto fileName = makeFileName(address);
|
||||||
|
|
||||||
|
printf("Simulator: reading config from %s\n", fileName.c_str());
|
||||||
|
|
||||||
|
std::ifstream flash;
|
||||||
|
flash.open(fileName, std::ios::binary);
|
||||||
|
|
||||||
|
if (!flash.is_open()) {
|
||||||
|
// no file, nothing to read
|
||||||
|
// setting ot all 1s emulates real erased flash behavior
|
||||||
|
memset(buffer, 0xFF, size);
|
||||||
|
return HAL_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
flash.read(buffer, size);
|
||||||
|
|
||||||
|
flash.close();
|
||||||
|
|
||||||
|
return HAL_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int intFlashWrite(flashaddr_t address, const char* buffer, size_t size) {
|
||||||
|
auto fileName = makeFileName(address);
|
||||||
|
printf("Simulator: writing config to %s\n", fileName.c_str());
|
||||||
|
|
||||||
|
std::ofstream flash;
|
||||||
|
flash.open(fileName, std::ios::binary | std::ios::trunc);
|
||||||
|
|
||||||
|
flash.write(buffer, size);
|
||||||
|
|
||||||
|
flash.close();
|
||||||
|
|
||||||
|
return HAL_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write from file in to memory
|
||||||
|
// void simulatorWriteFlash(const persistent_config_container_s& cfg) {
|
||||||
|
// std::ofstream flash;
|
||||||
|
// flash.open(simFileName, std::ios::binary | std::ios::trunc);
|
||||||
|
|
||||||
|
// const char* ptr = reinterpret_cast<const char*>(&cfg);
|
||||||
|
// flash.write(ptr, sizeof(cfg));
|
||||||
|
|
||||||
|
// flash.close();
|
||||||
|
// }
|
||||||
|
|
|
@ -123,7 +123,10 @@
|
||||||
|
|
||||||
#define FUEL_MATH_EXTREME_LOGGING FALSE
|
#define FUEL_MATH_EXTREME_LOGGING FALSE
|
||||||
#define EFI_ANALOG_SENSORS TRUE
|
#define EFI_ANALOG_SENSORS TRUE
|
||||||
#define EFI_INTERNAL_FLASH FALSE
|
#define EFI_INTERNAL_FLASH TRUE
|
||||||
|
#define EFI_STORAGE_INT_FLASH TRUE
|
||||||
|
#define EFI_FLASH_WRITE_THREAD TRUE
|
||||||
|
#define EFI_STORAGE_EXT_SNOR FALSE
|
||||||
#define EFI_RTC FALSE
|
#define EFI_RTC FALSE
|
||||||
#define EFI_MALFUNCTION_INDICATOR FALSE
|
#define EFI_MALFUNCTION_INDICATOR FALSE
|
||||||
#define EFI_HD44780_LCD FALSE
|
#define EFI_HD44780_LCD FALSE
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#if HAL_USE_CAN
|
#if HAL_USE_CAN
|
||||||
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
|
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
|
||||||
bool isValidCanTxPin(brain_pin_e) { return true; }
|
static bool isValidCanTxPin(brain_pin_e) { return true; }
|
||||||
bool isValidCanRxPin(brain_pin_e) { return true; }
|
static bool isValidCanRxPin(brain_pin_e) { return true; }
|
||||||
#endif // HAL_USE_CAN
|
#endif // HAL_USE_CAN
|
||||||
|
|
||||||
|
static bool allowFlashWhileRunning() { return true; }
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <chprintf.h>
|
#include <chprintf.h>
|
||||||
#include "rusefi_lua.h"
|
#include "rusefi_lua.h"
|
||||||
#include "can_hw.h"
|
#include "can_hw.h"
|
||||||
|
#include "flash_main.h"
|
||||||
|
|
||||||
#define DEFAULT_SIM_RPM 1200
|
#define DEFAULT_SIM_RPM 1200
|
||||||
#define DEFAULT_SNIFFER_THR 2500
|
#define DEFAULT_SNIFFER_THR 2500
|
||||||
|
@ -98,7 +99,9 @@ void rusEfiFunctionalTest(void) {
|
||||||
|
|
||||||
// todo: reduce code duplication with initEngineContoller
|
// todo: reduce code duplication with initEngineContoller
|
||||||
|
|
||||||
resetConfigurationExt(MINIMAL_PINS);
|
initFlash();
|
||||||
|
loadConfiguration();
|
||||||
|
|
||||||
enableTriggerStimulator();
|
enableTriggerStimulator();
|
||||||
|
|
||||||
commonInitEngineController();
|
commonInitEngineController();
|
||||||
|
|
Loading…
Reference in New Issue