auto-sync
This commit is contained in:
parent
2d87e53d12
commit
7d5ff83aed
|
@ -59,20 +59,11 @@ typedef struct {
|
|||
engine_configuration2_s *engineConfiguration2;
|
||||
} configuration_s;
|
||||
|
||||
void prepareOutputSignals(engine_configuration_s *engineConfiguration,
|
||||
engine_configuration2_s *engineConfiguration2);
|
||||
|
||||
void initializeIgnitionActions(float advance, float dwellAngle, engine_configuration_s *engineConfiguration, engine_configuration2_s *engineConfiguration2, IgnitionEventList *list);
|
||||
void addFuelEvents(engine_configuration_s const *e, engine_configuration2_s *engineConfiguration2, ActuatorEventList *list, injection_mode_e mode);
|
||||
|
||||
void registerActuatorEventExt(engine_configuration_s const *engineConfiguration, trigger_shape_s * s, ActuatorEvent *e, OutputSignal *actuator, float angleOffset);
|
||||
|
||||
void resetConfigurationExt(Logging * logger, engine_type_e engineType,
|
||||
engine_configuration_s *engineConfiguration,
|
||||
engine_configuration2_s *engineConfiguration2);
|
||||
void applyNonPersistentConfiguration(Logging * logger, engine_configuration_s *engineConfiguration,
|
||||
engine_configuration2_s *engineConfiguration2);
|
||||
|
||||
void setDefaultNonPersistentConfiguration(engine_configuration2_s *engineConfiguration2);
|
||||
void printConfiguration(engine_configuration_s *engineConfiguration, engine_configuration2_s *engineConfiguration2);
|
||||
|
||||
|
|
|
@ -79,4 +79,9 @@ private:
|
|||
void setPumpsCounter(engine_configuration_s *engineConfiguration, int newValue);
|
||||
};
|
||||
|
||||
void resetConfigurationExt(Logging * logger, engine_type_e engineType,
|
||||
Engine *engine);
|
||||
void applyNonPersistentConfiguration(Logging * logger, Engine *engine);
|
||||
void prepareOutputSignals(Engine *engine);
|
||||
|
||||
#endif /* ENGINE_H_ */
|
||||
|
|
|
@ -403,8 +403,9 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_
|
|||
boardConfiguration->isEngineControlEnabled = true;
|
||||
}
|
||||
|
||||
void resetConfigurationExt(Logging * logger, engine_type_e engineType, engine_configuration_s *engineConfiguration,
|
||||
engine_configuration2_s *engineConfiguration2) {
|
||||
void resetConfigurationExt(Logging * logger, engine_type_e engineType, Engine *engine) {
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
||||
board_configuration_s *boardConfiguration = &engineConfiguration->bc;
|
||||
/**
|
||||
* Let's apply global defaults first
|
||||
|
@ -503,7 +504,7 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType, engine_co
|
|||
firmwareError("Unexpected engine type: %d", engineType);
|
||||
|
||||
}
|
||||
applyNonPersistentConfiguration(logger, engineConfiguration, engineConfiguration2);
|
||||
applyNonPersistentConfiguration(logger, engine);
|
||||
|
||||
#if EFI_TUNER_STUDIO
|
||||
syncTunerStudioCopy();
|
||||
|
@ -514,8 +515,9 @@ engine_configuration2_s::engine_configuration2_s() {
|
|||
engineConfiguration = NULL;
|
||||
}
|
||||
|
||||
void applyNonPersistentConfiguration(Logging * logger, engine_configuration_s *engineConfiguration,
|
||||
engine_configuration2_s *engineConfiguration2) {
|
||||
void applyNonPersistentConfiguration(Logging * logger, Engine *engine) {
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
||||
// todo: this would require 'initThermistors() to re-establish a reference, todo: fix
|
||||
// memset(engineConfiguration2, 0, sizeof(engine_configuration2_s));
|
||||
#if EFI_PROD_CODE
|
||||
|
@ -531,7 +533,7 @@ void applyNonPersistentConfiguration(Logging * logger, engine_configuration_s *e
|
|||
return;
|
||||
}
|
||||
|
||||
prepareOutputSignals(engineConfiguration, engineConfiguration2);
|
||||
prepareOutputSignals(engine);
|
||||
// todo: looks like this is here only for unit tests. todo: remove
|
||||
initializeIgnitionActions(0, 0, engineConfiguration, engineConfiguration2,
|
||||
&engineConfiguration2->engineEventConfiguration.ignitionEvents[0]);
|
||||
|
|
|
@ -19,12 +19,13 @@
|
|||
|
||||
#include "datalogging.h"
|
||||
|
||||
#include "ec2.h"
|
||||
#include "engine.h"
|
||||
|
||||
#define DEFAULT_ENGINE_TYPE FORD_ASPIRE_1996
|
||||
|
||||
static bool needToWriteConfiguration = false;
|
||||
|
||||
extern Engine engine;
|
||||
static Logging logger;
|
||||
|
||||
extern persistent_config_container_s persistentState;
|
||||
|
@ -87,7 +88,7 @@ static bool isValidCrc(persistent_config_container_s *state) {
|
|||
}
|
||||
|
||||
static void doResetConfiguration(void) {
|
||||
resetConfigurationExt(&logger, engineConfiguration->engineType, engineConfiguration, engineConfiguration2);
|
||||
resetConfigurationExt(&logger, engineConfiguration->engineType, &engine);
|
||||
}
|
||||
|
||||
static bool hasValidEngineType(engine_configuration_s *engineConfiguration) {
|
||||
|
@ -101,16 +102,16 @@ void readFromFlash(void) {
|
|||
|
||||
if (!isValidCrc(&persistentState)) {
|
||||
printMsg(&logger, "Need to reset flash to default due to CRC");
|
||||
resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, engineConfiguration, engineConfiguration2);
|
||||
resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, &engine);
|
||||
} else if (persistentState.version == FLASH_DATA_VERSION && persistentState.size == PERSISTENT_SIZE) {
|
||||
printMsg(&logger, "Got valid configuration from flash!");
|
||||
applyNonPersistentConfiguration(&logger, engineConfiguration, engineConfiguration2);
|
||||
applyNonPersistentConfiguration(&logger, &engine);
|
||||
} else if (hasValidEngineType(engineConfiguration)) {
|
||||
printMsg(&logger, "Resetting but saving engine type [%d]", engineConfiguration->engineType);
|
||||
resetConfigurationExt(&logger, engineConfiguration->engineType, engineConfiguration, engineConfiguration2);
|
||||
resetConfigurationExt(&logger, engineConfiguration->engineType, &engine);
|
||||
} else {
|
||||
printMsg(&logger, "Need to reset flash to default due to version change");
|
||||
resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, engineConfiguration, engineConfiguration2);
|
||||
resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, &engine);
|
||||
}
|
||||
// we can only change the state after the CRC check
|
||||
engineConfiguration->firmwareVersion = getRusEfiVersion();
|
||||
|
|
|
@ -339,7 +339,10 @@ int getCylinderId(firing_order_e firingOrder, int index) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
void prepareOutputSignals(engine_configuration_s *engineConfiguration, engine_configuration2_s *engineConfiguration2) {
|
||||
void prepareOutputSignals(Engine *engine) {
|
||||
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
||||
|
||||
// todo: move this reset into decoder
|
||||
engineConfiguration2->triggerShape.calculateTriggerSynchPoint(&engineConfiguration->triggerConfig);
|
||||
|
|
|
@ -109,8 +109,8 @@ bool isValidIntakeAirTemperature(float temperature) {
|
|||
float getCoolantTemperature(Engine * engine) {
|
||||
float temperature = getTemperatureC(&engine->clt);
|
||||
if (!isValidCoolantTemperature(temperature)) {
|
||||
efiAssert(engineConfiguration2->engineConfiguration!=NULL, "NULL engineConfiguration", NAN);
|
||||
if (engineConfiguration2->engineConfiguration->hasCltSensor) {
|
||||
efiAssert(engine->engineConfiguration!=NULL, "NULL engineConfiguration", NAN);
|
||||
if (engine->engineConfiguration->hasCltSensor) {
|
||||
warning(OBD_PCM_Processor_Fault, "unrealistic CLT %f", temperature);
|
||||
}
|
||||
return LIMPING_MODE_CLT_TEMPERATURE;
|
||||
|
|
|
@ -198,7 +198,7 @@ static void setIdleMode(int mode) {
|
|||
|
||||
void setEngineType(int value) {
|
||||
engineConfiguration->engineType = (engine_type_e) value;
|
||||
resetConfigurationExt(&logger, (engine_type_e) value, engineConfiguration, engineConfiguration2);
|
||||
resetConfigurationExt(&logger, (engine_type_e) value, &engine);
|
||||
#if EFI_INTERNAL_FLASH
|
||||
writeToFlash();
|
||||
// scheduleReset();
|
||||
|
|
|
@ -267,7 +267,7 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
|
|||
|
||||
if (eventIndex == 0) {
|
||||
if (localVersion.isOld())
|
||||
prepareOutputSignals(mainTriggerCallback->engineConfiguration, mainTriggerCallback->engineConfiguration2);
|
||||
prepareOutputSignals(mainTriggerCallback->engine);
|
||||
|
||||
/**
|
||||
* TODO: warning. there is a bit of a hack here, todo: improve.
|
||||
|
|
|
@ -70,6 +70,8 @@ static bool isEmulating = true;
|
|||
static Logging logger;
|
||||
static LocalVersionHolder localVersion;
|
||||
|
||||
extern Engine engine;
|
||||
|
||||
void setTriggerEmulatorRPM(int rpm) {
|
||||
engineConfiguration->bc.triggerSimulatorFrequency = rpm;
|
||||
/**
|
||||
|
@ -90,7 +92,7 @@ static void updateTriggerShapeIfNeeded(PwmConfig *state) {
|
|||
scheduleMsg(&logger, "Stimulator: updating trigger shape: %d/%d %d", localVersion.getVersion(),
|
||||
getGlobalConfigurationVersion(), currentTimeMillis());
|
||||
|
||||
applyNonPersistentConfiguration(&logger, engineConfiguration, engineConfiguration2);
|
||||
applyNonPersistentConfiguration(&logger, &engine);
|
||||
|
||||
trigger_shape_s *s = &engineConfiguration2->triggerShape;
|
||||
int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates,
|
||||
|
|
|
@ -180,7 +180,7 @@ void initHardware(Logging *logger, Engine *engine) {
|
|||
*/
|
||||
if (SHOULD_INGORE_FLASH()) {
|
||||
engineConfiguration->engineType = FORD_ASPIRE_1996;
|
||||
resetConfigurationExt(logger, engineConfiguration->engineType, engineConfiguration, engineConfiguration2);
|
||||
resetConfigurationExt(logger, engineConfiguration->engineType, engine);
|
||||
writeToFlash();
|
||||
} else {
|
||||
readFromFlash();
|
||||
|
|
|
@ -28,7 +28,7 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) {
|
|||
|
||||
initSpeedDensity(ec);
|
||||
|
||||
resetConfigurationExt(NULL, FORD_INLINE_6_1995, ec, &ec2);
|
||||
resetConfigurationExt(NULL, FORD_INLINE_6_1995, &engine);
|
||||
ec->mafAdcChannel = (adc_channel_e)TEST_MAF_CHANNEL;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,14 +41,15 @@ void sendOutConfirmation(char *value, int i) {
|
|||
}
|
||||
|
||||
int getTheAngle(engine_type_e engineType) {
|
||||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
EngineTestHelper eth(engineType);
|
||||
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
|
||||
|
||||
initDataStructures(ec);
|
||||
resetConfigurationExt(NULL, engineType, ec, &ec2);
|
||||
resetConfigurationExt(NULL, engineType, ð.engine);
|
||||
|
||||
trigger_shape_s * shape = &ec2.triggerShape;
|
||||
trigger_shape_s * shape = ð.ec2.triggerShape;
|
||||
return findTriggerZeroEventIndex(shape, &ec->triggerConfig);
|
||||
}
|
||||
|
||||
|
@ -58,14 +59,14 @@ static void testDodgeNeonDecoder(void) {
|
|||
|
||||
assertEqualsM("trigger zero index", 8, getTheAngle(DODGE_NEON_1995));
|
||||
|
||||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
EngineTestHelper eth(DODGE_NEON_1995);
|
||||
|
||||
resetConfigurationExt(NULL, DODGE_NEON_1995, ec, &ec2);
|
||||
assertEquals(8, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
|
||||
trigger_shape_s * shape = &ec2.triggerShape;
|
||||
resetConfigurationExt(NULL, DODGE_NEON_1995, ð.engine);
|
||||
assertEquals(8, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
trigger_shape_s * shape = ð.ec2.triggerShape;
|
||||
TriggerState state;
|
||||
|
||||
assertFalseM("1 shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
|
@ -117,14 +118,14 @@ static void test1995FordInline6TriggerDecoder(void) {
|
|||
|
||||
initTriggerDecoder();
|
||||
|
||||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
EngineTestHelper eth(FORD_INLINE_6_1995);
|
||||
|
||||
resetConfigurationExt(NULL, FORD_INLINE_6_1995, ec, &ec2);
|
||||
assertEqualsM("triggerShapeSynchPointIndex", 0, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
|
||||
trigger_shape_s * shape = &ec2.triggerShape;
|
||||
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);
|
||||
|
@ -137,7 +138,7 @@ static void test1995FordInline6TriggerDecoder(void) {
|
|||
assertTriggerPosition(&position, 6, 0);
|
||||
|
||||
|
||||
IgnitionEventList *ecl = &ec2.engineEventConfiguration.ignitionEvents[0];
|
||||
IgnitionEventList *ecl = ð.ec2.engineEventConfiguration.ignitionEvents[0];
|
||||
assertEqualsM("ignition events size", 6, ecl->size);
|
||||
assertEqualsM("event index", 0, ecl->events[0].dwellPosition.eventIndex);
|
||||
assertEquals(0, ecl->events[0].dwellPosition.angleOffset);
|
||||
|
@ -181,11 +182,11 @@ void testFordAspire(void) {
|
|||
|
||||
assertEquals(4, getTheAngle(FORD_ASPIRE_1996));
|
||||
|
||||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
resetConfigurationExt(NULL, FORD_ASPIRE_1996, ec, &ec2);
|
||||
assertEquals(4, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
EngineTestHelper eth(FORD_ASPIRE_1996);
|
||||
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
resetConfigurationExt(NULL, FORD_ASPIRE_1996, ð.engine);
|
||||
assertEquals(4, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
assertEquals(800, ec->fuelRpmBins[0]);
|
||||
assertEquals(7000, ec->fuelRpmBins[15]);
|
||||
|
@ -202,24 +203,23 @@ void testFordAspire(void) {
|
|||
void testMazda323(void) {
|
||||
printf("*************************************************** testMazda323\r\n");
|
||||
|
||||
EngineTestHelper eth(MAZDA_323);
|
||||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
resetConfigurationExt(NULL, MAZDA_323, ec, &ec2);
|
||||
assertEquals(0, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
resetConfigurationExt(NULL, MAZDA_323, ð.engine);
|
||||
assertEquals(0, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
}
|
||||
|
||||
void testMazdaMianaNbDecoder(void) {
|
||||
printf("*************************************************** testMazdaMianaNbDecoder\r\n");
|
||||
|
||||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
resetConfigurationExt(NULL, MAZDA_MIATA_NB, ec, &ec2);
|
||||
assertEquals(11, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
EngineTestHelper eth(MAZDA_MIATA_NB);
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
resetConfigurationExt(NULL, MAZDA_MIATA_NB, ð.engine);
|
||||
assertEquals(11, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
TriggerState state;
|
||||
trigger_shape_s * shape = &ec2.triggerShape;
|
||||
trigger_shape_s * shape = ð.ec2.triggerShape;
|
||||
|
||||
int a = 0;
|
||||
state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, a + 20);
|
||||
|
@ -297,32 +297,31 @@ void testMazdaMianaNbDecoder(void) {
|
|||
static void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPointIndex, float channel1duty, float channel2duty) {
|
||||
printf("*************************************************** %s\r\n", msg);
|
||||
|
||||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
assertEquals(0, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
EngineTestHelper eth(type);
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
|
||||
assertEquals(0, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
initSpeedDensity(ec);
|
||||
resetConfigurationExt(NULL, type, ec, &ec2);
|
||||
resetConfigurationExt(NULL, type, ð.engine);
|
||||
|
||||
assertEqualsM("synchPointIndex", synchPointIndex, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
assertEqualsM("synchPointIndex", synchPointIndex, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
assertEqualsM("channel1duty", channel1duty, ec2.triggerShape.dutyCycle[0]);
|
||||
assertEqualsM("channel2duty", channel2duty, ec2.triggerShape.dutyCycle[1]);
|
||||
assertEqualsM("channel1duty", channel1duty, eth.ec2.triggerShape.dutyCycle[0]);
|
||||
assertEqualsM("channel2duty", channel2duty, eth.ec2.triggerShape.dutyCycle[1]);
|
||||
}
|
||||
|
||||
void testGY6_139QMB(void) {
|
||||
printf("*************************************************** testGY6_139QMB\r\n");
|
||||
|
||||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
resetConfigurationExt(NULL, GY6_139QMB, ec, &ec2);
|
||||
EngineTestHelper eth(GY6_139QMB);
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
resetConfigurationExt(NULL, GY6_139QMB, ð.engine);
|
||||
|
||||
TriggerState state;
|
||||
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
|
||||
trigger_shape_s * shape = &ec2.triggerShape;
|
||||
trigger_shape_s * shape = ð.ec2.triggerShape;
|
||||
|
||||
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
assertEquals(0, state.getCurrentIndex());
|
||||
|
|
|
@ -74,7 +74,7 @@ void rusEfiFunctionalTest(void) {
|
|||
engine.engineConfiguration2 = engineConfiguration2;
|
||||
|
||||
|
||||
resetConfigurationExt(NULL, FORD_ASPIRE_1996, engineConfiguration, engineConfiguration2);
|
||||
resetConfigurationExt(NULL, FORD_ASPIRE_1996, &engine);
|
||||
|
||||
initThermistors(&engine);
|
||||
initAlgo(engineConfiguration);
|
||||
|
|
Loading…
Reference in New Issue