share some knock logic (#3246)
* knocky knock * only if TS * typo * merge
This commit is contained in:
parent
b5bde5c307
commit
bf98546314
|
@ -8,6 +8,7 @@
|
|||
#include "pch.h"
|
||||
#include "knock_logic.h"
|
||||
#include "os_access.h"
|
||||
#include "peak_detect.h"
|
||||
|
||||
int getCylinderKnockBank(uint8_t cylinderIndex) {
|
||||
// C/C++ can't index in to bit fields, we have to provide lookup ourselves
|
||||
|
@ -42,3 +43,26 @@ int getCylinderKnockBank(uint8_t cylinderIndex) {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
using PD = PeakDetect<float, MS2NT(100)>;
|
||||
static PD peakDetectors[12];
|
||||
static PD allCylinderPeakDetector;
|
||||
|
||||
void onKnockSenseCompleted(uint8_t cylinderIndex, float dbv, efitick_t lastKnockTime) {
|
||||
#if EFI_TUNER_STUDIO
|
||||
// Pass through per-cylinder peak detector
|
||||
float cylPeak = peakDetectors[cylinderIndex].detect(dbv, lastKnockTime);
|
||||
tsOutputChannels.knockLevels[cylinderIndex] = roundf(cylPeak);
|
||||
|
||||
// Pass through all-cylinders peak detector
|
||||
tsOutputChannels.knockLevel = allCylinderPeakDetector.detect(dbv, lastKnockTime);
|
||||
|
||||
// If this was a knock, count it!
|
||||
bool isKnock = dbv > ENGINE(engineState).knockThreshold;
|
||||
if (isKnock) {
|
||||
tsOutputChannels.knockCount++;
|
||||
}
|
||||
#endif // EFI_TUNER_STUDIO
|
||||
|
||||
// TODO: retard timing, then put it back!
|
||||
}
|
||||
|
|
|
@ -8,3 +8,5 @@
|
|||
#pragma once
|
||||
|
||||
int getCylinderKnockBank(uint8_t cylinderIndex);
|
||||
|
||||
void onKnockSenseCompleted(uint8_t cylinderIndex, float levelDbv, efitick_t lastKnockTime);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "thread_controller.h"
|
||||
#include "knock_logic.h"
|
||||
#include "software_knock.h"
|
||||
#include "peak_detect.h"
|
||||
|
||||
#if EFI_SOFTWARE_KNOCK
|
||||
|
||||
|
@ -142,7 +141,7 @@ static void startKnockSampling(uint8_t cylinderIndex) {
|
|||
lastKnockSampleTime = getTimeNowNt();
|
||||
}
|
||||
|
||||
static void startKnockSamplingNoParam(void *arg) {
|
||||
static void startKnockSamplingNoParam(void*) {
|
||||
// ugly as hell but that's error: cast between incompatible function types from 'void (*)(uint8_t)' {aka 'void (*)(unsigned char)'} to 'schfunc_t' {aka 'void (*)(void*)'} [-Werror=cast-function-type]
|
||||
startKnockSampling(cylinderIndexCopy);
|
||||
}
|
||||
|
@ -177,10 +176,6 @@ void initSoftwareKnock() {
|
|||
}
|
||||
}
|
||||
|
||||
using PD = PeakDetect<float, MS2NT(100)>;
|
||||
static PD peakDetectors[12];
|
||||
static PD allCylinderPeakDetector;
|
||||
|
||||
void processLastKnockEvent() {
|
||||
if (!knockNeedsProcess) {
|
||||
return;
|
||||
|
@ -226,17 +221,7 @@ void processLastKnockEvent() {
|
|||
// clamp to reasonable range
|
||||
db = clampF(-100, db, 100);
|
||||
|
||||
// Pass through peak detector
|
||||
float cylPeak = peakDetectors[currentCylinderIndex].detect(db, lastKnockTime);
|
||||
|
||||
tsOutputChannels.knockLevels[currentCylinderIndex] = roundf(cylPeak);
|
||||
tsOutputChannels.knockLevel = allCylinderPeakDetector.detect(db, lastKnockTime);
|
||||
|
||||
// If this was a knock, count it!
|
||||
bool isKnock = db > ENGINE(engineState).knockThreshold;
|
||||
if (isKnock) {
|
||||
tsOutputChannels.knockCount++;
|
||||
}
|
||||
onKnockSenseCompleted(currentCylinderIndex, db, lastKnockTime);
|
||||
}
|
||||
|
||||
void KnockThread::ThreadTask() {
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "trigger_central.h"
|
||||
#include "hip9011_logic.h"
|
||||
#include "hip9011.h"
|
||||
#include "knock_logic.h"
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#include "mpu_util.h"
|
||||
|
@ -242,6 +243,9 @@ static void endIntegration(HIP9011 *hip) {
|
|||
*/
|
||||
if (hip->state == IS_INTEGRATING) {
|
||||
intHold.setLow();
|
||||
|
||||
hip->knockSampleTimestamp = getTimeNowNt();
|
||||
|
||||
if (instance.adv_mode) {
|
||||
/* read value over SPI in thread mode */
|
||||
hip->state = NOT_READY;
|
||||
|
@ -486,9 +490,8 @@ static msg_t hipThread(void *arg) {
|
|||
/* report */
|
||||
engine->knockLogic(knockVolts);
|
||||
|
||||
/* TunerStudio */
|
||||
tsOutputChannels.knockLevels[instance.cylinderNumber] = knockVolts;
|
||||
tsOutputChannels.knockLevel = knockVolts;
|
||||
// TODO: convert knock level to dBv
|
||||
onKnockSenseCompleted(instance.cylinderNumber, knockVolts, instance.knockSampleTimestamp);
|
||||
|
||||
#if EFI_HIP_9011_DEBUG
|
||||
/* debug */
|
||||
|
|
|
@ -128,6 +128,9 @@ public:
|
|||
|
||||
float rpmLookup[INT_LOOKUP_SIZE];
|
||||
|
||||
// Timestamp of the last sensed event
|
||||
efitick_t knockSampleTimestamp = 0;
|
||||
|
||||
#if EFI_HIP_9011_DEBUG
|
||||
/* SPI counters */
|
||||
int correctResponsesCount = 0;
|
||||
|
|
Loading…
Reference in New Issue