From 896f02bd6708b01c7e44dc38fa1d5cdcb21e76db Mon Sep 17 00:00:00 2001 From: liaoao Date: Wed, 17 Jul 2024 16:00:53 +0800 Subject: [PATCH] rpmsg_port_spi: add nbits to spicfg Support more spi config paramters for Rpmsg Port SPI/SPI Slave Signed-off-by: liaoao --- drivers/rpmsg/rpmsg_port_spi.c | 9 +++++++-- drivers/rpmsg/rpmsg_port_spi_slave.c | 18 ++++++++++++++---- include/nuttx/rpmsg/rpmsg_port.h | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/rpmsg/rpmsg_port_spi.c b/drivers/rpmsg/rpmsg_port_spi.c index 1961372621..1a2f6874a8 100644 --- a/drivers/rpmsg/rpmsg_port_spi.c +++ b/drivers/rpmsg/rpmsg_port_spi.c @@ -45,6 +45,8 @@ # define rpmsg_port_spi_crc16(hdr) 0 #endif +#define BYTES2WORDS(s,b) ((b) / ((s)->nbits >> 3)) + /**************************************************************************** * Private Types ****************************************************************************/ @@ -70,6 +72,7 @@ struct rpmsg_port_spi_s /* SPI devices' configuration */ uint32_t devid; + int nbits; /* Reserved for cmd send */ @@ -292,7 +295,8 @@ static int rpmsg_port_spi_sreq_handler(FAR struct ioexpander_dev_s *dev, rpmsginfo("irq send cmd:%u avail:%u\n", txhdr->cmd, txhdr->avail); SPI_SELECT(rpspi->spi, rpspi->devid, true); - SPI_EXCHANGE(rpspi->spi, txhdr, rpspi->rxhdr, rpspi->cmdhdr->len); + SPI_EXCHANGE(rpspi->spi, txhdr, rpspi->rxhdr, + BYTES2WORDS(rpspi, rpspi->cmdhdr->len)); rpspi->rxavail = txhdr->avail; return 0; @@ -470,7 +474,7 @@ rpmsg_port_spi_init_hardware(FAR struct rpmsg_port_spi_s *rpspi, return ret; } - SPI_SETBITS(spi, 8); + SPI_SETBITS(spi, spicfg->nbits); SPI_SETMODE(spi, spicfg->mode); SPI_SETFREQUENCY(spi, spicfg->freq); SPI_REGISTERCALLBACK(spi, rpmsg_port_spi_complete_handler, rpspi); @@ -479,6 +483,7 @@ rpmsg_port_spi_init_hardware(FAR struct rpmsg_port_spi_s *rpspi, rpspi->spi = spi; rpspi->ioe = ioe; rpspi->devid = spicfg->devid; + rpspi->nbits = spicfg->nbits; return 0; } diff --git a/drivers/rpmsg/rpmsg_port_spi_slave.c b/drivers/rpmsg/rpmsg_port_spi_slave.c index da2679a08e..6d8f0099d2 100644 --- a/drivers/rpmsg/rpmsg_port_spi_slave.c +++ b/drivers/rpmsg/rpmsg_port_spi_slave.c @@ -46,6 +46,8 @@ # define rpmsg_port_spi_crc16(hdr) 0 #endif +#define BYTES2WORDS(s,b) ((b) / ((s)->nbits >> 3)) + /**************************************************************************** * Private Types ****************************************************************************/ @@ -69,11 +71,17 @@ struct rpmsg_port_spi_s uint8_t mreq; uint8_t sreq; + /* SPI devices' configuration */ + + int nbits; + /* Reserved for cmd send */ FAR struct rpmsg_port_header_s *cmdhdr; - /* Used for sync data state between sreq_handler and complete_handler */ + /* Used for sync data state between mreq_handler and + * rpmsg_port_spi_slave_notify + */ FAR struct rpmsg_port_header_s *txhdr; FAR struct rpmsg_port_header_s *rxhdr; @@ -193,7 +201,8 @@ void rpmsg_port_spi_exchange(FAR struct rpmsg_port_spi_s *rpspi) rpmsginfo("send cmd:%u avail:%u\n", txhdr->cmd, txhdr->avail); - SPIS_CTRLR_ENQUEUE(rpspi->spictrlr, txhdr, rpspi->cmdhdr->len); + SPIS_CTRLR_ENQUEUE(rpspi->spictrlr, txhdr, + BYTES2WORDS(rpspi, rpspi->cmdhdr->len)); IOEXP_WRITEPIN(rpspi->ioe, rpspi->sreq, 1); rpspi->rxavail = txhdr->avail; @@ -277,7 +286,7 @@ static size_t rpmsg_port_spi_slave_getdata(FAR struct spi_slave_dev_s *dev, container_of(dev, struct rpmsg_port_spi_s, spislv); *data = rpspi->rxhdr; - return rpspi->cmdhdr->len; + return BYTES2WORDS(rpspi, rpspi->cmdhdr->len); } /**************************************************************************** @@ -543,7 +552,8 @@ rpmsg_port_spi_init_hardware(FAR struct rpmsg_port_spi_s *rpspi, rpspi->ioe = ioe; rpspi->spictrlr = spictrlr; rpspi->spislv.ops = &g_rpmsg_port_spi_slave_ops; - SPIS_CTRLR_BIND(spictrlr, &rpspi->spislv, spicfg->mode, 8); + SPIS_CTRLR_BIND(spictrlr, &rpspi->spislv, spicfg->mode, spicfg->nbits); + rpspi->nbits = spicfg->nbits; return 0; } diff --git a/include/nuttx/rpmsg/rpmsg_port.h b/include/nuttx/rpmsg/rpmsg_port.h index 540d8d46e9..b102ffd788 100644 --- a/include/nuttx/rpmsg/rpmsg_port.h +++ b/include/nuttx/rpmsg/rpmsg_port.h @@ -79,6 +79,7 @@ struct rpmsg_port_spi_config_s int sreq_invert; /* Pin options described in ioexpander.h */ int mode; /* Mode of enum spi_mode_e */ + int nbits; uint32_t devid; /* Device ID of enum spi_devtype_e */ uint32_t freq; /* SPI frequency (Hz) */ };