auto-sync

This commit is contained in:
rusEfi 2014-11-25 19:03:21 -06:00
parent d99d6fe04b
commit 76ef575ad7
5 changed files with 66 additions and 70 deletions

View File

@ -41,6 +41,9 @@ public:
trigger_shape_s triggerShape;
float angleExtra[IGNITION_PIN_COUNT];
io_pin_e ignitionPin[IGNITION_PIN_COUNT];
void onTriggerEvent(uint64_t nowNt);
EngineState engineState;
uint64_t lastTriggerEventTimeNt;

View File

@ -90,73 +90,32 @@ void setSingleCoilDwell(engine_configuration_s *engineConfiguration) {
OutputSignalList injectonSignals CCM_OPTIONAL;
static void registerSparkEvent(IgnitionEventList *list, io_pin_e pin, float localAdvance,
float dwell DECLARE_ENGINE_PARAMETER_S) {
// todo efiAssertVoid(list->size)
IgnitionEvent *event = &list->events[list->size++];
if (!isPinAssigned(pin)) {
// todo: extact method for this index math
warning(OBD_PCM_Processor_Fault, "no_pin_cl #%d", (int) pin - (int) SPARKOUT_1_OUTPUT + 1);
}
event->io_pin = pin;
event->advance = localAdvance;
findTriggerPosition(&event->dwellPosition, localAdvance - dwell PASS_ENGINE_PARAMETER);
}
void initializeIgnitionActions(float advance, float dwellAngle,
IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) {
void initializeIgnitionActions(float advance, float dwellAngle, IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) {
efiAssertVoid(engineConfiguration->cylindersCount > 0, "cylindersCount");
list->resetEventList();
switch (CONFIG(ignitionMode)) {
case IM_ONE_COIL:
for (int i = 0; i < CONFIG(cylindersCount); i++) {
// todo: extract method
float localAdvance = advance
+ (float) CONFIG(engineCycle) * i / CONFIG(cylindersCount);
for (int i = 0; i < CONFIG(cylindersCount); i++) {
float localAdvance = advance + ENGINE(angleExtra[i]);
io_pin_e pin = ENGINE(ignitionPin[i]);
registerSparkEvent(list, SPARKOUT_1_OUTPUT, localAdvance,
dwellAngle PASS_ENGINE_PARAMETER);
// todo efiAssertVoid(list->size)
IgnitionEvent *event = &list->events[list->size++];
if (!isPinAssigned(pin)) {
// todo: extact method for this index math
warning(OBD_PCM_Processor_Fault, "no_pin_cl #%d", (int) pin - (int) SPARKOUT_1_OUTPUT + 1);
}
break;
case IM_WASTED_SPARK:
for (int i = 0; i < CONFIG(cylindersCount); i++) {
float localAdvance = advance
+ (float) CONFIG(engineCycle) * i / CONFIG(cylindersCount);
event->io_pin = pin;
event->advance = localAdvance;
int wastedIndex = i % (CONFIG(cylindersCount) / 2);
int id = getCylinderId(CONFIG(firingOrder), wastedIndex) - 1;
io_pin_e ioPin = (io_pin_e) (SPARKOUT_1_OUTPUT + id);
registerSparkEvent(list, ioPin, localAdvance, dwellAngle PASS_ENGINE_PARAMETER);
}
break;
case IM_INDIVIDUAL_COILS:
for (int i = 0; i < CONFIG(cylindersCount); i++) {
float localAdvance = advance
+ (float) CONFIG(engineCycle) * i / CONFIG(cylindersCount);
io_pin_e pin = (io_pin_e) ((int) SPARKOUT_1_OUTPUT + getCylinderId(CONFIG(firingOrder), i) - 1);
registerSparkEvent(list, pin, localAdvance,
dwellAngle PASS_ENGINE_PARAMETER);
}
break;
default:
firmwareError("unsupported ignitionMode %d in initializeIgnitionActions()", engineConfiguration->ignitionMode);
findTriggerPosition(&event->dwellPosition, localAdvance - dwellAngle
PASS_ENGINE_PARAMETER);
}
}
void FuelSchedule::registerInjectionEvent(io_pin_e pin, float angle,
bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S) {
void FuelSchedule::registerInjectionEvent(io_pin_e pin, float angle, bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S) {
ActuatorEventList *list = &events;
if (!isSimultanious && !isPinAssigned(pin)) {
@ -255,18 +214,13 @@ float getSparkDwellMsT(int rpm DECLARE_ENGINE_PARAMETER_S) {
return interpolate2d(rpm, engineConfiguration->sparkDwellBins, engineConfiguration->sparkDwell, DWELL_CURVE_SIZE);
}
void findTriggerPosition(event_trigger_position_s *position,
float angleOffset DECLARE_ENGINE_PARAMETER_S) {
angleOffset += CONFIG(globalTriggerAngleOffset);
fixAngle(angleOffset);
static int findAngleIndex(float angleOffset DECLARE_ENGINE_PARAMETER_S) {
/**
* Here we rely on this to be pre-calculated, that's a performance optimization
*/
int engineCycleEventCount = engine->engineCycleEventCount;
efiAssertVoid(engineCycleEventCount > 0, "engineCycleEventCount");
efiAssert(engineCycleEventCount > 0, "engineCycleEventCount", 0);
uint32_t middle;
uint32_t left = 0;
@ -276,29 +230,36 @@ void findTriggerPosition(event_trigger_position_s *position,
* Let's find the last trigger angle which is less or equal to the desired angle
* todo: extract binary search as template method?
*/
float eventAngle;
while (true) {
middle = (left + right) / 2;
eventAngle = TRIGGER_SHAPE(eventAngles[middle]);
float eventAngle = TRIGGER_SHAPE(eventAngles[middle]);
if (middle == left) {
break;
return middle;
}
if (angleOffset < eventAngle) {
right = middle;
} else if (angleOffset > eventAngle) {
left = middle;
} else {
break;
return middle;
}
}
}
void findTriggerPosition(event_trigger_position_s *position, float angleOffset DECLARE_ENGINE_PARAMETER_S) {
angleOffset += CONFIG(globalTriggerAngleOffset);
fixAngle(angleOffset);
int index = findAngleIndex(angleOffset PASS_ENGINE_PARAMETER);
float eventAngle = TRIGGER_SHAPE(eventAngles[index]);
if (angleOffset < eventAngle) {
firmwareError("angle constraint violation in registerActuatorEventExt(): %f/%f", angleOffset, eventAngle);
return;
}
position->eventIndex = middle;
position->eventIndex = index;
position->eventAngle = eventAngle;
position->angleOffset = angleOffset - eventAngle;
}
@ -331,6 +292,28 @@ int getCylinderId(firing_order_e firingOrder, int index) {
return -1;
}
io_pin_e getIgnitionPinForIndex(int i DECLARE_ENGINE_PARAMETER_S) {
switch (CONFIG(ignitionMode)) {
case IM_ONE_COIL:
return SPARKOUT_1_OUTPUT;
break;
case IM_WASTED_SPARK: {
int wastedIndex = i % (CONFIG(cylindersCount) / 2);
int id = getCylinderId(CONFIG(firingOrder), wastedIndex) - 1;
return (io_pin_e) (SPARKOUT_1_OUTPUT + id);
}
break;
case IM_INDIVIDUAL_COILS:
return (io_pin_e) ((int) SPARKOUT_1_OUTPUT + getCylinderId(CONFIG(firingOrder), i) - 1);
break;
default:
firmwareError("unsupported ignitionMode %d in initializeIgnitionActions()", engineConfiguration->ignitionMode);
return SPARKOUT_1_OUTPUT;
}
}
void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
@ -338,9 +321,16 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
// todo: move this reset into decoder
engine->triggerShape.calculateTriggerSynchPoint(engineConfiguration, engine);
for (int i = 0; i < CONFIG(cylindersCount); i++) {
ENGINE(angleExtra[i])= (float) CONFIG(engineCycle) * i / CONFIG(cylindersCount);
ENGINE(ignitionPin[i]) = getIgnitionPinForIndex(i PASS_ENGINE_PARAMETER);
}
injectonSignals.clear();
engineConfiguration2->crankingInjectionEvents.addFuelEvents(
engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER);
engineConfiguration2->crankingInjectionEvents.addFuelEvents(engineConfiguration->crankingInjectionMode
PASS_ENGINE_PARAMETER);
engineConfiguration2->injectionEvents.addFuelEvents(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
}

View File

@ -85,6 +85,7 @@ typedef Thread thread_t;
* optimization
*/
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
#define ENGINE(x) _engine.x
#define TRIGGER_SHAPE(x) _engine.triggerShape.x
#endif /* GLOBAL_H_ */

View File

@ -46,6 +46,7 @@ class Engine;
#define PASS_ENGINE_PARAMETER , engine, engineConfiguration
#define CONFIG(x) engineConfiguration->x
#define ENGINE(x) engine->x
#define TRIGGER_SHAPE(x) engine->triggerShape.x
#endif /* GLOBAL_H_ */

View File

@ -99,4 +99,5 @@ typedef EventListener event_listener_t;
#define PASS_ENGINE_PARAMETER
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
#define ENGINE(x) engine->x
#define TRIGGER_SHAPE(x) engine->triggerShape.x