auto-sync

This commit is contained in:
rusEfi 2014-11-07 22:03:53 -06:00
parent 3ecd2425d5
commit 06cc8915ef
16 changed files with 40 additions and 42 deletions

View File

@ -174,7 +174,7 @@ void printState(Engine *engine, int currentCkpEventCounter) {
// debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2); // debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2);
// debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2); // debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2);
debugFloat(&logger, "fuel_lag", getInjectorLag(engineConfiguration, getVBatt(engineConfiguration)), 2); debugFloat(&logger, "fuel_lag", getInjectorLag(engineConfiguration, getVBatt(engineConfiguration)), 2);
debugFloat(&logger, "fuel", getFuelMs(rpm, engine), 2); debugFloat(&logger, "fuel", getFuelMs(rpm PASS_ENGINE_PARAMETER), 2);
debugFloat(&logger, "timing", getAdvance(engineConfiguration, rpm, engineLoad), 2); debugFloat(&logger, "timing", getAdvance(engineConfiguration, rpm, engineLoad), 2);

View File

@ -45,8 +45,6 @@ float getAccelEnrichment(void) {
#if EFI_PROD_CODE #if EFI_PROD_CODE
static THD_WORKING_AREA(aeThreadStack, UTILITY_THREAD_STACK_SIZE); static THD_WORKING_AREA(aeThreadStack, UTILITY_THREAD_STACK_SIZE);
extern engine_configuration_s *engineConfiguration;
static msg_t DiffEnrichmentThread(int param) { static msg_t DiffEnrichmentThread(int param) {
chRegSetThreadName("Diff Enrichment"); chRegSetThreadName("Diff Enrichment");
while (TRUE) { while (TRUE) {

View File

@ -37,6 +37,10 @@ void Engine::onTriggerEvent(uint64_t nowUs) {
lastTriggerEventTimeUs = nowUs; lastTriggerEventTimeUs = nowUs;
} }
Engine::Engine() {
rpmCalculator = NULL;
}
void Engine::init() { void Engine::init() {
#if EFI_PROD_CODE || EFI_SIMULATOR #if EFI_PROD_CODE || EFI_SIMULATOR
initLogging(&logger, "engine"); initLogging(&logger, "engine");

View File

@ -26,6 +26,7 @@ class RpmCalculator;
class Engine { class Engine {
public: public:
Engine();
void init(); void init();
RpmCalculator *rpmCalculator; RpmCalculator *rpmCalculator;
engine_configuration_s *engineConfiguration; engine_configuration_s *engineConfiguration;

View File

@ -41,6 +41,8 @@
#include "accel_enrichment.h" #include "accel_enrichment.h"
#endif /* EFI_ACCEL_ENRICHMENT */ #endif /* EFI_ACCEL_ENRICHMENT */
EXTERN_ENGINE;
float getBaseFuel(Engine *engine, int rpm) { float getBaseFuel(Engine *engine, int rpm) {
if (engine->engineConfiguration->algorithm == LM_SPEED_DENSITY) { if (engine->engineConfiguration->algorithm == LM_SPEED_DENSITY) {
return getSpeedDensityFuel(engine, rpm); return getSpeedDensityFuel(engine, rpm);
@ -71,8 +73,7 @@ static int getNumberOfInjections(engine_configuration_s const *engineConfigurati
/** /**
* @returns Length of fuel injection, in milliseconds * @returns Length of fuel injection, in milliseconds
*/ */
float getFuelMs(int rpm, Engine *engine) { float getFuelMs(int rpm DECLATE_ENGINE_PARAMETER) {
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
float theoreticalInjectionLength; float theoreticalInjectionLength;
if (isCrankingR(rpm)) { if (isCrankingR(rpm)) {
theoreticalInjectionLength = getCrankingFuel(engine) / getNumberOfInjections(engineConfiguration, engineConfiguration->crankingInjectionMode); theoreticalInjectionLength = getCrankingFuel(engine) / getNumberOfInjections(engineConfiguration, engineConfiguration->crankingInjectionMode);

View File

@ -20,6 +20,6 @@ float getCltCorrection(engine_configuration_s *engineConfiguration, float clt);
float getRunningFuel(float baseFuel, Engine *engine, int rpm); float getRunningFuel(float baseFuel, Engine *engine, int rpm);
float getCrankingFuel(Engine *engine); float getCrankingFuel(Engine *engine);
float getCrankingFuel3(engine_configuration_s *engineConfiguration, float coolantTemperature, uint32_t revolutionCounterSinceStart); float getCrankingFuel3(engine_configuration_s *engineConfiguration, float coolantTemperature, uint32_t revolutionCounterSinceStart);
float getFuelMs(int rpm, Engine *engine); float getFuelMs(int rpm DECLATE_ENGINE_PARAMETER);
#endif /* FUEL_MAP_H_ */ #endif /* FUEL_MAP_H_ */

View File

@ -23,12 +23,9 @@
class MainTriggerCallback { class MainTriggerCallback {
public: public:
// MainTriggerCallback();
void init(Engine *engine, engine_configuration2_s *engineConfiguration2); void init(Engine *engine, engine_configuration2_s *engineConfiguration2);
Engine *engine; Engine *engine;
engine_configuration_s *engineConfiguration;
engine_configuration2_s *engineConfiguration2;
}; };
void initMainEventListener(Engine *engine, engine_configuration2_s *engineConfiguration2); void initMainEventListener(Engine *engine, engine_configuration2_s *engineConfiguration2);

View File

@ -41,7 +41,7 @@
static histogram_s waveChartHisto; static histogram_s waveChartHisto;
#endif #endif
extern engine_configuration_s *engineConfiguration; EXTERN_ENGINE;
/** /**
* This is the number of events in the digital chart which would be displayed * This is the number of events in the digital chart which would be displayed

View File

@ -32,7 +32,7 @@
static Logging logger; static Logging logger;
extern engine_configuration_s *engineConfiguration; EXTERN_ENGINE;
extern board_configuration_s *boardConfiguration; extern board_configuration_s *boardConfiguration;
static bool_t isRunningBench = false; static bool_t isRunningBench = false;

View File

@ -17,7 +17,7 @@
#include "efiGpio.h" #include "efiGpio.h"
#include "svnversion.h" #include "svnversion.h"
extern engine_configuration_s *engineConfiguration; EXTERN_ENGINE;
#define LCD_WIDTH 20 #define LCD_WIDTH 20
// this value should be even // this value should be even

View File

@ -20,8 +20,7 @@
#define LIMPING_MODE_IAT_TEMPERATURE 30.0f #define LIMPING_MODE_IAT_TEMPERATURE 30.0f
#define LIMPING_MODE_CLT_TEMPERATURE 70.0f #define LIMPING_MODE_CLT_TEMPERATURE 70.0f
extern engine_configuration_s *engineConfiguration; EXTERN_ENGINE;
extern engine_configuration2_s *engineConfiguration2;
static bool initialized = false; static bool initialized = false;

View File

@ -81,8 +81,8 @@ static INLINE void handleFuelInjectionEvent(ActuatorEvent *event, int rpm DECLAT
/** /**
* todo: we do not really need to calculate fuel for each individual cylinder * todo: we do not really need to calculate fuel for each individual cylinder
*/ */
float fuelMs = getFuelMs(rpm, engine) float fuelMs = getFuelMs(rpm PASS_ENGINE_PARAMETER)
* engine->engineConfiguration->globalFuelCorrection; * engineConfiguration->globalFuelCorrection;
if (cisnan(fuelMs)) { if (cisnan(fuelMs)) {
warning(OBD_PCM_Processor_Fault, "NaN injection pulse"); warning(OBD_PCM_Processor_Fault, "NaN injection pulse");
return; return;
@ -109,7 +109,6 @@ static INLINE void handleFuel(uint32_t eventIndex, int rpm DECLATE_ENGINE_PARAME
efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#3"); efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#3");
efiAssertVoid(eventIndex < engine->engineConfiguration2->triggerShape.getLength(), "event index"); efiAssertVoid(eventIndex < engine->engineConfiguration2->triggerShape.getLength(), "event index");
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
/** /**
* Ignition events are defined by addFuelEvents() according to selected * Ignition events are defined by addFuelEvents() according to selected
* fueling strategy * fueling strategy
@ -131,7 +130,6 @@ static INLINE void handleFuel(uint32_t eventIndex, int rpm DECLATE_ENGINE_PARAME
static INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *iEvent, static INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *iEvent,
int rpm DECLATE_ENGINE_PARAMETER) { int rpm DECLATE_ENGINE_PARAMETER) {
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
float dwellMs = getSparkDwellMsT(engineConfiguration, rpm); float dwellMs = getSparkDwellMsT(engineConfiguration, rpm);
@ -241,14 +239,14 @@ void showMainHistogram(void) {
* This is the main trigger event handler. * This is the main trigger event handler.
* Both injection and ignition are controlled from this method. * Both injection and ignition are controlled from this method.
*/ */
void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTriggerCallback *mainTriggerCallback) { void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTriggerCallback *mtc) {
Engine *engine = mtc->engine;
(void) ckpSignalType; (void) ckpSignalType;
efiAssertVoid(eventIndex < 2 * mainTriggerCallback->engineConfiguration2->triggerShape.shaftPositionEventCount, efiAssertVoid(eventIndex < 2 * engine->engineConfiguration2->triggerShape.shaftPositionEventCount,
"event index"); "event index");
efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#2"); efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#2");
int rpm = getRpmE(mainTriggerCallback->engine); int rpm = getRpmE(engine);
// int rpm = getRpmE(&engine);
if (rpm == 0) { if (rpm == 0) {
// this happens while we just start cranking // this happens while we just start cranking
// todo: check for 'trigger->is_synchnonized?' // todo: check for 'trigger->is_synchnonized?'
@ -258,7 +256,7 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
warning(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, "noisy trigger"); warning(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, "noisy trigger");
return; return;
} }
if (rpm > mainTriggerCallback->engineConfiguration->rpmHardLimit) { if (rpm > engine->engineConfiguration->rpmHardLimit) {
warning(OBD_PCM_Processor_Fault, "skipping stroke due to rpm=%d", rpm); warning(OBD_PCM_Processor_Fault, "skipping stroke due to rpm=%d", rpm);
return; return;
} }
@ -271,7 +269,7 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
if (eventIndex == 0) { if (eventIndex == 0) {
if (localVersion.isOld()) if (localVersion.isOld())
prepareOutputSignals(mainTriggerCallback->engine); prepareOutputSignals(engine);
/** /**
* TODO: warning. there is a bit of a hack here, todo: improve. * TODO: warning. there is a bit of a hack here, todo: improve.
@ -285,12 +283,12 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
* Within one engine cycle all cylinders are fired with same timing advance. * Within one engine cycle all cylinders are fired with same timing advance.
* todo: one day we can control cylinders individually * todo: one day we can control cylinders individually
*/ */
float dwellMs = getSparkDwellMsT(mainTriggerCallback->engineConfiguration, rpm); float dwellMs = getSparkDwellMsT(engine->engineConfiguration, rpm);
if (cisnan(dwellMs) || dwellMs < 0) { if (cisnan(dwellMs) || dwellMs < 0) {
firmwareError("invalid dwell: %f at %d", dwellMs, rpm); firmwareError("invalid dwell: %f at %d", dwellMs, rpm);
return; return;
} }
float advance = getAdvance(mainTriggerCallback->engineConfiguration, rpm, getEngineLoadT(mainTriggerCallback->engine)); float advance = getAdvance(engine->engineConfiguration, rpm, getEngineLoadT(engine));
if (cisnan(advance)) { if (cisnan(advance)) {
// error should already be reported // error should already be reported
return; return;
@ -298,18 +296,20 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
float dwellAngle = dwellMs / getOneDegreeTimeMs(rpm); float dwellAngle = dwellMs / getOneDegreeTimeMs(rpm);
initializeIgnitionActions(advance, dwellAngle, mainTriggerCallback->engineConfiguration, initializeIgnitionActions(advance, dwellAngle, engine->engineConfiguration,
mainTriggerCallback->engineConfiguration2, engine->engineConfiguration2,
&mainTriggerCallback->engineConfiguration2->ignitionEvents[revolutionIndex]); &engine->engineConfiguration2->ignitionEvents[revolutionIndex]);
} }
triggerEventsQueue.executeAll(getCrankEventCounter()); triggerEventsQueue.executeAll(getCrankEventCounter());
Engine *engine = mainTriggerCallback->engine; // todo: remove these local variables soon
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
handleFuel(eventIndex, rpm PASS_ENGINE_PARAMETER); handleFuel(eventIndex, rpm PASS_ENGINE_PARAMETER);
handleSpark(eventIndex, rpm, handleSpark(eventIndex, rpm,
&mainTriggerCallback->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER); &engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER);
#if EFI_HISTOGRAMS && EFI_PROD_CODE #if EFI_HISTOGRAMS && EFI_PROD_CODE
int diff = hal_lld_get_counter_value() - beforeCallback; int diff = hal_lld_get_counter_value() - beforeCallback;
if (diff > 0) if (diff > 0)
@ -330,9 +330,6 @@ static void showTriggerHistogram(void) {
void MainTriggerCallback::init(Engine *engine, engine_configuration2_s *engineConfiguration2) { void MainTriggerCallback::init(Engine *engine, engine_configuration2_s *engineConfiguration2) {
efiAssertVoid(engine!=NULL, "engine NULL"); efiAssertVoid(engine!=NULL, "engine NULL");
this->engine = engine; this->engine = engine;
this->engineConfiguration = engine->engineConfiguration;
efiAssertVoid(engineConfiguration!=NULL, "engineConfiguration NULL");
this->engineConfiguration2 = engineConfiguration2;
} }
static void showMainInfo(Engine *engine) { static void showMainInfo(Engine *engine) {
@ -340,7 +337,7 @@ static void showMainInfo(Engine *engine) {
float el = getEngineLoadT(mainTriggerCallbackInstance.engine); float el = getEngineLoadT(mainTriggerCallbackInstance.engine);
#if EFI_PROD_CODE #if EFI_PROD_CODE
scheduleMsg(&logger, "rpm %d engine_load %f", rpm, el); scheduleMsg(&logger, "rpm %d engine_load %f", rpm, el);
scheduleMsg(&logger, "fuel %fms timing %f", getFuelMs(rpm, mainTriggerCallbackInstance.engine), scheduleMsg(&logger, "fuel %fms timing %f", getFuelMs(rpm PASS_ENGINE_PARAMETER),
getAdvance(mainTriggerCallbackInstance.engine->engineConfiguration, rpm, el)); getAdvance(mainTriggerCallbackInstance.engine->engineConfiguration, rpm, el));
#endif #endif
} }
@ -356,7 +353,7 @@ void initMainEventListener(Engine *engine, engine_configuration2_s *engineConfig
initLogging(&logger, "main event handler"); initLogging(&logger, "main event handler");
printMsg(&logger, "initMainLoop: %d", currentTimeMillis()); printMsg(&logger, "initMainLoop: %d", currentTimeMillis());
if (!isInjectionEnabled(mainTriggerCallbackInstance.engineConfiguration)) if (!isInjectionEnabled(mainTriggerCallbackInstance.engine->engineConfiguration))
printMsg(&logger, "!!!!!!!!!!!!!!!!!!! injection disabled"); printMsg(&logger, "!!!!!!!!!!!!!!!!!!! injection disabled");
#endif #endif

View File

@ -48,8 +48,7 @@ int getRpmE(Engine *engine) {
return engine->rpmCalculator->rpm(); return engine->rpmCalculator->rpm();
} }
extern engine_configuration_s *engineConfiguration; EXTERN_ENGINE;
extern engine_configuration2_s *engineConfiguration2;
#if EFI_PROD_CODE || EFI_SIMULATOR #if EFI_PROD_CODE || EFI_SIMULATOR
static Logging logger; static Logging logger;

View File

@ -64,7 +64,8 @@ typedef Thread thread_t;
* On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter * On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter
*/ */
#define EXTERN_ENGINE extern Engine *engine; #define EXTERN_ENGINE extern Engine *engine; \
extern engine_configuration_s *engineConfiguration;
#define DECLATE_ENGINE_PARAMETER #define DECLATE_ENGINE_PARAMETER
#define PASS_ENGINE_PARAMETER #define PASS_ENGINE_PARAMETER

View File

@ -34,7 +34,7 @@ typedef void * Logging;
#define EXTERN_ENGINE #define EXTERN_ENGINE
#define DECLATE_ENGINE_PARAMETER , Engine *engine #define DECLATE_ENGINE_PARAMETER , Engine *engine, engine_configuration_s *engineConfiguration
#define PASS_ENGINE_PARAMETER , engine #define PASS_ENGINE_PARAMETER , engine, engineConfiguration
#endif /* GLOBAL_H_ */ #endif /* GLOBAL_H_ */

View File

@ -86,7 +86,8 @@ typedef VirtualTimer virtual_timer_t;
typedef EventListener event_listener_t; typedef EventListener event_listener_t;
#define THD_WORKING_AREA WORKING_AREA #define THD_WORKING_AREA WORKING_AREA
#define EXTERN_ENGINE extern Engine *engine; #define EXTERN_ENGINE extern Engine *engine; \
extern engine_configuration_s *engineConfiguration;
#define DECLATE_ENGINE_PARAMETER #define DECLATE_ENGINE_PARAMETER
#define PASS_ENGINE_PARAMETER #define PASS_ENGINE_PARAMETER