auto-sync

This commit is contained in:
rusEfi 2014-11-25 10:04:15 -06:00
parent ef729cccdd
commit 249444a7cd
17 changed files with 43 additions and 72 deletions

View File

@ -27,12 +27,11 @@
#include "engine_configuration.h"
#include "engine_math.h"
extern engine_configuration_s *engineConfiguration;
//extern engine_configuration2_s *engineConfiguration2;
EXTERN_ENGINE;
static Map3D1616 advanceMap;
float getBaseAdvance(int rpm, float engineLoad) {
float getBaseAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
if (cisnan(engineLoad)) {
warning(OBD_PCM_Processor_Fault, "NaN engine load");
return NAN;
@ -48,13 +47,13 @@ float getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
if (isCrankingR(rpm)) {
angle = -engineConfiguration->crankingTimingAngle;
} else {
angle = getBaseAdvance(rpm, engineLoad);
angle = getBaseAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER);
}
angle -= engineConfiguration->ignitionOffset;
angle = fixAngle(angle PASS_ENGINE_PARAMETER);
fixAngle(angle);
return angle;
}
void prepareTimingMap(void) {
void prepareTimingMap(DECLARE_ENGINE_PARAMETER_F) {
advanceMap.init(engineConfiguration->ignitionTable);
}

View File

@ -14,6 +14,6 @@
#include "engine.h"
float getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S);
void prepareTimingMap(void);
void prepareTimingMap(DECLARE_ENGINE_PARAMETER_F);
#endif /* ADVANCE_H_ */

View File

