spi: Refactor SPI Slave interface prefix to sync with I2C Slave

This commit is contained in:
Gustavo Henrique Nihei
2021-06-04 10:51:13 -03:00
committed by David Sidrane
parent 27782aca19
commit 0b3c2c7603
11 changed files with 573 additions and 551 deletions
+3 -3
View File
@@ -142,8 +142,8 @@ extern "C"
* Public Function Prototypes
****************************************************************************/
struct spi_dev_s; /* Forward reference */
struct spi_sctrlr_s; /* Forward reference */
struct spi_dev_s; /* Forward reference */
struct spi_slave_ctrlr_s; /* Forward reference */
/****************************************************************************
* Name: sam_spibus_initialize
@@ -176,7 +176,7 @@ FAR struct spi_dev_s *sam_spibus_initialize(int port);
*
****************************************************************************/
FAR struct spi_sctrlr_s *sam_spi_slave_initialize(int port);
FAR struct spi_slave_ctrlr_s *sam_spi_slave_initialize(int port);
/****************************************************************************
* Name: sam_spi[0|1]select, sam_spi[0|1]status, and sam_spi[0|1]cmddata
+89 -79
View File
@@ -72,9 +72,13 @@
struct sam_spidev_s
{
struct spi_sctrlr_s sctrlr; /* Externally visible part of the SPI slave
* controller interface */
struct spi_sdev_s *sdev; /* Bound SPI slave device interface */
/* Externally visible part of the SPI slave controller interface */
struct spi_slave_ctrlr_s ctrlr;
/* Bound SPI slave device interface */
struct spi_slave_dev_s *dev;
xcpt_t handler; /* SPI interrupt handler */
uint32_t base; /* SPI controller register base address */
sem_t spisem; /* Assures mutually exclusive access to SPI */
@@ -111,15 +115,15 @@ struct sam_spidev_s
#ifdef CONFIG_SAMV7_SPI_REGDEBUG
static bool spi_checkreg(struct sam_spidev_s *priv, bool wr,
uint32_t value, uint32_t address);
uint32_t value, uint32_t address);
#else
# define spi_checkreg(priv,wr,value,address) (false)
#endif
static uint32_t spi_getreg(struct sam_spidev_s *priv,
unsigned int offset);
unsigned int offset);
static void spi_putreg(struct sam_spidev_s *priv, uint32_t value,
unsigned int offset);
unsigned int offset);
#ifdef CONFIG_DEBUG_SPI_INFO
static void spi_dumpregs(struct sam_spidev_s *priv, const char *msg);
@@ -139,20 +143,21 @@ static int spi_interrupt(int irq, void *context, FAR void *arg);
static uint16_t spi_dequeue(struct sam_spidev_s *priv);
static void spi_setmode(struct sam_spidev_s *priv,
enum spi_smode_e mode);
enum spi_slave_mode_e mode);
static void spi_setbits(struct sam_spidev_s *priv,
int nbits);
int nbits);
/* SPI slave controller methods */
static void spi_bind(struct spi_sctrlr_s *sctrlr,
struct spi_sdev_s *sdev, enum spi_smode_e mode,
int nbits);
static void spi_unbind(struct spi_sctrlr_s *sctrlr);
static int spi_enqueue(struct spi_sctrlr_s *sctrlr,
FAR const void *data, size_t nwords);
static bool spi_qfull(struct spi_sctrlr_s *sctrlr);
static void spi_qflush(struct spi_sctrlr_s *sctrlr);
static void spi_bind(struct spi_slave_ctrlr_s *ctrlr,
struct spi_slave_dev_s *dev,
enum spi_slave_mode_e mode,
int nbits);
static void spi_unbind(struct spi_slave_ctrlr_s *ctrlr);
static int spi_enqueue(struct spi_slave_ctrlr_s *ctrlr,
FAR const void *data, size_t len);
static bool spi_qfull(struct spi_slave_ctrlr_s *ctrlr);
static void spi_qflush(struct spi_slave_ctrlr_s *ctrlr);
/****************************************************************************
* Private Data
@@ -168,7 +173,7 @@ static const uint8_t g_csroffset[4] =
/* SPI slave controller driver operations */
static const struct spi_sctrlrops_s g_sctrlr_ops =
static const struct spi_slave_ctrlrops_s g_ctrlr_ops =
{
.bind = spi_bind,
.unbind = spi_unbind,
@@ -180,13 +185,13 @@ static const struct spi_sctrlrops_s g_sctrlr_ops =
#ifdef CONFIG_SAMV7_SPI0_SLAVE
/* This is the overall state of the SPI0 controller */
static struct sam_spidev_s g_spi0_sctrlr;
static struct sam_spidev_s g_spi0_ctrlr;
#endif
#ifdef CONFIG_SAMV7_SPI1_SLAVE
/* This is the overall state of the SPI0 controller */
static struct sam_spidev_s g_spi1_sctrlr;
static struct sam_spidev_s g_spi1_ctrlr;
#endif
/****************************************************************************
@@ -468,7 +473,7 @@ static int spi_interrupt(int irq, void *context, FAR void *arg)
if (priv->nss)
{
priv->nss = false;
SPI_SDEV_SELECT(priv->sdev, true);
SPIS_DEV_SELECT(priv->dev, true);
}
/* Read the RDR to get the data and to clear the pending RDRF
@@ -486,7 +491,7 @@ static int spi_interrupt(int irq, void *context, FAR void *arg)
/* Report the receipt of data to the SPI device driver */
SPI_SDEV_RECEIVE(priv->sdev, (const uint16_t *)&data,
SPIS_DEV_RECEIVE(priv->dev, (const uint16_t *)&data,
sizeof(data));
}
@@ -552,7 +557,7 @@ static int spi_interrupt(int irq, void *context, FAR void *arg)
/* Report the state change to the SPI device driver */
priv->nss = true;
SPI_SDEV_SELECT(priv->sdev, false);
SPIS_DEV_SELECT(priv->dev, false);
}
}
@@ -630,7 +635,7 @@ static uint16_t spi_dequeue(struct sam_spidev_s *priv)
* Name: spi_setmode
*
* Description:
* Set the SPI mode. See enum spi_smode_e for mode definitions
* Set the SPI mode. See enum spi_slave_mode_e for mode definitions
*
* Input Parameters:
* priv - SPI device data structure
@@ -641,7 +646,8 @@ static uint16_t spi_dequeue(struct sam_spidev_s *priv)
*
****************************************************************************/
static void spi_setmode(struct sam_spidev_s *priv, enum spi_smode_e mode)
static void spi_setmode(struct sam_spidev_s *priv,
enum spi_slave_mode_e mode)
{
uint32_t regval;
@@ -743,35 +749,36 @@ static void spi_setbits(struct sam_spidev_s *priv, int nbits)
*
* Description:
* Bind the SPI slave device interface to the SPI slave controller
* interface and configure the SPI interface. Upon return, the SPI
* interface and configure the SPI interface. Upon return, the SPI
* slave controller driver is fully operational and ready to perform
* transfers.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* sdev - SPI slave device interface instance
* mode - The SPI mode requested
* nbits - The number of bits requests.
* If value is greater > 0 then it implies MSB first
* If value is below < 0, then it implies LSB first with -nbits
* ctrlr - SPI Slave controller interface instance
* dev - SPI Slave device interface instance
* mode - The SPI Slave mode requested
* nbits - The number of bits requested.
* If value is greater than 0, then it implies MSB first
* If value is less than 0, then it implies LSB first with -nbits
*
* Returned Value:
* none
* None.
*
****************************************************************************/
static void spi_bind(struct spi_sctrlr_s *sctrlr,
struct spi_sdev_s *sdev, enum spi_smode_e mode,
static void spi_bind(struct spi_slave_ctrlr_s *ctrlr,
struct spi_slave_dev_s *dev,
enum spi_slave_mode_e mode,
int nbits)
{
struct sam_spidev_s *priv = (struct sam_spidev_s *)sctrlr;
struct sam_spidev_s *priv = (struct sam_spidev_s *)ctrlr;
uint32_t regval;
int ret;
FAR const void *data;
spiinfo("sdev=%p mode=%d nbits=%d\n", sdv, mode, nbits);
spiinfo("dev=%p mode=%d nbits=%d\n", sdv, mode, nbits);
DEBUGASSERT(priv != NULL && priv->sdev == NULL && sdev != NULL);
DEBUGASSERT(priv != NULL && priv->dev == NULL && dev != NULL);
/* Get exclusive access to the SPI device */
@@ -790,7 +797,7 @@ static void spi_bind(struct spi_sctrlr_s *sctrlr,
* controller interface.
*/
priv->sdev = sdev;
priv->dev = dev;
/* Call the slaved device's select() and cmddata() methods to indicate
* the initial state of the chip select and command/data discretes.
@@ -804,9 +811,9 @@ static void spi_bind(struct spi_sctrlr_s *sctrlr,
* the Command/Data indication (not yet impklemented).
*/
SPI_SDEV_SELECT(sdev, false);
SPIS_DEV_SELECT(dev, false);
#warning Missing logic
SPI_SDEV_CMDDATA(sdev, false);
SPIS_DEV_CMDDATA(dev, false);
/* Discard any queued data */
@@ -817,7 +824,7 @@ static void spi_bind(struct spi_sctrlr_s *sctrlr,
* be shifted out the SPI clock is detected.
*/
SPI_SDEV_GETDATA(sdev, &data);
SPIS_DEV_GETDATA(dev, &data);
priv->outval = *(const uint16_t *)data;
spi_putreg(priv, priv->outval, SAM_SPI_TDR_OFFSET);
@@ -865,25 +872,25 @@ static void spi_bind(struct spi_sctrlr_s *sctrlr,
*
* Description:
* Un-bind the SPI slave device interface from the SPI slave controller
* interface. Reset the SPI interface and restore the SPI slave
* controller driver to its initial state,
* interface. Reset the SPI interface and restore the SPI slave
* controller driver to its initial state.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* none
* None.
*
****************************************************************************/
static void spi_unbind(struct spi_sctrlr_s *sctrlr)
static void spi_unbind(struct spi_slave_ctrlr_s *ctrlr)
{
struct sam_spidev_s *priv = (struct sam_spidev_s *)sctrlr;
struct sam_spidev_s *priv = (struct sam_spidev_s *)ctrlr;
DEBUGASSERT(priv != NULL);
spiinfo("Unbinding %p\n", priv->sdev);
spiinfo("Unbinding %p\n", priv->dev);
DEBUGASSERT(priv->sdev != NULL);
DEBUGASSERT(priv->dev != NULL);
/* Get exclusive access to the SPI device */
@@ -895,7 +902,7 @@ static void spi_unbind(struct spi_sctrlr_s *sctrlr)
/* Unbind the SPI slave interface */
priv->sdev = NULL;
priv->dev = NULL;
/* Disable the SPI peripheral */
@@ -913,15 +920,18 @@ static void spi_unbind(struct spi_sctrlr_s *sctrlr)
* Name: spi_enqueue
*
* Description:
* Enqueue the next value to be shifted out from the interface. This adds
* Enqueue the next value to be shifted out from the interface. This adds
* the word the controller driver for a subsequent transfer but has no
* effect on anyin-process or currently "committed" transfers
* effect on any in-process or currently "committed" transfers.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* data - Command/data mode data value to be shifted out. The width of
* the data must be the same as the nbits parameter previously
* provided to the bind() methods.
* ctrlr - SPI Slave controller interface instance
* data - Pointer to the command/data mode data to be shifted out.
* The data width must be aligned to the nbits parameter which was
* previously provided to the bind() method.
* len - Number of units of "nbits" wide to enqueue,
* "nbits" being the data width previously provided to the bind()
* method.
*
* Returned Value:
* Zero if the word was successfully queue; A negated errno valid is
@@ -930,17 +940,17 @@ static void spi_unbind(struct spi_sctrlr_s *sctrlr)
*
****************************************************************************/
static int spi_enqueue(struct spi_sctrlr_s *sctrlr, FAR const void *data,
size_t nwords)
static int spi_enqueue(struct spi_slave_ctrlr_s *ctrlr,
FAR const void *data, size_t len)
{
struct sam_spidev_s *priv = (struct sam_spidev_s *)sctrlr;
struct sam_spidev_s *priv = (struct sam_spidev_s *)ctrlr;
irqstate_t flags;
uint32_t regval;
int next;
int ret;
spiinfo("data=%04x\n", *(const uint16_t *)data);
DEBUGASSERT(priv != NULL && priv->sdev != NULL);
DEBUGASSERT(priv != NULL && priv->dev != NULL);
/* Get exclusive access to the SPI device */
@@ -1001,22 +1011,22 @@ static int spi_enqueue(struct spi_sctrlr_s *sctrlr, FAR const void *data,
* additional word to the queue.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* true if the output wueue is full
* true if the output queue is full, false otherwise.
*
****************************************************************************/
static bool spi_qfull(struct spi_sctrlr_s *sctrlr)
static bool spi_qfull(struct spi_slave_ctrlr_s *ctrlr)
{
struct sam_spidev_s *priv = (struct sam_spidev_s *)sctrlr;
struct sam_spidev_s *priv = (struct sam_spidev_s *)ctrlr;
irqstate_t flags;
bool bret;
int ret;
int next;
DEBUGASSERT(priv != NULL && priv->sdev != NULL);
DEBUGASSERT(priv != NULL && priv->dev != NULL);
/* Get exclusive access to the SPI device */
@@ -1053,26 +1063,26 @@ static bool spi_qfull(struct spi_sctrlr_s *sctrlr)
* Name: spi_qflush
*
* Description:
* Discard all saved values in the output queue. On return from this
* function the output queue will be empty. Any in-progress or otherwise
* Discard all saved values in the output queue. On return from this
* function the output queue will be empty. Any in-progress or otherwise
* "committed" output values may not be flushed.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* None
* None.
*
****************************************************************************/
static void spi_qflush(struct spi_sctrlr_s *sctrlr)
static void spi_qflush(struct spi_slave_ctrlr_s *ctrlr)
{
struct sam_spidev_s *priv = (struct sam_spidev_s *)sctrlr;
struct sam_spidev_s *priv = (struct sam_spidev_s *)ctrlr;
irqstate_t flags;
spiinfo("data=%04x\n", data);
DEBUGASSERT(priv != NULL && priv->sdev != NULL);
DEBUGASSERT(priv != NULL && priv->dev != NULL);
/* Get exclusive access to the SPI device */
@@ -1106,7 +1116,7 @@ static void spi_qflush(struct spi_sctrlr_s *sctrlr)
*
****************************************************************************/
struct spi_sctrlr_s *sam_spi_slave_initialize(int port)
struct spi_slave_ctrlr_s *sam_spi_slave_initialize(int port)
{
struct sam_spidev_s *priv;
int spino = (port & __SPI_SPI_MASK) >> __SPI_SPI_SHIFT;
@@ -1128,18 +1138,18 @@ struct spi_sctrlr_s *sam_spi_slave_initialize(int port)
#if defined(CONFIG_SAMV7_SPI0_SLAVE) && defined(CONFIG_SAMV7_SPI1_SLAVE)
if (spino == 0)
{
priv = &g_spi0_sctrlr;
priv = &g_spi0_ctrlr;
}
else
{
priv = &g_spi1_sctrlr;
priv = &g_spi1_ctrlr;
}
#elif defined(CONFIG_SAMV7_SPI0_SLAVE)
priv = &g_spi0_sctrlr;
priv = &g_spi0_ctrlr;
#elif defined(CONFIG_SAMV7_SPI1_SLAVE)
priv = &g_spi1_sctrlr;
priv = &g_spi1_ctrlr;
#endif
/* Set up the initial state for this chip select structure. Other fields
@@ -1150,7 +1160,7 @@ struct spi_sctrlr_s *sam_spi_slave_initialize(int port)
/* Initialize the SPI operations */
priv->sctrlr.ops = &g_sctrlr_ops;
priv->ctrlr.ops = &g_ctrlr_ops;
/* Save the SPI controller number */
@@ -1262,6 +1272,6 @@ struct spi_sctrlr_s *sam_spi_slave_initialize(int port)
priv->nbits = 8;
spiinfo("csr[offset=%02x]=%08x\n", offset, regval);
return &priv->sctrlr;
return &priv->ctrlr;
}
#endif /* CONFIG_SAMV7_SPI_SLAVE */
+1 -1
View File
@@ -79,7 +79,7 @@ FAR struct spi_dev_s *stm32_spibus_initialize(int bus);
*
****************************************************************************/
FAR struct spi_sctrlr_s *stm32_spi_slave_initialize(int bus);
FAR struct spi_slave_ctrlr_s *stm32_spi_slave_initialize(int bus);
/****************************************************************************
* Name: stm32_spi1/2/...select and stm32_spi1/2/...status
+92 -87
View File
@@ -179,9 +179,10 @@ enum spi_config_e
struct stm32_spidev_s
{
struct spi_sctrlr_s sctrlr; /* Externally visible part of the
* SPI slave interface */
struct spi_sdev_s *sdev; /* Bound SPI slave device interface */
/* Externally visible part of the SPI slave interface */
struct spi_slave_ctrlr_s ctrlr;
struct spi_slave_dev_s *dev; /* Bound SPI slave device interface */
uint32_t spibase; /* SPIn base address */
uint32_t spiclock; /* Clocking for the SPI module */
uint8_t irq; /* SPI IRQ number */
@@ -268,16 +269,17 @@ static int spi_nssinterrupt(int irq, void *context, void *arg);
/* SPI slave methods */
static void spi_bind(struct spi_sctrlr_s *sctrlr,
struct spi_sdev_s *sdev, enum spi_smode_e mode,
int nbits);
static void spi_unbind(struct spi_sctrlr_s *sctrlr);
static int spi_enqueue(struct spi_sctrlr_s *sctrlr,
static void spi_bind(struct spi_slave_ctrlr_s *ctrlr,
struct spi_slave_dev_s *dev,
enum spi_slave_mode_e mode,
int nbits);
static void spi_unbind(struct spi_slave_ctrlr_s *ctrlr);
static int spi_enqueue(struct spi_slave_ctrlr_s *ctrlr,
FAR const void *data,
size_t len);
static bool spi_qfull(struct spi_sctrlr_s *sctrlr);
static void spi_qflush(struct spi_sctrlr_s *sctrlr);
static size_t spi_qpoll(struct spi_sctrlr_s *sctrlr);
static bool spi_qfull(struct spi_slave_ctrlr_s *ctrlr);
static void spi_qflush(struct spi_slave_ctrlr_s *ctrlr);
static size_t spi_qpoll(struct spi_slave_ctrlr_s *ctrlr);
/* Initialization */
@@ -296,7 +298,7 @@ static int spi_pm_prepare(FAR struct pm_callback_s *cb, int domain,
/* SPI slave controller driver operations */
static const struct spi_sctrlrops_s g_sctrlr_ops =
static const struct spi_slave_ctrlrops_s g_ctrlr_ops =
{
.bind = spi_bind,
.unbind = spi_unbind,
@@ -327,8 +329,8 @@ static const struct spi_sctrlrops_s g_sctrlr_ops =
#define SPI_SLAVE_INIT(x) \
{ \
.sctrlr.ops = &g_sctrlr_ops, \
.sdev = NULL, \
.ctrlr.ops = &g_ctrlr_ops, \
.dev = NULL, \
.spibase = STM32_SPI##x##_BASE, \
.spiclock = SPI45_KERNEL_CLOCK_FREQ, \
.irq = STM32_IRQ_SPI##x, \
@@ -346,7 +348,7 @@ __attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static
uint8_t SPI_SLAVE_INQ(1)[DMA_ALIGN_UP(CONFIG_STM32H7_SPI_SLAVE_QSIZE)]
__attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static struct stm32_spidev_s g_spi1sctrlr = SPI_SLAVE_INIT(1);
static struct stm32_spidev_s g_spi1ctrlr = SPI_SLAVE_INIT(1);
#endif
@@ -358,7 +360,7 @@ __attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static
uint8_t SPI_SLAVE_INQ(2)[DMA_ALIGN_UP(CONFIG_STM32H7_SPI_SLAVE_QSIZE)]
__attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static struct stm32_spidev_s g_spi2sctrlr = SPI_SLAVE_INIT(2);
static struct stm32_spidev_s g_spi2ctrlr = SPI_SLAVE_INIT(2);
#endif
@@ -370,7 +372,7 @@ __attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static
uint8_t SPI_SLAVE_INQ(3)[DMA_ALIGN_UP(CONFIG_STM32H7_SPI_SLAVE_QSIZE)]
__attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static struct stm32_spidev_s g_spi3sctrlr = SPI_SLAVE_INIT(3);
static struct stm32_spidev_s g_spi3ctrlr = SPI_SLAVE_INIT(3);
#endif
@@ -382,7 +384,7 @@ __attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static
uint8_t SPI_SLAVE_INQ(4)[DMA_ALIGN_UP(CONFIG_STM32H7_SPI_SLAVE_QSIZE)]
__attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static struct stm32_spidev_s g_spi4sctrlr = SPI_SLAVE_INIT(4);
static struct stm32_spidev_s g_spi4ctrlr = SPI_SLAVE_INIT(4);
#endif
@@ -394,7 +396,7 @@ __attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static
uint8_t SPI_SLAVE_INQ(5)[DMA_ALIGN_UP(CONFIG_STM32H7_SPI_SLAVE_QSIZE)]
__attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static struct stm32_spidev_s g_spi5sctrlr = SPI_SLAVE_INIT(5);
static struct stm32_spidev_s g_spi5ctrlr = SPI_SLAVE_INIT(5);
#endif
@@ -408,7 +410,7 @@ __attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static
uint8_t SPI_SLAVE_INQ(6)[DMA_ALIGN_UP(CONFIG_STM32H7_SPI_SLAVE_QSIZE)]
__attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
static struct stm32_spidev_s g_spi6sctrlr = SPI_SLAVE_INIT(6);
static struct stm32_spidev_s g_spi6ctrlr = SPI_SLAVE_INIT(6);
#endif
@@ -898,9 +900,9 @@ static void spi_dmatxstart(FAR struct stm32_spidev_s *priv)
*
****************************************************************************/
static int spi_lock(FAR struct spi_sctrlr_s *sctrlr, bool lock)
static int spi_lock(FAR struct spi_slave_ctrlr_s *ctrlr, bool lock)
{
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)sctrlr;
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)ctrlr;
int ret;
if (lock)
@@ -971,10 +973,10 @@ static inline void spi_enable(FAR struct stm32_spidev_s *priv, bool state)
*
****************************************************************************/
static void spi_setmode(FAR struct spi_sctrlr_s *sctrlr,
static void spi_setmode(FAR struct spi_slave_ctrlr_s *ctrlr,
enum spi_mode_e mode)
{
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)sctrlr;
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)ctrlr;
uint32_t setbits = 0;
uint32_t clrbits = 0;
@@ -1037,9 +1039,9 @@ static void spi_setmode(FAR struct spi_sctrlr_s *sctrlr,
*
****************************************************************************/
static void spi_setbits(FAR struct spi_sctrlr_s *sctrlr, int nbits)
static void spi_setbits(FAR struct spi_slave_ctrlr_s *ctrlr, int nbits)
{
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)sctrlr;
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)ctrlr;
uint32_t setbits = 0;
uint32_t clrbits = 0;
@@ -1087,37 +1089,37 @@ static void spi_setbits(FAR struct spi_sctrlr_s *sctrlr, int nbits)
*
* Description:
* Bind the SPI slave device interface to the SPI slave controller
* interface and configure the SPI interface. Upon return, the SPI
* interface and configure the SPI interface. Upon return, the SPI
* slave controller driver is fully operational and ready to perform
* transfers.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* sdev - SPI slave device interface instance
* mode - The SPI mode requested
* nbits - The number of bits requests.
* If value is greater > 0 then it implies MSB first
* If value is below < 0, then it implies LSB first with -nbits
* ctrlr - SPI Slave controller interface instance
* dev - SPI Slave device interface instance
* mode - The SPI Slave mode requested
* nbits - The number of bits requested.
* If value is greater than 0, then it implies MSB first
* If value is less than 0, then it implies LSB first with -nbits
*
* Returned Value:
* none
* None.
*
****************************************************************************/
static void spi_bind(struct spi_sctrlr_s *sctrlr,
struct spi_sdev_s *sdev, enum spi_smode_e mode,
static void spi_bind(struct spi_slave_ctrlr_s *ctrlr,
struct spi_slave_dev_s *dev, enum spi_slave_mode_e mode,
int nbits)
{
struct stm32_spidev_s *priv = (struct stm32_spidev_s *)sctrlr;
struct stm32_spidev_s *priv = (struct stm32_spidev_s *)ctrlr;
uint32_t nss_gpio;
spiinfo("sdev=%p mode=%d nbits=%d\n", sdv, mode, nbits);
spiinfo("dev=%p mode=%d nbits=%d\n", sdv, mode, nbits);
DEBUGASSERT(priv != NULL && priv->sdev == NULL && sdev != NULL);
DEBUGASSERT(priv != NULL && priv->dev == NULL && dev != NULL);
/* Get exclusive access to the SPI device */
spi_lock(sctrlr, true);
spi_lock(ctrlr, true);
/* Make sure the spi is disabled */
@@ -1137,7 +1139,7 @@ static void spi_bind(struct spi_sctrlr_s *sctrlr,
* controller interface.
*/
priv->sdev = sdev;
priv->dev = dev;
/* Initialize the circular buffer head */
@@ -1145,8 +1147,8 @@ static void spi_bind(struct spi_sctrlr_s *sctrlr,
/* Setup to begin normal SPI operation */
spi_setmode(sctrlr, mode);
spi_setbits(sctrlr, nbits);
spi_setmode(ctrlr, mode);
spi_setbits(ctrlr, nbits);
/* First, configure NSS as GPIO EXTI input */
@@ -1167,7 +1169,7 @@ static void spi_bind(struct spi_sctrlr_s *sctrlr,
UNUSED(ret);
#endif
spi_lock(sctrlr, false);
spi_lock(ctrlr, false);
}
/****************************************************************************
@@ -1252,33 +1254,33 @@ static int spi_nssinterrupt(int irq, void *context, void *arg)
*
* Description:
* Un-bind the SPI slave device interface from the SPI slave controller
* interface. Reset the SPI interface and restore the SPI slave
* controller driver to its initial state,
* interface. Reset the SPI interface and restore the SPI slave
* controller driver to its initial state.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* none
* None.
*
****************************************************************************/
static void spi_unbind(struct spi_sctrlr_s *sctrlr)
static void spi_unbind(struct spi_slave_ctrlr_s *ctrlr)
{
struct stm32_spidev_s *priv = (struct stm32_spidev_s *)sctrlr;
struct stm32_spidev_s *priv = (struct stm32_spidev_s *)ctrlr;
DEBUGASSERT(priv != NULL);
spiinfo("Unbinding %p\n", priv->sdev);
spiinfo("Unbinding %p\n", priv->dev);
DEBUGASSERT(priv->sdev != NULL);
DEBUGASSERT(priv->dev != NULL);
/* Get exclusive access to the SPI device */
spi_lock(sctrlr, true);
spi_lock(ctrlr, true);
/* Unbind the SPI slave interface */
priv->sdev = NULL;
priv->dev = NULL;
/* Disable DMA */
@@ -1289,22 +1291,25 @@ static void spi_unbind(struct spi_sctrlr_s *sctrlr)
spi_enable(priv, false);
spi_lock(sctrlr, false);
spi_lock(ctrlr, false);
}
/****************************************************************************
* Name: spi_enqueue
*
* Description:
* Enqueue the next value to be shifted out from the interface. This adds
* Enqueue the next value to be shifted out from the interface. This adds
* the word the controller driver for a subsequent transfer but has no
* effect on anyin-process or currently "committed" transfers
* effect on any in-process or currently "committed" transfers.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* data - Command/data mode data value to be shifted out. The width of
* the data must be the same as the nbits parameter previously
* provided to the bind() methods.
* ctrlr - SPI Slave controller interface instance
* data - Pointer to the command/data mode data to be shifted out.
* The data width must be aligned to the nbits parameter which was
* previously provided to the bind() method.
* len - Number of units of "nbits" wide to enqueue,
* "nbits" being the data width previously provided to the bind()
* method.
*
* Returned Value:
* Zero if the word was successfully queue; A negated errno valid is
@@ -1313,8 +1318,8 @@ static void spi_unbind(struct spi_sctrlr_s *sctrlr)
*
****************************************************************************/
static int spi_enqueue(struct spi_sctrlr_s *sctrlr, FAR const void *data,
size_t len)
static int spi_enqueue(struct spi_slave_ctrlr_s *ctrlr,
FAR const void *data, size_t len)
{
return 0;
}
@@ -1327,14 +1332,14 @@ static int spi_enqueue(struct spi_sctrlr_s *sctrlr, FAR const void *data,
* additional word to the queue.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* true if the output wueue is full
* true if the output queue is full, false otherwise.
*
****************************************************************************/
static bool spi_qfull(struct spi_sctrlr_s *sctrlr)
static bool spi_qfull(struct spi_slave_ctrlr_s *ctrlr)
{
return false;
}
@@ -1343,24 +1348,24 @@ static bool spi_qfull(struct spi_sctrlr_s *sctrlr)
* Name: spi_qflush
*
* Description:
* Discard all saved values in the output queue. On return from this
* function the output queue will be empty. Any in-progress or otherwise
* Discard all saved values in the output queue. On return from this
* function the output queue will be empty. Any in-progress or otherwise
* "committed" output values may not be flushed.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* None
* None.
*
****************************************************************************/
static void spi_qflush(struct spi_sctrlr_s *sctrlr)
static void spi_qflush(struct spi_slave_ctrlr_s *ctrlr)
{
struct stm32_spidev_s *priv = (struct stm32_spidev_s *)sctrlr;
struct stm32_spidev_s *priv = (struct stm32_spidev_s *)ctrlr;
irqstate_t flags;
DEBUGASSERT(priv != NULL && priv->sdev != NULL);
DEBUGASSERT(priv != NULL && priv->dev != NULL);
#ifdef CONFIG_STM32H7_SPI_DMA
if (!priv->dmarunning)
@@ -1371,7 +1376,7 @@ static void spi_qflush(struct spi_sctrlr_s *sctrlr)
/* Get exclusive access to the SPI device */
spi_lock(sctrlr, true);
spi_lock(ctrlr, true);
flags = enter_critical_section();
/* Flush the input buffers */
@@ -1389,7 +1394,7 @@ static void spi_qflush(struct spi_sctrlr_s *sctrlr)
priv->ohead = 0;
priv->otail = 0;
leave_critical_section(flags);
spi_lock(sctrlr, false);
spi_lock(ctrlr, false);
}
/****************************************************************************
@@ -1436,21 +1441,21 @@ static inline int spi_rx_buffer_free(uint8_t *ptr, int start, int end)
* Tell the controller to output all the receive queue data.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* Number of bytes left in the rx queue. If the device accepted all the
*
****************************************************************************/
static size_t spi_qpoll(struct spi_sctrlr_s *sctrlr)
static size_t spi_qpoll(struct spi_slave_ctrlr_s *ctrlr)
{
struct stm32_spidev_s *priv = (struct stm32_spidev_s *)sctrlr;
struct stm32_spidev_s *priv = (struct stm32_spidev_s *)ctrlr;
int itail;
int ihead;
uint16_t bytes_left;
DEBUGASSERT(priv != NULL && priv->sdev != NULL);
DEBUGASSERT(priv != NULL && priv->dev != NULL);
DEBUGASSERT(priv->ihead < CONFIG_STM32H7_SPI_SLAVE_QSIZE);
#ifdef CONFIG_STM32H7_SPI_DMA
@@ -1462,7 +1467,7 @@ static size_t spi_qpoll(struct spi_sctrlr_s *sctrlr)
/* Get exclusive access to the SPI device */
spi_lock(sctrlr, true);
spi_lock(ctrlr, true);
#ifdef CONFIG_STM32H7_SPI_DMA
itail = CONFIG_STM32H7_SPI_SLAVE_QSIZE - stm32_dmaresidual(priv->rxdma);
@@ -1477,7 +1482,7 @@ static size_t spi_qpoll(struct spi_sctrlr_s *sctrlr)
{
/* Receive the end of receive buffer */
priv->ihead += SPI_SDEV_RECEIVE(priv->sdev,
priv->ihead += SPIS_DEV_RECEIVE(priv->dev,
(const uint16_t *)&priv->inq[ihead],
CONFIG_STM32H7_SPI_SLAVE_QSIZE -
ihead);
@@ -1492,7 +1497,7 @@ static size_t spi_qpoll(struct spi_sctrlr_s *sctrlr)
{
/* Receive the data between ihead and itail */
priv->ihead += SPI_SDEV_RECEIVE(priv->sdev,
priv->ihead += SPIS_DEV_RECEIVE(priv->dev,
(const uint16_t *)&priv->inq[ihead],
itail - ihead);
@@ -1507,7 +1512,7 @@ static size_t spi_qpoll(struct spi_sctrlr_s *sctrlr)
? CONFIG_STM32H7_SPI_SLAVE_QSIZE - priv->ihead + itail
: itail - priv->ihead;
spi_lock(sctrlr, false);
spi_lock(ctrlr, false);
return bytes_left;
}
@@ -1732,7 +1737,7 @@ static void spi_slave_initialize(struct stm32_spidev_s *priv)
#define GPIO_SPI_NSS(x) GPIO_SPI##x##_NSS
#define SPI_SLAVE_INIT_BUS(x) \
priv = &g_spi##x##sctrlr; \
priv = &g_spi##x##ctrlr; \
\
/* Only configure if the bus is not already configured */ \
\
@@ -1751,7 +1756,7 @@ static void spi_slave_initialize(struct stm32_spidev_s *priv)
priv->initialized = true; \
}
FAR struct spi_sctrlr_s *stm32_spi_slave_initialize(int bus)
FAR struct spi_slave_ctrlr_s *stm32_spi_slave_initialize(int bus)
{
FAR struct stm32_spidev_s *priv = NULL;
irqstate_t flags = enter_critical_section();
@@ -1810,10 +1815,10 @@ FAR struct spi_sctrlr_s *stm32_spi_slave_initialize(int bus)
/* Initialize the SPI operations */
priv->sctrlr.ops = &g_sctrlr_ops;
priv->ctrlr.ops = &g_ctrlr_ops;
leave_critical_section(flags);
return (FAR struct spi_sctrlr_s *)priv;
return (FAR struct spi_slave_ctrlr_s *)priv;
}
#endif /* CONFIG_STM32H7_SPI1..6_SLAVE */
+5 -5
View File
@@ -127,7 +127,7 @@ int esp32c3_spi2_cmddata(FAR struct spi_dev_s *dev,
int esp32c3_spibus_uninitialize(FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: esp32c3_spislave_sctrlr_initialize
* Name: esp32c3_spislave_ctrlr_initialize
*
* Description:
* Initialize the selected SPI Slave bus.
@@ -141,23 +141,23 @@ int esp32c3_spibus_uninitialize(FAR struct spi_dev_s *dev);
*
****************************************************************************/
FAR struct spi_sctrlr_s *esp32c3_spislave_sctrlr_initialize(int port);
FAR struct spi_slave_ctrlr_s *esp32c3_spislave_ctrlr_initialize(int port);
/****************************************************************************
* Name: esp32c3_spislave_sctrlr_uninitialize
* Name: esp32c3_spislave_ctrlr_uninitialize
*
* Description:
* Uninitialize an SPI Slave bus.
*
* Input Parameters:
* sctrlr - SPI Slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* Zero (OK) is returned on success. Otherwise -1 (ERROR).
*
****************************************************************************/
int esp32c3_spislave_sctrlr_uninitialize(FAR struct spi_sctrlr_s *sctrlr);
int esp32c3_spislave_ctrlr_uninitialize(FAR struct spi_slave_ctrlr_s *ctrlr);
#endif /* CONFIG_ESP32C3_SPI */
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -121,7 +121,7 @@ int esp32_spi3_cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
int esp32_spibus_uninitialize(FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: esp32_spislv_sctrlr_initialize
* Name: esp32_spislv_ctrlr_initialize
*
* Description:
* Initialize the selected SPI slave bus
@@ -134,23 +134,23 @@ int esp32_spibus_uninitialize(FAR struct spi_dev_s *dev);
*
****************************************************************************/
FAR struct spi_sctrlr_s *esp32_spislv_sctrlr_initialize(int port);
FAR struct spi_slave_ctrlr_s *esp32_spislv_ctrlr_initialize(int port);
/****************************************************************************
* Name: esp32_spislv_sctrlr_uninitialize
* Name: esp32_spislv_ctrlr_uninitialize
*
* Description:
* Uninitialize an SPI slave bus
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI slave controller interface instance
*
* Returned Value:
* OK if success or fail
*
****************************************************************************/
int esp32_spislv_sctrlr_uninitialize(FAR struct spi_sctrlr_s *sctrlr);
int esp32_spislv_ctrlr_uninitialize(FAR struct spi_slave_ctrlr_s *ctrlr);
#endif /* CONFIG_ESP32_SPI */
File diff suppressed because it is too large Load Diff
@@ -55,25 +55,25 @@ int board_spislavedev_initialize(int bus)
{
int ret;
FAR struct spi_sctrlr_s *sctrlr;
FAR struct spi_slave_ctrlr_s *ctrlr;
spiinfo("Initializing /dev/spislv%d...\n", bus);
/* Initialize SPI Slave controller device */
sctrlr = esp32c3_spislave_sctrlr_initialize(bus);
if (sctrlr == NULL)
ctrlr = esp32c3_spislave_ctrlr_initialize(bus);
if (ctrlr == NULL)
{
spierr("Failed to initialize SPI%d as slave.\n", bus);
return -ENODEV;
}
ret = spislave_register(sctrlr, bus);
ret = spi_slave_register(ctrlr, bus);
if (ret < 0)
{
spierr("Failed to register /dev/spislv%d: %d\n", bus, ret);
esp32c3_spislave_sctrlr_uninitialize(sctrlr);
esp32c3_spislave_ctrlr_uninitialize(ctrlr);
}
return ret;
+80 -78
View File
@@ -58,15 +58,15 @@
* Private Types
****************************************************************************/
struct spislave_driver_s
struct spi_slave_driver_s
{
/* Externally visible part of the SPI Slave device interface */
struct spi_sdev_s dev;
struct spi_slave_dev_s dev;
/* Reference to SPI Slave controller interface */
struct spi_sctrlr_s *sctrlr;
struct spi_slave_ctrlr_s *ctrlr;
/* Receive buffer */
@@ -90,21 +90,23 @@ struct spislave_driver_s
/* Character driver methods */
static int spislave_open(FAR struct file *filep);
static int spislave_close(FAR struct file *filep);
static ssize_t spislave_read(FAR struct file *filep, FAR char *buffer,
static int spi_slave_open(FAR struct file *filep);
static int spi_slave_close(FAR struct file *filep);
static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t spislave_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int spislave_unlink(FAR struct inode *inode);
static ssize_t spi_slave_write(FAR struct file *filep,
FAR const char *buffer, size_t buflen);
static int spi_slave_unlink(FAR struct inode *inode);
/* SPI Slave driver methods */
static void spislave_select(FAR struct spi_sdev_s *sdev, bool selected);
static void spislave_cmddata(FAR struct spi_sdev_s *sdev, bool data);
static size_t spislave_getdata(FAR struct spi_sdev_s *sdev,
static void spi_slave_select(FAR struct spi_slave_dev_s *sdev,
bool selected);
static void spi_slave_cmddata(FAR struct spi_slave_dev_s *sdev,
bool data);
static size_t spi_slave_getdata(FAR struct spi_slave_dev_s *sdev,
FAR const void **data);
static size_t spislave_receive(FAR struct spi_sdev_s *sdev,
static size_t spi_slave_receive(FAR struct spi_slave_dev_s *sdev,
FAR const void *data, size_t nwords);
/****************************************************************************
@@ -114,28 +116,28 @@ static size_t spislave_receive(FAR struct spi_sdev_s *sdev,
static const struct file_operations g_spislavefops =
{
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
spislave_open, /* open */
spislave_close, /* close */
spi_slave_open, /* open */
spi_slave_close, /* close */
#else
NULL, /* open */
NULL, /* close */
#endif
spislave_read, /* read */
spislave_write, /* write */
spi_slave_read, /* read */
spi_slave_write, /* write */
NULL, /* seek */
NULL, /* ioctl */
NULL /* poll */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
, spislave_unlink /* unlink */
, spi_slave_unlink /* unlink */
#endif
};
static const struct spi_sdevops_s g_spisdev_ops =
static const struct spi_slave_devops_s g_spisdev_ops =
{
spislave_select, /* select */
spislave_cmddata, /* cmddata */
spislave_getdata, /* getdata */
spislave_receive, /* receive */
spi_slave_select, /* select */
spi_slave_cmddata, /* cmddata */
spi_slave_getdata, /* getdata */
spi_slave_receive, /* receive */
};
/****************************************************************************
@@ -143,7 +145,7 @@ static const struct spi_sdevops_s g_spisdev_ops =
****************************************************************************/
/****************************************************************************
* Name: spislave_open
* Name: spi_slave_open
*
* Description:
* This function is called whenever the SPI Slave device is opened.
@@ -158,10 +160,10 @@ static const struct spi_sdevops_s g_spisdev_ops =
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int spislave_open(FAR struct file *filep)
static int spi_slave_open(FAR struct file *filep)
{
FAR struct inode *inode;
FAR struct spislave_driver_s *priv;
FAR struct spi_slave_driver_s *priv;
int ret;
DEBUGASSERT(filep != NULL);
@@ -173,7 +175,7 @@ static int spislave_open(FAR struct file *filep)
/* Get our private data structure */
inode = filep->f_inode;
priv = (FAR struct spislave_driver_s *)inode->i_private;
priv = (FAR struct spi_slave_driver_s *)inode->i_private;
/* Get exclusive access to the SPI Slave driver state structure */
@@ -195,7 +197,7 @@ static int spislave_open(FAR struct file *filep)
#endif
/****************************************************************************
* Name: spislave_close
* Name: spi_slave_close
*
* Description:
* This routine is called when the SPI Slave device is closed.
@@ -210,10 +212,10 @@ static int spislave_open(FAR struct file *filep)
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int spislave_close(FAR struct file *filep)
static int spi_slave_close(FAR struct file *filep)
{
FAR struct inode *inode;
FAR struct spislave_driver_s *priv;
FAR struct spi_slave_driver_s *priv;
int ret;
DEBUGASSERT(filep != NULL);
@@ -225,7 +227,7 @@ static int spislave_close(FAR struct file *filep)
/* Get our private data structure */
inode = filep->f_inode;
priv = (FAR struct spislave_driver_s *)inode->i_private;
priv = (FAR struct spi_slave_driver_s *)inode->i_private;
/* Get exclusive access to the SPI Slave driver state structure */
@@ -259,7 +261,7 @@ static int spislave_close(FAR struct file *filep)
#endif
/****************************************************************************
* Name: spislave_read
* Name: spi_slave_read
*
* Description:
* This routine is called when the application requires to read the data
@@ -276,11 +278,11 @@ static int spislave_close(FAR struct file *filep)
*
****************************************************************************/
static ssize_t spislave_read(FAR struct file *filep, FAR char *buffer,
static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
FAR struct inode *inode;
FAR struct spislave_driver_s *priv;
FAR struct spi_slave_driver_s *priv;
size_t read_bytes;
size_t remaining_words;
@@ -289,7 +291,7 @@ static ssize_t spislave_read(FAR struct file *filep, FAR char *buffer,
/* Get our private data structure */
inode = filep->f_inode;
priv = (FAR struct spislave_driver_s *)inode->i_private;
priv = (FAR struct spi_slave_driver_s *)inode->i_private;
if (buffer == NULL)
{
@@ -297,7 +299,7 @@ static ssize_t spislave_read(FAR struct file *filep, FAR char *buffer,
return -ENOBUFS;
}
remaining_words = SPI_SCTRLR_QPOLL(priv->sctrlr);
remaining_words = SPIS_CTRLR_QPOLL(priv->ctrlr);
if (remaining_words == 0)
{
spiinfo("All words retrieved!\n");
@@ -315,7 +317,7 @@ static ssize_t spislave_read(FAR struct file *filep, FAR char *buffer,
}
/****************************************************************************
* Name: spislave_write
* Name: spi_slave_write
*
* Description:
* This routine is called when the application needs to enqueue data to be
@@ -332,11 +334,11 @@ static ssize_t spislave_read(FAR struct file *filep, FAR char *buffer,
*
****************************************************************************/
static ssize_t spislave_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen)
static ssize_t spi_slave_write(FAR struct file *filep,
FAR const char *buffer, size_t buflen)
{
FAR struct inode *inode;
FAR struct spislave_driver_s *priv;
FAR struct spi_slave_driver_s *priv;
size_t num_words;
size_t enqueued_bytes;
@@ -345,13 +347,13 @@ static ssize_t spislave_write(FAR struct file *filep, FAR const char *buffer,
/* Get our private data structure */
inode = filep->f_inode;
priv = (FAR struct spislave_driver_s *)inode->i_private;
priv = (FAR struct spi_slave_driver_s *)inode->i_private;
memcpy(priv->tx_buffer, buffer, buflen);
priv->tx_length = buflen;
num_words = BYTES2WORDS(priv->tx_length);
enqueued_bytes = WORDS2BYTES(SPI_SCTRLR_ENQUEUE(priv->sctrlr,
enqueued_bytes = WORDS2BYTES(SPIS_CTRLR_ENQUEUE(priv->ctrlr,
priv->tx_buffer,
num_words));
@@ -361,7 +363,7 @@ static ssize_t spislave_write(FAR struct file *filep, FAR const char *buffer,
}
/****************************************************************************
* Name: spislave_unlink
* Name: spi_slave_unlink
*
* Description:
* This routine is called when the SPI Slave device is unlinked.
@@ -375,9 +377,9 @@ static ssize_t spislave_write(FAR struct file *filep, FAR const char *buffer,
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int spislave_unlink(FAR struct inode *inode)
static int spi_slave_unlink(FAR struct inode *inode)
{
FAR struct spislave_driver_s *priv;
FAR struct spi_slave_driver_s *priv;
int ret;
DEBUGASSERT(inode != NULL);
@@ -385,7 +387,7 @@ static int spislave_unlink(FAR struct inode *inode)
/* Get our private data structure */
priv = (FAR struct spislave_driver_s *)inode->i_private;
priv = (FAR struct spi_slave_driver_s *)inode->i_private;
/* Get exclusive access to the SPI Slave driver state structure */
@@ -417,14 +419,14 @@ static int spislave_unlink(FAR struct inode *inode)
#endif
/****************************************************************************
* Name: spislave_select
* Name: spi_slave_select
*
* Description:
* This is a SPI device callback that is used when the SPI controller
* driver detects any change in the chip select pin.
*
* Input Parameters:
* sdev - SPI device interface instance
* dev - SPI Slave device interface instance
* selected - Indicates whether the chip select is in active state
*
* Returned Value:
@@ -436,13 +438,13 @@ static int spislave_unlink(FAR struct inode *inode)
*
****************************************************************************/
static void spislave_select(FAR struct spi_sdev_s *sdev, bool selected)
static void spi_slave_select(FAR struct spi_slave_dev_s *dev, bool selected)
{
spiinfo("sdev: %p CS: %s\n", sdev, selected ? "select" : "free");
spiinfo("sdev: %p CS: %s\n", dev, selected ? "select" : "free");
}
/****************************************************************************
* Name: spislave_cmddata
* Name: spi_slave_cmddata
*
* Description:
* This is a SPI device callback that is used when the SPI controller
@@ -455,7 +457,7 @@ static void spislave_select(FAR struct spi_sdev_s *sdev, bool selected)
* current command/data selection.
*
* Input Parameters:
* sdev - SPI device interface instance
* dev - SPI Slave device interface instance
* data - True: Data is selected
*
* Returned Value:
@@ -467,13 +469,13 @@ static void spislave_select(FAR struct spi_sdev_s *sdev, bool selected)
*
****************************************************************************/
static void spislave_cmddata(FAR struct spi_sdev_s *sdev, bool data)
static void spi_slave_cmddata(FAR struct spi_slave_dev_s *dev, bool data)
{
spiinfo("sdev: %p CMD: %s\n", sdev, data ? "data" : "command");
spiinfo("sdev: %p CMD: %s\n", dev, data ? "data" : "command");
}
/****************************************************************************
* Name: spislave_getdata
* Name: spi_slave_getdata
*
* Description:
* This is a SPI device callback that is used when the SPI controller
@@ -486,7 +488,7 @@ static void spislave_cmddata(FAR struct spi_sdev_s *sdev, bool data)
* method. Normally only LCD devices distinguish command and data.
*
* Input Parameters:
* sdev - SPI device interface instance
* dev - SPI Slave device interface instance
* data - Pointer to the data buffer pointer to be shifed out.
* The device will set the data buffer pointer to the actual data
*
@@ -499,10 +501,10 @@ static void spislave_cmddata(FAR struct spi_sdev_s *sdev, bool data)
*
****************************************************************************/
static size_t spislave_getdata(FAR struct spi_sdev_s *sdev,
FAR const void **data)
static size_t spi_slave_getdata(FAR struct spi_slave_dev_s *dev,
FAR const void **data)
{
FAR struct spislave_driver_s *priv = (FAR struct spislave_driver_s *)sdev;
FAR struct spi_slave_driver_s *priv = (FAR struct spi_slave_driver_s *)dev;
*data = priv->tx_buffer;
@@ -510,7 +512,7 @@ static size_t spislave_getdata(FAR struct spi_sdev_s *sdev,
}
/****************************************************************************
* Name: spislave_receive
* Name: spi_slave_receive
*
* Description:
* This is a SPI device callback that is used when the SPI controller
@@ -518,7 +520,7 @@ static size_t spislave_getdata(FAR struct spi_sdev_s *sdev,
* synchronization by several words.
*
* Input Parameters:
* sdev - SPI device interface instance
* dev - SPI Slave device interface instance
* data - Pointer to the new data that has been shifted in
* len - Length of the new data in units of nbits wide,
* nbits being the data width previously provided to the bind()
@@ -536,10 +538,10 @@ static size_t spislave_getdata(FAR struct spi_sdev_s *sdev,
*
****************************************************************************/
static size_t spislave_receive(FAR struct spi_sdev_s *sdev,
FAR const void *data, size_t len)
static size_t spi_slave_receive(FAR struct spi_slave_dev_s *dev,
FAR const void *data, size_t len)
{
FAR struct spislave_driver_s *priv = (FAR struct spislave_driver_s *)sdev;
FAR struct spi_slave_driver_s *priv = (FAR struct spi_slave_driver_s *)dev;
size_t recv_bytes = MIN(len, sizeof(priv->rx_buffer));
memcpy(priv->rx_buffer, data, recv_bytes);
@@ -554,37 +556,37 @@ static size_t spislave_receive(FAR struct spi_sdev_s *sdev,
****************************************************************************/
/****************************************************************************
* Name: spislave_register
* Name: spi_slave_register
*
* Description:
* Register the SPI Slave character device as 'devpath'.
* Register the SPI Slave character device driver as 'devpath'.
*
* Input Parameters:
* sctrlr - An instance of the SPI Slave interface to use to communicate
* with the SPI Slave device
* bus - The SPI Slave bus number. This will be used as the SPI device
* minor number. The SPI Slave character device will be
* registered as /dev/spislvN where N is the minor number
* ctrlr - An instance of the SPI Slave interface to use to communicate
* with the SPI Slave device
* bus - The SPI Slave bus number. This will be used as the SPI device
* minor number. The SPI Slave character device will be
* registered as /dev/spislvN where N is the minor number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int spislave_register(FAR struct spi_sctrlr_s *sctrlr, int bus)
int spi_slave_register(FAR struct spi_slave_ctrlr_s *ctrlr, int bus)
{
FAR struct spislave_driver_s *priv;
FAR struct spi_slave_driver_s *priv;
char devname[DEVNAME_FMTLEN];
int ret;
/* Sanity check */
DEBUGASSERT(sctrlr != NULL && (unsigned int)bus < 1000);
DEBUGASSERT(ctrlr != NULL && (unsigned int)bus < 1000);
/* Initialize the SPI Slave device structure */
priv = (FAR struct spislave_driver_s *)
kmm_zalloc(sizeof(struct spislave_driver_s));
priv = (FAR struct spi_slave_driver_s *)
kmm_zalloc(sizeof(struct spi_slave_driver_s));
if (!priv)
{
spierr("ERROR: Failed to allocate instance\n");
@@ -592,7 +594,7 @@ int spislave_register(FAR struct spi_sctrlr_s *sctrlr, int bus)
}
priv->dev.ops = &g_spisdev_ops;
priv->sctrlr = sctrlr;
priv->ctrlr = ctrlr;
#ifdef CONFIG_SPI_SLAVE_DRIVER_COLORIZE_TX_BUFFER
memset(priv->tx_buffer,
@@ -618,7 +620,7 @@ int spislave_register(FAR struct spi_sctrlr_s *sctrlr, int bus)
kmm_free(priv);
}
SPI_SCTRLR_BIND(priv->sctrlr, (FAR struct spi_sdev_s *)priv,
SPIS_CTRLR_BIND(priv->ctrlr, (FAR struct spi_slave_dev_s *)priv,
CONFIG_SPI_SLAVE_DRIVER_MODE,
CONFIG_SPI_SLAVE_DRIVER_WIDTH);
+84 -83
View File
@@ -45,7 +45,7 @@
/* Access macros ************************************************************/
/****************************************************************************
* Name: SPI_SCTRLR_BIND
* Name: SPIS_CTRLR_BIND
*
* Description:
* Bind the SPI slave device interface to the SPI slave controller
@@ -54,22 +54,22 @@
* transfers.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* sdev - SPI slave device interface instance
* mode - The SPI mode requested
* nbits - The number of bits requests.
* If value is greater than 0, then it implies MSB first
* If value is less than 0, then it implies LSB first with -nbits
* ctrlr - SPI Slave controller interface instance
* dev - SPI Slave device interface instance
* mode - The SPI Slave mode requested
* nbits - The number of bits requested.
* If value is greater than 0, then it implies MSB first
* If value is less than 0, then it implies LSB first with -nbits
*
* Returned Value:
* None.
*
****************************************************************************/
#define SPI_SCTRLR_BIND(c,d,m,n) ((c)->ops->bind(c,d,m,n))
#define SPIS_CTRLR_BIND(c,d,m,n) ((c)->ops->bind(c,d,m,n))
/****************************************************************************
* Name: SPI_SCTRLR_UNBIND
* Name: SPIS_CTRLR_UNBIND
*
* Description:
* Un-bind the SPI slave device interface from the SPI slave controller
@@ -77,17 +77,17 @@
* controller driver to its initial state.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* None.
*
****************************************************************************/
#define SPI_SCTRLR_UNBIND(c) ((c)->ops->unbind(c))
#define SPIS_CTRLR_UNBIND(c) ((c)->ops->unbind(c))
/****************************************************************************
* Name: SPI_SCTRLR_ENQUEUE
* Name: SPIS_CTRLR_ENQUEUE
*
* Description:
* Enqueue the next value to be shifted out from the interface. This adds
@@ -95,43 +95,43 @@
* effect on any in-process or currently "committed" transfers.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* data - Pointer to the command/data mode data to be shifted out.
* The data width must be aligned to the nbits parameter which was
* previously provided to the bind() method.
* len - Number of units of "nbits" wide to enqueue,
* "nbits" being the data width previously provided to the bind()
* method.
* ctrlr - SPI Slave controller interface instance
* data - Pointer to the command/data mode data to be shifted out.
* The data width must be aligned to the nbits parameter which was
* previously provided to the bind() method.
* len - Number of units of "nbits" wide to enqueue,
* "nbits" being the data width previously provided to the bind()
* method.
*
* Returned Value:
* Number of data items successfully queued, or a negated errno:
* - "len" if all the data was successfully queued
* - "0..len-1" if queue is full
* - "-errno" in any other error
* - "len" if all the data was successfully queued
* - "0..len-1" if queue is full
* - "-errno" in any other error
*
****************************************************************************/
#define SPI_SCTRLR_ENQUEUE(c,v,l) ((c)->ops->enqueue(c,v,l))
#define SPIS_CTRLR_ENQUEUE(c,v,l) ((c)->ops->enqueue(c,v,l))
/****************************************************************************
* Name: SPI_SCTRLR_QFULL
* Name: SPIS_CTRLR_QFULL
*
* Description:
* Return true if the queue is full or false if there is space to add an
* additional word to the queue.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* true if the output queue is full, false otherwise.
*
****************************************************************************/
#define SPI_SCTRLR_QFULL(c) ((c)->ops->qfull(c))
#define SPIS_CTRLR_QFULL(c) ((c)->ops->qfull(c))
/****************************************************************************
* Name: SPI_SCTRLR_QFLUSH
* Name: SPIS_CTRLR_QFLUSH
*
* Description:
* Discard all saved values in the output queue. On return from this
@@ -139,22 +139,22 @@
* "committed" output values may not be flushed.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* None.
*
****************************************************************************/
#define SPI_SCTRLR_QFLUSH(c) ((c)->ops->qflush(c))
#define SPIS_CTRLR_QFLUSH(c) ((c)->ops->qflush(c))
/****************************************************************************
* Name: SPI_SCTRLR_QPOLL
* Name: SPIS_CTRLR_QPOLL
*
* Description:
* Tell the controller to output all the receive queue data.
*
* This will cause 1..n SPI_SDEV_RECEIVE calls back to the slave device,
* This will cause 1..n SPIS_DEV_RECEIVE calls back to the slave device,
* offering blocks of data to the device. From each call, the slave device
* driver will return the number of data units it accepted/read out.
*
@@ -175,7 +175,7 @@
* of bytes that was offered to each receive call.
*
* Input Parameters:
* sctrlr - SPI slave controller interface instance
* ctrlr - SPI Slave controller interface instance
*
* Returned Value:
* Number of units of width "nbits" left in the RX queue. If the device
@@ -183,17 +183,17 @@
*
****************************************************************************/
#define SPI_SCTRLR_QPOLL(c) ((c)->ops->qpoll(c))
#define SPIS_CTRLR_QPOLL(c) ((c)->ops->qpoll(c))
/****************************************************************************
* Name: SPI_SDEV_SELECT
* Name: SPIS_DEV_SELECT
*
* Description:
* This is a SPI device callback that is used when the SPI controller
* driver detects any change in the chip select pin.
*
* Input Parameters:
* sdev - SPI device interface instance
* dev - SPI Slave device interface instance
* selected - Indicates whether the chip select is in active state
*
* Returned Value:
@@ -205,10 +205,10 @@
*
****************************************************************************/
#define SPI_SDEV_SELECT(d,s) ((d)->ops->select(d,s))
#define SPIS_DEV_SELECT(d,s) ((d)->ops->select(d,s))
/****************************************************************************
* Name: SPI_SDEV_CMDDATA
* Name: SPIS_DEV_CMDDATA
*
* Description:
* This is a SPI device callback that is used when the SPI controller
@@ -221,7 +221,7 @@
* current command/data selection.
*
* Input Parameters:
* sdev - SPI device interface instance
* dev - SPI Slave device interface instance
* data - True: Data is selected
*
* Returned Value:
@@ -233,10 +233,10 @@
*
****************************************************************************/
#define SPI_SDEV_CMDDATA(d,i) ((d)->ops->cmddata(d,i))
#define SPIS_DEV_CMDDATA(d,i) ((d)->ops->cmddata(d,i))
/****************************************************************************
* Name: SPI_SDEV_GETDATA
* Name: SPIS_DEV_GETDATA
*
* Description:
* This is a SPI device callback that is used when the SPI controller
@@ -249,7 +249,7 @@
* method. Normally only LCD devices distinguish command and data.
*
* Input Parameters:
* sdev - SPI device interface instance
* dev - SPI Slave device interface instance
* data - Pointer to the data buffer pointer to be shifed out.
* The device will set the data buffer pointer to the actual data
*
@@ -262,10 +262,10 @@
*
****************************************************************************/
#define SPI_SDEV_GETDATA(d,v) ((d)->ops->getdata(d,v))
#define SPIS_DEV_GETDATA(d,v) ((d)->ops->getdata(d,v))
/****************************************************************************
* Name: SPI_SDEV_RECEIVE
* Name: SPIS_DEV_RECEIVE
*
* Description:
* This is a SPI device callback that is used when the SPI controller
@@ -273,7 +273,7 @@
* synchronization by several words.
*
* Input Parameters:
* sdev - SPI device interface instance
* dev - SPI Slave device interface instance
* data - Pointer to the new data that has been shifted in
* len - Length of the new data in units of nbits wide,
* nbits being the data width previously provided to the bind()
@@ -291,7 +291,7 @@
*
****************************************************************************/
#define SPI_SDEV_RECEIVE(d,v,l) ((d)->ops->receive(d,v,l))
#define SPIS_DEV_RECEIVE(d,v,l) ((d)->ops->receive(d,v,l))
/****************************************************************************
* Public Types
@@ -299,7 +299,7 @@
/* There are two interfaces defined for the implementation of SPI slave:
*
* 1) struct spi_sctrlr_s: Defines one interface between the SPI
* 1) struct spi_slave_ctrlr_s: Defines one interface between the SPI
* slave device and the SPI slave controller hardware. This interface
* is implemented by the SPI slave device controller lower-half driver
* and is provided to the SPI slave device driver when that driver
@@ -307,7 +307,7 @@
* unique to the SPI slave implementation. The prototype is probably
* something like:
*
* FAR struct spi_sctrlr_s *xyz_spi_slave_initialize(int port);
* FAR struct spi_slave_ctrlr_s *xyz_spi_slave_initialize(int port);
*
* Given an SPI port number, this function returns an instance of the
* SPI slave controller interface.
@@ -316,24 +316,25 @@
* appear in a header file associated with the specific SPI slave
* implementation.
*
* 2) struct spi_sdev_s: Defines the second interface between the SPI
* 2) struct spi_slave_dev_s: Defines the second interface between the SPI
* slave device and the SPI slave controller hardware. This interface
* is implemented by the SPI slave device. The slave device passes this
* interface to the struct spi_sctrlr_s during initialization
* by calling the bind() method of the struct spi_sctrlr_s
* interface to the struct spi_slave_ctrlr_s during initialization
* by calling the bind() method of the struct spi_slave_ctrlr_s
* interface.
*
* The basic initialization steps are:
*
* 1) Board-specific logic calls board- or chip-specific logic to create an
* instance of the SPI slave controller interface, struct spi_sctrlr_s.
* instance of the SPI slave controller interface,
* struct spi_slave_ctrlr_s.
*
* 2) Board-specific logic then calls up_dev_initialize() to initialize
* the SPI slave device. The board-specific logic passes the instance
* of struct spi_sctrlr_s to support the initialization.
* of struct spi_slave_ctrlr_s to support the initialization.
*
* 3) The SPI slave device driver creates and initializes an instance of
* struct spi_sdev_s; it passes this instance to the bind() method of
* struct spi_slave_dev_s; it passes this instance to the bind() method of
* of the SPI slave controller interface.
*
* 4) The SPI slave controller will (1) call the slave device's select()
@@ -466,7 +467,7 @@
* solution might not be possible.
*/
enum spi_smode_e
enum spi_slave_mode_e
{
SPISLAVE_MODE0 = 0, /* CPOL=0 CPHA=0 */
SPISLAVE_MODE1, /* CPOL=0 CPHA=1 */
@@ -476,20 +477,20 @@ enum spi_smode_e
/* The SPI slave controller driver vtable */
struct spi_sctrlr_s; /* Forward reference */
struct spi_sdev_s; /* Forward reference */
struct spi_slave_ctrlr_s; /* Forward reference */
struct spi_slave_dev_s; /* Forward reference */
struct spi_sctrlrops_s
struct spi_slave_ctrlrops_s
{
CODE void (*bind)(FAR struct spi_sctrlr_s *sctrlr,
FAR struct spi_sdev_s *sdev, enum spi_smode_e mode,
int nbits);
CODE void (*unbind)(FAR struct spi_sctrlr_s *sctrlr);
CODE int (*enqueue)(FAR struct spi_sctrlr_s *sctrlr,
FAR const void *data, size_t nwords);
CODE bool (*qfull)(FAR struct spi_sctrlr_s *sctrlr);
CODE void (*qflush)(FAR struct spi_sctrlr_s *sctrlr);
CODE size_t (*qpoll)(FAR struct spi_sctrlr_s *sctrlr);
CODE void (*bind)(FAR struct spi_slave_ctrlr_s *ctrlr,
FAR struct spi_slave_dev_s *sdev,
enum spi_slave_mode_e mode, int nbits);
CODE void (*unbind)(FAR struct spi_slave_ctrlr_s *ctrlr);
CODE int (*enqueue)(FAR struct spi_slave_ctrlr_s *ctrlr,
FAR const void *data, size_t nwords);
CODE bool (*qfull)(FAR struct spi_slave_ctrlr_s *ctrlr);
CODE void (*qflush)(FAR struct spi_slave_ctrlr_s *ctrlr);
CODE size_t (*qpoll)(FAR struct spi_slave_ctrlr_s *ctrlr);
};
/* SPI slave controller private data. This structure only defines the
@@ -498,22 +499,22 @@ struct spi_sctrlrops_s
* the vtable structure pointer.
*/
struct spi_sctrlr_s
struct spi_slave_ctrlr_s
{
FAR const struct spi_sctrlrops_s *ops;
FAR const struct spi_slave_ctrlrops_s *ops;
/* Private SPI slave controller driver data may follow */
};
/* The SPI slave device driver vtable */
struct spi_sdevops_s
struct spi_slave_devops_s
{
CODE void (*select)(FAR struct spi_sdev_s *sdev, bool selected);
CODE void (*cmddata)(FAR struct spi_sdev_s *sdev, bool data);
CODE size_t (*getdata)(FAR struct spi_sdev_s *sdev,
CODE void (*select)(FAR struct spi_slave_dev_s *sdev, bool selected);
CODE void (*cmddata)(FAR struct spi_slave_dev_s *sdev, bool data);
CODE size_t (*getdata)(FAR struct spi_slave_dev_s *sdev,
FAR const void **data);
CODE size_t (*receive)(FAR struct spi_sdev_s *sdev,
CODE size_t (*receive)(FAR struct spi_slave_dev_s *sdev,
FAR const void *data, size_t nwords);
};
@@ -523,9 +524,9 @@ struct spi_sdevops_s
* the vtable structure pointer.
*/
struct spi_sdev_s
struct spi_slave_dev_s
{
FAR const struct spi_sdevops_s *ops;
FAR const struct spi_slave_devops_s *ops;
/* Private SPI slave device driver data may follow */
};
@@ -543,17 +544,17 @@ struct spi_sdev_s
****************************************************************************/
/****************************************************************************
* Name: spislave_register
* Name: spi_slave_register
*
* Description:
* Register the SPI Slave echo character device as 'devpath'.
* Register the SPI Slave character device driver as 'devpath'.
*
* Input Parameters:
* sctrlr - An instance of the SPI Slave interface to use to communicate
* with the SPI Slave echo device
* bus - The SPI Slave bus number. This will be used as the SPI device
* minor number. The SPI Slave character device will be
* registered as /dev/spislvN where N is the minor number
* ctrlr - An instance of the SPI Slave interface to use to communicate
* with the SPI Slave device
* bus - The SPI Slave bus number. This will be used as the SPI device
* minor number. The SPI Slave character device will be
* registered as /dev/spislvN where N is the minor number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
@@ -561,7 +562,7 @@ struct spi_sdev_s
****************************************************************************/
#ifdef CONFIG_SPI_SLAVE_DRIVER
int spislave_register(FAR struct spi_sctrlr_s *sctrlr, int bus);
int spi_slave_register(FAR struct spi_slave_ctrlr_s *ctrlr, int bus);
#endif /* CONFIG_SPI_SLAVE_DRIVER */
#undef EXTERN