better conditional compilation

This commit is contained in:
rusefi 2019-01-31 17:55:23 -05:00
parent ed4fed57fb
commit da4fb3a19f
14 changed files with 144 additions and 108 deletions

View File

@ -471,7 +471,7 @@ void updateDevConsoleState(void) {
systime_t nowSeconds = getTimeNowSeconds();
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
int currentCkpEventCounter = getCrankEventCounter();
if (prevCkpEventCounter == currentCkpEventCounter && timeOfPreviousReport == nowSeconds) {
return;
@ -595,8 +595,12 @@ static void setBlinkingPeriod(int value) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
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);
return justHadError || isTriggerDecoderError();
#else
return false;
#endif /* EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
}
extern bool consoleByteArrived;

View File

@ -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) {
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
if (cisnan(engineLoad)) {
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);
fixAngle(angle, "getAdvance", CUSTOM_ERR_ADCANCE_CALC_ANGLE);
return angle;
#else
return 0;
#endif
}
void setDefaultIatTimingCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {

View File

@ -55,6 +55,7 @@ FsioState::FsioState() {
}
void Engine::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
#if !EFI_UNIT_TEST
// we have a confusing threading model so some synchronization would not hurt
bool alreadyLocked = lockAnyContext();
@ -83,11 +84,12 @@ void Engine::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUF
if (!alreadyLocked) {
unlockAnyContext();
}
#endif
#endif /* EFI_UNIT_TEST */
if (!TRIGGER_SHAPE(shapeDefinitionError)) {
prepareOutputSignals(PASS_ENGINE_PARAMETER_SIGNATURE);
}
#endif /* EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
}
static void cylinderCleanupControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) {

View File

@ -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
*/
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);
injection_mode_e mode = isCranking ?
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 theoreticalInjectionLength * engineConfiguration->globalFuelCorrection + injectorLag;
#else
return 0;
#endif
}
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
*/
floatms_t getBaseTableFuel(int rpm, float engineLoad) {
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
if (cisnan(engineLoad)) {
warning(CUSTOM_NAN_ENGINE_LOAD_2, "NaN engine load");
return 0;
@ -305,6 +310,9 @@ floatms_t getBaseTableFuel(int rpm, float engineLoad) {
warning(CUSTOM_ERR_FUEL_TABLE_NOT_READY, "baseFuel table not ready");
}
return result;
#else
return 0;
#endif
}
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {

View File

@ -277,7 +277,7 @@ static void invokePerSecond(void) {
}
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");
#if EFI_PROD_CODE
/**
@ -723,7 +723,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
initEgoAveraging(PASS_ENGINE_PARAMETER_SIGNATURE);
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
if (CONFIGB(isEngineControlEnabled)) {
/**
* This method initialized the main listener which actually runs injectors & ignition

View File

@ -261,7 +261,9 @@ void runBenchTest(uint16_t subsystem, uint16_t index) {
milBench();
} else if (subsystem == 0x17) {
// cmd_test_idle_valve
#if EFI_IDLE_CONTROL || defined(__DOXYGEN__)
startIdleBench();
#endif
} else if (subsystem == 0x20 && index == 0x3456) {
// call to pit
setCallFromPitStop(30000);

View File

@ -242,6 +242,7 @@ static floatms_t getCrankingSparkDwell(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
* @return Spark dwell time, in milliseconds. 0 if tables are not ready.
*/
floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
float dwellMs;
if (ENGINE(rpmCalculator).isCranking(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 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 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
if (ignitionMode == IM_INDIVIDUAL_COILS && ENGINE(rpmCalculator.isSpinningUp(PASS_ENGINE_PARAMETER_SIGNATURE)))
ignitionMode = IM_WASTED_SPARK;
#endif /* EFI_SHAFT_POSITION_INPUT */
return ignitionMode;
}

View File

@ -1128,7 +1128,9 @@ typedef struct {
VoidFloat callback;
} 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_maf_voltage", setMockMafVoltage},
{"mock_afr_voltage", setMockAfrVoltage},
@ -1136,6 +1138,7 @@ const command_f_s commandsF[] = {{"mock_iat_voltage", setMockIatVoltage},
{"mock_map_voltage", setMockMapVoltage},
{"mock_vbatt_voltage", setMockVBattVoltage},
{"mock_clt_voltage", setMockCltVoltage},
#endif
{"fsio_curve_1_value", setFsioCurve1Value},
{"fsio_curve_2_value", setFsioCurve2Value},
{"ignition_offset", setIgnitionOffset},

View File

@ -33,7 +33,7 @@
#endif
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
#include "main_trigger_callback.h"
#include "efiGpio.h"

View File

@ -13,8 +13,6 @@
#include "engine.h"
#include "rpm_calculator.h"
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
#include "trigger_central.h"
#include "engine_configuration.h"
#include "engine_math.h"
@ -40,6 +38,43 @@ extern WaveChart waveChart;
#define NO_RPM_EVENTS_TIMEOUT_SECS 2
#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
;
@ -61,20 +96,6 @@ RpmCalculator::RpmCalculator() {
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
*/
@ -163,14 +184,6 @@ uint32_t RpmCalculator::getRevolutionCounter(void) {
return revolutionCounterSinceBoot;
}
uint32_t RpmCalculator::getRevolutionCounterSinceStart(void) {
return revolutionCounterSinceStart;
}
float RpmCalculator::getRpmAcceleration() {
return 1.0 * previousRpmValue / rpmValue;
}
void RpmCalculator::setStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
revolutionCounterSinceStart = 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);
}
/**
* @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.
*

View File

@ -8,8 +8,6 @@
#include "global.h"
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
#include "trigger_central.h"
#include "trigger_decoder.h"
#include "main_trigger_callback.h"
@ -25,6 +23,29 @@
#include "trigger_simulator.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__)
#include "rfiutil.h"
#include "pin_repository.h"
@ -204,29 +225,10 @@ void hwHandleShaftSignal(trigger_event_e signal) {
}
#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() {
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 bool isUpEvent[6] = { false, true, false, true, false, true };

View File

@ -20,8 +20,6 @@
#include "global.h"
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
#include "obd_error_codes.h"
#include "trigger_decoder.h"
#include "cyclic_buffer.h"
@ -36,6 +34,49 @@
#include "sensor_chart.h"
#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
;
@ -124,12 +165,6 @@ int TriggerState::getTotalRevolutionCounter() const {
return totalRevolutionCounter;
}
TriggerStateWithRunningStatistics::TriggerStateWithRunningStatistics() :
//https://en.cppreference.com/w/cpp/language/zero_initialization
timeOfLastEvent(), instantRpmValue()
{
}
void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// here we take timestamps of events which happened prior to synchronization and place them
// 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()) )
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 {
return currentCycle.current_index;
}
@ -295,13 +301,6 @@ bool TriggerState::isEvenRevolution() const {
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) {
shaft_is_synchronized = false;
// Needed for early instant-RPM detection

View File

@ -100,7 +100,9 @@ public:
void resetTriggerState();
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
virtual void runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
#endif
/**
* this is start of real trigger cycle
@ -147,7 +149,9 @@ public:
float prevInstantRpmValue = 0;
void movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE);
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);
#endif
/**
* Update timeOfLastEvent[] on every trigger event - even without synchronization
* Needed for early spin-up RPM detection.

View File

@ -187,11 +187,13 @@ void runRusEfi(void) {
*/
initPinRepository();
#if EFI_INTERNAL_FLASH || defined(__DOXYGEN__)
/**
* First thing is reading configuration from flash memory.
* In order to have complete flexibility configuration has to go before anything else.
*/
readConfiguration(&sharedLogger);
#endif /* EFI_INTERNAL_FLASH */
// TODO: need to fix this place!!! should be a version of PASS_ENGINE_PARAMETER_SIGNATURE somehow
prepareVoidConfiguration(&activeConfiguration);