From 9c2dd1073433017ded2774438882d213a92ec610 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 8 Oct 2019 17:44:59 -0700 Subject: [PATCH] low hanging performance fruit (#969) --- firmware/hw_layer/adc_inputs.cpp | 15 ++++++--------- firmware/hw_layer/hardware.cpp | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/firmware/hw_layer/adc_inputs.cpp b/firmware/hw_layer/adc_inputs.cpp index d7347f7794..79b1727cbb 100644 --- a/firmware/hw_layer/adc_inputs.cpp +++ b/firmware/hw_layer/adc_inputs.cpp @@ -459,29 +459,26 @@ static void adc_callback_slow(ADCDriver *adcp, adcsample_t *buffer, size_t n) { (void) buffer; (void) n; - slowAdc.invalidateSamplesCache(); - - efiAssertVoid(CUSTOM_ERR_6671, getCurrentRemainingStack() > 128, "lowstck#9c"); /* 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) { + slowAdc.invalidateSamplesCache(); + + efiAssertVoid(CUSTOM_ERR_6671, getCurrentRemainingStack() > 128, "lowstck#9c"); + /* Calculates the average values from the ADC samples.*/ for (int i = 0; i < slowAdc.size(); i++) { int value = getAvgAdcValue(i, slowAdc.samples, ADC_BUF_DEPTH_SLOW, slowAdc.size()); adcsample_t prev = slowAdc.values.adc_data[i]; float result = (slowAdcCounter == 0) ? value : CONFIG(slowAdcAlpha) * value + (1 - CONFIG(slowAdcAlpha)) * prev; -// if (slowAdcCounter == 0) { -// biq[i].initValue(value); -// } -// float result = biq[i].getValue(value); slowAdc.values.adc_data[i] = (int)result; } slowAdcCounter++; - } - AdcSubscription::UpdateSubscribers(); + AdcSubscription::UpdateSubscribers(); + } } static char errorMsgBuff[_MAX_FILLER + 2]; diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 160f4ac833..55d8ce5c7d 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -195,8 +195,6 @@ extern AdcDevice fastAdc; * This method is not in the adc* lower-level file because it is more business logic then hardware. */ void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) { - fastAdc.invalidateSamplesCache(); - (void) buffer; (void) n; /** @@ -204,6 +202,8 @@ void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) { * intermediate callback when the buffer is half full. * */ if (adcp->state == ADC_COMPLETE) { + fastAdc.invalidateSamplesCache(); + /** * this callback is executed 10 000 times a second, it needs to be as fast as possible */