From 8e7d2a8e3334e38303c639243cdb50805aaf42cd Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 30 May 2015 20:04:45 -0400 Subject: [PATCH] auto-sync --- firmware/controllers/algo/engine.h | 6 ++++++ firmware/hw_layer/HIP9011.cpp | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index e3357d928f..a6e48e5a18 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -195,7 +195,13 @@ public: bool_t isRunningPwmTest; + /** + * Are we experiencing knock right now? + */ bool_t knockNow; + /** + * Have we experienced knock since engine was started? + */ bool_t knockEver; /** diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index 6accb75e05..2aafdcf8cc 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -21,6 +21,7 @@ * * @date Nov 27, 2013 * @author Andrey Belomutskiy, (c) 2012-2015 + * @Spilly */ #include "main.h" @@ -55,6 +56,7 @@ static int currentGainIndex = -1; static int currentIntergratorIndex = -1; static int settingUpdateCount = 0; static int totalKnockEventsCount = 0; +static int currentPrescaler; static efitimeus_t timeOfLastKnockEvent = 0; @@ -195,7 +197,6 @@ static void intHoldCallback(trigger_event_e ckpEventType, uint32_t index DECLARE static void setPrescalerAndSDO(int value) { engineConfiguration->hip9011PrescalerAndSDO = value; - scheduleMsg(logger, "Reboot to apply %d", value); } static void setBand(float value) { @@ -230,24 +231,32 @@ void hipAdcCallback(adcsample_t value) { int integratorIndex = getIntegrationIndexByRpm(engine->rpmCalculator.rpmValue); int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain); int bandIndex = getBandIndex(); + int prescalerIndex = engineConfiguration->hip9011PrescalerAndSDO; if (currentGainIndex != gainIndex) { currentGainIndex = gainIndex; - tx_buff[0] = gainIndex; + tx_buff[0] = SET_GAIN_CMD + gainIndex; state = IS_SENDING_SPI_COMMAND; spiSelectI(driver); spiStartExchangeI(driver, 1, tx_buff, rx_buff); } else if (currentIntergratorIndex != integratorIndex) { currentIntergratorIndex = integratorIndex; - tx_buff[0] = integratorIndex; + tx_buff[0] = SET_INTEGRATOR_CMD + integratorIndex; state = IS_SENDING_SPI_COMMAND; spiSelectI(driver); spiStartExchangeI(driver, 1, tx_buff, rx_buff); } else if (currentBandIndex != bandIndex) { currentBandIndex = bandIndex; - tx_buff[0] = bandIndex; + tx_buff[0] = SET_BAND_PASS_CMD + bandIndex; + + state = IS_SENDING_SPI_COMMAND; + spiSelectI(driver); + spiStartExchangeI(driver, 1, tx_buff, rx_buff); + } else if (currentPrescaler != prescalerIndex) { + currentPrescaler = prescalerIndex; + tx_buff[0] = SET_PRESCALER_CMD + prescalerIndex; state = IS_SENDING_SPI_COMMAND; spiSelectI(driver); @@ -257,7 +266,6 @@ void hipAdcCallback(adcsample_t value) { } } } - static bool_t needToInit = true; static void hipStartupCode(void) { @@ -272,8 +280,9 @@ static void hipStartupCode(void) { // D[4:1] = 1000 : 24 MHz - // '0' for 4MHz - SPI_SYNCHRONOUS(SET_PRESCALER_CMD + engineConfiguration->hip9011PrescalerAndSDO); +// '0' for 4MHz + currentPrescaler = engineConfiguration->hip9011PrescalerAndSDO; + SPI_SYNCHRONOUS(SET_PRESCALER_CMD + currentPrescaler); chThdSleepMilliseconds(10);