mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 12:14:32 +02:00
Merge branch 'bugfix/fix_adc_filter_acquire_logic_v5.1' into 'release/v5.1'
adc: fix adc filter driver acquire logic (v5.1) See merge request espressif/esp-idf!25507
This commit is contained in:
@@ -21,8 +21,8 @@ static portMUX_TYPE s_filter_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
|||||||
|
|
||||||
|
|
||||||
#if SOC_ADC_DIG_IIR_FILTER_UNIT_BINDED
|
#if SOC_ADC_DIG_IIR_FILTER_UNIT_BINDED
|
||||||
static atomic_bool s_adc_filter_claimed[SOC_ADC_PERIPH_NUM] = {ATOMIC_VAR_INIT(false),
|
static atomic_bool s_adc_filter_claimed[SOC_ADC_DIGI_IIR_FILTER_NUM] = {ATOMIC_VAR_INIT(false),
|
||||||
#if (SOC_ADC_PERIPH_NUM >= 2)
|
#if (SOC_ADC_DIGI_IIR_FILTER_NUM >= 2)
|
||||||
ATOMIC_VAR_INIT(false)
|
ATOMIC_VAR_INIT(false)
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@@ -59,16 +59,18 @@ static esp_err_t s_adc_filter_claim(adc_continuous_handle_t handle, adc_iir_filt
|
|||||||
{
|
{
|
||||||
(void)unit;
|
(void)unit;
|
||||||
assert(handle && filter_ctx);
|
assert(handle && filter_ctx);
|
||||||
|
|
||||||
|
portENTER_CRITICAL(&s_filter_spinlock);
|
||||||
for (int i = 0; i < SOC_ADC_DIGI_IIR_FILTER_NUM; i++) {
|
for (int i = 0; i < SOC_ADC_DIGI_IIR_FILTER_NUM; i++) {
|
||||||
portENTER_CRITICAL(&s_filter_spinlock);
|
|
||||||
bool found = !handle->iir_filter[i];
|
bool found = !handle->iir_filter[i];
|
||||||
handle->iir_filter[i] = filter_ctx;
|
|
||||||
filter_ctx->filter_id = i;
|
|
||||||
portEXIT_CRITICAL(&s_filter_spinlock);
|
|
||||||
if (found) {
|
if (found) {
|
||||||
|
handle->iir_filter[i] = filter_ctx;
|
||||||
|
filter_ctx->filter_id = i;
|
||||||
|
portEXIT_CRITICAL(&s_filter_spinlock);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
portEXIT_CRITICAL(&s_filter_spinlock);
|
||||||
|
|
||||||
return ESP_ERR_NOT_FOUND;
|
return ESP_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,8 @@
|
|||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
#include "esp_adc/adc_oneshot.h"
|
#include "esp_adc/adc_oneshot.h"
|
||||||
#include "test_common_adc.h"
|
#include "test_common_adc.h"
|
||||||
|
#include "esp_adc/adc_continuous.h"
|
||||||
|
#include "esp_adc/adc_filter.h"
|
||||||
|
|
||||||
const __attribute__((unused)) static char *TAG = "TEST_ADC";
|
const __attribute__((unused)) static char *TAG = "TEST_ADC";
|
||||||
|
|
||||||
@@ -127,3 +129,40 @@ TEST_CASE("ADC oneshot fast work with ISR", "[adc_oneshot]")
|
|||||||
TEST_ESP_OK(gptimer_del_timer(timer));
|
TEST_ESP_OK(gptimer_del_timer(timer));
|
||||||
TEST_ESP_OK(adc_oneshot_del_unit(isr_test_ctx.adc_handle));
|
TEST_ESP_OK(adc_oneshot_del_unit(isr_test_ctx.adc_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SOC_ADC_DMA_SUPPORTED
|
||||||
|
#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
|
||||||
|
TEST_CASE("ADC filter exhausted allocation", "[adc_oneshot]")
|
||||||
|
{
|
||||||
|
adc_continuous_handle_t handle = NULL;
|
||||||
|
adc_continuous_handle_cfg_t adc_config = {
|
||||||
|
.max_store_buf_size = 1024,
|
||||||
|
.conv_frame_size = 1024,
|
||||||
|
};
|
||||||
|
TEST_ESP_OK(adc_continuous_new_handle(&adc_config, &handle));
|
||||||
|
|
||||||
|
adc_iir_filter_handle_t filter_hdl[SOC_ADC_DIGI_IIR_FILTER_NUM + 1] = {};
|
||||||
|
adc_continuous_iir_filter_config_t filter_config = {
|
||||||
|
.unit = ADC_UNIT_1,
|
||||||
|
.channel = ADC_CHANNEL_0,
|
||||||
|
.coeff = ADC_DIGI_IIR_FILTER_COEFF_2,
|
||||||
|
};
|
||||||
|
for (int i = 0; i < SOC_ADC_DIGI_IIR_FILTER_NUM; i++) {
|
||||||
|
#if SOC_ADC_DIG_IIR_FILTER_UNIT_BINDED
|
||||||
|
//On these chips, the unit and the filter_id should be the same
|
||||||
|
filter_config.unit = i;
|
||||||
|
#endif
|
||||||
|
TEST_ESP_OK(adc_new_continuous_iir_filter(handle, &filter_config, &filter_hdl[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
filter_config.unit = ADC_UNIT_1;
|
||||||
|
TEST_ASSERT(adc_new_continuous_iir_filter(handle, &filter_config, &filter_hdl[SOC_ADC_DIGI_IIR_FILTER_NUM]) == ESP_ERR_NOT_FOUND);
|
||||||
|
|
||||||
|
for (int i = 0; i < SOC_ADC_DIGI_IIR_FILTER_NUM; i++) {
|
||||||
|
TEST_ESP_OK(adc_del_continuous_iir_filter(filter_hdl[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ESP_OK(adc_continuous_deinit(handle));
|
||||||
|
}
|
||||||
|
#endif //#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
|
||||||
|
#endif //#if SOC_ADC_DMA_SUPPORTED
|
||||||
|
Reference in New Issue
Block a user