hip9011: get callback from spark on each cylinder (#2499)
* hip9011: get callback from spark on each cylinder * hip9011: cleanup unused
This commit is contained in:
parent
7de5e303a3
commit
5fda278503
|
@ -15,6 +15,8 @@
|
|||
#include "perf_trace.h"
|
||||
#include "tooth_logger.h"
|
||||
|
||||
#include "hip9011.h"
|
||||
|
||||
#if EFI_ENGINE_CONTROL
|
||||
|
||||
#if EFI_TUNER_STUDIO
|
||||
|
@ -204,6 +206,9 @@ if (engineConfiguration->debugMode == DBG_DWELL_METRIC) {
|
|||
#if EFI_SOFTWARE_KNOCK
|
||||
startKnockSampling(event->cylinderNumber);
|
||||
#endif
|
||||
#if EFI_HIP_9011
|
||||
hip9011_startKnockSampling(event->cylinderNumber, nowNt);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void startDwellByTurningSparkPinHigh(IgnitionEvent *event, IgnitionOutputPin *output) {
|
||||
|
|
|
@ -533,12 +533,6 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
|||
#endif /* EFI_MAP_AVERAGING */
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
#if EFI_HIP_9011
|
||||
if (CONFIG(isHip9011Enabled)) {
|
||||
intHoldCallback(signal, triggerIndexForListeners, timestamp PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if EFI_LOGIC_ANALYZER
|
||||
waTriggerEventListener(signal, triggerIndexForListeners, timestamp PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#endif
|
||||
|
|
|
@ -71,8 +71,8 @@ HIP9011 instance(&hardware);
|
|||
static unsigned char tx_buff[1];
|
||||
static unsigned char rx_buff[1];
|
||||
|
||||
static scheduling_s startTimer[2];
|
||||
static scheduling_s endTimer[2];
|
||||
static scheduling_s startTimer;
|
||||
static scheduling_s endTimer;
|
||||
|
||||
static Logging *logger;
|
||||
|
||||
|
@ -167,16 +167,14 @@ static void showHipInfo(void) {
|
|||
instance.invalidHip9011ResponsesCount,
|
||||
instance.invalidHip9011ResponsesCount > 0 ? "NOT GOOD" : "ok");
|
||||
|
||||
scheduleMsg(logger, "CS@%s updateCount=%d",
|
||||
hwPortname(CONFIG(hip9011CsPin)),
|
||||
instance.settingUpdateCount);
|
||||
|
||||
#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 */
|
||||
|
||||
|
@ -184,6 +182,9 @@ static void showHipInfo(void) {
|
|||
engineConfiguration->knockDetectionWindowStart,
|
||||
engineConfiguration->knockDetectionWindowEnd);
|
||||
|
||||
scheduleMsg(logger, "Status: overruns %d",
|
||||
instance.overrun);
|
||||
|
||||
hipValueMax = 0;
|
||||
engine->printKnockState();
|
||||
}
|
||||
|
@ -247,25 +248,24 @@ static void endIntegration(void *) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Shaft Position callback used to start or finish HIP integration
|
||||
* Ignition callback used to start HIP integration and schedule finish
|
||||
*/
|
||||
void intHoldCallback(trigger_event_e ckpEventType, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
(void)ckpEventType;
|
||||
// this callback is invoked on interrupt thread
|
||||
if (index != 0)
|
||||
void hip9011_startKnockSampling(uint8_t cylinderNumber, efitick_t nowNt) {
|
||||
if (!CONFIG(isHip9011Enabled))
|
||||
return;
|
||||
|
||||
ScopePerf perf(PE::Hip9011IntHoldCallback);
|
||||
|
||||
int rpm = GET_RPM();
|
||||
if (!isValidRpm(rpm))
|
||||
/* overrun? */
|
||||
if (instance.state != READY_TO_INTEGRATE) {
|
||||
instance.overrun++;
|
||||
return;
|
||||
}
|
||||
|
||||
int structIndex = getRevolutionCounter() % 2;
|
||||
// todo: schedule this based on closest trigger event, same as ignition works
|
||||
scheduleByAngle(&startTimer[structIndex], edgeTimestamp, engineConfiguration->knockDetectionWindowStart,
|
||||
&startIntegration);
|
||||
scheduleByAngle(&endTimer[structIndex], edgeTimestamp, engineConfiguration->knockDetectionWindowEnd,
|
||||
instance.cylinderNumber = cylinderNumber;
|
||||
startIntegration(NULL);
|
||||
|
||||
/* TODO: reference to knockDetectionWindowStart */
|
||||
scheduleByAngle(&endTimer, nowNt,
|
||||
engineConfiguration->knockDetectionWindowEnd - engineConfiguration->knockDetectionWindowStart,
|
||||
&endIntegration);
|
||||
}
|
||||
|
||||
|
@ -307,12 +307,15 @@ void hipAdcCallback(adcsample_t adcValue) {
|
|||
if (instance.state == WAITING_FOR_ADC_TO_SKIP) {
|
||||
instance.state = WAITING_FOR_RESULT_ADC;
|
||||
} else if (instance.state == WAITING_FOR_RESULT_ADC) {
|
||||
engine->knockVolts = adcValue * adcToVolts(1) * CONFIG(analogInputDividerCoefficient);
|
||||
hipValueMax = maxF(engine->knockVolts, hipValueMax);
|
||||
engine->knockLogic(engine->knockVolts);
|
||||
float knockVolts = adcValue * adcToVolts(1) * CONFIG(analogInputDividerCoefficient);
|
||||
hipValueMax = maxF(knockVolts, hipValueMax);
|
||||
engine->knockLogic(knockVolts);
|
||||
|
||||
instance.handleValue(GET_RPM() DEFINE_PARAM_SUFFIX(PASS_HIP_PARAMS));
|
||||
|
||||
/* TunerStudio */
|
||||
tsOutputChannels.knockLevels[instance.cylinderNumber] = knockVolts;
|
||||
tsOutputChannels.knockLevel = knockVolts;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,4 +23,4 @@ void setPrescalerAndSDO(int value);
|
|||
void setKnockThresh(float value);
|
||||
void setMaxKnockSubDeg(int value);
|
||||
|
||||
void intHoldCallback(trigger_event_e ckpEventType, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void hip9011_startKnockSampling(uint8_t cylinderNumber, efitick_t nowNt);
|
||||
|
|
|
@ -76,7 +76,6 @@ public:
|
|||
|
||||
int currentIntergratorIndex = -1;
|
||||
bool needToInit = true;
|
||||
int settingUpdateCount = 0;
|
||||
int totalKnockEventsCount = 0;
|
||||
int currentPrescaler = 0;
|
||||
Hip9011HardwareInterface *hardware;
|
||||
|
@ -91,6 +90,10 @@ public:
|
|||
* hipOutput should be set to used FAST adc device
|
||||
*/
|
||||
hip_state_e state;
|
||||
uint8_t cylinderNumber;
|
||||
|
||||
/* error counters */
|
||||
int overrun = 0;
|
||||
|
||||
float rpmLookup[INT_LOOKUP_SIZE];
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue