esp32/esp32_spi.c: Use device specific locks.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2021-09-27 14:05:52 +02:00 committed by Xiang Xiao
parent 0123243f9a
commit 2273684cb1

View File

@ -39,6 +39,7 @@
#include <nuttx/irq.h>
#include <nuttx/clock.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
@ -162,6 +163,8 @@ struct esp32_spi_priv_s
/* Actual SPI send/receive bits once transmission */
uint8_t nbits;
spinlock_t lock; /* Device specific lock. */
};
/****************************************************************************
@ -1451,13 +1454,13 @@ struct spi_dev_s *esp32_spibus_initialize(int port)
return NULL;
}
spi_dev = (struct spi_dev_s *)priv;
flags = spin_lock_irqsave(&priv->lock);
flags = enter_critical_section();
spi_dev = (struct spi_dev_s *)priv;
if ((volatile int)priv->refs != 0)
{
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return spi_dev;
}
@ -1471,7 +1474,7 @@ struct spi_dev_s *esp32_spibus_initialize(int port)
1, ESP32_CPUINT_LEVEL);
if (priv->cpuint < 0)
{
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return NULL;
}
@ -1481,7 +1484,7 @@ struct spi_dev_s *esp32_spibus_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;
}
@ -1492,7 +1495,7 @@ struct spi_dev_s *esp32_spibus_initialize(int port)
priv->refs++;
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return spi_dev;
}
@ -1517,15 +1520,15 @@ int esp32_spibus_uninitialize(struct spi_dev_s *dev)
return ERROR;
}
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
if (--priv->refs != 0)
{
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return OK;
}
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
if (priv->config->use_dma)
{