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 EFI_MAP_AVERAGING
if (engineConfiguration->isMapAveragingEnabled) { if (engineConfiguration->isMapAveragingEnabled) {
initMapAveraging(sharedLogger, engine); initMapAveraging(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
} }
#endif /* EFI_MAP_AVERAGING */ #endif /* EFI_MAP_AVERAGING */
@ -831,6 +831,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

@ -110,15 +110,19 @@ 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");
#if !EFI_UNIT_TEST
bool wasLocked = lockAnyContext(); bool wasLocked = lockAnyContext();
; #endif
// 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 !EFI_UNIT_TEST
if (!wasLocked) {
unlockAnyContext(); unlockAnyContext();
; }
#endif /* !EFI_UNIT_TEST */
mapAveragingPin.setHigh(); mapAveragingPin.setHigh();
} }
@ -176,7 +180,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
@ -197,13 +203,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
@ -214,14 +222,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;
@ -271,7 +279,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;
@ -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 // 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;
} }
@ -339,7 +347,7 @@ float getMap(void) {
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
void initMapAveraging(Logging *sharedLogger, Engine *engine) { void initMapAveraging(Logging *sharedLogger DECLARE_CONFIG_PARAMETER_SUFFIX) {
logger = sharedLogger; logger = sharedLogger;
// startTimer[0].name = "map start0"; // startTimer[0].name = "map start0";
@ -351,7 +359,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,7 +16,7 @@
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 #if EFI_TUNER_STUDIO

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 FALSE
#endif /* EFIFEATURES_H_ */ #endif /* EFIFEATURES_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);