From 36d6d356705f385d71904057be073f70c54e2c88 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 29 Sep 2014 19:02:57 -0500 Subject: [PATCH] auto-sync --- firmware/controllers/math/engine_math.cpp | 41 +++++++++++-------- firmware/controllers/system/efiGpio.cpp | 8 ++++ firmware/controllers/system/efiGpio.h | 1 + .../controllers/trigger/rpm_calculator.cpp | 6 ++- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 3f8ecdb845..b5f40a444e 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -28,6 +28,7 @@ #include "OutputSignalList.h" #include "trigger_decoder.h" #include "event_registry.h" +#include "efiGpio.h" /* * default Volumetric Efficiency @@ -38,7 +39,6 @@ // return interpolate(500, 0.5, 5000, 1.1, rpm); //} - /** * @return number of milliseconds in one crankshaft revolution */ @@ -102,7 +102,8 @@ int isCrankingRT(engine_configuration_s *engineConfiguration, int rpm) { return rpm > 0 && rpm < engineConfiguration->crankingSettings.crankingRpm; } -OutputSignalList injectonSignals CCM_OPTIONAL; +OutputSignalList injectonSignals CCM_OPTIONAL +; static void registerSparkEvent(engine_configuration_s const *engineConfiguration, trigger_shape_s * s, IgnitionEventList *list, io_pin_e pin, float localAdvance, float dwell) { @@ -111,6 +112,9 @@ static void registerSparkEvent(engine_configuration_s const *engineConfiguration if (event == NULL) return; // error already reported + if (!isPinAssigned(pin)) { + warning(OBD_PCM_Processor_Fault, "pin not assigned for coil #%d", (int) pin - (int) SPARKOUT_1_OUTPUT); + } event->io_pin = pin; event->advance = localAdvance; @@ -131,8 +135,8 @@ void initializeIgnitionActions(float advance, float dwellAngle, engine_configura // todo: extract method float localAdvance = advance + 720.0f * i / engineConfiguration->cylindersCount; - registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, - SPARKOUT_1_OUTPUT, localAdvance, dwellAngle); + registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, SPARKOUT_1_OUTPUT, + localAdvance, dwellAngle); } break; case IM_WASTED_SPARK: @@ -144,8 +148,8 @@ void initializeIgnitionActions(float advance, float dwellAngle, engine_configura int id = getCylinderId(engineConfiguration->firingOrder, wastedIndex) - 1; io_pin_e ioPin = (io_pin_e) (SPARKOUT_1_OUTPUT + id); - registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, - ioPin, localAdvance, dwellAngle); + registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, ioPin, localAdvance, + dwellAngle); } @@ -155,8 +159,8 @@ void initializeIgnitionActions(float advance, float dwellAngle, engine_configura float localAdvance = advance + 720.0f * i / engineConfiguration->cylindersCount; io_pin_e pin = (io_pin_e) ((int) SPARKOUT_1_OUTPUT + getCylinderId(engineConfiguration->firingOrder, i) - 1); - registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, pin, - localAdvance, dwellAngle); + registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, pin, localAdvance, + dwellAngle); } break; @@ -165,12 +169,13 @@ void initializeIgnitionActions(float advance, float dwellAngle, engine_configura } } -static void registerInjectionEvent(engine_configuration_s const *e, - trigger_shape_s *s, - ActuatorEventList *list, - io_pin_e pin, - float angle - ) { +static void registerInjectionEvent(engine_configuration_s const *e, trigger_shape_s *s, ActuatorEventList *list, + io_pin_e pin, float angle) { + + if (!isPinAssigned(pin)) { + warning(OBD_PCM_Processor_Fault, "pin not assigned for injector #%d", (int) pin - (int) INJECTOR_1_OUTPUT); + } + registerActuatorEventExt(e, s, list->getNextActuatorEvent(), injectonSignals.add(pin), angle); } @@ -267,7 +272,7 @@ void findTriggerPosition(engine_configuration_s const *engineConfiguration, trig if (middle == left) { break; - } + } if (angleOffset < s->eventAngles[middle]) { right = middle; @@ -296,9 +301,9 @@ void registerActuatorEventExt(engine_configuration_s const *engineConfiguration, efiAssertVoid(s->getSize() > 0, "uninitialized trigger_shape_s"); if (e == NULL) { - // error already reported + // error already reported return; - } + } e->actuator = actuator; findTriggerPosition(engineConfiguration, s, &e->position, angleOffset); @@ -308,7 +313,7 @@ static int order_1_THEN_3_THEN_4_THEN2[] = { 1, 3, 4, 2 }; static int order_1_THEN_5_THEN_3_THEN_6_THEN_2_THEN_4[] = { 1, 5, 3, 6, 2, 4 }; -static int order_1_8_4_3_6_5_7_2[] = {1, 8, 4, 3, 6, 5, 7, 2}; +static int order_1_8_4_3_6_5_7_2[] = { 1, 8, 4, 3, 6, 5, 7, 2 }; /** * @param index from zero to cylindersCount - 1 diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index 931a198772..761d64df37 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -68,3 +68,11 @@ void setOutputPinValue(io_pin_e pin, int logicValue) { setPinValue(&outputs[pin], getElectricalValue(logicValue, mode), logicValue); } +bool isPinAssigned(io_pin_e pin) { +#if EFI_PROD_CODE + return outputs[pin].port != GPIO_NULL; +#else + return true; +#endif +} + diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index 9f42062603..4016d3a3ca 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -34,6 +34,7 @@ int getLogicPinValue(OutputPin * outputPin); int getOutputPinValue(io_pin_e pin); int getElectricalValue(int logicalValue, pin_output_mode_e mode); void setOutputPinValue(io_pin_e pin, int logicValue); +bool isPinAssigned(io_pin_e pin); void setPinValue(OutputPin * outputPin, int electricalValue, int logicValue); #ifdef __cplusplus diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 87de1ec803..0deb1b7e44 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -210,8 +210,10 @@ void initRpmCalculator(void) { void scheduleByAngle(scheduling_s *timer, float angle, schfunc_t callback, void *param) { int rpm = getRpm(); if (!isValidRpm(rpm)) { - // this might happen in case of a single trigger event after a pause - warning(OBD_PCM_Processor_Fault, "Invalid rpm: %d", rpm); + /** + * this might happen in case of a single trigger event after a pause - this is normal, so no + * warning here + */ return; } float delayMs = getOneDegreeTimeMs(rpm) * angle;