From b8ce0daf858754fcb4983e6f35290b01cecfeecb Mon Sep 17 00:00:00 2001 From: rusefi Date: Wed, 20 Nov 2019 01:42:03 -0500 Subject: [PATCH] more code into unit tests --- firmware/controllers/trigger/aux_valves.cpp | 16 +++++----------- firmware/controllers/trigger/aux_valves.h | 2 +- .../trigger/main_trigger_callback.cpp | 2 +- firmware/controllers/trigger/rpm_calculator.cpp | 12 +++++------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/firmware/controllers/trigger/aux_valves.cpp b/firmware/controllers/trigger/aux_valves.cpp index 593c09688a..5efcbff995 100644 --- a/firmware/controllers/trigger/aux_valves.cpp +++ b/firmware/controllers/trigger/aux_valves.cpp @@ -37,7 +37,7 @@ static void turnOff(NamedOutputPin *output) { static void auxValveTriggerCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) { UNUSED(ckpSignalType); -#if EFI_PROD_CODE || EFI_SIMULATOR + if (index != SCHEDULING_TRIGGER_INDEX) { return; } @@ -46,8 +46,7 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType, return; } - for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT; - valveIndex++) { + for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT; valveIndex++) { NamedOutputPin *output = &enginePins.auxValve[valveIndex]; @@ -66,27 +65,22 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType, fixAngle(onTime, "onTime", CUSTOM_ERR_6556); scheduleByAngle(rpm, &turnOnEvent[valveIndex][phaseIndex], onTime, - (schfunc_t) &turnOn, output); + (schfunc_t) &turnOn, output PASS_ENGINE_PARAMETER_SUFFIX); angle_t offTime = extra + engine->engineState.auxValveEnd; fixAngle(offTime, "offTime", CUSTOM_ERR_6557); scheduleByAngle(rpm, &turnOffEvent[valveIndex][phaseIndex], offTime, - (schfunc_t) &turnOff, output); - + (schfunc_t) &turnOff, output PASS_ENGINE_PARAMETER_SUFFIX); } } - -#endif /* EFI_PROD_CODE || EFI_SIMULATOR */ } -void initAuxValves(Logging *sharedLogger) { +void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { UNUSED(sharedLogger); -#if EFI_PROD_CODE || EFI_SIMULATOR if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) { return; } addTriggerEventListener(auxValveTriggerCallback, "tach", engine); -#endif /* EFI_PROD_CODE || EFI_SIMULATOR */ } void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/trigger/aux_valves.h b/firmware/controllers/trigger/aux_valves.h index 14221cb605..172b488cff 100644 --- a/firmware/controllers/trigger/aux_valves.h +++ b/firmware/controllers/trigger/aux_valves.h @@ -10,7 +10,7 @@ #include "engine.h" -void initAuxValves(Logging *sharedLogger); +void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE); #endif /* CONTROLLERS_TRIGGER_AUX_VALVES_H_ */ diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 9f3f6e9f52..6bac5d4551 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -631,7 +631,7 @@ void initMainEventListener(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX efiAssertVoid(CUSTOM_ERR_6631, engine!=NULL, "null engine"); initSparkLogic(logger); - initAuxValves(logger); + initAuxValves(logger PASS_ENGINE_PARAMETER_SUFFIX); #if EFI_PROD_CODE addConsoleAction("performanceinfo", showTriggerHistogram); diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index f64c31e246..107f47f7d8 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -13,7 +13,7 @@ * @author Andrey Belomutskiy, (c) 2012-2019 */ -#include "global.h" +#include "globalaccess.h" #include "os_access.h" #include "engine.h" #include "rpm_calculator.h" @@ -291,12 +291,12 @@ static scheduling_s tdcScheduler[2]; static char rpmBuffer[_MAX_FILLER]; -#if EFI_PROD_CODE || EFI_SIMULATOR /** * This callback has nothing to do with actual engine control, it just sends a Top Dead Center mark to the rusEfi console * digital sniffer. */ -static void onTdcCallback(void) { +static void onTdcCallback(Engine *engine) { + EXPAND_Engine; itoa10(rpmBuffer, GET_RPM()); #if EFI_ENGINE_SNIFFER waveChart.startDataCollection(); @@ -317,11 +317,11 @@ static void tdcMarkCallback(trigger_event_e ckpSignalType, // todo: use tooth event-based scheduling, not just time-based scheduling if (isValidRpm(rpm)) { scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(), - (schfunc_t) onTdcCallback, NULL); + (schfunc_t) onTdcCallback, engine PASS_ENGINE_PARAMETER_SUFFIX); } } } -#endif + /** * @return Current crankshaft angle, 0 to 720 for four-stroke @@ -344,10 +344,8 @@ void initRpmCalculator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { if (hasFirmwareError()) { return; } -#if EFI_PROD_CODE || EFI_SIMULATOR addTriggerEventListener(tdcMarkCallback, "chart TDC mark", engine); -#endif addTriggerEventListener(rpmShaftPositionCallback, "rpm reporter", engine); }