auto-sync

This commit is contained in:
rusEfi 2014-11-24 20:03:34 -06:00
parent 3b34c95c01
commit f575e7bd55
20 changed files with 55 additions and 52 deletions

View File

@ -169,8 +169,8 @@ void printState(Engine *engine, int currentCkpEventCounter) {
// debugFloat(&logger, "table_spark", getAdvance(rpm, getMaf()), 2);
float engineLoad = getEngineLoadT(engine);
float baseFuel = getBaseFuel(engine, rpm);
float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER);
float baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER);
debugFloat(&logger, "fuel_base", baseFuel, 2);
// debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2);
// debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2);
@ -333,7 +333,7 @@ static void showFuelInfo2(float rpm, float engineLoad, Engine *engine) {
}
static void showFuelInfo(Engine *engine) {
showFuelInfo2((float) getRpmE(engine), getEngineLoadT(engine), engine);
showFuelInfo2((float) getRpmE(engine), getEngineLoadT(PASS_ENGINE_PARAMETER), engine);
}
#endif /* EFI_PROD_CODE */
@ -420,7 +420,7 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputC
float coolant = getCoolantTemperature(engine);
float intake = getIntakeAirTemperature(engine);
float engineLoad = getEngineLoadT(engine);
float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER);
float baseFuelMs = getBaseTableFuel(engineConfiguration, (int) rpm, engineLoad);
tsOutputChannels->rpm = rpm;

View File

@ -51,7 +51,7 @@ float getAccelEnrichment(void) {
static msg_t DiffEnrichmentThread(int param) {
chRegSetThreadName("Diff Enrichment");
while (TRUE) {
instance.updateDiffEnrichment(engineConfiguration, getEngineLoad());
instance.updateDiffEnrichment(engineConfiguration, getEngineLoadT(PASS_ENGINE_PARAMETER));
chThdSleepMilliseconds(100);
}
#if defined __GNUC__

View File

@ -43,11 +43,11 @@
EXTERN_ENGINE;
float getBaseFuel(Engine *engine, int rpm) {
float getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S) {
if (engine->engineConfiguration->algorithm == LM_SPEED_DENSITY) {
return getSpeedDensityFuel(engine, rpm);
} else {
float engineLoad = getEngineLoadT(engine);
float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_F);
return getBaseTableFuel(engine->engineConfiguration, rpm, engineLoad);
}
}
@ -78,7 +78,7 @@ float getFuelMs(int rpm DECLARE_ENGINE_PARAMETER_S) {
if (isCrankingR(rpm)) {
theoreticalInjectionLength = getCrankingFuel(engine) / getNumberOfInjections(engineConfiguration, engineConfiguration->crankingInjectionMode);
} else {
float baseFuel = getBaseFuel(engine, rpm);
float baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER);
float fuelPerCycle = getRunningFuel(baseFuel, rpm PASS_ENGINE_PARAMETER);
theoreticalInjectionLength = fuelPerCycle / getNumberOfInjections(engineConfiguration, engine->engineConfiguration->injectionMode);
}

View File

@ -12,7 +12,7 @@
void prepareFuelMap(engine_configuration_s *engineConfiguration);
float getBaseFuel(Engine *engine, int rpm);
float getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S);
float getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm, float engineLoad);
float getIatCorrection(float iat DECLARE_ENGINE_PARAMETER_S);
float getInjectorLag(float vBatt DECLARE_ENGINE_PARAMETER_S);

View File

@ -29,7 +29,7 @@ public:
};
void initMainEventListener(Engine *engine, engine_configuration2_s *engineConfiguration2);
void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex, Engine *engine);
void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECLARE_ENGINE_PARAMETER_S);
#endif
int isIgnitionTimingError(void);

View File

