diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 8eba5363a6..ca714cd618 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -75,6 +75,10 @@ extern bool main_loop_started; #include "CJ125.h" #endif /* EFI_PROD_CODE */ +#if EFI_MAP_AVERAGING +#include "map_averaging.h" +#endif + #if EFI_FSIO || defined(__DOXYGEN__) #include "fsio_impl.h" #endif /* EFI_FSIO */ @@ -808,6 +812,11 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ cjPostState(tsOutputChannels); break; #endif /* EFI_CJ125 */ +#if EFI_MAP_AVERAGING + case DBG_MAP: + postMapState(tsOutputChannels); + break; +#endif /* EFI_MAP_AVERAGING */ #if EFI_CAN_SUPPORT || defined(__DOXYGEN__) case DBG_CAN: postCanState(tsOutputChannels); diff --git a/firmware/controllers/algo/auto_generated_enums.cpp b/firmware/controllers/algo/auto_generated_enums.cpp index f27d2b15d5..1a91c52310 100644 --- a/firmware/controllers/algo/auto_generated_enums.cpp +++ b/firmware/controllers/algo/auto_generated_enums.cpp @@ -713,8 +713,8 @@ case DBG_CJ125: return "DBG_CJ125"; case DBG_CAN: return "DBG_CAN"; -case DBG_27: - return "DBG_27"; +case DBG_MAP: + return "DBG_MAP"; case DBG_28: return "DBG_28"; case DBG_29: diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index ac07d03e33..6f968c2dfb 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -763,7 +763,7 @@ typedef enum { DBG_STATUS = 24, DBG_CJ125 = 25, DBG_CAN = 26, - DBG_27 = 27, + DBG_MAP = 27, DBG_28 = 28, DBG_29 = 29, diff --git a/firmware/controllers/algo/rusefi_generated.h b/firmware/controllers/algo/rusefi_generated.h index 810e37fc8a..1be0ed14da 100644 --- a/firmware/controllers/algo/rusefi_generated.h +++ b/firmware/controllers/algo/rusefi_generated.h @@ -55,7 +55,7 @@ #define MAP_ACCEL_TAPER 8 #define BARO_CORR_SIZE 4 #define MAF_DECODING_COUNT 256 -#define debug_mode_e_enum "Alternator_PID", "TPS accel enrich", "Warmup PID", "IDLE", "EL accl enrich", "Trigger Counters", "FSIO_ADC", "AUX_PID_1", "VVT PID", "Cranking", "Timing", "Closed-loop fuel corr PID", "VSS", "SD card", "sr5", "Knock", "Trigger Sync", "Electronic Throttle", "Executor", "Bench Test", "Aux Valves", "ADC", "INSTANT_RPM", "FSIO_EXPRESSION", "Status", "CJ125", "CAN", "mode27", "mode28", "mode29" +#define debug_mode_e_enum "Alternator_PID", "TPS accel enrich", "Warmup PID", "IDLE", "EL accl enrich", "Trigger Counters", "FSIO_ADC", "AUX_PID_1", "VVT PID", "Cranking", "Timing", "Closed-loop fuel corr PID", "VSS", "SD card", "sr5", "Knock", "Trigger Sync", "Electronic Throttle", "Executor", "Bench Test", "Aux Valves", "ADC", "INSTANT_RPM", "FSIO_EXPRESSION", "Status", "CJ125", "CAN", "MAP", "mode28", "mode29" #define vvt_mode_e_enum "First half", "Second half", "2GZ", "Miata NB2", "mode4", "mode5", "mode6", "mode7" #define mass_storage_e_enum "Auto", "Always", "Never" #define brain_input_pin_e_enum "INVALID", "PA1", "PA2", "PA3", "INVALID", "PA5", "PA6", "PA7", "PA8", "PA9", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PA15", "INVALID", "INVALID", "INVALID", "PB3", "PB4", "PB5", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PC6", "PC7", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PE5", "PE6", "INVALID", "INVALID", "PE9", "INVALID", "PE11", "INVALID", "INVALID", "INVALID", "INVALID", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index 37a511f7e5..e240374bf3 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -69,7 +69,7 @@ static int counters[2]; /** * Running MAP accumulator - sum of all measurements within averaging window */ -static volatile float mapAccumulator = 0; +static volatile float mapAdcAccumulator = 0; /** * Running counter of measurements to consider for averaging */ @@ -110,7 +110,7 @@ static void startAveraging(void *arg) { bool wasLocked = lockAnyContext(); ; // with locking we would have a consistent state - mapAccumulator = 0; + mapAdcAccumulator = 0; mapMeasurementsCounter = 0; isAveraging = true; if (!wasLocked) @@ -163,7 +163,7 @@ void mapAveragingAdcCallback(adcsample_t adcValue) { ; // with locking we would have a consistent state - mapAccumulator += adcValue; + mapAdcAccumulator += adcValue; mapMeasurementsCounter++; if (!alreadyLocked) unlockAnyContext(); @@ -177,8 +177,7 @@ static void endAveraging(void *arg) { isAveraging = false; // with locking we would have a consistent state #if EFI_PROD_CODE || defined(__DOXYGEN__) - v_averagedMapValue = adcToVoltsDivided( - mapAccumulator / mapMeasurementsCounter); + v_averagedMapValue = adcToVoltsDivided(mapAdcAccumulator / mapMeasurementsCounter); // todo: move out of locked context? averagedMapRunningBuffer[averagedMapBufIdx] = getMapByVoltage(v_averagedMapValue); // increment circular running buffer index @@ -208,6 +207,12 @@ static void applyMapMinBufferLength() { } } +void postMapState(TunerStudioOutputChannels *tsOutputChannels) { + tsOutputChannels->debugFloatField1 = v_averagedMapValue; + tsOutputChannels->debugFloatField2 = engine->engineState.mapAveragingDuration; + tsOutputChannels->debugIntField1 = mapMeasurementsCounter; +} + void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int rpm = engine->rpmCalculator.rpmValue; if (isValidRpm(rpm)) { @@ -267,20 +272,25 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, } angle_t samplingEnd = samplingStart + samplingDuration; - if (!cisnan(samplingEnd)) { - fixAngle(samplingEnd, "samplingEnd"); - // only if value is already prepared - int structIndex = getRevolutionCounter() % 2; - // todo: schedule this based on closest trigger event, same as ignition works - scheduleByAngle(rpm, &startTimer[i][structIndex], samplingStart, - startAveraging, NULL, &engine->rpmCalculator); - scheduleByAngle(rpm, &endTimer[i][structIndex], samplingEnd, - endAveraging, NULL, &engine->rpmCalculator); - engine->m.mapAveragingCbTime = GET_TIMESTAMP() - - engine->m.beforeMapAveragingCb; - } - } + if (cisnan(samplingEnd)) { + // todo: when would this happen? + warning(CUSTOM_ERR_6549, "no map angles"); + return; + } + + + fixAngle(samplingEnd, "samplingEnd"); + // only if value is already prepared + int structIndex = getRevolutionCounter() % 2; + // todo: schedule this based on closest trigger event, same as ignition works + scheduleByAngle(rpm, &startTimer[i][structIndex], samplingStart, + startAveraging, NULL, &engine->rpmCalculator); + scheduleByAngle(rpm, &endTimer[i][structIndex], samplingEnd, + endAveraging, NULL, &engine->rpmCalculator); + engine->m.mapAveragingCbTime = GET_TIMESTAMP() + - engine->m.beforeMapAveragingCb; + } } static void showMapStats(void) { diff --git a/firmware/controllers/map_averaging.h b/firmware/controllers/map_averaging.h index 08edb379a4..2142705c30 100644 --- a/firmware/controllers/map_averaging.h +++ b/firmware/controllers/map_averaging.h @@ -18,6 +18,7 @@ void mapAveragingAdcCallback(adcsample_t newValue); void initMapAveraging(Logging *sharedLogger, Engine *engine); void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE); +void postMapState(TunerStudioOutputChannels *tsOutputChannels); #endif /* EFI_MAP_AVERAGING */ diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 4b6ef49adc..a4263d1038 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -148,7 +148,7 @@ float baseFuel;+Fuel squirt duration while cranking\nA number of curves adjust t int16_t rpm;+Cranking mode threshold. Special cranking logic controls fuel and spark while RPM is below this threshold\nset cranking_rpm X;"RPM", 1, 0, 0, 3000, 0 end_struct -#define debug_mode_e_enum "Alternator_PID", "TPS accel enrich", "Warmup PID", "IDLE", "EL accl enrich", "Trigger Counters", "FSIO_ADC", "AUX_PID_1", "VVT PID", "Cranking", "Timing", "Closed-loop fuel corr PID", "VSS", "SD card", "sr5", "Knock", "Trigger Sync", "Electronic Throttle", "Executor", "Bench Test", "Aux Valves", "ADC", "INSTANT_RPM", "FSIO_EXPRESSION", "Status", "CJ125", "CAN", "mode27", "mode28", "mode29" +#define debug_mode_e_enum "Alternator_PID", "TPS accel enrich", "Warmup PID", "IDLE", "EL accl enrich", "Trigger Counters", "FSIO_ADC", "AUX_PID_1", "VVT PID", "Cranking", "Timing", "Closed-loop fuel corr PID", "VSS", "SD card", "sr5", "Knock", "Trigger Sync", "Electronic Throttle", "Executor", "Bench Test", "Aux Valves", "ADC", "INSTANT_RPM", "FSIO_EXPRESSION", "Status", "CJ125", "CAN", "MAP", "mode28", "mode29" custom debug_mode_e 4 bits, U32, @OFFSET@, [0:4], @@debug_mode_e_enum@@ #define vvt_mode_e_enum "First half", "Second half", "2GZ", "Miata NB2", "mode4", "mode5", "mode6", "mode7"