Skip to content

Commit f4802dd

Browse files
Raffael RostagnoMaureenHelm
authored andcommitted
gdma: esp32: Modulate interrupts with low level calls
Use LL calls to enable/disable interrupts rather than make calls to the interrupt controller. Signed-off-by: Raffael Rostagno <[email protected]>
1 parent 1b72ec0 commit f4802dd

File tree

1 file changed

+20
-94
lines changed

1 file changed

+20
-94
lines changed

drivers/dma/dma_esp32_gdma.c

Lines changed: 20 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ struct dma_esp32_channel {
6060
dma_callback_t cb;
6161
void *user_data;
6262
dma_descriptor_t desc;
63-
#if defined(CONFIG_SOC_SERIES_ESP32S3)
64-
struct intr_handle_data_t *intr_handle;
65-
#endif
6663
};
6764

6865
struct dma_esp32_config {
@@ -108,7 +105,7 @@ static void IRAM_ATTR dma_esp32_isr_handle_tx(const struct device *dev,
108105
}
109106
}
110107

111-
#if !defined(CONFIG_SOC_SERIES_ESP32C6)
108+
#if !defined(CONFIG_SOC_SERIES_ESP32C6) && !defined(CONFIG_SOC_SERIES_ESP32S3)
112109
static void IRAM_ATTR dma_esp32_isr_handle(const struct device *dev, uint8_t rx_id, uint8_t tx_id)
113110
{
114111
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
@@ -129,54 +126,6 @@ static void IRAM_ATTR dma_esp32_isr_handle(const struct device *dev, uint8_t rx_
129126
}
130127
#endif
131128

132-
#if defined(CONFIG_SOC_SERIES_ESP32C3)
133-
static int dma_esp32_enable_interrupt(const struct device *dev,
134-
struct dma_esp32_channel *dma_channel)
135-
{
136-
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
137-
138-
return esp_intr_enable(config->irq_src[dma_channel->channel_id]);
139-
}
140-
141-
static int dma_esp32_disable_interrupt(const struct device *dev,
142-
struct dma_esp32_channel *dma_channel)
143-
{
144-
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
145-
146-
return esp_intr_disable(config->irq_src[dma_channel->channel_id]);
147-
}
148-
#elif defined(CONFIG_SOC_SERIES_ESP32C6)
149-
static int dma_esp32_enable_interrupt(const struct device *dev, uint32_t channel)
150-
{
151-
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
152-
153-
return esp_intr_enable(config->irq_src[channel]);
154-
}
155-
156-
static int dma_esp32_disable_interrupt(const struct device *dev, uint32_t channel)
157-
{
158-
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
159-
160-
return esp_intr_disable(config->irq_src[channel]);
161-
}
162-
#else
163-
static int dma_esp32_enable_interrupt(const struct device *dev,
164-
struct dma_esp32_channel *dma_channel)
165-
{
166-
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
167-
168-
return esp_intr_enable(dma_channel->intr_handle);
169-
}
170-
171-
static int dma_esp32_disable_interrupt(const struct device *dev,
172-
struct dma_esp32_channel *dma_channel)
173-
{
174-
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
175-
176-
return esp_intr_disable(dma_channel->intr_handle);
177-
}
178-
179-
#endif
180129
static int dma_esp32_config_rx_descriptor(struct dma_esp32_channel *dma_channel,
181130
struct dma_block_config *block)
182131
{
@@ -359,20 +308,17 @@ static int dma_esp32_start(const struct device *dev, uint32_t channel)
359308
return -EINVAL;
360309
}
361310

362-
#if defined(CONFIG_SOC_SERIES_ESP32C6)
363-
if (dma_esp32_enable_interrupt(dev, channel)) {
364-
#else
365-
if (dma_esp32_enable_interrupt(dev, dma_channel)) {
366-
#endif
367-
return -EINVAL;
368-
}
369-
370311
if (dma_channel->periph_id == SOC_GDMA_TRIG_PERIPH_M2M0) {
371312
struct dma_esp32_channel *dma_channel_rx =
372313
&config->dma_channel[dma_channel->channel_id * 2];
373314
struct dma_esp32_channel *dma_channel_tx =
374315
&config->dma_channel[(dma_channel->channel_id * 2) + 1];
375316

317+
gdma_ll_rx_enable_interrupt(data->hal.dev, dma_channel->channel_id,
318+
UINT32_MAX, true);
319+
gdma_ll_tx_enable_interrupt(data->hal.dev, dma_channel->channel_id,
320+
GDMA_LL_EVENT_TX_EOF, true);
321+
376322
gdma_ll_rx_set_desc_addr(data->hal.dev, dma_channel->channel_id,
377323
(int32_t)&dma_channel_rx->desc);
378324
gdma_ll_rx_start(data->hal.dev, dma_channel->channel_id);
@@ -382,10 +328,14 @@ static int dma_esp32_start(const struct device *dev, uint32_t channel)
382328
gdma_ll_tx_start(data->hal.dev, dma_channel->channel_id);
383329
} else {
384330
if (dma_channel->dir == DMA_RX) {
331+
gdma_ll_rx_enable_interrupt(data->hal.dev, dma_channel->channel_id,
332+
UINT32_MAX, true);
385333
gdma_ll_rx_set_desc_addr(data->hal.dev, dma_channel->channel_id,
386334
(int32_t)&dma_channel->desc);
387335
gdma_ll_rx_start(data->hal.dev, dma_channel->channel_id);
388336
} else if (dma_channel->dir == DMA_TX) {
337+
gdma_ll_tx_enable_interrupt(data->hal.dev, dma_channel->channel_id,
338+
GDMA_LL_EVENT_TX_EOF, true);
389339
gdma_ll_tx_set_desc_addr(data->hal.dev, dma_channel->channel_id,
390340
(int32_t)&dma_channel->desc);
391341
gdma_ll_tx_start(data->hal.dev, dma_channel->channel_id);
@@ -409,22 +359,22 @@ static int dma_esp32_stop(const struct device *dev, uint32_t channel)
409359
return -EINVAL;
410360
}
411361

412-
#if defined(CONFIG_SOC_SERIES_ESP32C6)
413-
if (dma_esp32_disable_interrupt(dev, channel)) {
414-
#else
415-
if (dma_esp32_disable_interrupt(dev, dma_channel)) {
416-
#endif
417-
return -EINVAL;
418-
}
419-
420362
if (dma_channel->periph_id == SOC_GDMA_TRIG_PERIPH_M2M0) {
363+
gdma_ll_rx_enable_interrupt(data->hal.dev, dma_channel->channel_id,
364+
UINT32_MAX, false);
365+
gdma_ll_tx_enable_interrupt(data->hal.dev, dma_channel->channel_id,
366+
GDMA_LL_EVENT_TX_EOF, false);
421367
gdma_ll_rx_stop(data->hal.dev, dma_channel->channel_id);
422368
gdma_ll_tx_stop(data->hal.dev, dma_channel->channel_id);
423369
}
424370

425371
if (dma_channel->dir == DMA_RX) {
372+
gdma_ll_rx_enable_interrupt(data->hal.dev, dma_channel->channel_id,
373+
UINT32_MAX, false);
426374
gdma_ll_rx_stop(data->hal.dev, dma_channel->channel_id);
427375
} else if (dma_channel->dir == DMA_TX) {
376+
gdma_ll_tx_enable_interrupt(data->hal.dev, dma_channel->channel_id,
377+
GDMA_LL_EVENT_TX_EOF, false);
428378
gdma_ll_tx_stop(data->hal.dev, dma_channel->channel_id);
429379
}
430380

@@ -499,7 +449,6 @@ static int dma_esp32_reload(const struct device *dev, uint32_t channel, uint32_t
499449
return 0;
500450
}
501451

502-
#if defined(CONFIG_SOC_SERIES_ESP32C3) || defined(CONFIG_SOC_SERIES_ESP32C6)
503452
static int dma_esp32_configure_irq(const struct device *dev)
504453
{
505454
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
@@ -518,30 +467,7 @@ static int dma_esp32_configure_irq(const struct device *dev)
518467

519468
return 0;
520469
}
521-
#else
522-
static int dma_esp32_configure_irq(const struct device *dev)
523-
{
524-
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
525-
struct dma_esp32_data *data = (struct dma_esp32_data *)dev->data;
526-
struct dma_esp32_channel *dma_channel;
527-
528-
for (uint8_t i = 0; i < config->irq_size; i++) {
529-
dma_channel = &config->dma_channel[i];
530-
int ret = esp_intr_alloc(config->irq_src[i],
531-
0,
532-
(ISR_HANDLER)config->irq_handlers[i / 2],
533-
(void *)dev,
534-
&dma_channel->intr_handle);
535-
if (ret != 0) {
536-
LOG_ERR("Could not allocate interrupt handler");
537-
return ret;
538-
}
539-
}
540-
541-
return 0;
542-
}
543470

544-
#endif
545471
static int dma_esp32_init(const struct device *dev)
546472
{
547473
struct dma_esp32_config *config = (struct dma_esp32_config *)dev->config;
@@ -588,7 +514,7 @@ static const struct dma_driver_api dma_esp32_api = {
588514
.reload = dma_esp32_reload,
589515
};
590516

591-
#if defined(CONFIG_SOC_SERIES_ESP32C6)
517+
#if defined(CONFIG_SOC_SERIES_ESP32C6) || defined(CONFIG_SOC_SERIES_ESP32S3)
592518

593519
#define DMA_ESP32_DEFINE_IRQ_HANDLER(channel) \
594520
__attribute__((unused)) static void IRAM_ATTR dma_esp32_isr_##channel##_rx( \
@@ -626,7 +552,7 @@ static const struct dma_driver_api dma_esp32_api = {
626552

627553
#endif
628554

629-
#if defined(CONFIG_SOC_SERIES_ESP32C6)
555+
#if defined(CONFIG_SOC_SERIES_ESP32C6) || defined(CONFIG_SOC_SERIES_ESP32S3)
630556
#define ESP32_DMA_HANDLER(channel) dma_esp32_isr_##channel##_rx, dma_esp32_isr_##channel##_tx
631557
#else
632558
#define ESP32_DMA_HANDLER(channel) dma_esp32_isr_##channel

0 commit comments

Comments
 (0)