auto-sync

This commit is contained in:
rusEfi 2015-02-12 15:04:27 -06:00
parent 192c439f0b
commit fa6f230ab9
4 changed files with 25 additions and 16 deletions

View File

@ -106,6 +106,9 @@ typedef struct {
uint32_t beforeAdvance;
uint32_t advanceTime;
uint32_t beforeFuelCalc;
uint32_t fuelCalcTime;
} monitoring_timestamps_s;
class Engine {
@ -124,6 +127,11 @@ public:
Thermistor iat;
Thermistor clt;
/**
* Fuel injection duration for current engine cycle
*/
float fuelMs;
/**
* ignition dwell duration as crankshaft angle
*/

View File

@ -118,14 +118,14 @@ int getRevolutionCounter(void);
* @param dwell the number of ticks of output duration
*
*/
void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayMs, float durationMs) {
void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayUs, float durationUs) {
#if EFI_GPIO
if (durationMs < 0) {
firmwareError("duration cannot be negative: %d", durationMs);
if (durationUs < 0) {
firmwareError("duration cannot be negative: %d", durationUs);
return;
}
if (cisnan(durationMs)) {
firmwareError("NaN in scheduleOutput", durationMs);
if (cisnan(durationUs)) {
firmwareError("NaN in scheduleOutput", durationUs);
return;
}
@ -134,7 +134,7 @@ void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayMs, floa
scheduling_s * sUp = &signal->signalTimerUp[index];
scheduling_s * sDown = &signal->signalTimerDown[index];
scheduleByTime("out up", sUp, nowUs + (int) MS2US(delayMs), (schfunc_t) &turnPinHigh, signal->output);
scheduleByTime("out down", sDown, nowUs + (int) MS2US(delayMs + durationMs), (schfunc_t) &turnPinLow, signal->output);
scheduleByTime("out up", sUp, nowUs + (int) delayUs, (schfunc_t) &turnPinHigh, signal->output);
scheduleByTime("out down", sDown, nowUs + (int) (delayUs + durationUs), (schfunc_t) &turnPinLow, signal->output);
#endif
}

View File

@ -39,7 +39,7 @@ struct OutputSignal_struct {
scheduling_s signalTimerDown[2];
};
void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayMs, float durationMs);
void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayUs, float durationUs);
void initSignalExecutor(void);
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param);

View File

@ -100,10 +100,7 @@ static void endSimultaniousInjection(Engine *engine) {
}
static ALWAYS_INLINE void handleFuelInjectionEvent(InjectionEvent *event, int rpm DECLARE_ENGINE_PARAMETER_S) {
/**
* todo: we do not really need to calculate fuel for each individual cylinder
*/
float fuelMs = getFuelMs(rpm PASS_ENGINE_PARAMETER) * engineConfiguration->globalFuelCorrection;
float fuelMs = ENGINE(fuelMs);
if (cisnan(fuelMs)) {
warning(OBD_PCM_Processor_Fault, "NaN injection pulse");
return;
@ -116,7 +113,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(InjectionEvent *event, int rp
if (engine->isCylinderCleanupMode)
return;
float delayMs = getOneDegreeTimeMs(rpm) * event->position.angleOffset;
float delayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->position.angleOffset;
if (event->isSimultanious) {
if (fuelMs < 0) {
@ -138,11 +135,11 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(InjectionEvent *event, int rp
scheduling_s * sUp = &signal->signalTimerUp[index];
scheduling_s * sDown = &signal->signalTimerDown[index];
scheduleTask("out up", sUp, (int) MS2US(delayMs), (schfunc_t) &startSimultaniousInjection, engine);
scheduleTask("out down", sDown, (int) MS2US(delayMs) + MS2US(fuelMs), (schfunc_t) &endSimultaniousInjection, engine);
scheduleTask("out up", sUp, (int) delayUs, (schfunc_t) &startSimultaniousInjection, engine);
scheduleTask("out down", sDown, (int) delayUs + MS2US(fuelMs), (schfunc_t) &endSimultaniousInjection, engine);
} else {
scheduleOutput(event->actuator, getTimeNowUs(), delayMs, fuelMs);
scheduleOutput(event->actuator, getTimeNowUs(), delayUs, MS2US(fuelMs));
}
}
@ -348,6 +345,10 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL
}
if (eventIndex == 0) {
engine->m.beforeFuelCalc = GET_TIMESTAMP();
ENGINE(fuelMs) = getFuelMs(rpm PASS_ENGINE_PARAMETER) * engineConfiguration->globalFuelCorrection;
engine->m.fuelCalcTime = GET_TIMESTAMP() - engine->m.beforeFuelCalc;
engine->m.beforeIgnitionSch = GET_TIMESTAMP();
/**