2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file HIP9011.cpp
|
|
|
|
* @brief HIP9011/TPIC8101 driver
|
|
|
|
*
|
2017-01-27 09:03:05 -08:00
|
|
|
* Jan 2017 status:
|
|
|
|
* 1) seems to be kind of working - reacts to parameter changes and does produce variable output
|
|
|
|
* 2) only one (first) channel is currently used
|
|
|
|
* 3) engine control does not yet react to knock since very little actual testing - no engine runs with proven knock yet
|
|
|
|
*
|
|
|
|
*
|
2017-01-27 18:04:23 -08:00
|
|
|
* http://rusefi.com/forum/viewtopic.php?f=4&t=400
|
|
|
|
* http://rusefi.com/forum/viewtopic.php?f=5&t=778
|
|
|
|
*
|
2015-07-10 06:01:56 -07:00
|
|
|
* pin1 VDD
|
|
|
|
* pin2 GND
|
|
|
|
*
|
|
|
|
* pin8 Chip Select - CS
|
2017-01-27 09:03:05 -08:00
|
|
|
* pin11 Slave Data Out - MISO
|
2015-07-10 06:01:56 -07:00
|
|
|
* pin12 Slave Data In - MOSI
|
|
|
|
* pin13 SPI clock - SCLK
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* http://www.ti.com/lit/ds/symlink/tpic8101.pdf
|
|
|
|
* http://www.intersil.com/content/dam/Intersil/documents/hip9/hip9011.pdf
|
|
|
|
* http://www.intersil.com/content/dam/Intersil/documents/an97/an9770.pdf
|
|
|
|
* http://e2e.ti.com/cfs-file/__key/telligent-evolution-components-attachments/00-26-01-00-00-42-36-40/TPIC8101-Training.pdf
|
|
|
|
*
|
|
|
|
* max SPI frequency: 5MHz max
|
|
|
|
*
|
|
|
|
* @date Nov 27, 2013
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
* @Spilly
|
|
|
|
*/
|
|
|
|
|
2018-09-16 19:26:57 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "engine.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "hardware.h"
|
|
|
|
#include "rpm_calculator.h"
|
|
|
|
#include "trigger_central.h"
|
2019-04-01 14:04:49 -07:00
|
|
|
#include "hip9011_logic.h"
|
|
|
|
#include "hip9011.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "adc_inputs.h"
|
2020-03-24 17:19:19 -07:00
|
|
|
#include "perf_trace.h"
|
2021-02-28 04:30:45 -08:00
|
|
|
#include "thread_priority.h"
|
2019-03-31 14:44:34 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "engine_controller.h"
|
|
|
|
|
2018-11-03 10:27:48 -07:00
|
|
|
#if EFI_PROD_CODE
|
|
|
|
#include "pin_repository.h"
|
2020-01-06 05:44:23 -08:00
|
|
|
#include "mpu_util.h"
|
2021-03-30 07:56:25 -07:00
|
|
|
#include "os_util.h"
|
2018-11-03 10:27:48 -07:00
|
|
|
#endif
|
|
|
|
|
2019-04-12 17:52:51 -07:00
|
|
|
#if EFI_HIP_9011
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
/*==========================================================================*/
|
|
|
|
/* Local definitions. */
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
/*==========================================================================*/
|
|
|
|
/* Local variables and types. */
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
2019-08-18 12:04:02 -07:00
|
|
|
static NamedOutputPin intHold(PROTOCOL_HIP_NAME);
|
2021-03-20 05:40:36 -07:00
|
|
|
static NamedOutputPin Cs(PROTOCOL_HIP_NAME);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-06-08 06:51:36 -07:00
|
|
|
class Hip9011Hardware : public Hip9011HardwareInterface {
|
2021-03-30 07:56:25 -07:00
|
|
|
int sendSyncCommand(uint8_t command, uint8_t *rx_ptr) override;
|
2019-01-07 20:55:56 -08:00
|
|
|
};
|
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
/* TODO: include following stuff in object */
|
|
|
|
/* wake semaphore */
|
|
|
|
static semaphore_t wake;
|
|
|
|
|
|
|
|
static SPIDriver *spi;
|
|
|
|
|
2019-01-07 20:55:56 -08:00
|
|
|
static Hip9011Hardware hardware;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
static float hipValueMax = 0;
|
|
|
|
|
2019-01-07 20:55:56 -08:00
|
|
|
HIP9011 instance(&hardware);
|
2019-01-03 21:22:35 -08:00
|
|
|
|
2021-03-27 11:12:49 -07:00
|
|
|
static scheduling_s endTimer;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
static Logging *logger;
|
|
|
|
|
|
|
|
// SPI_CR1_BR_1 // 5MHz
|
|
|
|
// SPI_CR1_CPHA Clock Phase
|
|
|
|
// todo: nicer method which would mention SPI speed explicitly?
|
|
|
|
|
2018-11-03 06:44:34 -07:00
|
|
|
#if EFI_PROD_CODE
|
2020-01-06 05:44:23 -08:00
|
|
|
static SPIConfig hipSpiCfg = {
|
|
|
|
.circular = false,
|
|
|
|
.end_cb = NULL,
|
|
|
|
.ssport = NULL,
|
|
|
|
.sspad = 0,
|
|
|
|
.cr1 =
|
2021-03-20 05:40:36 -07:00
|
|
|
SPI_CR1_8BIT_MODE |
|
2020-01-06 05:44:23 -08:00
|
|
|
SPI_CR1_MSTR |
|
|
|
|
SPI_CR1_CPHA |
|
|
|
|
//SPI_CR1_BR_1 // 5MHz
|
2021-03-20 05:40:36 -07:00
|
|
|
SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_BR_2,
|
2020-01-06 05:44:23 -08:00
|
|
|
.cr2 =
|
|
|
|
SPI_CR2_8BIT_MODE
|
|
|
|
};
|
2019-01-03 19:53:34 -08:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
/*==========================================================================*/
|
|
|
|
/* Forward declarations */
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
static void hip_addconsoleActions(void);
|
|
|
|
|
|
|
|
/*==========================================================================*/
|
|
|
|
/* Local functions. */
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
static int checkResponse(uint8_t tx, uint8_t rx) {
|
|
|
|
/* TODO: implement response check for Advanced SPI mode too */
|
|
|
|
if (tx == rx) {
|
2019-01-07 20:55:56 -08:00
|
|
|
instance.correctResponsesCount++;
|
2021-03-30 07:56:25 -07:00
|
|
|
return 0;
|
2015-07-10 15:02:29 -07:00
|
|
|
} else {
|
2021-03-30 07:56:25 -07:00
|
|
|
instance.invalidResponsesCount++;
|
|
|
|
return -1;
|
2015-07-10 15:02:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
int Hip9011Hardware::sendSyncCommand(uint8_t tx, uint8_t *rx_ptr) {
|
|
|
|
int ret;
|
|
|
|
uint8_t rx;
|
|
|
|
|
|
|
|
/* Acquire ownership of the bus. */
|
|
|
|
spiAcquireBus(spi);
|
|
|
|
/* Setup transfer parameters. */
|
|
|
|
spiStart(spi, &hipSpiCfg);
|
|
|
|
/* Slave Select assertion. */
|
|
|
|
spiSelect(spi);
|
|
|
|
/* Transfer */
|
|
|
|
rx = spiPolledExchange(spi, tx);
|
|
|
|
/* Slave Select de-assertion. */
|
|
|
|
spiUnselect(spi);
|
|
|
|
/* Ownership release. */
|
|
|
|
spiReleaseBus(spi);
|
|
|
|
/* check response */
|
|
|
|
if (instance.adv_mode == false) {
|
|
|
|
/* only default SPI mode SDO is directly equals the SDI (echo function) */
|
|
|
|
ret = checkResponse(tx, rx);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2019-01-07 20:55:56 -08:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
if (rx_ptr) {
|
|
|
|
*rx_ptr = rx;
|
|
|
|
}
|
2019-01-07 20:55:56 -08:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
return 0;
|
2019-01-07 20:55:56 -08:00
|
|
|
}
|
|
|
|
|
2020-03-29 16:06:03 -07:00
|
|
|
EXTERN_ENGINE;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
static int hip_wake_driver(void)
|
|
|
|
{
|
|
|
|
/* Entering a reentrant critical zone.*/
|
|
|
|
syssts_t sts = chSysGetStatusAndLockX();
|
|
|
|
chSemSignalI(&wake);
|
|
|
|
if (!port_is_isr_context()) {
|
|
|
|
/**
|
|
|
|
* chSemSignalI above requires rescheduling
|
|
|
|
* interrupt handlers have implicit rescheduling
|
|
|
|
*/
|
|
|
|
chSchRescheduleS();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2021-03-30 07:56:25 -07:00
|
|
|
/* Leaving the critical zone.*/
|
|
|
|
chSysRestoreStatusX(sts);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
return 0;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2020-01-06 21:41:18 -08:00
|
|
|
static void startIntegration(void *) {
|
2019-01-03 21:22:35 -08:00
|
|
|
if (instance.state == READY_TO_INTEGRATE) {
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* SPI communication is only allowed while not integrating, so we postpone the exchange
|
|
|
|
* until we are done integrating
|
|
|
|
*/
|
2019-01-03 21:22:35 -08:00
|
|
|
instance.state = IS_INTEGRATING;
|
2017-04-21 16:23:20 -07:00
|
|
|
intHold.setHigh();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-06 21:41:18 -08:00
|
|
|
static void endIntegration(void *) {
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* isIntegrating could be 'false' if an SPI command was pending thus we did not integrate during this
|
|
|
|
* engine cycle
|
|
|
|
*/
|
2019-01-03 21:22:35 -08:00
|
|
|
if (instance.state == IS_INTEGRATING) {
|
2017-04-21 16:23:20 -07:00
|
|
|
intHold.setLow();
|
2019-01-03 21:22:35 -08:00
|
|
|
instance.state = WAITING_FOR_ADC_TO_SKIP;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-27 11:12:49 -07:00
|
|
|
* Ignition callback used to start HIP integration and schedule finish
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2021-03-27 11:12:49 -07:00
|
|
|
void hip9011_startKnockSampling(uint8_t cylinderNumber, efitick_t nowNt) {
|
|
|
|
if (!CONFIG(isHip9011Enabled))
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
2020-03-24 17:19:19 -07:00
|
|
|
|
2021-03-27 11:12:49 -07:00
|
|
|
/* overrun? */
|
|
|
|
if (instance.state != READY_TO_INTEGRATE) {
|
|
|
|
instance.overrun++;
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
2021-03-27 11:12:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
instance.cylinderNumber = cylinderNumber;
|
|
|
|
startIntegration(NULL);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-27 11:12:49 -07:00
|
|
|
/* TODO: reference to knockDetectionWindowStart */
|
|
|
|
scheduleByAngle(&endTimer, nowNt,
|
|
|
|
engineConfiguration->knockDetectionWindowEnd - engineConfiguration->knockDetectionWindowStart,
|
2020-01-06 21:41:18 -08:00
|
|
|
&endIntegration);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2018-11-03 06:44:34 -07:00
|
|
|
void hipAdcCallback(adcsample_t adcValue) {
|
2019-01-03 21:22:35 -08:00
|
|
|
if (instance.state == WAITING_FOR_ADC_TO_SKIP) {
|
|
|
|
instance.state = WAITING_FOR_RESULT_ADC;
|
|
|
|
} else if (instance.state == WAITING_FOR_RESULT_ADC) {
|
2021-03-30 07:56:25 -07:00
|
|
|
/* offload calculations to driver thread */
|
|
|
|
instance.raw_value = adcValue;
|
|
|
|
instance.state = NOT_READY;
|
|
|
|
hip_wake_driver();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
static int hip_init(void) {
|
|
|
|
int ret;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
ret = instance.hw->sendSyncCommand(SET_PRESCALER_CMD(instance.prescaler), NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
// '0' for channel #1
|
|
|
|
ret = instance.hw->sendSyncCommand(SET_CHANNEL_CMD(instance.channelIdx), NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-07-10 20:01:24 -07:00
|
|
|
|
2019-12-11 14:48:55 -08:00
|
|
|
if (CONFIG(useTpicAdvancedMode)) {
|
2015-07-10 06:01:56 -07:00
|
|
|
// enable advanced mode for digital integrator output
|
2021-03-30 07:56:25 -07:00
|
|
|
ret = instance.hw->sendSyncCommand(SET_ADVANCED_MODE_CMD, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
instance.adv_mode = true;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-01-03 21:22:35 -08:00
|
|
|
instance.state = READY_TO_INTEGRATE;
|
2021-03-30 07:56:25 -07:00
|
|
|
|
|
|
|
return 0;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2020-08-01 15:59:09 -07:00
|
|
|
static THD_WORKING_AREA(hipThreadStack, UTILITY_THREAD_STACK_SIZE);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
static msg_t hipThread(void *arg) {
|
2021-03-30 07:56:25 -07:00
|
|
|
int ret;
|
2021-03-20 05:40:36 -07:00
|
|
|
UNUSED(arg);
|
2021-03-30 07:56:25 -07:00
|
|
|
chRegSetThreadName("hip9011 worker");
|
2015-07-11 12:01:54 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
/* Acquire ownership of the bus. */
|
|
|
|
spiAcquireBus(spi);
|
2015-07-11 12:01:54 -07:00
|
|
|
// some time to let the hardware start
|
2021-03-20 05:40:36 -07:00
|
|
|
Cs.setValue(true);
|
2015-07-11 12:01:54 -07:00
|
|
|
chThdSleepMilliseconds(100);
|
2021-03-20 05:40:36 -07:00
|
|
|
Cs.setValue(false);
|
2015-07-11 12:01:54 -07:00
|
|
|
chThdSleepMilliseconds(100);
|
2021-03-20 05:40:36 -07:00
|
|
|
Cs.setValue(true);
|
2021-03-30 07:56:25 -07:00
|
|
|
/* Ownership release. */
|
|
|
|
spiReleaseBus(spi);
|
2015-07-11 12:01:54 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
/* init semaphore */
|
|
|
|
chSemObjectInit(&wake, 10);
|
|
|
|
|
|
|
|
chThdSleepMilliseconds(100);
|
2015-07-11 12:01:54 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
do {
|
|
|
|
/* retry until success */
|
|
|
|
ret = hip_init();
|
|
|
|
if (ret) {
|
|
|
|
warning(CUSTOM_OBD_KNOCK_PROCESSOR, "TPIC/HIP does not respond: %d", ret);
|
|
|
|
chThdSleepMilliseconds(10 * 1000);
|
|
|
|
}
|
|
|
|
} while (ret);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
msg_t msg;
|
|
|
|
|
|
|
|
/* load new/updated settings */
|
|
|
|
instance.handleSettings(GET_RPM() DEFINE_PARAM_SUFFIX(PASS_HIP_PARAMS));
|
|
|
|
/* State */
|
|
|
|
instance.state = READY_TO_INTEGRATE;
|
|
|
|
|
|
|
|
msg = chSemWaitTimeout(&wake, TIME_INFINITE);
|
|
|
|
if (msg == MSG_TIMEOUT) {
|
|
|
|
/* ??? */
|
|
|
|
} else {
|
|
|
|
/* TODO: check for correct cylinder/input */
|
|
|
|
if (1) {
|
|
|
|
/* calculations */
|
|
|
|
float knockVolts = instance.raw_value * adcToVolts(1) * CONFIG(analogInputDividerCoefficient);
|
|
|
|
hipValueMax = maxF(knockVolts, hipValueMax);
|
|
|
|
engine->knockLogic(knockVolts);
|
|
|
|
|
|
|
|
/* TunerStudio */
|
|
|
|
tsOutputChannels.knockLevels[instance.cylinderNumber] = knockVolts;
|
|
|
|
tsOutputChannels.knockLevel = knockVolts;
|
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
2021-03-30 07:56:25 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
/*==========================================================================*/
|
|
|
|
/* Exported functions. */
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
2019-04-19 12:11:00 -07:00
|
|
|
void stopHip9001_pins() {
|
2020-12-18 14:18:12 -08:00
|
|
|
intHold.deInit();
|
2021-03-20 05:40:36 -07:00
|
|
|
Cs.deInit();
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
hipSpiCfg.ssport = NULL;
|
|
|
|
#endif
|
2019-04-19 12:11:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void startHip9001_pins() {
|
2019-12-11 14:48:55 -08:00
|
|
|
intHold.initPin("hip int/hold", CONFIG(hip9011IntHoldPin), &CONFIG(hip9011IntHoldPinMode));
|
2021-03-20 05:40:36 -07:00
|
|
|
Cs.initPin("hip CS", CONFIG(hip9011CsPin), &CONFIG(hip9011CsPinMode));
|
2019-04-19 12:11:00 -07:00
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
void initHip9011(Logging *sharedLogger) {
|
|
|
|
logger = sharedLogger;
|
2021-03-30 07:56:25 -07:00
|
|
|
|
2019-12-11 14:48:55 -08:00
|
|
|
if (!CONFIG(isHip9011Enabled))
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
|
2018-11-03 06:44:34 -07:00
|
|
|
#if EFI_PROD_CODE
|
2021-03-30 07:56:25 -07:00
|
|
|
spi = getSpiDevice(CONFIG(hip9011SpiDevice));
|
|
|
|
if (spi == NULL) {
|
2019-03-26 06:38:23 -07:00
|
|
|
// error already reported
|
|
|
|
return;
|
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-12-11 14:48:55 -08:00
|
|
|
hipSpiCfg.ssport = getHwPort("hip", CONFIG(hip9011CsPin));
|
|
|
|
hipSpiCfg.sspad = getHwPin("hip", CONFIG(hip9011CsPin));
|
2019-05-27 14:02:46 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-19 12:11:00 -07:00
|
|
|
startHip9001_pins();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
/* load settings */
|
|
|
|
instance.channelIdx = 0;
|
|
|
|
instance.prescaler = CONFIG(hip9011PrescalerAndSDO);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
scheduleMsg(logger, "Starting HIP9011/TPIC8101 driver");
|
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
chThdCreateStatic(hipThreadStack, sizeof(hipThreadStack), PRIO_HIP9011, (tfunc_t)(void*) hipThread, NULL);
|
|
|
|
|
|
|
|
hip_addconsoleActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*==========================================================================*/
|
|
|
|
/* Debug functions. */
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
static void showHipInfo(void) {
|
|
|
|
if (!CONFIG(isHip9011Enabled)) {
|
|
|
|
scheduleMsg(logger, "hip9011 driver not active");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduleMsg(logger, "enabled=%s state=%s",
|
|
|
|
boolToString(CONFIG(isHip9011Enabled)),
|
|
|
|
getHip_state_e(instance.state));
|
|
|
|
|
|
|
|
scheduleMsg(logger, " bore=%.2fmm freq=%.2fkHz",
|
|
|
|
engineConfiguration->cylinderBore,
|
|
|
|
instance.getBand(PASS_HIP_PARAMS));
|
|
|
|
|
|
|
|
scheduleMsg(logger, " band idx=%d integrator idx=%d gain %.2f (idx %d) output=%s",
|
|
|
|
instance.bandIdx,
|
|
|
|
instance.intergratorIdx,
|
|
|
|
engineConfiguration->hip9011Gain,
|
|
|
|
instance.gainIdx,
|
|
|
|
getAdc_channel_e(engineConfiguration->hipOutputChannel));
|
|
|
|
|
|
|
|
scheduleMsg(logger, " PaSDO=0x%x",
|
|
|
|
instance.prescaler);
|
|
|
|
|
|
|
|
scheduleMsg(logger, " knockVThreshold=%.2f knockCount=%d maxKnockSubDeg=%.2f",
|
|
|
|
engineConfiguration->knockVThreshold,
|
|
|
|
engine->knockCount,
|
|
|
|
engineConfiguration->maxKnockSubDeg);
|
|
|
|
|
|
|
|
scheduleMsg(logger, " spi=%s IntHold@%s(0x%x) correct response=%d incorrect response=%d (%s)",
|
|
|
|
getSpi_device_e(engineConfiguration->hip9011SpiDevice),
|
|
|
|
hwPortname(CONFIG(hip9011IntHoldPin)),
|
|
|
|
CONFIG(hip9011IntHoldPinMode),
|
|
|
|
instance.correctResponsesCount,
|
|
|
|
instance.invalidResponsesCount,
|
|
|
|
instance.invalidResponsesCount > 0 ? "NOT GOOD" : "ok");
|
|
|
|
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
scheduleMsg(logger, "hip %.2fv/last=%.2f/max=%.2f adv=%d",
|
|
|
|
engine->knockVolts,
|
|
|
|
getVoltage("hipinfo", engineConfiguration->hipOutputChannel),
|
|
|
|
hipValueMax,
|
|
|
|
CONFIG(useTpicAdvancedMode));
|
|
|
|
scheduleMsg(logger, "hip9011 CS@%s",
|
|
|
|
hwPortname(CONFIG(hip9011CsPin)));
|
|
|
|
printSpiConfig(logger, "hip9011", CONFIG(hip9011SpiDevice));
|
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
scheduleMsg(logger, "start %.2f end %.2f",
|
|
|
|
engineConfiguration->knockDetectionWindowStart,
|
|
|
|
engineConfiguration->knockDetectionWindowEnd);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
scheduleMsg(logger, "Status: overruns %d",
|
|
|
|
instance.overrun);
|
|
|
|
|
|
|
|
hipValueMax = 0;
|
|
|
|
engine->printKnockState();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setMaxKnockSubDeg(int value) {
|
|
|
|
engineConfiguration->maxKnockSubDeg = value;
|
|
|
|
showHipInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setKnockThresh(float value) {
|
|
|
|
engineConfiguration->knockVThreshold = value;
|
|
|
|
showHipInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setPrescalerAndSDO(int value) {
|
|
|
|
engineConfiguration->hip9011PrescalerAndSDO = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setHipBand(float value) {
|
|
|
|
engineConfiguration->knockBandCustom = value;
|
|
|
|
showHipInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setHipGain(float value) {
|
|
|
|
engineConfiguration->hip9011Gain = value;
|
|
|
|
showHipInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hip_addconsoleActions(void) {
|
|
|
|
addConsoleAction("hipinfo", showHipInfo);
|
2017-01-06 14:01:28 -08:00
|
|
|
addConsoleActionF("set_gain", setHipGain);
|
|
|
|
addConsoleActionF("set_band", setHipBand);
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleActionI("set_hip_prescalerandsdo", setPrescalerAndSDO);
|
|
|
|
addConsoleActionF("set_knock_threshold", setKnockThresh);
|
|
|
|
addConsoleActionI("set_max_knock_sub_deg", setMaxKnockSubDeg);
|
2021-03-30 07:56:25 -07:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:07:41 -07:00
|
|
|
#endif /* EFI_HIP_9011 */
|