From c9852aa7b53f069ea93229fbfcb0f31e62cbb961 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 13 Sep 2015 10:01:39 -0400 Subject: [PATCH] auto-sync --- .../controllers/algo/engine_configuration.cpp | 21 +++++++------- firmware/controllers/flash_main.cpp | 1 + .../system/pwm_generator_logic.cpp | 1 + .../controllers/trigger/trigger_decoder.cpp | 28 +++++++++++-------- .../controllers/trigger/trigger_decoder.h | 1 + .../controllers/trigger/trigger_structure.cpp | 7 +++++ firmware/hw_layer/hardware.cpp | 1 + firmware/rusefi.cpp | 6 ++-- 8 files changed, 43 insertions(+), 23 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 96d912c9e3..c7b2adeb63 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -29,7 +29,7 @@ #include "engine_math.h" #include "speed_density.h" #include "advance_map.h" -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) #include "electronic_throttle.h" #include "alternatorController.h" #endif @@ -66,7 +66,7 @@ EXTERN_ENGINE; -#if EFI_TUNER_STUDIO +#if EFI_TUNER_STUDIO || defined(__DOXYGEN__) #include "tunerstudio.h" #endif @@ -177,7 +177,7 @@ void prepareVoidConfiguration(engine_configuration_s *activeConfiguration) { boardConfiguration->acRelayPin = GPIO_UNASSIGNED; boardConfiguration->acRelayPinMode = OM_DEFAULT; -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) setDefaultAlternatorParameters(); setDefaultEtbParameters(); #endif @@ -228,7 +228,7 @@ void prepareVoidConfiguration(engine_configuration_s *activeConfiguration) { * and the settings saves in flash memory. */ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { -#if ! EFI_UNIT_TEST +#if (! EFI_UNIT_TEST) || defined(__DOXYGEN__) memset(&persistentState.persistentConfiguration, 0, sizeof(persistentState.persistentConfiguration)); #endif prepareVoidConfiguration(engineConfiguration); @@ -472,7 +472,7 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->idleStepperReactionTime = 10; engineConfiguration->idleStepperTotalSteps = 150; -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) engineConfiguration->engineChartSize = 300; #else // need more events for automated test @@ -618,7 +618,7 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_EN * Let's apply global defaults first */ setDefaultConfiguration(PASS_ENGINE_PARAMETER_F); -#if EFI_SIMULATOR +#if EFI_SIMULATOR || defined(__DOXYGEN__) engineConfiguration->directSelfStimulation = true; #endif /* */ engineConfiguration->engineType = engineType; @@ -758,13 +758,14 @@ engine_configuration2_s::engine_configuration2_s() { } void applyNonPersistentConfiguration(Logging * logger DECLARE_ENGINE_PARAMETER_S) { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "apply c"); + scheduleMsg(logger, "applyNonPersistentConfiguration()"); +#endif // todo: this would require 'initThermistors() to re-establish a reference, todo: fix // memset(engineConfiguration2, 0, sizeof(engine_configuration2_s)); -#if EFI_PROD_CODE - scheduleMsg(logger, "applyNonPersistentConfiguration()"); -#endif -#if EFI_ENGINE_CONTROL +#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) engine->triggerShape.initializeTriggerShape(logger PASS_ENGINE_PARAMETER); #endif if (engine->triggerShape.getSize() == 0) { diff --git a/firmware/controllers/flash_main.cpp b/firmware/controllers/flash_main.cpp index 772f47eadb..6f562e3c11 100644 --- a/firmware/controllers/flash_main.cpp +++ b/firmware/controllers/flash_main.cpp @@ -106,6 +106,7 @@ static bool hasValidEngineType(engine_configuration_s *engineConfiguration) { } void readFromFlash(void) { + efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "read f"); printMsg(logger, "readFromFlash()"); flashRead(FLASH_ADDR, (char *) &persistentState, PERSISTENT_SIZE); diff --git a/firmware/controllers/system/pwm_generator_logic.cpp b/firmware/controllers/system/pwm_generator_logic.cpp index e44629f405..46c4218925 100644 --- a/firmware/controllers/system/pwm_generator_logic.cpp +++ b/firmware/controllers/system/pwm_generator_logic.cpp @@ -22,6 +22,7 @@ SimplePwm::SimplePwm() { sr[0] = waveInstance; init(_switchTimes, sr); } + void PwmConfig::baseConstructor() { memset(&scheduling, 0, sizeof(scheduling)); memset(&safe, 0, sizeof(safe)); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 731bf451df..2c512cc4aa 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -164,7 +164,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no bool_t isPrimary = triggerWheel == T_PRIMARY; if (isLessImportant(signal)) { -#if EFI_UNIT_TEST +#if EFI_UNIT_TEST || defined(__DOXYGEN__) if (printTriggerDebug) { printf("%s isLessImportant %s\r\n", getTrigger_type_e(engineConfiguration->trigger.type), @@ -189,7 +189,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no isFirstEvent = false; // todo: skip a number of signal from the beginning -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) // scheduleMsg(&logger, "from %f to %f %d %d", triggerConfig->syncRatioFrom, triggerConfig->syncRatioTo, currentDuration, shaftPositionState->toothed_previous_duration); // scheduleMsg(&logger, "ratio %f", 1.0 * currentDuration/ shaftPositionState->toothed_previous_duration); #else @@ -235,7 +235,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no } -#if EFI_UNIT_TEST +#if EFI_UNIT_TEST || defined(__DOXYGEN__) if (printTriggerDebug) { printf("%s isSynchronizationPoint=%d index=%d %s\r\n", getTrigger_type_e(engineConfiguration->trigger.type), @@ -258,7 +258,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no lastDecodingErrorTime = getTimeNowNt(); totalTriggerErrorCounter++; if (engineConfiguration->isPrintTriggerSynchDetails) { -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) scheduleMsg(logger, "error: synchronizationPoint @ index %d expected %d/%d/%d got %d/%d/%d", currentCycle.current_index, TRIGGER_SHAPE(expectedEventCount[0]), TRIGGER_SHAPE(expectedEventCount[1]), TRIGGER_SHAPE(expectedEventCount[2]), currentCycle.eventCount[0], currentCycle.eventCount[1], currentCycle.eventCount[2]); @@ -365,11 +365,12 @@ static void configureOnePlus60_2(TriggerShape *s, operation_mode_e operationMode * External logger is needed because at this point our logger is not yet initialized */ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_S) { - TriggerShape *triggerShape = this; - -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) + efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "init t"); scheduleMsg(logger, "initializeTriggerShape()"); #endif + TriggerShape *triggerShape = this; + const trigger_config_s *triggerConfig = &engineConfiguration->trigger; clear(); @@ -543,6 +544,9 @@ static uint32_t doFindTrigger(TriggerStimulatorHelper *helper, TriggerShape * sh return EFI_ERROR_CODE; } +// todo: reuse trigger central state here to reduce RAM usage? +static TriggerState state; + /** * Trigger shape is defined in a way which is convenient for trigger shape definition * On the other hand, trigger decoder indexing begins from synchronization event. @@ -551,11 +555,13 @@ static uint32_t doFindTrigger(TriggerStimulatorHelper *helper, TriggerShape * sh */ uint32_t findTriggerZeroEventIndex(TriggerShape * shape, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S) { - - // todo: should this variable be declared 'static' to reduce stack usage? - TriggerState state; +#if EFI_PROD_CODE || defined(__DOXYGEN__) + efiAssert(getRemainingStack(chThdSelf()) > 128, "findPos", -1); +#endif errorDetection.clear(); + state.reset(); + // todo: should this variable be declared 'static' to reduce stack usage? TriggerStimulatorHelper helper; @@ -594,7 +600,7 @@ void initTriggerDecoderLogger(Logging *sharedLogger) { } void initTriggerDecoder(void) { -#if (EFI_PROD_CODE || EFI_SIMULATOR) +#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) outputPinRegisterExt2("trg_err", &triggerDecoderErrorPin, boardConfiguration->triggerErrorPin, &boardConfiguration->triggerErrorPinMode); #endif } diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 8c96a1f31c..f4ea2298cc 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -88,6 +88,7 @@ public: uint32_t orderingErrorCounter; uint32_t runningOrderingErrorCounter; + void reset(); void resetRunningCounters(); uint32_t runningRevolutionCounter; diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 1f849ebf73..bd0e530de7 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -67,6 +67,9 @@ int TriggerShape::getTriggerShapeSynchPointIndex() { } void TriggerShape::calculateTriggerSynchPoint(DECLARE_ENGINE_PARAMETER_F) { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "calc s"); +#endif trigger_config_s const*triggerConfig = &engineConfiguration->trigger; triggerShapeSynchPointIndex = findTriggerZeroEventIndex(this, triggerConfig PASS_ENGINE_PARAMETER); @@ -151,6 +154,10 @@ void multi_wave_s::setSwitchTime(int index, float value) { } TriggerState::TriggerState() { + reset(); +} + +void TriggerState::reset() { cycleCallback = NULL; shaft_is_synchronized = false; toothed_previous_time = 0; diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 6b0efee42f..a52a1b236b 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -212,6 +212,7 @@ void applyNewHardwareSettings(void) { } void initHardware(Logging *l) { + efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "init h"); sharedLogger = l; engine_configuration_s *engineConfiguration = engine->engineConfiguration; efiAssertVoid(engineConfiguration!=NULL, "engineConfiguration"); diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 114e781fbd..79a66d65eb 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -164,6 +164,8 @@ void applyNewConfiguration(void) { } void runRusEfi(void) { + efiAssertVoid(getRemainingStack(chThdSelf()) > 512, "init s"); + msObjectInit(&firmwareErrorMessageStream, errorMessageBuffer, sizeof(errorMessageBuffer), 0); #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) @@ -203,7 +205,7 @@ void runRusEfi(void) { #if EFI_PERF_METRICS || defined(__DOXYGEN__) initTimePerfActions(&sharedLogger); #endif - + #if EFI_ENGINE_EMULATOR || defined(__DOXYGEN__) initEngineEmulator(&sharedLogger, engine); #endif @@ -273,5 +275,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20150912; + return 20150913; }