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 c61009c2cfd803f18b1c09415ca54111e7ff548b Author: Abdelatif Guettouche <[email protected]> AuthorDate: Wed Sep 8 14:24:55 2021 +0200 esp32/esp32_spi_slave.c: Use device specific locks. Signed-off-by: Abdelatif Guettouche <[email protected]> --- arch/xtensa/src/esp32/esp32_spi_slave.c | 41 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/arch/xtensa/src/esp32/esp32_spi_slave.c b/arch/xtensa/src/esp32/esp32_spi_slave.c index 269e427..213d518 100644 --- a/arch/xtensa/src/esp32/esp32_spi_slave.c +++ b/arch/xtensa/src/esp32/esp32_spi_slave.c @@ -41,6 +41,7 @@ #include <nuttx/irq.h> #include <nuttx/clock.h> #include <nuttx/semaphore.h> +#include <nuttx/spinlock.h> #include <nuttx/spi/spi.h> #include <nuttx/spi/slave.h> @@ -163,6 +164,8 @@ struct esp32_spislv_priv_s /* Copy from config to speed up checking */ bool dma_chan; + + spinlock_t lock; /* Device specific lock. */ }; /**************************************************************************** @@ -1009,7 +1012,7 @@ static void esp32_spislv_bind(struct spi_slave_ctrlr_s *ctrlr, DEBUGASSERT(priv != NULL && priv->dev == NULL && dev != NULL); - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); priv->dev = dev; @@ -1031,7 +1034,7 @@ static void esp32_spislv_bind(struct spi_slave_ctrlr_s *ctrlr, esp32_spi_set_regbits(priv, SPI_CMD_OFFSET, SPI_USR_M); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); } /**************************************************************************** @@ -1061,7 +1064,7 @@ static void esp32_spislv_unbind(struct spi_slave_ctrlr_s *ctrlr) DEBUGASSERT(priv->dev != NULL); - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); up_disable_irq(priv->config->irq); @@ -1076,7 +1079,7 @@ static void esp32_spislv_unbind(struct spi_slave_ctrlr_s *ctrlr) priv->dev = NULL; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); } /**************************************************************************** @@ -1114,7 +1117,7 @@ static int esp32_spislv_enqueue(struct spi_slave_ctrlr_s *ctrlr, ctrlr, data, nwords); DEBUGASSERT(priv != NULL && priv->dev != NULL); - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); bufsize = SPI_SLAVE_BUFSIZE - priv->txlen; if (!bufsize) @@ -1135,7 +1138,7 @@ static int esp32_spislv_enqueue(struct spi_slave_ctrlr_s *ctrlr, } } - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return ret; } @@ -1165,9 +1168,9 @@ static bool esp32_spislv_qfull(struct spi_slave_ctrlr_s *ctrlr) spiinfo("spi_qfull(ctrlr=%p)\n", ctrlr); - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); ret = priv->txlen == SPI_SLAVE_BUFSIZE; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return ret; } @@ -1195,11 +1198,11 @@ static void esp32_spislv_qflush(struct spi_slave_ctrlr_s *ctrlr) DEBUGASSERT(priv != NULL && priv->dev != NULL); - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); priv->rxlen = 0; priv->txlen = 0; priv->txen = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); } /**************************************************************************** @@ -1225,12 +1228,12 @@ static size_t esp32_spislv_qpoll(struct spi_slave_ctrlr_s *ctrlr) DEBUGASSERT(priv != NULL && priv->dev != NULL); - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); esp32_spislv_rx(priv); n = priv->rxlen; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return n; } @@ -1274,11 +1277,11 @@ struct spi_slave_ctrlr_s *esp32_spislv_ctrlr_initialize(int port) spislv_dev = (struct spi_slave_ctrlr_s *)priv; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); if ((volatile int)priv->refs != 0) { - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return spislv_dev; } @@ -1307,14 +1310,14 @@ struct spi_slave_ctrlr_s *esp32_spislv_ctrlr_initialize(int port) { esp32_teardown_irq(priv->cpu, priv->config->periph, priv->cpuint); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return NULL; } priv->refs++; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return spislv_dev; } @@ -1345,11 +1348,11 @@ int esp32_spislv_ctrlr_uninitialize(struct spi_slave_ctrlr_s *ctrlr) return ERROR; } - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); if (--priv->refs) { - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return OK; } @@ -1357,7 +1360,7 @@ int esp32_spislv_ctrlr_uninitialize(struct spi_slave_ctrlr_s *ctrlr) esp32_teardown_irq(priv->cpu, priv->config->periph, priv->cpuint); esp32_spislv_deinit(ctrlr); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return OK; }
