You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/08/04 02:52:20 UTC

[incubator-nuttx] branch master updated (5588bc4 -> 238a96e)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from 5588bc4  mtd/ramtron.c: Reassert CS between commands
     new 3e44c34  arch/xtensa/esp32_spi&i2c: Get the CPU index when attaching an interrupt.
     new 0ca5fb4  arch/xtensa/esp32: When calling up_cpu_index no need to check if in SMP mode.  up_cpu_index already does that.
     new 239f0e2  arch/xtensa/esp32: Keep track to which CPU the interrupt was attached. This is used when dettaching.
     new 4f2f2ef  arch/xtensa: Get the cpu member out of the read only structure.
     new 238a96e  arch/esp32_cpuint.c: Simplify up_disable/enable_irq.

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/xtensa/src/esp32/esp32_cpuint.c    | 18 ++----------------
 arch/xtensa/src/esp32/esp32_gpio.c      |  4 ----
 arch/xtensa/src/esp32/esp32_i2c.c       | 18 ++++++++----------
 arch/xtensa/src/esp32/esp32_serial.c    | 25 ++++++-------------------
 arch/xtensa/src/esp32/esp32_spi.c       | 13 +++++++------
 arch/xtensa/src/esp32/esp32_spi_slave.c | 13 +++++++------
 arch/xtensa/src/esp32/esp32_wdt.c       | 12 ++++++------
 7 files changed, 36 insertions(+), 67 deletions(-)

[incubator-nuttx] 01/05: arch/xtensa/esp32_spi&i2c: Get the CPU index when attaching an interrupt.

Posted by xi...@apache.org.
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 3e44c347fdf72ae4257e9adb0c58b796274c4b41
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Mon Aug 2 10:37:30 2021 +0200

    arch/xtensa/esp32_spi&i2c: Get the CPU index when attaching an
    interrupt.
    
    Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
 arch/xtensa/src/esp32/esp32_i2c.c       | 3 +++
 arch/xtensa/src/esp32/esp32_spi.c       | 3 +++
 arch/xtensa/src/esp32/esp32_spi_slave.c | 3 +++
 3 files changed, 9 insertions(+)

diff --git a/arch/xtensa/src/esp32/esp32_i2c.c b/arch/xtensa/src/esp32/esp32_i2c.c
index 28ecac7..3eba107 100644
--- a/arch/xtensa/src/esp32/esp32_i2c.c
+++ b/arch/xtensa/src/esp32/esp32_i2c.c
@@ -1569,6 +1569,9 @@ FAR struct i2c_master_s *esp32_i2cbus_initialize(int port)
       return NULL;
     }
 
+  /* Set up to receive peripheral interrupts on the current CPU */
+
+  config->cpu = up_cpu_index();
   up_disable_irq(priv->cpuint);
   esp32_attach_peripheral(config->cpu, config->periph, priv->cpuint);
 
diff --git a/arch/xtensa/src/esp32/esp32_spi.c b/arch/xtensa/src/esp32/esp32_spi.c
index 0175c01..12d746d 100644
--- a/arch/xtensa/src/esp32/esp32_spi.c
+++ b/arch/xtensa/src/esp32/esp32_spi.c
@@ -1473,6 +1473,9 @@ FAR struct spi_dev_s *esp32_spibus_initialize(int port)
           return NULL;
         }
 
+      /* Set up to receive peripheral interrupts on the current CPU */
+
+      priv->config->cpu = up_cpu_index();
       up_disable_irq(priv->cpuint);
       esp32_attach_peripheral(priv->config->cpu,
                               priv->config->periph,
diff --git a/arch/xtensa/src/esp32/esp32_spi_slave.c b/arch/xtensa/src/esp32/esp32_spi_slave.c
index e16b645..0d13bec 100644
--- a/arch/xtensa/src/esp32/esp32_spi_slave.c
+++ b/arch/xtensa/src/esp32/esp32_spi_slave.c
@@ -1306,6 +1306,9 @@ FAR struct spi_slave_ctrlr_s *esp32_spislv_ctrlr_initialize(int port)
       return NULL;
     }
 
