57#define PROTOCOL_HIP_NAME "HIP"
70 int checkResponseDefMode(uint8_t tx, uint8_t rx);
71 int checkResponseAdvMode(uint8_t tx, uint8_t rx);
99#ifdef _CHIBIOS_RT_CONF_VER_6_1_
113 SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_BR_2,
123#if EFI_HIP_9011_DEBUG
131int Hip9011Hardware::checkResponseDefMode(uint8_t tx, uint8_t rx) {
140int Hip9011Hardware::checkResponseAdvMode(uint8_t tx, uint8_t rx) {
144 if ((rx & rep_mask) != rep_value)
148 if ((tx & 0xe0) == SET_PRESCALER_CMD(0)){
152 }
else if ((tx & 0xfe) == SET_CHANNEL_CMD(0)) {
156 }
else if ((tx & 0xc0) == SET_BAND_PASS_CMD(0)) {
158 rep_value = SET_BAND_PASS_REP;
159 }
else if ((tx & 0xc0) == SET_GAIN_CMD(0)) {
161 rep_value = SET_GAIN_REP;
162 }
else if ((tx & 0xe0) == SET_INTEGRATOR_CMD(0)) {
164 rep_value = SET_INTEGRATOR_REP;
165 }
else if ((tx & 0xff) == SET_ADVANCED_MODE_CMD) {
167 rep_value = SET_ADVANCED_MODE_REP;
188 rx = spiPolledExchange(
spi, tx);
198 ret = checkResponseAdvMode(tx, rx);
200 ret = checkResponseDefMode(tx, rx);
202 #if EFI_HIP_9011_DEBUG
216 syssts_t sts = chSysGetStatusAndLockX();
218 if (!port_is_isr_context()) {
226 chSysRestoreStatusX(sts);
240 #if EFI_HIP_9011_DEBUG
303 { startIntegration, &instance });
307 { endIntegration, &instance });
309 #if EFI_HIP_9011_DEBUG
333 volts * HIP9011_DIGITAL_OUTPUT_MAX / HIP9011_ANALOG_OUTPUT_MAX;
342 uint8_t ret0, ret1, ret2;
366 if ((ret0 == SET_BAND_PASS_REP) &&
367 (ret1 == SET_GAIN_REP) &&
368 (ret2 == SET_INTEGRATOR_REP))
397 if (rx != SET_ADVANCED_MODE_REP) {
415 #if EFI_HIP_9011_DEBUG
434 chRegSetThreadName(
"hip9011 worker");
443 chThdSleepMilliseconds(100);
445 chThdSleepMilliseconds(100);
450 chThdSleepMilliseconds(100);
458 chThdSleepMilliseconds(10 * 1000);
475 msg = chSemWaitTimeout(&
wake, TIME_INFINITE);
476 if (msg == MSG_TIMEOUT) {
494 if (!(idx < HIP_INPUT_CHANNELS))
497 float knockNormalized = 0.0f;
498 float knockVolts = 0.0f;
508 knockNormalized = ((
float)rawValue) / HIP9011_DIGITAL_OUTPUT_MAX;
511 knockVolts = knockNormalized * HIP9011_ANALOG_OUTPUT_MAX;
514 if (correctCylinder) {
518 #if EFI_HIP_9011_DEBUG
573 efiPrintf(
"Starting HIP9011/TPIC8101 driver");
576 chSemObjectInit(&
wake, 10);
577 chThdCreateStatic(hipThreadStack,
sizeof(hipThreadStack), PRIO_HIP9011, (tfunc_t)(
void*)
hipThread, NULL);
579 #if EFI_HIP_9011_DEBUG
588#if EFI_HIP_9011_DEBUG
592 "Not ready/calculating",
593 "Ready for integration",
595 "Waiting for first ADC sample",
596 "Waiting for second ADC sample"
601 efiPrintf(
"hip9011 driver not active");
605 efiPrintf(
"HIP9011: enabled %s",
612 efiPrintf(
" State %s",
615 efiPrintf(
" Advanced mode: enabled %d used %d",
619 efiPrintf(
" Input Ch %d (cylinder %d next %d)",
624 efiPrintf(
" Cyl bore %.2fmm freq %.2fkHz band idx 0x%x",
629 efiPrintf(
" Integrator %d uS idx 0x%x RPM %d",
633 efiPrintf(
" Gain %.2f idx 0x%x",
637 efiPrintf(
" PaSDO=0x%x",
640 efiPrintf(
" IntHold %s (mode 0x%x)",
644 efiPrintf(
" Spi %s CS %s (mode 0x%x)",
653 efiPrintf(
" SPI: good response %d incorrect response %d",
657 efiPrintf(
" Counters: samples %d overruns %d sync miss %d",
660 efiPrintf(
" Window start %.2f end %.2f",
665 efiPrintf(
" Adc input %d (%.2f V)",
670 for (
int i = 0; i < HIP_INPUT_CHANNELS; i++) {
671 efiPrintf(
" input[%d] %d -> %.3f (max %.3f)",
const char * getSpi_device_e(spi_device_e value)
constexpr auto & module()
float getBand(DEFINE_HIP_PARAMS)
int getIntegrationTimeByIndex(int index)
efitick_t knockSampleTimestamp
void handleSettings(int rpm DEFINE_PARAM_SUFFIX(DEFINE_HIP_PARAMS))
int correctResponsesCount
int8_t expectedCylinderNumber
int readValueAndHandleChannel(DEFINE_HIP_PARAMS)
int handleChannel(DEFINE_HIP_PARAMS)
Hip9011HardwareInterface * hw
uint16_t rpmLookup[INT_LOOKUP_SIZE]
uint16_t rawValue[HIP_INPUT_CHANNELS]
int invalidResponsesCount
virtual int sendSyncCommand(unsigned char command, uint8_t *rx_ptr)=0
virtual void setLow(const char *msg)
virtual void setHigh(const char *msg)
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e outputMode, bool forceInitWithFatalError=false)
void setValue(const char *msg, int logicValue, bool isForce=false)
static float getOrZero(SensorType type)
void addConsoleActionF(const char *token, VoidFloat callback)
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
const char * boolToString(bool value)
static Engine *const engine
static constexpr engine_configuration_s * engineConfiguration
bool warning(ObdCode code, const char *fmt,...)
void printSpiConfig(const char *msg, spi_device_e device)
SPIDriver * getSpiDevice(spi_device_e spiDevice)
static THD_WORKING_AREA(hipThreadStack, UTILITY_THREAD_STACK_SIZE)
void onStartKnockSampling(uint8_t, float, uint8_t)
static NamedOutputPin intHold(PROTOCOL_HIP_NAME)
static void startIntegration(HIP9011 *hip)
static int hip_testAdvMode()
static int hip_wake_driver()
static float normalizedValue[HIP_INPUT_CHANNELS]
static float normalizedValueMax[HIP_INPUT_CHANNELS]
static SPIConfig hipSpiCfg
void hip9011_onFireEvent(uint8_t cylinderNumber, efitick_t nowNt)
static void setHipGain(float value)
void hipAdcCallback(float volts)
static const char * hip_state_names[]
static void endIntegration(HIP9011 *hip)
static msg_t hipThread(void *arg)
static void showHipInfo()
static void hip_addconsoleActions()
static NamedOutputPin Cs(PROTOCOL_HIP_NAME)
static Hip9011Hardware hardware
static void setPrescaler(int value)
@ WAITING_FOR_ADC_TO_SKIP
UNUSED(samplingTimeSeconds)
@ CUSTOM_OBD_KNOCK_PROCESSOR
const char * hwPortname(brain_pin_e brainPin)
efitick_t scheduleByAngle(scheduling_s *timer, efitick_t nowNt, angle_t angle, action_s action)
int16_t knockSamplingDuration
pin_output_mode_e hip9011CsPinMode
float knockDetectionWindowStart
adc_channel_e hipOutputChannel
pin_output_mode_e hip9011IntHoldPinMode
spi_device_e hip9011SpiDevice