auto-sync
This commit is contained in:
parent
f2245df847
commit
3fed6f6b22
|
@ -195,7 +195,13 @@ public:
|
||||||
|
|
||||||
bool_t isRunningPwmTest;
|
bool_t isRunningPwmTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we experiencing knock right now?
|
||||||
|
*/
|
||||||
bool_t knockNow;
|
bool_t knockNow;
|
||||||
|
/**
|
||||||
|
* Have we experienced knock since engine was started?
|
||||||
|
*/
|
||||||
bool_t knockEver;
|
bool_t knockEver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*
|
*
|
||||||
* @date Nov 27, 2013
|
* @date Nov 27, 2013
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2015
|
* @author Andrey Belomutskiy, (c) 2012-2015
|
||||||
|
* @Spilly
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
@ -55,6 +56,7 @@ static int currentGainIndex = -1;
|
||||||
static int currentIntergratorIndex = -1;
|
static int currentIntergratorIndex = -1;
|
||||||
static int settingUpdateCount = 0;
|
static int settingUpdateCount = 0;
|
||||||
static int totalKnockEventsCount = 0;
|
static int totalKnockEventsCount = 0;
|
||||||
|
static int currentPrescaler;
|
||||||
|
|
||||||
static efitimeus_t timeOfLastKnockEvent = 0;
|
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) {
|
static void setPrescalerAndSDO(int value) {
|
||||||
engineConfiguration->hip9011PrescalerAndSDO = value;
|
engineConfiguration->hip9011PrescalerAndSDO = value;
|
||||||
scheduleMsg(logger, "Reboot to apply %d", value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setBand(float value) {
|
static void setBand(float value) {
|
||||||
|
@ -230,24 +231,32 @@ void hipAdcCallback(adcsample_t value) {
|
||||||
int integratorIndex = getIntegrationIndexByRpm(engine->rpmCalculator.rpmValue);
|
int integratorIndex = getIntegrationIndexByRpm(engine->rpmCalculator.rpmValue);
|
||||||
int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain);
|
int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain);
|
||||||
int bandIndex = getBandIndex();
|
int bandIndex = getBandIndex();
|
||||||
|
int prescalerIndex = engineConfiguration->hip9011PrescalerAndSDO;
|
||||||
|
|
||||||
if (currentGainIndex != gainIndex) {
|
if (currentGainIndex != gainIndex) {
|
||||||
currentGainIndex = gainIndex;
|
currentGainIndex = gainIndex;
|
||||||
tx_buff[0] = gainIndex;
|
tx_buff[0] = SET_GAIN_CMD + gainIndex;
|
||||||
|
|
||||||
state = IS_SENDING_SPI_COMMAND;
|
state = IS_SENDING_SPI_COMMAND;
|
||||||
spiSelectI(driver);
|
spiSelectI(driver);
|
||||||
spiStartExchangeI(driver, 1, tx_buff, rx_buff);
|
spiStartExchangeI(driver, 1, tx_buff, rx_buff);
|
||||||
} else if (currentIntergratorIndex != integratorIndex) {
|
} else if (currentIntergratorIndex != integratorIndex) {
|
||||||
currentIntergratorIndex = integratorIndex;
|
currentIntergratorIndex = integratorIndex;
|
||||||
tx_buff[0] = integratorIndex;
|
tx_buff[0] = SET_INTEGRATOR_CMD + integratorIndex;
|
||||||
|
|
||||||
state = IS_SENDING_SPI_COMMAND;
|
state = IS_SENDING_SPI_COMMAND;
|
||||||
spiSelectI(driver);
|
spiSelectI(driver);
|
||||||
spiStartExchangeI(driver, 1, tx_buff, rx_buff);
|
spiStartExchangeI(driver, 1, tx_buff, rx_buff);
|
||||||
} else if (currentBandIndex != bandIndex) {
|
} else if (currentBandIndex != bandIndex) {
|
||||||
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;
|
state = IS_SENDING_SPI_COMMAND;
|
||||||
spiSelectI(driver);
|
spiSelectI(driver);
|
||||||
|
@ -257,7 +266,6 @@ void hipAdcCallback(adcsample_t value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool_t needToInit = true;
|
static bool_t needToInit = true;
|
||||||
|
|
||||||
static void hipStartupCode(void) {
|
static void hipStartupCode(void) {
|
||||||
|
@ -273,7 +281,8 @@ static void hipStartupCode(void) {
|
||||||
|
|
||||||
|
|
||||||
// '0' for 4MHz
|
// '0' for 4MHz
|
||||||
SPI_SYNCHRONOUS(SET_PRESCALER_CMD + engineConfiguration->hip9011PrescalerAndSDO);
|
currentPrescaler = engineConfiguration->hip9011PrescalerAndSDO;
|
||||||
|
SPI_SYNCHRONOUS(SET_PRESCALER_CMD + currentPrescaler);
|
||||||
|
|
||||||
chThdSleepMilliseconds(10);
|
chThdSleepMilliseconds(10);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue