modularize knock adc for h7 (#7086)
* modularize knock adc for h7 only:uaefi * modularize knock adc for h7 only:uaefi
This commit is contained in:
parent
714c190093
commit
ec83526370
|
@ -38,93 +38,13 @@ static volatile size_t sampleCount = 0;
|
|||
|
||||
chibios_rt::BinarySemaphore knockSem(/* taken =*/ true);
|
||||
|
||||
static void completionCallback(ADCDriver* adcp) {
|
||||
if (adcp->state == ADC_COMPLETE) {
|
||||
void onKnockSamplingComplete() {
|
||||
knockNeedsProcess = true;
|
||||
|
||||
// Notify the processing thread that it's time to process this sample
|
||||
chSysLockFromISR();
|
||||
knockSem.signalI();
|
||||
chSysUnlockFromISR();
|
||||
}
|
||||
}
|
||||
|
||||
static void errorCallback(ADCDriver*, adcerror_t) {
|
||||
}
|
||||
|
||||
static const uint32_t smpr1 =
|
||||
ADC_SMPR1_SMP_AN10(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN11(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN12(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN13(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN14(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN15(KNOCK_SAMPLE_TIME);
|
||||
|
||||
static const uint32_t smpr2 =
|
||||
ADC_SMPR2_SMP_AN0(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN1(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN2(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN3(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN4(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN5(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN6(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN7(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN8(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN9(KNOCK_SAMPLE_TIME);
|
||||
|
||||
static const ADCConversionGroup adcConvGroupCh1 = {
|
||||
.circular = FALSE,
|
||||
.num_channels = 1,
|
||||
.end_cb = &completionCallback,
|
||||
.error_cb = &errorCallback,
|
||||
.cr1 = 0,
|
||||
.cr2 = ADC_CR2_SWSTART,
|
||||
// sample times for channels 10...18
|
||||
.smpr1 = smpr1,
|
||||
// sample times for channels 0...9
|
||||
.smpr2 = smpr2,
|
||||
|
||||
.htr = 0,
|
||||
.ltr = 0,
|
||||
|
||||
.sqr1 = 0,
|
||||
.sqr2 = 0,
|
||||
.sqr3 = ADC_SQR3_SQ1_N(KNOCK_ADC_CH1)
|
||||
};
|
||||
|
||||
// Not all boards have a second channel - configure it if it exists
|
||||
#if KNOCK_HAS_CH2
|
||||
static const ADCConversionGroup adcConvGroupCh2 = {
|
||||
.circular = FALSE,
|
||||
.num_channels = 1,
|
||||
.end_cb = &completionCallback,
|
||||
.error_cb = &errorCallback,
|
||||
.cr1 = 0,
|
||||
.cr2 = ADC_CR2_SWSTART,
|
||||
// sample times for channels 10...18
|
||||
.smpr1 = smpr1,
|
||||
// sample times for channels 0...9
|
||||
.smpr2 = smpr2,
|
||||
|
||||
.htr = 0,
|
||||
.ltr = 0,
|
||||
|
||||
.sqr1 = 0,
|
||||
.sqr2 = 0,
|
||||
.sqr3 = ADC_SQR3_SQ1_N(KNOCK_ADC_CH2)
|
||||
};
|
||||
#endif // KNOCK_HAS_CH2
|
||||
|
||||
static const ADCConversionGroup* getConversionGroup(uint8_t channelIdx) {
|
||||
#if KNOCK_HAS_CH2
|
||||
if (channelIdx == 1) {
|
||||
return &adcConvGroupCh2;
|
||||
}
|
||||
#else
|
||||
(void)channelIdx;
|
||||
#endif // KNOCK_HAS_CH2
|
||||
|
||||
return &adcConvGroupCh1;
|
||||
}
|
||||
|
||||
void onStartKnockSampling(uint8_t cylinderNumber, float samplingSeconds, uint8_t channelIdx) {
|
||||
|
@ -149,7 +69,7 @@ void onStartKnockSampling(uint8_t cylinderNumber, float samplingSeconds, uint8_t
|
|||
sampleCount = 0xFFFFFFFE & static_cast<size_t>(clampF(100, samplingSeconds * sampleRate, efi::size(sampleBuffer)));
|
||||
|
||||
// Select the appropriate conversion group - it will differ depending on which sensor this cylinder should listen on
|
||||
auto conversionGroup = getConversionGroup(channelIdx);
|
||||
auto conversionGroup = getKnockConversionGroup(channelIdx);
|
||||
|
||||
//current chanel number for spectrum TS plugin
|
||||
channelNumber = channelIdx;
|
||||
|
@ -181,7 +101,6 @@ void initSoftwareKnock() {
|
|||
}
|
||||
|
||||
knockFilter.configureBandpass(KNOCK_SAMPLE_RATE, frequencyHz, 3);
|
||||
adcStart(&KNOCK_ADC, nullptr);
|
||||
|
||||
#ifdef KNOCK_SPECTROGRAM
|
||||
if(engineConfiguration->enableKnockSpectrogram)
|
||||
|
|
|
@ -112,6 +112,8 @@ static constexpr AdcToken invalidAdcToken = (AdcToken)(-1);
|
|||
|
||||
AdcToken enableFastAdcChannel(const char* msg, adc_channel_e channel);
|
||||
adcsample_t getFastAdc(AdcToken token);
|
||||
const ADCConversionGroup* getKnockConversionGroup(uint8_t channelIdx);
|
||||
void onKnockSamplingComplete();
|
||||
#endif // HAL_USE_ADC
|
||||
|
||||
void printFullAdcReport(void);
|
||||
|
|
|
@ -52,6 +52,10 @@ void portInitAdc() {
|
|||
nvicDisableVector(STM32_ADC_NUMBER);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef KNOCK_ADC
|
||||
adcStart(&KNOCK_ADC, nullptr);
|
||||
#endif // KNOCK_ADC
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -227,4 +231,93 @@ adcsample_t getFastAdc(AdcToken token) {
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef EFI_SOFTWARE_KNOCK
|
||||
#include "knock_config.h"
|
||||
|
||||
static void knockCompletionCallback(ADCDriver* adcp) {
|
||||
if (adcp->state == ADC_COMPLETE) {
|
||||
onKnockSamplingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
static void knockErrorCallback(ADCDriver*, adcerror_t) {
|
||||
}
|
||||
|
||||
static const uint32_t smpr1 =
|
||||
ADC_SMPR1_SMP_AN10(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN11(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN12(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN13(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN14(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR1_SMP_AN15(KNOCK_SAMPLE_TIME);
|
||||
|
||||
static const uint32_t smpr2 =
|
||||
ADC_SMPR2_SMP_AN0(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN1(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN2(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN3(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN4(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN5(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN6(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN7(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN8(KNOCK_SAMPLE_TIME) |
|
||||
ADC_SMPR2_SMP_AN9(KNOCK_SAMPLE_TIME);
|
||||
|
||||
static const ADCConversionGroup adcConvGroupCh1 = {
|
||||
.circular = FALSE,
|
||||
.num_channels = 1,
|
||||
.end_cb = &knockCompletionCallback,
|
||||
.error_cb = &knockErrorCallback,
|
||||
.cr1 = 0,
|
||||
.cr2 = ADC_CR2_SWSTART,
|
||||
// sample times for channels 10...18
|
||||
.smpr1 = smpr1,
|
||||
// sample times for channels 0...9
|
||||
.smpr2 = smpr2,
|
||||
|
||||
.htr = 0,
|
||||
.ltr = 0,
|
||||
|
||||
.sqr1 = 0,
|
||||
.sqr2 = 0,
|
||||
.sqr3 = ADC_SQR3_SQ1_N(KNOCK_ADC_CH1)
|
||||
};
|
||||
|
||||
// Not all boards have a second channel - configure it if it exists
|
||||
#if KNOCK_HAS_CH2
|
||||
static const ADCConversionGroup adcConvGroupCh2 = {
|
||||
.circular = FALSE,
|
||||
.num_channels = 1,
|
||||
.end_cb = &knockCompletionCallback,
|
||||
.error_cb = &knockErrorCallback,
|
||||
.cr1 = 0,
|
||||
.cr2 = ADC_CR2_SWSTART,
|
||||
// sample times for channels 10...18
|
||||
.smpr1 = smpr1,
|
||||
// sample times for channels 0...9
|
||||
.smpr2 = smpr2,
|
||||
|
||||
.htr = 0,
|
||||
.ltr = 0,
|
||||
|
||||
.sqr1 = 0,
|
||||
.sqr2 = 0,
|
||||
.sqr3 = ADC_SQR3_SQ1_N(KNOCK_ADC_CH2)
|
||||
};
|
||||
#endif // KNOCK_HAS_CH2
|
||||
|
||||
const ADCConversionGroup* getKnockConversionGroup(uint8_t channelIdx) {
|
||||
#if KNOCK_HAS_CH2
|
||||
if (channelIdx == 1) {
|
||||
return &adcConvGroupCh2;
|
||||
}
|
||||
#else
|
||||
(void)channelIdx;
|
||||
#endif // KNOCK_HAS_CH2
|
||||
|
||||
return &adcConvGroupCh1;
|
||||
}
|
||||
|
||||
#endif // EFI_SOFTWARE_KNOCK
|
||||
|
||||
#endif // HAL_USE_ADC
|
||||
|
|
Loading…
Reference in New Issue