@ -126,7 +126,7 @@ static void endAveraging(void *arg) {
/**
* Shaft Position callback used to schedule start and end of MAP averaging
*/
static void shaftPositionCallback(trigger_event_e ckpEventType, uint32_t index, Engine *arg) {
static void shaftPositionCallback(trigger_event_e ckpEventType, uint32_t index DECLARE_ENGINE_PARAMETER_S) {
// this callback is invoked on interrupt thread
if (index != 0)

View File

@ -65,7 +65,7 @@ static void maThread(int param) {
// ideally this should be atomic, but hopefully it's good enough
int rpm = getRpm();
float load = getEngineLoad();
float load = getEngineLoadT(PASS_ENGINE_PARAMETER);
float afr = getAfr();
addAfr(rpm, load, afr);

View File

@ -66,9 +66,8 @@ float fixAngle(float angle DECLARE_ENGINE_PARAMETER_S) {
* @brief Returns engine load according to selected engine_load_mode
*
*/
float getEngineLoadT(Engine *engine) {
float getEngineLoadT(DECLARE_ENGINE_PARAMETER_F) {
efiAssert(engine!=NULL, "engine 2NULL", NAN);
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
efiAssert(engineConfiguration!=NULL, "engineConfiguration 2NULL", NAN);
switch (engineConfiguration->algorithm) {
case LM_MAF:

View File

@ -50,8 +50,8 @@ float getCrankshaftRevolutionTimeMs(int rpm);
#define isCrankingR(rpm) ((rpm) > 0 && (rpm) < engineConfiguration->crankingSettings.crankingRpm)
float getEngineLoadT(Engine *engine);
#define getEngineLoad() getEngineLoadT(engine)
float getEngineLoadT(DECLARE_ENGINE_PARAMETER_F);
float getSparkDwellMsT(int rpm DECLARE_ENGINE_PARAMETER_S);

View File

@ -288,7 +288,7 @@ void showMainHistogram(void) {
* This is the main trigger event handler.
* Both injection and ignition are controlled from this method.
*/
void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex, Engine *engine) {
void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECLARE_ENGINE_PARAMETER_S) {
if (hasFirmwareError()) {
/**
* In case on a major error we should not process any more events.
@ -301,9 +301,6 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex, Eng
efiAssertVoid(eventIndex < 2 * engine->triggerShape.shaftPositionEventCount, "event index");
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "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
@ -348,7 +345,8 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex, Eng
firmwareError("invalid dwell: %f at %d", dwellMs, rpm);
return;
}
float advance = getAdvance(rpm, getEngineLoadT(engine) PASS_ENGINE_PARAMETER);
float el = getEngineLoadT(PASS_ENGINE_PARAMETER_F);
float advance = getAdvance(rpm, el PASS_ENGINE_PARAMETER);
if (cisnan(advance)) {
// error should already be reported
@ -402,8 +400,8 @@ void MainTriggerCallback::init(Engine *engine, engine_configuration2_s *engineCo
static void showMainInfo(Engine *engine) {
int rpm = engine->rpmCalculator.rpm();
float el = getEngineLoadT(mainTriggerCallbackInstance.engine);
#if EFI_PROD_CODE
float el = getEngineLoadT(PASS_ENGINE_PARAMETER);
scheduleMsg(&logger, "rpm %d engine_load %f", rpm, el);
scheduleMsg(&logger, "fuel %fms timing %f", getFuelMs(rpm PASS_ENGINE_PARAMETER),
getAdvance(rpm, el PASS_ENGINE_PARAMETER));

View File

@ -127,7 +127,7 @@ bool isCranking(void) {
* updated here.
* This callback is invoked on interrupt thread.
*/
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Engine *engine) {
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S) {
RpmCalculator *rpmState = &engine->rpmCalculator;
uint64_t nowNt = getTimeNowNt();
#if EFI_PROD_CODE
@ -186,7 +186,7 @@ static void onTdcCallback(void) {
/**
* This trigger callback schedules the actual physical TDC callback in relation to trigger synchronization point.
*/
static void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0, Engine *engine) {
static void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0 DECLARE_ENGINE_PARAMETER_S) {
(void) ckpSignalType;
bool isTriggerSynchronizationPoint = index0 == 0;
if (isTriggerSynchronizationPoint) {

View File

@ -10,6 +10,7 @@
#define RPM_REPORTER_H_
#include <global.h>
#include "engine_configuration.h"
#define WC_DOWN "d"
#define WC_UP "u"
@ -62,7 +63,7 @@ private:
#define getRpmE(engine) (engine)->rpmCalculator.rpm()
bool isCrankingE(Engine *engine);
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Engine *engine);
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S);
/**
* @brief Initialize RPM calculator
*/

View File

@ -70,7 +70,7 @@ void hwHandleShaftSignal(trigger_event_e signal) {
maxTriggerReentraint = triggerReentraint;
triggerReentraint++;
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#8");
triggerCentral.handleShaftSignal(engine, signal);
triggerCentral.handleShaftSignal(signal, engine, engine->engineConfiguration);
triggerReentraint--;
}
#endif /* EFI_PROD_CODE */
@ -109,7 +109,7 @@ static ALWAYS_INLINE void reportEventToWaveChart(trigger_event_e ckpSignalType,
}
}
void TriggerCentral::handleShaftSignal(Engine *engine, trigger_event_e signal) {
void TriggerCentral::handleShaftSignal(trigger_event_e signal, Engine *engine, engine_configuration_s *engineConfiguration) {
efiAssertVoid(engine!=NULL, "configuration");
nowNt = getTimeNowNt();
@ -140,7 +140,7 @@ void TriggerCentral::handleShaftSignal(Engine *engine, trigger_event_e signal) {
/**
* This invocation changes the state of triggerState
*/
triggerState.decodeTriggerEvent(triggerShape, &engine->engineConfiguration->triggerConfig, signal, nowNt);
triggerState.decodeTriggerEvent(triggerShape, &engineConfiguration->triggerConfig, signal, nowNt);
if (!triggerState.shaft_is_synchronized) {
// we should not propagate event if we do not know where we are
@ -169,7 +169,11 @@ void TriggerCentral::handleShaftSignal(Engine *engine, trigger_event_e signal) {
/**
* Here we invoke all the listeners - the main engine control logic is inside these listeners
*/
invokeIntIntVoidCallbacks(&triggerListeneres, signal, triggerIndexForListeners);
for (int i = 0; i < triggerListeneres.currentListenersCount; i++) {
ShaftPositionListener listener = (ShaftPositionListener)triggerListeneres.callbacks[i];
(listener)(signal, triggerIndexForListeners PASS_ENGINE_PARAMETER);
}
}
#if EFI_HISTOGRAMS && EFI_PROD_CODE
int afterCallback = hal_lld_get_counter_value();

View File

@ -13,7 +13,7 @@
#include "trigger_decoder.h"
class Engine;
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, Engine *engine);
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index DECLARE_ENGINE_PARAMETER_S);
#ifdef __cplusplus
#include "ec2.h"
@ -25,7 +25,7 @@ class TriggerCentral {
public:
TriggerCentral();
void addEventListener(ShaftPositionListener handler, const char *name, Engine *engine);
void handleShaftSignal(Engine *engine, trigger_event_e signal);
void handleShaftSignal(trigger_event_e signal, Engine *engine, engine_configuration_s *engineConfiguration);
int getHwEventCounter(int index);
TriggerState triggerState;
uint64_t nowNt;

View File

@ -136,9 +136,8 @@ static void initWave(const char *name, int index) {
}
#endif
static void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index, Engine *arg) {
static void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S) {
(void)ckpSignalType;
(void)arg;
if (index != 0) {
return;
}

View File

@ -75,6 +75,7 @@ typedef Thread thread_t;
#define DECLARE_ENGINE_PARAMETER_F void
#define DECLARE_ENGINE_PARAMETER_S
#define PASS_ENGINE_PARAMETER_F
#define PASS_ENGINE_PARAMETER
#endif /* GLOBAL_H_ */

View File

@ -33,9 +33,9 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) {
void EngineTestHelper::fireTriggerEvents() {
for (int i = 0; i < 24; i++) {
timeNow += 5000; // 5ms
triggerCentral.handleShaftSignal(&engine, SHAFT_PRIMARY_UP);
triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &engine, engine.engineConfiguration);
timeNow += 5000;
triggerCentral.handleShaftSignal(&engine, SHAFT_PRIMARY_DOWN);
triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &engine, engine.engineConfiguration);
}
}
@ -43,6 +43,6 @@ void EngineTestHelper::initTriggerShapeAndRpmCalculator() {
initializeTriggerShape(NULL, ec, &engine);
incrementGlobalConfigurationVersion();
triggerCentral.addEventListener((ShaftPositionListener) &rpmShaftPositionCallback, "rpm reporter", &engine);
triggerCentral.addEventListener(rpmShaftPositionCallback, "rpm reporter", &engine);
}

View File

@ -42,6 +42,7 @@ class Engine;
#define DECLARE_ENGINE_PARAMETER_F Engine *engine, engine_configuration_s *engineConfiguration
#define DECLARE_ENGINE_PARAMETER_S , Engine *engine, engine_configuration_s *engineConfiguration
#define PASS_ENGINE_PARAMETER_F engine, engineConfiguration
#define PASS_ENGINE_PARAMETER , engine, engineConfiguration
#endif /* GLOBAL_H_ */

View File

@ -58,7 +58,7 @@ void testFuelMap(void) {
// because all the correction tables are zero
printf("*************************************************** getRunningFuel 1\r\n");
float baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(&eth.engine));
float baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
assertEqualsM("base fuel", 5.0, getRunningFuel(baseFuel, 5 PASS_ENGINE_PARAMETER));
printf("*************************************************** setting IAT table\r\n");
@ -87,7 +87,7 @@ void testFuelMap(void) {
// 1005 * 2 for IAT correction
printf("*************************************************** getRunningFuel 2\r\n");
baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(&eth.engine));
baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
assertEqualsM("v1", 30150, getRunningFuel(baseFuel, 5 PASS_ENGINE_PARAMETER));
testMafValue = 0;

View File

@ -404,13 +404,13 @@ static void testRpmCalculator(void) {
static MainTriggerCallback triggerCallbackInstance;
triggerCallbackInstance.init(&eth.engine, ec2);
eth.triggerCentral.addEventListener((ShaftPositionListener)&mainTriggerCallback, "main loop", &eth.engine);
eth.triggerCentral.addEventListener(mainTriggerCallback, "main loop", &eth.engine);
// engine.rpmCalculator = &eth.rpmState;
prepareTimingMap();
timeNow += 5000; // 5ms
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_UP);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
assertEqualsM("index #2", 0, eth.triggerCentral.triggerState.getCurrentIndex());
assertEqualsM("queue size", 6, schedulingQueue.size());
assertEqualsM("ev 1", 246444, schedulingQueue.getForUnitText(0)->momentX);
@ -418,11 +418,11 @@ static void testRpmCalculator(void) {
schedulingQueue.clear();
timeNow += 5000;
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_DOWN);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
timeNow += 5000; // 5ms
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_UP);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
timeNow += 5000;
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_DOWN);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
assertEqualsM("index #3", 3, eth.triggerCentral.triggerState.getCurrentIndex());
assertEqualsM("queue size 3", 6, schedulingQueue.size());
assertEqualsM("ev 3", 259777, schedulingQueue.getForUnitText(0)->momentX);
@ -432,24 +432,24 @@ static void testRpmCalculator(void) {
schedulingQueue.clear();
timeNow += 5000;
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_DOWN);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
timeNow += 5000; // 5ms
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_UP);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
timeNow += 5000; // 5ms
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_UP);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
assertEqualsM("index #4", 6, eth.triggerCentral.triggerState.getCurrentIndex());
assertEqualsM("queue size 4", 6, schedulingQueue.size());
assertEqualsM("4/0", 273111, schedulingQueue.getForUnitText(0)->momentX);
schedulingQueue.clear();
timeNow += 5000;
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_DOWN);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
assertEqualsM("queue size 5", 0, schedulingQueue.size());
// assertEqualsM("5/1", 284500, schedulingQueue.getForUnitText(0)->momentUs);
schedulingQueue.clear();
timeNow += 5000; // 5ms
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_UP);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
assertEqualsM("queue size 6", 6, schedulingQueue.size());
assertEqualsM("6/0", 286444, schedulingQueue.getForUnitText(0)->momentX);
assertEqualsM("6/1", 285944, schedulingQueue.getForUnitText(1)->momentX);
@ -457,12 +457,12 @@ static void testRpmCalculator(void) {
schedulingQueue.clear();
timeNow += 5000;
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_DOWN);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
assertEqualsM("queue size 7", 0, schedulingQueue.size());
schedulingQueue.clear();
timeNow += 5000; // 5ms
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_UP);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
assertEqualsM("queue size 8", 6, schedulingQueue.size());
assertEqualsM("8/0", 299777, schedulingQueue.getForUnitText(0)->momentX);
assertEqualsM("8/1", 299277, schedulingQueue.getForUnitText(1)->momentX);
@ -471,12 +471,12 @@ static void testRpmCalculator(void) {
schedulingQueue.clear();
timeNow += 5000;
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_DOWN);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
assertEqualsM("queue size 9", 0, schedulingQueue.size());
schedulingQueue.clear();
timeNow += 5000; // 5ms
eth.triggerCentral.handleShaftSignal(&eth.engine, SHAFT_PRIMARY_UP);
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
assertEqualsM("queue size 10", 0, schedulingQueue.size());
schedulingQueue.clear();
}