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 af65d2e04a211ccc85e185148e3e30a623447e36
Author: Ahmed Ashraf NourEldeen <[email protected]>
AuthorDate: Tue Sep 22 07:38:39 2026 +0300

    arch/xtensa/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/xtensa/src/common/espressif/esp_irq.c | 39 +++++++++++++++++++++++++++++-
 arch/xtensa/src/common/espressif/esp_irq.h | 18 ++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/arch/xtensa/src/common/espressif/esp_irq.c 
b/arch/xtensa/src/common/espressif/esp_irq.c
index b5c525ebef4..68f4ddb1c68 100644
--- a/arch/xtensa/src/common/espressif/esp_irq.c
+++ b/arch/xtensa/src/common/espressif/esp_irq.c
@@ -788,7 +788,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;
 }
@@ -888,6 +894,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/xtensa/src/common/espressif/esp_irq.h 
b/arch/xtensa/src/common/espressif/esp_irq.h
index 5197d68d73b..aafa2d0bb7b 100644
--- a/arch/xtensa/src/common/espressif/esp_irq.h
+++ b/arch/xtensa/src/common/espressif/esp_irq.h
@@ -231,6 +231,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_cpuint_initialize
  *

Reply via email to