refactoring

This commit is contained in:
rusefi 2017-05-25 22:49:40 -04:00
parent fa18efb4c9
commit a7ef2eb305
1 changed files with 21 additions and 32 deletions

View File

@ -174,36 +174,19 @@ bool isCrankingE(Engine *engine) {
*/ */
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) { uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) {
RpmCalculator *rpmState = &engine->rpmCalculator;
efitick_t nowNt = getTimeNowNt(); efitick_t nowNt = getTimeNowNt();
ENGINE(m.beforeRpmCb) = GET_TIMESTAMP();
#if EFI_PROD_CODE #if EFI_PROD_CODE
efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "lowstckRCL"); efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "lowstckRCL");
#endif #endif
#if EFI_SENSOR_CHART || defined(__DOXYGEN__) if (index == 0) {
angle_t crankAngle = NAN; ENGINE(m.beforeRpmCb) = GET_TIMESTAMP();
int signal = -1; RpmCalculator *rpmState = &engine->rpmCalculator;
if (ENGINE(sensorChartMode) == SC_TRIGGER) {
crankAngle = getCrankshaftAngleNt(nowNt PASS_ENGINE_PARAMETER_SUFFIX);
signal = 1000 * ckpSignalType + index;
}
#endif
if (index != 0) { bool hadRpmRecently = rpmState->isRunning(PASS_ENGINE_PARAMETER_SIGNATURE);
#if EFI_SENSOR_CHART || defined(__DOXYGEN__)
if (ENGINE(sensorChartMode) == SC_TRIGGER) {
scAddData(crankAngle, signal);
}
#endif
return;
}
// todo: wrap this with if (index == 0) statement this would make scAddData logic simpler
bool hadRpmRecently = rpmState->isRunning(PASS_ENGINE_PARAMETER_SIGNATURE); if (hadRpmRecently) {
efitime_t diffNt = nowNt - rpmState->lastRpmEventTimeNt;
if (hadRpmRecently) {
efitime_t diffNt = nowNt - rpmState->lastRpmEventTimeNt;
/** /**
* Four stroke cycle is two crankshaft revolutions * Four stroke cycle is two crankshaft revolutions
* *
@ -211,24 +194,30 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
* and each revolution of crankshaft consists of two engine cycles revolutions * and each revolution of crankshaft consists of two engine cycles revolutions
* *
*/ */
if (diffNt == 0) { if (diffNt == 0) {
rpmState->setRpmValue(NOISY_RPM PASS_ENGINE_PARAMETER_SUFFIX); rpmState->setRpmValue(NOISY_RPM PASS_ENGINE_PARAMETER_SUFFIX);
} else { } else {
int mult = (int)getEngineCycle(engineConfiguration->operationMode) / 360; int mult = (int)getEngineCycle(engineConfiguration->operationMode) / 360;
int rpm = (int) (60 * US2NT(US_PER_SECOND_LL) * mult / diffNt); int rpm = (int) (60 * US2NT(US_PER_SECOND_LL) * mult / diffNt);
rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm PASS_ENGINE_PARAMETER_SUFFIX); rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm PASS_ENGINE_PARAMETER_SUFFIX);
}
} }
rpmState->onNewEngineCycle();
rpmState->lastRpmEventTimeNt = nowNt;
ENGINE(m.rpmCbTime) = GET_TIMESTAMP() - ENGINE(m.beforeRpmCb);
} }
rpmState->onNewEngineCycle();
rpmState->lastRpmEventTimeNt = nowNt;
#if EFI_SENSOR_CHART || defined(__DOXYGEN__) #if EFI_SENSOR_CHART || defined(__DOXYGEN__)
// this 'index==0' case is here so that it happens after cycle callback so // this 'index==0' case is here so that it happens after cycle callback so
// it goes into sniffer report into the first position // it goes into sniffer report into the first position
if (ENGINE(sensorChartMode) == SC_TRIGGER) { if (ENGINE(sensorChartMode) == SC_TRIGGER) {
angle_t crankAngle = getCrankshaftAngleNt(nowNt PASS_ENGINE_PARAMETER_SUFFIX);
int signal = 1000 * ckpSignalType + index;
scAddData(crankAngle, signal); scAddData(crankAngle, signal);
} }
#endif #endif
ENGINE(m.rpmCbTime) = GET_TIMESTAMP() - ENGINE(m.beforeRpmCb);
} }
static scheduling_s tdcScheduler[2]; static scheduling_s tdcScheduler[2];