auto-sync

This commit is contained in:
rusEfi 2015-04-13 19:04:35 -04:00
parent 91663368f5
commit b2506350ac
7 changed files with 34 additions and 30 deletions

View File

@ -143,7 +143,7 @@ public:
/** /**
* Fuel injection duration for current engine cycle * Fuel injection duration for current engine cycle
*/ */
float fuelMs; floatms_t fuelMs;
/** /**
* ignition dwell duration as crankshaft angle * ignition dwell duration as crankshaft angle

View File

@ -32,7 +32,7 @@ public:
class InjectionEvent { class InjectionEvent {
public: public:
event_trigger_position_s position; event_trigger_position_s injectionStart;
OutputSignal *actuator; OutputSignal *actuator;
/** /**
* This is a performance optimization - it's more efficient to handle all * This is a performance optimization - it's more efficient to handle all

View File

@ -31,6 +31,7 @@ typedef uint64_t efitick_t;
typedef float angle_t; typedef float angle_t;
typedef float floatms_t; typedef float floatms_t;
typedef float floatus_t;
/** /**
* numeric value from 0 to 100 * numeric value from 0 to 100

View File

@ -132,14 +132,15 @@ void FuelSchedule::registerInjectionEvent(OutputSignalList *sourceList, NamedOut
ev->actuator = actuator; ev->actuator = actuator;
findTriggerPosition(&ev->position, angle PASS_ENGINE_PARAMETER); findTriggerPosition(&ev->injectionStart, angle PASS_ENGINE_PARAMETER);
if(!hasEvents[ev->position.eventIndex]) { if (!hasEvents[ev->injectionStart.eventIndex]) {
hasEvents[ev->position.eventIndex] = true; hasEvents[ev->injectionStart.eventIndex] = true;
eventsCount++; eventsCount++;
} }
} }
FuelSchedule::FuelSchedule() { FuelSchedule::FuelSchedule() {
clear();
} }
void FuelSchedule::clear() { void FuelSchedule::clear() {

View File

@ -99,28 +99,28 @@ static void endSimultaniousInjection(Engine *engine) {
} }
static ALWAYS_INLINE void handleFuelInjectionEvent(InjectionEvent *event, int rpm DECLARE_ENGINE_PARAMETER_S) { static ALWAYS_INLINE void handleFuelInjectionEvent(InjectionEvent *event, int rpm DECLARE_ENGINE_PARAMETER_S) {
float fuelMs = ENGINE(fuelMs); floatms_t injectionDuration = ENGINE(fuelMs);
if (cisnan(fuelMs)) { if (cisnan(injectionDuration)) {
warning(OBD_PCM_Processor_Fault, "NaN injection pulse"); warning(OBD_PCM_Processor_Fault, "NaN injection pulse");
return; return;
} }
if (fuelMs < 0) { if (injectionDuration < 0) {
warning(OBD_PCM_Processor_Fault, "Negative injection pulse %f", fuelMs); warning(OBD_PCM_Processor_Fault, "Negative injection pulse %f", injectionDuration);
return; return;
} }
if (engine->isCylinderCleanupMode) if (engine->isCylinderCleanupMode)
return; return;
float delayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->position.angleOffset; floatus_t injectionStartDelayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->injectionStart.angleOffset;
if (event->isSimultanious) { if (event->isSimultanious) {
if (fuelMs < 0) { if (injectionDuration < 0) {
firmwareError("duration cannot be negative: %d", fuelMs); firmwareError("duration cannot be negative: %d", injectionDuration);
return; return;
} }
if (cisnan(fuelMs)) { if (cisnan(injectionDuration)) {
firmwareError("NaN in scheduleOutput", fuelMs); firmwareError("NaN in scheduleOutput", injectionDuration);
return; return;
} }
/** /**
@ -134,11 +134,11 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(InjectionEvent *event, int rp
scheduling_s * sUp = &signal->signalTimerUp[index]; scheduling_s * sUp = &signal->signalTimerUp[index];
scheduling_s * sDown = &signal->signalTimerDown[index]; scheduling_s * sDown = &signal->signalTimerDown[index];
scheduleTask("out up", sUp, (int) delayUs, (schfunc_t) &startSimultaniousInjection, engine); scheduleTask("out up", sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine);
scheduleTask("out down", sDown, (int) delayUs + MS2US(fuelMs), (schfunc_t) &endSimultaniousInjection, engine); scheduleTask("out down", sDown, (int) injectionStartDelayUs + MS2US(injectionDuration), (schfunc_t) &endSimultaniousInjection, engine);
} else { } else {
scheduleOutput(event->actuator, getTimeNowUs(), delayUs, MS2US(fuelMs)); scheduleOutput(event->actuator, getTimeNowUs(), injectionStartDelayUs, MS2US(injectionDuration));
} }
} }
@ -168,7 +168,7 @@ static ALWAYS_INLINE void handleFuel(uint32_t eventIndex, int rpm DECLARE_ENGINE
for (int i = 0; i < source->size; i++) { for (int i = 0; i < source->size; i++) {
InjectionEvent *event = &source->elements[i]; InjectionEvent *event = &source->elements[i];
if (event->position.eventIndex != eventIndex) if (event->injectionStart.eventIndex != eventIndex)
continue; continue;
handleFuelInjectionEvent(event, rpm PASS_ENGINE_PARAMETER); handleFuelInjectionEvent(event, rpm PASS_ENGINE_PARAMETER);
} }
@ -183,14 +183,14 @@ static ALWAYS_INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *i
return; return;
} }
float sparkDelayUs = engine->rpmCalculator.oneDegreeUs * iEvent->dwellPosition.angleOffset; floatus_t chargeDelayUs = engine->rpmCalculator.oneDegreeUs * iEvent->dwellPosition.angleOffset;
int isIgnitionError = sparkDelayUs < 0; int isIgnitionError = chargeDelayUs < 0;
ignitionErrorDetection.add(isIgnitionError); ignitionErrorDetection.add(isIgnitionError);
if (isIgnitionError) { if (isIgnitionError) {
#if EFI_PROD_CODE #if EFI_PROD_CODE
scheduleMsg(logger, "Negative spark delay=%f", sparkDelayUs); scheduleMsg(logger, "Negative spark delay=%f", chargeDelayUs);
#endif #endif
sparkDelayUs = 0; chargeDelayUs = 0;
return; return;
} }
@ -209,7 +209,7 @@ static ALWAYS_INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *i
/** /**
* The start of charge is always within the current trigger event range, so just plain time-based scheduling * The start of charge is always within the current trigger event range, so just plain time-based scheduling
*/ */
scheduleTask("spark up", sUp, sparkDelayUs, (schfunc_t) &turnPinHigh, iEvent->output); scheduleTask("spark up", sUp, chargeDelayUs, (schfunc_t) &turnPinHigh, iEvent->output);
/** /**
* Spark event is often happening during a later trigger event timeframe * Spark event is often happening during a later trigger event timeframe
* TODO: improve precision * TODO: improve precision

View File

@ -58,7 +58,7 @@ public:
/** /**
* This is a performance optimization: let's pre-calulate this each time RPM changes * This is a performance optimization: let's pre-calulate this each time RPM changes
*/ */
volatile float oneDegreeUs; volatile floatus_t oneDegreeUs;
volatile uint64_t lastRpmEventTimeNt; volatile uint64_t lastRpmEventTimeNt;
private: private:
/** /**

View File

@ -188,16 +188,18 @@ void testAngleResolver(void) {
ae.reset(); ae.reset();
printf("*************************************************** testAngleResolver 0\r\n"); printf("*************************************************** testAngleResolver 0\r\n");
findTriggerPosition(&ae.add()->position, 53 - 175 PASS_ENGINE_PARAMETER); findTriggerPosition(&ae.add()->injectionStart, 53 - 175 PASS_ENGINE_PARAMETER);
assertEqualsM("size", 1, ae.size); assertEqualsM("size", 1, ae.size);
assertEquals(1, ae.elements[0].position.eventIndex); // assertEquals(0, ae.elements[0].injectionStart.eventIndex);
assertEquals(3.1588, ae.elements[0].position.angleOffset); // assertEquals(53, ae.elements[0].injectionStart.angleOffset);
assertEquals(1, ae.elements[0].injectionStart.eventIndex);
assertEquals(3.1588, ae.elements[0].injectionStart.angleOffset);
printf("*************************************************** testAngleResolver 2\r\n"); printf("*************************************************** testAngleResolver 2\r\n");
ae.reset(); ae.reset();
findTriggerPosition(&ae.add()->position, 51 + 180 - 175 PASS_ENGINE_PARAMETER); findTriggerPosition(&ae.add()->injectionStart, 51 + 180 - 175 PASS_ENGINE_PARAMETER);
assertEquals(2, ae.elements[0].position.eventIndex); assertEquals(2, ae.elements[0].injectionStart.eventIndex);
assertEquals(112.3495, ae.elements[0].position.angleOffset); assertEquals(112.3495, ae.elements[0].injectionStart.angleOffset);
} }
void testPinHelper(void) { void testPinHelper(void) {