auto-sync

This commit is contained in:
rusEfi 2014-11-07 21:04:45 -06:00
parent 9af8706443
commit 3ecd2425d5
20 changed files with 138 additions and 102 deletions

View File

@ -14,7 +14,9 @@
#include "engine_math.h" #include "engine_math.h"
#include "signal_executor.h" #include "signal_executor.h"
extern Engine engine; EXTERN_ENGINE;
static AccelEnrichmemnt instance; static AccelEnrichmemnt instance;
void AccelEnrichmemnt::updateDiffEnrichment(engine_configuration_s *engineConfiguration, float engineLoad) { void AccelEnrichmemnt::updateDiffEnrichment(engine_configuration_s *engineConfiguration, float engineLoad) {

View File

@ -84,10 +84,14 @@ static engine_configuration2_s ec2 CCM_OPTIONAL
; ;
engine_configuration2_s * engineConfiguration2 = &ec2; engine_configuration2_s * engineConfiguration2 = &ec2;
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
/** /**
* todo: this should probably become 'static', i.e. private, and propagated around explicitly? * todo: this should probably become 'static', i.e. private, and propagated around explicitly?
*/ */
Engine engine; static Engine _engine;
Engine * engine = &_engine;
#endif
/** /**
* I am not sure if this needs to be configurable. * I am not sure if this needs to be configurable.
@ -123,9 +127,9 @@ static void updateErrorCodes(void) {
/** /**
* technically we can set error codes right inside the getMethods, but I a bit on a fence about it * technically we can set error codes right inside the getMethods, but I a bit on a fence about it
*/ */
setError(isValidIntakeAirTemperature(getIntakeAirTemperature(&engine)), setError(isValidIntakeAirTemperature(getIntakeAirTemperature(engine)),
OBD_Intake_Air_Temperature_Circuit_Malfunction); OBD_Intake_Air_Temperature_Circuit_Malfunction);
setError(isValidCoolantTemperature(getCoolantTemperature(&engine)), setError(isValidCoolantTemperature(getCoolantTemperature(engine)),
OBD_Engine_Coolant_Temperature_Circuit_Malfunction); OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
} }
@ -137,9 +141,9 @@ static void fanRelayControl(void) {
int newValue; int newValue;
if (isCurrentlyOn) { if (isCurrentlyOn) {
// if the fan is already on, we keep it on till the 'fanOff' temperature // if the fan is already on, we keep it on till the 'fanOff' temperature
newValue = getCoolantTemperature(&engine) > engineConfiguration->fanOffTemperature; newValue = getCoolantTemperature(engine) > engineConfiguration->fanOffTemperature;
} else { } else {
newValue = getCoolantTemperature(&engine) > engineConfiguration->fanOnTemperature; newValue = getCoolantTemperature(engine) > engineConfiguration->fanOnTemperature;
} }
if (isCurrentlyOn != newValue) { if (isCurrentlyOn != newValue) {

View File

@ -25,7 +25,7 @@
static bool needToWriteConfiguration = false; static bool needToWriteConfiguration = false;
extern Engine engine; EXTERN_ENGINE;
static Logging logger; static Logging logger;
extern persistent_config_container_s persistentState; extern persistent_config_container_s persistentState;
@ -63,6 +63,7 @@ void writeToFlashIfPending() {
void writeToFlash(void) { void writeToFlash(void) {
#if EFI_INTERNAL_FLASH #if EFI_INTERNAL_FLASH
scheduleMsg(&logger, " !!!!!!!!!!!!!!!!!!!! BE SURE NOT WRITE WITH IGNITION ON !!!!!!!!!!!!!!!!!!!!");
persistentState.size = PERSISTENT_SIZE; persistentState.size = PERSISTENT_SIZE;
persistentState.version = FLASH_DATA_VERSION; persistentState.version = FLASH_DATA_VERSION;
scheduleMsg(&logger, "flash compatible with %d", persistentState.version); scheduleMsg(&logger, "flash compatible with %d", persistentState.version);
@ -88,7 +89,7 @@ static bool isValidCrc(persistent_config_container_s *state) {
} }
static void doResetConfiguration(void) { static void doResetConfiguration(void) {
resetConfigurationExt(&logger, engineConfiguration->engineType, &engine); resetConfigurationExt(&logger, engineConfiguration->engineType, engine);
} }
static bool hasValidEngineType(engine_configuration_s *engineConfiguration) { static bool hasValidEngineType(engine_configuration_s *engineConfiguration) {
@ -102,16 +103,16 @@ void readFromFlash(void) {
if (!isValidCrc(&persistentState)) { if (!isValidCrc(&persistentState)) {
printMsg(&logger, "Need to reset flash to default due to CRC"); printMsg(&logger, "Need to reset flash to default due to CRC");
resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, &engine); resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, engine);
} else if (persistentState.version == FLASH_DATA_VERSION && persistentState.size == PERSISTENT_SIZE) { } else if (persistentState.version == FLASH_DATA_VERSION && persistentState.size == PERSISTENT_SIZE) {
printMsg(&logger, "Got valid configuration from flash!"); printMsg(&logger, "Got valid configuration from flash!");
applyNonPersistentConfiguration(&logger, &engine); applyNonPersistentConfiguration(&logger, engine);
} else if (hasValidEngineType(engineConfiguration)) { } else if (hasValidEngineType(engineConfiguration)) {
printMsg(&logger, "Resetting but saving engine type [%d]", engineConfiguration->engineType); printMsg(&logger, "Resetting but saving engine type [%d]", engineConfiguration->engineType);
resetConfigurationExt(&logger, engineConfiguration->engineType, &engine); resetConfigurationExt(&logger, engineConfiguration->engineType, engine);
} else { } else {
printMsg(&logger, "Need to reset flash to default due to version change"); printMsg(&logger, "Need to reset flash to default due to version change");
resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, &engine); resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, engine);
} }
// we can only change the state after the CRC check // we can only change the state after the CRC check
engineConfiguration->firmwareVersion = getRusEfiVersion(); engineConfiguration->firmwareVersion = getRusEfiVersion();

View File

@ -43,7 +43,7 @@ extern engine_configuration_s *engineConfiguration;
static volatile int idleSwitchState; static volatile int idleSwitchState;
static Logging logger; static Logging logger;
extern Engine engine; EXTERN_ENGINE;
static SimplePwm idleValvePwm; static SimplePwm idleValvePwm;

View File

@ -64,7 +64,7 @@ static volatile int mapMeasurementsCounter = 0;
*/ */
static float v_averagedMapValue; static float v_averagedMapValue;
extern Engine engine; EXTERN_ENGINE;
extern engine_configuration_s *engineConfiguration; extern engine_configuration_s *engineConfiguration;

View File

@ -21,7 +21,7 @@ extern engine_configuration_s *engineConfiguration;
static Logging logger; static Logging logger;
extern Engine engine; EXTERN_ENGINE;
static THD_WORKING_AREA(maThreadStack, UTILITY_THREAD_STACK_SIZE); static THD_WORKING_AREA(maThreadStack, UTILITY_THREAD_STACK_SIZE);

View File

@ -54,7 +54,7 @@ int isCrankingRT(engine_configuration_s *engineConfiguration, int rpm);
#define isCrankingR(rpm) isCrankingRT(engineConfiguration, rpm) #define isCrankingR(rpm) isCrankingRT(engineConfiguration, rpm)
float getEngineLoadT(Engine *engine); float getEngineLoadT(Engine *engine);
#define getEngineLoad() getEngineLoadT(&engine) #define getEngineLoad() getEngineLoadT(engine)
float getSparkDwellMsT(engine_configuration_s *engineConfiguration, int rpm); float getSparkDwellMsT(engine_configuration_s *engineConfiguration, int rpm);

View File

@ -182,17 +182,17 @@ static void doPrintConfiguration(Engine *engine) {
printConfiguration(engineConfiguration, engine->engineConfiguration2); printConfiguration(engineConfiguration, engine->engineConfiguration2);
} }
extern Engine engine; EXTERN_ENGINE;
static void setFixedModeTiming(int value) { static void setFixedModeTiming(int value) {
engineConfiguration->fixedModeTiming = value; engineConfiguration->fixedModeTiming = value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
} }
static void setTimingMode(int value) { static void setTimingMode(int value) {
engineConfiguration->timingMode = (timing_mode_e) value; engineConfiguration->timingMode = (timing_mode_e) value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
} }
@ -202,13 +202,13 @@ static void setIdleMode(int mode) {
void setEngineType(int value) { void setEngineType(int value) {
engineConfiguration->engineType = (engine_type_e) value; engineConfiguration->engineType = (engine_type_e) value;
resetConfigurationExt(&logger, (engine_type_e) value, &engine); resetConfigurationExt(&logger, (engine_type_e) value, engine);
#if EFI_INTERNAL_FLASH #if EFI_INTERNAL_FLASH
writeToFlash(); writeToFlash();
// scheduleReset(); // scheduleReset();
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setIdleSolenoidFrequency(int value) { static void setIdleSolenoidFrequency(int value) {
@ -217,49 +217,49 @@ static void setIdleSolenoidFrequency(int value) {
static void setInjectionPinMode(int value) { static void setInjectionPinMode(int value) {
boardConfiguration->injectionPinMode = (pin_output_mode_e) value; boardConfiguration->injectionPinMode = (pin_output_mode_e) value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setIgnitionPinMode(int value) { static void setIgnitionPinMode(int value) {
boardConfiguration->ignitionPinMode = (pin_output_mode_e) value; boardConfiguration->ignitionPinMode = (pin_output_mode_e) value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setIdlePinMode(int value) { static void setIdlePinMode(int value) {
boardConfiguration->idleValvePinMode = (pin_output_mode_e) value; boardConfiguration->idleValvePinMode = (pin_output_mode_e) value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setInjectionOffset(int value) { static void setInjectionOffset(int value) {
engineConfiguration->injectionOffset = value; engineConfiguration->injectionOffset = value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
} }
static void setIgnitionOffset(int value) { static void setIgnitionOffset(int value) {
engineConfiguration->ignitionOffset = value; engineConfiguration->ignitionOffset = value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
} }
static void setFuelPumpPinMode(int value) { static void setFuelPumpPinMode(int value) {
boardConfiguration->fuelPumpPinMode = (pin_output_mode_e) value; boardConfiguration->fuelPumpPinMode = (pin_output_mode_e) value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setMalfunctionIndicatorPinMode(int value) { static void setMalfunctionIndicatorPinMode(int value) {
boardConfiguration->malfunctionIndicatorPinMode = (pin_output_mode_e) value; boardConfiguration->malfunctionIndicatorPinMode = (pin_output_mode_e) value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setAnalogChartMode(int value) { static void setAnalogChartMode(int value) {
engineConfiguration->analogChartMode = value; engineConfiguration->analogChartMode = value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setRpmMultiplier(int value) { static void setRpmMultiplier(int value) {
engineConfiguration->rpmMultiplier = value; engineConfiguration->rpmMultiplier = value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static char pinNameBuffer[16]; static char pinNameBuffer[16];
@ -314,12 +314,12 @@ static void printTPSInfo(void) {
} }
static void printTemperatureInfo(void) { static void printTemperatureInfo(void) {
printThermistor("CLT", &engine.clt); printThermistor("CLT", &engine->clt);
if (!isValidCoolantTemperature(getCoolantTemperature(&engine))) { if (!isValidCoolantTemperature(getCoolantTemperature(engine))) {
scheduleMsg(&logger, "CLT sensing error"); scheduleMsg(&logger, "CLT sensing error");
} }
printThermistor("IAT", &engine.iat); printThermistor("IAT", &engine->iat);
if (!isValidIntakeAirTemperature(getIntakeAirTemperature(&engine))) { if (!isValidIntakeAirTemperature(getIntakeAirTemperature(engine))) {
scheduleMsg(&logger, "IAT sensing error"); scheduleMsg(&logger, "IAT sensing error");
} }
@ -330,22 +330,22 @@ static void printTemperatureInfo(void) {
static void setCrankingRpm(int value) { static void setCrankingRpm(int value) {
engineConfiguration->crankingSettings.crankingRpm = value; engineConfiguration->crankingSettings.crankingRpm = value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setAlgorithm(int value) { static void setAlgorithm(int value) {
engineConfiguration->algorithm = (engine_load_mode_e) value; engineConfiguration->algorithm = (engine_load_mode_e) value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setFiringOrder(int value) { static void setFiringOrder(int value) {
engineConfiguration->firingOrder = (firing_order_e) value; engineConfiguration->firingOrder = (firing_order_e) value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setRpmHardLimit(int value) { static void setRpmHardLimit(int value) {
engineConfiguration->rpmHardLimit = value; engineConfiguration->rpmHardLimit = value;
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setCrankingFuel(float timeMs) { static void setCrankingFuel(float timeMs) {
@ -356,50 +356,50 @@ static void setCrankingFuel(float timeMs) {
static void setGlobalTriggerAngleOffset(int value) { static void setGlobalTriggerAngleOffset(int value) {
engineConfiguration->globalTriggerAngleOffset = value; engineConfiguration->globalTriggerAngleOffset = value;
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setCrankingTimingAngle(float value) { static void setCrankingTimingAngle(float value) {
engineConfiguration->crankingTimingAngle = value; engineConfiguration->crankingTimingAngle = value;
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setCrankingInjectionMode(int value) { static void setCrankingInjectionMode(int value) {
engineConfiguration->crankingInjectionMode = (injection_mode_e) value; engineConfiguration->crankingInjectionMode = (injection_mode_e) value;
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setInjectionMode(int value) { static void setInjectionMode(int value) {
engineConfiguration->injectionMode = (injection_mode_e) value; engineConfiguration->injectionMode = (injection_mode_e) value;
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setIgnitionMode(int value) { static void setIgnitionMode(int value) {
engineConfiguration->ignitionMode = (ignition_mode_e) value; engineConfiguration->ignitionMode = (ignition_mode_e) value;
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setTriggerType(int value) { static void setTriggerType(int value) {
engineConfiguration->triggerConfig.triggerType = (trigger_type_e) value; engineConfiguration->triggerConfig.triggerType = (trigger_type_e) value;
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setToothedWheel(int total, int skipped) { static void setToothedWheel(int total, int skipped) {
setToothedWheelConfiguration(&engineConfiguration2->triggerShape, total, skipped, engineConfiguration); setToothedWheelConfiguration(&engineConfiguration2->triggerShape, total, skipped, engineConfiguration);
// initializeTriggerShape(&logger, engineConfiguration, engineConfiguration2); // initializeTriggerShape(&logger, engineConfiguration, engineConfiguration2);
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setCrankingChargeAngle(float value) { static void setCrankingChargeAngle(float value) {
engineConfiguration->crankingChargeAngle = value; engineConfiguration->crankingChargeAngle = value;
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
doPrintConfiguration(&engine); doPrintConfiguration(engine);
} }
static void setGlobalFuelCorrection(float value) { static void setGlobalFuelCorrection(float value) {

View File

@ -54,6 +54,8 @@
#include "event_queue.h" #include "event_queue.h"
#include "engine.h" #include "engine.h"
EXTERN_ENGINE;
static LocalVersionHolder localVersion; static LocalVersionHolder localVersion;
static MainTriggerCallback mainTriggerCallbackInstance; static MainTriggerCallback mainTriggerCallbackInstance;
@ -75,12 +77,12 @@ static cyclic_buffer ignitionErrorDetection;
static Logging logger; static Logging logger;
static void handleFuelInjectionEvent(MainTriggerCallback *mainTriggerCallback, ActuatorEvent *event, int rpm) { static INLINE void handleFuelInjectionEvent(ActuatorEvent *event, int rpm DECLATE_ENGINE_PARAMETER) {
/** /**
* 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, mainTriggerCallback->engine) float fuelMs = getFuelMs(rpm, engine)
* mainTriggerCallback->engineConfiguration->globalFuelCorrection; * engine->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;
@ -90,7 +92,7 @@ static void handleFuelInjectionEvent(MainTriggerCallback *mainTriggerCallback, A
return; return;
} }
if (mainTriggerCallback->engine->isCylinderCleanupMode) if (engine->isCylinderCleanupMode)
return; return;
float delay = getOneDegreeTimeMs(rpm) * event->position.angleOffset; float delay = getOneDegreeTimeMs(rpm) * event->position.angleOffset;
@ -101,11 +103,11 @@ static void handleFuelInjectionEvent(MainTriggerCallback *mainTriggerCallback, A
scheduleOutput(event->actuator, delay, fuelMs); scheduleOutput(event->actuator, delay, fuelMs);
} }
static void handleFuel(Engine *engine, MainTriggerCallback *mainTriggerCallback, uint32_t eventIndex, int rpm) { static INLINE void handleFuel(uint32_t eventIndex, int rpm DECLATE_ENGINE_PARAMETER) {
if (!isInjectionEnabled(mainTriggerCallback->engineConfiguration)) if (!isInjectionEnabled(engine->engineConfiguration))
return; return;
efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#3"); efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#3");
efiAssertVoid(eventIndex < mainTriggerCallback->engineConfiguration2->triggerShape.getLength(), "event index"); efiAssertVoid(eventIndex < engine->engineConfiguration2->triggerShape.getLength(), "event index");
engine_configuration_s *engineConfiguration = engine->engineConfiguration; engine_configuration_s *engineConfiguration = engine->engineConfiguration;
/** /**
@ -114,8 +116,8 @@ static void handleFuel(Engine *engine, MainTriggerCallback *mainTriggerCallback,
*/ */
FuelSchedule *fs = FuelSchedule *fs =
isCrankingR(rpm) ? isCrankingR(rpm) ?
&mainTriggerCallback->engineConfiguration2->crankingInjectionEvents : &engine->engineConfiguration2->crankingInjectionEvents :
&mainTriggerCallback->engineConfiguration2->injectionEvents; &engine->engineConfiguration2->injectionEvents;
ActuatorEventList *source = &fs->events; ActuatorEventList *source = &fs->events;
@ -123,14 +125,14 @@ static void handleFuel(Engine *engine, MainTriggerCallback *mainTriggerCallback,
ActuatorEvent *event = &source->events[i]; ActuatorEvent *event = &source->events[i];
if (event->position.eventIndex != eventIndex) if (event->position.eventIndex != eventIndex)
continue; continue;
handleFuelInjectionEvent(mainTriggerCallback, event, rpm); handleFuelInjectionEvent(event, rpm PASS_ENGINE_PARAMETER);
} }
} }
static void handleSparkEvent(MainTriggerCallback *mainTriggerCallback, uint32_t eventIndex, IgnitionEvent *iEvent, static INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *iEvent,
int rpm) { int rpm DECLATE_ENGINE_PARAMETER) {
engine_configuration_s *engineConfiguration = mainTriggerCallback->engineConfiguration; engine_configuration_s *engineConfiguration = engine->engineConfiguration;
engine_configuration2_s *engineConfiguration2 = mainTriggerCallback->engineConfiguration2; engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
float dwellMs = getSparkDwellMsT(engineConfiguration, rpm); float dwellMs = getSparkDwellMsT(engineConfiguration, rpm);
if (cisnan(dwellMs) || dwellMs < 0) { if (cisnan(dwellMs) || dwellMs < 0) {
@ -192,9 +194,9 @@ static void handleSparkEvent(MainTriggerCallback *mainTriggerCallback, uint32_t
} }
} }
static void handleSpark(MainTriggerCallback *mainTriggerCallback, uint32_t eventIndex, int rpm, static INLINE void handleSpark(uint32_t eventIndex, int rpm,
IgnitionEventList *list) { IgnitionEventList *list DECLATE_ENGINE_PARAMETER) {
if (!isValidRpm(rpm) || !mainTriggerCallback->engineConfiguration->isIgnitionEnabled) if (!isValidRpm(rpm) || !engine->engineConfiguration->isIgnitionEnabled)
return; // this might happen for instance in case of a single trigger event after a pause return; // this might happen for instance in case of a single trigger event after a pause
/** /**
@ -223,7 +225,7 @@ static void handleSpark(MainTriggerCallback *mainTriggerCallback, uint32_t event
IgnitionEvent *event = &list->events[i]; IgnitionEvent *event = &list->events[i];
if (event->dwellPosition.eventIndex != eventIndex) if (event->dwellPosition.eventIndex != eventIndex)
continue; continue;
handleSparkEvent(mainTriggerCallback, eventIndex, event, rpm); handleSparkEvent(eventIndex, event, rpm PASS_ENGINE_PARAMETER);
} }
} }
@ -303,9 +305,11 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
triggerEventsQueue.executeAll(getCrankEventCounter()); triggerEventsQueue.executeAll(getCrankEventCounter());
handleFuel(mainTriggerCallback->engine, mainTriggerCallback, eventIndex, rpm); Engine *engine = mainTriggerCallback->engine;
handleSpark(mainTriggerCallback, eventIndex, rpm,
&mainTriggerCallback->engineConfiguration2->ignitionEvents[revolutionIndex]); handleFuel(eventIndex, rpm PASS_ENGINE_PARAMETER);
handleSpark(eventIndex, rpm,
&mainTriggerCallback->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)

View File

@ -53,7 +53,7 @@ extern engine_configuration2_s *engineConfiguration2;
#if EFI_PROD_CODE || EFI_SIMULATOR #if EFI_PROD_CODE || EFI_SIMULATOR
static Logging logger; static Logging logger;
extern Engine engine; EXTERN_ENGINE;
#endif #endif
RpmCalculator::RpmCalculator() { RpmCalculator::RpmCalculator() {
@ -117,7 +117,7 @@ bool isCrankingE(Engine *engine) {
* WARNING: this is a heavy method because 'getRpm()' is relatively heavy * WARNING: this is a heavy method because 'getRpm()' is relatively heavy
*/ */
bool isCranking(void) { bool isCranking(void) {
return isCrankingE(&engine); return isCrankingE(engine);
} }
#endif #endif
@ -223,7 +223,7 @@ float getCrankshaftAngleNt(uint64_t timeNt) {
void initRpmCalculator(void) { void initRpmCalculator(void) {
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
initLogging(&logger, "rpm calc"); initLogging(&logger, "rpm calc");
engine.rpmCalculator = &rpmState; engine->rpmCalculator = &rpmState;
tdcScheduler[0].name = "tdc0"; tdcScheduler[0].name = "tdc0";
tdcScheduler[1].name = "tdc1"; tdcScheduler[1].name = "tdc1";

View File

@ -47,7 +47,7 @@ private:
volatile uint32_t revolutionCounterSinceStart; volatile uint32_t revolutionCounterSinceStart;
}; };
#define getRpm() getRpmE(&engine) #define getRpm() getRpmE(engine)
/** /**
* @brief Current RPM * @brief Current RPM

View File

@ -58,11 +58,11 @@ void addTriggerEventListener(ShaftPositionListener listener, const char *name, v
} }
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
extern Engine engine; EXTERN_ENGINE;
void hwHandleShaftSignal(trigger_event_e signal) { void hwHandleShaftSignal(trigger_event_e signal) {
efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#8"); efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#8");
triggerCentral.handleShaftSignal(&engine, signal); triggerCentral.handleShaftSignal(engine, signal);
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */

View File

@ -70,7 +70,7 @@ static bool isEmulating = true;
static Logging logger; static Logging logger;
static LocalVersionHolder localVersion; static LocalVersionHolder localVersion;
extern Engine engine; EXTERN_ENGINE;
void setTriggerEmulatorRPM(int rpm, Engine *engine) { void setTriggerEmulatorRPM(int rpm, Engine *engine) {
engineConfiguration->bc.triggerSimulatorFrequency = rpm; engineConfiguration->bc.triggerSimulatorFrequency = rpm;
@ -92,7 +92,7 @@ static void updateTriggerShapeIfNeeded(PwmConfig *state) {
scheduleMsg(&logger, "Stimulator: updating trigger shape: %d/%d %d", localVersion.getVersion(), scheduleMsg(&logger, "Stimulator: updating trigger shape: %d/%d %d", localVersion.getVersion(),
getGlobalConfigurationVersion(), currentTimeMillis()); getGlobalConfigurationVersion(), currentTimeMillis());
applyNonPersistentConfiguration(&logger, &engine); applyNonPersistentConfiguration(&logger, engine);
trigger_shape_s *s = &engineConfiguration2->triggerShape; trigger_shape_s *s = &engineConfiguration2->triggerShape;
int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates, int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates,

View File

@ -24,7 +24,7 @@
#include "engine.h" #include "engine.h"
#include "rpm_calculator.h" #include "rpm_calculator.h"
extern Engine engine; EXTERN_ENGINE;
#define CHART_RESET_DELAY 1 #define CHART_RESET_DELAY 1

View File

@ -50,4 +50,23 @@ typedef Thread thread_t;
#define THD_WORKING_AREA WORKING_AREA #define THD_WORKING_AREA WORKING_AREA
/**
* The following obscurantism is a hack to reduce stack usage, maybe even a questionable performance
* optimization.
*
* rusEfi main processing happends on IRQ so PORT_INT_REQUIRED_STACK has to be pretty large. Problem
* is that PORT_INT_REQUIRED_STACK is included within each user thread stack, thus this large stack multiplies
* and this consumes a lot of valueable RAM. While forcing the comiler to inline helps to some degree,
* it would be even better not to waste stack on passing the parameter.
*
* In the firmware we are using 'extern *Engine' - in the firmware Engine is a signleton
*
* 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 DECLATE_ENGINE_PARAMETER
#define PASS_ENGINE_PARAMETER
#endif /* GLOBAL_H_ */ #endif /* GLOBAL_H_ */

View File

@ -131,7 +131,7 @@ static bool hasFirmwareErrorFlag = FALSE;
extern engine_configuration_s *engineConfiguration; extern engine_configuration_s *engineConfiguration;
extern board_configuration_s *boardConfiguration; extern board_configuration_s *boardConfiguration;
extern engine_configuration2_s *engineConfiguration2; extern engine_configuration2_s *engineConfiguration2;
extern Engine engine; EXTERN_ENGINE;
char *getFirmwareError(void) { char *getFirmwareError(void) {
return (char*)errorMessageBuffer; return (char*)errorMessageBuffer;
@ -141,8 +141,8 @@ void runRusEfi(void) {
msObjectInit(&firmwareErrorMessageStream, errorMessageBuffer, sizeof(errorMessageBuffer), 0); msObjectInit(&firmwareErrorMessageStream, errorMessageBuffer, sizeof(errorMessageBuffer), 0);
// that's dirty, this assignment should be nicer or in a better spot // that's dirty, this assignment should be nicer or in a better spot
engine.engineConfiguration = engineConfiguration; engine->engineConfiguration = engineConfiguration;
engine.engineConfiguration2 = engineConfiguration2; engine->engineConfiguration2 = engineConfiguration2;
engineConfiguration2->engineConfiguration = engineConfiguration; engineConfiguration2->engineConfiguration = engineConfiguration;
@ -159,30 +159,30 @@ void runRusEfi(void) {
initializeConsole(); initializeConsole();
initLogging(&logging, "main"); initLogging(&logging, "main");
engine.init(); engine->init();
addConsoleAction("reset", scheduleReset); addConsoleAction("reset", scheduleReset);
/** /**
* Initialize hardware drivers * Initialize hardware drivers
*/ */
initHardware(&logging, &engine); initHardware(&logging, engine);
initStatusLoop(&engine); initStatusLoop(engine);
/** /**
* Now let's initialize actual engine control logic * Now let's initialize actual engine control logic
* todo: should we initialize some? most? controllers before hardware? * todo: should we initialize some? most? controllers before hardware?
*/ */
initEngineContoller(&engine); initEngineContoller(engine);
#if EFI_PERF_METRICS #if EFI_PERF_METRICS
initTimePerfActions(); initTimePerfActions();
#endif #endif
#if EFI_ENGINE_EMULATOR #if EFI_ENGINE_EMULATOR
initEngineEmulator(&engine); initEngineEmulator(engine);
#endif #endif
startStatusThreads(&engine); startStatusThreads(engine);
print("Running main loop\r\n"); print("Running main loop\r\n");
main_loop_started = TRUE; main_loop_started = TRUE;
@ -195,7 +195,7 @@ void runRusEfi(void) {
#if EFI_CLI_SUPPORT && !EFI_UART_ECHO_TEST_MODE #if EFI_CLI_SUPPORT && !EFI_UART_ECHO_TEST_MODE
// sensor state + all pending messages for our own dev console // sensor state + all pending messages for our own dev console
updateDevConsoleState(&engine); updateDevConsoleState(engine);
#endif /* EFI_CLI_SUPPORT */ #endif /* EFI_CLI_SUPPORT */
chThdSleepMilliseconds(boardConfiguration->consoleLoopPeriod); chThdSleepMilliseconds(boardConfiguration->consoleLoopPeriod);

View File

@ -32,4 +32,9 @@ typedef void * Logging;
#define CCM_OPTIONAL #define CCM_OPTIONAL
#define EXTERN_ENGINE
#define DECLATE_ENGINE_PARAMETER , Engine *engine
#define PASS_ENGINE_PARAMETER , engine
#endif /* GLOBAL_H_ */ #endif /* GLOBAL_H_ */

View File

@ -26,8 +26,6 @@
#include "engine_test_helper.h" #include "engine_test_helper.h"
#include "speed_density.h" #include "speed_density.h"
//Engine engine;
extern int timeNow; extern int timeNow;
extern bool printGapRatio; extern bool printGapRatio;
@ -338,9 +336,6 @@ void testGY6_139QMB(void) {
extern EventQueue schedulingQueue; extern EventQueue schedulingQueue;
// this is a very dirty and sad hack. todo: eliminate
extern Engine engine;
extern int mockTps; extern int mockTps;
static void testStartupFuelPumping(void) { static void testStartupFuelPumping(void) {

View File

@ -85,3 +85,8 @@ void unlockAnyContext(void);
typedef VirtualTimer virtual_timer_t; 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 DECLATE_ENGINE_PARAMETER
#define PASS_ENGINE_PARAMETER

View File

@ -29,7 +29,8 @@
#include "tunerstudio.h" #include "tunerstudio.h"
#include "trigger_emulator.h" #include "trigger_emulator.h"
Engine engine; static Engine _engine;
Engine *engine = &_engine;
extern WaveChart waveChart; extern WaveChart waveChart;
@ -63,34 +64,34 @@ void rusEfiFunctionalTest(void) {
initFakeBoard(); initFakeBoard();
initStatusLoop(&engine); initStatusLoop(engine);
initDataStructures(engineConfiguration); initDataStructures(engineConfiguration);
engine.engineConfiguration = engineConfiguration; engine->engineConfiguration = engineConfiguration;
engine.engineConfiguration2 = engineConfiguration2; engine->engineConfiguration2 = engineConfiguration2;
resetConfigurationExt(NULL, FORD_ASPIRE_1996, &engine); resetConfigurationExt(NULL, FORD_ASPIRE_1996, engine);
initThermistors(&engine); initThermistors(engine);
initAlgo(engineConfiguration); initAlgo(engineConfiguration);
initRpmCalculator(); initRpmCalculator();
initAnalogChart(); initAnalogChart();
initTriggerEmulator(&engine); initTriggerEmulator(engine);
initMainEventListener(&engine, engineConfiguration2); initMainEventListener(engine, engineConfiguration2);
initTriggerCentral(&engine); initTriggerCentral(engine);
startStatusThreads(&engine); startStatusThreads(engine);
startTunerStudioConnectivity(); startTunerStudioConnectivity();
} }
void printPendingMessages(void) { void printPendingMessages(void) {
updateDevConsoleState(&engine); updateDevConsoleState(engine);
waveChart.publishChartIfFull(); waveChart.publishChartIfFull();
} }