From 7bb8bb7f140d6d96962da164262b42e2ed3f4807 Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 14 Oct 2019 09:09:08 -0400 Subject: [PATCH] preparing for #974 code comments & refactoring --- firmware/controllers/engine_controller.cpp | 4 +-- firmware/controllers/map_averaging.cpp | 30 ++++++++++++++-------- firmware/controllers/map_averaging.h | 2 +- unit_tests/efifeatures.h | 1 + unit_tests/main.cpp | 8 +----- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index dd64d509fb..c5c35ca481 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -774,7 +774,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) #if EFI_MAP_AVERAGING if (engineConfiguration->isMapAveragingEnabled) { - initMapAveraging(sharedLogger, engine); + initMapAveraging(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); } #endif /* EFI_MAP_AVERAGING */ @@ -831,6 +831,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20191009; + return 20191013; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index ef97130c20..3a6cda0e5a 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -110,15 +110,19 @@ static bool isAveraging = false; static void startAveraging(void *arg) { (void) arg; efiAssertVoid(CUSTOM_ERR_6649, getCurrentRemainingStack() > 128, "lowstck#9"); +#if !EFI_UNIT_TEST bool wasLocked = lockAnyContext(); - ; +#endif // with locking we would have a consistent state mapAdcAccumulator = 0; mapMeasurementsCounter = 0; isAveraging = true; - if (!wasLocked) +#if !EFI_UNIT_TEST + if (!wasLocked) { unlockAnyContext(); - ; + } +#endif /* !EFI_UNIT_TEST */ + mapAveragingPin.setHigh(); } @@ -176,7 +180,9 @@ void mapAveragingAdcCallback(adcsample_t adcValue) { static void endAveraging(void *arg) { (void) arg; +#if ! EFI_UNIT_TEST bool wasLocked = lockAnyContext(); +#endif isAveraging = false; // with locking we would have a consistent state #if HAL_USE_ADC @@ -197,13 +203,15 @@ static void endAveraging(void *arg) { warning(CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values"); } #endif +#if ! EFI_UNIT_TEST if (!wasLocked) unlockAnyContext(); ; +#endif mapAveragingPin.setLow(); } -static void applyMapMinBufferLength() { +static void applyMapMinBufferLength(DECLARE_ENGINE_PARAMETER_SIGNATURE) { // check range mapMinBufferLength = maxI(minI(CONFIGB(mapMinBufferLength), MAX_MAP_BUFFER_LENGTH), 1); // reset index @@ -214,14 +222,14 @@ static void applyMapMinBufferLength() { } } -void postMapState(TunerStudioOutputChannels *tsOutputChannels) { #if EFI_TUNER_STUDIO +void postMapState(TunerStudioOutputChannels *tsOutputChannels) { tsOutputChannels->debugFloatField1 = v_averagedMapValue; tsOutputChannels->debugFloatField2 = engine->engineState.mapAveragingDuration; tsOutputChannels->debugFloatField3 = currentPressure; tsOutputChannels->debugIntField1 = mapMeasurementsCounter; -#endif /* EFI_TUNER_STUDIO */ } +#endif /* EFI_TUNER_STUDIO */ void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int rpm = GET_RPM_VALUE; @@ -271,7 +279,7 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, } if (CONFIGB(mapMinBufferLength) != mapMinBufferLength) { - applyMapMinBufferLength(); + applyMapMinBufferLength(PASS_ENGINE_PARAMETER_SIGNATURE); } measurementsPerRevolution = measurementsPerRevolutionCounter; @@ -305,9 +313,9 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, // we are loosing precision in case of changing RPM - the further away is the event the worse is precision // todo: schedule this based on closest trigger event, same as ignition works scheduleByAngle(rpm, &startTimer[i][structIndex], samplingStart, - startAveraging, NULL, &engine->rpmCalculator); + startAveraging, NULL, &engine->rpmCalculator PASS_ENGINE_PARAMETER_SUFFIX); scheduleByAngle(rpm, &endTimer[i][structIndex], samplingEnd, - endAveraging, NULL, &engine->rpmCalculator); + endAveraging, NULL, &engine->rpmCalculator PASS_ENGINE_PARAMETER_SUFFIX); engine->m.mapAveragingCbTime = getTimeNowLowerNt() - engine->m.beforeMapAveragingCb; } @@ -339,7 +347,7 @@ float getMap(void) { } #endif /* EFI_PROD_CODE */ -void initMapAveraging(Logging *sharedLogger, Engine *engine) { +void initMapAveraging(Logging *sharedLogger DECLARE_CONFIG_PARAMETER_SUFFIX) { logger = sharedLogger; // startTimer[0].name = "map start0"; @@ -351,7 +359,7 @@ void initMapAveraging(Logging *sharedLogger, Engine *engine) { addTriggerEventListener(&mapAveragingTriggerCallback, "MAP averaging", engine); #endif /* EFI_SHAFT_POSITION_INPUT */ addConsoleAction("faststat", showMapStats); - applyMapMinBufferLength(); + applyMapMinBufferLength(PASS_ENGINE_PARAMETER_SIGNATURE); } #else diff --git a/firmware/controllers/map_averaging.h b/firmware/controllers/map_averaging.h index 7da86b64ac..6df7c1125b 100644 --- a/firmware/controllers/map_averaging.h +++ b/firmware/controllers/map_averaging.h @@ -16,7 +16,7 @@ void mapAveragingAdcCallback(adcsample_t newValue); #endif -void initMapAveraging(Logging *sharedLogger, Engine *engine); +void initMapAveraging(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE); #if EFI_TUNER_STUDIO diff --git a/unit_tests/efifeatures.h b/unit_tests/efifeatures.h index 9e00d3bc6e..64a8f46500 100644 --- a/unit_tests/efifeatures.h +++ b/unit_tests/efifeatures.h @@ -64,5 +64,6 @@ #define EFI_BOARD_TEST FALSE #define EFI_JOYSTICK FALSE +#define EFI_MAP_AVERAGING FALSE #endif /* EFIFEATURES_H_ */ diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index 62b6707033..aa1b950b9a 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -34,12 +34,6 @@ efitick_t getTimeNowNt(void) { LoggingWithStorage sharedLogger("main"); -extern int revolutionCounterSinceBootForUnitTest; - -int getRevolutionCounter(void) { - return revolutionCounterSinceBootForUnitTest; -} - extern bool printTriggerDebug; bool verboseMode = false; @@ -47,7 +41,7 @@ GTEST_API_ int main(int argc, char **argv) { // printTriggerDebug = true; // resizeMap(); - printf("Success 20190825\r\n"); + printf("Success 20191013\r\n"); printAllTriggers(); // printConvertedTable(); testing::InitGoogleTest(&argc, argv);