auto-sync

This commit is contained in:
rusEfi 2015-05-23 21:12:03 -04:00
parent e78062b639
commit c26d69ade9
7 changed files with 100 additions and 29 deletions

View File

@ -1,4 +1,4 @@
// this section was generated by config_definition.jar on Sat May 23 19:27:45 EDT 2015
// this section was generated by config_definition.jar on Sat May 23 20:41:38 EDT 2015
// begin
#include "rusefi_types.h"
typedef struct {
@ -564,7 +564,7 @@ typedef struct {
/**
* offset 656
*/
brain_pin_e hip9011OutPin;
int unused1280;
/**
* offset 660
*/
@ -738,7 +738,11 @@ typedef struct {
/**
* offset 320
*/
float unused[3];
float unused[2];
/**
* offset 328
*/
int hip9011PrescalerAndSDO;
/**
* offset 332
*/
@ -1333,4 +1337,4 @@ typedef struct {
} persistent_config_s;
// end
// this section was generated by config_definition.jar on Sat May 23 19:27:45 EDT 2015
// this section was generated by config_definition.jar on Sat May 23 20:41:38 EDT 2015

View File

@ -108,6 +108,8 @@
#define iat_adcChannel_offset 316
#define unused_offset 320
#define unused_offset_hex 140
#define hip9011PrescalerAndSDO_offset 328
#define hip9011PrescalerAndSDO_offset_hex 148
#define knockBandCustom_offset 332
#define sparkDwellBins_offset 336
#define sparkDwellBins_offset_hex 150
@ -432,8 +434,8 @@
#define fsioFrequency16_offset 1270
#define hip9011CsPin_offset 1272
#define hip9011IntHoldPin_offset 1276
#define hip9011OutPin_offset 1280
#define hip9011OutPin_offset_hex 500
#define unused1280_offset 1280
#define unused1280_offset_hex 500
#define fsio_setting1_offset 1284
#define fsio_setting1_offset_hex 504
#define fsio_setting2_offset 1288

View File

@ -74,6 +74,9 @@ int getHip9011GainIndex(float gain) {
return i == GAIN_LOOKUP_SIZE ? GAIN_LOOKUP_SIZE - 1 : i;
}
int getHip9011BandIndex(float bore) {
return findIndex(bandFreqLookup, BAND_LOOKUP_SIZE, BAND(bore));
/**
* @param frequency knock frequencey, in kHz
*/
int getHip9011BandIndex(float frequency) {
return findIndex(bandFreqLookup, BAND_LOOKUP_SIZE, frequency);
}

View File

@ -20,7 +20,7 @@ extern const float bandFreqLookup[BAND_LOOKUP_SIZE];
float getRpmByAngleWindowAndTimeUs(int timeUs, float angleWindowWidth);
int getHip9011GainIndex(float gain);
int getHip9011BandIndex(float bore);
int getHip9011BandIndex(float frequency);
void prepareHip9011RpmLookup(float angleWindowWidth);
#define GAIN_INDEX(gain) (GAIN_LOOKUP_SIZE - 1 - findIndex(gainLookupInReverseOrder, GAIN_LOOKUP_SIZE, (gain)))

View File

@ -50,7 +50,7 @@ uint32_t hipLastExecutionCount;
/**
* band index is only send to HIP chip on startup
*/
static int bandIndex;
static int currentBandIndex;
static int currentGainIndex = -1;
static int currentIntergratorIndex = -1;
static int settingUpdateCount = 0;
@ -104,6 +104,12 @@ EXTERN_ENGINE
;
static char pinNameBuffer[16];
static float getBand(void) {
return engineConfiguration->knockBandCustom == 0 ?
BAND(engineConfiguration->cylinderBore) : engineConfiguration->knockBandCustom;
}
static void showHipInfo(void) {
if (!boardConfiguration->isHip9011Enabled) {
scheduleMsg(logger, "hip9011 driver not active");
@ -111,9 +117,10 @@ static void showHipInfo(void) {
}
printSpiState(logger, boardConfiguration);
scheduleMsg(logger, "bore=%fmm freq=%fkHz", engineConfiguration->cylinderBore, BAND(engineConfiguration->cylinderBore));
scheduleMsg(logger, "bore=%fmm freq=%fkHz PaSDO=%d", engineConfiguration->cylinderBore, getBand(),
engineConfiguration->hip9011PrescalerAndSDO);
scheduleMsg(logger, "band_index=%d gain %f/index=%d", bandIndex, boardConfiguration->hip9011Gain, currentGainIndex);
scheduleMsg(logger, "band_index=%d gain %f/index=%d", currentBandIndex, boardConfiguration->hip9011Gain, currentGainIndex);
scheduleMsg(logger, "integrator index=%d hip_threshold=%f totalKnockEventsCount=%d", currentIntergratorIndex,
engineConfiguration->hipThreshold, totalKnockEventsCount);
@ -186,16 +193,31 @@ static void intHoldCallback(trigger_event_e ckpEventType, uint32_t index DECLARE
engine->m.hipCbTime = GET_TIMESTAMP() - engine->m.beforeHipCb;
}
static void setPrescalerAndSDO(int value) {
engineConfiguration->hip9011PrescalerAndSDO = value;
scheduleMsg(logger, "Reboot to apply %d", value);
}
static void setBand(float value) {
engineConfiguration->knockBandCustom = value;
showHipInfo();
}
static void setGain(float value) {
boardConfiguration->hip9011Gain = value;
showHipInfo();
}
static void endOfSpiCommunication(SPIDriver *spip) {
static void endOfSpiExchange(SPIDriver *spip) {
spiUnselectI(driver);
state = READY_TO_INTEGRATE;
}
static int getBandIndex(void) {
float freq = getBand();
return getHip9011BandIndex(freq);
}
void hipAdcCallback(adcsample_t value) {
if (state == WAITING_FOR_ADC_TO_SKIP) {
state = WAITING_FOR_RESULT_ADC;
@ -207,19 +229,27 @@ void hipAdcCallback(adcsample_t value) {
int integratorIndex = getIntegrationIndexByRpm(engine->rpmCalculator.rpmValue);
int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain);
int bandIndex = getBandIndex();
if (currentGainIndex != gainIndex) {
state = IS_SENDING_SPI_COMMAND;
tx_buff[0] = gainIndex;
currentGainIndex = gainIndex;
tx_buff[0] = gainIndex;
state = IS_SENDING_SPI_COMMAND;
spiSelectI(driver);
spiStartExchangeI(driver, 1, tx_buff, rx_buff);
} else if (currentIntergratorIndex != integratorIndex) {
state = IS_SENDING_SPI_COMMAND;
tx_buff[0] = integratorIndex;
currentIntergratorIndex = integratorIndex;
tx_buff[0] = 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;
state = IS_SENDING_SPI_COMMAND;
spiSelectI(driver);
spiStartExchangeI(driver, 1, tx_buff, rx_buff);
} else {
@ -231,21 +261,38 @@ void hipAdcCallback(adcsample_t value) {
static bool_t needToInit = true;
static void hipStartupCode(void) {
// D[4:1] = 0000 : 4 MHz
// D[4:1] = 0001 : 5 MHz
// D[4:1] = 0010 : 6 MHz
// D[4:1] = 0011 ; 8 MHz
// D[4:1] = 0100 ; 10 MHz
// D[4:1] = 0101 ; 12 MHz
// D[4:1] = 0110 : 16 MHz
// D[4:1] = 0111 : 20 MHz
// D[4:1] = 1000 : 24 MHz
// '0' for 4MHz
SPI_SYNCHRONOUS(SET_PRESCALER_CMD + 0);
SPI_SYNCHRONOUS(SET_PRESCALER_CMD + engineConfiguration->hip9011PrescalerAndSDO);
chThdSleepMilliseconds(10);
// '0' for channel #1
SPI_SYNCHRONOUS(SET_CHANNEL_CMD + 0);
chThdSleepMilliseconds(10);
// band index depends on cylinder bore
SPI_SYNCHRONOUS(SET_BAND_PASS_CMD + bandIndex);
SPI_SYNCHRONOUS(SET_BAND_PASS_CMD + currentBandIndex);
chThdSleepMilliseconds(10);
/**
* Let's restart SPI to switch it from synchronous mode into
* asynchronous mode
*/
spiStop(driver);
spicfg.end_cb = endOfSpiCommunication;
spicfg.end_cb = endOfSpiExchange;
spiStart(driver, &spicfg);
state = READY_TO_INTEGRATE;
}
@ -255,8 +302,8 @@ static THD_WORKING_AREA(hipTreadStack, UTILITY_THREAD_STACK_SIZE);
static msg_t hipThread(void *arg) {
chRegSetThreadName("hip9011 init");
while (true) {
// 100 ms to let the hardware to start
chThdSleepMilliseconds(100);
// some time to let the hardware start
chThdSleepMilliseconds(500);
if (needToInit) {
hipStartupCode();
needToInit = false;
@ -287,7 +334,7 @@ void initHip9011(Logging *sharedLogger) {
scheduleMsg(logger, "Starting HIP9011/TPIC8101 driver");
spiStart(driver, &spicfg);
bandIndex = getHip9011BandIndex(engineConfiguration->cylinderBore);
currentBandIndex = getBandIndex();
/**
* this engine cycle callback would be scheduling actual integration start and end callbacks
@ -300,6 +347,8 @@ void initHip9011(Logging *sharedLogger) {
// palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(EFI_SPI2_AF) | PAL_STM32_OTYPE_OPENDRAIN);
addConsoleActionF("set_gain", setGain);
addConsoleActionF("set_band", setBand);
addConsoleActionI("set_hip_prescalerandsdo", setPrescalerAndSDO);
chThdCreateStatic(hipTreadStack, sizeof(hipTreadStack), NORMALPRIO, (tfunc_t) hipThread, NULL);
}

View File

@ -159,8 +159,9 @@ MAP_sensor_config_s map;@see hasMapSensor\n@see isMapAveragingEnabled
ThermistorConf clt;todo: merge with channel settings, use full-scale Thermistor here!
ThermistorConf iat;
float[3] unused;
float knockBandCustom;
float[2] unused;
int hip9011PrescalerAndSDO;;"integer", 1, 0.0, 0.0, 32, 0
float knockBandCustom;;"kHz", 1, 0.0, 0.0, 10.0, 2
float[DWELL_CURVE_SIZE] sparkDwellBins;;"RPM", 1, 0.0, 0.0, 18000, 2
@ -416,7 +417,7 @@ custom fsio_pwm_freq_t 2 scalar, U16, @OFFSET@, "Hz", 1, 0,
brain_pin_e hip9011CsPin;
brain_pin_e hip9011IntHoldPin;
brain_pin_e hip9011OutPin;
int unused1280;
custom fsio_setting_t 4 scalar, F32, @OFFSET@, "Val", 1, 0, 0, 18000, 0
fsio_setting_t[LE_COMMAND_COUNT iterate] fsio_setting;

View File

@ -40,7 +40,7 @@ enable2ndByteCanID = false
; see PAGE_0_SIZE in C source code
; CONFIG_DEFINITION_START
; this section was generated by ConfigDefinition.jar on Sat May 23 19:27:50 EDT 2015
; this section was generated by ConfigDefinition.jar on Sat May 23 20:41:42 EDT 2015
pageSize = 15288
page = 1
@ -86,7 +86,8 @@ page = 1
iat_bias_resistor = scalar, F32, 312, "Ohm", 1, 0, 0, 200000, 1
iat_adcChannel = bits, U32, 316, [0:3] "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PB0", "PB1", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5"
;skipping unused offset 320
;skipping knockBandCustom offset 332
hip9011PrescalerAndSDO = scalar, S32, 328, "integer", 1, 0.0, 0.0, 32, 0
knockBandCustom = scalar, F32, 332, "kHz", 1, 0.0, 0.0, 10.0, 2
sparkDwellBins = array, F32, 336, [8], "RPM", 1, 0.0, 0.0, 18000, 2
sparkDwell = array, F32, 368, [8], "ms", 1, 0.0, 0.0, 30.0, 2
displacement = scalar, F32, 400, "L", 1, 0, 0, 1000.0, 2
@ -313,7 +314,7 @@ page = 1
fsioFrequency16 = scalar, U16, 1270, "Hz", 1, 0, 0, 3000, 0
hip9011CsPin = bits, U32, 1272, [0:6], "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9", "PE10", "PE11", "PE12", "PE13", "PE14", "PE15", "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"
hip9011IntHoldPin = bits, U32, 1276, [0:6], "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9", "PE10", "PE11", "PE12", "PE13", "PE14", "PE15", "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"
hip9011OutPin = bits, U32, 1280, [0:6], "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9", "PE10", "PE11", "PE12", "PE13", "PE14", "PE15", "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"
;skipping unused1280 offset 1280
fsio_setting1 = scalar, F32, 1284, "Val", 1, 0, 0, 18000, 0
fsio_setting2 = scalar, F32, 1288, "Val", 1, 0, 0, 18000, 0
fsio_setting3 = scalar, F32, 1292, "Val", 1, 0, 0, 18000, 0
@ -921,6 +922,7 @@ fileVersion = { 20150522 }
subMenu = mainRealay, "Main Relay Settings"
subMenu = fuelPump, "Fuel Pump Settings"
subMenu = malfunction, "MIL Settings"
subMenu = hipFunction, "hip9011 Settings"
menu = "Tuning"
subMenu = generalSettings, "General"
subMenu = std_separator
@ -1163,6 +1165,16 @@ fileVersion = { 20150522 }
field = "MIL Pin Mode", malfunctionIndicatorPinMode
field = "MIL Pin", malfunctionIndicatorPin
; Engine->hip9011 Settings
dialog = hipFunction, "HIP9011 Settings"
field = "Enabled", isHip9011Enabled
field = "IntHold pin (hip9011 input)", hip9011IntHoldPin
field = "ChipSelect pin", hip9011CsPin
field = "hip Output/stm input", hipOutputChannel
field = "prescaler & SDO", hip9011PrescalerAndSDO
field = "Band Freq override", knockBandCustom
field = "!Always on SPI2"
; Engine->Battery & Alternator
dialog = battery, "Battery Settings", yAxis
field = "vBatt ADC input", vbattAdcChannel