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,31 +174,14 @@ 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) {
#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); bool hadRpmRecently = rpmState->isRunning(PASS_ENGINE_PARAMETER_SIGNATURE);
@ -221,14 +204,20 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
} }
rpmState->onNewEngineCycle(); rpmState->onNewEngineCycle();
rpmState->lastRpmEventTimeNt = nowNt; rpmState->lastRpmEventTimeNt = nowNt;
ENGINE(m.rpmCbTime) = GET_TIMESTAMP() - ENGINE(m.beforeRpmCb);
}
#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];