diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index 6e63f8d40e..2f97e75a27 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -100,7 +100,7 @@ angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) { } } angle -= engineConfiguration->ignitionOffset; - fixAngle(angle); + fixAngle(angle, "getAdvance"); return angle; } diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 77cef37127..320344c830 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -329,7 +329,7 @@ void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { angle_t cylinderOffset = getEngineCycle(engineConfiguration->operationMode) * i / engineConfiguration->specs.cylindersCount; float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition(); - fixAngle(cylinderStart); + fixAngle(cylinderStart, "cylinderStart"); engine->engineState.mapAveragingStart[i] = cylinderStart; } engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow, MAP_WINDOW_SIZE); diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 6d8754096b..8840bf6cd4 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -89,7 +89,7 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S) { angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_S) { float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_F); angle_t result = fuelPhaseMap.getValue(rpm, engineLoad) + CONFIG(extraInjectionOffset); - fixAngle(result); + fixAngle(result, "inj offset"); return result; } diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index b6d5c20503..ce50d68b6d 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -198,7 +198,7 @@ static void mapAveragingCallback(trigger_event_e ckpEventType, } angle_t samplingEnd = samplingStart + samplingDuration; - fixAngle(samplingEnd); + fixAngle(samplingEnd, "samplingEnd"); if (!cisnan(samplingEnd)) { // only if value is already prepared int structIndex = getRevolutionCounter() % 2; diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 2bf1221a84..e74b39b4b8 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -165,7 +165,7 @@ void FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_S) { #if EFI_UNIT_TEST ev->engine = engine; #endif - fixAngle(angle); + fixAngle(angle, "addFuel#1"); ev->outputs[0] = output; ev->outputs[1] = secondOutput; @@ -257,7 +257,7 @@ static int findAngleIndex(float target DECLARE_ENGINE_PARAMETER_S) { void findTriggerPosition(event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_S) { // convert engine cycle angle into trigger cycle angle angleOffset += tdcPosition(); - fixAngle(angleOffset); + fixAngle(angleOffset, "addFuel#2"); int index = TRIGGER_SHAPE(triggerIndexByAngle[(int)angleOffset]); angle_t eventAngle = TRIGGER_SHAPE(eventAngles[index]); diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index 9f9dc2112e..1a543bd8f3 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -20,9 +20,9 @@ void findTriggerPosition( event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_S); #if EFI_ENABLE_ASSERTS -#define assertAngleRange(angle) if(angle > 10000000 || angle < -10000000) { firmwareError(OBD_PCM_Processor_Fault, "angle range");angle = 0;} +#define assertAngleRange(angle, msg) if(angle > 10000000 || angle < -10000000) { firmwareError(OBD_PCM_Processor_Fault, "angle range %s %f", angle, msg);angle = 0;} #else -#define assertAngleRange(angle) {} +#define assertAngleRange(angle, msg) {} #endif void setInjectorLag(float value DECLARE_ENGINE_PARAMETER_S); @@ -32,9 +32,9 @@ void setInjectorLag(float value DECLARE_ENGINE_PARAMETER_S); * @brief Shifts angle into the [0..720) range for four stroke and [0..360) for two stroke * I guess this implementation would be faster than 'angle % engineCycle' */ -#define fixAngle(angle) \ +#define fixAngle(angle, msg) \ { \ - assertAngleRange(angle); \ + assertAngleRange(angle, msg); \ float engineCycleDurationLocalCopy = ENGINE(engineCycle); \ /* todo: split this method into 'fixAngleUp' and 'fixAngleDown'*/ \ /* as a performance optimization?*/ \ diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index ccdbfed4b0..9987c9f55b 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -120,7 +120,7 @@ void hwHandleVvtCamSignal(trigger_value_e front) { // convert engine cycle angle into trigger cycle angle vvtPosition -= tdcPosition(); - fixAngle(vvtPosition); + fixAngle(vvtPosition, "vvtPosition"); tc->vvtPosition = vvtPosition + engineConfiguration->vvtOffset; diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index c955f10ca4..67cb9b9f7c 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -323,7 +323,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no angle_t currentAngle = TRIGGER_SHAPE(eventAngles[currentCycle.current_index]); // todo: make this '90' depend on cylinder count? angle_t prevAngle = currentAngle - 90; - fixAngle(prevAngle); + fixAngle(prevAngle, "prevAngle"); // todo: prevIndex should be pre-calculated int prevIndex = TRIGGER_SHAPE(triggerIndexByAngle[(int)prevAngle]); // now let's get precise angle for that event @@ -332,7 +332,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no // uint32_t time = nowNt - timeOfLastEvent[prevIndex]; angle_t angleDiff = currentAngle - prevAngle; // todo: angle diff should be pre-calculated - fixAngle(angleDiff); + fixAngle(angleDiff, "angleDiff"); // float r = (60000000.0 / 360 * US_TO_NT_MULTIPLIER) * angleDiff / time; diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index ff996124bc..d3433dc37d 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -66,7 +66,7 @@ void TriggerShape::calculateTriggerSynchPoint(TriggerState *state DECLARE_ENGINE int triggerDefinitionCoordinate = (triggerShapeSynchPointIndex + eventIndex) % engine->engineCycleEventCount; int triggerDefinitionIndex = triggerDefinitionCoordinate >= size ? triggerDefinitionCoordinate - size : triggerDefinitionCoordinate; float angle = getAngle(triggerDefinitionCoordinate) - firstAngle; - fixAngle(angle); + fixAngle(angle, "trgSync"); if (engineConfiguration->useOnlyRisingEdgeForTrigger) { if (isFrontEvent[triggerDefinitionIndex]) { frontOnlyIndex += 2; diff --git a/firmware/development/wave_analyzer.cpp b/firmware/development/wave_analyzer.cpp index c3fa1156a7..b0617ed1da 100644 --- a/firmware/development/wave_analyzer.cpp +++ b/firmware/development/wave_analyzer.cpp @@ -243,7 +243,7 @@ static void reportWave(Logging *logging, int index) { appendPrintf(logging, "advance%d%s", index, DELIMETER); float angle = (offsetUs / oneDegreeUs) - tdcPosition(); - fixAngle(angle); + fixAngle(angle, "angle"); appendFloat(logging, angle, 3); appendPrintf(logging, "%s", DELIMETER); }