+  /* Set up to receive peripheral interrupts on the current CPU */
+
+  priv->config->cpu = up_cpu_index();
   up_disable_irq(priv->cpuint);
   esp32_attach_peripheral(priv->config->cpu,
                           priv->config->periph,

[incubator-nuttx] 05/05: arch/esp32_cpuint.c: Simplify up_disable/enable_irq.

Posted by xi...@apache.org.
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 238a96e7de402c9691c91346f931e26859dc027c
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Tue Aug 3 14:13:15 2021 +0200

    arch/esp32_cpuint.c: Simplify up_disable/enable_irq.
    
    Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
 arch/xtensa/src/esp32/esp32_cpuint.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_cpuint.c b/arch/xtensa/src/esp32/esp32_cpuint.c
index b7c941c..515ac47 100644
--- a/arch/xtensa/src/esp32/esp32_cpuint.c
+++ b/arch/xtensa/src/esp32/esp32_cpuint.c
@@ -399,18 +399,11 @@ int esp32_cpuint_initialize(void)
 
 void up_disable_irq(int cpuint)
 {
-#ifdef CONFIG_SMP
-  int cpu;
-#endif
+  int cpu = up_cpu_index();
 
   DEBUGASSERT(cpuint >= 0 && cpuint <= ESP32_CPUINT_MAX);
 
-#ifdef CONFIG_SMP
-  cpu = up_cpu_index();
   xtensa_disable_cpuint(&g_intenable[cpu], (1ul << cpuint));
-#else
-  xtensa_disable_cpuint(&g_intenable[0], (1ul << cpuint));
-#endif
 }
 
 /****************************************************************************
@@ -423,18 +416,11 @@ void up_disable_irq(int cpuint)
 
 void up_enable_irq(int cpuint)
 {
-#ifdef CONFIG_SMP
-  int cpu;
-#endif
+  int cpu = up_cpu_index();
 
   DEBUGASSERT(cpuint >= 0 && cpuint <= ESP32_CPUINT_MAX);
 
-#ifdef CONFIG_SMP
-  cpu = up_cpu_index();
   xtensa_enable_cpuint(&g_intenable[cpu], (1ul << cpuint));
-#else
-  xtensa_enable_cpuint(&g_intenable[0], (1ul << cpuint));
-#endif
 }
 
 /****************************************************************************

[incubator-nuttx] 04/05: arch/xtensa: Get the cpu member out of the read only structure.

Posted by xi...@apache.org.
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 4f2f2ef9fbfcef769a8d80131953c241310693e5
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Mon Aug 2 11:45:15 2021 +0200

    arch/xtensa: Get the cpu member out of the read only structure.
    
    Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
 arch/xtensa/src/esp32/esp32_i2c.c       | 17 ++++++-----------
 arch/xtensa/src/esp32/esp32_serial.c    |  8 ++++----
 arch/xtensa/src/esp32/esp32_spi.c       | 12 +++++-------
 arch/xtensa/src/esp32/esp32_spi_slave.c | 12 +++++-------
 4 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_i2c.c b/arch/xtensa/src/esp32/esp32_i2c.c
index 3eba107..2e2e158 100644
--- a/arch/xtensa/src/esp32/esp32_i2c.c
+++ b/arch/xtensa/src/esp32/esp32_i2c.c
@@ -172,7 +172,6 @@ struct esp32_i2c_config_s
   uint8_t sda_pin;            /* GPIO configuration for SDA as SDA */
 
 #ifndef CONFIG_I2C_POLLED
-  uint8_t cpu;                /* CPU ID */
   uint8_t periph;             /* Peripheral ID */
   uint8_t irq;                /* Interrupt ID */
 #endif
@@ -201,6 +200,8 @@ struct esp32_i2c_priv_s
 
 #ifndef CONFIG_I2C_POLLED
   sem_t sem_isr;               /* Interrupt wait semaphore */
+  int     cpuint;              /* CPU interrupt assigned to this I2C */
+  uint8_t cpu;                 /* CPU ID */
 #endif
 
   /* I2C work state (see enum esp32_i2cstate_e) */
@@ -212,10 +213,6 @@ struct esp32_i2c_priv_s
   uint8_t msgid;               /* Current message ID */
   ssize_t bytes;               /* Processed data bytes */
 
-#ifndef CONFIG_I2C_POLLED
-  int     cpuint;              /* CPU interrupt assigned to this I2C */
-#endif
-
   uint32_t error;              /* I2C transform error */
 
   bool ready_read;             /* If I2C has read data */
@@ -289,7 +286,6 @@ static const struct esp32_i2c_config_s esp32_i2c0_config =
   .scl_pin    = CONFIG_ESP32_I2C0_SCLPIN,
   .sda_pin    = CONFIG_ESP32_I2C0_SDAPIN,
 #ifndef CONFIG_I2C_POLLED
-  .cpu        = 0,
   .periph     = ESP32_PERIPH_I2C_EXT0,
   .irq        = ESP32_IRQ_I2C_EXT0,
 #endif
@@ -322,7 +318,6 @@ static const struct esp32_i2c_config_s esp32_i2c1_config =
   .scl_pin    = CONFIG_ESP32_I2C1_SCLPIN,
   .sda_pin    = CONFIG_ESP32_I2C1_SDAPIN,
 #ifndef CONFIG_I2C_POLLED
-  .cpu        = 0,
   .periph     = ESP32_PERIPH_I2C_EXT1,
   .irq        = ESP32_IRQ_I2C_EXT1,
 #endif
@@ -1571,14 +1566,14 @@ FAR struct i2c_master_s *esp32_i2cbus_initialize(int port)
 
   /* Set up to receive peripheral interrupts on the current CPU */
 
-  config->cpu = up_cpu_index();
+  priv->cpu = up_cpu_index();
   up_disable_irq(priv->cpuint);
-  esp32_attach_peripheral(config->cpu, config->periph, priv->cpuint);
+  esp32_attach_peripheral(priv->cpu, config->periph, priv->cpuint);
 
   ret = irq_attach(config->irq, esp32_i2c_irq, priv);
   if (ret != OK)
     {
-      esp32_detach_peripheral(config->cpu, config->periph, priv->cpuint);
+      esp32_detach_peripheral(priv->cpu, config->periph, priv->cpuint);
       esp32_free_cpuint(priv->cpuint);
 
       leave_critical_section(flags);
@@ -1630,7 +1625,7 @@ int esp32_i2cbus_uninitialize(FAR struct i2c_master_s *dev)
 
 #ifndef CONFIG_I2C_POLLED
   up_disable_irq(priv->cpuint);
-  esp32_detach_peripheral(priv->config->cpu,
+  esp32_detach_peripheral(priv->cpu,
                           priv->config->periph,
                           priv->cpuint);
   esp32_free_cpuint(priv->cpuint);
diff --git a/arch/xtensa/src/esp32/esp32_serial.c b/arch/xtensa/src/esp32/esp32_serial.c
index 6e178f2..352aad2 100644
--- a/arch/xtensa/src/esp32/esp32_serial.c
+++ b/arch/xtensa/src/esp32/esp32_serial.c
@@ -227,7 +227,6 @@ 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) */
@@ -256,6 +255,7 @@ struct esp32_dev_s
   uint32_t baud;                       /* Configured baud */
   uint32_t status;                     /* Saved status bits */
   int      cpuint;                     /* CPU interrupt assigned to this UART */
+  uint8_t  cpu;                        /* CPU ID */
   uint8_t  parity;                     /* 0=none, 1=odd, 2=even */
   uint8_t  bits;                       /* Number of bits (5-9) */
   bool     stopbits2;                  /* true: Configure with 2 stop bits instead of 1 */
@@ -1025,12 +1025,12 @@ static int esp32_attach(struct uart_dev_s *dev)
 
   /* Set up to receive peripheral interrupts on the current CPU */
 
-  priv->config->cpu = up_cpu_index();
+  priv->cpu = up_cpu_index();
 
   /* Attach the GPIO peripheral to the allocated CPU interrupt */
 
   up_disable_irq(priv->cpuint);
-  esp32_attach_peripheral(priv->config->cpu, priv->config->periph,
+  esp32_attach_peripheral(priv->cpu, priv->config->periph,
                           priv->cpuint);
 
   /* Attach and enable the IRQ */
@@ -1069,7 +1069,7 @@ static void esp32_detach(struct uart_dev_s *dev)
 
   /* Disassociate the peripheral interrupt from the CPU interrupt */
 
-  esp32_detach_peripheral(priv->config->cpu, priv->config->periph,
+  esp32_detach_peripheral(priv->cpu, priv->config->periph,
                           priv->cpuint);
 
   /* And release the CPU interrupt */
diff --git a/arch/xtensa/src/esp32/esp32_spi.c b/arch/xtensa/src/esp32/esp32_spi.c
index 12d746d..5c9b8e0 100644
--- a/arch/xtensa/src/esp32/esp32_spi.c
+++ b/arch/xtensa/src/esp32/esp32_spi.c
@@ -109,7 +109,6 @@ struct esp32_spi_config_s
   uint8_t miso_pin;           /* GPIO configuration for MISO */
   uint8_t clk_pin;            /* GPIO configuration for CLK */
 
-  uint8_t cpu;                /* CPU ID */
   uint8_t periph;             /* peripher ID */
   uint8_t irq;                /* Interrupt ID */
 
@@ -153,6 +152,7 @@ struct esp32_spi_priv_s
   sem_t            sem_isr;
 
   int              cpuint;      /* SPI interrupt ID */
+  uint8_t          cpu;         /* CPU ID */
 
   uint32_t         frequency;   /* Requested clock frequency */
   uint32_t         actual;      /* Actual clock frequency */
@@ -214,7 +214,6 @@ static const struct esp32_spi_config_s esp32_spi2_config =
   .mosi_pin     = CONFIG_ESP32_SPI2_MOSIPIN,
   .miso_pin     = CONFIG_ESP32_SPI2_MISOPIN,
   .clk_pin      = CONFIG_ESP32_SPI2_CLKPIN,
-  .cpu          = 0,
   .periph       = ESP32_PERIPH_SPI2,
   .irq          = ESP32_IRQ_SPI2,
   .clk_bit      = DPORT_SPI_CLK_EN_2,
@@ -289,7 +288,6 @@ static const struct esp32_spi_config_s esp32_spi3_config =
   .mosi_pin     = CONFIG_ESP32_SPI3_MOSIPIN,
   .miso_pin     = CONFIG_ESP32_SPI3_MISOPIN,
   .clk_pin      = CONFIG_ESP32_SPI3_CLKPIN,
-  .cpu          = 0,
   .periph       = ESP32_PERIPH_SPI3,
   .irq          = ESP32_IRQ_SPI3,
   .clk_bit      = DPORT_SPI_CLK_EN,
@@ -1475,15 +1473,15 @@ FAR struct spi_dev_s *esp32_spibus_initialize(int port)
 
       /* Set up to receive peripheral interrupts on the current CPU */
 
-      priv->config->cpu = up_cpu_index();
+      priv->cpu = up_cpu_index();
       up_disable_irq(priv->cpuint);
-      esp32_attach_peripheral(priv->config->cpu,
+      esp32_attach_peripheral(priv->cpu,
                               priv->config->periph,
                               priv->cpuint);
       ret = irq_attach(priv->config->irq, esp32_spi_interrupt, priv);
       if (ret != OK)
         {
-          esp32_detach_peripheral(priv->config->cpu,
+          esp32_detach_peripheral(priv->cpu,
                                   priv->config->periph,
                                   priv->cpuint);
           esp32_free_cpuint(priv->cpuint);
@@ -1537,7 +1535,7 @@ int esp32_spibus_uninitialize(FAR struct spi_dev_s *dev)
   if (priv->config->use_dma)
     {
       up_disable_irq(priv->cpuint);
-      esp32_detach_peripheral(priv->config->cpu,
+      esp32_detach_peripheral(priv->cpu,
                               priv->config->periph,
                               priv->cpuint);
       esp32_free_cpuint(priv->cpuint);
diff --git a/arch/xtensa/src/esp32/esp32_spi_slave.c b/arch/xtensa/src/esp32/esp32_spi_slave.c
index 0d13bec..7764bc9 100644
--- a/arch/xtensa/src/esp32/esp32_spi_slave.c
+++ b/arch/xtensa/src/esp32/esp32_spi_slave.c
@@ -101,7 +101,6 @@ struct esp32_spislv_config_s
   uint8_t miso_pin;           /* GPIO configuration for MISO */
   uint8_t clk_pin;            /* GPIO configuration for CLK */
 
-  uint8_t cpu;                /* CPU ID */
   uint8_t periph;             /* peripher ID */
   uint8_t irq;                /* Interrupt ID */
 
@@ -136,6 +135,7 @@ struct esp32_spislv_priv_s
 
   const struct esp32_spislv_config_s *config; /* Port configuration */
 
+  uint8_t          cpu;         /* CPU ID */
   int              cpuint;      /* SPI interrupt ID */
 
   enum spi_mode_e  mode;        /* Actual SPI hardware mode */
@@ -200,7 +200,6 @@ static const struct esp32_spislv_config_s esp32_spi2_config =
   .mosi_pin     = CONFIG_ESP32_SPI2_MOSIPIN,
   .miso_pin     = CONFIG_ESP32_SPI2_MISOPIN,
   .clk_pin      = CONFIG_ESP32_SPI2_CLKPIN,
-  .cpu          = 0,
   .periph       = ESP32_PERIPH_SPI2,
   .irq          = ESP32_IRQ_SPI2,
   .clk_bit      = DPORT_SPI_CLK_EN_2,
@@ -254,7 +253,6 @@ static const struct esp32_spislv_config_s esp32_spi3_config =
   .mosi_pin     = CONFIG_ESP32_SPI3_MOSIPIN,
   .miso_pin     = CONFIG_ESP32_SPI3_MISOPIN,
   .clk_pin      = CONFIG_ESP32_SPI3_CLKPIN,
-  .cpu          = 0,
   .periph       = ESP32_PERIPH_SPI3,
   .irq          = ESP32_IRQ_SPI3,
   .clk_bit      = DPORT_SPI_CLK_EN,
@@ -1308,16 +1306,16 @@ FAR struct spi_slave_ctrlr_s *esp32_spislv_ctrlr_initialize(int port)
 
   /* Set up to receive peripheral interrupts on the current CPU */
 
-  priv->config->cpu = up_cpu_index();
+  priv->cpu = up_cpu_index();
   up_disable_irq(priv->cpuint);
-  esp32_attach_peripheral(priv->config->cpu,
+  esp32_attach_peripheral(priv->cpu,
                           priv->config->periph,
                           priv->cpuint);
 
   ret = irq_attach(priv->config->irq, esp32_spislv_interrupt, priv);
   if (ret != OK)
     {
-      esp32_detach_peripheral(priv->config->cpu,
+      esp32_detach_peripheral(priv->cpu,
                               priv->config->periph,
                               priv->cpuint);
       esp32_free_cpuint(priv->cpuint);
@@ -1369,7 +1367,7 @@ int esp32_spislv_ctrlr_uninitialize(FAR struct spi_slave_ctrlr_s *ctrlr)
     }
 
   up_disable_irq(priv->cpuint);
-  esp32_detach_peripheral(priv->config->cpu,
+  esp32_detach_peripheral(priv->cpu,
                           priv->config->periph,
                           priv->cpuint);
   esp32_free_cpuint(priv->cpuint);

[incubator-nuttx] 02/05: arch/xtensa/esp32: When calling up_cpu_index no need to check if in SMP mode. up_cpu_index already does that.

Posted by xi...@apache.org.
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 0ca5fb4edcf88718aa87ccd1e956f3ac80d48c97
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Mon Aug 2 10:57:37 2021 +0200

    arch/xtensa/esp32: When calling up_cpu_index no need to check if in SMP
    mode.  up_cpu_index already does that.
    
    Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
 arch/xtensa/src/esp32/esp32_gpio.c   |  4 ----
 arch/xtensa/src/esp32/esp32_serial.c | 13 -------------
 2 files changed, 17 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_gpio.c b/arch/xtensa/src/esp32/esp32_gpio.c
index a429b23..8f89c96 100644
--- a/arch/xtensa/src/esp32/esp32_gpio.c
+++ b/arch/xtensa/src/esp32/esp32_gpio.c
@@ -417,11 +417,7 @@ void esp32_gpioirqinitialize(void)
 
   /* Set up to receive peripheral interrupts on the current CPU */
 
-#ifdef CONFIG_SMP
   cpu = up_cpu_index();
-#else
-  cpu = 0;
-#endif
 
   /* Attach the GPIO peripheral to the allocated CPU interrupt */
 
diff --git a/arch/xtensa/src/esp32/esp32_serial.c b/arch/xtensa/src/esp32/esp32_serial.c
index 88a3470..6944627 100644
--- a/arch/xtensa/src/esp32/esp32_serial.c
+++ b/arch/xtensa/src/esp32/esp32_serial.c
@@ -1025,11 +1025,7 @@ static int esp32_attach(struct uart_dev_s *dev)
 
   /* Set up to receive peripheral interrupts on the current CPU */
 
-#ifdef CONFIG_SMP
   cpu = up_cpu_index();
-#else
-  cpu = 0;
-#endif
 
   /* Attach the GPIO peripheral to the allocated CPU interrupt */
 
@@ -1073,12 +1069,7 @@ static void esp32_detach(struct uart_dev_s *dev)
 
   /* Disassociate the peripheral interrupt from the CPU interrupt */
 
-#ifdef CONFIG_SMP
   cpu = up_cpu_index();
-#else
-  cpu = 0;
-#endif
-
   esp32_detach_peripheral(cpu, priv->config->periph, priv->cpuint);
 
   /* And release the CPU interrupt */
@@ -1161,11 +1152,7 @@ static void dma_attach(uint8_t dma_chan)
 
   /* Set up to receive peripheral interrupts on the current CPU */
 
-#ifdef CONFIG_SMP
   cpu = up_cpu_index();
-#else
-  cpu = 0;
-#endif
 
   /* Attach the UHCI interrupt to the allocated CPU interrupt
    * and attach and enable the IRQ.

[incubator-nuttx] 03/05: arch/xtensa/esp32: Keep track to which CPU the interrupt was attached. This is used when dettaching.

Posted by xi...@apache.org.
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 <ab...@espressif.com>
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 <ab...@espressif.com>
---
 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;