Implement auto knock threshold sampling #3033

This commit is contained in:
rusefillc 2021-08-10 06:42:39 -04:00
parent baa3986957
commit cc9b8ffa98
3 changed files with 19 additions and 3 deletions

View File

@ -216,7 +216,7 @@ if (engineConfiguration->debugMode == DBG_DWELL_METRIC) {
}
#if EFI_SOFTWARE_KNOCK
startKnockSampling(event->cylinderNumber);
knockSamplingCallback(event->cylinderNumber, nowNt);
#endif
#if EFI_HIP_9011
hip9011_onFireEvent(event->cylinderNumber, nowNt);

View File

@ -19,6 +19,7 @@ static Biquad knockFilter;
static volatile bool knockIsSampling = false;
static volatile bool knockNeedsProcess = false;
static volatile size_t sampleCount = 0;
static int cylinderIndexCopy;
chibios_rt::BinarySemaphore knockSem(/* taken =*/ true);
@ -105,7 +106,7 @@ const ADCConversionGroup* getConversionGroup(uint8_t cylinderIndex) {
return &adcConvGroupCh1;
}
void startKnockSampling(uint8_t cylinderIndex) {
static void startKnockSampling(uint8_t cylinderIndex) {
if (!CONFIG(enableSoftwareKnock)) {
return;
}
@ -141,6 +142,20 @@ void startKnockSampling(uint8_t cylinderIndex) {
lastKnockSampleTime = getTimeNowNt();
}
static void startKnockSamplingNoParam(void *arg) {
// 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);
}
static scheduling_s startSampling;
void knockSamplingCallback(uint8_t cylinderIndex, efitick_t nowNt) {
cylinderIndexCopy = cylinderIndex;
scheduleByAngle(&startSampling, nowNt,
/*angle*/CONFIG(knockDetectionWindowStart), startKnockSamplingNoParam PASS_ENGINE_PARAMETER_SUFFIX);
}
class KnockThread : public ThreadController<256> {
public:
KnockThread() : ThreadController("knock", PRIO_KNOCK_PROCESS) {}

View File

@ -1,7 +1,8 @@
#pragma once
#include "pch.h"
#include <cstdint>
void initSoftwareKnock();
void startKnockSampling(uint8_t cylinderIndex);
void knockSamplingCallback(uint8_t cylinderIndex, efitick_t nowNt);
void processLastKnockEvent();