mirror of https://github.com/FOME-Tech/fome-fw.git
auto-sync
This commit is contained in:
parent
f1867644a6
commit
5b7c82b413
|
@ -41,6 +41,9 @@ public:
|
||||||
|
|
||||||
trigger_shape_s triggerShape;
|
trigger_shape_s triggerShape;
|
||||||
|
|
||||||
|
float angleExtra[IGNITION_PIN_COUNT];
|
||||||
|
io_pin_e ignitionPin[IGNITION_PIN_COUNT];
|
||||||
|
|
||||||
void onTriggerEvent(uint64_t nowNt);
|
void onTriggerEvent(uint64_t nowNt);
|
||||||
EngineState engineState;
|
EngineState engineState;
|
||||||
uint64_t lastTriggerEventTimeNt;
|
uint64_t lastTriggerEventTimeNt;
|
||||||
|
|
|
@ -90,8 +90,15 @@ void setSingleCoilDwell(engine_configuration_s *engineConfiguration) {
|
||||||
|
|
||||||
OutputSignalList injectonSignals CCM_OPTIONAL;
|
OutputSignalList injectonSignals CCM_OPTIONAL;
|
||||||
|
|
||||||
static void registerSparkEvent(IgnitionEventList *list, io_pin_e pin, float localAdvance,
|
void initializeIgnitionActions(float advance, float dwellAngle, IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) {
|
||||||
float dwell DECLARE_ENGINE_PARAMETER_S) {
|
|
||||||
|
efiAssertVoid(engineConfiguration->cylindersCount > 0, "cylindersCount");
|
||||||
|
|
||||||
|
list->resetEventList();
|
||||||
|
|
||||||
|
for (int i = 0; i < CONFIG(cylindersCount); i++) {
|
||||||
|
float localAdvance = advance + ENGINE(angleExtra[i]);
|
||||||
|
io_pin_e pin = ENGINE(ignitionPin[i]);
|
||||||
|
|
||||||
// todo efiAssertVoid(list->size)
|
// todo efiAssertVoid(list->size)
|
||||||
IgnitionEvent *event = &list->events[list->size++];
|
IgnitionEvent *event = &list->events[list->size++];
|
||||||
|
@ -101,62 +108,14 @@ static void registerSparkEvent(IgnitionEventList *list, io_pin_e pin, float loca
|
||||||
warning(OBD_PCM_Processor_Fault, "no_pin_cl #%d", (int) pin - (int) SPARKOUT_1_OUTPUT + 1);
|
warning(OBD_PCM_Processor_Fault, "no_pin_cl #%d", (int) pin - (int) SPARKOUT_1_OUTPUT + 1);
|
||||||
}
|
}
|
||||||
event->io_pin = pin;
|
event->io_pin = pin;
|
||||||
|
|
||||||
event->advance = localAdvance;
|
event->advance = localAdvance;
|
||||||
|
|
||||||
findTriggerPosition(&event->dwellPosition, localAdvance - dwell PASS_ENGINE_PARAMETER);
|
findTriggerPosition(&event->dwellPosition, localAdvance - dwellAngle
|
||||||
}
|
PASS_ENGINE_PARAMETER);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
registerSparkEvent(list, SPARKOUT_1_OUTPUT, localAdvance,
|
|
||||||
dwellAngle PASS_ENGINE_PARAMETER);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case IM_WASTED_SPARK:
|
|
||||||
for (int i = 0; i < CONFIG(cylindersCount); i++) {
|
|
||||||
float localAdvance = advance
|
|
||||||
+ (float) CONFIG(engineCycle) * i / CONFIG(cylindersCount);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuelSchedule::registerInjectionEvent(io_pin_e pin, float angle,
|
void FuelSchedule::registerInjectionEvent(io_pin_e pin, float angle, bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S) {
|
||||||
bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S) {
|
|
||||||
ActuatorEventList *list = &events;
|
ActuatorEventList *list = &events;
|
||||||
|
|
||||||
if (!isSimultanious && !isPinAssigned(pin)) {
|
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);
|
return interpolate2d(rpm, engineConfiguration->sparkDwellBins, engineConfiguration->sparkDwell, DWELL_CURVE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void findTriggerPosition(event_trigger_position_s *position,
|
static int findAngleIndex(float angleOffset DECLARE_ENGINE_PARAMETER_S) {
|
||||||
float angleOffset DECLARE_ENGINE_PARAMETER_S) {
|
|
||||||
|
|
||||||
angleOffset += CONFIG(globalTriggerAngleOffset);
|
|
||||||
fixAngle(angleOffset);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Here we rely on this to be pre-calculated, that's a performance optimization
|
* Here we rely on this to be pre-calculated, that's a performance optimization
|
||||||
*/
|
*/
|
||||||
int engineCycleEventCount = engine->engineCycleEventCount;
|
int engineCycleEventCount = engine->engineCycleEventCount;
|
||||||
|
|
||||||
efiAssertVoid(engineCycleEventCount > 0, "engineCycleEventCount");
|
efiAssert(engineCycleEventCount > 0, "engineCycleEventCount", 0);
|
||||||
|
|
||||||
uint32_t middle;
|
uint32_t middle;
|
||||||
uint32_t left = 0;
|
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
|
* Let's find the last trigger angle which is less or equal to the desired angle
|
||||||
* todo: extract binary search as template method?
|
* todo: extract binary search as template method?
|
||||||
*/
|
*/
|
||||||
float eventAngle;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
middle = (left + right) / 2;
|
middle = (left + right) / 2;
|
||||||
eventAngle = TRIGGER_SHAPE(eventAngles[middle]);
|
float eventAngle = TRIGGER_SHAPE(eventAngles[middle]);
|
||||||
|
|
||||||
if (middle == left) {
|
if (middle == left) {
|
||||||
break;
|
return middle;
|
||||||
}
|
}
|
||||||
if (angleOffset < eventAngle) {
|
if (angleOffset < eventAngle) {
|
||||||
right = middle;
|
right = middle;
|
||||||
} else if (angleOffset > eventAngle) {
|
} else if (angleOffset > eventAngle) {
|
||||||
left = middle;
|
left = middle;
|
||||||
} else {
|
} 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) {
|
if (angleOffset < eventAngle) {
|
||||||
firmwareError("angle constraint violation in registerActuatorEventExt(): %f/%f", angleOffset, eventAngle);
|
firmwareError("angle constraint violation in registerActuatorEventExt(): %f/%f", angleOffset, eventAngle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
position->eventIndex = middle;
|
position->eventIndex = index;
|
||||||
position->eventAngle = eventAngle;
|
position->eventAngle = eventAngle;
|
||||||
position->angleOffset = angleOffset - eventAngle;
|
position->angleOffset = angleOffset - eventAngle;
|
||||||
}
|
}
|
||||||
|
@ -331,6 +292,28 @@ int getCylinderId(firing_order_e firingOrder, int index) {
|
||||||
return -1;
|
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) {
|
void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
|
|
||||||
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
||||||
|
@ -338,9 +321,16 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
// todo: move this reset into decoder
|
// todo: move this reset into decoder
|
||||||
engine->triggerShape.calculateTriggerSynchPoint(engineConfiguration, engine);
|
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();
|
injectonSignals.clear();
|
||||||
engineConfiguration2->crankingInjectionEvents.addFuelEvents(
|
engineConfiguration2->crankingInjectionEvents.addFuelEvents(engineConfiguration->crankingInjectionMode
|
||||||
engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER);
|
PASS_ENGINE_PARAMETER);
|
||||||
engineConfiguration2->injectionEvents.addFuelEvents(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
|
engineConfiguration2->injectionEvents.addFuelEvents(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ typedef Thread thread_t;
|
||||||
* optimization
|
* optimization
|
||||||
*/
|
*/
|
||||||
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
|
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
|
||||||
|
#define ENGINE(x) _engine.x
|
||||||
#define TRIGGER_SHAPE(x) _engine.triggerShape.x
|
#define TRIGGER_SHAPE(x) _engine.triggerShape.x
|
||||||
|
|
||||||
#endif /* GLOBAL_H_ */
|
#endif /* GLOBAL_H_ */
|
||||||
|
|
|
@ -46,6 +46,7 @@ class Engine;
|
||||||
#define PASS_ENGINE_PARAMETER , engine, engineConfiguration
|
#define PASS_ENGINE_PARAMETER , engine, engineConfiguration
|
||||||
|
|
||||||
#define CONFIG(x) engineConfiguration->x
|
#define CONFIG(x) engineConfiguration->x
|
||||||
|
#define ENGINE(x) engine->x
|
||||||
#define TRIGGER_SHAPE(x) engine->triggerShape.x
|
#define TRIGGER_SHAPE(x) engine->triggerShape.x
|
||||||
|
|
||||||
#endif /* GLOBAL_H_ */
|
#endif /* GLOBAL_H_ */
|
||||||
|
|
Loading…
Reference in New Issue