1
1
/*
2
- * Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
2
+ * Copyright (c) 2022-2025 Espressif Systems (Shanghai) Co., Ltd.
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
@@ -16,7 +16,6 @@ LOG_MODULE_REGISTER(dma_esp32_gdma, CONFIG_DMA_LOG_LEVEL);
16
16
17
17
#include <soc.h>
18
18
#include <esp_memory_utils.h>
19
- #include <soc/soc_memory_types.h>
20
19
#include <errno.h>
21
20
#include <zephyr/kernel.h>
22
21
#include <zephyr/drivers/dma.h>
@@ -52,10 +51,7 @@ struct dma_esp32_channel {
52
51
int periph_id ;
53
52
dma_callback_t cb ;
54
53
void * user_data ;
55
- dma_descriptor_t desc ;
56
- #if defined(CONFIG_SOC_SERIES_ESP32S3 )
57
- intr_handle_t * intr_handle ;
58
- #endif
54
+ dma_descriptor_t desc_list [CONFIG_DMA_ESP32_MAX_DESCRIPTOR_NUM ];
59
55
};
60
56
61
57
struct dma_esp32_config {
@@ -110,7 +106,7 @@ static void IRAM_ATTR dma_esp32_isr_handle_tx(const struct device *dev,
110
106
}
111
107
}
112
108
113
- #if ! defined(CONFIG_SOC_SERIES_ESP32C6 ) && !defined( CONFIG_SOC_SERIES_ESP32S3 )
109
+ #if defined(SOC_GDMA_TX_RX_SHARE_INTERRUPT )
114
110
static void IRAM_ATTR dma_esp32_isr_handle (const struct device * dev , uint8_t rx_id , uint8_t tx_id )
115
111
{
116
112
struct dma_esp32_config * config = (struct dma_esp32_config * )dev -> config ;
@@ -534,15 +530,35 @@ static int dma_esp32_reload(const struct device *dev, uint32_t channel, uint32_t
534
530
static int dma_esp32_configure_irq (const struct device * dev )
535
531
{
536
532
struct dma_esp32_config * config = (struct dma_esp32_config * )dev -> config ;
533
+ struct dma_esp32_data * data = (struct dma_esp32_data * )dev -> data ;
537
534
struct irq_config * irq_cfg = (struct irq_config * )config -> irq_config ;
535
+ volatile uint32_t * status_reg ;
536
+ uint32_t status_mask ;
538
537
539
538
for (uint8_t i = 0 ; i < config -> irq_size ; i ++ ) {
540
- int ret = esp_intr_alloc (irq_cfg [i ].irq_source ,
539
+ #if defined(SOC_GDMA_TX_RX_SHARE_INTERRUPT )
540
+ status_reg = gdma_ll_rx_get_interrupt_status_reg (data -> hal .dev , i );
541
+ status_mask = (GDMA_LL_RX_EVENT_MASK | GDMA_LL_TX_EVENT_MASK );
542
+ #else
543
+ /* We assume device tree to feature RX/TX pairs */
544
+ if (i % 2 ) {
545
+ status_reg = gdma_ll_tx_get_interrupt_status_reg (data -> hal .dev , i / 2 );
546
+ status_mask = GDMA_LL_TX_EVENT_MASK ;
547
+ } else {
548
+ status_reg = gdma_ll_rx_get_interrupt_status_reg (data -> hal .dev , i / 2 );
549
+ status_mask = GDMA_LL_RX_EVENT_MASK ;
550
+ }
551
+ #endif
552
+
553
+ int ret = esp_intr_alloc_intrstatus (irq_cfg [i ].irq_source ,
541
554
ESP_PRIO_TO_FLAGS (irq_cfg [i ].irq_priority ) |
542
555
ESP_INT_FLAGS_CHECK (irq_cfg [i ].irq_flags ) | ESP_INTR_FLAG_IRAM ,
556
+ (uint32_t )status_reg ,
557
+ status_mask ,
543
558
(intr_handler_t )config -> irq_handlers [i ],
544
559
(void * )dev ,
545
560
NULL );
561
+
546
562
if (ret != 0 ) {
547
563
LOG_ERR ("Could not allocate interrupt handler" );
548
564
return ret ;
@@ -598,7 +614,16 @@ static DEVICE_API(dma, dma_esp32_api) = {
598
614
.reload = dma_esp32_reload ,
599
615
};
600
616
601
- #if defined(CONFIG_SOC_SERIES_ESP32C6 ) || defined(CONFIG_SOC_SERIES_ESP32S3 )
617
+ #if defined(SOC_GDMA_TX_RX_SHARE_INTERRUPT )
618
+
619
+ #define DMA_ESP32_DEFINE_IRQ_HANDLER (channel ) \
620
+ __attribute__((unused)) static void IRAM_ATTR dma_esp32_isr_##channel( \
621
+ const struct device *dev) \
622
+ { \
623
+ dma_esp32_isr_handle(dev, channel * 2, channel * 2 + 1); \
624
+ }
625
+
626
+ #else
602
627
603
628
#define DMA_ESP32_DEFINE_IRQ_HANDLER (channel ) \
604
629
__attribute__((unused)) static void IRAM_ATTR dma_esp32_isr_##channel##_rx( \
@@ -625,21 +650,12 @@ static DEVICE_API(dma, dma_esp32_api) = {
625
650
} \
626
651
}
627
652
628
- #else
629
-
630
- #define DMA_ESP32_DEFINE_IRQ_HANDLER (channel ) \
631
- __attribute__((unused)) static void IRAM_ATTR dma_esp32_isr_##channel( \
632
- const struct device *dev) \
633
- { \
634
- dma_esp32_isr_handle(dev, channel * 2, channel * 2 + 1); \
635
- }
636
-
637
653
#endif
638
654
639
- #if defined(CONFIG_SOC_SERIES_ESP32C6 ) || defined(CONFIG_SOC_SERIES_ESP32S3 )
640
- #define ESP32_DMA_HANDLER (channel ) dma_esp32_isr_##channel##_rx, dma_esp32_isr_##channel##_tx
641
- #else
655
+ #if defined(SOC_GDMA_TX_RX_SHARE_INTERRUPT )
642
656
#define ESP32_DMA_HANDLER (channel ) dma_esp32_isr_##channel
657
+ #else
658
+ #define ESP32_DMA_HANDLER (channel ) dma_esp32_isr_##channel##_rx, dma_esp32_isr_##channel##_tx
643
659
#endif
644
660
645
661
DMA_ESP32_DEFINE_IRQ_HANDLER (0 )
@@ -687,6 +703,6 @@ static void *irq_handlers[] = {
687
703
}; \
688
704
\
689
705
DEVICE_DT_INST_DEFINE(idx, &dma_esp32_init, NULL, &dma_data_##idx, &dma_config_##idx, \
690
- PRE_KERNEL_1 , CONFIG_DMA_INIT_PRIORITY, &dma_esp32_api);
706
+ PRE_KERNEL_2 , CONFIG_DMA_INIT_PRIORITY, &dma_esp32_api);
691
707
692
708
DT_INST_FOREACH_STATUS_OKAY (DMA_ESP32_INIT )
0 commit comments