This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 162369111e29a8bbcf48f24c74fd674f35355b37 Author: Ahmed Ashraf NourEldeen <[email protected]> AuthorDate: Mon Sep 21 15:55:00 2026 +0300 arch/risc-v/espressif: Add IRQ lookup by interrupt handle. Add esp_get_irq() to retrieve the IRQ associated with an interrupt handle. This allows the ESP OS abstraction to recover the IRQ when freeing an interrupt from its handle. The corresponding change in esp-hal-3rdparty is required to use this API when freeing interrupts. Related: #20216 Signed-off-by: Ahmed Ashraf NourEldeen <[email protected]> --- arch/risc-v/src/common/espressif/esp_irq.c | 39 +++++++++++++++++++++++++++++- arch/risc-v/src/common/espressif/esp_irq.h | 18 ++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/arch/risc-v/src/common/espressif/esp_irq.c b/arch/risc-v/src/common/espressif/esp_irq.c index 991ac89e472..7ab783ebd64 100644 --- a/arch/risc-v/src/common/espressif/esp_irq.c +++ b/arch/risc-v/src/common/espressif/esp_irq.c @@ -494,7 +494,13 @@ int esp_setup_irq_with_flags_intrstatus(int source, * CPU information, so no additional mapping is needed. */ - esp_set_handle(this_cpu(), irq, ret_handle); + ret = esp_set_handle(this_cpu(), irq, ret_handle); + if (ret < 0) + { + esp_intr_free(ret_handle); + kmm_free(isr_adapter_args); + return ret; + } return cpuint; } @@ -691,6 +697,37 @@ intr_handle_t esp_get_handle(int cpu, int irq) return g_handle_map[cpu][irq]; } +/**************************************************************************** + * Name: esp_get_irq + * + * Description: + * This function gets the IRQ associated with a handle + * + * Input Parameters: + * cpu - The CPU associated with the IRQ + * handle - The handle associated with a CPU interrupt + * + * Returned Value: + * The irq associated with the handle or negative value if no irq is + * associated with the handle. + * + ****************************************************************************/ + +int esp_get_irq(int cpu, intr_handle_t handle) +{ + int irq; + + for (irq = 0; irq < NR_IRQS; irq++) + { + if (g_handle_map[cpu][irq] == handle) + { + return irq; + } + } + + return -EINVAL; +} + /**************************************************************************** * Name: esp_clear_handle * diff --git a/arch/risc-v/src/common/espressif/esp_irq.h b/arch/risc-v/src/common/espressif/esp_irq.h index 36b54d933ca..32180b2c7bb 100644 --- a/arch/risc-v/src/common/espressif/esp_irq.h +++ b/arch/risc-v/src/common/espressif/esp_irq.h @@ -253,6 +253,24 @@ int esp_set_handle(int cpu, int irq, intr_handle_t handle); intr_handle_t esp_get_handle(int cpu, int irq); +/**************************************************************************** + * Name: esp_get_irq + * + * Description: + * This function gets the IRQ associated with a handle + * + * Input Parameters: + * cpu - The CPU associated with the IRQ + * handle - The handle associated with a CPU interrupt + * + * Returned Value: + * The irq associated with the handle or negative value if no irq is + * associated with the handle. + * + ****************************************************************************/ + +int esp_get_irq(int cpu, intr_handle_t handle); + /**************************************************************************** * Name: esp_get_iram_interrupt_records *
