fast adc callback (#3031)

* fast adc callback

* guard

* missed one

* now cypress will be happy
This commit is contained in:
Matthew Kennedy 2021-07-23 11:19:59 -07:00 committed by GitHub
parent a59179396f
commit 09192cfc4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 53 deletions

View File

@ -45,7 +45,7 @@ enum class PE : uint8_t {
GetSpeedDensityFuel,
WallFuelAdjust,
MapAveragingTriggerCallback,
AdcCallbackFastComplete,
Unused1,
SingleTimerExecutorScheduleByTimestamp,
GetTimeNowUs,
EventQueueExecuteCallback,

View File

@ -114,7 +114,12 @@ static adcsample_t getAvgAdcValue(int index, adcsample_t *samples, int bufDepth,
#define ADC_SAMPLING_FAST ADC_SAMPLE_28
#if EFI_USE_FAST_ADC
void adc_callback_fast(ADCDriver *adcp);
static void adc_callback_fast(ADCDriver *adcp) {
// State may not be complete if we get a callback for "half done"
if (adcp->state == ADC_COMPLETE) {
onFastAdcComplete(adcp->samples);
}
}
static ADCConversionGroup adcgrpcfgFast = {
.circular = FALSE,

View File

@ -65,3 +65,8 @@ void removeChannel(const char *name, adc_channel_e setting);
#endif /* HAL_USE_ADC */
void printFullAdcReport(void);
#if HAL_USE_ADC
// This callback is called by the ADC driver when a new fast ADC sample is ready
void onFastAdcComplete(adcsample_t* samples);
#endif

View File

@ -155,22 +155,18 @@ static int adcCallbackCounter = 0;
static volatile int averagedSamples[ADC_MAX_CHANNELS_COUNT];
static adcsample_t avgBuf[ADC_MAX_CHANNELS_COUNT];
void adc_callback_fast_internal(ADCDriver *adcp);
void onFastAdcCompleteInternal(adcsample_t* samples);
void adc_callback_fast(ADCDriver *adcp) {
adcsample_t *buffer = adcp->samples;
//size_t n = adcp->depth;
if (adcp->state == ADC_COMPLETE) {
void onFastAdcComplete(adcsample_t* samples) {
#if HAL_TRIGGER_USE_ADC
// we need to call this ASAP, because trigger processing is time-critical
if (triggerSampleIndex >= 0)
triggerAdcCallback(buffer[triggerSampleIndex]);
triggerAdcCallback(samples[triggerSampleIndex]);
#endif /* HAL_TRIGGER_USE_ADC */
// store the values for averaging
for (int i = fastAdc.size() - 1; i >= 0; i--) {
averagedSamples[i] += fastAdc.samples[i];
averagedSamples[i] += samples[i];
}
// if it's time to process the data
@ -181,7 +177,7 @@ void adc_callback_fast(ADCDriver *adcp) {
}
// call the real callback (see below)
adc_callback_fast_internal(adcp);
onFastAdcCompleteInternal(samples);
// reset the avg buffer & counter
for (int i = fastAdc.size() - 1; i >= 0; i--) {
@ -189,7 +185,6 @@ void adc_callback_fast(ADCDriver *adcp) {
}
adcCallbackCounter = 0;
}
}
}
#endif /* EFI_FASTER_UNIFORM_ADC */
@ -198,24 +193,12 @@ void adc_callback_fast(ADCDriver *adcp) {
* This method is not in the adc* lower-level file because it is more business logic then hardware.
*/
#if EFI_FASTER_UNIFORM_ADC
void adc_callback_fast_internal(ADCDriver *adcp) {
void onFastAdcCompleteInternal(adcsample_t* buffer) {
#else
void adc_callback_fast(ADCDriver *adcp) {
void onFastAdcComplete(adcsample_t* buffer) {
#endif
adcsample_t *buffer = adcp->samples;
size_t n = adcp->depth;
(void) buffer;
(void) n;
ScopePerf perf(PE::AdcCallbackFast);
/**
* Note, only in the ADC_COMPLETE state because the ADC driver fires an
* intermediate callback when the buffer is half full.
* */
if (adcp->state == ADC_COMPLETE) {
ScopePerf perf(PE::AdcCallbackFastComplete);
/**
* this callback is executed 10 000 times a second, it needs to be as fast as possible
*/
@ -239,7 +222,6 @@ void adc_callback_fast(ADCDriver *adcp) {
// if (tpsSampleIndex != TPS_IS_SLOW) {
// tpsFastAdc = buffer[tpsSampleIndex];
// }
}
}
#endif /* HAL_USE_ADC */