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/incubator-nuttx.git

commit 239f0e257b589a54e6733b53609a07f032e9af68
Author: Abdelatif Guettouche <[email protected]>
AuthorDate: Mon Aug 2 11:13:10 2021 +0200

    arch/xtensa/esp32: Keep track to which CPU the interrupt was attached.
    This is used when dettaching.
    
    Signed-off-by: Abdelatif Guettouche <[email protected]>
---
 arch/xtensa/src/esp32/esp32_serial.c | 12 ++++++------
 arch/xtensa/src/esp32/esp32_wdt.c    | 12 ++++++------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_serial.c 
b/arch/xtensa/src/esp32/esp32_serial.c
index 6944627..6e178f2 100644
--- a/arch/xtensa/src/esp32/esp32_serial.c
+++ b/arch/xtensa/src/esp32/esp32_serial.c
@@ -227,6 +227,7 @@ struct esp32_dmadesc_s 
s_dma_txdesc[UART_DMA_CONTROLLERS_NUM]
 struct esp32_config_s
 {
   const uint8_t id;             /* UART id */
+  uint8_t  cpu;                 /* CPU ID */
   uint8_t  periph;              /* UART peripheral ID */
   uint8_t  irq;                 /* IRQ number assigned to the peripheral */
   uint8_t  txpin;               /* Tx pin number (0-39) */
@@ -1010,7 +1011,6 @@ static void esp32_shutdown(struct uart_dev_s *dev)
 static int esp32_attach(struct uart_dev_s *dev)
 {
   struct esp32_dev_s *priv = (struct esp32_dev_s *)dev->priv;
-  int cpu;
   int ret = OK;
 
   /* Allocate a level-sensitive, priority 1 CPU interrupt for the UART */
@@ -1025,12 +1025,13 @@ static int esp32_attach(struct uart_dev_s *dev)
 
   /* Set up to receive peripheral interrupts on the current CPU */
 
-  cpu = up_cpu_index();
+  priv->config->cpu = up_cpu_index();
 
   /* Attach the GPIO peripheral to the allocated CPU interrupt */
 
   up_disable_irq(priv->cpuint);
-  esp32_attach_peripheral(cpu, priv->config->periph, priv->cpuint);
+  esp32_attach_peripheral(priv->config->cpu, priv->config->periph,
+                          priv->cpuint);
 
   /* Attach and enable the IRQ */
 
@@ -1060,7 +1061,6 @@ static int esp32_attach(struct uart_dev_s *dev)
 static void esp32_detach(struct uart_dev_s *dev)
 {
   struct esp32_dev_s *priv = (struct esp32_dev_s *)dev->priv;
-  int cpu;
 
   /* Disable and detach the CPU interrupt */
 
@@ -1069,8 +1069,8 @@ static void esp32_detach(struct uart_dev_s *dev)
 
   /* Disassociate the peripheral interrupt from the CPU interrupt */
 
-  cpu = up_cpu_index();
-  esp32_detach_peripheral(cpu, priv->config->periph, priv->cpuint);
+  esp32_detach_peripheral(priv->config->cpu, priv->config->periph,
+                          priv->cpuint);
 
   /* And release the CPU interrupt */
 
diff --git a/arch/xtensa/src/esp32/esp32_wdt.c 
b/arch/xtensa/src/esp32/esp32_wdt.c
index ccdc493..9be3f85 100644
--- a/arch/xtensa/src/esp32/esp32_wdt.c
+++ b/arch/xtensa/src/esp32/esp32_wdt.c
@@ -51,6 +51,7 @@ struct esp32_wdt_priv_s
   {
     FAR struct esp32_wdt_ops_s *ops;
     uint32_t                    base;    /* WDT register base address */
+    uint8_t                     cpu;     /* CPU ID */
     uint8_t                     periph;  /* Peripheral ID */
     uint8_t                     irq;     /* Interrupt ID */
     int                         cpuint;  /* CPU interrupt assigned to this wdt 
*/
@@ -696,7 +697,6 @@ static int esp32_wdt_setisr(FAR struct esp32_wdt_dev_s 
*dev, xcpt_t handler,
 {
   FAR struct esp32_wdt_priv_s *wdt = NULL;
   int ret = OK;
-  uint8_t cpu;
 
   DEBUGASSERT(dev);
 
@@ -715,8 +715,7 @@ static int esp32_wdt_setisr(FAR struct esp32_wdt_dev_s 
*dev, xcpt_t handler,
            */
 
           up_disable_irq(wdt->cpuint);
-          cpu = up_cpu_index();
-          esp32_detach_peripheral(cpu, wdt->periph, wdt->cpuint);
+          esp32_detach_peripheral(wdt->cpu, wdt->periph, wdt->cpuint);
           esp32_free_cpuint(wdt->cpuint);
           irq_detach(wdt->irq);
         }
@@ -739,6 +738,8 @@ static int esp32_wdt_setisr(FAR struct esp32_wdt_dev_s 
*dev, xcpt_t handler,
           goto errout;
         }
 
+      wdt->cpu = up_cpu_index();
+
       /* Disable the provided CPU Interrupt to configure it */
 
       up_disable_irq(wdt->cpuint);
@@ -747,8 +748,7 @@ static int esp32_wdt_setisr(FAR struct esp32_wdt_dev_s 
*dev, xcpt_t handler,
        * the current core
        */
 
-      cpu = up_cpu_index();
-      esp32_attach_peripheral(cpu, wdt->periph, wdt->cpuint);
+      esp32_attach_peripheral(wdt->cpu, wdt->periph, wdt->cpuint);
 
       /* Associate an IRQ Number (from the WDT) to an ISR */
 
@@ -756,7 +756,7 @@ static int esp32_wdt_setisr(FAR struct esp32_wdt_dev_s 
*dev, xcpt_t handler,
 
       if (ret != OK)
         {
-          esp32_detach_peripheral(cpu, wdt->periph, wdt->cpuint);
+          esp32_detach_peripheral(wdt->cpu, wdt->periph, wdt->cpuint);
           esp32_free_cpuint(wdt->cpuint);
           tmrerr("ERROR: Failed to associate an IRQ Number");
           goto errout;

Reply via email to