From b9a811ea8e9305aebe48107dbc15bdf674c59064 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 14 Jan 2015 22:03:40 -0600 Subject: [PATCH] auto-sync --- firmware/console/status_loop.cpp | 1 + .../tunerstudio/tunerstudio_configuration.h | 3 ++- .../controllers/algo/engine_configuration.h | 3 ++- .../controllers/trigger/rpm_calculator.cpp | 5 ++++ firmware/controllers/trigger/rpm_calculator.h | 5 ++++ firmware/hw_layer/HIP9011.cpp | 26 ++++++++++++++++--- firmware/hw_layer/HIP9011.h | 8 ++++++ firmware/hw_layer/adc_inputs.h | 1 - 8 files changed, 46 insertions(+), 6 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 6acc53e703..e12cb629c1 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -505,6 +505,7 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputC tsOutputChannels->atmospherePressure = getBaroPressure(); tsOutputChannels->manifold_air_pressure = getMap(); tsOutputChannels->engineLoad = engineLoad; + tsOutputChannels->rpmAcceleration = engine->rpmCalculator.getRpmAcceleration(); tsOutputChannels->checkEngine = hasErrorCodes(); #if EFI_PROD_CODE diff --git a/firmware/console/tunerstudio/tunerstudio_configuration.h b/firmware/console/tunerstudio/tunerstudio_configuration.h index a5f3dc89c4..3c093f1e26 100644 --- a/firmware/console/tunerstudio/tunerstudio_configuration.h +++ b/firmware/console/tunerstudio/tunerstudio_configuration.h @@ -80,7 +80,8 @@ typedef struct { unsigned int isAcSwitchEngaged : 1; // bit 4 int tsConfigVersion; egt_values_s egtValues; - int unused3[3]; + float rpmAcceleration; + int unused3[2]; } TunerStudioOutputChannels; #endif /* TUNERSTUDIO_CONFIGURATION_H_ */ diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 2f4ab32222..752ff6e8b8 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -612,7 +612,8 @@ typedef struct { */ brain_pin_e clutchUpPin; pin_input_mode_e clutchUpPinMode; - int unused3[182]; + float hipThreshold; + int unused3[181]; le_formula_t timingMultiplier; le_formula_t timingAdditive; diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 5410211add..8b87731802 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -68,6 +68,7 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_F) { } void RpmCalculator::setRpmValue(int value) { + previousRpmValue = rpmValue; rpmValue = value; if (rpmValue <= 0) { oneDegreeUs = NAN; @@ -89,6 +90,10 @@ uint32_t RpmCalculator::getRevolutionCounterSinceStart(void) { return revolutionCounterSinceStart; } +float RpmCalculator::getRpmAcceleration() { + return 1.0 * previousRpmValue / rpmValue; +} + /** * WARNING: this is a heavy method because 'getRpm()' is relatively heavy * diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 73dd666126..f9a2896c8d 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -38,14 +38,19 @@ public: */ bool isRunning(DECLARE_ENGINE_PARAMETER_F); int rpm(DECLARE_ENGINE_PARAMETER_F); + /** + * This method is invoked once per engine cycle right after we calculate new RPM value + */ void onNewEngineCycle(); uint32_t getRevolutionCounter(void); void setRpmValue(int value); uint32_t getRevolutionCounterSinceStart(void); + float getRpmAcceleration(); /** * This is public because sometimes we cannot afford to call isRunning() and the value is good enough */ volatile int rpmValue; + int previousRpmValue; /** * This is a performance optimization: let's pre-calulate this each time RPM changes */ diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index b59873613d..4971a01055 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -32,6 +32,7 @@ #include "trigger_central.h" #include "hip9011_lookup.h" #include "HIP9011.h" +#include "adc_inputs.h" #if EFI_HIP_9011 || defined(__DOXYGEN__) @@ -47,6 +48,10 @@ static int bandIndex; static int currentGainIndex = -1; static int currentIntergratorIndex = -1; static int settingUpdateCount = 0; +static int totalKnockEventsCount = 0; + +static hip_state_e state = READY_TO_INTEGRATE; +static efitimeus_t timeOfLastKnockEvent = 0; /** * Int/Hold pin is controlled from scheduler callbacks which are set according to current RPM @@ -96,9 +101,11 @@ static void showHipInfo(void) { scheduleMsg(logger, "bore=%f freq=%f", engineConfiguration->cylinderBore, BAND(engineConfiguration->cylinderBore)); scheduleMsg(logger, "band_index=%d gain %f/index=%d", bandIndex, boardConfiguration->hip9011Gain, currentGainIndex); - scheduleMsg(logger, "integrator index=%d", currentIntergratorIndex); + scheduleMsg(logger, "integrator index=%d hip_threshold=%f totalKnockEventsCount=%d", currentIntergratorIndex, + engineConfiguration->hipThreshold, totalKnockEventsCount); - scheduleMsg(logger, "spi= int=%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin), nonZeroResponse); + scheduleMsg(logger, "spi= int=%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin), + nonZeroResponse); scheduleMsg(logger, "CS=%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount); } @@ -110,6 +117,8 @@ void setHip9011FrankensoPinout(void) { boardConfiguration->hip9011CsPin = GPIOD_0; boardConfiguration->hip9011IntHoldPin = GPIOB_11; boardConfiguration->is_enabled_spi_2 = true; + + engineConfiguration->hipThreshold = 2; } static void startIntegration(void) { @@ -119,6 +128,7 @@ static void startIntegration(void) { * until we are done integrating */ isIntegrating = true; + state = IS_INTEGRATING; intHold.setValue(true); } } @@ -136,6 +146,7 @@ static void endIntegration(void) { int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain); if (currentGainIndex != gainIndex) { + state = IS_SENDING_SPI_COMMAND; tx_buff[0] = gainIndex; currentGainIndex = gainIndex; @@ -146,6 +157,7 @@ static void endIntegration(void) { } if (currentIntergratorIndex != integratorIndex) { + state = IS_SENDING_SPI_COMMAND; tx_buff[0] = integratorIndex; currentIntergratorIndex = integratorIndex; @@ -154,6 +166,7 @@ static void endIntegration(void) { spiStartExchangeI(driver, 1, tx_buff, rx_buff); return; } + state = READY_TO_INTEGRATE; } } @@ -190,7 +203,14 @@ static void endOfSpiCommunication(SPIDriver *spip) { } void hipAdcCallback(adcsample_t value) { - + if (state == WAITING_FOR_ADC_TO_SKIP) { + state = WAITING_FOR_RESULT_ADC; + } else if (state == WAITING_FOR_RESULT_ADC) { + if (adcToVoltsDivided(value) > engineConfiguration->hipThreshold) { + totalKnockEventsCount++; + timeOfLastKnockEvent = getTimeNowUs(); + } + } } void initHip9011(Logging *sharedLogger) { diff --git a/firmware/hw_layer/HIP9011.h b/firmware/hw_layer/HIP9011.h index 2e7bad6d3d..b3e26cc54b 100644 --- a/firmware/hw_layer/HIP9011.h +++ b/firmware/hw_layer/HIP9011.h @@ -9,6 +9,14 @@ #ifndef HIP9011_H_ #define HIP9011_H_ +typedef enum { + READY_TO_INTEGRATE, + IS_INTEGRATING, + IS_SENDING_SPI_COMMAND, + WAITING_FOR_ADC_TO_SKIP, + WAITING_FOR_RESULT_ADC, +} hip_state_e; + // 0b01000000 #define SET_PRESCALER_CMD 0x40 diff --git a/firmware/hw_layer/adc_inputs.h b/firmware/hw_layer/adc_inputs.h index 6ef34572b1..4595d13264 100644 --- a/firmware/hw_layer/adc_inputs.h +++ b/firmware/hw_layer/adc_inputs.h @@ -14,7 +14,6 @@ #if HAL_USE_ADC || defined(__DOXYGEN__) - const char * getAdcMode(adc_channel_e hwChannel); int getAdcChannelPin(adc_channel_e hwChannel); void initAdcInputs(bool boardTestMode);