mirror of https://github.com/rusefi/rusefi-1.git
smarter PWM API - need to pass arbitrary pointer
This commit is contained in:
parent
91ac74c1c9
commit
1dffb21e89
|
@ -124,7 +124,7 @@ void setAltPFactor(float p) {
|
||||||
showAltInfo();
|
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_ERR_6643, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex");
|
||||||
efiAssertVoid(CUSTOM_IDLE_WAVE_CNT, state->multiWave.waveCount == 1, "invalid idle waveCount");
|
efiAssertVoid(CUSTOM_IDLE_WAVE_CNT, state->multiWave.waveCount == 1, "invalid idle waveCount");
|
||||||
OutputPin *output = state->outputPins[0];
|
OutputPin *output = state->outputPins[0];
|
||||||
|
@ -167,7 +167,7 @@ void initAlternatorCtrl(Logging *sharedLogger) {
|
||||||
&engine->executor,
|
&engine->executor,
|
||||||
CONFIGB(alternatorControlPin),
|
CONFIGB(alternatorControlPin),
|
||||||
&enginePins.alternatorPin,
|
&enginePins.alternatorPin,
|
||||||
engineConfiguration->alternatorPwmFrequency, 0.1, applyAlternatorPinState);
|
engineConfiguration->alternatorPwmFrequency, 0.1, (pwm_gen_callback*)applyAlternatorPinState);
|
||||||
}
|
}
|
||||||
instance.Start();
|
instance.Start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,7 +449,7 @@ void setDefaultIdleParameters(void) {
|
||||||
engineConfiguration->idleRpmPid.periodMs = 10;
|
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_6645, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex");
|
||||||
efiAssertVoid(CUSTOM_ERR_6646, state->multiWave.waveCount == 1, "invalid idle waveCount");
|
efiAssertVoid(CUSTOM_ERR_6646, state->multiWave.waveCount == 1, "invalid idle waveCount");
|
||||||
OutputPin *output = state->outputPins[0];
|
OutputPin *output = state->outputPins[0];
|
||||||
|
|
|
@ -44,6 +44,7 @@ PwmConfig::PwmConfig() {
|
||||||
stateChangeCallback = NULL;
|
stateChangeCallback = NULL;
|
||||||
executor = NULL;
|
executor = NULL;
|
||||||
name = "[noname]";
|
name = "[noname]";
|
||||||
|
arg = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PwmConfig::PwmConfig(float *st, SingleWave *waves) : PwmConfig() {
|
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
|
* this custom handling of zero value comes from CJ125 heater code
|
||||||
* TODO: is this really needed? cover by unit test?
|
* TODO: is this really needed? cover by unit test?
|
||||||
*/
|
*/
|
||||||
stateChangeCallback(this, 0);
|
stateChangeCallback(this, 0, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dutyCycle < ZERO_PWM_THRESHOLD) {
|
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
|
* 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);
|
return getTimeNowUs() + MS2US(NAN_FREQUENCY_SLEEP_PERIOD_MS);
|
||||||
}
|
}
|
||||||
if (mode != PM_NORMAL) {
|
if (mode != PM_NORMAL) {
|
||||||
|
@ -181,7 +182,7 @@ efitimeus_t PwmConfig::togglePwmState() {
|
||||||
cbStateIndex = 1;
|
cbStateIndex = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateChangeCallback(this, cbStateIndex);
|
stateChangeCallback(this, cbStateIndex, arg);
|
||||||
|
|
||||||
efitimeus_t nextSwitchTimeUs = getNextSwitchTimeUs(this);
|
efitimeus_t nextSwitchTimeUs = getNextSwitchTimeUs(this);
|
||||||
#if DEBUG_PWM
|
#if DEBUG_PWM
|
||||||
|
@ -331,7 +332,7 @@ void startSimplePwmExt(SimplePwm *state, const char *msg,
|
||||||
*
|
*
|
||||||
* This method takes ~350 ticks.
|
* 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_6663, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex");
|
||||||
efiAssertVoid(CUSTOM_ERR_6664, state->multiWave.waveCount <= PWM_PHASE_MAX_WAVE_PER_PWM, "invalid waveCount");
|
efiAssertVoid(CUSTOM_ERR_6664, state->multiWave.waveCount <= PWM_PHASE_MAX_WAVE_PER_PWM, "invalid waveCount");
|
||||||
for (int channelIndex = 0; channelIndex < state->multiWave.waveCount; channelIndex++) {
|
for (int channelIndex = 0; channelIndex < state->multiWave.waveCount; channelIndex++) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ typedef struct {
|
||||||
class PwmConfig;
|
class PwmConfig;
|
||||||
|
|
||||||
typedef void (pwm_cycle_callback)(PwmConfig *state);
|
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 {
|
typedef enum {
|
||||||
PM_ZERO,
|
PM_ZERO,
|
||||||
|
@ -54,6 +54,7 @@ public:
|
||||||
PwmConfig();
|
PwmConfig();
|
||||||
PwmConfig(float *switchTimes, SingleWave *waves);
|
PwmConfig(float *switchTimes, SingleWave *waves);
|
||||||
void init(float *switchTimes, SingleWave *waves);
|
void init(float *switchTimes, SingleWave *waves);
|
||||||
|
void *arg = NULL;
|
||||||
|
|
||||||
void weComplexInit(const char *msg,
|
void weComplexInit(const char *msg,
|
||||||
ExecutorInterface *executor,
|
ExecutorInterface *executor,
|
||||||
|
|
|
@ -133,7 +133,7 @@ static void updateTriggerShapeIfNeeded(PwmConfig *state) {
|
||||||
|
|
||||||
static TriggerEmulatorHelper helper;
|
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) {
|
if (stopEmulationAtIndex == stateIndex) {
|
||||||
isEmulating = false;
|
isEmulating = false;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ static void emulatorApplyPinState(PwmConfig *state, int stateIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||||
applyPinState(state, stateIndex);
|
applyPinState(state, stateIndex, arg);
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
if (engineConfiguration->directSelfStimulation) {
|
if (engineConfiguration->directSelfStimulation) {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,8 @@ void initPwmGenerator(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default implementation of pwm_gen_callback which simply toggles the pins
|
* 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_ */
|
#endif /* PWM_GENERATOR_H_ */
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// This file was generated by Version2Header
|
// 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
|
#ifndef GIT_HASH
|
||||||
#define GIT_HASH "bbcb86ec1f62140ebc31322f5ec6761e293a8e62"
|
#define GIT_HASH "606b2e8e75993c359c63ec4fc6dbbbdfd0dd9285"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef VCS_VERSION
|
#ifndef VCS_VERSION
|
||||||
#define VCS_VERSION "17098"
|
#define VCS_VERSION "17145"
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue