From 04f6913d560b11be2c1af07a1486bff5a8e13fc2 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 24 Nov 2019 20:48:25 -0500 Subject: [PATCH] MapAveragingCallback schedules all cylinders at once #974 saving pennies --- firmware/config/engines/custom_engine.cpp | 7 +++++++ firmware/controllers/map_averaging.cpp | 4 ++-- firmware/controllers/trigger/aux_valves.cpp | 4 ++-- firmware/controllers/trigger/rpm_calculator.cpp | 7 ++----- firmware/controllers/trigger/rpm_calculator.h | 2 +- firmware/hw_layer/hip9011.cpp | 4 ++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index 4715f5d276..7c310b9cef 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -253,6 +253,13 @@ void setEtbTestConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) { // set tps_max 540 engineConfiguration->tpsMax = 540; + // yes, 30K - that's a test configuration + engineConfiguration->rpmHardLimit = 30000; + + setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); + engineConfiguration->trigger.type = TT_TOOTHED_WHEEL_60_2; + + boardConfiguration->ignitionPins[0] = GPIO_UNASSIGNED; boardConfiguration->ignitionPins[1] = GPIO_UNASSIGNED; boardConfiguration->ignitionPins[2] = GPIO_UNASSIGNED; diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index 90caf93845..d5970a6207 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -313,9 +313,9 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, // at the moment we schedule based on time prediction based on current RPM and angle // 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, + scheduleByAngle(&startTimer[i][structIndex], samplingStart, startAveraging, NULL PASS_ENGINE_PARAMETER_SUFFIX); - scheduleByAngle(rpm, &endTimer[i][structIndex], samplingEnd, + scheduleByAngle(&endTimer[i][structIndex], samplingEnd, endAveraging, NULL PASS_ENGINE_PARAMETER_SUFFIX); engine->m.mapAveragingCbTime = getTimeNowLowerNt() - engine->m.beforeMapAveragingCb; diff --git a/firmware/controllers/trigger/aux_valves.cpp b/firmware/controllers/trigger/aux_valves.cpp index 3f1da8941e..6181d63803 100644 --- a/firmware/controllers/trigger/aux_valves.cpp +++ b/firmware/controllers/trigger/aux_valves.cpp @@ -101,12 +101,12 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType, } fixAngle(onTime, "onTime", CUSTOM_ERR_6556); - scheduleByAngle(rpm, onEvent, + scheduleByAngle(onEvent, onTime, (schfunc_t) &plainPinTurnOn, output PASS_ENGINE_PARAMETER_SUFFIX); angle_t offTime = extra + engine->engineState.auxValveEnd; fixAngle(offTime, "offTime", CUSTOM_ERR_6557); - scheduleByAngle(rpm, offEvent, + scheduleByAngle(offEvent, offTime, (schfunc_t) &plainPinTurnOff, output PASS_ENGINE_PARAMETER_SUFFIX); if (isOverlap) { diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 6d2c802970..baa97581c4 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -319,7 +319,7 @@ static void tdcMarkCallback(trigger_event_e ckpSignalType, int rpm = GET_RPM(); // todo: use tooth event-based scheduling, not just time-based scheduling if (isValidRpm(rpm)) { - scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(), + scheduleByAngle(&tdcScheduler[revIndex2], tdcPosition(), (schfunc_t) onTdcCallback, engine PASS_ENGINE_PARAMETER_SUFFIX); } } @@ -358,14 +358,11 @@ void initRpmCalculator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { * The callback would be executed once after the duration of time which * it takes the crankshaft to rotate to the specified angle. */ -void scheduleByAngle(float rpm, scheduling_s *timer, angle_t angle, +void scheduleByAngle(scheduling_s *timer, angle_t angle, schfunc_t callback, void *param DECLARE_ENGINE_PARAMETER_SUFFIX) { ScopePerf perf(PE::ScheduleByAngle); - efiAssertVoid(CUSTOM_ANGLE_NAN, !cisnan(angle), "NaN angle?"); - efiAssertVoid(CUSTOM_ERR_6634, isValidRpm(rpm), "RPM check expected"); float delayUs = ENGINE(rpmCalculator.oneDegreeUs) * angle; - efiAssertVoid(CUSTOM_ERR_6635, !cisnan(delayUs), "NaN delay?"); ENGINE(executor.scheduleForLater(timer, (int) delayUs, callback, param)); } diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 6df6cc0c9d..e7be215c06 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -166,6 +166,6 @@ float getCrankshaftAngleNt(efitime_t timeNt DECLARE_ENGINE_PARAMETER_SUFFIX); #define addEngineSnifferEvent(n, msg) {} #endif /* EFI_ENGINE_SNIFFER */ -void scheduleByAngle(float rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param DECLARE_ENGINE_PARAMETER_SUFFIX); +void scheduleByAngle(scheduling_s *timer, angle_t angle, schfunc_t callback, void *param DECLARE_ENGINE_PARAMETER_SUFFIX); #endif /* RPM_REPORTER_H_ */ diff --git a/firmware/hw_layer/hip9011.cpp b/firmware/hw_layer/hip9011.cpp index bbedf7ad85..35016527b2 100644 --- a/firmware/hw_layer/hip9011.cpp +++ b/firmware/hw_layer/hip9011.cpp @@ -254,12 +254,12 @@ static void intHoldCallback(trigger_event_e ckpEventType, uint32_t index DECLARE int structIndex = getRevolutionCounter() % 2; // todo: schedule this based on closest trigger event, same as ignition works - scheduleByAngle(rpm, &startTimer[structIndex], engineConfiguration->knockDetectionWindowStart, + scheduleByAngle(&startTimer[structIndex], engineConfiguration->knockDetectionWindowStart, (schfunc_t) &startIntegration, NULL PASS_ENGINE_PARAMETER_SUFFIX); #if EFI_PROD_CODE hipLastExecutionCount = lastExecutionCount; #endif /* EFI_PROD_CODE */ - scheduleByAngle(rpm, &endTimer[structIndex], engineConfiguration->knockDetectionWindowEnd, + scheduleByAngle(&endTimer[structIndex], engineConfiguration->knockDetectionWindowEnd, (schfunc_t) &endIntegration, NULL PASS_ENGINE_PARAMETER_SUFFIX); engine->m.hipCbTime = getTimeNowLowerNt() - engine->m.beforeHipCb;