Final cleanup of ENGINE macros (#3567)

Fix some uses of ENGINE() not detected by regex due to parenthesis.
Remove now empty engine_ptr.h
Don't worry about EFI_* not being defined, the compiler defaults to 0 if they aren't.
This commit is contained in:
Scott Smith 2021-11-17 10:45:10 -08:00 committed by GitHub
parent f9f13f0bad
commit 659cc68be1
37 changed files with 42 additions and 96 deletions

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "engine_ptr.h"
#include "ac_control_generated.h" #include "ac_control_generated.h"
class AcState final : public ac_control_s { class AcState final : public ac_control_s {

View File

@ -7,7 +7,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
#include "closed_loop_controller.h" #include "closed_loop_controller.h"
#include "rusefi_types.h" #include "rusefi_types.h"

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "engine_ptr.h"
void updateFans(bool acActive); void updateFans(bool acActive);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "engine_ptr.h"
void initGpPwm(); void initGpPwm();
void updateGppwm(); void updateGppwm();

View File

@ -9,7 +9,6 @@
#pragma once #pragma once
#include "engine_module.h" #include "engine_module.h"
#include "engine_ptr.h"
#include "rusefi_types.h" #include "rusefi_types.h"
#include "periodic_task.h" #include "periodic_task.h"
#include "pid.h" #include "pid.h"

View File

@ -7,7 +7,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
#include "periodic_task.h" #include "periodic_task.h"
#include "closed_loop_controller.h" #include "closed_loop_controller.h"
#include "pwm_generator_logic.h" #include "pwm_generator_logic.h"

View File

@ -89,7 +89,7 @@ angle_t getAdvanceCorrections(int rpm) {
iatCorrection = iatAdvanceCorrectionMap.getValue(rpm, iat); iatCorrection = iatAdvanceCorrectionMap.getValue(rpm, iat);
} }
float pidTimingCorrection = ENGINE(engineModules).unmock<IdleController>().getIdleTimingAdjustment(rpm); float pidTimingCorrection = engine->engineModules.unmock<IdleController>().getIdleTimingAdjustment(rpm);
if (engineConfiguration->debugMode == DBG_IGNITION_TIMING) { if (engineConfiguration->debugMode == DBG_IGNITION_TIMING) {
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO

View File

@ -1,4 +1,3 @@
#include "engine_ptr.h"
void setDefaultBaseEngine(); void setDefaultBaseEngine();
void setDefaultFuel(); void setDefaultFuel();

View File

@ -7,7 +7,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
void updateDynoView(); void updateDynoView();
void updateDynoViewCan(); void updateDynoViewCan();

View File

@ -235,7 +235,7 @@ void Engine::periodicSlowCallback() {
updateGppwm(); updateGppwm();
ENGINE(engineModules).apply_all([](auto & m) { m.onSlowCallback(); }); engine->engineModules.apply_all([](auto & m) { m.onSlowCallback(); });
#if EFI_BOOST_CONTROL #if EFI_BOOST_CONTROL
updateBoostControl(); updateBoostControl();
@ -632,7 +632,7 @@ void Engine::periodicFastCallback() {
tachSignalCallback(); tachSignalCallback();
ENGINE(engineModules).apply_all([](auto & m) { m.onFastCallback(); }); engine->engineModules.apply_all([](auto & m) { m.onFastCallback(); });
} }
void doScheduleStopEngine() { void doScheduleStopEngine() {

View File

@ -28,6 +28,18 @@
#include "launch_control.h" #include "launch_control.h"
#include "type_list.h" #include "type_list.h"
#ifndef EFI_UNIT_TEST
#error EFI_UNIT_TEST must be defined!
#endif
#ifndef EFI_SIMULATOR
#error EFI_SIMULATOR must be defined!
#endif
#ifndef EFI_PROD_CODE
#error EFI_PROD_CODE must be defined!
#endif
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER #if EFI_SIGNAL_EXECUTOR_ONE_TIMER
// PROD real firmware uses this implementation // PROD real firmware uses this implementation
#include "single_timer_executor.h" #include "single_timer_executor.h"

View File

@ -164,7 +164,7 @@ void onBurnRequest() {
* See preCalculate which is invoked BOTH on start and configuration change * See preCalculate which is invoked BOTH on start and configuration change
*/ */
void incrementGlobalConfigurationVersion() { void incrementGlobalConfigurationVersion() {
ENGINE(globalConfigurationVersion++); engine->globalConfigurationVersion++;
#if EFI_DEFAILED_LOGGING #if EFI_DEFAILED_LOGGING
efiPrintf("set globalConfigurationVersion=%d", globalConfigurationVersion); efiPrintf("set globalConfigurationVersion=%d", globalConfigurationVersion);
#endif /* EFI_DEFAILED_LOGGING */ #endif /* EFI_DEFAILED_LOGGING */
@ -197,7 +197,7 @@ void incrementGlobalConfigurationVersion() {
onConfigurationChangeFsioCallback(&activeConfiguration); onConfigurationChangeFsioCallback(&activeConfiguration);
#endif /* EFI_FSIO */ #endif /* EFI_FSIO */
ENGINE(engineModules).apply_all([](auto & m) { engine->engineModules.apply_all([](auto & m) {
m.onConfigurationChange(&activeConfiguration); m.onConfigurationChange(&activeConfiguration);
}); });
rememberCurrentConfiguration(); rememberCurrentConfiguration();
@ -1169,7 +1169,7 @@ void applyNonPersistentConfiguration() {
assertEngineReference(); assertEngineReference();
#if EFI_ENGINE_CONTROL #if EFI_ENGINE_CONTROL
ENGINE(initializeTriggerWaveform()); engine->initializeTriggerWaveform();
#endif // EFI_ENGINE_CONTROL #endif // EFI_ENGINE_CONTROL
} }

View File

@ -215,7 +215,7 @@ int getNumberOfInjections(injection_mode_e mode) {
} }
float getInjectionModeDurationMultiplier() { float getInjectionModeDurationMultiplier() {
injection_mode_e mode = ENGINE(getCurrentInjectionMode()); injection_mode_e mode = engine->getCurrentInjectionMode();
switch (mode) { switch (mode) {
case IM_SIMULTANEOUS: { case IM_SIMULTANEOUS: {
@ -281,7 +281,7 @@ float getInjectionMass(int rpm) {
// Prepare injector flow rate & deadtime // Prepare injector flow rate & deadtime
engine->engineModules.get<InjectorModel>().prepare(); engine->engineModules.get<InjectorModel>().prepare();
floatms_t tpsAccelEnrich = ENGINE(tpsAccelEnrichment.getTpsEnrichment()); floatms_t tpsAccelEnrich = engine->tpsAccelEnrichment.getTpsEnrichment();
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(tpsAccelEnrich), "NaN tpsAccelEnrich", 0); efiAssert(CUSTOM_ERR_ASSERT, !cisnan(tpsAccelEnrich), "NaN tpsAccelEnrich", 0);
engine->engineState.tpsAccelEnrich = tpsAccelEnrich; engine->engineState.tpsAccelEnrich = tpsAccelEnrich;

View File

@ -7,7 +7,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
#include "rusefi_types.h" #include "rusefi_types.h"
void initFuelMap(); void initFuelMap();

View File

@ -7,7 +7,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
#include "timer.h" #include "timer.h"
void initLaunchControl(); void initLaunchControl();

View File

@ -28,7 +28,6 @@
#include "efitime.h" #include "efitime.h"
#ifdef __cplusplus #ifdef __cplusplus
#include "engine_ptr.h"
#include "datalogging.h" #include "datalogging.h"
#include "cli_registry.h" #include "cli_registry.h"
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -1,42 +0,0 @@
/**
* @file engine_ptr.h
*/
#pragma once
#ifndef EFI_UNIT_TEST
#error EFI_UNIT_TEST must be defined!
#endif
#ifndef EFI_SIMULATOR
#error EFI_SIMULATOR must be defined!
#endif
#ifndef EFI_PROD_CODE
#error EFI_PROD_CODE must be defined!
#endif
#ifdef __cplusplus
class Engine;
#endif // def __cplusplus
struct engine_configuration_s;
struct persistent_config_s;
#if EFI_UNIT_TEST
#define CONFIG(x) engineConfiguration->x
#define ENGINE(x) engine->x
#else // EFI_UNIT_TEST
#define ENGINE(x) ___engine.x
/**
* this macro allows the compiled to figure out the complete static address, that's a performance
* optimization which is hopefully useful at least for anything trigger-related
*
* this is related to the fact that for unit tests we prefer to explicitly pass references in method signature thus code covered by
* unit tests would need to use by-reference access. These macro allow us to have faster by-address access in real firmware and by-reference
* access in unit tests
*/
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
#endif // EFI_UNIT_TEST

View File

@ -154,19 +154,19 @@ void turnInjectionPinLow(InjectionEvent *event) {
output->close(nowNt); output->close(nowNt);
} }
} }
ENGINE(injectionEvents.addFuelEventsForCylinder(event->ownIndex)); engine->injectionEvents.addFuelEventsForCylinder(event->ownIndex);
} }
void InjectionEvent::onTriggerTooth(size_t trgEventIndex, int rpm, efitick_t nowNt) { void InjectionEvent::onTriggerTooth(size_t trgEventIndex, int rpm, efitick_t nowNt) {
uint32_t eventIndex = injectionStart.triggerEventIndex; uint32_t eventIndex = injectionStart.triggerEventIndex;
// right after trigger change we are still using old & invalid fuel schedule. good news is we do not change trigger on the fly in real life // right after trigger change we are still using old & invalid fuel schedule. good news is we do not change trigger on the fly in real life
// efiAssertVoid(CUSTOM_ERR_ASSERT_VOID, eventIndex < ENGINE(triggerShape.getLength()), "handleFuel/event sch index"); // efiAssertVoid(CUSTOM_ERR_ASSERT_VOID, eventIndex < engine->triggerShape.getLength(), "handleFuel/event sch index");
if (eventIndex != trgEventIndex) { if (eventIndex != trgEventIndex) {
return; return;
} }
// Select fuel mass from the correct bank // Select fuel mass from the correct bank
uint8_t bankIndex = CONFIG(cylinderBankSelect[this->cylinderNumber]); uint8_t bankIndex = engineConfiguration->cylinderBankSelect[this->cylinderNumber];
float injectionMassGrams = engine->injectionMass[bankIndex]; float injectionMassGrams = engine->injectionMass[bankIndex];
// Perform wall wetting adjustment on fuel mass, not duration, so that // Perform wall wetting adjustment on fuel mass, not duration, so that
@ -286,9 +286,9 @@ static void handleFuel(const bool limitedFuel, uint32_t trgEventIndex, int rpm,
efiAssertVoid(CUSTOM_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3"); efiAssertVoid(CUSTOM_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3");
efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index"); efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index");
ENGINE(tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1))); engine->tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1));
if (trgEventIndex == 0) { if (trgEventIndex == 0) {
ENGINE(tpsAccelEnrichment.onEngineCycleTps()); engine->tpsAccelEnrichment.onEngineCycleTps();
} }
if (limitedFuel) { if (limitedFuel) {

View File

@ -139,7 +139,7 @@ void RpmCalculator::assignRpmValue(float floatRpmValue) {
* this would make sure that we have good numbers for first cranking revolution * this would make sure that we have good numbers for first cranking revolution
* #275 cranking could be improved * #275 cranking could be improved
*/ */
ENGINE(periodicFastCallback()); engine->periodicFastCallback();
} }
} }
} }
@ -391,7 +391,7 @@ efitick_t scheduleByAngle(scheduling_s *timer, efitick_t edgeTimestamp, angle_t
int32_t delayNt = USF2NT(delayUs); int32_t delayNt = USF2NT(delayUs);
efitime_t delayedTime = edgeTimestamp + delayNt; efitime_t delayedTime = edgeTimestamp + delayNt;
ENGINE(executor.scheduleByTimestampNt("angle", timer, delayedTime, action)); engine->executor.scheduleByTimestampNt("angle", timer, delayedTime, action);
return delayedTime; return delayedTime;
} }

View File

@ -160,7 +160,7 @@ private:
}; };
// Just a getter for rpmValue which also handles mockRpm if not EFI_PROD_CODE // Just a getter for rpmValue which also handles mockRpm if not EFI_PROD_CODE
#define GET_RPM() ( ENGINE(rpmCalculator.getRpm()) ) #define GET_RPM() ( engine->rpmCalculator.getRpm() )
#define isValidRpm(rpm) ((rpm) > 0 && (rpm) < UNREALISTIC_RPM) #define isValidRpm(rpm) ((rpm) > 0 && (rpm) < UNREALISTIC_RPM)
@ -176,7 +176,7 @@ void initRpmCalculator();
float getCrankshaftAngleNt(efitick_t timeNt); float getCrankshaftAngleNt(efitick_t timeNt);
#define getRevolutionCounter() ENGINE(rpmCalculator.getRevolutionCounterM()) #define getRevolutionCounter() (engine->rpmCalculator.getRevolutionCounterM())
#if EFI_ENGINE_SNIFFER #if EFI_ENGINE_SNIFFER
#define addEngineSnifferEvent(name, msg) { efiAssertVoid(OBD_PCM_Processor_Fault, engine!=NULL, "engine ptr missing"); if (engine->isEngineChartEnabled) { waveChart.addEvent3((name), (msg)); } } #define addEngineSnifferEvent(name, msg) { efiAssertVoid(OBD_PCM_Processor_Fault, engine!=NULL, "engine ptr missing"); if (engine->isEngineChartEnabled) { waveChart.addEvent3((name), (msg)); } }

View File

@ -74,15 +74,15 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_
event->sparkDwell = sparkDwell; event->sparkDwell = sparkDwell;
// change of sign here from 'before TDC' to 'after TDC' // change of sign here from 'before TDC' to 'after TDC'
angle_t ignitionPositionWithinEngineCycle = ENGINE(ignitionPositionWithinEngineCycle[event->cylinderIndex]); angle_t ignitionPositionWithinEngineCycle = engine->ignitionPositionWithinEngineCycle[event->cylinderIndex];
assertAngleRange(ignitionPositionWithinEngineCycle, "aPWEC", CUSTOM_ERR_6566); assertAngleRange(ignitionPositionWithinEngineCycle, "aPWEC", CUSTOM_ERR_6566);
// this correction is usually zero (not used) // this correction is usually zero (not used)
float perCylinderCorrection = CONFIG(timing_offset_cylinder[event->cylinderIndex]); float perCylinderCorrection = engineConfiguration->timing_offset_cylinder[event->cylinderIndex];
const angle_t sparkAngle = -engine->engineState.timingAdvance + engine->knockController.getKnockRetard() + ignitionPositionWithinEngineCycle + perCylinderCorrection; const angle_t sparkAngle = -engine->engineState.timingAdvance + engine->knockController.getKnockRetard() + ignitionPositionWithinEngineCycle + perCylinderCorrection;
efiAssertVoid(CUSTOM_SPARK_ANGLE_9, !cisnan(sparkAngle), "findAngle#9"); efiAssertVoid(CUSTOM_SPARK_ANGLE_9, !cisnan(sparkAngle), "findAngle#9");
efiAssertVoid(CUSTOM_SPARK_ANGLE_1, !cisnan(sparkAngle), "sparkAngle#1"); efiAssertVoid(CUSTOM_SPARK_ANGLE_1, !cisnan(sparkAngle), "sparkAngle#1");
const int index = ENGINE(ignitionPin[event->cylinderIndex]); const int index = engine->ignitionPin[event->cylinderIndex];
const int coilIndex = ID2INDEX(getCylinderId(index)); const int coilIndex = ID2INDEX(getCylinderId(index));
IgnitionOutputPin *output = &enginePins.coils[coilIndex]; IgnitionOutputPin *output = &enginePins.coils[coilIndex];

View File

@ -29,7 +29,6 @@
*/ */
#include "global.h" #include "global.h"
#include "engine_ptr.h"
#define EXPECTED_REMAINING_STACK 128 #define EXPECTED_REMAINING_STACK 128

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "engine_ptr.h"
#include "rusefi_types.h" #include "rusefi_types.h"
#include <cstdint> #include <cstdint>

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "engine_ptr.h"
#include "sensor.h" #include "sensor.h"
class ClosedLoopFuelCellBase { class ClosedLoopFuelCellBase {

View File

@ -410,7 +410,7 @@ ignition_mode_e getCurrentIgnitionMode() {
ignition_mode_e ignitionMode = engineConfiguration->ignitionMode; ignition_mode_e ignitionMode = engineConfiguration->ignitionMode;
#if EFI_SHAFT_POSITION_INPUT #if EFI_SHAFT_POSITION_INPUT
// In spin-up cranking mode we don't have full phase sync. info yet, so wasted spark mode is better // In spin-up cranking mode we don't have full phase sync. info yet, so wasted spark mode is better
if (ignitionMode == IM_INDIVIDUAL_COILS && ENGINE(rpmCalculator.isSpinningUp())) if (ignitionMode == IM_INDIVIDUAL_COILS && engine->rpmCalculator.isSpinningUp())
ignitionMode = IM_WASTED_SPARK; ignitionMode = IM_WASTED_SPARK;
#endif /* EFI_SHAFT_POSITION_INPUT */ #endif /* EFI_SHAFT_POSITION_INPUT */
return ignitionMode; return ignitionMode;

View File

@ -11,7 +11,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
void setBosch0280218037(persistent_config_s *engineConfiguration); void setBosch0280218037(persistent_config_s *engineConfiguration);
void setBosch0280218004(persistent_config_s *engineConfiguration); void setBosch0280218004(persistent_config_s *engineConfiguration);

View File

@ -6,7 +6,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
struct air_pressure_sensor_config_s; struct air_pressure_sensor_config_s;

View File

@ -10,7 +10,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
#include "state_sequence.h" #include "state_sequence.h"
#include "engine_configuration_generated_structures.h" #include "engine_configuration_generated_structures.h"

View File

@ -823,7 +823,7 @@ void onConfigurationChangeTriggerCallback() {
assertEngineReference(); assertEngineReference();
#if EFI_ENGINE_CONTROL #if EFI_ENGINE_CONTROL
ENGINE(initializeTriggerWaveform()); engine->initializeTriggerWaveform();
engine->triggerCentral.noiseFilter.resetAccumSignalData(); engine->triggerCentral.noiseFilter.resetAccumSignalData();
#endif #endif
} }

View File

@ -7,6 +7,5 @@
#pragma once #pragma once
#include "engine_ptr.h"
void initEngineEmulator(); void initEngineEmulator();

View File

@ -9,7 +9,6 @@
#pragma once #pragma once
#include "global.h" #include "global.h"
#include "engine_ptr.h"
#define INITIAL_PIN_STATE -1 #define INITIAL_PIN_STATE -1
#define GPIO_NULL NULL #define GPIO_NULL NULL

View File

@ -4,7 +4,6 @@
#pragma once #pragma once
#include "engine_ptr.h"
// Call this once at startup to initialize, configure, and subscribe sensors // Call this once at startup to initialize, configure, and subscribe sensors
void initNewSensors(); void initNewSensors();

View File

@ -12,7 +12,6 @@
#include "efifeatures.h" #include "efifeatures.h"
#include "rusefi_generated.h" #include "rusefi_generated.h"
#include "loggingcentral.h" #include "loggingcentral.h"
#include "engine_ptr.h"
#include "error_handling.h" #include "error_handling.h"
#include "global.h" #include "global.h"
#include "efi_gpio.h" #include "efi_gpio.h"

View File

@ -350,9 +350,7 @@ void EngineTestHelper::assertEvent(const char *msg, int index, void *callback, e
void EngineTestHelper::applyTriggerWaveform() { void EngineTestHelper::applyTriggerWaveform() {
Engine *engine = &this->engine; engine.initializeTriggerWaveform();
ENGINE(initializeTriggerWaveform());
incrementGlobalConfigurationVersion(); incrementGlobalConfigurationVersion();
} }

View File

@ -8,4 +8,3 @@
#pragma once #pragma once
#include "global.h" #include "global.h"
#include "engine_ptr.h"

View File

@ -14,13 +14,13 @@ TEST(ignition, twoCoils) {
EngineTestHelper eth(FRANKENSO_BMW_M73_F); EngineTestHelper eth(FRANKENSO_BMW_M73_F);
// first one to fire uses first coil // first one to fire uses first coil
ASSERT_EQ(ENGINE(ignitionPin[ID2INDEX(1)]), 0); ASSERT_EQ(engine->ignitionPin[ID2INDEX(1)], 0);
ASSERT_EQ(ENGINE(ignitionPin[ID2INDEX(2)]), 1); ASSERT_EQ(engine->ignitionPin[ID2INDEX(2)], 1);
ASSERT_EQ(ENGINE(ignitionPin[ID2INDEX(3)]), 0); ASSERT_EQ(engine->ignitionPin[ID2INDEX(3)], 0);
ASSERT_EQ(ENGINE(ignitionPin[ID2INDEX(4)]), 1); ASSERT_EQ(engine->ignitionPin[ID2INDEX(4)], 1);
ASSERT_EQ(ENGINE(ignitionPin[ID2INDEX(11)]), 0); ASSERT_EQ(engine->ignitionPin[ID2INDEX(11)], 0);
ASSERT_EQ(ENGINE(ignitionPin[ID2INDEX(12)]), 1); ASSERT_EQ(engine->ignitionPin[ID2INDEX(12)], 1);
// let's recalculate with zero timing so that we can focus on relation advance between cylinders // let's recalculate with zero timing so that we can focus on relation advance between cylinders
engine->engineState.timingAdvance = 0; engine->engineState.timingAdvance = 0;

View File

@ -60,7 +60,7 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) {
float expectedAEValue = 29.2; float expectedAEValue = 29.2;
// it does not matter how many times we invoke 'getTpsEnrichment' - state does not change // it does not matter how many times we invoke 'getTpsEnrichment' - state does not change
for (int i = 0; i <20;i++) { for (int i = 0; i <20;i++) {
ASSERT_NEAR(expectedAEValue, ENGINE(tpsAccelEnrichment.getTpsEnrichment()), EPS4D); ASSERT_NEAR(expectedAEValue, engine->tpsAccelEnrichment.getTpsEnrichment(), EPS4D);
} }
expectedInvocationCounter++; expectedInvocationCounter++;