From ef729cccdd5a4905aab1a3f72718364cec88c4f0 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 25 Nov 2014 09:03:25 -0600 Subject: [PATCH] auto-sync --- firmware/controllers/algo/advance_map.cpp | 4 +++- firmware/controllers/math/engine_math.cpp | 9 +++++---- firmware/controllers/trigger/trigger_structure.cpp | 4 +++- firmware/emulation/wave_analyzer.cpp | 4 +++- firmware/global.h | 10 +++++++++- unit_tests/global.h | 2 ++ win32_functional_tests/simulator/global.h | 6 +++++- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index db7fbbd5ca..a844edf35d 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -50,7 +50,9 @@ float getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) { } else { angle = getBaseAdvance(rpm, engineLoad); } - return fixAngle(angle - engineConfiguration->ignitionOffset PASS_ENGINE_PARAMETER); + angle -= engineConfiguration->ignitionOffset; + angle = fixAngle(angle PASS_ENGINE_PARAMETER); + return angle; } void prepareTimingMap(void) { diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index b42c283ff2..8f1032d559 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -56,9 +56,9 @@ float fixAngle(float angle DECLARE_ENGINE_PARAMETER_S) { efiAssert(engineConfiguration->engineCycle != 0, "engine cycle", NAN); // I guess this implementation would be faster than 'angle % 720' while (angle < 0) - angle += engineConfiguration->engineCycle; - while (angle >= engineConfiguration->engineCycle) - angle -= engineConfiguration->engineCycle; + angle += CONFIG(engineCycle); + while (angle >= CONFIG(engineCycle)) + angle -= CONFIG(engineCycle); return angle; } @@ -281,7 +281,8 @@ int getEngineCycleEventCount2(operation_mode_e mode, trigger_shape_s * s) { void findTriggerPosition(trigger_shape_s * s, event_trigger_position_s *position, float angleOffset DECLARE_ENGINE_PARAMETER_S) { - angleOffset = fixAngle(angleOffset + engineConfiguration->globalTriggerAngleOffset PASS_ENGINE_PARAMETER); + angleOffset += engineConfiguration->globalTriggerAngleOffset; + angleOffset = fixAngle(angleOffset PASS_ENGINE_PARAMETER); int engineCycleEventCount = getEngineCycleEventCount2(getOperationMode(engineConfiguration), s); diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index f095ab4c3f..82c3464352 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -72,7 +72,9 @@ void trigger_shape_s::setTriggerShapeSynchPointIndex(engine_configuration_s *eng // explicit check for zero to avoid issues where logical zero is not exactly zero due to float nature eventAngles[i] = 0; } else { - eventAngles[i] = fixAngle(getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle PASS_ENGINE_PARAMETER); + float angle = getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle; + angle = fixAngle(angle PASS_ENGINE_PARAMETER); + eventAngles[i] = angle; } } } diff --git a/firmware/emulation/wave_analyzer.cpp b/firmware/emulation/wave_analyzer.cpp index 08ec14ab23..06218d6ac9 100644 --- a/firmware/emulation/wave_analyzer.cpp +++ b/firmware/emulation/wave_analyzer.cpp @@ -228,7 +228,9 @@ static void reportWave(Logging *logging, int index) { float oneDegreeUs = getOneDegreeTimeUs(getRpm()); appendPrintf(logging, "advance%d%s", index, DELIMETER); - appendFloat(logging, fixAngle((offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset PASS_ENGINE_PARAMETER), 3); + float angle = (offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset; + angle = fixAngle(angle PASS_ENGINE_PARAMETER); + appendFloat(logging, angle, 3); appendPrintf(logging, "%s", DELIMETER); } } diff --git a/firmware/global.h b/firmware/global.h index 9ad4262a3d..d129cd7111 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -71,11 +71,19 @@ typedef Thread thread_t; #define EXTERN_ENGINE extern Engine *engine; \ extern engine_configuration_s *engineConfiguration; \ - extern board_configuration_s *boardConfiguration; + extern board_configuration_s *boardConfiguration; \ + extern persistent_config_container_s persistentState #define DECLARE_ENGINE_PARAMETER_F void #define DECLARE_ENGINE_PARAMETER_S #define PASS_ENGINE_PARAMETER_F #define PASS_ENGINE_PARAMETER +/** + * this macro allows the compiled to figure out the complete static address, that's a performance + * optimization + */ +#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x + + #endif /* GLOBAL_H_ */ diff --git a/unit_tests/global.h b/unit_tests/global.h index 6432d71232..09d57329cb 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -45,4 +45,6 @@ class Engine; #define PASS_ENGINE_PARAMETER_F engine, engineConfiguration #define PASS_ENGINE_PARAMETER , engine, engineConfiguration +#define CONFIG(x) engineConfiguration->x + #endif /* GLOBAL_H_ */ diff --git a/win32_functional_tests/simulator/global.h b/win32_functional_tests/simulator/global.h index c0991f66f7..269bdcb450 100644 --- a/win32_functional_tests/simulator/global.h +++ b/win32_functional_tests/simulator/global.h @@ -90,9 +90,13 @@ typedef EventListener event_listener_t; #define EXTERN_ENGINE extern Engine *engine; \ extern engine_configuration_s *engineConfiguration; \ - extern board_configuration_s *boardConfiguration; + extern board_configuration_s *boardConfiguration; \ + extern persistent_config_container_s persistentState #define DECLARE_ENGINE_PARAMETER_F void #define DECLARE_ENGINE_PARAMETER_S #define PASS_ENGINE_PARAMETER_F #define PASS_ENGINE_PARAMETER + +#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x +