simulator reads/writes configuration (#4605)

* simulator reads/writes configuration

* c_str

* include order
This commit is contained in:
Matthew Kennedy 2022-09-23 05:47:50 -07:00 committed by GitHub
parent 36575c1d0e
commit b76a7cbcd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 96 additions and 5 deletions

View File

@ -64,12 +64,15 @@ extern bool main_loop_started;
#include "HD44780.h"
#include "rusefi.h"
#include "pin_repository.h"
#include "flash_main.h"
#include "max31855.h"
#include "single_timer_executor.h"
#include "periodic_task.h"
#endif /* EFI_PROD_CODE */
#if EFI_INTERNAL_FLASH
#include "flash_main.h"
#endif
#if EFI_CJ125
#include "cj125.h"
#endif /* EFI_CJ125 */

View File

@ -11,6 +11,7 @@
#if EFI_INTERNAL_FLASH
#include "mpu_util.h"
#include "flash_main.h"
#include "eficonsole.h"

1
simulator/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
flash*.bin

View File

@ -18,6 +18,11 @@
#include "chprintf.h"
#include "rusEfiFunctionalTest.h"
#include <iostream>
#include <filesystem>
#include <fstream>
#include <sstream>
#define CONSOLE_WA_SIZE THD_WORKING_AREA_SIZE(4096)
bool main_loop_started = false;
@ -188,3 +193,76 @@ int main(int argc, char** argv) {
chEvtUnregister(chnGetEventSource(&SD2), &sd2fel);
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();
// }

View File

@ -123,7 +123,10 @@
#define FUEL_MATH_EXTREME_LOGGING FALSE
#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_MALFUNCTION_INDICATOR FALSE
#define EFI_HD44780_LCD FALSE

View File

@ -2,6 +2,8 @@
#if HAL_USE_CAN
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
bool isValidCanTxPin(brain_pin_e) { return true; }
bool isValidCanRxPin(brain_pin_e) { return true; }
static bool isValidCanTxPin(brain_pin_e) { return true; }
static bool isValidCanRxPin(brain_pin_e) { return true; }
#endif // HAL_USE_CAN
static bool allowFlashWhileRunning() { return true; }

View File

@ -25,6 +25,7 @@
#include <chprintf.h>
#include "rusefi_lua.h"
#include "can_hw.h"
#include "flash_main.h"
#define DEFAULT_SIM_RPM 1200
#define DEFAULT_SNIFFER_THR 2500
@ -98,7 +99,9 @@ void rusEfiFunctionalTest(void) {
// todo: reduce code duplication with initEngineContoller
resetConfigurationExt(MINIMAL_PINS);
initFlash();
loadConfiguration();
enableTriggerStimulator();
commonInitEngineController();