diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 2ed580d16e..19c7d85d49 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -142,7 +142,7 @@ void printSensors(Engine *engine) { reportSensorF("TRG_0_DUTY", getTriggerDutyCycle(0), 2); reportSensorF("TRG_1_DUTY", getTriggerDutyCycle(1), 2); - reportSensorF(getCaption(LP_THROTTLE), getTPS(), 2); + reportSensorF(getCaption(LP_THROTTLE), getTPS(engine->engineConfiguration), 2); if (engineConfiguration->hasCltSensor) { reportSensorF(getCaption(LP_ECT), getCoolantTemperature(engineConfiguration2), 2); @@ -356,7 +356,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels) { int rpm = 0; #endif - float tps = getTPS(); + float tps = getTPS(engineConfiguration); float coolant = getCoolantTemperature(engineConfiguration2); float intake = getIntakeAirTemperature(engineConfiguration2); diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 9147394ff2..40c78d990a 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -81,3 +81,26 @@ void Engine::watchdog() { stopPins(); } + +StartupFuelPumping::StartupFuelPumping() { + +} + +void StartupFuelPumping::setPumpsCounter(int newValue) { + if (pumpsCounter != newValue) { + pumpsCounter = newValue; + } +} + +void StartupFuelPumping::update(Engine *engine) { + if (engine->rpmCalculator->rpm() == 0) { + bool isAbove50 = getTPS(engine->engineConfiguration) >= 50; + + } else { + /** + * Engine is not stopped - not priming pumping mode + */ + setPumpsCounter(0); + } +} + diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 7b01b9a953..43b9626ec8 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -48,4 +48,14 @@ private: bool stopPins(); }; +class StartupFuelPumping { +public: + StartupFuelPumping(); + void update(Engine *engine); + bool isTpsAbove50; + int pumpsCounter; +private: + void setPumpsCounter(int newValue); +}; + #endif /* ENGINE_H_ */ diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 95386a891b..fbd733bc37 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -171,7 +171,7 @@ int getTimeNowSeconds(void) { static void cylinderCleanupControl(Engine *engine) { bool newValue; if (engineConfiguration->isCylinderCleanupEnabled) { - newValue = isCrankingE(engine) && getTPS() > 95; + newValue = isCrankingE(engine) && getTPS(engine->engineConfiguration) > 95; } else { newValue = false; } diff --git a/firmware/controllers/engine_controller.h b/firmware/controllers/engine_controller.h index 5390ab979f..4907aa37d3 100644 --- a/firmware/controllers/engine_controller.h +++ b/firmware/controllers/engine_controller.h @@ -17,11 +17,4 @@ char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer); void initEngineContoller(void); -class StartupFuelPumping { -public: - void update(Engine *engine); - bool isTpsAbove50; - int pumpsCounter; -}; - #endif /* ENGINE_STATUS_H_ */ diff --git a/firmware/controllers/lcd_controller.cpp b/firmware/controllers/lcd_controller.cpp index 9ef60621bf..f6e81c9480 100644 --- a/firmware/controllers/lcd_controller.cpp +++ b/firmware/controllers/lcd_controller.cpp @@ -50,7 +50,7 @@ static char * prepareCltIatTpsLine(char *buffer) { ptr = ftoa(ptr, getIntakeAirTemperature(engineConfiguration2), 10.0f); ptr = appendStr(ptr, " TP"); - ptr = itoa10(ptr, (int) getTPS()); + ptr = itoa10(ptr, (int) getTPS(engine.engineConfiguration)); return ptr; } diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index cbd7cbf432..240cc23bb8 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -75,7 +75,7 @@ float getEngineLoadT(Engine *engine) { case LM_MAP: return getMap(); case LM_ALPHA_N: - return getTPS(); + return getTPS(engineConfiguration); default: firmwareError("Unexpected engine load parameter: %d", engineConfiguration->algorithm); return -1; diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index 71cdbfba00..a12da99a9b 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -66,7 +66,7 @@ float getSpeedDensityFuel(Engine *engine, int rpm) { engine_configuration_s *engineConfiguration = engine->engineConfiguration; - float tps = getTPS(); + float tps = getTPS(engineConfiguration); float coolantC = getCoolantTemperature(engine->engineConfiguration2); float intakeC = getIntakeAirTemperature(engine->engineConfiguration2); float tChargeK = convertCelsiusToKelvin(getTCharge(rpm, tps, coolantC, intakeC)); diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index 4f2d7bcb15..a260ac3dcd 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -47,7 +47,7 @@ float getTpsRateOfChange(void) { * Return current TPS position based on configured ADC levels, and adc * * */ -float getTpsValue(int adc) { +static float getTpsValue(engine_configuration_s *engineConfiguration, int adc) { if (adc < engineConfiguration->tpsMin) { return 0.0f; } @@ -82,10 +82,10 @@ int getTPS10bitAdc(void) { /** * @brief Position on physical primary TPS */ -static float getPrimatyRawTPS(void) { +static float getPrimatyRawTPS(engine_configuration_s *engineConfiguration) { // blue, 1st board /* PA7 - blue TP */ - float tpsValue = getTpsValue(getTPS10bitAdc()); + float tpsValue = getTpsValue(engineConfiguration, getTPS10bitAdc()); return tpsValue; } @@ -96,12 +96,12 @@ static float getPrimatyRawTPS(void) { * * @return Current TPS position, percent of WOT. 0 means idle and 100 means Wide Open Throttle */ -float getTPS(void) { +float getTPS(engine_configuration_s *engineConfiguration) { // todo: if (config->isDualTps) // todo: blah blah // todo: if two TPS do not match - show OBD code via malfunction_central.c - return getPrimatyRawTPS(); + return getPrimatyRawTPS(engineConfiguration); } int convertVoltageTo10bitADC(float voltage) { diff --git a/firmware/controllers/sensors/tps.h b/firmware/controllers/sensors/tps.h index 3565f2c0c8..8e3da0c53d 100644 --- a/firmware/controllers/sensors/tps.h +++ b/firmware/controllers/sensors/tps.h @@ -11,8 +11,9 @@ #define TPS_H_ #include "global.h" +#include "engine_configuration.h" -float getTPS(void); +float getTPS(engine_configuration_s *engineConfiguration); int convertVoltageTo10bitADC(float voltage); int getTPS10bitAdc(void); float getTPSVoltage(void); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index a81d624682..a282311a03 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -300,7 +300,7 @@ static void printTPSInfo(void) { scheduleMsg(&logger, "tps min %d/max %d v=%f @%s%d", engineConfiguration->tpsMin, engineConfiguration->tpsMax, getTPSVoltage(), portname(port), pin); #endif - scheduleMsg(&logger, "current 10bit=%d value=%f rate=%f", getTPS10bitAdc(), getTPS(), getTpsRateOfChange()); + scheduleMsg(&logger, "current 10bit=%d value=%f rate=%f", getTPS10bitAdc(), getTPS(engineConfiguration), getTpsRateOfChange()); } static void printTemperatureInfo(void) { diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index f6552c69d5..3587b39c89 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -57,6 +57,9 @@ extern Engine engine; #endif RpmCalculator::RpmCalculator() { +#if !EFI_PROD_CODE + mockRpm = MOCK_UNDEFINED; +#endif rpmValue = 0; // we need this initial to have not_running at first invocation @@ -74,6 +77,10 @@ bool RpmCalculator::isRunning(void) { // todo: migrate to float return result or add a float verion? this would have with calculations // todo: add a version which does not check time & saves time? need to profile int RpmCalculator::rpm(void) { +#if !EFI_PROD_CODE + if (mockRpm != MOCK_UNDEFINED) + return mockRpm; +#endif if (!isRunning()) { return 0; } @@ -111,13 +118,12 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Rpm if (index != 0) { #if EFI_ANALOG_CHART || defined(__DOXYGEN__) if (engineConfiguration->analogChartMode == AC_TRIGGER) - acAddData(getCrankshaftAngle(nowUs), 1000 * ckpSignalType + index); + acAddData(getCrankshaftAngle(nowUs), 1000 * ckpSignalType + index); #endif return; } rpmState->revolutionCounter++; - bool hadRpmRecently = rpmState->isRunning(); if (hadRpmRecently) { @@ -139,7 +145,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Rpm rpmState->lastRpmEventTimeUs = nowUs; #if EFI_ANALOG_CHART || defined(__DOXYGEN__) if (engineConfiguration->analogChartMode == AC_TRIGGER) - acAddData(getCrankshaftAngle(nowUs), index); + acAddData(getCrankshaftAngle(nowUs), index); #endif } diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 565fd0d4cf..7344f7f2b1 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -22,8 +22,13 @@ #ifdef __cplusplus #include "engine.h" +#define MOCK_UNDEFINED -1 + class RpmCalculator { public: +#if !EFI_PROD_CODE + int mockRpm; +#endif RpmCalculator(); int rpm(void); volatile int rpmValue; @@ -32,8 +37,7 @@ public: * This counter is incremented with each revolution of one of the shafts. Could be * crankshaft could be camshaft. */ - volatile int revolutionCounter; - bool isRunning(void); + volatile int revolutionCounter;bool isRunning(void); }; #define getRpm() getRpmE(&engine) @@ -47,8 +51,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Rpm #endif #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /* __cplusplus */ /** diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 4fd5d591cf..0166fef58b 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -241,5 +241,5 @@ void firmwareError(const char *fmt, ...) { } int getRusEfiVersion(void) { - return 20141016; + return 20141017; } diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index f7c11eaf57..fe5882e13c 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -342,6 +342,24 @@ extern EventQueue schedulingQueue; // this is a very dirty and sad hack. todo: eliminate extern Engine engine; +static void testStartupFuelPumping(void) { + EngineTestHelper eth(FORD_INLINE_6_1995); + + StartupFuelPumping sf; + + Engine * engine = ð.engine; + RpmCalculator rc; + engine->rpmCalculator = &rc; + + engine->rpmCalculator->mockRpm = 0; + + engine->engineConfiguration->tpsMin = 0; + engine->engineConfiguration->tpsMin = 5; + + sf.update(engine); + +} + static void testRpmCalculator(void) { printf("*************************************************** testRpmCalculator\r\n"); @@ -492,4 +510,5 @@ void testTriggerDecoder(void) { testMazda323(); testRpmCalculator(); + testStartupFuelPumping(); }