better conditional compilation
This commit is contained in:
parent
ed4fed57fb
commit
da4fb3a19f
|
@ -471,7 +471,7 @@ void updateDevConsoleState(void) {
|
||||||
|
|
||||||
systime_t nowSeconds = getTimeNowSeconds();
|
systime_t nowSeconds = getTimeNowSeconds();
|
||||||
|
|
||||||
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
int currentCkpEventCounter = getCrankEventCounter();
|
int currentCkpEventCounter = getCrankEventCounter();
|
||||||
if (prevCkpEventCounter == currentCkpEventCounter && timeOfPreviousReport == nowSeconds) {
|
if (prevCkpEventCounter == currentCkpEventCounter && timeOfPreviousReport == nowSeconds) {
|
||||||
return;
|
return;
|
||||||
|
@ -595,8 +595,12 @@ static void setBlinkingPeriod(int value) {
|
||||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||||
|
|
||||||
static bool isTriggerErrorNow() {
|
static bool isTriggerErrorNow() {
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
bool justHadError = (getTimeNowNt() - engine->triggerCentral.triggerState.lastDecodingErrorTime) < US2NT(2 * 1000 * 3 * blinkingPeriod);
|
bool justHadError = (getTimeNowNt() - engine->triggerCentral.triggerState.lastDecodingErrorTime) < US2NT(2 * 1000 * 3 * blinkingPeriod);
|
||||||
return justHadError || isTriggerDecoderError();
|
return justHadError || isTriggerDecoderError();
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif /* EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool consoleByteArrived;
|
extern bool consoleByteArrived;
|
||||||
|
|
|
@ -145,6 +145,7 @@ static angle_t getCrankingAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAM
|
||||||
|
|
||||||
|
|
||||||
angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
if (cisnan(engineLoad)) {
|
if (cisnan(engineLoad)) {
|
||||||
return 0; // any error should already be reported
|
return 0; // any error should already be reported
|
||||||
}
|
}
|
||||||
|
@ -177,6 +178,9 @@ angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(angle), "_AngleN5", 0);
|
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(angle), "_AngleN5", 0);
|
||||||
fixAngle(angle, "getAdvance", CUSTOM_ERR_ADCANCE_CALC_ANGLE);
|
fixAngle(angle, "getAdvance", CUSTOM_ERR_ADCANCE_CALC_ANGLE);
|
||||||
return angle;
|
return angle;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefaultIatTimingCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void setDefaultIatTimingCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
|
|
@ -55,6 +55,7 @@ FsioState::FsioState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
void Engine::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
#if !EFI_UNIT_TEST
|
#if !EFI_UNIT_TEST
|
||||||
// we have a confusing threading model so some synchronization would not hurt
|
// we have a confusing threading model so some synchronization would not hurt
|
||||||
bool alreadyLocked = lockAnyContext();
|
bool alreadyLocked = lockAnyContext();
|
||||||
|
@ -83,11 +84,12 @@ void Engine::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUF
|
||||||
if (!alreadyLocked) {
|
if (!alreadyLocked) {
|
||||||
unlockAnyContext();
|
unlockAnyContext();
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* EFI_UNIT_TEST */
|
||||||
|
|
||||||
if (!TRIGGER_SHAPE(shapeDefinitionError)) {
|
if (!TRIGGER_SHAPE(shapeDefinitionError)) {
|
||||||
prepareOutputSignals(PASS_ENGINE_PARAMETER_SIGNATURE);
|
prepareOutputSignals(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
}
|
}
|
||||||
|
#endif /* EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cylinderCleanupControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
static void cylinderCleanupControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
|
|
@ -151,6 +151,7 @@ percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
* in case of single point injection mode the amount of fuel into all cylinders, otherwise the amount for one cylinder
|
* in case of single point injection mode the amount of fuel into all cylinders, otherwise the amount for one cylinder
|
||||||
*/
|
*/
|
||||||
floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
bool isCranking = ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE);
|
bool isCranking = ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
injection_mode_e mode = isCranking ?
|
injection_mode_e mode = isCranking ?
|
||||||
engineConfiguration->crankingInjectionMode :
|
engineConfiguration->crankingInjectionMode :
|
||||||
|
@ -190,6 +191,9 @@ floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
return 0; // we can end up here during configuration reset
|
return 0; // we can end up here during configuration reset
|
||||||
}
|
}
|
||||||
return theoreticalInjectionLength * engineConfiguration->globalFuelCorrection + injectorLag;
|
return theoreticalInjectionLength * engineConfiguration->globalFuelCorrection + injectorLag;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
@ -294,6 +298,7 @@ float getFuelCutOffCorrection(efitick_t nowNt, int rpm DECLARE_ENGINE_PARAMETER_
|
||||||
* @return Fuel injection duration injection as specified in the fuel map, in milliseconds
|
* @return Fuel injection duration injection as specified in the fuel map, in milliseconds
|
||||||
*/
|
*/
|
||||||
floatms_t getBaseTableFuel(int rpm, float engineLoad) {
|
floatms_t getBaseTableFuel(int rpm, float engineLoad) {
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
if (cisnan(engineLoad)) {
|
if (cisnan(engineLoad)) {
|
||||||
warning(CUSTOM_NAN_ENGINE_LOAD_2, "NaN engine load");
|
warning(CUSTOM_NAN_ENGINE_LOAD_2, "NaN engine load");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -305,6 +310,9 @@ floatms_t getBaseTableFuel(int rpm, float engineLoad) {
|
||||||
warning(CUSTOM_ERR_FUEL_TABLE_NOT_READY, "baseFuel table not ready");
|
warning(CUSTOM_ERR_FUEL_TABLE_NOT_READY, "baseFuel table not ready");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
|
|
@ -277,7 +277,7 @@ static void invokePerSecond(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void periodicSlowCallback(Engine *engine) {
|
static void periodicSlowCallback(Engine *engine) {
|
||||||
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
efiAssertVoid(CUSTOM_ERR_6661, getRemainingStack(chThdGetSelfX()) > 64, "lowStckOnEv");
|
efiAssertVoid(CUSTOM_ERR_6661, getRemainingStack(chThdGetSelfX()) > 64, "lowStckOnEv");
|
||||||
#if EFI_PROD_CODE
|
#if EFI_PROD_CODE
|
||||||
/**
|
/**
|
||||||
|
@ -723,7 +723,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
|
||||||
|
|
||||||
initEgoAveraging(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initEgoAveraging(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
if (CONFIGB(isEngineControlEnabled)) {
|
if (CONFIGB(isEngineControlEnabled)) {
|
||||||
/**
|
/**
|
||||||
* This method initialized the main listener which actually runs injectors & ignition
|
* This method initialized the main listener which actually runs injectors & ignition
|
||||||
|
|
|
@ -261,7 +261,9 @@ void runBenchTest(uint16_t subsystem, uint16_t index) {
|
||||||
milBench();
|
milBench();
|
||||||
} else if (subsystem == 0x17) {
|
} else if (subsystem == 0x17) {
|
||||||
// cmd_test_idle_valve
|
// cmd_test_idle_valve
|
||||||
|
#if EFI_IDLE_CONTROL || defined(__DOXYGEN__)
|
||||||
startIdleBench();
|
startIdleBench();
|
||||||
|
#endif
|
||||||
} else if (subsystem == 0x20 && index == 0x3456) {
|
} else if (subsystem == 0x20 && index == 0x3456) {
|
||||||
// call to pit
|
// call to pit
|
||||||
setCallFromPitStop(30000);
|
setCallFromPitStop(30000);
|
||||||
|
|
|
@ -242,6 +242,7 @@ static floatms_t getCrankingSparkDwell(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
* @return Spark dwell time, in milliseconds. 0 if tables are not ready.
|
* @return Spark dwell time, in milliseconds. 0 if tables are not ready.
|
||||||
*/
|
*/
|
||||||
floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
float dwellMs;
|
float dwellMs;
|
||||||
if (ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
if (ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
||||||
dwellMs = getCrankingSparkDwell(PASS_ENGINE_PARAMETER_SIGNATURE);
|
dwellMs = getCrankingSparkDwell(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
@ -257,6 +258,9 @@ floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return dwellMs;
|
return dwellMs;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -453,9 +457,11 @@ void prepareIgnitionPinIndices(ignition_mode_e ignitionMode DECLARE_ENGINE_PARAM
|
||||||
*/
|
*/
|
||||||
ignition_mode_e getCurrentIgnitionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
ignition_mode_e getCurrentIgnitionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
ignition_mode_e ignitionMode = CONFIG(ignitionMode);
|
ignition_mode_e ignitionMode = CONFIG(ignitionMode);
|
||||||
|
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
||||||
// 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(PASS_ENGINE_PARAMETER_SIGNATURE)))
|
if (ignitionMode == IM_INDIVIDUAL_COILS && ENGINE(rpmCalculator.isSpinningUp(PASS_ENGINE_PARAMETER_SIGNATURE)))
|
||||||
ignitionMode = IM_WASTED_SPARK;
|
ignitionMode = IM_WASTED_SPARK;
|
||||||
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
||||||
return ignitionMode;
|
return ignitionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1128,7 +1128,9 @@ typedef struct {
|
||||||
VoidFloat callback;
|
VoidFloat callback;
|
||||||
} command_f_s;
|
} command_f_s;
|
||||||
|
|
||||||
const command_f_s commandsF[] = {{"mock_iat_voltage", setMockIatVoltage},
|
const command_f_s commandsF[] = {
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
|
{"mock_iat_voltage", setMockIatVoltage},
|
||||||
{"mock_pedal_position", setMockPedalPosition},
|
{"mock_pedal_position", setMockPedalPosition},
|
||||||
{"mock_maf_voltage", setMockMafVoltage},
|
{"mock_maf_voltage", setMockMafVoltage},
|
||||||
{"mock_afr_voltage", setMockAfrVoltage},
|
{"mock_afr_voltage", setMockAfrVoltage},
|
||||||
|
@ -1136,6 +1138,7 @@ const command_f_s commandsF[] = {{"mock_iat_voltage", setMockIatVoltage},
|
||||||
{"mock_map_voltage", setMockMapVoltage},
|
{"mock_map_voltage", setMockMapVoltage},
|
||||||
{"mock_vbatt_voltage", setMockVBattVoltage},
|
{"mock_vbatt_voltage", setMockVBattVoltage},
|
||||||
{"mock_clt_voltage", setMockCltVoltage},
|
{"mock_clt_voltage", setMockCltVoltage},
|
||||||
|
#endif
|
||||||
{"fsio_curve_1_value", setFsioCurve1Value},
|
{"fsio_curve_1_value", setFsioCurve1Value},
|
||||||
{"fsio_curve_2_value", setFsioCurve2Value},
|
{"fsio_curve_2_value", setFsioCurve2Value},
|
||||||
{"ignition_offset", setIgnitionOffset},
|
{"ignition_offset", setIgnitionOffset},
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
|
|
||||||
#include "main_trigger_callback.h"
|
#include "main_trigger_callback.h"
|
||||||
#include "efiGpio.h"
|
#include "efiGpio.h"
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "rpm_calculator.h"
|
#include "rpm_calculator.h"
|
||||||
|
|
||||||
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
|
||||||
|
|
||||||
#include "trigger_central.h"
|
#include "trigger_central.h"
|
||||||
#include "engine_configuration.h"
|
#include "engine_configuration.h"
|
||||||
#include "engine_math.h"
|
#include "engine_math.h"
|
||||||
|
@ -40,6 +38,43 @@ extern WaveChart waveChart;
|
||||||
#define NO_RPM_EVENTS_TIMEOUT_SECS 2
|
#define NO_RPM_EVENTS_TIMEOUT_SECS 2
|
||||||
#endif /* NO_RPM_EVENTS_TIMEOUT_SECS */
|
#endif /* NO_RPM_EVENTS_TIMEOUT_SECS */
|
||||||
|
|
||||||
|
float RpmCalculator::getRpmAcceleration() {
|
||||||
|
return 1.0 * previousRpmValue / rpmValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RpmCalculator::isStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
|
||||||
|
// Spinning-up with zero RPM means that the engine is not ready yet, and is treated as 'stopped'.
|
||||||
|
return state == STOPPED || (state == SPINNING_UP && rpmValue == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RpmCalculator::isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
|
||||||
|
// Spinning-up with non-zero RPM is suitable for all engine math, as good as cranking
|
||||||
|
return state == CRANKING || (state == SPINNING_UP && rpmValue > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RpmCalculator::isSpinningUp(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
|
||||||
|
return state == SPINNING_UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RpmCalculator::getRevolutionCounterSinceStart(void) {
|
||||||
|
return revolutionCounterSinceStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return -1 in case of isNoisySignal(), current RPM otherwise
|
||||||
|
*/
|
||||||
|
// todo: migrate to float return result or add a float version? this would have with calculations
|
||||||
|
int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
|
||||||
|
#if !EFI_PROD_CODE
|
||||||
|
if (mockRpm != MOCK_UNDEFINED) {
|
||||||
|
return mockRpm;
|
||||||
|
}
|
||||||
|
#endif /* EFI_PROD_CODE */
|
||||||
|
return rpmValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
||||||
|
|
||||||
EXTERN_ENGINE
|
EXTERN_ENGINE
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -61,20 +96,6 @@ RpmCalculator::RpmCalculator() {
|
||||||
revolutionCounterSinceBootForUnitTest = 0;
|
revolutionCounterSinceBootForUnitTest = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RpmCalculator::isStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
|
|
||||||
// Spinning-up with zero RPM means that the engine is not ready yet, and is treated as 'stopped'.
|
|
||||||
return state == STOPPED || (state == SPINNING_UP && rpmValue == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RpmCalculator::isSpinningUp(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
|
|
||||||
return state == SPINNING_UP;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RpmCalculator::isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
|
|
||||||
// Spinning-up with non-zero RPM is suitable for all engine math, as good as cranking
|
|
||||||
return state == CRANKING || (state == SPINNING_UP && rpmValue > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if there was a full shaft revolution within the last second
|
* @return true if there was a full shaft revolution within the last second
|
||||||
*/
|
*/
|
||||||
|
@ -163,14 +184,6 @@ uint32_t RpmCalculator::getRevolutionCounter(void) {
|
||||||
return revolutionCounterSinceBoot;
|
return revolutionCounterSinceBoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RpmCalculator::getRevolutionCounterSinceStart(void) {
|
|
||||||
return revolutionCounterSinceStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
float RpmCalculator::getRpmAcceleration() {
|
|
||||||
return 1.0 * previousRpmValue / rpmValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RpmCalculator::setStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void RpmCalculator::setStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
revolutionCounterSinceStart = 0;
|
revolutionCounterSinceStart = 0;
|
||||||
if (rpmValue != 0) {
|
if (rpmValue != 0) {
|
||||||
|
@ -204,19 +217,6 @@ void RpmCalculator::setSpinningUp(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFI
|
||||||
prepareIgnitionPinIndices(getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX);
|
prepareIgnitionPinIndices(getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return -1 in case of isNoisySignal(), current RPM otherwise
|
|
||||||
*/
|
|
||||||
// todo: migrate to float return result or add a float version? this would have with calculations
|
|
||||||
int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
|
|
||||||
#if !EFI_PROD_CODE
|
|
||||||
if (mockRpm != MOCK_UNDEFINED) {
|
|
||||||
return mockRpm;
|
|
||||||
}
|
|
||||||
#endif /* EFI_PROD_CODE */
|
|
||||||
return rpmValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Shaft position callback used by RPM calculation logic.
|
* @brief Shaft position callback used by RPM calculation logic.
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
|
||||||
|
|
||||||
#include "trigger_central.h"
|
#include "trigger_central.h"
|
||||||
#include "trigger_decoder.h"
|
#include "trigger_decoder.h"
|
||||||
#include "main_trigger_callback.h"
|
#include "main_trigger_callback.h"
|
||||||
|
@ -25,6 +23,29 @@
|
||||||
#include "trigger_simulator.h"
|
#include "trigger_simulator.h"
|
||||||
|
|
||||||
#include "rpm_calculator.h"
|
#include "rpm_calculator.h"
|
||||||
|
|
||||||
|
TriggerCentral::TriggerCentral() : hwEventCounters() {
|
||||||
|
// we need this initial to have not_running at first invocation
|
||||||
|
previousShaftEventTimeNt = (efitimems_t) -10 * US2NT(US_PER_SECOND_LL);
|
||||||
|
|
||||||
|
clearCallbacks(&triggerListeneres);
|
||||||
|
triggerState.resetTriggerState();
|
||||||
|
resetAccumSignalData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TriggerCentral::resetAccumSignalData() {
|
||||||
|
memset(lastSignalTimes, 0xff, sizeof(lastSignalTimes)); // = -1
|
||||||
|
memset(accumSignalPeriods, 0, sizeof(accumSignalPeriods));
|
||||||
|
memset(accumSignalPrevPeriods, 0, sizeof(accumSignalPrevPeriods));
|
||||||
|
}
|
||||||
|
|
||||||
|
int TriggerCentral::getHwEventCounter(int index) {
|
||||||
|
return hwEventCounters[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
||||||
|
|
||||||
|
|
||||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||||
#include "rfiutil.h"
|
#include "rfiutil.h"
|
||||||
#include "pin_repository.h"
|
#include "pin_repository.h"
|
||||||
|
@ -204,29 +225,10 @@ void hwHandleShaftSignal(trigger_event_e signal) {
|
||||||
}
|
}
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
|
|
||||||
TriggerCentral::TriggerCentral() : hwEventCounters() {
|
|
||||||
// we need this initial to have not_running at first invocation
|
|
||||||
previousShaftEventTimeNt = (efitimems_t) -10 * US2NT(US_PER_SECOND_LL);
|
|
||||||
|
|
||||||
clearCallbacks(&triggerListeneres);
|
|
||||||
triggerState.resetTriggerState();
|
|
||||||
resetAccumSignalData();
|
|
||||||
}
|
|
||||||
|
|
||||||
int TriggerCentral::getHwEventCounter(int index) {
|
|
||||||
return hwEventCounters[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
void TriggerCentral::resetCounters() {
|
void TriggerCentral::resetCounters() {
|
||||||
memset(hwEventCounters, 0, sizeof(hwEventCounters));
|
memset(hwEventCounters, 0, sizeof(hwEventCounters));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerCentral::resetAccumSignalData() {
|
|
||||||
memset(lastSignalTimes, 0xff, sizeof(lastSignalTimes)); // = -1
|
|
||||||
memset(accumSignalPeriods, 0, sizeof(accumSignalPeriods));
|
|
||||||
memset(accumSignalPrevPeriods, 0, sizeof(accumSignalPrevPeriods));
|
|
||||||
}
|
|
||||||
|
|
||||||
static char shaft_signal_msg_index[15];
|
static char shaft_signal_msg_index[15];
|
||||||
|
|
||||||
static bool isUpEvent[6] = { false, true, false, true, false, true };
|
static bool isUpEvent[6] = { false, true, false, true, false, true };
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
|
||||||
|
|
||||||
#include "obd_error_codes.h"
|
#include "obd_error_codes.h"
|
||||||
#include "trigger_decoder.h"
|
#include "trigger_decoder.h"
|
||||||
#include "cyclic_buffer.h"
|
#include "cyclic_buffer.h"
|
||||||
|
@ -36,6 +34,49 @@
|
||||||
#include "sensor_chart.h"
|
#include "sensor_chart.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TriggerState::TriggerState() {
|
||||||
|
resetTriggerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TriggerState::resetTriggerState() {
|
||||||
|
triggerCycleCallback = NULL;
|
||||||
|
shaft_is_synchronized = false;
|
||||||
|
toothed_previous_time = 0;
|
||||||
|
|
||||||
|
memset(toothDurations, 0, sizeof(toothDurations));
|
||||||
|
|
||||||
|
totalRevolutionCounter = 0;
|
||||||
|
totalTriggerErrorCounter = 0;
|
||||||
|
orderingErrorCounter = 0;
|
||||||
|
lastDecodingErrorTime = US2NT(-10000000LL);
|
||||||
|
someSortOfTriggerError = false;
|
||||||
|
|
||||||
|
memset(toothDurations, 0, sizeof(toothDurations));
|
||||||
|
curSignal = SHAFT_PRIMARY_FALLING;
|
||||||
|
prevSignal = SHAFT_PRIMARY_FALLING;
|
||||||
|
startOfCycleNt = 0;
|
||||||
|
|
||||||
|
resetCurrentCycleState();
|
||||||
|
memset(expectedTotalTime, 0, sizeof(expectedTotalTime));
|
||||||
|
|
||||||
|
totalEventCountBase = 0;
|
||||||
|
isFirstEvent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TriggerState::resetCurrentCycleState() {
|
||||||
|
memset(currentCycle.eventCount, 0, sizeof(currentCycle.eventCount));
|
||||||
|
memset(currentCycle.timeOfPreviousEventNt, 0, sizeof(currentCycle.timeOfPreviousEventNt));
|
||||||
|
memset(currentCycle.totalTimeNt, 0, sizeof(currentCycle.totalTimeNt));
|
||||||
|
currentCycle.current_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TriggerStateWithRunningStatistics::TriggerStateWithRunningStatistics() :
|
||||||
|
//https://en.cppreference.com/w/cpp/language/zero_initialization
|
||||||
|
timeOfLastEvent(), instantRpmValue()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
||||||
|
|
||||||
EXTERN_ENGINE
|
EXTERN_ENGINE
|
||||||
;
|
;
|
||||||
|
@ -124,12 +165,6 @@ int TriggerState::getTotalRevolutionCounter() const {
|
||||||
return totalRevolutionCounter;
|
return totalRevolutionCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerStateWithRunningStatistics::TriggerStateWithRunningStatistics() :
|
|
||||||
//https://en.cppreference.com/w/cpp/language/zero_initialization
|
|
||||||
timeOfLastEvent(), instantRpmValue()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
// here we take timestamps of events which happened prior to synchronization and place them
|
// here we take timestamps of events which happened prior to synchronization and place them
|
||||||
// at appropriate locations
|
// at appropriate locations
|
||||||
|
@ -254,35 +289,6 @@ static trigger_value_e eventType[6] = { TV_FALL, TV_RISE, TV_FALL, TV_RISE, TV_F
|
||||||
|
|
||||||
#define isLessImportant(type) (needToSkipFall(type) || needToSkipRise(type) || (!considerEventForGap()) )
|
#define isLessImportant(type) (needToSkipFall(type) || needToSkipRise(type) || (!considerEventForGap()) )
|
||||||
|
|
||||||
TriggerState::TriggerState() {
|
|
||||||
resetTriggerState();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TriggerState::resetTriggerState() {
|
|
||||||
triggerCycleCallback = NULL;
|
|
||||||
shaft_is_synchronized = false;
|
|
||||||
toothed_previous_time = 0;
|
|
||||||
|
|
||||||
memset(toothDurations, 0, sizeof(toothDurations));
|
|
||||||
|
|
||||||
totalRevolutionCounter = 0;
|
|
||||||
totalTriggerErrorCounter = 0;
|
|
||||||
orderingErrorCounter = 0;
|
|
||||||
lastDecodingErrorTime = US2NT(-10000000LL);
|
|
||||||
someSortOfTriggerError = false;
|
|
||||||
|
|
||||||
memset(toothDurations, 0, sizeof(toothDurations));
|
|
||||||
curSignal = SHAFT_PRIMARY_FALLING;
|
|
||||||
prevSignal = SHAFT_PRIMARY_FALLING;
|
|
||||||
startOfCycleNt = 0;
|
|
||||||
|
|
||||||
resetCurrentCycleState();
|
|
||||||
memset(expectedTotalTime, 0, sizeof(expectedTotalTime));
|
|
||||||
|
|
||||||
totalEventCountBase = 0;
|
|
||||||
isFirstEvent = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TriggerState::getCurrentIndex() const {
|
int TriggerState::getCurrentIndex() const {
|
||||||
return currentCycle.current_index;
|
return currentCycle.current_index;
|
||||||
}
|
}
|
||||||
|
@ -295,13 +301,6 @@ bool TriggerState::isEvenRevolution() const {
|
||||||
return totalRevolutionCounter & 1;
|
return totalRevolutionCounter & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerState::resetCurrentCycleState() {
|
|
||||||
memset(currentCycle.eventCount, 0, sizeof(currentCycle.eventCount));
|
|
||||||
memset(currentCycle.timeOfPreviousEventNt, 0, sizeof(currentCycle.timeOfPreviousEventNt));
|
|
||||||
memset(currentCycle.totalTimeNt, 0, sizeof(currentCycle.totalTimeNt));
|
|
||||||
currentCycle.current_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TriggerState::onSynchronizationLost(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void TriggerState::onSynchronizationLost(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
shaft_is_synchronized = false;
|
shaft_is_synchronized = false;
|
||||||
// Needed for early instant-RPM detection
|
// Needed for early instant-RPM detection
|
||||||
|
|
|
@ -100,7 +100,9 @@ public:
|
||||||
|
|
||||||
void resetTriggerState();
|
void resetTriggerState();
|
||||||
|
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
virtual void runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
virtual void runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this is start of real trigger cycle
|
* this is start of real trigger cycle
|
||||||
|
@ -147,7 +149,9 @@ public:
|
||||||
float prevInstantRpmValue = 0;
|
float prevInstantRpmValue = 0;
|
||||||
void movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
float calculateInstantRpm(int *prevIndex, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
float calculateInstantRpm(int *prevIndex, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||||
virtual void runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
virtual void runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Update timeOfLastEvent[] on every trigger event - even without synchronization
|
* Update timeOfLastEvent[] on every trigger event - even without synchronization
|
||||||
* Needed for early spin-up RPM detection.
|
* Needed for early spin-up RPM detection.
|
||||||
|
|
|
@ -187,11 +187,13 @@ void runRusEfi(void) {
|
||||||
*/
|
*/
|
||||||
initPinRepository();
|
initPinRepository();
|
||||||
|
|
||||||
|
#if EFI_INTERNAL_FLASH || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* First thing is reading configuration from flash memory.
|
* First thing is reading configuration from flash memory.
|
||||||
* In order to have complete flexibility configuration has to go before anything else.
|
* In order to have complete flexibility configuration has to go before anything else.
|
||||||
*/
|
*/
|
||||||
readConfiguration(&sharedLogger);
|
readConfiguration(&sharedLogger);
|
||||||
|
#endif /* EFI_INTERNAL_FLASH */
|
||||||
// TODO: need to fix this place!!! should be a version of PASS_ENGINE_PARAMETER_SIGNATURE somehow
|
// TODO: need to fix this place!!! should be a version of PASS_ENGINE_PARAMETER_SIGNATURE somehow
|
||||||
prepareVoidConfiguration(&activeConfiguration);
|
prepareVoidConfiguration(&activeConfiguration);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue