From 1dffb21e8982646a0a9a1133397516ff82956022 Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 12 Apr 2019 20:06:09 -0400 Subject: [PATCH] smarter PWM API - need to pass arbitrary pointer --- firmware/controllers/actuators/alternator_controller.cpp | 4 ++-- firmware/controllers/actuators/idle_thread.cpp | 2 +- firmware/controllers/scheduling/pwm_generator_logic.cpp | 9 +++++---- firmware/controllers/scheduling/pwm_generator_logic.h | 3 ++- firmware/controllers/trigger/trigger_emulator_algo.cpp | 4 ++-- firmware/hw_layer/pwm_generator.h | 3 ++- firmware/svnversion.h | 6 +++--- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/firmware/controllers/actuators/alternator_controller.cpp b/firmware/controllers/actuators/alternator_controller.cpp index 10fdb74177..022fa39a28 100644 --- a/firmware/controllers/actuators/alternator_controller.cpp +++ b/firmware/controllers/actuators/alternator_controller.cpp @@ -124,7 +124,7 @@ void setAltPFactor(float p) { showAltInfo(); } -static void applyAlternatorPinState(PwmConfig *state, int stateIndex) { +static void applyAlternatorPinState(PwmConfig *state, int stateIndex, PwmConfig *arg) /* pwm_gen_callback */ { efiAssertVoid(CUSTOM_ERR_6643, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex"); efiAssertVoid(CUSTOM_IDLE_WAVE_CNT, state->multiWave.waveCount == 1, "invalid idle waveCount"); OutputPin *output = state->outputPins[0]; @@ -167,7 +167,7 @@ void initAlternatorCtrl(Logging *sharedLogger) { &engine->executor, CONFIGB(alternatorControlPin), &enginePins.alternatorPin, - engineConfiguration->alternatorPwmFrequency, 0.1, applyAlternatorPinState); + engineConfiguration->alternatorPwmFrequency, 0.1, (pwm_gen_callback*)applyAlternatorPinState); } instance.Start(); } diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index 9df155aca8..dbf5850b75 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -449,7 +449,7 @@ void setDefaultIdleParameters(void) { engineConfiguration->idleRpmPid.periodMs = 10; } -static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) { +static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex, void *arg) /* pwm_gen_callback */ { efiAssertVoid(CUSTOM_ERR_6645, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex"); efiAssertVoid(CUSTOM_ERR_6646, state->multiWave.waveCount == 1, "invalid idle waveCount"); OutputPin *output = state->outputPins[0]; diff --git a/firmware/controllers/scheduling/pwm_generator_logic.cpp b/firmware/controllers/scheduling/pwm_generator_logic.cpp index be124a96dd..bc7dd300ca 100644 --- a/firmware/controllers/scheduling/pwm_generator_logic.cpp +++ b/firmware/controllers/scheduling/pwm_generator_logic.cpp @@ -44,6 +44,7 @@ PwmConfig::PwmConfig() { stateChangeCallback = NULL; executor = NULL; name = "[noname]"; + arg = this; } PwmConfig::PwmConfig(float *st, SingleWave *waves) : PwmConfig() { @@ -74,7 +75,7 @@ void SimplePwm::setSimplePwmDutyCycle(float dutyCycle) { * this custom handling of zero value comes from CJ125 heater code * TODO: is this really needed? cover by unit test? */ - stateChangeCallback(this, 0); + stateChangeCallback(this, 0, arg); } if (dutyCycle < ZERO_PWM_THRESHOLD) { @@ -156,7 +157,7 @@ efitimeus_t PwmConfig::togglePwmState() { /** * NaN period means PWM is paused, we also set the pin low */ - stateChangeCallback(this, 0); + stateChangeCallback(this, 0, arg); return getTimeNowUs() + MS2US(NAN_FREQUENCY_SLEEP_PERIOD_MS); } if (mode != PM_NORMAL) { @@ -181,7 +182,7 @@ efitimeus_t PwmConfig::togglePwmState() { cbStateIndex = 1; } - stateChangeCallback(this, cbStateIndex); + stateChangeCallback(this, cbStateIndex, arg); efitimeus_t nextSwitchTimeUs = getNextSwitchTimeUs(this); #if DEBUG_PWM @@ -331,7 +332,7 @@ void startSimplePwmExt(SimplePwm *state, const char *msg, * * This method takes ~350 ticks. */ -void applyPinState(PwmConfig *state, int stateIndex) { +void applyPinState(PwmConfig *state, int stateIndex, void *arg) /* pwm_gen_callback */ { efiAssertVoid(CUSTOM_ERR_6663, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex"); efiAssertVoid(CUSTOM_ERR_6664, state->multiWave.waveCount <= PWM_PHASE_MAX_WAVE_PER_PWM, "invalid waveCount"); for (int channelIndex = 0; channelIndex < state->multiWave.waveCount; channelIndex++) { diff --git a/firmware/controllers/scheduling/pwm_generator_logic.h b/firmware/controllers/scheduling/pwm_generator_logic.h index 84b89ccdb0..e241a81679 100644 --- a/firmware/controllers/scheduling/pwm_generator_logic.h +++ b/firmware/controllers/scheduling/pwm_generator_logic.h @@ -38,7 +38,7 @@ typedef struct { class PwmConfig; typedef void (pwm_cycle_callback)(PwmConfig *state); -typedef void (pwm_gen_callback)(PwmConfig *state, int stateIndex); +typedef void (pwm_gen_callback)(PwmConfig *state, int stateIndex, void *arg); typedef enum { PM_ZERO, @@ -54,6 +54,7 @@ public: PwmConfig(); PwmConfig(float *switchTimes, SingleWave *waves); void init(float *switchTimes, SingleWave *waves); + void *arg = NULL; void weComplexInit(const char *msg, ExecutorInterface *executor, diff --git a/firmware/controllers/trigger/trigger_emulator_algo.cpp b/firmware/controllers/trigger/trigger_emulator_algo.cpp index a13aeac47f..5e49e4250e 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.cpp +++ b/firmware/controllers/trigger/trigger_emulator_algo.cpp @@ -133,7 +133,7 @@ static void updateTriggerShapeIfNeeded(PwmConfig *state) { static TriggerEmulatorHelper helper; -static void emulatorApplyPinState(PwmConfig *state, int stateIndex) { +static void emulatorApplyPinState(PwmConfig *state, int stateIndex, void *arg) /* pwm_gen_callback */ { if (stopEmulationAtIndex == stateIndex) { isEmulating = false; } @@ -141,7 +141,7 @@ static void emulatorApplyPinState(PwmConfig *state, int stateIndex) { return; } #if EFI_PROD_CODE || defined(__DOXYGEN__) - applyPinState(state, stateIndex); + applyPinState(state, stateIndex, arg); #endif /* EFI_PROD_CODE */ if (engineConfiguration->directSelfStimulation) { /** diff --git a/firmware/hw_layer/pwm_generator.h b/firmware/hw_layer/pwm_generator.h index 7654713ae6..b9188c61f8 100644 --- a/firmware/hw_layer/pwm_generator.h +++ b/firmware/hw_layer/pwm_generator.h @@ -19,7 +19,8 @@ void initPwmGenerator(void); /** * default implementation of pwm_gen_callback which simply toggles the pins + * */ -void applyPinState(PwmConfig *state, int stateIndex); +void applyPinState(PwmConfig *state, int stateIndex, void* arg) /* pwm_gen_callback */; #endif /* PWM_GENERATOR_H_ */ diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 7a4d81a117..6185f02c82 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,12 +1,12 @@ // This file was generated by Version2Header -// Sun Apr 07 12:26:48 EDT 2019 +// Fri Apr 12 18:42:01 EDT 2019 #ifndef GIT_HASH -#define GIT_HASH "bbcb86ec1f62140ebc31322f5ec6761e293a8e62" +#define GIT_HASH "606b2e8e75993c359c63ec4fc6dbbbdfd0dd9285" #endif #ifndef VCS_VERSION -#define VCS_VERSION "17098" +#define VCS_VERSION "17145" #endif