This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit fd4914b9535765f7cf1c98f6f59fc229ec330f4d Author: Eren Terzioglu <eren.terzio...@espressif.com> AuthorDate: Wed Feb 26 14:13:41 2025 +0100 arch/xtensa/esp32[s3]: Add more dma functions Add dma function to use peripheral more efficiently Signed-off-by: Eren Terzioglu <eren.terzio...@espressif.com> --- arch/xtensa/src/esp32s3/esp32s3_dma.c | 156 ++++++++++++++++++++++++++++++++++ arch/xtensa/src/esp32s3/esp32s3_dma.h | 88 +++++++++++++++++++ arch/xtensa/src/esp32s3/hal.mk | 1 + 3 files changed, 245 insertions(+) diff --git a/arch/xtensa/src/esp32s3/esp32s3_dma.c b/arch/xtensa/src/esp32s3/esp32s3_dma.c index af988665fc..7bf8e35607 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_dma.c +++ b/arch/xtensa/src/esp32s3/esp32s3_dma.c @@ -45,6 +45,13 @@ #include "hardware/esp32s3_soc.h" #include "hardware/esp32s3_system.h" +#include "soc/gdma_periph.h" +#include "hal/gdma_hal.h" +#include "hal/gdma_types.h" +#include "hal/gdma_ll.h" +#include "periph_ctrl.h" +#include "hal/dma_types.h" + /**************************************************************************** * Pre-processor Macros ****************************************************************************/ @@ -58,6 +65,7 @@ static bool g_dma_chan_used[ESP32S3_DMA_CHAN_MAX]; static mutex_t g_dma_lock = NXMUTEX_INITIALIZER; +static gdma_hal_context_t ctx; /**************************************************************************** * Public Functions @@ -387,6 +395,152 @@ void esp32s3_dma_load(struct esp32s3_dmadesc_s *dmadesc, int chan, bool tx) } } +/**************************************************************************** + * Name: esp32s3_dma_reset_channel + * + * Description: + * Resets dma channel. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32s3_dma_reset_channel(int chan, bool tx) +{ + if (tx) + { + gdma_ll_tx_reset_channel(ctx.dev, chan); + } + else + { + gdma_ll_rx_reset_channel(ctx.dev, chan); + } +} + +/**************************************************************************** + * Name: esp32s3_dma_enable_interrupt + * + * Description: + * Enable/Disable DMA interrupt. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * mask - Interrupt mask to change + * en - true: enable; false: disable + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32s3_dma_enable_interrupt(int chan, bool tx, uint32_t mask, bool en) +{ + if (tx) + { + gdma_ll_tx_enable_interrupt(ctx.dev, chan, mask, en); + } + else + { + gdma_ll_rx_enable_interrupt(ctx.dev, chan, mask, en); + } +} + +/**************************************************************************** + * Name: esp32s3_dma_get_interrupt + * + * Description: + * Gets DMA interrupt status. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * + * Returned Value: + * Interrupt status value. + * + ****************************************************************************/ + +int esp32s3_dma_get_interrupt(int chan, bool tx) +{ + uint32_t intr_status = 0; + + if (tx) + { + intr_status = gdma_ll_tx_get_interrupt_status(ctx.dev, chan); + } + else + { + intr_status = gdma_ll_rx_get_interrupt_status(ctx.dev, chan); + } + + return intr_status; +} + +/**************************************************************************** + * Name: esp32s3_dma_clear_interrupt + * + * Description: + * Clear DMA interrupt. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * mask - Interrupt mask to change + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32s3_dma_clear_interrupt(int chan, bool tx, uint32_t mask) +{ + if (tx) + { + gdma_ll_tx_clear_interrupt_status(ctx.dev, chan, mask); + } + else + { + gdma_ll_rx_clear_interrupt_status(ctx.dev, chan, mask); + } +} + +/**************************************************************************** + * Name: esp32s3_dma_get_desc_addr + * + * Description: + * Gets desc addr of DMA interrupt. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * + * Returned Value: + * Desc addr. + * + ****************************************************************************/ + +int esp32s3_dma_get_desc_addr(int chan, bool tx) +{ + uint32_t desc_addr = 0; + + if (tx) + { + desc_addr = gdma_ll_tx_get_eof_desc_addr(ctx.dev, chan); + } + else + { + desc_addr = gdma_ll_rx_get_success_eof_desc_addr(ctx.dev, chan); + } + + return desc_addr; +} + /**************************************************************************** * Name: esp32s3_dma_enable * @@ -540,6 +694,8 @@ void esp32s3_dma_init(void) modifyreg32(SYSTEM_PERIP_CLK_EN1_REG, 0, SYSTEM_DMA_CLK_EN_M); modifyreg32(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST_M, 0); + gdma_hal_init(&ctx, 0); + /* enable DMA clock gating */ modifyreg32(DMA_MISC_CONF_REG, 0, DMA_CLK_EN_M); diff --git a/arch/xtensa/src/esp32s3/esp32s3_dma.h b/arch/xtensa/src/esp32s3/esp32s3_dma.h index 74e28e0649..7f66d294aa 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_dma.h +++ b/arch/xtensa/src/esp32s3/esp32s3_dma.h @@ -207,6 +207,94 @@ uint32_t esp32s3_dma_setup(struct esp32s3_dmadesc_s *dmadesc, uint32_t num, void esp32s3_dma_load(struct esp32s3_dmadesc_s *dmadesc, int chan, bool tx); +/**************************************************************************** + * Name: esp32s3_dma_reset_channel + * + * Description: + * Resets dma channel. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32s3_dma_reset_channel(int chan, bool tx); + +/**************************************************************************** + * Name: esp32s3_dma_enable_interrupt + * + * Description: + * Enable/Disable DMA interrupt. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * mask - Interrupt mask to change + * en - true: enable; false: disable + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32s3_dma_enable_interrupt(int chan, bool tx, uint32_t mask, bool en); + +/**************************************************************************** + * Name: esp32s3_dma_get_interrupt + * + * Description: + * Gets DMA interrupt status. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * + * Returned Value: + * Interrupt status value. + * + ****************************************************************************/ + +int esp32s3_dma_get_interrupt(int chan, bool tx); + +/**************************************************************************** + * Name: esp32s3_dma_clear_interrupt + * + * Description: + * Clear DMA interrupt. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * mask - Interrupt mask to change + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32s3_dma_clear_interrupt(int chan, bool tx, uint32_t mask); + +/**************************************************************************** + * Name: esp32s3_dma_get_desc_addr + * + * Description: + * Gets desc addr of DMA interrupt. + * + * Input Parameters: + * chan - DMA channel + * tx - true: TX mode; false: RX mode + * + * Returned Value: + * Desc addr. + * + ****************************************************************************/ + +int esp32s3_dma_get_desc_addr(int chan, bool tx); + /**************************************************************************** * Name: esp32s3_dma_enable * diff --git a/arch/xtensa/src/esp32s3/hal.mk b/arch/xtensa/src/esp32s3/hal.mk index b7d441d6ce..8bd319f4c9 100644 --- a/arch/xtensa/src/esp32s3/hal.mk +++ b/arch/xtensa/src/esp32s3/hal.mk @@ -110,6 +110,7 @@ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)$(CHIP_SERIES)$(DELIM)efuse_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)brownout_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)efuse_hal.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)gdma_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)gpio_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)ledc_hal_iram.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)ledc_hal.c