refactoring

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

View File

@ -174,31 +174,14 @@ bool isCrankingE(Engine *engine) {
*/
void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) {
RpmCalculator *rpmState = &engine->rpmCalculator;
efitick_t nowNt = getTimeNowNt();
ENGINE(m.beforeRpmCb) = GET_TIMESTAMP();
#if EFI_PROD_CODE
efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "lowstckRCL");
#endif
#if EFI_SENSOR_CHART || defined(__DOXYGEN__)
angle_t crankAngle = NAN;
int signal = -1;
if (ENGINE(sensorChartMode) == SC_TRIGGER) {
crankAngle = getCrankshaftAngleNt(nowNt PASS_ENGINE_PARAMETER_SUFFIX);
signal = 1000 * ckpSignalType + index;
}
#endif
if (index != 0) {
#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
if (index == 0) {
ENGINE(m.beforeRpmCb) = GET_TIMESTAMP();
RpmCalculator *rpmState = &engine->rpmCalculator;
bool hadRpmRecently = rpmState->isRunning(PASS_ENGINE_PARAMETER_SIGNATURE);
@ -221,14 +204,20 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
}
rpmState->onNewEngineCycle();
rpmState->lastRpmEventTimeNt = nowNt;
ENGINE(m.rpmCbTime) = GET_TIMESTAMP() - ENGINE(m.beforeRpmCb);
}
#if EFI_SENSOR_CHART || defined(__DOXYGEN__)
// this 'index==0' case is here so that it happens after cycle callback so
// it goes into sniffer report into the first position
if (ENGINE(sensorChartMode) == SC_TRIGGER) {
angle_t crankAngle = getCrankshaftAngleNt(nowNt PASS_ENGINE_PARAMETER_SUFFIX);
int signal = 1000 * ckpSignalType + index;
scAddData(crankAngle, signal);
}
#endif
ENGINE(m.rpmCbTime) = GET_TIMESTAMP() - ENGINE(m.beforeRpmCb);
}
static scheduling_s tdcScheduler[2];