From 196337a8ded9e8b9f991b5fe7dc67e0930575f5e Mon Sep 17 00:00:00 2001 From: rusefi Date: Wed, 29 Jul 2020 22:48:41 -0400 Subject: [PATCH] NA6 progress --- firmware/config/engines/mazda_miata_1_6.cpp | 14 +++++++------- firmware/controllers/algo/engine_configuration.h | 2 ++ firmware/controllers/core/fsio_impl.cpp | 9 +++++++-- firmware/controllers/core/fsio_impl.h | 3 ++- unit_tests/tests/test_idle_controller.cpp | 4 ++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/firmware/config/engines/mazda_miata_1_6.cpp b/firmware/config/engines/mazda_miata_1_6.cpp index c3a08c08bc..b341e14a1c 100644 --- a/firmware/config/engines/mazda_miata_1_6.cpp +++ b/firmware/config/engines/mazda_miata_1_6.cpp @@ -112,7 +112,7 @@ static void miataNAcommonEngineSettings(DECLARE_CONFIG_PARAMETER_SIGNATURE) { setCommonNTCSensor(&engineConfiguration->iat, 2700); #if IGN_LOAD_COUNT == DEFAULT_IGN_LOAD_COUNT - copyTimingTable(mapBased16IgnitionTable, config->ignitionTable); + MEMCPY(config->ignitionTable, mapBased16IgnitionTable); #endif engineConfiguration->idle.solenoidFrequency = 160; @@ -134,10 +134,10 @@ void miataNAcommon(DECLARE_CONFIG_PARAMETER_SIGNATURE) { static void setMiataNA6_settings(DECLARE_CONFIG_PARAMETER_SIGNATURE) { engineConfiguration->isFasterEngineSpinUpEnabled = true; - memcpy(config->veRpmBins, ve16RpmBins, sizeof(ve16RpmBins)); - memcpy(config->veLoadBins, ve16LoadBins, sizeof(ve16LoadBins)); + MEMCPY(config->veRpmBins, ve16RpmBins); + MEMCPY(config->veLoadBins, ve16LoadBins); #if DEFAULT_FUEL_LOAD_COUNT == FUEL_LOAD_COUNT - copyFuelTable(mapBased16VeTable, config->veTable); + MEMCPY(config->veTable, mapBased16VeTable); #endif setWholeFuelMap(6 PASS_CONFIG_PARAMETER_SUFFIX); @@ -194,7 +194,7 @@ static void setMiataNA6_settings(DECLARE_CONFIG_PARAMETER_SIGNATURE) { engineConfiguration->tpsMax = 656; // convert 12to10 bit (ADC/4) engineConfiguration->injectionMode = IM_BATCH; - copyFuelTable(miataNA6_maf_fuel_table, config->fuelTable); + MEMCPY(config->fuelTable, miataNA6_maf_fuel_table); } /** @@ -386,10 +386,10 @@ void setMiataNA6_MAP_MRE(DECLARE_CONFIG_PARAMETER_SIGNATURE) { engineConfiguration->useFSIO12ForIdleOffset = true; - setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_OFFSET), "ac_on_switch 0 cfg_acIdleExtraOffset if" PASS_ENGINE_PARAMETER_SUFFIX); + setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_OFFSET), "ac_on_switch 0 cfg_acIdleExtraOffset if" PASS_CONFIG_PARAMETER_SUFFIX); engineConfiguration->useFSIO13ForIdleMinValue = true; - setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch 0 cfg_acIdleExtraMin if" PASS_ENGINE_PARAMETER_SUFFIX); + setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch 0 cfg_acIdleExtraMin if" PASS_CONFIG_PARAMETER_SUFFIX); engineConfiguration->useIdleTimingPidControl = true; diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 5931a0d673..3ed305d200 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -53,6 +53,8 @@ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE); void commonFrankensoAnalogInputs(engine_configuration_s *engineConfiguration); void setFrankenso0_1_joystick(engine_configuration_s *engineConfiguration); +#define MEMCPY(dest, src) {memcpy(dest, src, sizeof(src));} + void copyTargetAfrTable(fuel_table_t const source, afr_table_t destination); void copyFuelTable(fuel_table_t const source, fuel_table_t destination); void copyTimingTable(ignition_table_t const source, ignition_table_t destination); diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index eb34704278..038f0594f2 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -614,7 +614,7 @@ static void setFsioSetting(float humanIndexF, float value) { #endif } -void setFsioExpression(const char *indexStr, const char *quotedLine DECLARE_ENGINE_PARAMETER_SUFFIX) { +void setFsioExpression(const char *indexStr, const char *quotedLine DECLARE_CONFIG_PARAMETER_SUFFIX) { int index = atoi(indexStr) - 1; if (index < 0 || index >= FSIO_COMMAND_COUNT) { scheduleMsg(logger, "invalid FSIO index: %d", index); @@ -628,6 +628,11 @@ void setFsioExpression(const char *indexStr, const char *quotedLine DECLARE_ENGI scheduleMsg(logger, "setting user out #%d to [%s]", index + 1, l); strcpy(config->fsioFormulas[index], l); +} + +void applyFsioExpression(const char *indexStr, const char *quotedLine DECLARE_ENGINE_PARAMETER_SUFFIX) { + setFsioExpression(indexStr, quotedLine PASS_CONFIG_PARAMETER_SUFFIX); + // this would apply the changes applyFsioConfiguration(PASS_ENGINE_PARAMETER_SIGNATURE); showFsioInfo(); @@ -718,7 +723,7 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { #endif /* EFI_PROD_CODE */ #if EFI_PROD_CODE || EFI_SIMULATOR - addConsoleActionSS("set_rpn_expression", setFsioExpression); + addConsoleActionSS("set_rpn_expression", applyFsioExpression); addConsoleActionFF("set_fsio_setting", setFsioSetting); addConsoleAction("fsioinfo", showFsioInfo); addConsoleActionS("rpn_eval", (VoidCharPtr) rpnEval); diff --git a/firmware/controllers/core/fsio_impl.h b/firmware/controllers/core/fsio_impl.h index a20d1155fe..e44df761e0 100644 --- a/firmware/controllers/core/fsio_impl.h +++ b/firmware/controllers/core/fsio_impl.h @@ -40,7 +40,8 @@ void setFsioExt(int index, brain_pin_e pin, const char * exp, int pwmFrequency D void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); void runFsio(DECLARE_ENGINE_PARAMETER_SIGNATURE); -void setFsioExpression(const char *indexStr, const char *quotedLine DECLARE_ENGINE_PARAMETER_SUFFIX); +void setFsioExpression(const char *indexStr, const char *quotedLine DECLARE_CONFIG_PARAMETER_SUFFIX); +void applyFsioExpression(const char *indexStr, const char *quotedLine DECLARE_ENGINE_PARAMETER_SUFFIX); float getFsioOutputValue(int index DECLARE_ENGINE_PARAMETER_SUFFIX); void applyFsioConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE); void onConfigurationChangeFsioCallback(engine_configuration_s *previousConfiguration DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/unit_tests/tests/test_idle_controller.cpp b/unit_tests/tests/test_idle_controller.cpp index 0e8911fa96..d1a4035906 100644 --- a/unit_tests/tests/test_idle_controller.cpp +++ b/unit_tests/tests/test_idle_controller.cpp @@ -33,10 +33,10 @@ TEST(idle, fsioPidParameters) { engineConfiguration->acIdleExtraMin = 30; engineConfiguration->useFSIO12ForIdleOffset = true; - setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_OFFSET), "ac_on_switch 0 cfg_acIdleExtraOffset if" PASS_ENGINE_PARAMETER_SUFFIX); + applyFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_OFFSET), "ac_on_switch 0 cfg_acIdleExtraOffset if" PASS_ENGINE_PARAMETER_SUFFIX); engineConfiguration->useFSIO13ForIdleMinValue = true; - setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch 0 cfg_acIdleExtraMin if" PASS_ENGINE_PARAMETER_SUFFIX); + applyFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch 0 cfg_acIdleExtraMin if" PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_EQ(1, hasAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE)); setMockVoltage(engineConfiguration->acSwitchAdc, 0 PASS_ENGINE_PARAMETER_SUFFIX);