From 14c494155249edbc25bdeee85c6d4bf4bde56d1b Mon Sep 17 00:00:00 2001 From: rusEfi Date: Fri, 26 Aug 2016 17:02:37 -0400 Subject: [PATCH] auto-sync --- firmware/config/stm32f4ems/efifeatures.h | 2 + firmware/controllers/algo/signal_executor.cpp | 42 +++++++++++++++++-- firmware/controllers/system/efiGpio.h | 2 + .../trigger/main_trigger_callback.cpp | 24 +++++++---- unit_tests/engine_test_helper.cpp | 5 +++ unit_tests/main.cpp | 1 + unit_tests/test_fuel_map.cpp | 1 - unit_tests/test_trigger_decoder.cpp | 37 ++++++++-------- unit_tests/test_trigger_decoder.h | 2 + 9 files changed, 84 insertions(+), 32 deletions(-) diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index b3302e801d..a7815a022e 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -78,6 +78,8 @@ #define EFI_SIGNAL_EXECUTOR_ONE_TIMER TRUE #define EFI_SIGNAL_EXECUTOR_HW_TIMER FALSE +#define FUEL_MATH_EXTREME_LOGGING FALSE + #define EFI_INTERNAL_FLASH TRUE /** diff --git a/firmware/controllers/algo/signal_executor.cpp b/firmware/controllers/algo/signal_executor.cpp index df523e7a0b..7bd46afa6d 100644 --- a/firmware/controllers/algo/signal_executor.cpp +++ b/firmware/controllers/algo/signal_executor.cpp @@ -37,7 +37,7 @@ EXTERN_ENGINE; #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) #include "engine_sniffer.h" extern WaveChart waveChart; -#endif +#endif /* EFI_ENGINE_SNIFFER */ #include "efiGpio.h" @@ -109,6 +109,42 @@ void turnPinLow(NamedOutputPin *output) { int getRevolutionCounter(void); +#if FUEL_MATH_EXTREME_LOGGING +extern LoggingWithStorage sharedLogger; +#endif /* FUEL_MATH_EXTREME_LOGGING */ + +// todo: make these macro? kind of a penny optimization if compiler is not smart to inline +void seTurnPinHigh(NamedOutputPin *output) { +#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__) + const char * w = output->currentLogicValue == true ? "err" : ""; + scheduleMsg(&sharedLogger, "^ %spin=%s eventIndex %d", w, output->name, + getRevolutionCounter()); +#endif /* FUEL_MATH_EXTREME_LOGGING */ + + + turnPinHigh(output); +} + +void seTurnPinLow(NamedOutputPin *output) { +#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__) + const char * w = output->currentLogicValue == false ? "err" : ""; + + scheduleMsg(&sharedLogger, "- %spin=%s eventIndex %d", w, output->name, + getRevolutionCounter()); +#endif /* FUEL_MATH_EXTREME_LOGGING */ + + turnPinLow(output); +} + +void seScheduleByTime(const char *prefix, scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, NamedOutputPin *param) { +#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__) + scheduleMsg(&sharedLogger, "sch %s %x %d %s", prefix, scheduling, + time, param->name); +#endif /* FUEL_MATH_EXTREME_LOGGING */ + scheduleByTime(prefix, scheduling, time, callback, param); +} + + /** * * @param delay the number of ticks before the output signal @@ -135,7 +171,7 @@ void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayUs, floa printf("scheduling output %s\r\n", output->name); #endif - scheduleByTime("out up", sUp, nowUs + (int) delayUs, (schfunc_t) &turnPinHigh, output); - scheduleByTime("out down", sDown, nowUs + (int) (delayUs + durationUs), (schfunc_t) &turnPinLow, output); + seScheduleByTime("out up", sUp, nowUs + (int) delayUs, (schfunc_t) &seTurnPinHigh, output); + seScheduleByTime("out down", sDown, nowUs + (int) (delayUs + durationUs), (schfunc_t) &seTurnPinLow, output); #endif } diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index 0776ade900..528904ce36 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -129,6 +129,8 @@ typedef struct { void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brainPin, pin_output_mode_e *outputMode); +void seTurnPinHigh(NamedOutputPin *output); +void seTurnPinLow(NamedOutputPin *output); void turnPinHigh(NamedOutputPin *output); void turnPinLow(NamedOutputPin *output); void turnSparkPinHigh(NamedOutputPin *output); diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index e85b61c647..cb8df7e7be 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -128,8 +128,10 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int eventIndex, bool limitedF return; } - // scheduleMsg(logger, "handleFuel totalPerCycle=%f", totalPerCycle); - // scheduleMsg(logger, "handleFuel engineCycleDuration=%f", engineCycleDuration); +#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) + scheduleMsg(logger, "handleFuel totalPerCycle=%f", totalPerCycle); + scheduleMsg(logger, "handleFuel engineCycleDuration=%f", engineCycleDuration); +#endif /* EFI_DEFAILED_LOGGING */ if (engine->isCylinderCleanupMode) { return; @@ -137,12 +139,14 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int eventIndex, bool limitedF floatus_t injectionStartDelayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->injectionStart.angleOffset; -// scheduleMsg(logger, "handleFuel pin=%s eventIndex %d duration=%fms %d", event->output->name, -// eventIndex, -// injectionDuration, -// getRevolutionCounter()); -// scheduleMsg(logger, "handleFuel pin=%s delay=%f %d", event->output->name, injectionStartDelayUs, -// getRevolutionCounter()); +#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) + scheduleMsg(logger, "handleFuel pin=%s eventIndex %d duration=%fms %d", event->output->name, + eventIndex, + injectionDuration, + getRevolutionCounter()); + scheduleMsg(logger, "handleFuel pin=%s delay=%f %d", event->output->name, injectionStartDelayUs, + getRevolutionCounter()); +#endif /* EFI_DEFAILED_LOGGING */ OutputSignal *signal = &ENGINE(engineConfiguration2)->fuelActuators[eventIndex]; @@ -196,7 +200,9 @@ static ALWAYS_INLINE void handleFuel(bool limitedFuel, uint32_t eventIndex, int if (!fs->hasEvents[eventIndex]) return; -// scheduleMsg(logger, "handleFuel ind=%d %d", eventIndex, getRevolutionCounter()); +#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__) + scheduleMsg(logger, "handleFuel ind=%d %d", eventIndex, getRevolutionCounter()); +#endif /* EFI_DEFAILED_LOGGING */ ENGINE(tpsAccelEnrichment.onNewValue(getTPS(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER)); ENGINE(engineLoadAccelEnrichment.onEngineCycle(PASS_ENGINE_PARAMETER_F)); diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index ff62b12799..3d52bd30e0 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -11,6 +11,7 @@ #include "speed_density.h" #include "fuel_math.h" #include "accel_enrichment.h" +#include "thermistors.h" extern int timeNow; @@ -47,6 +48,10 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste resetConfigurationExt(NULL, engineType PASS_ENGINE_PARAMETER); prepareShapes(PASS_ENGINE_PARAMETER_F); engine->engineConfiguration->mafAdcChannel = (adc_channel_e)TEST_MAF_CHANNEL; + + initThermistors(NULL PASS_ENGINE_PARAMETER); + // this is needed to have valid CLT and IAT. + engine->updateSlowSensors(PASS_ENGINE_PARAMETER_F); } void EngineTestHelper::fireTriggerEvents(int count) { diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index a38938c9e1..56fec2f00d 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -106,6 +106,7 @@ int getRevolutionCounter(void) { } int main(void) { + testFuelSchedulerBug299(); testLogicExpressions(); testOverflow64Counter(); testInterpolate3d(); diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 99c5a11b60..7048c47101 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -55,7 +55,6 @@ void testFuelMap(void) { printf("*************************************************** initThermistors\r\n"); - initThermistors(NULL PASS_ENGINE_PARAMETER); printf("*** getInjectorLag\r\n"); assertEqualsM("lag", 1.04, getInjectorLag(12 PASS_ENGINE_PARAMETER)); diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index 12ced6665b..28ccbde479 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -123,7 +123,6 @@ void test1995FordInline6TriggerDecoder(void) { assertEqualsM("triggerShapeSynchPointIndex", 0, shape->getTriggerShapeSynchPointIndex()); // this is needed to have valid CLT and IAT. todo: extract method - initThermistors(NULL PASS_ENGINE_PARAMETER); engine->updateSlowSensors(PASS_ENGINE_PARAMETER_F); event_trigger_position_s position; @@ -207,13 +206,6 @@ void testFordAspire(void) { assertEqualsM("higher rpm dwell", 3.25, getSparkDwell(6000 PASS_ENGINE_PARAMETER)); } -void testMazda323(void) { - printf("*************************************************** testMazda323\r\n"); - - EngineTestHelper eth(MAZDA_323); - assertEquals(0, eth.engine.triggerShape.getTriggerShapeSynchPointIndex()); -} - static void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPointIndex, float channel1duty, float channel2duty) { printf("*************************************************** %s\r\n", msg); @@ -241,7 +233,7 @@ extern EventQueue schedulingQueue; extern int mockTps; -static void testStartupFuelPumping(void) { +void testStartupFuelPumping(void) { printf("*************************************************** testStartupFuelPumping\r\n"); EngineTestHelper eth(FORD_INLINE_6_1995); EXPAND_EngineTestHelper; @@ -307,16 +299,10 @@ void testRpmCalculator(void) { efiAssertVoid(eth.engine.engineConfiguration!=NULL, "null config in engine"); - // this is needed to have valid CLT and IAT. todo: extract method - initThermistors(NULL PASS_ENGINE_PARAMETER); - engine->updateSlowSensors(PASS_ENGINE_PARAMETER_F); - engineConfiguration->trigger.customTotalToothCount = 8; engineConfiguration->globalFuelCorrection = 3; eth.initTriggerShapeAndRpmCalculator(); - // this is a very dirty and sad hack. todo: eliminate -// engine.engineConfiguration = eth.engine.engineConfiguration; setInjectorLag(0 PASS_ENGINE_PARAMETER); engine->updateSlowSensors(PASS_ENGINE_PARAMETER_F); @@ -423,7 +409,7 @@ void testRpmCalculator(void) { { scheduling_s *ev0 = schedulingQueue.getForUnitText(0); - assertREquals((void*)ev0->callback, (void*)turnPinHigh); + assertREqualsM("turnHigh", (void*)ev0->callback, (void*)seTurnPinHigh); assertEqualsM("ev 0/2", st + 26666 - 1515, ev0->momentX); assertEqualsLM("o 0/2", (long)&enginePins.injectors[2], (long)ev0->param); @@ -556,11 +542,12 @@ void testTriggerDecoder(void) { // assertEqualsM2("rpm#2", 16666.3750, eth.engine.triggerCentral.triggerState.instantRpmValue[1], 0.5); } -// testTriggerDecoder2("miata 1990", MIATA_1990, 0, 0.6280, 0.0); + testTriggerDecoder2("miata 1990", MIATA_1990, 11, 0.2985, 0.3890); testTriggerDecoder3("miata 1994", MIATA_1994_DEVIATOR, 11, 0.2985, 0.3890, MIATA_NA_GAP); testTriggerDecoder3("citroen", CITROEN_TU3JP, 0, 0.4833, 0.0, 2.9994); -// testTriggerDecoder3("neon NGC4", DODGE_NEON_2003, 70, 0.5000, 0.4983, CHRYSLER_NGC4_GAP); + testTriggerDecoder2("MAZDA_323", MAZDA_323, 0, 0.4833, 0); + testTriggerDecoder3("neon NGC4", DODGE_NEON_2003, 6, 0.5000, 0.0, CHRYSLER_NGC4_GAP); { @@ -586,8 +573,20 @@ void testTriggerDecoder(void) { testTriggerDecoder2("vw ABA", VW_ABA, 114, 0.5000, 0.0); - testMazda323(); testStartupFuelPumping(); testRpmCalculator(); } + +void testFuelSchedulerBug299(void) { + printf("*************************************************** testFuelSchedulerBug299\r\n"); + EngineTestHelper eth(TEST_ENGINE); + EXPAND_EngineTestHelper; + + timeNow = 0; + schedulingQueue.clear(); + + assertEqualsM("CLT", 70, engine->engineState.clt); + + +} diff --git a/unit_tests/test_trigger_decoder.h b/unit_tests/test_trigger_decoder.h index 7444d710dd..f763c13720 100644 --- a/unit_tests/test_trigger_decoder.h +++ b/unit_tests/test_trigger_decoder.h @@ -9,7 +9,9 @@ #define TEST_TRIGGER_DECODER_H_ void testTriggerDecoder(void); +void testFuelSchedulerBug299(void); void testRpmCalculator(void); +void testStartupFuelPumping(void); void test1995FordInline6TriggerDecoder(void); #endif /* TEST_TRIGGER_DECODER_H_ */