auto-sync

This commit is contained in:
rusEfi 2014-11-25 12:03:01 -06:00
parent 94bf364bc6
commit fc2b417ec6
6 changed files with 48 additions and 39 deletions

View File

@ -24,8 +24,7 @@ public:
void clear();
ActuatorEventList events;
void addFuelEvents(trigger_shape_s *s,
injection_mode_e mode DECLARE_ENGINE_PARAMETER_S);
void addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S);
void registerInjectionEvent(
io_pin_e pin, float angle, bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S);

View File

@ -36,6 +36,9 @@ public:
Thermistor iat;
Thermistor clt;
float dwellAngle;
float advance;
trigger_shape_s triggerShape;
void onTriggerEvent(uint64_t nowNt);
@ -62,6 +65,9 @@ public:
uint32_t beforeIgnitionMath;
uint32_t ignitionMathTime;
uint32_t beforeIgnitionSch;
uint32_t ignitionSchTime;
uint32_t time2;
uint32_t time3;
uint32_t time4;
@ -104,6 +110,6 @@ void prepareShapes(Engine *engine);
void resetConfigurationExt(Logging * logger, engine_type_e engineType,
Engine *engine);
void applyNonPersistentConfiguration(Logging * logger, Engine *engine);
void prepareOutputSignals(Engine *engine);
void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F);
#endif /* ENGINE_H_ */

View File

@ -598,9 +598,9 @@ void applyNonPersistentConfiguration(Logging * logger, Engine *engine) {
}
void prepareShapes(Engine *engine) {
prepareOutputSignals(engine);
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
prepareOutputSignals(PASS_ENGINE_PARAMETER_F);
// todo: looks like this is here only for unit tests. todo: remove
initializeIgnitionActions(0, 0, &engineConfiguration2->ignitionEvents[0] PASS_ENGINE_PARAMETER);

View File

@ -190,7 +190,7 @@ void FuelSchedule::clear() {
memset(hasEvents, 0, sizeof(hasEvents));
}
void FuelSchedule::addFuelEvents(trigger_shape_s *s, injection_mode_e mode DECLARE_ENGINE_PARAMETER_S) {
void FuelSchedule::addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S) {
ActuatorEventList *list = &events;
;
list->resetEventList();
@ -332,20 +332,17 @@ int getCylinderId(firing_order_e firingOrder, int index) {
return -1;
}
void prepareOutputSignals(Engine *engine) {
void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
// todo: move this reset into decoder
engine->triggerShape.calculateTriggerSynchPoint(engineConfiguration, engine);
trigger_shape_s * ts = &engine->triggerShape;
injectonSignals.clear();
engineConfiguration2->crankingInjectionEvents.addFuelEvents(ts,
engineConfiguration2->crankingInjectionEvents.addFuelEvents(
engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER);
engineConfiguration2->injectionEvents.addFuelEvents(ts, engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
engineConfiguration2->injectionEvents.addFuelEvents(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
}
void setFuelRpmBin(engine_configuration_s *engineConfiguration, float l, float r) {

View File

@ -283,6 +283,23 @@ void showMainHistogram(void) {
#endif
}
static void doSomeCalc(int rpm DECLARE_ENGINE_PARAMETER_S) {
/**
* Within one engine cycle all cylinders are fired with same timing advance.
* todo: one day we can control cylinders individually
*/
float dwellMs = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER);
if (cisnan(dwellMs) || dwellMs < 0) {
firmwareError("invalid dwell: %f at %d", dwellMs, rpm);
return;
}
float el = getEngineLoadT(PASS_ENGINE_PARAMETER_F);
engine->advance = -getAdvance(rpm, el PASS_ENGINE_PARAMETER);
engine->dwellAngle = dwellMs / getOneDegreeTimeMs(rpm);
}
/**
* This is the main trigger event handler.
* Both injection and ignition are controlled from this method.
@ -323,9 +340,13 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL
if (eventIndex == 0) {
if (localVersion.isOld())
prepareOutputSignals(engine);
engine->beforeIgnitionMath = GET_TIMESTAMP();
prepareOutputSignals(PASS_ENGINE_PARAMETER_F);
engine->beforeIgnitionMath = GET_TIMESTAMP();
doSomeCalc(rpm PASS_ENGINE_PARAMETER);
engine->ignitionMathTime = GET_TIMESTAMP() - engine->beforeIgnitionMath;
engine->beforeIgnitionSch = GET_TIMESTAMP();
/**
* TODO: warning. there is a bit of a hack here, todo: improve.
* currently output signals/times signalTimerUp from the previous revolutions could be
@ -333,42 +354,25 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL
* but we are already repurposing the output signals, but everything works because we
* are not affecting that space in memory. todo: use two instances of 'ignitionSignals'
*/
/**
* Within one engine cycle all cylinders are fired with same timing advance.
* todo: one day we can control cylinders individually
*/
float dwellMs = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER);
if (cisnan(dwellMs) || dwellMs < 0) {
firmwareError("invalid dwell: %f at %d", dwellMs, rpm);
return;
}
float el = getEngineLoadT(PASS_ENGINE_PARAMETER_F);
float advance = getAdvance(rpm, el PASS_ENGINE_PARAMETER);
if (cisnan(advance)) {
// error should already be reported
return;
}
float dwellAngle = dwellMs / getOneDegreeTimeMs(rpm);
float maxAllowedDwellAngle = engineConfiguration->engineCycle / 2;
if (engineConfiguration->ignitionMode == IM_ONE_COIL) {
maxAllowedDwellAngle = engineConfiguration->engineCycle / engineConfiguration->cylindersCount / 1.1;
}
if (dwellAngle > maxAllowedDwellAngle) {
warning(OBD_PCM_Processor_Fault, "dwell angle too long: %f", dwellAngle);
if (engine->dwellAngle > maxAllowedDwellAngle) {
warning(OBD_PCM_Processor_Fault, "dwell angle too long: %f", engine->dwellAngle);
}
// todo: add some check for dwell overflow? like 4 times 6 ms while engine cycle is less then that
initializeIgnitionActions(-advance, dwellAngle,
if (cisnan(engine->advance)) {
// error should already be reported
return;
}
initializeIgnitionActions(engine->advance, engine->dwellAngle,
&engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER);
engine->ignitionMathTime = GET_TIMESTAMP() - engine->beforeIgnitionMath;
engine->ignitionSchTime = GET_TIMESTAMP() - engine->beforeIgnitionSch;
}
triggerEventsQueue.executeAll(getCrankEventCounter());

View File

@ -221,7 +221,10 @@ static void triggerInfo(Engine *engine) {
scheduleMsg(&logger, "Template %s/%d trigger %d", getConfigurationName(engineConfiguration->engineType),
engineConfiguration->engineType, engineConfiguration->triggerConfig.triggerType);
scheduleMsg(&logger, "sn=%d ignitionMathTime=%d", ts->isSynchronizationNeeded, engine->ignitionMathTime);
scheduleMsg(&logger, "sn=%d ignitionMathTime=%d schTime=%d",
ts->isSynchronizationNeeded,
engine->ignitionMathTime,
engine->ignitionSchTime);
scheduleMsg(&logger, "trigger event counters %d/%d/%d/%d", triggerCentral.getHwEventCounter(0),
triggerCentral.getHwEventCounter(1), triggerCentral.getHwEventCounter(2),