0% found this document useful (0 votes)
22 views3 pages

Adc New Data

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Adc New Data

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

data, when pool is full

---
components/esp_adc/adc_continuous.c | 28 +++++++++++++++----
components/esp_adc/adc_continuous_internal.h | 4 +++
.../esp_adc/include/esp_adc/adc_continuous.h | 3 ++
3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/components/esp_adc/adc_continuous.c


b/components/esp_adc/adc_continuous.c
index 90d5c78c478..6341236881d 100644
--- a/components/esp_adc/adc_continuous.c
+++ b/components/esp_adc/adc_continuous.c
@@ -112,6 +112,7 @@ esp_err_t adc_continuous_new_handle(const
adc_continuous_handle_cfg_t *hdl_confi
}

//ringbuffer storage/struct buffer


+ adc_ctx->ringbuf_size = hdl_config->max_store_buf_size;
adc_ctx->ringbuf_storage = heap_caps_calloc(1, hdl_config->max_store_buf_size,
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
adc_ctx->ringbuf_struct = heap_caps_calloc(1, sizeof(StaticRingbuffer_t),
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (!adc_ctx->ringbuf_storage || !adc_ctx->ringbuf_struct) {
@@ -230,6 +231,7 @@ esp_err_t adc_continuous_new_handle(const
adc_continuous_handle_cfg_t *hdl_confi
};
adc_hal_dma_ctx_config(&adc_ctx->hal, &config);

+ adc_ctx->flags.flush_pool = hdl_config->flags.flush_pool;
adc_ctx->fsm = ADC_FSM_INIT;
*ret_handle = adc_ctx;

@@ -308,11 +310,27 @@ static IRAM_ATTR bool s_adc_dma_intr(adc_continuous_ctx_t


*adc_digi_ctx)
}

if (ret == pdFALSE) {
- //ringbuffer overflow
- if (adc_digi_ctx->cbs.on_pool_ovf) {
- adc_continuous_evt_data_t edata = {};
- if (adc_digi_ctx->cbs.on_pool_ovf(adc_digi_ctx, &edata,
adc_digi_ctx->user_data)) {
- need_yield |= true;
+ if (adc_digi_ctx->flags.flush_pool) {
+ size_t actual_size = 0;
+ uint8_t *old_data = xRingbufferReceiveUpToFromISR(adc_digi_ctx-
>ringbuf_hdl, &actual_size, adc_digi_ctx->ringbuf_size);
+ /**
+ * Replace by ringbuffer reset API when this API is ready.
+ * Now we do mannual reset.
+ */
+ if (old_data) {
+ vRingbufferReturnItemFromISR(adc_digi_ctx->ringbuf_hdl,
old_data, &taskAwoken);
+ xRingbufferSendFromISR(adc_digi_ctx->ringbuf_hdl,
current_desc->buffer, current_desc->dw0.length, &taskAwoken);
+ if (taskAwoken == pdTRUE) {
+ need_yield |= true;
+ }
+ }
+ } else {
+ //ringbuffer overflow
+ if (adc_digi_ctx->cbs.on_pool_ovf) {
+ adc_continuous_evt_data_t edata = {};
+ if (adc_digi_ctx->cbs.on_pool_ovf(adc_digi_ctx, &edata,
adc_digi_ctx->user_data)) {
+ need_yield |= true;
+ }
}
}
}
diff --git a/components/esp_adc/adc_continuous_internal.h
b/components/esp_adc/adc_continuous_internal.h
index e352c300e79..3d8d7a39872 100644
--- a/components/esp_adc/adc_continuous_internal.h
+++ b/components/esp_adc/adc_continuous_internal.h
@@ -66,6 +66,7 @@ struct adc_continuous_ctx_t {
RingbufHandle_t ringbuf_hdl; //RX ringbuffer
handler
void* ringbuf_storage; //Ringbuffer
storage buffer
void* ringbuf_struct; //Ringbuffer
structure buffer
+ size_t ringbuf_size; //Ringbuffer size
intptr_t rx_eof_desc_addr; //eof descriptor
address of RX channel
adc_fsm_t fsm; //ADC continuous
mode driver internal states
bool use_adc1; //1: ADC unit1
will be used; 0: ADC unit1 won't be used.
@@ -76,6 +77,9 @@ struct adc_continuous_ctx_t {
adc_continuous_evt_cbs_t cbs; //Callbacks
void *user_data; //User context
esp_pm_lock_handle_t pm_lock; //For power
management
+ struct {
+ uint32_t flush_pool: 1; //Flush the internal pool when the pool is
full. With this flag, the `on_pool_ovf` event will not happen.
+ } flags;
#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
adc_iir_filter_t *iir_filter[SOC_ADC_DIGI_IIR_FILTER_NUM];
//ADC IIR filter context
#endif
diff --git a/components/esp_adc/include/esp_adc/adc_continuous.h
b/components/esp_adc/include/esp_adc/adc_continuous.h
index d4827669e91..e1e67baa32e 100644
--- a/components/esp_adc/include/esp_adc/adc_continuous.h
+++ b/components/esp_adc/include/esp_adc/adc_continuous.h
@@ -54,6 +54,9 @@ typedef struct adc_continuous_ctx_t *adc_continuous_handle_t;
typedef struct {
uint32_t max_store_buf_size; ///< Max length of the conversion Results that
driver can store, in bytes.
uint32_t conv_frame_size; ///< Conversion frame size, in bytes. This
should be in multiples of `SOC_ADC_DIGI_DATA_BYTES_PER_CONV`.
+ struct {
+ uint32_t flush_pool: 1; ///< Flush the internal pool when the pool is
full. With this flag, the `on_pool_ovf` event will not happen.
+ } flags;
} adc_continuous_handle_cfg_t;

/**
--
2.25.1

You might also like