preparing for #974

code comments & refactoring
This commit is contained in:
rusefi 2019-10-14 09:09:08 -04:00
parent 12137fc7cd
commit 7bb8bb7f14
5 changed files with 24 additions and 21 deletions

View File

@ -774,7 +774,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
#if EFI_MAP_AVERAGING
if (engineConfiguration->isMapAveragingEnabled) {
initMapAveraging(sharedLogger, engine);
initMapAveraging(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
}
#endif /* EFI_MAP_AVERAGING */
@ -831,6 +831,6 @@ int getRusEfiVersion(void) {
if (initBootloader() != 0)
return 123;
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
return 20191009;
return 20191013;
}
#endif /* EFI_UNIT_TEST */

View File

@ -110,15 +110,19 @@ static bool isAveraging = false;
static void startAveraging(void *arg) {
(void) arg;
efiAssertVoid(CUSTOM_ERR_6649, getCurrentRemainingStack() > 128, "lowstck#9");
#if !EFI_UNIT_TEST
bool wasLocked = lockAnyContext();
;
#endif
// with locking we would have a consistent state
mapAdcAccumulator = 0;
mapMeasurementsCounter = 0;
isAveraging = true;
if (!wasLocked)
#if !EFI_UNIT_TEST
if (!wasLocked) {
unlockAnyContext();
;
}
#endif /* !EFI_UNIT_TEST */
mapAveragingPin.setHigh();
}
@ -176,7 +180,9 @@ void mapAveragingAdcCallback(adcsample_t adcValue) {
static void endAveraging(void *arg) {
(void) arg;
#if ! EFI_UNIT_TEST
bool wasLocked = lockAnyContext();
#endif
isAveraging = false;
// with locking we would have a consistent state
#if HAL_USE_ADC
@ -197,13 +203,15 @@ static void endAveraging(void *arg) {
warning(CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values");
}
#endif
#if ! EFI_UNIT_TEST
if (!wasLocked)
unlockAnyContext();
;
#endif
mapAveragingPin.setLow();
}
static void applyMapMinBufferLength() {
static void applyMapMinBufferLength(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// check range
mapMinBufferLength = maxI(minI(CONFIGB(mapMinBufferLength), MAX_MAP_BUFFER_LENGTH), 1);
// reset index
@ -214,14 +222,14 @@ static void applyMapMinBufferLength() {
}
}
void postMapState(TunerStudioOutputChannels *tsOutputChannels) {
#if EFI_TUNER_STUDIO
void postMapState(TunerStudioOutputChannels *tsOutputChannels) {
tsOutputChannels->debugFloatField1 = v_averagedMapValue;
tsOutputChannels->debugFloatField2 = engine->engineState.mapAveragingDuration;
tsOutputChannels->debugFloatField3 = currentPressure;
tsOutputChannels->debugIntField1 = mapMeasurementsCounter;
#endif /* EFI_TUNER_STUDIO */
}
#endif /* EFI_TUNER_STUDIO */
void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
int rpm = GET_RPM_VALUE;
@ -271,7 +279,7 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType,
}
if (CONFIGB(mapMinBufferLength) != mapMinBufferLength) {
applyMapMinBufferLength();
applyMapMinBufferLength(PASS_ENGINE_PARAMETER_SIGNATURE);
}
measurementsPerRevolution = measurementsPerRevolutionCounter;
@ -305,9 +313,9 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType,
// 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
scheduleByAngle(rpm, &startTimer[i][structIndex], samplingStart,
startAveraging, NULL, &engine->rpmCalculator);
startAveraging, NULL, &engine->rpmCalculator PASS_ENGINE_PARAMETER_SUFFIX);
scheduleByAngle(rpm, &endTimer[i][structIndex], samplingEnd,
endAveraging, NULL, &engine->rpmCalculator);
endAveraging, NULL, &engine->rpmCalculator PASS_ENGINE_PARAMETER_SUFFIX);
engine->m.mapAveragingCbTime = getTimeNowLowerNt()
- engine->m.beforeMapAveragingCb;
}
@ -339,7 +347,7 @@ float getMap(void) {
}
#endif /* EFI_PROD_CODE */
void initMapAveraging(Logging *sharedLogger, Engine *engine) {
void initMapAveraging(Logging *sharedLogger DECLARE_CONFIG_PARAMETER_SUFFIX) {
logger = sharedLogger;
// startTimer[0].name = "map start0";
@ -351,7 +359,7 @@ void initMapAveraging(Logging *sharedLogger, Engine *engine) {
addTriggerEventListener(&mapAveragingTriggerCallback, "MAP averaging", engine);
#endif /* EFI_SHAFT_POSITION_INPUT */
addConsoleAction("faststat", showMapStats);
applyMapMinBufferLength();
applyMapMinBufferLength(PASS_ENGINE_PARAMETER_SIGNATURE);
}
#else

View File

@ -16,7 +16,7 @@
void mapAveragingAdcCallback(adcsample_t newValue);
#endif
void initMapAveraging(Logging *sharedLogger, Engine *engine);
void initMapAveraging(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#if EFI_TUNER_STUDIO

View File

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

View File

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