Skip to content

Commit 72d49fe

Browse files
committed
driver: adc16 dma support async and repeat sample
add support for async call and repeat sample test 1. change the DMA req to 2 byte each 2. increase the buffer pre-dma 3. add protection on invalid buffer depends on: PR #56104 fixing: issue #56070 Signed-off-by: Hake Huang <[email protected]>
1 parent da9059b commit 72d49fe

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

drivers/adc/adc_mcux_adc16.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static void adc_dma_callback(const struct device *dma_dev, void *callback_arg,
8282
struct mcux_adc16_data *data = dev->data;
8383

8484
LOG_DBG("DMA done");
85+
data->buffer++;
8586
adc_context_on_sampling_done(&data->ctx, dev);
8687
}
8788
#endif
@@ -196,6 +197,19 @@ static int start_read(const struct device *dev,
196197
}
197198
ADC16_SetHardwareAverage(config->base, mode);
198199

200+
if (sequence->buffer_size < 2) {
201+
LOG_ERR("sequence buffer size too small %d < 2", sequence->buffer_size);
202+
return -EINVAL;
203+
}
204+
205+
if (sequence->options) {
206+
if (sequence->buffer_size <
207+
2 * (sequence->options->extra_samplings + 1)) {
208+
LOG_ERR("sequence buffer size too small < 2 * extra + 2");
209+
return -EINVAL;
210+
}
211+
}
212+
199213
data->buffer = sequence->buffer;
200214

201215
adc_context_start_read(&data->ctx, sequence);
@@ -271,8 +285,7 @@ static void adc_context_start_sampling(struct adc_context *ctx)
271285

272286
#ifdef CONFIG_ADC_MCUX_ADC16_ENABLE_EDMA
273287
LOG_DBG("config dma");
274-
data->buffer = ctx->sequence.buffer;
275-
data->adc_dma_config.dma_block.block_size = ctx->sequence.buffer_size;
288+
data->adc_dma_config.dma_block.block_size = 2;
276289
data->adc_dma_config.dma_block.dest_address = (uint32_t)data->buffer;
277290
data->adc_dma_config.dma_cfg.head_block =
278291
&(data->adc_dma_config.dma_block);
@@ -380,21 +393,19 @@ static int mcux_adc16_init(const struct device *dev)
380393
#ifdef CONFIG_ADC_MCUX_ADC16_ENABLE_EDMA
381394
/* Enable DMA. */
382395
ADC16_EnableDMA(base, true);
383-
384396
data->adc_dma_config.dma_cfg.block_count = 1U;
385397
data->adc_dma_config.dma_cfg.dma_slot = config->dma_slot;
386398
data->adc_dma_config.dma_cfg.channel_direction = PERIPHERAL_TO_MEMORY;
387-
data->adc_dma_config.dma_cfg.source_burst_length = 4U;
388-
data->adc_dma_config.dma_cfg.dest_burst_length = 4U;
399+
data->adc_dma_config.dma_cfg.source_burst_length = 2U;
400+
data->adc_dma_config.dma_cfg.dest_burst_length = 2U;
389401
data->adc_dma_config.dma_cfg.channel_priority = 0U;
390402
data->adc_dma_config.dma_cfg.dma_callback = adc_dma_callback;
391403
data->adc_dma_config.dma_cfg.user_data = (void *)dev;
392404

393-
data->adc_dma_config.dma_cfg.source_data_size = 4U;
394-
data->adc_dma_config.dma_cfg.dest_data_size = 4U;
405+
data->adc_dma_config.dma_cfg.source_data_size = 2U;
406+
data->adc_dma_config.dma_cfg.dest_data_size = 2U;
395407
data->adc_dma_config.dma_block.source_address = (uint32_t)&base->R[0];
396408

397-
398409
if (data->dev_dma == NULL || !device_is_ready(data->dev_dma)) {
399410
LOG_ERR("dma binding fail");
400411
return -EINVAL;

0 commit comments

Comments
 (0)