refactoring around GET_RPM

This commit is contained in:
rusefi 2019-01-21 20:33:21 -05:00
parent 1b8217392c
commit 7a20bda66f
14 changed files with 27 additions and 26 deletions

View File

@ -838,7 +838,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
{
float instantRpm = engine->triggerCentral.triggerState.instantRpm;
tsOutputChannels->debugFloatField1 = instantRpm;
tsOutputChannels->debugFloatField2 = instantRpm / GET_RPM();
tsOutputChannels->debugFloatField2 = instantRpm / GET_RPM_VALUE;
}
break;
case DBG_ION:

View File

@ -68,7 +68,7 @@ static msg_t auxPidThread(int param) {
pidReset();
}
float rpm = GET_RPM();
float rpm = GET_RPM_VALUE;
// todo: make this configurable?
bool enabledAtCurrentRpm = rpm > engineConfiguration->cranking.rpm;

View File

@ -65,7 +65,7 @@ static msg_t AltCtrlThread(int param) {
}
// todo: migrate this to FSIO
bool alternatorShouldBeEnabledAtCurrentRpm = GET_RPM() > engineConfiguration->cranking.rpm;
bool alternatorShouldBeEnabledAtCurrentRpm = GET_RPM_VALUE > engineConfiguration->cranking.rpm;
engine->isAlternatorControlEnabled = CONFIG(isAlternatorControlEnabled) && alternatorShouldBeEnabledAtCurrentRpm;
if (!engine->isAlternatorControlEnabled) {

View File

@ -451,7 +451,7 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) {
OutputPin *output = state->outputPins[0];
int value = state->multiWave.getChannelState(/*channelIndex*/0, stateIndex);
if (!value /* always allow turning solenoid off */ ||
(GET_RPM() != 0 || timeToStopIdleTest != 0) /* do not run solenoid unless engine is spinning or bench testing in progress */
(GET_RPM_VALUE != 0 || timeToStopIdleTest != 0) /* do not run solenoid unless engine is spinning or bench testing in progress */
) {
output->setValue(value);
}

View File

@ -224,7 +224,7 @@ void postMapState(TunerStudioOutputChannels *tsOutputChannels) {
}
void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
int rpm = GET_RPM();
int rpm = GET_RPM_VALUE;
if (isValidRpm(rpm)) {
MAP_sensor_config_s * c = &engineConfiguration->map;
angle_t start = interpolate2d("mapa", rpm, c->samplingAngleBins, c->samplingAngle, MAP_ANGLE_SIZE);
@ -261,7 +261,7 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType,
return;
engine->m.beforeMapAveragingCb = GET_TIMESTAMP();
int rpm = GET_RPM();
int rpm = GET_RPM_VALUE;
if (!isValidRpm(rpm)) {
return;
}
@ -322,7 +322,7 @@ float getMap(void) {
}
#if EFI_ANALOG_SENSORS || defined(__DOXYGEN__)
if (!isValidRpm(GET_RPM()) || currentPressure == NO_VALUE_YET)
if (!isValidRpm(GET_RPM_VALUE) || currentPressure == NO_VALUE_YET)
return validateMap(getRawMap()); // maybe return NaN in case of stopped engine?
return validateMap(currentPressure);
#else

View File

@ -238,7 +238,7 @@ static floatms_t getCrankingSparkDwell(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} else {
// technically this could be implemented via interpolate2d
float angle = engineConfiguration->crankingChargeAngle;
return getOneDegreeTimeMs(GET_RPM()) * angle;
return getOneDegreeTimeMs(GET_RPM_VALUE) * angle;
}
}

View File

@ -40,7 +40,7 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType,
if (index != SCHEDULING_TRIGGER_INDEX) {
return;
}
int rpm = GET_RPM();
int rpm = GET_RPM_VALUE;
if (!isValidRpm(rpm)) {
return;
}

View File

@ -315,7 +315,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
InjectorOutputPin *output = event->outputs[0];
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
printf("fuelout %s duration %d total=%d\t\n", output->name, (int)durationUs,
(int)MS2US(getCrankshaftRevolutionTimeMs(GET_RPM())));
(int)MS2US(getCrankshaftRevolutionTimeMs(GET_RPM_VALUE)));
#endif /*EFI_PRINTF_FUEL_DETAILS */
@ -350,7 +350,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if ! EFI_UNIT_TEST
if (GET_RPM() < CONFIG(fuelClosedLoopRpmThreshold) ||
if (GET_RPM_VALUE < CONFIG(fuelClosedLoopRpmThreshold) ||
ENGINE(sensors.clt) < CONFIG(fuelClosedLoopCltThreshold) ||
getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(fuelClosedLoopTpsThreshold) ||
ENGINE(sensors.currentAfr) < CONFIGB(fuelClosedLoopAfrLowThreshold) ||
@ -456,7 +456,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D
return;
}
int rpm = GET_RPM();
int rpm = GET_RPM_VALUE;
if (rpm == 0) {
// this happens while we just start cranking
// todo: check for 'trigger->is_synchnonized?'

View File

@ -207,13 +207,10 @@ void RpmCalculator::setSpinningUp(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFI
}
/**
* WARNING: this is a heavy method because 'getRpm()' is relatively heavy
*
* @return -1 in case of isNoisySignal(), current RPM otherwise
*/
// todo: migrate to float return result or add a float version? this would have with calculations
// todo: add a version which does not check time & saves time? need to profile
int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
#if !EFI_PROD_CODE
if (mockRpm != MOCK_UNDEFINED) {
return mockRpm;

View File

@ -53,8 +53,6 @@ typedef enum {
RUNNING,
} spinning_state_e;
#define GET_RPM() ( ENGINE(rpmCalculator.rpmValue) )
class RpmCalculator {
public:
#if !EFI_PROD_CODE
@ -94,7 +92,11 @@ public:
*/
void setStopSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE);
int getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE);
/**
* Just a getter for rpmValue
* Also hangles mockRpm if not EFI_PROD_CODE
*/
int getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) const;
/**
* This method is invoked once per engine cycle right after we calculate new RPM value
*/
@ -157,6 +159,10 @@ private:
*/
#define getRpmE(engine) (engine)->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE)
#define GET_RPM_VALUE ( ENGINE(rpmCalculator.rpmValue) )
#define isValidRpm(rpm) ((rpm) > 0 && (rpm) < UNREALISTIC_RPM)
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX);
/**
* @brief Initialize RPM calculator
@ -167,8 +173,6 @@ float getCrankshaftAngleNt(efitime_t timeNt DECLARE_ENGINE_PARAMETER_SUFFIX);
int getRevolutionCounter(void);
#define isValidRpm(rpm) ((rpm) > 0 && (rpm) < UNREALISTIC_RPM)
#if EFI_ENGINE_SNIFFER
#define addEngineSnifferEvent(name, msg) if (ENGINE(isEngineChartEnabled)) { waveChart.addEvent3((name), (msg)); }
#else

View File

@ -131,7 +131,7 @@ void turnSparkPinLow(IgnitionEvent *event) {
static void turnSparkPinHigh2(IgnitionEvent *event, IgnitionOutputPin *output) {
#if ! EFI_UNIT_TEST || defined(__DOXYGEN__)
if (GET_RPM() > 2 * engineConfiguration->cranking.rpm) {
if (GET_RPM_VALUE > 2 * engineConfiguration->cranking.rpm) {
const char *outputName = output->name;
if (prevSparkName == outputName && getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) != IM_ONE_COIL) {
warning(CUSTOM_OBD_SKIPPED_SPARK, "looks like skipped spark event %d %s", getRevolutionCounter(), outputName);

View File

@ -566,7 +566,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
}
if (!isValidIndex(PASS_ENGINE_PARAMETER_SIGNATURE) && !engine->isInitializingTrigger) {
// let's not show a warning if we are just starting to spin
if (GET_RPM() != 0) {
if (GET_RPM_VALUE != 0) {
warning(CUSTOM_SYNC_ERROR, "sync error: index #%d above total size %d", currentCycle.current_index, getTriggerSize());
lastDecodingErrorTime = getTimeNowNt();
someSortOfTriggerError = true;

View File

@ -241,7 +241,7 @@ static void intHoldCallback(trigger_event_e ckpEventType, uint32_t index DECLARE
return;
engine->m.beforeHipCb = GET_TIMESTAMP();
int rpm = GET_RPM();
int rpm = GET_RPM_VALUE;
if (!isValidRpm(rpm))
return;
@ -299,7 +299,7 @@ void hipAdcCallback(adcsample_t adcValue) {
hipValueMax = maxF(engine->knockVolts, hipValueMax);
engine->knockLogic(engine->knockVolts);
instance.handleValue(GET_RPM() DEFINE_PARAM_SUFFIX(PASS_HIP_PARAMS));
instance.handleValue(GET_RPM_VALUE DEFINE_PARAM_SUFFIX(PASS_HIP_PARAMS));
}
}

View File

@ -104,5 +104,5 @@ TEST(cranking, testFasterEngineSpinningUp60_2) {
setupSimpleTestEngineWithMaf(&eth, IM_SEQUENTIAL, TT_TOOTHED_WHEEL_60_2);
eth.fireTriggerEvents2(30 /* count */, 1 /*ms*/);
}