Merge remote-tracking branch 'upstream/master' into perf-tracing

This commit is contained in:
Matthew Kennedy 2019-10-14 23:45:39 -07:00
commit d6e065f99e
23 changed files with 94 additions and 85 deletions

View File

@ -54,10 +54,8 @@ FsioState::FsioState() {
void Engine::eInitializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX) { void Engine::eInitializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
#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();
#endif /* EFI_UNIT_TEST */
TRIGGER_SHAPE(initializeTriggerShape(logger, TRIGGER_SHAPE(initializeTriggerShape(logger,
engineConfiguration->ambiguousOperationMode, engineConfiguration->ambiguousOperationMode,
@ -87,11 +85,9 @@ void Engine::eInitializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SU
engine->engineCycleEventCount = TRIGGER_SHAPE(getLength()); engine->engineCycleEventCount = TRIGGER_SHAPE(getLength());
} }
#if !EFI_UNIT_TEST
if (!alreadyLocked) { if (!alreadyLocked) {
unlockAnyContext(); unlockAnyContext();
} }
#endif /* EFI_UNIT_TEST */
if (!TRIGGER_SHAPE(shapeDefinitionError)) { if (!TRIGGER_SHAPE(shapeDefinitionError)) {
prepareOutputSignals(PASS_ENGINE_PARAMETER_SIGNATURE); prepareOutputSignals(PASS_ENGINE_PARAMETER_SIGNATURE);

View File

@ -227,9 +227,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
void EngineState::updateTChargeK(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX) { void EngineState::updateTChargeK(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_ENGINE_CONTROL #if EFI_ENGINE_CONTROL
float coolantC = ENGINE(sensors.clt); float newTCharge = getTCharge(rpm, tps, getCoolantTemperature(), getIntakeAirTemperature() PASS_ENGINE_PARAMETER_SUFFIX);
float intakeC = ENGINE(sensors.iat);
float newTCharge = getTCharge(rpm, tps, coolantC, intakeC PASS_ENGINE_PARAMETER_SUFFIX);
// convert to microsecs and then to seconds // convert to microsecs and then to seconds
efitick_t curTime = getTimeNowNt(); efitick_t curTime = getTimeNowNt();
float secsPassed = (float)NT2US(curTime - timeSinceLastTChargeK) / 1000000.0f; float secsPassed = (float)NT2US(curTime - timeSinceLastTChargeK) / 1000000.0f;

View File

@ -73,12 +73,14 @@ DISPLAY(DISPLAY_IF(isCrankingState)) floatms_t getCrankingFuel3(float coolantTem
DISPLAY_SENSOR(TPS); DISPLAY_SENSOR(TPS);
DISPLAY_TEXT(eol); DISPLAY_TEXT(eol);
DISPLAY_TEXT(Cranking_fuel); floatms_t crankingFuel = baseCrankingFuel
floatms_t crankingFuel = engine->engineState.DISPLAY_PREFIX(cranking).DISPLAY_FIELD(fuel) = baseCrankingFuel
* engine->engineState.cranking.durationCoefficient * engine->engineState.cranking.durationCoefficient
* engine->engineState.cranking.coolantTemperatureCoefficient * engine->engineState.cranking.coolantTemperatureCoefficient
* engine->engineState.cranking.tpsCoefficient; * engine->engineState.cranking.tpsCoefficient;
DISPLAY_TEXT(Cranking_fuel);
engine->engineState.DISPLAY_PREFIX(cranking).DISPLAY_FIELD(fuel) = crankingFuel;
if (crankingFuel <= 0) { if (crankingFuel <= 0) {
warning(CUSTOM_ERR_ZERO_CRANKING_FUEL, "Cranking fuel value %f", crankingFuel); warning(CUSTOM_ERR_ZERO_CRANKING_FUEL, "Cranking fuel value %f", crankingFuel);
} }

View File

@ -92,6 +92,8 @@
#include "cj125.h" #include "cj125.h"
#endif /* EFI_CJ125 */ #endif /* EFI_CJ125 */
EXTERN_ENGINE;
// this method is used by real firmware and simulator and unit test // this method is used by real firmware and simulator and unit test
void mostCommonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { void mostCommonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if !EFI_UNIT_TEST #if !EFI_UNIT_TEST
@ -114,6 +116,12 @@ void mostCommonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMET
initElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE); initElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */ #endif /* EFI_ELECTRONIC_THROTTLE_BODY */
#if EFI_MAP_AVERAGING
if (engineConfiguration->isMapAveragingEnabled) {
initMapAveraging(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
}
#endif /* EFI_MAP_AVERAGING */
} }
EXTERN_ENGINE; EXTERN_ENGINE;
@ -751,12 +759,6 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
initMalfunctionIndicator(); initMalfunctionIndicator();
#endif /* EFI_MALFUNCTION_INDICATOR */ #endif /* EFI_MALFUNCTION_INDICATOR */
#if EFI_MAP_AVERAGING
if (engineConfiguration->isMapAveragingEnabled) {
initMapAveraging(sharedLogger, engine);
}
#endif /* EFI_MAP_AVERAGING */
initEgoAveraging(PASS_ENGINE_PARAMETER_SIGNATURE); initEgoAveraging(PASS_ENGINE_PARAMETER_SIGNATURE);
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
@ -810,6 +812,6 @@ int getRusEfiVersion(void) {
if (initBootloader() != 0) if (initBootloader() != 0)
return 123; return 123;
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */ #endif /* EFI_BOOTLOADER_INCLUDE_CODE */
return 20191009; return 20191013;
} }
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */

View File

@ -111,15 +111,16 @@ static bool isAveraging = false;
static void startAveraging(void *arg) { static void startAveraging(void *arg) {
(void) arg; (void) arg;
efiAssertVoid(CUSTOM_ERR_6649, getCurrentRemainingStack() > 128, "lowstck#9"); efiAssertVoid(CUSTOM_ERR_6649, getCurrentRemainingStack() > 128, "lowstck#9");
bool wasLocked = lockAnyContext(); bool wasLocked = lockAnyContext();
;
// with locking we would have a consistent state // with locking we would have a consistent state
mapAdcAccumulator = 0; mapAdcAccumulator = 0;
mapMeasurementsCounter = 0; mapMeasurementsCounter = 0;
isAveraging = true; isAveraging = true;
if (!wasLocked) if (!wasLocked) {
unlockAnyContext(); unlockAnyContext();
; }
mapAveragingPin.setHigh(); mapAveragingPin.setHigh();
} }
@ -177,7 +178,9 @@ void mapAveragingAdcCallback(adcsample_t adcValue) {
static void endAveraging(void *arg) { static void endAveraging(void *arg) {
(void) arg; (void) arg;
#if ! EFI_UNIT_TEST
bool wasLocked = lockAnyContext(); bool wasLocked = lockAnyContext();
#endif
isAveraging = false; isAveraging = false;
// with locking we would have a consistent state // with locking we would have a consistent state
#if HAL_USE_ADC #if HAL_USE_ADC
@ -198,13 +201,15 @@ static void endAveraging(void *arg) {
warning(CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values"); warning(CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values");
} }
#endif #endif
#if ! EFI_UNIT_TEST
if (!wasLocked) if (!wasLocked)
unlockAnyContext(); unlockAnyContext();
; ;
#endif
mapAveragingPin.setLow(); mapAveragingPin.setLow();
} }
static void applyMapMinBufferLength() { static void applyMapMinBufferLength(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// check range // check range
mapMinBufferLength = maxI(minI(CONFIGB(mapMinBufferLength), MAX_MAP_BUFFER_LENGTH), 1); mapMinBufferLength = maxI(minI(CONFIGB(mapMinBufferLength), MAX_MAP_BUFFER_LENGTH), 1);
// reset index // reset index
@ -215,14 +220,14 @@ static void applyMapMinBufferLength() {
} }
} }
void postMapState(TunerStudioOutputChannels *tsOutputChannels) {
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO
void postMapState(TunerStudioOutputChannels *tsOutputChannels) {
tsOutputChannels->debugFloatField1 = v_averagedMapValue; tsOutputChannels->debugFloatField1 = v_averagedMapValue;
tsOutputChannels->debugFloatField2 = engine->engineState.mapAveragingDuration; tsOutputChannels->debugFloatField2 = engine->engineState.mapAveragingDuration;
tsOutputChannels->debugFloatField3 = currentPressure; tsOutputChannels->debugFloatField3 = currentPressure;
tsOutputChannels->debugIntField1 = mapMeasurementsCounter; tsOutputChannels->debugIntField1 = mapMeasurementsCounter;
#endif /* EFI_TUNER_STUDIO */
} }
#endif /* EFI_TUNER_STUDIO */
void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
int rpm = GET_RPM_VALUE; int rpm = GET_RPM_VALUE;
@ -237,6 +242,9 @@ void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
angle_t cylinderOffset = getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) * i / engineConfiguration->specs.cylindersCount; angle_t cylinderOffset = getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) * i / engineConfiguration->specs.cylindersCount;
efiAssertVoid(CUSTOM_ERR_6692, !cisnan(cylinderOffset), "cylinderOffset"); efiAssertVoid(CUSTOM_ERR_6692, !cisnan(cylinderOffset), "cylinderOffset");
// part of this formula related to specific cylinder offset is never changing - we can
// move the loop into start-up calculation and not have this loop as part of periodic calculation
// todo: change the logic as described above in order to reduce periodic CPU usage?
float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition(); float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition();
fixAngle(cylinderStart, "cylinderStart", CUSTOM_ERR_6562); fixAngle(cylinderStart, "cylinderStart", CUSTOM_ERR_6562);
engine->engineState.mapAveragingStart[i] = cylinderStart; engine->engineState.mapAveragingStart[i] = cylinderStart;
@ -272,7 +280,7 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType,
} }
if (CONFIGB(mapMinBufferLength) != mapMinBufferLength) { if (CONFIGB(mapMinBufferLength) != mapMinBufferLength) {
applyMapMinBufferLength(); applyMapMinBufferLength(PASS_ENGINE_PARAMETER_SIGNATURE);
} }
measurementsPerRevolution = measurementsPerRevolutionCounter; measurementsPerRevolution = measurementsPerRevolutionCounter;
@ -301,12 +309,14 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType,
fixAngle(samplingEnd, "samplingEnd", CUSTOM_ERR_6563); fixAngle(samplingEnd, "samplingEnd", CUSTOM_ERR_6563);
// only if value is already prepared // only if value is already prepared
int structIndex = engine->rpmCalculator.getRevolutionCounter() % 2; int structIndex = getRevolutionCounter() % 2;
// at the moment we schedule based on time prediction based on current RPM and angle
// we are loosing precision in case of changing RPM - the further away is the event the worse is precision
// todo: schedule this based on closest trigger event, same as ignition works // todo: schedule this based on closest trigger event, same as ignition works
scheduleByAngle(rpm, &startTimer[i][structIndex], samplingStart, scheduleByAngle(rpm, &startTimer[i][structIndex], samplingStart,
startAveraging, NULL, &engine->rpmCalculator); startAveraging, NULL, &engine->rpmCalculator PASS_ENGINE_PARAMETER_SUFFIX);
scheduleByAngle(rpm, &endTimer[i][structIndex], samplingEnd, scheduleByAngle(rpm, &endTimer[i][structIndex], samplingEnd,
endAveraging, NULL, &engine->rpmCalculator); endAveraging, NULL, &engine->rpmCalculator PASS_ENGINE_PARAMETER_SUFFIX);
engine->m.mapAveragingCbTime = getTimeNowLowerNt() engine->m.mapAveragingCbTime = getTimeNowLowerNt()
- engine->m.beforeMapAveragingCb; - engine->m.beforeMapAveragingCb;
} }
@ -338,7 +348,7 @@ float getMap(void) {
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
void initMapAveraging(Logging *sharedLogger, Engine *engine) { void initMapAveraging(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
logger = sharedLogger; logger = sharedLogger;
// startTimer[0].name = "map start0"; // startTimer[0].name = "map start0";
@ -350,7 +360,7 @@ void initMapAveraging(Logging *sharedLogger, Engine *engine) {
addTriggerEventListener(&mapAveragingTriggerCallback, "MAP averaging", engine); addTriggerEventListener(&mapAveragingTriggerCallback, "MAP averaging", engine);
#endif /* EFI_SHAFT_POSITION_INPUT */ #endif /* EFI_SHAFT_POSITION_INPUT */
addConsoleAction("faststat", showMapStats); addConsoleAction("faststat", showMapStats);
applyMapMinBufferLength(); applyMapMinBufferLength(PASS_ENGINE_PARAMETER_SIGNATURE);
} }
#else #else

View File

@ -16,9 +16,12 @@
void mapAveragingAdcCallback(adcsample_t newValue); void mapAveragingAdcCallback(adcsample_t newValue);
#endif #endif
void initMapAveraging(Logging *sharedLogger, Engine *engine); void initMapAveraging(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE); void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#if EFI_TUNER_STUDIO
void postMapState(TunerStudioOutputChannels *tsOutputChannels); void postMapState(TunerStudioOutputChannels *tsOutputChannels);
#endif
#endif /* EFI_MAP_AVERAGING */ #endif /* EFI_MAP_AVERAGING */

View File

@ -37,7 +37,7 @@
#include "tps.h" #include "tps.h"
#include "engine_math.h" #include "engine_math.h"
#include "fuel_math.h" #include "fuel_math.h"
#include "allsensors.h" #include "thermistors.h"
extern CANTxFrame txmsg; extern CANTxFrame txmsg;

View File

@ -338,7 +338,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
if (GET_RPM_VALUE < CONFIG(fuelClosedLoopRpmThreshold) || if (GET_RPM_VALUE < CONFIG(fuelClosedLoopRpmThreshold) ||
ENGINE(sensors.clt) < CONFIG(fuelClosedLoopCltThreshold) || getCoolantTemperature() < CONFIG(fuelClosedLoopCltThreshold) ||
getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(fuelClosedLoopTpsThreshold) || getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(fuelClosedLoopTpsThreshold) ||
ENGINE(sensors.currentAfr) < CONFIGB(fuelClosedLoopAfrLowThreshold) || ENGINE(sensors.currentAfr) < CONFIGB(fuelClosedLoopAfrLowThreshold) ||
ENGINE(sensors.currentAfr) > engineConfiguration->fuelClosedLoopAfrHighThreshold) { ENGINE(sensors.currentAfr) > engineConfiguration->fuelClosedLoopAfrHighThreshold) {
@ -583,7 +583,7 @@ void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// If 'primeInjFalloffTemperature' is not specified (by default), we have a prime pulse deactivation at zero celsius degrees, which is okay. // If 'primeInjFalloffTemperature' is not specified (by default), we have a prime pulse deactivation at zero celsius degrees, which is okay.
const float maxPrimeInjAtTemperature = -40.0f; // at this temperature the pulse is maximal. const float maxPrimeInjAtTemperature = -40.0f; // at this temperature the pulse is maximal.
floatms_t pulseLength = interpolateClamped(maxPrimeInjAtTemperature, CONFIG(startOfCrankingPrimingPulse), floatms_t pulseLength = interpolateClamped(maxPrimeInjAtTemperature, CONFIG(startOfCrankingPrimingPulse),
CONFIG(primeInjFalloffTemperature), 0.0f, ENGINE(sensors.clt)); CONFIG(primeInjFalloffTemperature), 0.0f, getCoolantTemperature());
if (pulseLength > 0) { if (pulseLength > 0) {
startSimultaniousInjection(engine); startSimultaniousInjection(engine);
efitimeus_t turnOffDelayUs = (efitimeus_t)efiRound(MS2US(pulseLength), 1.0f); efitimeus_t turnOffDelayUs = (efitimeus_t)efiRound(MS2US(pulseLength), 1.0f);

View File

@ -6,8 +6,11 @@
* Actual getRpm() is calculated once per crankshaft revolution, based on the amount of time passed * Actual getRpm() is calculated once per crankshaft revolution, based on the amount of time passed
* since the start of previous shaft revolution. * since the start of previous shaft revolution.
* *
* We also have 'instant RPM' logic separate from this 'cycle RPM' logic. Open question is why do we not use
* instant RPM instead of cycle RPM more often.
*
* @date Jan 1, 2013 * @date Jan 1, 2013
* @author Andrey Belomutskiy, (c) 2012-2018 * @author Andrey Belomutskiy, (c) 2012-2019
*/ */
#include "global.h" #include "global.h"
@ -22,8 +25,7 @@
#if EFI_PROD_CODE #if EFI_PROD_CODE
#include "os_util.h" #include "os_util.h"
#include "engine.h" #endif /* EFI_PROD_CODE */
#endif
#if EFI_SENSOR_CHART #if EFI_SENSOR_CHART
#include "sensor_chart.h" #include "sensor_chart.h"
@ -86,8 +88,6 @@ extern bool hasFirmwareErrorFlag;
static Logging * logger; static Logging * logger;
int revolutionCounterSinceBootForUnitTest = 0;
RpmCalculator::RpmCalculator() { RpmCalculator::RpmCalculator() {
#if !EFI_PROD_CODE #if !EFI_PROD_CODE
mockRpm = MOCK_UNDEFINED; mockRpm = MOCK_UNDEFINED;
@ -97,7 +97,6 @@ RpmCalculator::RpmCalculator() {
// we need this initial to have not_running at first invocation // we need this initial to have not_running at first invocation
lastRpmEventTimeNt = (efitime_t) -10 * US2NT(US_PER_SECOND_LL); lastRpmEventTimeNt = (efitime_t) -10 * US2NT(US_PER_SECOND_LL);
revolutionCounterSinceBootForUnitTest = 0;
} }
/** /**
@ -179,12 +178,9 @@ spinning_state_e RpmCalculator::getState() const {
void RpmCalculator::onNewEngineCycle() { void RpmCalculator::onNewEngineCycle() {
revolutionCounterSinceBoot++; revolutionCounterSinceBoot++;
revolutionCounterSinceStart++; revolutionCounterSinceStart++;
#if EFI_UNIT_TEST
revolutionCounterSinceBootForUnitTest = revolutionCounterSinceBoot;
#endif /* EFI_UNIT_TEST */
} }
uint32_t RpmCalculator::getRevolutionCounter(void) const { uint32_t RpmCalculator::getRevolutionCounterM(void) const {
return revolutionCounterSinceBoot; return revolutionCounterSinceBoot;
} }
@ -231,9 +227,7 @@ void RpmCalculator::setSpinningUp(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFI
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) { uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) {
efitick_t nowNt = getTimeNowNt(); efitick_t nowNt = getTimeNowNt();
#if EFI_PROD_CODE
efiAssertVoid(CUSTOM_ERR_6632, getCurrentRemainingStack() > 256, "lowstckRCL"); efiAssertVoid(CUSTOM_ERR_6632, getCurrentRemainingStack() > 256, "lowstckRCL");
#endif
RpmCalculator *rpmState = &engine->rpmCalculator; RpmCalculator *rpmState = &engine->rpmCalculator;
@ -316,7 +310,7 @@ static void tdcMarkCallback(trigger_event_e ckpSignalType,
(void) ckpSignalType; (void) ckpSignalType;
bool isTriggerSynchronizationPoint = index0 == 0; bool isTriggerSynchronizationPoint = index0 == 0;
if (isTriggerSynchronizationPoint && ENGINE(isEngineChartEnabled)) { if (isTriggerSynchronizationPoint && ENGINE(isEngineChartEnabled)) {
int revIndex2 = engine->rpmCalculator.getRevolutionCounter() % 2; int revIndex2 = getRevolutionCounter() % 2;
int rpm = GET_RPM(); int rpm = GET_RPM();
// todo: use tooth event-based scheduling, not just time-based scheduling // todo: use tooth event-based scheduling, not just time-based scheduling
if (isValidRpm(rpm)) { if (isValidRpm(rpm)) {
@ -327,12 +321,6 @@ static void tdcMarkCallback(trigger_event_e ckpSignalType,
} }
#endif #endif
#if EFI_PROD_CODE || EFI_SIMULATOR
int getRevolutionCounter() {
return engine->rpmCalculator.getRevolutionCounter();
}
#endif
/** /**
* @return Current crankshaft angle, 0 to 720 for four-stroke * @return Current crankshaft angle, 0 to 720 for four-stroke
*/ */
@ -362,7 +350,6 @@ void initRpmCalculator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
addTriggerEventListener(rpmShaftPositionCallback, "rpm reporter", engine); addTriggerEventListener(rpmShaftPositionCallback, "rpm reporter", engine);
} }
#if EFI_PROD_CODE || EFI_SIMULATOR
/** /**
* Schedules a callback 'angle' degree of crankshaft from now. * Schedules a callback 'angle' degree of crankshaft from now.
* The callback would be executed once after the duration of time which * The callback would be executed once after the duration of time which
@ -370,17 +357,17 @@ void initRpmCalculator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
*/ */
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle,
schfunc_t callback, void *param, RpmCalculator *calc DECLARE_ENGINE_PARAMETER_SUFFIX) { schfunc_t callback, void *param, RpmCalculator *calc DECLARE_ENGINE_PARAMETER_SUFFIX) {
// todo: remove 'calc' parameter
UNUSED(rpm); UNUSED(rpm);
ScopePerf perf(PE::ScheduleByAngle); ScopePerf perf(PE::ScheduleByAngle);
efiAssertVoid(CUSTOM_ANGLE_NAN, !cisnan(angle), "NaN angle?"); efiAssertVoid(CUSTOM_ANGLE_NAN, !cisnan(angle), "NaN angle?");
efiAssertVoid(CUSTOM_ERR_6634, isValidRpm(rpm), "RPM check expected"); efiAssertVoid(CUSTOM_ERR_6634, isValidRpm(rpm), "RPM check expected");
float delayUs = calc->oneDegreeUs * angle; float delayUs = ENGINE(rpmCalculator.oneDegreeUs) * angle;
efiAssertVoid(CUSTOM_ERR_6635, !cisnan(delayUs), "NaN delay?"); efiAssertVoid(CUSTOM_ERR_6635, !cisnan(delayUs), "NaN delay?");
engine->executor.scheduleForLater(timer, (int) delayUs, callback, param); ENGINE(executor.scheduleForLater(timer, (int) delayUs, callback, param));
} }
#endif
#else #else
RpmCalculator::RpmCalculator() { RpmCalculator::RpmCalculator() {

View File

@ -89,7 +89,7 @@ public:
* This method is invoked once per engine cycle right after we calculate new RPM value * This method is invoked once per engine cycle right after we calculate new RPM value
*/ */
void onNewEngineCycle(); void onNewEngineCycle();
uint32_t getRevolutionCounter(void) const; uint32_t getRevolutionCounterM(void) const;
void setRpmValue(int value DECLARE_ENGINE_PARAMETER_SUFFIX); void setRpmValue(int value DECLARE_ENGINE_PARAMETER_SUFFIX);
/** /**
* The same as setRpmValue() but without state change. * The same as setRpmValue() but without state change.
@ -158,7 +158,7 @@ void initRpmCalculator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
float getCrankshaftAngleNt(efitime_t timeNt DECLARE_ENGINE_PARAMETER_SUFFIX); float getCrankshaftAngleNt(efitime_t timeNt DECLARE_ENGINE_PARAMETER_SUFFIX);
int getRevolutionCounter(void); #define getRevolutionCounter() ENGINE(rpmCalculator.getRevolutionCounterM())
#if EFI_ENGINE_SNIFFER #if EFI_ENGINE_SNIFFER
#define addEngineSnifferEvent(name, msg) if (ENGINE(isEngineChartEnabled)) { waveChart.addEvent3((name), (msg)); } #define addEngineSnifferEvent(name, msg) if (ENGINE(isEngineChartEnabled)) { waveChart.addEvent3((name), (msg)); }

View File

@ -37,6 +37,10 @@ int isIgnitionTimingError(void) {
} }
static void fireSparkBySettingPinLow(IgnitionEvent *event, IgnitionOutputPin *output) { static void fireSparkBySettingPinLow(IgnitionEvent *event, IgnitionOutputPin *output) {
#if EFI_UNIT_TEST
Engine *engine = event->engine;
#endif /* EFI_UNIT_TEST */
#if SPARK_EXTREME_LOGGING #if SPARK_EXTREME_LOGGING
scheduleMsg(logger, "spark goes low %d %s %d current=%d cnt=%d id=%d", getRevolutionCounter(), output->name, (int)getTimeNowUs(), scheduleMsg(logger, "spark goes low %d %s %d current=%d cnt=%d id=%d", getRevolutionCounter(), output->name, (int)getTimeNowUs(),
output->currentLogicValue, output->outOfOrder, event->sparkId); output->currentLogicValue, output->outOfOrder, event->sparkId);
@ -162,7 +166,12 @@ if (engineConfiguration->debugMode == DBG_DWELL_METRIC) {
} }
static void startDwellByTurningSparkPinHigh(IgnitionEvent *event, IgnitionOutputPin *output) { static void startDwellByTurningSparkPinHigh(IgnitionEvent *event, IgnitionOutputPin *output) {
#if EFI_UNIT_TEST
Engine *engine = event->engine;
EXPAND_Engine;
#endif /* EFI_UNIT_TEST */
// todo: no reason for this to be disabled in unit_test mode?!
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
if (GET_RPM_VALUE > 2 * engineConfiguration->cranking.rpm) { if (GET_RPM_VALUE > 2 * engineConfiguration->cranking.rpm) {

View File

@ -77,7 +77,7 @@ static uint32_t skipUntilEngineCycle = 0;
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
extern WaveChart waveChart; extern WaveChart waveChart;
static void resetNow(void) { static void resetNow(void) {
skipUntilEngineCycle = engine->rpmCalculator.getRevolutionCounter() + 3; skipUntilEngineCycle = getRevolutionCounter() + 3;
waveChart.reset(); waveChart.reset();
} }
#endif #endif
@ -169,7 +169,7 @@ void WaveChart::addEvent3(const char *name, const char * msg) {
if (!ENGINE(isEngineChartEnabled)) { if (!ENGINE(isEngineChartEnabled)) {
return; return;
} }
if (skipUntilEngineCycle != 0 && ENGINE(rpmCalculator.getRevolutionCounter()) < skipUntilEngineCycle) if (skipUntilEngineCycle != 0 && getRevolutionCounter() < skipUntilEngineCycle)
return; return;
#if EFI_SIMULATOR #if EFI_SIMULATOR
// todo: add UI control to enable this for firmware if desired // todo: add UI control to enable this for firmware if desired

View File

@ -39,7 +39,7 @@ void scAddData(float angle, float value) {
return; return;
} }
if (engine->rpmCalculator.getRevolutionCounter() % engineConfiguration->sensorChartFrequency != 0) { if (getRevolutionCounter() % engineConfiguration->sensorChartFrequency != 0) {
/** /**
* We are here if we do NOT need to add an event to the analog chart * We are here if we do NOT need to add an event to the analog chart
*/ */

View File

@ -80,7 +80,7 @@ void WaveReader::onFallEvent() {
efitick_t width = nowUs - widthEventTimeUs; efitick_t width = nowUs - widthEventTimeUs;
last_wave_high_widthUs = width; last_wave_high_widthUs = width;
int revolutionCounter = engine->rpmCalculator.getRevolutionCounter(); int revolutionCounter = getRevolutionCounter();
totalOnTimeAccumulatorUs += width; totalOnTimeAccumulatorUs += width;
if (currentRevolutionCounter != revolutionCounter) { if (currentRevolutionCounter != revolutionCounter) {

View File

@ -1,12 +1,12 @@
// This file was generated by Version2Header // This file was generated by Version2Header
// Wed Sep 11 18:20:00 EDT 2019 // Mon Oct 14 12:58:12 EDT 2019
#ifndef GIT_HASH #ifndef GIT_HASH
#define GIT_HASH "33d13a78fc6eb5ba5c56835ab17b7ec1de34ed69" #define GIT_HASH "7bb8bb7f140d6d96962da164262b42e2ed3f4807"
#endif #endif
#ifndef VCS_VERSION #ifndef VCS_VERSION
#define VCS_VERSION "19879" #define VCS_VERSION "20053"
#endif #endif

View File

@ -120,7 +120,7 @@ void rusEfiFunctionalTest(void) {
initTriggerCentral(&sharedLogger); initTriggerCentral(&sharedLogger);
initTriggerEmulator(&sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); initTriggerEmulator(&sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
#if EFI_MAP_AVERAGING #if EFI_MAP_AVERAGING
initMapAveraging(&sharedLogger, engine); initMapAveraging(&sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
#endif /* EFI_MAP_AVERAGING */ #endif /* EFI_MAP_AVERAGING */
initMainEventListener(&sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); initMainEventListener(&sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);

View File

@ -64,5 +64,6 @@
#define EFI_BOARD_TEST FALSE #define EFI_BOARD_TEST FALSE
#define EFI_JOYSTICK FALSE #define EFI_JOYSTICK FALSE
#define EFI_MAP_AVERAGING TRUE
#endif /* EFIFEATURES_H_ */ #endif /* EFIFEATURES_H_ */

View File

@ -100,4 +100,8 @@ void print(const char *fmt, ...);
#define CONFIG_PARAM(x) (x) #define CONFIG_PARAM(x) (x)
#define lockAnyContext() false
#define unlockAnyContext() {}
#endif /* GLOBAL_H_ */ #endif /* GLOBAL_H_ */

View File

@ -34,12 +34,6 @@ efitick_t getTimeNowNt(void) {
LoggingWithStorage sharedLogger("main"); LoggingWithStorage sharedLogger("main");
extern int revolutionCounterSinceBootForUnitTest;
int getRevolutionCounter(void) {
return revolutionCounterSinceBootForUnitTest;
}
extern bool printTriggerDebug; extern bool printTriggerDebug;
bool verboseMode = false; bool verboseMode = false;
@ -47,7 +41,7 @@ GTEST_API_ int main(int argc, char **argv) {
// printTriggerDebug = true; // printTriggerDebug = true;
// resizeMap(); // resizeMap();
printf("Success 20190825\r\n"); printf("Success 20191013\r\n");
printAllTriggers(); printAllTriggers();
// printConvertedTable(); // printConvertedTable();
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);

View File

@ -85,11 +85,10 @@ TEST(misc, testFuelMap) {
setFlatInjectorLag(0 PASS_CONFIG_PARAMETER_SUFFIX); setFlatInjectorLag(0 PASS_CONFIG_PARAMETER_SUFFIX);
float iat = getIntakeAirTemperature(); ASSERT_FALSE(cisnan(getIntakeAirTemperature()));
ASSERT_FALSE(cisnan(iat));
float iatCorrection = getIatFuelCorrection(-KELV PASS_ENGINE_PARAMETER_SUFFIX); float iatCorrection = getIatFuelCorrection(-KELV PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_EQ( 2, iatCorrection) << "IAT"; ASSERT_EQ( 2, iatCorrection) << "IAT";
engine->sensors.clt = getCoolantTemperature(); ASSERT_FALSE(cisnan(getCoolantTemperature()));
float cltCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_SIGNATURE); float cltCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ( 1, cltCorrection) << "CLT"; ASSERT_EQ( 1, cltCorrection) << "CLT";
float injectorLag = getInjectorLag(getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); float injectorLag = getInjectorLag(getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX);

View File

@ -11,6 +11,7 @@
#include "fsio_impl.h" #include "fsio_impl.h"
#include "cli_registry.h" #include "cli_registry.h"
#include "engine_test_helper.h" #include "engine_test_helper.h"
#include "thermistors.h"
#define TEST_POOL_SIZE 256 #define TEST_POOL_SIZE 256
@ -19,7 +20,7 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
case LE_METHOD_FAN: case LE_METHOD_FAN:
return engine->fsioState.mockFan; return engine->fsioState.mockFan;
case LE_METHOD_COOLANT: case LE_METHOD_COOLANT:
return engine->sensors.clt; return getCoolantTemperature();
case LE_METHOD_RPM: case LE_METHOD_RPM:
return engine->fsioState.mockRpm; return engine->fsioState.mockRpm;
case LE_METHOD_CRANKING_RPM: case LE_METHOD_CRANKING_RPM:

View File

@ -584,7 +584,7 @@ static void setTestBug299(EngineTestHelper *eth) {
// inj #0 |.......#|........|.......#|........| // inj #0 |.......#|........|.......#|........|
// inj #1 |........|.......#|........|.......#| // inj #1 |........|.......#|........|.......#|
ASSERT_EQ( 4, engine->executor.size()) << "qs#00"; ASSERT_EQ( 4, engine->executor.size()) << "qs#00";
ASSERT_EQ( 3, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt#3"; ASSERT_EQ( 3, getRevolutionCounter()) << "rev cnt#3";
eth->assertInjectorUpEvent("setTestBug299: 1@0", 0, MS2US(8.5), 0); eth->assertInjectorUpEvent("setTestBug299: 1@0", 0, MS2US(8.5), 0);
eth->assertInjectorDownEvent("@1", 1, MS2US(10), 0); eth->assertInjectorDownEvent("@1", 1, MS2US(10), 0);
eth->assertInjectorUpEvent("1@2", 2, MS2US(18.5), 1); eth->assertInjectorUpEvent("1@2", 2, MS2US(18.5), 1);
@ -607,7 +607,7 @@ static void setTestBug299(EngineTestHelper *eth) {
// inj #0 |.......#|........|.......#|........| // inj #0 |.......#|........|.......#|........|
// inj #1 |........|.......#|........|.......#| // inj #1 |........|.......#|........|.......#|
ASSERT_EQ( 8, engine->executor.size()) << "qs#0"; ASSERT_EQ( 8, engine->executor.size()) << "qs#0";
ASSERT_EQ( 3, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt#3"; ASSERT_EQ( 3, getRevolutionCounter()) << "rev cnt#3";
eth->assertInjectorUpEvent("02@0", 0, MS2US(-11.5), 0); eth->assertInjectorUpEvent("02@0", 0, MS2US(-11.5), 0);
eth->assertInjectorDownEvent("@1", 1, MS2US(-10), 0); eth->assertInjectorDownEvent("@1", 1, MS2US(-10), 0);
eth->assertInjectorUpEvent("@2", 2, MS2US(-1.5), 1); eth->assertInjectorUpEvent("@2", 2, MS2US(-1.5), 1);
@ -650,7 +650,7 @@ static void setTestBug299(EngineTestHelper *eth) {
// inj #0 |.......#|........|........|........| // inj #0 |.......#|........|........|........|
// inj #1 |........|.......#|........|........| // inj #1 |........|.......#|........|........|
ASSERT_EQ( 4, engine->executor.size()) << "qs#0-2"; ASSERT_EQ( 4, engine->executor.size()) << "qs#0-2";
ASSERT_EQ( 4, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt#4"; ASSERT_EQ( 4, getRevolutionCounter()) << "rev cnt#4";
eth->assertInjectorUpEvent("0@0", 0, MS2US(8.5), 0); eth->assertInjectorUpEvent("0@0", 0, MS2US(8.5), 0);
eth->assertInjectorDownEvent("0@1", 1, MS2US(10), 0); eth->assertInjectorDownEvent("0@1", 1, MS2US(10), 0);
eth->assertInjectorUpEvent("0@2", 2, MS2US(18.5), 1); eth->assertInjectorUpEvent("0@2", 2, MS2US(18.5), 1);
@ -706,9 +706,9 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) {
ASSERT_EQ( 0, engine->executor.size()) << "qs#1#2"; ASSERT_EQ( 0, engine->executor.size()) << "qs#1#2";
ASSERT_EQ( 4, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt#4#0"; ASSERT_EQ( 4, getRevolutionCounter()) << "rev cnt#4#0";
eth.firePrimaryTriggerRise(); eth.firePrimaryTriggerRise();
ASSERT_EQ( 5, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt#4#1"; ASSERT_EQ( 5, getRevolutionCounter()) << "rev cnt#4#1";
// time...|0.......|10......|20......|30......|40......|50......|60......| // time...|0.......|10......|20......|30......|40......|50......|60......|
// inj #0 |########|##...###|########|.....###|########|........|........| // inj #0 |########|##...###|########|.....###|########|........|........|
// inj #1 |.....###|########|....####|########|........|........|........| // inj #1 |.....###|########|....####|########|........|........|........|
@ -726,7 +726,7 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) {
// { // {
// scheduling_s *ev = engine->executor.getForUnitTest(9); // scheduling_s *ev = engine->executor.getForUnitTest(9);
// ASSERT_EQ( 5, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt#4#2"; // ASSERT_EQ( 5, getRevolutionCounter()) << "rev cnt#4#2";
// ASSERT_TRUE(ev == &engineConfiguration->fuelActuators[2].signalPair[1].signalTimerDown) << "down 50"; // ASSERT_TRUE(ev == &engineConfiguration->fuelActuators[2].signalPair[1].signalTimerDown) << "down 50";
// } // }
@ -736,7 +736,7 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) {
eth.fireFall(20); eth.fireFall(20);
ASSERT_EQ( 8, engine->executor.size()) << "qs#2#1"; ASSERT_EQ( 8, engine->executor.size()) << "qs#2#1";
ASSERT_EQ( 5, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt#5"; ASSERT_EQ( 5, getRevolutionCounter()) << "rev cnt#5";
// using old fuel schedule - but already wider pulses // using old fuel schedule - but already wider pulses
// time...|-20.....|-10.....|0.......|10......|20......|30......|40......| // time...|-20.....|-10.....|0.......|10......|20......|30......|40......|
// inj #0 |........|.....###|########|.....###|########|........|........| // inj #0 |........|.....###|########|.....###|########|........|........|
@ -781,7 +781,7 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) {
eth.firePrimaryTriggerRise(); eth.firePrimaryTriggerRise();
ASSERT_EQ( 4, engine->executor.size()) << "qs#2#2"; ASSERT_EQ( 4, engine->executor.size()) << "qs#2#2";
ASSERT_EQ( 6, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt6"; ASSERT_EQ( 6, getRevolutionCounter()) << "rev cnt6";
// time...|-20.....|-10.....|0.......|10......|20......|30......|40......| // time...|-20.....|-10.....|0.......|10......|20......|30......|40......|
// inj #0 |########|.....###|########|....####|........|........|........| // inj #0 |########|.....###|########|....####|........|........|........|
// inj #1 |.....###|########|.....###|########|........|........|........| // inj #1 |.....###|########|.....###|########|........|........|........|
@ -821,7 +821,7 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) {
eth.firePrimaryTriggerFall(); eth.firePrimaryTriggerFall();
ASSERT_EQ( 5, engine->executor.size()) << "qs#3"; ASSERT_EQ( 5, engine->executor.size()) << "qs#3";
ASSERT_EQ( 6, engine->rpmCalculator.getRevolutionCounter()) << "rev cnt6"; ASSERT_EQ( 6, getRevolutionCounter()) << "rev cnt6";
ASSERT_EQ( 0, eth.executeActions()) << "executed #6"; ASSERT_EQ( 0, eth.executeActions()) << "executed #6";

View File

@ -12,6 +12,9 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
// This lets us inspect private state from unit tests
#define private public
#define EPS1D 0.1 #define EPS1D 0.1
#define EPS2D 0.01 #define EPS2D 0.01
#define EPS3D 0.001 #define EPS3D 0.001