auto-sync

This commit is contained in:
rusEfi 2014-11-25 09:03:25 -06:00
parent df006b2a02
commit ef729cccdd
7 changed files with 30 additions and 9 deletions

View File

@ -50,7 +50,9 @@ float getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
} else {
angle = getBaseAdvance(rpm, engineLoad);
}
return fixAngle(angle - engineConfiguration->ignitionOffset PASS_ENGINE_PARAMETER);
angle -= engineConfiguration->ignitionOffset;
angle = fixAngle(angle PASS_ENGINE_PARAMETER);
return angle;
}
void prepareTimingMap(void) {

View File

@ -56,9 +56,9 @@ float fixAngle(float angle DECLARE_ENGINE_PARAMETER_S) {
efiAssert(engineConfiguration->engineCycle != 0, "engine cycle", NAN);
// I guess this implementation would be faster than 'angle % 720'
while (angle < 0)
angle += engineConfiguration->engineCycle;
while (angle >= engineConfiguration->engineCycle)
angle -= engineConfiguration->engineCycle;
angle += CONFIG(engineCycle);
while (angle >= CONFIG(engineCycle))
angle -= CONFIG(engineCycle);
return angle;
}
@ -281,7 +281,8 @@ int getEngineCycleEventCount2(operation_mode_e mode, trigger_shape_s * s) {
void findTriggerPosition(trigger_shape_s * s, event_trigger_position_s *position,
float angleOffset DECLARE_ENGINE_PARAMETER_S) {
angleOffset = fixAngle(angleOffset + engineConfiguration->globalTriggerAngleOffset PASS_ENGINE_PARAMETER);
angleOffset += engineConfiguration->globalTriggerAngleOffset;
angleOffset = fixAngle(angleOffset PASS_ENGINE_PARAMETER);
int engineCycleEventCount = getEngineCycleEventCount2(getOperationMode(engineConfiguration), s);

View File

@ -72,7 +72,9 @@ void trigger_shape_s::setTriggerShapeSynchPointIndex(engine_configuration_s *eng
// explicit check for zero to avoid issues where logical zero is not exactly zero due to float nature
eventAngles[i] = 0;
} else {
eventAngles[i] = fixAngle(getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle PASS_ENGINE_PARAMETER);
float angle = getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle;
angle = fixAngle(angle PASS_ENGINE_PARAMETER);
eventAngles[i] = angle;
}
}
}

View File

@ -228,7 +228,9 @@ static void reportWave(Logging *logging, int index) {
float oneDegreeUs = getOneDegreeTimeUs(getRpm());
appendPrintf(logging, "advance%d%s", index, DELIMETER);
appendFloat(logging, fixAngle((offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset PASS_ENGINE_PARAMETER), 3);
float angle = (offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset;
angle = fixAngle(angle PASS_ENGINE_PARAMETER);
appendFloat(logging, angle, 3);
appendPrintf(logging, "%s", DELIMETER);
}
}

View File

@ -71,11 +71,19 @@ typedef Thread thread_t;
#define EXTERN_ENGINE extern Engine *engine; \
extern engine_configuration_s *engineConfiguration; \
extern board_configuration_s *boardConfiguration;
extern board_configuration_s *boardConfiguration; \
extern persistent_config_container_s persistentState
#define DECLARE_ENGINE_PARAMETER_F void
#define DECLARE_ENGINE_PARAMETER_S
#define PASS_ENGINE_PARAMETER_F
#define PASS_ENGINE_PARAMETER
/**
* this macro allows the compiled to figure out the complete static address, that's a performance
* optimization
*/
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
#endif /* GLOBAL_H_ */

View File

@ -45,4 +45,6 @@ class Engine;
#define PASS_ENGINE_PARAMETER_F engine, engineConfiguration
#define PASS_ENGINE_PARAMETER , engine, engineConfiguration
#define CONFIG(x) engineConfiguration->x
#endif /* GLOBAL_H_ */

View File

@ -90,9 +90,13 @@ typedef EventListener event_listener_t;
#define EXTERN_ENGINE extern Engine *engine; \
extern engine_configuration_s *engineConfiguration; \
extern board_configuration_s *boardConfiguration;
extern board_configuration_s *boardConfiguration; \
extern persistent_config_container_s persistentState
#define DECLARE_ENGINE_PARAMETER_F void
#define DECLARE_ENGINE_PARAMETER_S
#define PASS_ENGINE_PARAMETER_F
#define PASS_ENGINE_PARAMETER
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x