@ -27,9 +27,11 @@
#include "signal_executor.h"
#include "speed_density.h"
void initDataStructures(engine_configuration_s *engineConfiguration) {
EXTERN_ENGINE;
void initDataStructures(DECLARE_ENGINE_PARAMETER_F) {
prepareFuelMap(engineConfiguration);
prepareTimingMap();
prepareTimingMap(PASS_ENGINE_PARAMETER_F);
initSpeedDensity(engineConfiguration);
}

View File

@ -15,7 +15,7 @@ extern "C"
{
#endif /* __cplusplus */
void initDataStructures(engine_configuration_s *engineConfiguration);
void initDataStructures(DECLARE_ENGINE_PARAMETER_F);
void initAlgo(engine_configuration_s *engineConfiguration);
#ifdef __cplusplus

View File

@ -48,20 +48,6 @@ float getCrankshaftRevolutionTimeMs(int rpm) {
return 360 * getOneDegreeTimeMs(rpm);
}
/**
* @brief Shifts angle into the [0..720) range
* TODO: should be 'crankAngleRange' range?
*/
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 += CONFIG(engineCycle);
while (angle >= CONFIG(engineCycle))
angle -= CONFIG(engineCycle);
return angle;
}
/**
* @brief Returns engine load according to selected engine_load_mode
*
@ -282,7 +268,7 @@ void findTriggerPosition(trigger_shape_s * s, event_trigger_position_s *position
float angleOffset DECLARE_ENGINE_PARAMETER_S) {
angleOffset += engineConfiguration->globalTriggerAngleOffset;
angleOffset = fixAngle(angleOffset PASS_ENGINE_PARAMETER);
fixAngle(angleOffset);
int engineCycleEventCount = getEngineCycleEventCount2(getOperationMode(engineConfiguration), s);

View File

@ -31,7 +31,15 @@ extern "C"
{
#endif /* __cplusplus */
float fixAngle(float angle DECLARE_ENGINE_PARAMETER_S);
/**
* @brief Shifts angle into the [0..720) range for four stroke and [0..360) for two stroke
* I guess this implementation would be faster than 'angle % engineCycle'
*/
#define fixAngle(angle) \
while (angle < 0) \
angle += CONFIG(engineCycle); \
while (angle >= CONFIG(engineCycle)) \
angle -= CONFIG(engineCycle);
/**
* @return time needed to rotate crankshaft by one degree, in milliseconds.

View File

@ -298,7 +298,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL
}
(void) ckpSignalType;
efiAssertVoid(eventIndex < 2 * engine->triggerShape.shaftPositionEventCount, "event index");
efiAssertVoid(eventIndex < 2 * engine->triggerShape.getSize(), "event index");
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#2");
int rpm = getRpmE(engine);

View File

@ -213,8 +213,6 @@ void initializeSkippedToothTriggerShapeExt(trigger_shape_s *s, int totalTeethCou
s->totalToothCount = totalTeethCount;
s->skippedToothCount = skippedCount;
initializeSkippedToothTriggerShape(s, totalTeethCount, skippedCount, operationMode);
s->assignSize();
}
/**
@ -305,7 +303,6 @@ void initializeTriggerShape(Logging *logger, engine_configuration_s const *engin
;
return;
}
triggerShape->assignSize();
triggerShape->wave.checkSwitchTimes(triggerShape->getSize());
}

View File

@ -33,7 +33,5 @@ void configureGmTriggerShape(trigger_shape_s *s) {
s->addEvent(720 - w, T_PRIMARY, TV_HIGH);
s->addEvent(720.0, T_PRIMARY, TV_LOW);
s->assignSize();
}

View File

@ -42,8 +42,6 @@ void initializeMazdaMiataNaShape(trigger_shape_s *s) {
s->addEvent(590.39625, T_SECONDARY, TV_HIGH);
s->addEvent(656.5125, T_SECONDARY, TV_LOW);
s->addEvent(720.0f, T_PRIMARY, TV_LOW);
s->assignSize();
}
void initializeMazdaMiataNbShape(trigger_shape_s *s) {
@ -82,8 +80,6 @@ void initializeMazdaMiataNbShape(trigger_shape_s *s) {
s->addEvent(680.0f, T_SECONDARY, TV_HIGH);
s->addEvent(720.0f, T_PRIMARY, TV_LOW);
s->assignSize();
}
void configureMazdaProtegeLx(trigger_shape_s *s) {
@ -126,7 +122,5 @@ void configureMazdaProtegeLx(trigger_shape_s *s) {
s->addEvent(a - z * 720, T_PRIMARY, TV_HIGH);
s->addEvent(a, T_PRIMARY, TV_LOW);
s->assignSize();
s->isSynchronizationNeeded = false;
}

View File

@ -26,8 +26,6 @@ void configureFordAspireTriggerShape(trigger_shape_s * s) {
s->addEvent(x + 360 + y, T_SECONDARY, TV_HIGH);
s->addEvent(x + 540, T_SECONDARY, TV_LOW);
s->addEvent(720, T_PRIMARY, TV_LOW);
s->assignSize();
}
void initializeMitsubishi4g18(trigger_shape_s *s) {
@ -53,6 +51,4 @@ void initializeMitsubishi4g18(trigger_shape_s *s) {
s->addEvent(720.0 - secondaryWidth, T_SECONDARY, TV_HIGH);
s->addEvent(720.0, T_SECONDARY, TV_LOW);
s->assignSize();
}

View File

@ -24,6 +24,8 @@
#include "trigger_decoder.h"
#include "engine_math.h"
EXTERN_ENGINE;
trigger_shape_helper::trigger_shape_helper() {
for (int i = 0; i < TRIGGER_CHANNEL_COUNT; i++) {
waves[i].init(pinStates[i]);
@ -40,10 +42,6 @@ trigger_shape_s::trigger_shape_s() :
invertOnAdd = false;
}
void trigger_shape_s::assignSize() {
shaftPositionEventCount = getSize();
}
int trigger_shape_s::getSize() const {
return size;
}
@ -73,7 +71,7 @@ void trigger_shape_s::setTriggerShapeSynchPointIndex(engine_configuration_s *eng
eventAngles[i] = 0;
} else {
float angle = getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle;
angle = fixAngle(angle PASS_ENGINE_PARAMETER);
fixAngle(angle);
eventAngles[i] = angle;
}
}
@ -82,7 +80,6 @@ void trigger_shape_s::setTriggerShapeSynchPointIndex(engine_configuration_s *eng
void trigger_shape_s::reset(operation_mode_e operationMode) {
this->operationMode = operationMode;
size = 0;
shaftPositionEventCount = 0;
triggerShapeSynchPointIndex = 0;
memset(initialState, 0, sizeof(initialState));
memset(switchTimesBuffer, 0, sizeof(switchTimesBuffer));
@ -395,8 +392,6 @@ void configureHondaAccordCDDip(trigger_shape_s *s) {
s->addEvent(720.0f, T_SECONDARY, TV_HIGH);
s->isSynchronizationNeeded = false;
s->assignSize();
}
void configureHondaAccordCD(trigger_shape_s *s, bool with3rdSignal) {
@ -444,6 +439,4 @@ void configureHondaAccordCD(trigger_shape_s *s, bool with3rdSignal) {
sb = addAccordPair(s, sb);
s->addEvent(i * 180.0f, T_PRIMARY, TV_LOW);
}
s->assignSize();
}

View File

@ -62,18 +62,8 @@ public:
void addEvent(float angle, trigger_wheel_e const waveIndex, trigger_value_e const state);
void reset(operation_mode_e operationMode);
int getSize() const;
void assignSize();
multi_wave_s wave;
/**
* Total count of shaft events per CAM or CRANK shaft revolution.
* TODO this should be migrated to CRANKshaft revolution, this would go together
* TODO with eliminating RPM_MULT magic constant
*
* todo: somehow changing the type of this to uint32_t breaks unit tests? WHY?
*/
int shaftPositionEventCount;
/**
* this one is per CRANKshaft revolution
*/
@ -98,6 +88,12 @@ public:
private:
trigger_shape_helper h;
/**
* Total count of shaft events per CAM or CRANK shaft revolution.
* TODO this should be migrated to CRANKshaft revolution, this would go together
* TODO with eliminating RPM_MULT magic constant
*/
int size;
/**
* index of synchronization event within trigger_shape_s

View File

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

View File

@ -175,7 +175,7 @@ void initHardware(Logging *logger, Engine *engine) {
return;
}
initDataStructures(engineConfiguration);
initDataStructures(PASS_ENGINE_PARAMETER_F);
#if EFI_INTERNAL_FLASH

View File

@ -41,11 +41,12 @@ void sendOutConfirmation(char *value, int i) {
int getTheAngle(engine_type_e engineType) {
EngineTestHelper eth(engineType);
engine_configuration_s *ec = eth.ec;
initDataStructures(ec);
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = eth.ec;
initDataStructures(PASS_ENGINE_PARAMETER_F);
trigger_shape_s * shape = &eth.engine.triggerShape;
return findTriggerZeroEventIndex(shape, &ec->triggerConfig);
return findTriggerZeroEventIndex(shape, &engineConfiguration->triggerConfig);
}
static void testDodgeNeonDecoder(void) {
@ -384,12 +385,13 @@ static void testRpmCalculator(void) {
initThermistors(&eth.engine);
engine_configuration_s *ec = &eth.persistentConfig.engineConfiguration;
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = &eth.persistentConfig.engineConfiguration;
engine_configuration2_s *ec2 = &eth.ec2;
ec->triggerConfig.customTotalToothCount = 8;
ec->globalFuelCorrection = 3;
engineConfiguration->triggerConfig.customTotalToothCount = 8;
engineConfiguration->globalFuelCorrection = 3;
eth.initTriggerShapeAndRpmCalculator();
// this is a very dirty and sad hack. todo: eliminate
@ -408,7 +410,7 @@ static void testRpmCalculator(void) {
eth.triggerCentral.addEventListener(mainTriggerCallback, "main loop", &eth.engine);
// engine.rpmCalculator = &eth.rpmState;
prepareTimingMap();
prepareTimingMap(PASS_ENGINE_PARAMETER_F);
timeNow += 5000; // 5ms
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);

View File

@ -67,7 +67,7 @@ void rusEfiFunctionalTest(void) {
initFakeBoard();
initStatusLoop(engine);
initDataStructures(engineConfiguration);
initDataStructures(PASS_ENGINE_PARAMETER_F);
engine->engineConfiguration = engineConfiguration;
engine->engineConfiguration2 = engineConfiguration2;