diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index a060633796..63771f7376 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -141,8 +141,6 @@ typedef enum { Force_4b_engine_type = ENUM_32_BITS, } engine_type_e; -#define DEFAULT_ENGINE_TYPE CUSTOM_ENGINE - typedef enum { TT_TOOTHED_WHEEL = 0, TT_FORD_ASPIRE = 1, diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 78b69474cb..a5ff706d73 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -309,42 +309,6 @@ static ALWAYS_INLINE void ignitionMathCalc(int rpm DECLARE_ENGINE_PARAMETER_S) { uint32_t *cyccnt = (uint32_t*) &DWT->CYCCNT; #endif -static ALWAYS_INLINE void scheduleIgnitionAndFuelEvents(int rpm, int revolutionIndex DECLARE_ENGINE_PARAMETER_S) { - - engine->m.beforeIgnitionSch = GET_TIMESTAMP(); - /** - * TODO: warning. there is a bit of a hack here, todo: improve. - * currently output signals/times signalTimerUp from the previous revolutions could be - * still used because they have crossed the revolution boundary - * but we are already re-purposing the output signals, but everything works because we - * are not affecting that space in memory. todo: use two instances of 'ignitionSignals' - */ - float maxAllowedDwellAngle = (int) (getEngineCycle(engineConfiguration->operationMode) / 2); // the cast is about making Coverity happy - - if (engineConfiguration->ignitionMode == IM_ONE_COIL) { - maxAllowedDwellAngle = getEngineCycle(engineConfiguration->operationMode) / engineConfiguration->specs.cylindersCount / 1.1; - } - - if (engine->engineState.dwellAngle == 0) { - warning(CUSTOM_OBD_32, "dwell is zero?"); - } - if (engine->engineState.dwellAngle > maxAllowedDwellAngle) { - warning(CUSTOM_OBD_33, "dwell angle too long: %f", engine->engineState.dwellAngle); - } - - // todo: add some check for dwell overflow? like 4 times 6 ms while engine cycle is less then that - - IgnitionEventList *list = &engine->engineConfiguration2->ignitionEvents[revolutionIndex]; - - if (cisnan(ENGINE(engineState.timingAdvance))) { - // error should already be reported - list->reset(); // reset is needed to clear previous ignition schedule - return; - } - initializeIgnitionActions(ENGINE(engineState.timingAdvance), ENGINE(engineState.dwellAngle), list PASS_ENGINE_PARAMETER); - engine->m.ignitionSchTime = GET_TIMESTAMP() - engine->m.beforeIgnitionSch; -} - /** * This is the main trigger event handler. * Both injection and ignition are controlled from this method. @@ -429,9 +393,6 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D ENGINE(m.ignitionMathTime) = GET_TIMESTAMP() - ENGINE(m.beforeIgnitionMath); } - if (trgEventIndex == 0) { - scheduleIgnitionAndFuelEvents(rpm, revolutionIndex PASS_ENGINE_PARAMETER); - } /** * For fuel we schedule start of injection based on trigger angle, and then inject for @@ -441,7 +402,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D /** * For spark we schedule both start of coil charge and actual spark based on trigger angle */ - handleSpark(limitedSpark, trgEventIndex, rpm, + handleSpark(revolutionIndex, limitedSpark, trgEventIndex, rpm, &engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER); #if (EFI_HISTOGRAMS && EFI_PROD_CODE) || defined(__DOXYGEN__) int diff = hal_lld_get_counter_value() - beforeCallback; diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 2c44eef032..a80b075e3d 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -8,6 +8,7 @@ #include "engine_math.h" #include "utlist.h" #include "event_queue.h" +#include "efilib2.h" EXTERN_ENGINE; @@ -116,8 +117,48 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI } } -void handleSpark(bool limitedSpark, uint32_t trgEventIndex, int rpm, +static ALWAYS_INLINE void prepareIgnitionSchedule(int rpm, int revolutionIndex DECLARE_ENGINE_PARAMETER_S) { + + engine->m.beforeIgnitionSch = GET_TIMESTAMP(); + /** + * TODO: warning. there is a bit of a hack here, todo: improve. + * currently output signals/times signalTimerUp from the previous revolutions could be + * still used because they have crossed the revolution boundary + * but we are already re-purposing the output signals, but everything works because we + * are not affecting that space in memory. todo: use two instances of 'ignitionSignals' + */ + float maxAllowedDwellAngle = (int) (getEngineCycle(engineConfiguration->operationMode) / 2); // the cast is about making Coverity happy + + if (engineConfiguration->ignitionMode == IM_ONE_COIL) { + maxAllowedDwellAngle = getEngineCycle(engineConfiguration->operationMode) / engineConfiguration->specs.cylindersCount / 1.1; + } + + if (engine->engineState.dwellAngle == 0) { + warning(CUSTOM_OBD_32, "dwell is zero?"); + } + if (engine->engineState.dwellAngle > maxAllowedDwellAngle) { + warning(CUSTOM_OBD_33, "dwell angle too long: %f", engine->engineState.dwellAngle); + } + + // todo: add some check for dwell overflow? like 4 times 6 ms while engine cycle is less then that + + IgnitionEventList *list = &engine->engineConfiguration2->ignitionEvents[revolutionIndex]; + + if (cisnan(ENGINE(engineState.timingAdvance))) { + // error should already be reported + list->reset(); // reset is needed to clear previous ignition schedule + return; + } + initializeIgnitionActions(ENGINE(engineState.timingAdvance), ENGINE(engineState.dwellAngle), list PASS_ENGINE_PARAMETER); + engine->m.ignitionSchTime = GET_TIMESTAMP() - engine->m.beforeIgnitionSch; +} + +void handleSpark(int revolutionIndex, bool limitedSpark, uint32_t trgEventIndex, int rpm, IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { + if (trgEventIndex == 0) { + prepareIgnitionSchedule(rpm, revolutionIndex PASS_ENGINE_PARAMETER); + } + if (!isValidRpm(rpm) || !CONFIG(isIgnitionEnabled)) { // this might happen for instance in case of a single trigger event after a pause return; diff --git a/firmware/controllers/trigger/spark_logic.h b/firmware/controllers/trigger/spark_logic.h index 4af1e0e083..3b73200225 100644 --- a/firmware/controllers/trigger/spark_logic.h +++ b/firmware/controllers/trigger/spark_logic.h @@ -11,7 +11,7 @@ #include "engine.h" int isInjectionEnabled(engine_configuration_s *engineConfiguration); -void handleSpark(bool limitedSpark, uint32_t trgEventIndex, int rpm, +void handleSpark(int revolutionIndex, bool limitedSpark, uint32_t trgEventIndex, int rpm, IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S); void initSparkLogic(Logging *sharedLogger); void turnSparkPinHigh(NamedOutputPin *output); diff --git a/firmware/global.h b/firmware/global.h index f6570b03f7..c0cb4358e3 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -12,6 +12,8 @@ #include #include +#define DEFAULT_ENGINE_TYPE CUSTOM_ENGINE + // this is about MISRA not liking 'time.h'. todo: figure out something #if defined __GNUC__ // GCC diff --git a/unit_tests/global.h b/unit_tests/global.h index dfd213d13b..7d6cf15f51 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -8,6 +8,8 @@ #ifndef GLOBAL_H_ #define GLOBAL_H_ +#define DEFAULT_ENGINE_TYPE CUSTOM_ENGINE + #include #include #include diff --git a/win32_functional_tests/simulator/global.h b/win32_functional_tests/simulator/global.h index 4ddbb242cb..445f27cc2b 100644 --- a/win32_functional_tests/simulator/global.h +++ b/win32_functional_tests/simulator/global.h @@ -1,4 +1,6 @@ +#define DEFAULT_ENGINE_TYPE FORD_ESCORT_GT + #include #include #include diff --git a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp index 6d19de364e..69581be642 100644 --- a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp +++ b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp @@ -31,7 +31,6 @@ #include "map_averaging.h" #define DEFAULT_SIM_RPM 1200 -#define DEFAULT_ENGINE_TYPE FORD_ESCORT_GT #define DEFAULT_SNIFFER_THR 2500 EXTERN_ENGINE;