auto-sync
This commit is contained in:
parent
9323dee529
commit
23a5ddb6b9
|
@ -264,6 +264,11 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_
|
|||
engineConfiguration->isWaveAnalyzerEnabled = true;
|
||||
engineConfiguration->isIdleThreadEnabled = true;
|
||||
|
||||
/**
|
||||
* this is RPM. 10000 rpm is only 166Hz, 800 rpm is 13Hz
|
||||
*/
|
||||
boardConfiguration->triggerSimulatorFrequency = 1200;
|
||||
|
||||
|
||||
boardConfiguration->idleValvePin = GPIOE_2;
|
||||
boardConfiguration->idleValvePinMode = OM_DEFAULT;
|
||||
|
@ -387,6 +392,7 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType, engine_co
|
|||
*/
|
||||
setDefaultConfiguration(engineConfiguration, boardConfiguration);
|
||||
engineConfiguration->engineType = engineType;
|
||||
engineConfiguration->headerMagicValue = HEADER_MAGIC_NUMBER;
|
||||
/**
|
||||
* And override them with engine-specific defaults
|
||||
*/
|
||||
|
|
|
@ -202,7 +202,7 @@ typedef struct {
|
|||
|
||||
} board_configuration_s;
|
||||
|
||||
|
||||
#define HEADER_MAGIC_NUMBER 0x1221239
|
||||
|
||||
/**
|
||||
* @brief Engine configuration.
|
||||
|
|
|
@ -85,6 +85,8 @@ typedef enum {
|
|||
MIATA_1994 = 20,
|
||||
MIATA_1996 = 21,
|
||||
|
||||
ET_UNUSED = 22,
|
||||
|
||||
Force_4b_engine_type = ENUM_SIZE_HACK,
|
||||
} engine_type_e;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "ec2.h"
|
||||
|
||||
static engine_type_e defaultEngineType = FORD_ASPIRE_1996;
|
||||
#define DEFAULT_ENGINE_TYPE FORD_ASPIRE_1996
|
||||
|
||||
static bool needToWriteConfiguration = false;
|
||||
|
||||
|
@ -30,7 +30,6 @@ static Logging logger;
|
|||
extern persistent_config_container_s persistentState;
|
||||
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
extern board_configuration_s *boardConfiguration;
|
||||
|
||||
extern engine_configuration2_s * engineConfiguration2;
|
||||
|
||||
|
@ -91,23 +90,27 @@ static void doResetConfiguration(void) {
|
|||
resetConfigurationExt(&logger, engineConfiguration->engineType, engineConfiguration, engineConfiguration2);
|
||||
}
|
||||
|
||||
static bool hasValidEngineType(engine_configuration_s *engineConfiguration) {
|
||||
uint32_t ordinal = (uint32_t)engineConfiguration->engineType;
|
||||
return ordinal < ET_UNUSED && engineConfiguration->headerMagicValue == HEADER_MAGIC_NUMBER;
|
||||
}
|
||||
|
||||
void readFromFlash(void) {
|
||||
printMsg(&logger, "readFromFlash()");
|
||||
|
||||
flashRead(FLASH_ADDR, (char *) &persistentState, PERSISTENT_SIZE);
|
||||
|
||||
//setDefaultNonPersistentConfiguration(engineConfiguration2);
|
||||
|
||||
if (!isValidCrc(&persistentState) || persistentState.size != PERSISTENT_SIZE) {
|
||||
if (!isValidCrc(&persistentState)) {
|
||||
printMsg(&logger, "Need to reset flash to default due to CRC");
|
||||
resetConfigurationExt(&logger, defaultEngineType, engineConfiguration, engineConfiguration2);
|
||||
} else if (persistentState.version != FLASH_DATA_VERSION) {
|
||||
printMsg(&logger, "Need to reset flash to default due to version change");
|
||||
resetConfigurationExt(&logger, defaultEngineType, engineConfiguration, engineConfiguration2);
|
||||
|
||||
} else {
|
||||
resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, engineConfiguration, engineConfiguration2);
|
||||
} else if (persistentState.version == FLASH_DATA_VERSION && persistentState.size == PERSISTENT_SIZE) {
|
||||
printMsg(&logger, "Got valid configuration from flash!");
|
||||
applyNonPersistentConfiguration(&logger, engineConfiguration, engineConfiguration2);
|
||||
} else if (hasValidEngineType(engineConfiguration)) {
|
||||
printMsg(&logger, "Resetting but saving engine type [%d]", engineConfiguration->engineType);
|
||||
resetConfigurationExt(&logger, engineConfiguration->engineType, engineConfiguration, engineConfiguration2);
|
||||
} else {
|
||||
printMsg(&logger, "Need to reset flash to default due to version change");
|
||||
resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, engineConfiguration, engineConfiguration2);
|
||||
}
|
||||
// we can only change the state after the CRC check
|
||||
engineConfiguration->firmwareVersion = getRusEfiVersion();
|
||||
|
|
|
@ -176,12 +176,12 @@ void initializeSkippedToothTriggerShapeExt(trigger_shape_s *s, int totalTeethCou
|
|||
/**
|
||||
* External logger is needed because at this point our logger is not yet initialized
|
||||
*/
|
||||
void initializeTriggerShape(Logging *logger, engine_configuration_s *engineConfiguration,
|
||||
void initializeTriggerShape(Logging *logger, engine_configuration_s const *engineConfiguration,
|
||||
engine_configuration2_s *engineConfiguration2) {
|
||||
#if EFI_PROD_CODE
|
||||
scheduleMsg(logger, "initializeTriggerShape()");
|
||||
#endif
|
||||
trigger_config_s *triggerConfig = &engineConfiguration->triggerConfig;
|
||||
const trigger_config_s *triggerConfig = &engineConfiguration->triggerConfig;
|
||||
trigger_shape_s *triggerShape = &engineConfiguration2->triggerShape;
|
||||
|
||||
setTriggerSynchronizationGap(triggerShape, 2);
|
||||
|
@ -212,11 +212,11 @@ void initializeTriggerShape(Logging *logger, engine_configuration_s *engineConfi
|
|||
return;
|
||||
|
||||
case TT_FORD_ASPIRE:
|
||||
configureFordAspireTriggerShape(triggerConfig, triggerShape);
|
||||
configureFordAspireTriggerShape(triggerShape);
|
||||
return;
|
||||
|
||||
case TT_GM_7X:
|
||||
configureGmTriggerShape(triggerConfig, triggerShape);
|
||||
configureGmTriggerShape(triggerShape);
|
||||
return;
|
||||
|
||||
case TT_FORD_ESCORT_GT:
|
||||
|
|
|
@ -79,7 +79,7 @@ private:
|
|||
|
||||
void initializeSkippedToothTriggerShapeExt(trigger_shape_s *s, int totalTeethCount, int skippedCount, operation_mode_e operationMode);
|
||||
uint32_t findTriggerZeroEventIndex(trigger_shape_s * shape, trigger_config_s const*triggerConfig);
|
||||
void initializeTriggerShape(Logging *logger, engine_configuration_s *engineConfiguration, engine_configuration2_s *engineConfiguration2);
|
||||
void initializeTriggerShape(Logging *logger, engine_configuration_s const *engineConfiguration, engine_configuration2_s *engineConfiguration2);
|
||||
void initTriggerDecoder(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -31,6 +31,7 @@ static Logging logger;
|
|||
static LocalVersionHolder localVersion;
|
||||
|
||||
void setTriggerEmulatorRPM(int rpm) {
|
||||
engineConfiguration->bc.triggerSimulatorFrequency = rpm;
|
||||
/**
|
||||
* All we need to do here is to change the periodMs
|
||||
* togglePwmState() would see that the periodMs has changed and act accordingly
|
||||
|
@ -63,7 +64,7 @@ void initTriggerEmulatorLogic(pwm_gen_callback *stateChangeCallback) {
|
|||
|
||||
|
||||
trigger_shape_s *s = &engineConfiguration2->triggerShape;
|
||||
setTriggerEmulatorRPM(DEFAULT_EMULATION_RPM);
|
||||
setTriggerEmulatorRPM(engineConfiguration->bc.triggerSimulatorFrequency);
|
||||
int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates, s->wave.waves[2].pinStates};
|
||||
weComplexInit("position sensor", &triggerSignal, s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM, pinStates,
|
||||
updateTriggerShapeIfNeeded, stateChangeCallback);
|
||||
|
|
|
@ -10,19 +10,6 @@
|
|||
|
||||
#include "pwm_generator_logic.h"
|
||||
|
||||
/**
|
||||
* this is RPM. 10000 rpm is only 166Hz, 800 rpm is 13Hz
|
||||
*/
|
||||
#define DEFAULT_EMULATION_RPM 1200
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void initTriggerEmulatorLogic(pwm_gen_callback *callback);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* TRIGGER_EMULATOR_ALGO_H_ */
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "trigger_gm.h"
|
||||
|
||||
void configureGmTriggerShape(trigger_config_s *triggerConfig, trigger_shape_s *s) {
|
||||
void configureGmTriggerShape(trigger_shape_s *s) {
|
||||
s->reset(FOUR_STROKE_CAM_SENSOR);
|
||||
|
||||
// all angles are x2 here - so, 5 degree width is 10
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
|
||||
#include "trigger_structure.h"
|
||||
|
||||
void configureGmTriggerShape(trigger_config_s *triggerConfig, trigger_shape_s *s);
|
||||
void configureGmTriggerShape(trigger_shape_s *s);
|
||||
|
||||
#endif /* TRIGGER_GM_H_ */
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "trigger_mitsubishi.h"
|
||||
|
||||
void configureFordAspireTriggerShape(trigger_config_s *triggerConfig, trigger_shape_s * s) {
|
||||
void configureFordAspireTriggerShape(trigger_shape_s * s) {
|
||||
s->isSynchronizationNeeded = false;
|
||||
s->reset(FOUR_STROKE_CAM_SENSOR);
|
||||
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
#include "trigger_structure.h"
|
||||
|
||||
void initializeMitsubishi4g18(trigger_shape_s *s);
|
||||
void configureFordAspireTriggerShape(trigger_config_s *triggerConfig, trigger_shape_s * s);
|
||||
void configureFordAspireTriggerShape(trigger_shape_s * s);
|
||||
|
||||
#endif /* TRIGGER_MITSUBISHI_H_ */
|
||||
|
|
|
@ -23,7 +23,7 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) {
|
|||
|
||||
initSpeedDensity(ec);
|
||||
|
||||
resetConfigurationExt(NULL, FORD_INLINE_6_1995, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, FORD_INLINE_6_1995, ec, &ec2);
|
||||
ec->mafAdcChannel = (adc_channel_e)TEST_MAF_CHANNEL;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ int getTheAngle(engine_type_e engineType) {
|
|||
engine_configuration2_s ec2;
|
||||
|
||||
initDataStructures(ec);
|
||||
resetConfigurationExt(NULL, engineType, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, engineType, ec, &ec2);
|
||||
|
||||
trigger_shape_s * shape = &ec2.triggerShape;
|
||||
return findTriggerZeroEventIndex(shape, &ec->triggerConfig);
|
||||
|
@ -60,7 +60,7 @@ static void testDodgeNeonDecoder(void) {
|
|||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
|
||||
resetConfigurationExt(NULL, DODGE_NEON_1995, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, DODGE_NEON_1995, ec, &ec2);
|
||||
assertEquals(8, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
trigger_shape_s * shape = &ec2.triggerShape;
|
||||
|
@ -119,7 +119,7 @@ static void test1995FordInline6TriggerDecoder(void) {
|
|||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
|
||||
resetConfigurationExt(NULL, FORD_INLINE_6_1995, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, FORD_INLINE_6_1995, ec, &ec2);
|
||||
assertEqualsM("triggerShapeSynchPointIndex", 0, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
trigger_shape_s * shape = &ec2.triggerShape;
|
||||
|
@ -182,7 +182,7 @@ void testFordAspire(void) {
|
|||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
resetConfigurationExt(NULL, FORD_ASPIRE_1996, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, FORD_ASPIRE_1996, ec, &ec2);
|
||||
assertEquals(4, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
assertEquals(800, ec->fuelRpmBins[0]);
|
||||
|
@ -203,7 +203,7 @@ void testMazda323(void) {
|
|||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
resetConfigurationExt(NULL, MAZDA_323, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, MAZDA_323, ec, &ec2);
|
||||
assertEquals(0, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@ void testMazdaMianaNbDecoder(void) {
|
|||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
resetConfigurationExt(NULL, MAZDA_MIATA_NB, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, MAZDA_MIATA_NB, ec, &ec2);
|
||||
assertEquals(11, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
TriggerState state;
|
||||
|
@ -301,7 +301,7 @@ static void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPo
|
|||
assertEquals(0, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
initSpeedDensity(ec);
|
||||
resetConfigurationExt(NULL, type, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, type, ec, &ec2);
|
||||
|
||||
assertEqualsM("synchPointIndex", synchPointIndex, ec2.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
|
||||
|
@ -315,7 +315,7 @@ void testGY6_139QMB(void) {
|
|||
persistent_config_s persistentConfig;
|
||||
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
|
||||
engine_configuration2_s ec2;
|
||||
resetConfigurationExt(NULL, GY6_139QMB, ec, &ec2, &persistentConfig.engineConfiguration.bc);
|
||||
resetConfigurationExt(NULL, GY6_139QMB, ec, &ec2);
|
||||
|
||||
TriggerState state;
|
||||
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
|
|
Loading…
Reference in New Issue