diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 0490220840..60d210bd8c 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -631,3 +631,9 @@ void doScheduleStopEngine() { //backupRamFlush(); #endif // EFI_PROD_CODE } + +EngineRotationState * getEngineRotationState() { + return &engine->rpmCalculator; +} + + diff --git a/firmware/controllers/engine_cycle/fuel_schedule.cpp b/firmware/controllers/engine_cycle/fuel_schedule.cpp index c04508dcfa..0745fd95da 100644 --- a/firmware/controllers/engine_cycle/fuel_schedule.cpp +++ b/firmware/controllers/engine_cycle/fuel_schedule.cpp @@ -55,7 +55,7 @@ InjectionEvent::InjectionEvent() { // Returns the start angle of this injector in engine coordinates (0-720 for a 4 stroke), // or unexpected if unable to calculate the start angle due to missing information. expected InjectionEvent::computeInjectionAngle(int cylinderIndex) const { - floatus_t oneDegreeUs = engine->rpmCalculator.oneDegreeUs; // local copy + floatus_t oneDegreeUs = getEngineRotationState()->getOneDegreeUs(); // local copy if (cisnan(oneDegreeUs)) { // in order to have fuel schedule we need to have current RPM // wonder if this line slows engine startup? diff --git a/firmware/controllers/engine_cycle/rpm_calculator.h b/firmware/controllers/engine_cycle/rpm_calculator.h index 06c8676e42..2fb16c7a5e 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.h +++ b/firmware/controllers/engine_cycle/rpm_calculator.h @@ -11,6 +11,7 @@ #include "scheduler.h" #include "stored_value_sensor.h" #include "timer.h" +#include "rpm_calculator_api.h" // we use this value in case of noise on trigger input lines #define NOISY_RPM -1 @@ -39,7 +40,7 @@ typedef enum { /** * Most consumers should access value via Sensor framework by SensorType::Rpm key */ -class RpmCalculator : public StoredValueSensor { +class RpmCalculator : public StoredValueSensor, public EngineRotationState { public: RpmCalculator(); @@ -109,12 +110,17 @@ public: * this is RPM on previous engine cycle. */ int previousRpmValue = 0; + /** * This is a performance optimization: let's pre-calculate this each time RPM changes * NaN while engine is not spinning */ volatile floatus_t oneDegreeUs = NAN; + floatus_t getOneDegreeUs() override { + return oneDegreeUs; + } + Timer lastTdcTimer; // RPM rate of change, in RPM per second diff --git a/firmware/controllers/engine_cycle/rpm_calculator_api.h b/firmware/controllers/engine_cycle/rpm_calculator_api.h new file mode 100644 index 0000000000..1fab4d6068 --- /dev/null +++ b/firmware/controllers/engine_cycle/rpm_calculator_api.h @@ -0,0 +1,12 @@ +/** + * @file rpm_calculator_api.h + */ + +#include "rusefi_types.h" + +class EngineRotationState { +public: + virtual floatus_t getOneDegreeUs() = 0; +}; + +EngineRotationState * getEngineRotationState();