refactor prime (#4627)
This commit is contained in:
parent
974f6f540d
commit
264d33d30e
|
@ -194,8 +194,6 @@ static void doPeriodicSlowCallback() {
|
|||
|
||||
if (engine->rpmCalculator.isStopped()) {
|
||||
resetAccel();
|
||||
} else {
|
||||
updatePrimeInjectionPulseState();
|
||||
}
|
||||
|
||||
if (engine->versionForConfigurationListeners.isOld(engine->getGlobalConfigurationVersion())) {
|
||||
|
|
|
@ -8,12 +8,6 @@
|
|||
#include "sensor.h"
|
||||
#include "backup_ram.h"
|
||||
|
||||
void PrimeController::onPrimeEnd() {
|
||||
endSimultaneousInjectionOnlyTogglePins();
|
||||
|
||||
m_isPriming = false;
|
||||
}
|
||||
|
||||
floatms_t PrimeController::getPrimeDuration() const {
|
||||
auto clt = Sensor::get(SensorType::Clt);
|
||||
|
||||
|
@ -28,16 +22,18 @@ floatms_t PrimeController::getPrimeDuration() const {
|
|||
|
||||
return engine->module<InjectorModel>()->getInjectionDuration(primeMass);
|
||||
}
|
||||
|
||||
// Check if the engine is not stopped or cylinder cleanup is activated
|
||||
static bool isPrimeInjectionPulseSkipped() {
|
||||
if (!getEngineRotationState()->isStopped())
|
||||
// Skip if the engine is already spinning
|
||||
if (!getEngineRotationState()->isStopped()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Skip if cylinder cleanup is active
|
||||
return engineConfiguration->isCylinderCleanupEnabled && (Sensor::getOrZero(SensorType::Tps1) > CLEANUP_MODE_TPS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prime injection pulse
|
||||
*/
|
||||
void PrimeController::onIgnitionStateChanged(bool ignitionOn) {
|
||||
if (!ignitionOn) {
|
||||
// don't prime on ignition-off
|
||||
|
@ -46,34 +42,49 @@ void PrimeController::onIgnitionStateChanged(bool ignitionOn) {
|
|||
|
||||
// First, we need a protection against 'fake' ignition switch on and off (i.e. no engine started), to avoid repeated prime pulses.
|
||||
// So we check and update the ignition switch counter in non-volatile backup-RAM
|
||||
#if EFI_PROD_CODE
|
||||
uint32_t ignSwitchCounter = backupRamLoad(BACKUP_IGNITION_SWITCH_COUNTER);
|
||||
#else /* EFI_PROD_CODE */
|
||||
uint32_t ignSwitchCounter = 0;
|
||||
#endif /* EFI_PROD_CODE */
|
||||
uint32_t ignSwitchCounter = getKeyCycleCounter();
|
||||
|
||||
// if we're just toying with the ignition switch, give it another chance eventually...
|
||||
if (ignSwitchCounter > 10)
|
||||
if (ignSwitchCounter > 10) {
|
||||
ignSwitchCounter = 0;
|
||||
}
|
||||
|
||||
// If we're going to skip this pulse, then save the counter as 0.
|
||||
// That's because we'll definitely need the prime pulse next time (either due to the cylinder cleanup or the engine spinning)
|
||||
if (isPrimeInjectionPulseSkipped())
|
||||
if (isPrimeInjectionPulseSkipped()) {
|
||||
ignSwitchCounter = -1;
|
||||
}
|
||||
|
||||
// start prime injection if this is a 'fresh start'
|
||||
if (ignSwitchCounter == 0) {
|
||||
auto primeDelayMs = engineConfiguration->primingDelay * 1000;
|
||||
|
||||
auto startTime = getTimeNowNt() + MS2NT(primeDelayMs);
|
||||
getExecutorInterface()->scheduleByTimestampNt("prime", &m_start, startTime, { PrimeController::onPrimeStartAdapter, this});
|
||||
getExecutorInterface()->scheduleByTimestampNt("prime", &m_start, startTime, { PrimeController::onPrimeStartAdapter, this });
|
||||
} else {
|
||||
efiPrintf("Skipped priming pulse since ignSwitchCounter = %d", ignSwitchCounter);
|
||||
}
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
// we'll reset it later when the engine starts
|
||||
backupRamSave(BACKUP_IGNITION_SWITCH_COUNTER, ignSwitchCounter + 1);
|
||||
#endif /* EFI_PROD_CODE */
|
||||
setKeyCycleCounter(ignSwitchCounter + 1);
|
||||
}
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
uint32_t PrimeController::getKeyCycleCounter() const {
|
||||
return backupRamLoad(BACKUP_IGNITION_SWITCH_COUNTER);
|
||||
}
|
||||
|
||||
void PrimeController::setKeyCycleCounter(uint32_t count) {
|
||||
backupRamSave(BACKUP_IGNITION_SWITCH_COUNTER, count);
|
||||
}
|
||||
#else // not EFI_PROD_CODE
|
||||
uint32_t PrimeController::getKeyCycleCounter() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PrimeController::setKeyCycleCounter(uint32_t) { }
|
||||
#endif
|
||||
|
||||
void PrimeController::onPrimeStart() {
|
||||
auto durationMs = getPrimeDuration();
|
||||
|
||||
|
@ -93,16 +104,16 @@ void PrimeController::onPrimeStart() {
|
|||
getExecutorInterface()->scheduleByTimestampNt("prime", &m_end, endTime, { onPrimeEndAdapter, this });
|
||||
}
|
||||
|
||||
void updatePrimeInjectionPulseState() {
|
||||
static bool counterWasReset = false;
|
||||
if (counterWasReset)
|
||||
return;
|
||||
void PrimeController::onPrimeEnd() {
|
||||
endSimultaneousInjectionOnlyTogglePins();
|
||||
|
||||
m_isPriming = false;
|
||||
}
|
||||
|
||||
void PrimeController::onSlowCallback() {
|
||||
if (!getEngineRotationState()->isStopped()) {
|
||||
#if EFI_PROD_CODE
|
||||
backupRamSave(BACKUP_IGNITION_SWITCH_COUNTER, 0);
|
||||
#endif /* EFI_PROD_CODE */
|
||||
counterWasReset = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
class PrimeController : public EngineModule {
|
||||
public:
|
||||
void onIgnitionStateChanged(bool ignitionOn) override;
|
||||
void onSlowCallback() override;
|
||||
|
||||
floatms_t getPrimeDuration() const;
|
||||
|
||||
|
@ -35,7 +36,7 @@ private:
|
|||
static void onPrimeEndAdapter(PrimeController* instance) {
|
||||
instance->onPrimeEnd();
|
||||
}
|
||||
};
|
||||
|
||||
// reset injection switch counter if the engine started spinning
|
||||
void updatePrimeInjectionPulseState();
|
||||
uint32_t getKeyCycleCounter() const;
|
||||
void setKeyCycleCounter(uint32_t count);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue