minor perf tweaks (#1946)

* only start PWM if needed

* put important stuff first

* use conversion

* this broke the logic
This commit is contained in:
Matthew Kennedy 2020-11-15 21:06:11 -08:00 committed by GitHub
parent 7cba09b3fa
commit 2f4294ac4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 47 deletions

View File

@ -52,35 +52,44 @@ public:
// Configure the disable pin first - ensure things are in a safe state // Configure the disable pin first - ensure things are in a safe state
m_disablePin.initPin("ETB Disable", pinDisable); m_disablePin.initPin("ETB Disable", pinDisable);
m_disablePin.setValue(0);
// Clamp to >100hz // Clamp to >100hz
int clampedFrequency = maxI(100, frequency); int clampedFrequency = maxI(100, frequency);
// no need to complicate event queue with ETB PWM in unit tests // no need to complicate event queue with ETB PWM in unit tests
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
startSimplePwmHard(&m_pwmEnable, "ETB Enable", if (useTwoWires) {
executor, startSimplePwmHard(&m_pwmDir1, "ETB Dir 1",
pinEnable, executor,
&m_pinEnable, pinDir1,
clampedFrequency, &m_pinDir1,
0 clampedFrequency,
); 0
);
startSimplePwmHard(&m_pwmDir1, "ETB Dir 1", startSimplePwmHard(&m_pwmDir2, "ETB Dir 2",
executor, executor,
pinDir1, pinDir2,
&m_pinDir1, &m_pinDir2,
clampedFrequency, clampedFrequency,
0 0
); );
startSimplePwmHard(&m_pwmDir2, "ETB Dir 2", m_pinEnable.initPin("ETB Enable", pinEnable);
executor,
pinDir2, } else {
&m_pinDir2, m_pinDir1.initPin("ETB Dir 1", pinDir1);
clampedFrequency, m_pinDir2.initPin("ETB Dir 2", pinDir2);
0
); startSimplePwmHard(&m_pwmEnable, "ETB Enable",
executor,
pinEnable,
&m_pinEnable,
clampedFrequency,
0
);
}
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
} }
}; };

View File

@ -174,25 +174,22 @@ void initIdleHardware(Logging* sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
*/ */
// todo: even for double-solenoid mode we can probably use same single SimplePWM // todo: even for double-solenoid mode we can probably use same single SimplePWM
// todo: open question why do we pass 'OutputPin' into 'startSimplePwmExt' if we have custom applyIdleSolenoidPinState listener anyway? // todo: open question why do we pass 'OutputPin' into 'startSimplePwmExt' if we have custom applyIdleSolenoidPinState listener anyway?
if (!CONFIG(isDoubleSolenoidIdle)) { if (CONFIG(idle).solenoidPin != GPIO_UNASSIGNED) {
startSimplePwm(&idleSolenoidOpen, "Idle Valve",
&engine->executor,
&enginePins.idleSolenoidPin,
CONFIG(idle).solenoidFrequency, PERCENT_TO_DUTY(CONFIG(manIdlePosition)),
(pwm_gen_callback*)applyIdleSolenoidPinState);
} else {
startSimplePwm(&idleSolenoidOpen, "Idle Valve Open", startSimplePwm(&idleSolenoidOpen, "Idle Valve Open",
&engine->executor, &engine->executor,
&enginePins.idleSolenoidPin, &enginePins.idleSolenoidPin,
CONFIG(idle).solenoidFrequency, PERCENT_TO_DUTY(CONFIG(manIdlePosition)), CONFIG(idle).solenoidFrequency, PERCENT_TO_DUTY(CONFIG(manIdlePosition)),
(pwm_gen_callback*)applyIdleSolenoidPinState); (pwm_gen_callback*)applyIdleSolenoidPinState);
startSimplePwm(&idleSolenoidClose, "Idle Valve Close",
&engine->executor,
&enginePins.secondIdleSolenoidPin,
CONFIG(idle).solenoidFrequency, PERCENT_TO_DUTY(CONFIG(manIdlePosition)),
(pwm_gen_callback*)applyIdleSolenoidPinState);
} }
if (CONFIG(isDoubleSolenoidIdle) && CONFIG(secondSolenoidPin) != GPIO_UNASSIGNED) {
startSimplePwm(&idleSolenoidClose, "Idle Valve Close",
&engine->executor,
&enginePins.secondIdleSolenoidPin,
CONFIG(idle).solenoidFrequency, PERCENT_TO_DUTY(CONFIG(manIdlePosition)),
(pwm_gen_callback*)applyIdleSolenoidPinState);
}
idlePositionSensitivityThreshold = 0.0f; idlePositionSensitivityThreshold = 0.0f;
} }
} }

View File

@ -87,10 +87,9 @@ void setMockState(brain_pin_e pin, bool state DECLARE_ENGINE_PARAMETER_SUFFIX) {
/** /**
* 64-bit result would not overflow, but that's complex stuff for our 32-bit MCU * 64-bit result would not overflow, but that's complex stuff for our 32-bit MCU
*/ */
//todo: macro to save method invocation
efitimeus_t getTimeNowUs(void) { efitimeus_t getTimeNowUs(void) {
ScopePerf perf(PE::GetTimeNowUs); ScopePerf perf(PE::GetTimeNowUs);
return getTimeNowNt() / (CORE_CLOCK / 1000000); return NT2US(getTimeNowNt());
} }
volatile uint32_t lastLowerNt = 0; volatile uint32_t lastLowerNt = 0;

View File

@ -130,6 +130,14 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_
} }
void fireSparkAndPrepareNextSchedule(IgnitionEvent *event) { void fireSparkAndPrepareNextSchedule(IgnitionEvent *event) {
for (int i = 0; i< MAX_OUTPUTS_FOR_IGNITION;i++) {
IgnitionOutputPin *output = event->outputs[i];
if (output) {
fireSparkBySettingPinLow(event, output);
}
}
efitick_t nowNt = getTimeNowNt(); efitick_t nowNt = getTimeNowNt();
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
@ -141,13 +149,6 @@ void fireSparkAndPrepareNextSchedule(IgnitionEvent *event) {
LogTriggerCoilState(nowNt, false PASS_ENGINE_PARAMETER_SUFFIX); LogTriggerCoilState(nowNt, false PASS_ENGINE_PARAMETER_SUFFIX);
#endif // EFI_TOOTH_LOGGER #endif // EFI_TOOTH_LOGGER
for (int i = 0; i< MAX_OUTPUTS_FOR_IGNITION;i++) {
IgnitionOutputPin *output = event->outputs[i];
if (output) {
fireSparkBySettingPinLow(event, output);
}
}
#if !EFI_UNIT_TEST #if !EFI_UNIT_TEST
if (engineConfiguration->debugMode == DBG_DWELL_METRIC) { if (engineConfiguration->debugMode == DBG_DWELL_METRIC) {
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO