auto-sync
This commit is contained in:
parent
06cc8915ef
commit
51a379a6b1
|
@ -173,10 +173,10 @@ void printState(Engine *engine, int currentCkpEventCounter) {
|
|||
debugFloat(&logger, "fuel_base", baseFuel, 2);
|
||||
// debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2);
|
||||
// debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2);
|
||||
debugFloat(&logger, "fuel_lag", getInjectorLag(engineConfiguration, getVBatt(engineConfiguration)), 2);
|
||||
debugFloat(&logger, "fuel_lag", getInjectorLag(getVBatt(engineConfiguration) PASS_ENGINE_PARAMETER), 2);
|
||||
debugFloat(&logger, "fuel", getFuelMs(rpm PASS_ENGINE_PARAMETER), 2);
|
||||
|
||||
debugFloat(&logger, "timing", getAdvance(engineConfiguration, rpm, engineLoad), 2);
|
||||
debugFloat(&logger, "timing", getAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER), 2);
|
||||
|
||||
// float map = getMap();
|
||||
|
||||
|
@ -317,16 +317,16 @@ static void showFuelInfo2(float rpm, float engineLoad, Engine *engine) {
|
|||
scheduleMsg(&logger2, "cranking fuel: %f", getCrankingFuel(engine));
|
||||
|
||||
if (engine->rpmCalculator->isRunning()) {
|
||||
float iatCorrection = getIatCorrection(engineConfiguration, getIntakeAirTemperature(engine));
|
||||
float cltCorrection = getCltCorrection(engineConfiguration, getCoolantTemperature(engine));
|
||||
float injectorLag = getInjectorLag(engineConfiguration, getVBatt(engineConfiguration));
|
||||
float iatCorrection = getIatCorrection(getIntakeAirTemperature(engine) PASS_ENGINE_PARAMETER);
|
||||
float cltCorrection = getCltCorrection(getCoolantTemperature(engine) PASS_ENGINE_PARAMETER);
|
||||
float injectorLag = getInjectorLag(getVBatt(engineConfiguration) PASS_ENGINE_PARAMETER);
|
||||
scheduleMsg(&logger2, "rpm=%f engineLoad=%f", rpm, engineLoad);
|
||||
scheduleMsg(&logger2, "baseFuel=%f", baseFuelMs);
|
||||
|
||||
scheduleMsg(&logger2, "iatCorrection=%f cltCorrection=%f injectorLag=%f", iatCorrection, cltCorrection,
|
||||
injectorLag);
|
||||
|
||||
float value = getRunningFuel(baseFuelMs, engine, (int) rpm);
|
||||
float value = getRunningFuel(baseFuelMs, (int) rpm PASS_ENGINE_PARAMETER);
|
||||
scheduleMsg(&logger2, "injection pulse width: %f", value);
|
||||
}
|
||||
}
|
||||
|
@ -452,8 +452,8 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputC
|
|||
tsOutputChannels->isIatError = !isValidIntakeAirTemperature(getIntakeAirTemperature(engine));
|
||||
#endif
|
||||
tsOutputChannels->tCharge = getTCharge(rpm, tps, coolant, intake);
|
||||
tsOutputChannels->sparkDwell = getSparkDwellMsT(engineConfiguration, rpm);
|
||||
tsOutputChannels->pulseWidthMs = getRunningFuel(baseFuelMs, engine, rpm);
|
||||
tsOutputChannels->sparkDwell = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER);
|
||||
tsOutputChannels->pulseWidthMs = getRunningFuel(baseFuelMs, rpm PASS_ENGINE_PARAMETER);
|
||||
tsOutputChannels->crankingFuelMs = getCrankingFuel(engine);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ static bool intermediateLoggingBufferInited = FALSE;
|
|||
/**
|
||||
* @returns true if data does not fit into this buffer
|
||||
*/
|
||||
static bool validateBuffer(Logging *logging, uint32_t extraLen) {
|
||||
static INLINE bool validateBuffer(Logging *logging, uint32_t extraLen) {
|
||||
if (logging->buffer == NULL) {
|
||||
firmwareError("Logging not initialized: %s", logging->name);
|
||||
return true;
|
||||
|
|
|
@ -43,7 +43,7 @@ float getBaseAdvance(int rpm, float engineLoad) {
|
|||
engineConfiguration->ignitionRpmBins);
|
||||
}
|
||||
|
||||
float getAdvance(engine_configuration_s *engineConfiguration, int rpm, float engineLoad) {
|
||||
float getAdvance(int rpm, float engineLoad DECLATE_ENGINE_PARAMETER) {
|
||||
float angle;
|
||||
if (isCrankingR(rpm)) {
|
||||
angle = engineConfiguration->crankingTimingAngle;
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
#define AD_LOAD_COUNT 16
|
||||
#define AD_RPM_COUNT 16
|
||||
|
||||
#include "engine_configuration.h"
|
||||
#include "engine.h"
|
||||
|
||||
float getAdvance(engine_configuration_s *engineConfiguration, int rpm, float engineLoad);
|
||||
float getAdvance(int rpm, float engineLoad DECLATE_ENGINE_PARAMETER);
|
||||
void prepareTimingMap(void);
|
||||
|
||||
#endif /* ADVANCE_H_ */
|
||||
|
|
|
@ -20,10 +20,10 @@ class FuelSchedule {
|
|||
public:
|
||||
ActuatorEventList events;
|
||||
|
||||
void addFuelEvents(engine_configuration_s const *e, trigger_shape_s *s,
|
||||
injection_mode_e mode);
|
||||
void registerInjectionEvent(engine_configuration_s const *e, trigger_shape_s *s,
|
||||
io_pin_e pin, float angle);
|
||||
void addFuelEvents(trigger_shape_s *s,
|
||||
injection_mode_e mode DECLATE_ENGINE_PARAMETER);
|
||||
void registerInjectionEvent(trigger_shape_s *s,
|
||||
io_pin_e pin, float angle DECLATE_ENGINE_PARAMETER);
|
||||
|
||||
};
|
||||
|
||||
|
@ -51,13 +51,10 @@ public:
|
|||
IgnitionEventList ignitionEvents[2];
|
||||
};
|
||||
|
||||
void initializeIgnitionActions(float advance, float dwellAngle, engine_configuration_s *engineConfiguration,
|
||||
engine_configuration2_s *engineConfiguration2, IgnitionEventList *list);
|
||||
void initializeIgnitionActions(float advance, float dwellAngle,
|
||||
engine_configuration2_s *engineConfiguration2, IgnitionEventList *list DECLATE_ENGINE_PARAMETER);
|
||||
|
||||
void setDefaultNonPersistentConfiguration(engine_configuration2_s *engineConfiguration2);
|
||||
void printConfiguration(engine_configuration_s *engineConfiguration, engine_configuration2_s *engineConfiguration2);
|
||||
|
||||
void registerActuatorEventExt(engine_configuration_s const *engineConfiguration, trigger_shape_s * s, ActuatorEvent *e,
|
||||
OutputSignal *actuator, float angleOffset);
|
||||
|
||||
#endif /* EC2_H_ */
|
||||
|
|
|
@ -578,8 +578,8 @@ void applyNonPersistentConfiguration(Logging * logger, Engine *engine) {
|
|||
|
||||
prepareOutputSignals(engine);
|
||||
// todo: looks like this is here only for unit tests. todo: remove
|
||||
initializeIgnitionActions(0, 0, engineConfiguration, engineConfiguration2,
|
||||
&engineConfiguration2->ignitionEvents[0]);
|
||||
initializeIgnitionActions(0, 0, engineConfiguration2,
|
||||
&engineConfiguration2->ignitionEvents[0] PASS_ENGINE_PARAMETER);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -79,17 +79,16 @@ float getFuelMs(int rpm DECLATE_ENGINE_PARAMETER) {
|
|||
theoreticalInjectionLength = getCrankingFuel(engine) / getNumberOfInjections(engineConfiguration, engineConfiguration->crankingInjectionMode);
|
||||
} else {
|
||||
float baseFuel = getBaseFuel(engine, rpm);
|
||||
float fuelPerCycle = getRunningFuel(baseFuel, engine, rpm);
|
||||
float fuelPerCycle = getRunningFuel(baseFuel, rpm PASS_ENGINE_PARAMETER);
|
||||
theoreticalInjectionLength = fuelPerCycle / getNumberOfInjections(engineConfiguration, engine->engineConfiguration->injectionMode);
|
||||
}
|
||||
float injectorLag = getInjectorLag(engineConfiguration, getVBatt(engineConfiguration));
|
||||
float injectorLag = getInjectorLag(getVBatt(engineConfiguration) PASS_ENGINE_PARAMETER);
|
||||
return theoreticalInjectionLength + injectorLag;
|
||||
}
|
||||
|
||||
float getRunningFuel(float baseFuelMs, Engine *engine, int rpm) {
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
float iatCorrection = getIatCorrection(engineConfiguration, getIntakeAirTemperature(engine));
|
||||
float cltCorrection = getCltCorrection(engineConfiguration, getCoolantTemperature(engine));
|
||||
float getRunningFuel(float baseFuelMs, int rpm DECLATE_ENGINE_PARAMETER) {
|
||||
float iatCorrection = getIatCorrection(getIntakeAirTemperature(engine) PASS_ENGINE_PARAMETER);
|
||||
float cltCorrection = getCltCorrection(getCoolantTemperature(engine) PASS_ENGINE_PARAMETER);
|
||||
|
||||
#if EFI_ACCEL_ENRICHMENT
|
||||
float accelEnrichment = getAccelEnrichment();
|
||||
|
@ -106,7 +105,7 @@ static Map3D1616 fuelMap;
|
|||
* @param vBatt Battery voltage.
|
||||
* @return Time in ms for injection opening time based on current battery voltage
|
||||
*/
|
||||
float getInjectorLag(engine_configuration_s *engineConfiguration, float vBatt) {
|
||||
float getInjectorLag(float vBatt DECLATE_ENGINE_PARAMETER) {
|
||||
if (cisnan(vBatt)) {
|
||||
warning(OBD_System_Voltage_Malfunction, "vBatt=%f", vBatt);
|
||||
return engineConfiguration->injectorLag;
|
||||
|
@ -128,13 +127,13 @@ void prepareFuelMap(engine_configuration_s *engineConfiguration) {
|
|||
/**
|
||||
* @brief Engine warm-up fuel correction.
|
||||
*/
|
||||
float getCltCorrection(engine_configuration_s *engineConfiguration, float clt) {
|
||||
float getCltCorrection(float clt DECLATE_ENGINE_PARAMETER) {
|
||||
if (cisnan(clt))
|
||||
return 1; // this error should be already reported somewhere else, let's just handle it
|
||||
return interpolate2d(clt, engineConfiguration->cltFuelCorrBins, engineConfiguration->cltFuelCorr, CLT_CURVE_SIZE);
|
||||
}
|
||||
|
||||
float getIatCorrection(engine_configuration_s *engineConfiguration, float iat) {
|
||||
float getIatCorrection(float iat DECLATE_ENGINE_PARAMETER) {
|
||||
if (cisnan(iat))
|
||||
return 1; // this error should be already reported somewhere else, let's just handle it
|
||||
return interpolate2d(iat, engineConfiguration->iatFuelCorrBins, engineConfiguration->iatFuelCorr, IAT_CURVE_SIZE);
|
||||
|
|
|
@ -14,10 +14,10 @@ void prepareFuelMap(engine_configuration_s *engineConfiguration);
|
|||
|
||||
float getBaseFuel(Engine *engine, int rpm);
|
||||
float getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm, float engineLoad);
|
||||
float getIatCorrection(engine_configuration_s *engineConfiguration, float iat);
|
||||
float getInjectorLag(engine_configuration_s *engineConfiguration, float vBatt);
|
||||
float getCltCorrection(engine_configuration_s *engineConfiguration, float clt);
|
||||
float getRunningFuel(float baseFuel, Engine *engine, int rpm);
|
||||
float getIatCorrection(float iat DECLATE_ENGINE_PARAMETER);
|
||||
float getInjectorLag(float vBatt DECLATE_ENGINE_PARAMETER);
|
||||
float getCltCorrection(float clt DECLATE_ENGINE_PARAMETER);
|
||||
float getRunningFuel(float baseFuel, int rpm DECLATE_ENGINE_PARAMETER);
|
||||
float getCrankingFuel(Engine *engine);
|
||||
float getCrankingFuel3(engine_configuration_s *engineConfiguration, float coolantTemperature, uint32_t revolutionCounterSinceStart);
|
||||
float getFuelMs(int rpm DECLATE_ENGINE_PARAMETER);
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "event_registry.h"
|
||||
#include "efiGpio.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
/*
|
||||
* default Volumetric Efficiency
|
||||
*/
|
||||
|
@ -106,8 +108,8 @@ int isCrankingRT(engine_configuration_s *engineConfiguration, int rpm) {
|
|||
OutputSignalList injectonSignals CCM_OPTIONAL
|
||||
;
|
||||
|
||||
static void registerSparkEvent(engine_configuration_s const *engineConfiguration, trigger_shape_s * s,
|
||||
IgnitionEventList *list, io_pin_e pin, float localAdvance, float dwell) {
|
||||
static void registerSparkEvent(trigger_shape_s * s,
|
||||
IgnitionEventList *list, io_pin_e pin, float localAdvance, float dwell DECLATE_ENGINE_PARAMETER) {
|
||||
|
||||
IgnitionEvent *event = list->getNextActuatorEvent();
|
||||
if (event == NULL)
|
||||
|
@ -121,11 +123,11 @@ static void registerSparkEvent(engine_configuration_s const *engineConfiguration
|
|||
|
||||
event->advance = localAdvance;
|
||||
|
||||
findTriggerPosition(engineConfiguration, s, &event->dwellPosition, localAdvance - dwell);
|
||||
findTriggerPosition(s, &event->dwellPosition, localAdvance - dwell PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
|
||||
void initializeIgnitionActions(float advance, float dwellAngle, engine_configuration_s *engineConfiguration,
|
||||
engine_configuration2_s *engineConfiguration2, IgnitionEventList *list) {
|
||||
void initializeIgnitionActions(float advance, float dwellAngle,
|
||||
engine_configuration2_s *engineConfiguration2, IgnitionEventList *list DECLATE_ENGINE_PARAMETER) {
|
||||
|
||||
efiAssertVoid(engineConfiguration->cylindersCount > 0, "cylindersCount");
|
||||
|
||||
|
@ -137,8 +139,8 @@ void initializeIgnitionActions(float advance, float dwellAngle, engine_configura
|
|||
// todo: extract method
|
||||
float localAdvance = advance + 720.0f * i / engineConfiguration->cylindersCount;
|
||||
|
||||
registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, SPARKOUT_1_OUTPUT,
|
||||
localAdvance, dwellAngle);
|
||||
registerSparkEvent(&engineConfiguration2->triggerShape, list, SPARKOUT_1_OUTPUT,
|
||||
localAdvance, dwellAngle PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
break;
|
||||
case IM_WASTED_SPARK:
|
||||
|
@ -150,8 +152,8 @@ void initializeIgnitionActions(float advance, float dwellAngle, engine_configura
|
|||
int id = getCylinderId(engineConfiguration->firingOrder, wastedIndex) - 1;
|
||||
io_pin_e ioPin = (io_pin_e) (SPARKOUT_1_OUTPUT + id);
|
||||
|
||||
registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, ioPin, localAdvance,
|
||||
dwellAngle);
|
||||
registerSparkEvent(&engineConfiguration2->triggerShape, list, ioPin, localAdvance,
|
||||
dwellAngle PASS_ENGINE_PARAMETER);
|
||||
|
||||
}
|
||||
|
||||
|
@ -161,8 +163,8 @@ void initializeIgnitionActions(float advance, float dwellAngle, engine_configura
|
|||
float localAdvance = advance + 720.0f * i / engineConfiguration->cylindersCount;
|
||||
|
||||
io_pin_e pin = (io_pin_e) ((int) SPARKOUT_1_OUTPUT + getCylinderId(engineConfiguration->firingOrder, i) - 1);
|
||||
registerSparkEvent(engineConfiguration, &engineConfiguration2->triggerShape, list, pin, localAdvance,
|
||||
dwellAngle);
|
||||
registerSparkEvent(&engineConfiguration2->triggerShape, list, pin, localAdvance,
|
||||
dwellAngle PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -171,8 +173,16 @@ void initializeIgnitionActions(float advance, float dwellAngle, engine_configura
|
|||
}
|
||||
}
|
||||
|
||||
void FuelSchedule::registerInjectionEvent(engine_configuration_s const *e, trigger_shape_s *s,
|
||||
io_pin_e pin, float angle) {
|
||||
static void registerActuatorEventExt(trigger_shape_s * s, ActuatorEvent *ev,
|
||||
OutputSignal *actuator, float angle DECLATE_ENGINE_PARAMETER) {
|
||||
|
||||
|
||||
findTriggerPosition(s, &ev->position, angle PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
|
||||
|
||||
void FuelSchedule::registerInjectionEvent(trigger_shape_s *s,
|
||||
io_pin_e pin, float angle DECLATE_ENGINE_PARAMETER) {
|
||||
ActuatorEventList *list = &events;
|
||||
|
||||
if (!isPinAssigned(pin)) {
|
||||
|
@ -191,47 +201,47 @@ void FuelSchedule::registerInjectionEvent(engine_configuration_s const *e, trigg
|
|||
}
|
||||
ev->actuator = actuator;
|
||||
|
||||
registerActuatorEventExt(e, s, ev, actuator, angle);
|
||||
registerActuatorEventExt(s, ev, actuator, angle PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
|
||||
void FuelSchedule::addFuelEvents(engine_configuration_s const *e, trigger_shape_s *s,
|
||||
injection_mode_e mode) {
|
||||
void FuelSchedule::addFuelEvents(trigger_shape_s *s,
|
||||
injection_mode_e mode DECLATE_ENGINE_PARAMETER) {
|
||||
ActuatorEventList *list = &events;
|
||||
;
|
||||
list->resetEventList();
|
||||
|
||||
float baseAngle = e->globalTriggerAngleOffset + e->injectionOffset;
|
||||
float baseAngle = engineConfiguration->globalTriggerAngleOffset + engineConfiguration->injectionOffset;
|
||||
|
||||
switch (mode) {
|
||||
case IM_SEQUENTIAL:
|
||||
for (int i = 0; i < e->cylindersCount; i++) {
|
||||
io_pin_e pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + getCylinderId(e->firingOrder, i) - 1);
|
||||
float angle = baseAngle + i * 720.0 / e->cylindersCount;
|
||||
registerInjectionEvent(e, s, pin, angle);
|
||||
for (int i = 0; i < engineConfiguration->cylindersCount; i++) {
|
||||
io_pin_e pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + getCylinderId(engineConfiguration->firingOrder, i) - 1);
|
||||
float angle = baseAngle + i * 720.0 / engineConfiguration->cylindersCount;
|
||||
registerInjectionEvent(s, pin, angle PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
break;
|
||||
case IM_SIMULTANEOUS:
|
||||
for (int i = 0; i < e->cylindersCount; i++) {
|
||||
float angle = baseAngle + i * 720.0 / e->cylindersCount;
|
||||
for (int i = 0; i < engineConfiguration->cylindersCount; i++) {
|
||||
float angle = baseAngle + i * 720.0 / engineConfiguration->cylindersCount;
|
||||
|
||||
for (int j = 0; j < e->cylindersCount; j++) {
|
||||
for (int j = 0; j < engineConfiguration->cylindersCount; j++) {
|
||||
io_pin_e pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + j);
|
||||
registerInjectionEvent(e, s, pin, angle);
|
||||
registerInjectionEvent(s, pin, angle PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IM_BATCH:
|
||||
for (int i = 0; i < e->cylindersCount; i++) {
|
||||
int index = i % (e->cylindersCount / 2);
|
||||
for (int i = 0; i < engineConfiguration->cylindersCount; i++) {
|
||||
int index = i % (engineConfiguration->cylindersCount / 2);
|
||||
io_pin_e pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + index);
|
||||
float angle = baseAngle + i * 720.0 / e->cylindersCount;
|
||||
registerInjectionEvent(e, s, pin, angle);
|
||||
float angle = baseAngle + i * 720.0 / engineConfiguration->cylindersCount;
|
||||
registerInjectionEvent(s, pin, angle PASS_ENGINE_PARAMETER);
|
||||
|
||||
/**
|
||||
* also fire the 2nd half of the injectors so that we can implement a batch mode on individual wires
|
||||
*/
|
||||
pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + index + (e->cylindersCount / 2));
|
||||
registerInjectionEvent(e, s, pin, angle);
|
||||
pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + index + (engineConfiguration->cylindersCount / 2));
|
||||
registerInjectionEvent(s, pin, angle PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -242,7 +252,7 @@ void FuelSchedule::addFuelEvents(engine_configuration_s const *e, trigger_shape_
|
|||
/**
|
||||
* @return Spark dwell time, in milliseconds.
|
||||
*/
|
||||
float getSparkDwellMsT(engine_configuration_s *engineConfiguration, int rpm) {
|
||||
float getSparkDwellMsT(int rpm DECLATE_ENGINE_PARAMETER) {
|
||||
if (isCrankingR(rpm)) {
|
||||
if(engineConfiguration->useConstantDwellDuringCranking) {
|
||||
return engineConfiguration->ignitionDwellForCrankingMs;
|
||||
|
@ -269,8 +279,8 @@ int getEngineCycleEventCount(engine_configuration_s const *engineConfiguration,
|
|||
return getEngineCycleEventCount2(getOperationMode(engineConfiguration), s);
|
||||
}
|
||||
|
||||
void findTriggerPosition(engine_configuration_s const *engineConfiguration, trigger_shape_s * s,
|
||||
event_trigger_position_s *position, float angleOffset) {
|
||||
void findTriggerPosition(trigger_shape_s * s,
|
||||
event_trigger_position_s *position, float angleOffset DECLATE_ENGINE_PARAMETER) {
|
||||
|
||||
angleOffset = fixAngle(engineConfiguration, angleOffset + engineConfiguration->globalTriggerAngleOffset);
|
||||
|
||||
|
@ -315,13 +325,6 @@ void findTriggerPosition(engine_configuration_s const *engineConfiguration, trig
|
|||
position->angleOffset = angleOffset - eventAngle;
|
||||
}
|
||||
|
||||
void registerActuatorEventExt(engine_configuration_s const *e, trigger_shape_s * s, ActuatorEvent *ev,
|
||||
OutputSignal *actuator, float angle) {
|
||||
|
||||
|
||||
findTriggerPosition(e, s, &ev->position, angle);
|
||||
}
|
||||
|
||||
static int order_1_THEN_3_THEN_4_THEN2[] = { 1, 3, 4, 2 };
|
||||
|
||||
static int order_1_THEN_5_THEN_3_THEN_6_THEN_2_THEN_4[] = { 1, 5, 3, 6, 2, 4 };
|
||||
|
@ -361,10 +364,10 @@ engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
|||
trigger_shape_s * ts = &engineConfiguration2->triggerShape;
|
||||
|
||||
injectonSignals.clear();
|
||||
engineConfiguration2->crankingInjectionEvents.addFuelEvents(engineConfiguration, ts,
|
||||
engineConfiguration->crankingInjectionMode);
|
||||
engineConfiguration2->injectionEvents.addFuelEvents(engineConfiguration, ts,
|
||||
engineConfiguration->injectionMode);
|
||||
engineConfiguration2->crankingInjectionEvents.addFuelEvents(ts,
|
||||
engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER);
|
||||
engineConfiguration2->injectionEvents.addFuelEvents(ts,
|
||||
engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
|
||||
void setFuelRpmBin(engine_configuration_s *engineConfiguration, float l, float r) {
|
||||
|
|
|
@ -11,13 +11,14 @@
|
|||
#include "engine_configuration.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "ec2.h"
|
||||
#include "trigger_structure.h"
|
||||
#include "table_helper.h"
|
||||
#include "engine.h"
|
||||
|
||||
void findTriggerPosition(engine_configuration_s const *engineConfiguration, trigger_shape_s * s,
|
||||
event_trigger_position_s *position, float angleOffset);
|
||||
void findTriggerPosition(trigger_shape_s * s,
|
||||
event_trigger_position_s *position, float angleOffset DECLATE_ENGINE_PARAMETER);
|
||||
|
||||
int isInjectionEnabled(engine_configuration_s *engineConfiguration);
|
||||
|
||||
|
@ -56,7 +57,7 @@ int isCrankingRT(engine_configuration_s *engineConfiguration, int rpm);
|
|||
float getEngineLoadT(Engine *engine);
|
||||
#define getEngineLoad() getEngineLoadT(engine)
|
||||
|
||||
float getSparkDwellMsT(engine_configuration_s *engineConfiguration, int rpm);
|
||||
float getSparkDwellMsT(int rpm DECLATE_ENGINE_PARAMETER);
|
||||
|
||||
int getCylinderId(firing_order_e firingOrder, int index);
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ void EventQueue::insertTask(scheduling_s *scheduling, uint64_t timeUs, schfunc_t
|
|||
firmwareError("NULL callback");
|
||||
|
||||
int alreadyPending = checkIfPending(scheduling);
|
||||
if (alreadyPending || hasFirmwareError())
|
||||
if (alreadyPending)
|
||||
return;
|
||||
|
||||
scheduling->momentUs = timeUs;
|
||||
|
|
|
@ -81,8 +81,7 @@ static INLINE void handleFuelInjectionEvent(ActuatorEvent *event, int rpm DECLAT
|
|||
/**
|
||||
* todo: we do not really need to calculate fuel for each individual cylinder
|
||||
*/
|
||||
float fuelMs = getFuelMs(rpm PASS_ENGINE_PARAMETER)
|
||||
* engineConfiguration->globalFuelCorrection;
|
||||
float fuelMs = getFuelMs(rpm PASS_ENGINE_PARAMETER) * engineConfiguration->globalFuelCorrection;
|
||||
if (cisnan(fuelMs)) {
|
||||
warning(OBD_PCM_Processor_Fault, "NaN injection pulse");
|
||||
return;
|
||||
|
@ -132,7 +131,7 @@ static INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *iEvent,
|
|||
int rpm DECLATE_ENGINE_PARAMETER) {
|
||||
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
||||
|
||||
float dwellMs = getSparkDwellMsT(engineConfiguration, rpm);
|
||||
float dwellMs = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER);
|
||||
if (cisnan(dwellMs) || dwellMs < 0) {
|
||||
firmwareError("invalid dwell: %f at %d", dwellMs, rpm);
|
||||
return;
|
||||
|
@ -170,8 +169,8 @@ static INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *iEvent,
|
|||
* TODO: improve precision
|
||||
*/
|
||||
|
||||
findTriggerPosition(engineConfiguration, &engineConfiguration2->triggerShape, &iEvent->sparkPosition,
|
||||
iEvent->advance);
|
||||
findTriggerPosition(&engineConfiguration2->triggerShape, &iEvent->sparkPosition,
|
||||
iEvent->advance PASS_ENGINE_PARAMETER);
|
||||
|
||||
if (iEvent->sparkPosition.eventIndex == eventIndex) {
|
||||
/**
|
||||
|
@ -240,12 +239,23 @@ void showMainHistogram(void) {
|
|||
* Both injection and ignition are controlled from this method.
|
||||
*/
|
||||
void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTriggerCallback *mtc) {
|
||||
if(hasFirmwareError()) {
|
||||
/**
|
||||
* In case on a major error we should not process any more events.
|
||||
* TODO: add 'pin shutdown' invocation somewhere
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
Engine *engine = mtc->engine;
|
||||
(void) ckpSignalType;
|
||||
efiAssertVoid(eventIndex < 2 * engine->engineConfiguration2->triggerShape.shaftPositionEventCount,
|
||||
"event index");
|
||||
efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#2");
|
||||
|
||||
// todo: remove these local variables soon?
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
|
||||
int rpm = getRpmE(engine);
|
||||
if (rpm == 0) {
|
||||
// this happens while we just start cranking
|
||||
|
@ -283,12 +293,12 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
|
|||
* Within one engine cycle all cylinders are fired with same timing advance.
|
||||
* todo: one day we can control cylinders individually
|
||||
*/
|
||||
float dwellMs = getSparkDwellMsT(engine->engineConfiguration, rpm);
|
||||
float dwellMs = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER);
|
||||
if (cisnan(dwellMs) || dwellMs < 0) {
|
||||
firmwareError("invalid dwell: %f at %d", dwellMs, rpm);
|
||||
return;
|
||||
}
|
||||
float advance = getAdvance(engine->engineConfiguration, rpm, getEngineLoadT(engine));
|
||||
float advance = getAdvance(rpm, getEngineLoadT(engine) PASS_ENGINE_PARAMETER);
|
||||
if (cisnan(advance)) {
|
||||
// error should already be reported
|
||||
return;
|
||||
|
@ -296,17 +306,13 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
|
|||
|
||||
float dwellAngle = dwellMs / getOneDegreeTimeMs(rpm);
|
||||
|
||||
initializeIgnitionActions(advance, dwellAngle, engine->engineConfiguration,
|
||||
initializeIgnitionActions(advance, dwellAngle,
|
||||
engine->engineConfiguration2,
|
||||
&engine->engineConfiguration2->ignitionEvents[revolutionIndex]);
|
||||
&engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
|
||||
triggerEventsQueue.executeAll(getCrankEventCounter());
|
||||
|
||||
// todo: remove these local variables soon
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
|
||||
|
||||
handleFuel(eventIndex, rpm PASS_ENGINE_PARAMETER);
|
||||
handleSpark(eventIndex, rpm,
|
||||
&engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER);
|
||||
|
@ -338,7 +344,7 @@ static void showMainInfo(Engine *engine) {
|
|||
#if EFI_PROD_CODE
|
||||
scheduleMsg(&logger, "rpm %d engine_load %f", rpm, el);
|
||||
scheduleMsg(&logger, "fuel %fms timing %f", getFuelMs(rpm PASS_ENGINE_PARAMETER),
|
||||
getAdvance(mainTriggerCallbackInstance.engine->engineConfiguration, rpm, el));
|
||||
getAdvance(rpm, el PASS_ENGINE_PARAMETER));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -230,6 +230,7 @@ void chDbgStackOverflowPanic(Thread *otp) {
|
|||
chDbgPanic3(panicMessage, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
// todo: make this a macro, noone can trust these compilers
|
||||
bool hasFirmwareError(void) {
|
||||
return hasFirmwareErrorFlag;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,10 @@ typedef void * Logging;
|
|||
|
||||
#define EXTERN_ENGINE
|
||||
|
||||
#ifdef __cplusplus
|
||||
class Engine;
|
||||
#endif
|
||||
|
||||
#define DECLATE_ENGINE_PARAMETER , Engine *engine, engine_configuration_s *engineConfiguration
|
||||
#define PASS_ENGINE_PARAMETER , engine, engineConfiguration
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* test_find_index.c
|
||||
* test_find_index.cpp
|
||||
*
|
||||
* Created on: Oct 30, 2013
|
||||
* Author: Andrey Belomutskiy, (c) 2012-2013
|
||||
*/
|
||||
|
||||
#include "engine_math.h"
|
||||
#include "main.h"
|
||||
#include "engine_math.h"
|
||||
#include "interpolation.h"
|
||||
#include <stdio.h>
|
||||
#include "engine_configuration.h"
|
||||
|
|
|
@ -151,6 +151,8 @@ static ActuatorEventList ae;
|
|||
void testAngleResolver(void) {
|
||||
printf("*************************************************** testAngleResolver\r\n");
|
||||
|
||||
Engine *engine = NULL;
|
||||
|
||||
engineConfiguration->globalTriggerAngleOffset = 175;
|
||||
trigger_shape_s * ts = &engineConfiguration2->triggerShape;
|
||||
|
||||
|
@ -171,15 +173,14 @@ void testAngleResolver(void) {
|
|||
|
||||
ae.resetEventList();
|
||||
printf("*************************************************** testAngleResolver 0\r\n");
|
||||
registerActuatorEventExt(engineConfiguration, &engineConfiguration2->triggerShape, ae.getNextActuatorEvent(), list.add(INJECTOR_1_OUTPUT), 53 - 175);
|
||||
findTriggerPosition(&engineConfiguration2->triggerShape, &ae.getNextActuatorEvent()->position, 53 - 175 PASS_ENGINE_PARAMETER);
|
||||
assertEqualsM("size", 1, ae.size);
|
||||
assertEquals(1, list.getSize());
|
||||
assertEquals(0, ae.events[0].position.eventIndex);
|
||||
assertEquals(53, ae.events[0].position.angleOffset);
|
||||
|
||||
printf("*************************************************** testAngleResolver 2\r\n");
|
||||
ae.resetEventList();
|
||||
registerActuatorEventExt(engineConfiguration, &engineConfiguration2->triggerShape, ae.getNextActuatorEvent(), list.add(INJECTOR_1_OUTPUT), 51 + 180 - 175);
|
||||
findTriggerPosition(&engineConfiguration2->triggerShape, &ae.getNextActuatorEvent()->position, 51 + 180 - 175 PASS_ENGINE_PARAMETER);
|
||||
assertEquals(2, ae.events[0].position.eventIndex);
|
||||
assertEquals(109.1, ae.events[0].position.angleOffset);
|
||||
}
|
||||
|
|
|
@ -118,21 +118,22 @@ static void test1995FordInline6TriggerDecoder(void) {
|
|||
|
||||
EngineTestHelper eth(FORD_INLINE_6_1995);
|
||||
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
engine_configuration_s *engineConfiguration = eth.engine.engineConfiguration;
|
||||
Engine *engine = ð.engine;
|
||||
|
||||
resetConfigurationExt(NULL, FORD_INLINE_6_1995, ð.engine);
|
||||
assertEqualsM("triggerShapeSynchPointIndex", 0, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
trigger_shape_s * shape = ð.ec2.triggerShape;
|
||||
event_trigger_position_s position;
|
||||
assertEqualsM("globalTriggerAngleOffset", 0, ec->globalTriggerAngleOffset);
|
||||
findTriggerPosition(ec, shape, &position, 0);
|
||||
assertEqualsM("globalTriggerAngleOffset", 0, engineConfiguration->globalTriggerAngleOffset);
|
||||
findTriggerPosition(shape, &position, 0 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 200);
|
||||
findTriggerPosition(shape, &position, 200 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 3, 20);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 360);
|
||||
findTriggerPosition(shape, &position, 360 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 6, 0);
|
||||
|
||||
|
||||
|
@ -148,31 +149,31 @@ static void test1995FordInline6TriggerDecoder(void) {
|
|||
|
||||
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
int r = 10;
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r);
|
||||
state.decodeTriggerEvent(shape, &engineConfiguration->triggerConfig, SHAFT_PRIMARY_DOWN, r);
|
||||
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, ++r);
|
||||
state.decodeTriggerEvent(shape, &engineConfiguration->triggerConfig, SHAFT_PRIMARY_UP, ++r);
|
||||
assertTrue(state.shaft_is_synchronized); // first signal rise synchronize
|
||||
assertEquals(0, state.getCurrentIndex());
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
|
||||
state.decodeTriggerEvent(shape, &engineConfiguration->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
|
||||
assertEquals(1, state.getCurrentIndex());
|
||||
|
||||
for (int i = 2; i < 10;) {
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r++);
|
||||
state.decodeTriggerEvent(shape, &engineConfiguration->triggerConfig, SHAFT_PRIMARY_UP, r++);
|
||||
assertEqualsM("even", i++, state.getCurrentIndex());
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
|
||||
state.decodeTriggerEvent(shape, &engineConfiguration->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
|
||||
assertEqualsM("odd", i++, state.getCurrentIndex());
|
||||
}
|
||||
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r++);
|
||||
state.decodeTriggerEvent(shape, &engineConfiguration->triggerConfig, SHAFT_PRIMARY_UP, r++);
|
||||
assertEquals(10, state.getCurrentIndex());
|
||||
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
|
||||
state.decodeTriggerEvent(shape, &engineConfiguration->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
|
||||
assertEquals(11, state.getCurrentIndex());
|
||||
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r++);
|
||||
state.decodeTriggerEvent(shape, &engineConfiguration->triggerConfig, SHAFT_PRIMARY_UP, r++);
|
||||
assertEquals(0, state.getCurrentIndex()); // new revolution
|
||||
|
||||
assertEqualsM("running dwell", 0.5, getSparkDwellMsT(ec, 2000));
|
||||
assertEqualsM("running dwell", 0.5, getSparkDwellMsT(2000 PASS_ENGINE_PARAMETER));
|
||||
}
|
||||
|
||||
void testFordAspire(void) {
|
||||
|
@ -182,20 +183,21 @@ void testFordAspire(void) {
|
|||
|
||||
EngineTestHelper eth(FORD_ASPIRE_1996);
|
||||
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
resetConfigurationExt(NULL, FORD_ASPIRE_1996, ð.engine);
|
||||
Engine *engine = ð.engine;
|
||||
engine_configuration_s *engineConfiguration = eth.ec;
|
||||
resetConfigurationExt(NULL, FORD_ASPIRE_1996, engine);
|
||||
assertEquals(4, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
assertEquals(800, ec->fuelRpmBins[0]);
|
||||
assertEquals(7000, ec->fuelRpmBins[15]);
|
||||
assertEquals(800, engineConfiguration->fuelRpmBins[0]);
|
||||
assertEquals(7000, engineConfiguration->fuelRpmBins[15]);
|
||||
|
||||
ec->crankingChargeAngle = 65;
|
||||
ec->crankingTimingAngle = 31;
|
||||
engineConfiguration->crankingChargeAngle = 65;
|
||||
engineConfiguration->crankingTimingAngle = 31;
|
||||
|
||||
assertEqualsM("cranking dwell", 54.166670, getSparkDwellMsT(ec, 200));
|
||||
assertEqualsM("running dwell", 4, getSparkDwellMsT(ec, 2000));
|
||||
assertEqualsM("cranking dwell", 54.166670, getSparkDwellMsT(200 PASS_ENGINE_PARAMETER));
|
||||
assertEqualsM("running dwell", 4, getSparkDwellMsT(2000 PASS_ENGINE_PARAMETER));
|
||||
|
||||
assertEqualsM("higher rpm dwell", 3.25, getSparkDwellMsT(ec, 6000));
|
||||
assertEqualsM("higher rpm dwell", 3.25, getSparkDwellMsT(6000 PASS_ENGINE_PARAMETER));
|
||||
}
|
||||
|
||||
void testMazda323(void) {
|
||||
|
@ -213,6 +215,8 @@ void testMazdaMianaNbDecoder(void) {
|
|||
|
||||
EngineTestHelper eth(MAZDA_MIATA_NB);
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
Engine *engine = ð.engine;
|
||||
engine_configuration_s *engineConfiguration = ec;
|
||||
resetConfigurationExt(NULL, MAZDA_MIATA_NB, ð.engine);
|
||||
assertEquals(11, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
|
@ -256,39 +260,39 @@ void testMazdaMianaNbDecoder(void) {
|
|||
|
||||
event_trigger_position_s position;
|
||||
assertEqualsM("globalTriggerAngleOffset", 276, ec->globalTriggerAngleOffset);
|
||||
findTriggerPosition(ec, shape, &position, 0);
|
||||
findTriggerPosition(shape, &position, 0 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 7, 46);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 180);
|
||||
findTriggerPosition(shape, &position, 180 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 13, 46);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 360);
|
||||
findTriggerPosition(shape, &position, 360 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 17, 46);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 444);
|
||||
findTriggerPosition(shape, &position, 444 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 444.1);
|
||||
findTriggerPosition(shape, &position, 444.1 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0.1);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 445);
|
||||
findTriggerPosition(shape, &position, 445 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 1);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 494);
|
||||
findTriggerPosition(shape, &position, 494 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 3, 0);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, 719);
|
||||
findTriggerPosition(shape, &position, 719 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 7, 45);
|
||||
|
||||
ec->globalTriggerAngleOffset = 0;
|
||||
findTriggerPosition(ec, shape, &position, 0);
|
||||
findTriggerPosition(shape, &position, 0 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0);
|
||||
|
||||
ec->globalTriggerAngleOffset = 10;
|
||||
findTriggerPosition(ec, shape, &position, 0);
|
||||
findTriggerPosition(shape, &position, 0 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 10);
|
||||
|
||||
findTriggerPosition(ec, shape, &position, -10);
|
||||
findTriggerPosition(shape, &position, -10 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue