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/11/06 10:14:15 UTC
[incubator-nuttx] 01/02: drivers/spi:Define SPI_~CS~_DELAY_CONTROL
to support other delays
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 040a04241e31a404104efca22c87ceaeafb5549f
Author: David Sidrane <Da...@NscDg.com>
AuthorDate: Fri Nov 5 09:54:40 2021 -0700
drivers/spi:Define SPI_~CS~_DELAY_CONTROL to support other delays
---
arch/arm/src/samv7/sam_spi.c | 15 +++++++++------
arch/risc-v/src/bl602/bl602_spi.c | 8 +++++---
arch/risc-v/src/mpfs/mpfs_spi.c | 2 +-
arch/z80/src/ez80/ez80_spi.c | 2 +-
boards/arm/kinetis/freedom-k66f/configs/nsh/defconfig | 2 +-
drivers/spi/Kconfig | 18 ++++++++++++------
drivers/spi/spi_transfer.c | 4 ++--
include/nuttx/spi/spi.h | 9 +++++----
include/nuttx/spi/spi_transfer.h | 3 ++-
9 files changed, 38 insertions(+), 25 deletions(-)
diff --git a/arch/arm/src/samv7/sam_spi.c b/arch/arm/src/samv7/sam_spi.c
index 99e05a2..fad6b7e 100644
--- a/arch/arm/src/samv7/sam_spi.c
+++ b/arch/arm/src/samv7/sam_spi.c
@@ -254,9 +254,9 @@ static int spi_lock(struct spi_dev_s *dev, bool lock);
static void spi_select(struct spi_dev_s *dev, uint32_t devid,
bool selected);
static uint32_t spi_setfrequency(struct spi_dev_s *dev, uint32_t frequency);
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
static int spi_setdelay(struct spi_dev_s *dev, uint32_t a, uint32_t b,
- uint32_t c);
+ uint32_t c, uint32_t i);
#endif
#ifdef CONFIG_SPI_HWFEATURES
static int spi_hwfeatures(struct spi_dev_s *dev, uint8_t features);
@@ -311,7 +311,7 @@ static const struct spi_ops_s g_spi0ops =
.lock = spi_lock,
.select = spi_select,
.setfrequency = spi_setfrequency,
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
.setdelay = spi_setdelay,
#endif
.setmode = spi_setmode,
@@ -353,7 +353,7 @@ static const struct spi_ops_s g_spi1ops =
.lock = spi_lock,
.select = spi_select,
.setfrequency = spi_setfrequency,
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
.setdelay = spi_setdelay,
#endif
.setmode = spi_setmode,
@@ -1105,15 +1105,17 @@ static uint32_t spi_setfrequency(struct spi_dev_s *dev, uint32_t frequency)
* startdelay - The delay between CS active and first CLK
* stopdelay - The delay between last CLK and CS inactive
* csdelay - The delay between CS inactive and CS active again
+ * ifdelay - The delay between frames
*
* Returned Value:
* Returns 0 if ok
*
****************************************************************************/
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
static int spi_setdelay(struct spi_dev_s *dev, uint32_t startdelay,
- uint32_t stopdelay, uint32_t csdelay)
+ uint32_t stopdelay, uint32_t csdelay,
+ uint32_t ifdelay)
{
struct sam_spics_s *spics = (struct sam_spics_s *)dev;
struct sam_spidev_s *spi = spi_device(spics);
@@ -1126,6 +1128,7 @@ static int spi_setdelay(struct spi_dev_s *dev, uint32_t startdelay,
spiinfo("cs=%d startdelay=%d\n", spics->cs, startdelay);
spiinfo("cs=%d stopdelay=%d\n", spics->cs, stopdelay);
spiinfo("cs=%d csdelay=%d\n", spics->cs, csdelay);
+ spiinfo("cs=%d ifdelay=%d\n", spics->if, ifdelay);
offset = (unsigned int)g_csroffset[spics->cs];
diff --git a/arch/risc-v/src/bl602/bl602_spi.c b/arch/risc-v/src/bl602/bl602_spi.c
index f4ef650..3f18cdc 100644
--- a/arch/risc-v/src/bl602/bl602_spi.c
+++ b/arch/risc-v/src/bl602/bl602_spi.c
@@ -196,7 +196,7 @@ static const struct spi_ops_s bl602_spi_ops =
.lock = bl602_spi_lock,
.select = bl602_spi_select,
.setfrequency = bl602_spi_setfrequency,
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
.setdelay = bl602_spi_setdelay,
#endif
.setmode = bl602_spi_setmode,
@@ -518,6 +518,7 @@ static uint32_t bl602_spi_setfrequency(struct spi_dev_s *dev,
* startdelay - The delay between CS active and first CLK
* stopdelay - The delay between last CLK and CS inactive
* csdelay - The delay between CS inactive and CS active again
+ * ifdelay - The delay between frames
*
* Returned Value:
* Returns zero (OK) on success; a negated errno value is return on any
@@ -525,9 +526,10 @@ static uint32_t bl602_spi_setfrequency(struct spi_dev_s *dev,
*
****************************************************************************/
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
static int bl602_spi_setdelay(struct spi_dev_s *dev, uint32_t startdelay,
- uint32_t stopdelay, uint32_t csdelay)
+ uint32_t stopdelay, uint32_t csdelay,
+ uint32_t ifdelay)
{
spierr("SPI CS delay control not supported\n");
DEBUGPANIC();
diff --git a/arch/risc-v/src/mpfs/mpfs_spi.c b/arch/risc-v/src/mpfs/mpfs_spi.c
index 6b58016..e5f7ce8 100644
--- a/arch/risc-v/src/mpfs/mpfs_spi.c
+++ b/arch/risc-v/src/mpfs/mpfs_spi.c
@@ -193,7 +193,7 @@ static const struct spi_ops_s mpfs_spi_ops =
.lock = mpfs_spi_lock,
.select = mpfs_spi_select,
.setfrequency = mpfs_spi_setfrequency,
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
.setdelay = mpfs_spi_setdelay,
#endif
.setmode = mpfs_spi_setmode,
diff --git a/arch/z80/src/ez80/ez80_spi.c b/arch/z80/src/ez80/ez80_spi.c
index 90976cf..b37d025 100644
--- a/arch/z80/src/ez80/ez80_spi.c
+++ b/arch/z80/src/ez80/ez80_spi.c
@@ -95,7 +95,7 @@ static const struct spi_ops_s g_spiops =
spi_lock, /* lock() */
ez80_spiselect, /* select(): Provided externally by board logic */
spi_setfrequency, /* setfrequency() */
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
NULL, /* setdelay() */
#endif
spi_setmode,
diff --git a/boards/arm/kinetis/freedom-k66f/configs/nsh/defconfig b/boards/arm/kinetis/freedom-k66f/configs/nsh/defconfig
index a3cded4..2576647 100644
--- a/boards/arm/kinetis/freedom-k66f/configs/nsh/defconfig
+++ b/boards/arm/kinetis/freedom-k66f/configs/nsh/defconfig
@@ -92,7 +92,7 @@ CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SERIAL_TERMIOS=y
-CONFIG_SPI_CS_DELAY_CONTROL=y
+CONFIG_SPI_DELAY_CONTROL=y
CONFIG_STACK_COLORATION=y
CONFIG_SYSTEM_I2CTOOL=y
CONFIG_SYSTEM_NSH=y
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 4743ede..f5c7f64 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -163,14 +163,20 @@ config SPI_BITORDER
Enables capability to select MSB- or LSB-first hardware feature for
data transfers.
-config SPI_CS_DELAY_CONTROL
- bool "SPI CS Delay Control"
+config SPI_DELAY_CONTROL
+ bool "SPI Delay Control"
default n
---help---
- Enables possibilities to define the SPI-ChipSelect-Delays like
- time between ChipSelect assertion and first Data-Bit, the time
- between the last Data-Bit and the de-assertion and the minimum
- delay between two ChipSelects.
+ Enables possibilities to define the SPI Delays such as
+ SPI-ChipSelect-Delays and inter frame delays.
+
+ SPI-ChipSelect-Delays: are the delay between ChipSelect assertion
+ and first Data-Bit, the delay between the last Data-Bit and the
+ de-assertion and the minimum delay between two ChipSelects.
+
+ The inter-frame delays also know as Inter-Data Idleness, controls the
+ delay between frames. (one transaction of nbits as configured with
+ SPI_SETBITS).
This option enables the setdelay() interface method.
diff --git a/drivers/spi/spi_transfer.c b/drivers/spi/spi_transfer.c
index ceaa9ed..82d1e70 100644
--- a/drivers/spi/spi_transfer.c
+++ b/drivers/spi/spi_transfer.c
@@ -72,8 +72,8 @@ int spi_transfer(FAR struct spi_dev_s *spi, FAR struct spi_sequence_s *seq)
SPI_SETFREQUENCY(spi, seq->frequency);
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
- ret = SPI_SETDELAY(spi, seq->a, seq->b, seq->c);
+#ifdef CONFIG_SPI_DELAY_CONTROL
+ ret = SPI_SETDELAY(spi, seq->a, seq->b, seq->c, seq->i);
if (ret < 0)
{
spierr("ERROR: SPI_SETDELAY failed: %d\n", ret);
diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h
index 3c50ed7..98889d9 100644
--- a/include/nuttx/spi/spi.h
+++ b/include/nuttx/spi/spi.h
@@ -124,6 +124,7 @@
* startdelay - The delay between CS active and first CLK
* stopdelay - The delay between last CLK and CS inactive
* csdelay - The delay between CS inactive and CS active again
+ * ifdelay - The delay between frames
*
* Returned Value:
* Returns zero (OK) on success; a negated errno value is return on any
@@ -131,8 +132,8 @@
*
****************************************************************************/
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
-# define SPI_SETDELAY(d,a,b,c) ((d)->ops->setdelay(d,a,b,c))
+#ifdef CONFIG_SPI_DELAY_CONTROL
+# define SPI_SETDELAY(d,a,b,c,i) ((d)->ops->setdelay(d,a,b,c,i))
#endif
/****************************************************************************
@@ -543,9 +544,9 @@ struct spi_ops_s
bool selected);
CODE uint32_t (*setfrequency)(FAR struct spi_dev_s *dev,
uint32_t frequency);
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
CODE int (*setdelay)(FAR struct spi_dev_s *dev, uint32_t a,
- uint32_t b, uint32_t c);
+ uint32_t b, uint32_t c, uint32_t i);
#endif
CODE void (*setmode)(FAR struct spi_dev_s *dev, enum spi_mode_e mode);
CODE void (*setbits)(FAR struct spi_dev_s *dev, int nbits);
diff --git a/include/nuttx/spi/spi_transfer.h b/include/nuttx/spi/spi_transfer.h
index c9f2342..a3ea58e 100644
--- a/include/nuttx/spi/spi_transfer.h
+++ b/include/nuttx/spi/spi_transfer.h
@@ -100,10 +100,11 @@ struct spi_sequence_s
uint8_t nbits; /* Number of bits */
uint8_t ntrans; /* Number of transactions */
uint32_t frequency; /* SPI frequency (Hz) */
-#ifdef CONFIG_SPI_CS_DELAY_CONTROL
+#ifdef CONFIG_SPI_DELAY_CONTROL
uint32_t a; /* Arguments to setdelay() */
uint32_t b;
uint32_t c;
+ uint32_t i;
#endif
/* A pointer to the list of transfers to be be performed. */