Make bit-order SPI H/W feature configurable for better error detection

This commit is contained in:
Gregory Nutt 2016-08-08 11:54:13 -06:00
parent c3cfd37791
commit 6df28bc74e
9 changed files with 44 additions and 9 deletions

View File

@ -1082,6 +1082,7 @@ static void spi_setbits(struct spi_dev_s *dev, int nbits)
#ifdef CONFIG_SPI_HWFEATURES #ifdef CONFIG_SPI_HWFEATURES
static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features)
{ {
#ifdef CONFIG_SPI_BITORDER
struct efm32_spidev_s *priv = (struct efm32_spidev_s *)dev; struct efm32_spidev_s *priv = (struct efm32_spidev_s *)dev;
const struct efm32_spiconfig_s *config; const struct efm32_spiconfig_s *config;
uint32_t regval; uint32_t regval;
@ -1124,6 +1125,9 @@ static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features)
/* Other H/W features are not supported */ /* Other H/W features are not supported */
return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS; return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS;
#else
return -ENOSYS;
#endif
} }
#endif #endif

View File

@ -1221,6 +1221,7 @@ static int spi_setdelay(struct spi_dev_s *dev, uint32_t startdelay,
#ifdef CONFIG_SPI_HWFEATURES #ifdef CONFIG_SPI_HWFEATURES
static int spi_hwfeatures(struct spi_dev_s *dev, uint8_t features) static int spi_hwfeatures(struct spi_dev_s *dev, uint8_t features)
{ {
#ifdef CONFIG_SPI_CS_CONTROL
struct sam_spics_s *spics = (struct sam_spics_s *)dev; struct sam_spics_s *spics = (struct sam_spics_s *)dev;
struct sam_spidev_s *spi = spi_device(spics); struct sam_spidev_s *spi = spi_device(spics);
uint32_t regval; uint32_t regval;
@ -1280,7 +1281,10 @@ static int spi_hwfeatures(struct spi_dev_s *dev, uint8_t features)
spi->escape_lastxfer = false; spi->escape_lastxfer = false;
} }
return 0; return ((features & ~HWFEAT_FORCE_CS_CONTROL_MASK) == 0) ? OK : -ENOSYS;
#else
return -ENOSYS;
#endif
} }
#endif #endif

View File

@ -1198,6 +1198,7 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits)
#ifdef CONFIG_SPI_HWFEATURES #ifdef CONFIG_SPI_HWFEATURES
static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features)
{ {
#ifdef CONFIG_SPI_BITORDER
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev; FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev;
uint16_t setbits; uint16_t setbits;
uint16_t clrbits; uint16_t clrbits;
@ -1224,6 +1225,9 @@ static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features)
/* Other H/W features are not supported */ /* Other H/W features are not supported */
return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS; return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS;
#else
return -ENOSYS;
#endif
} }
#endif #endif

View File

@ -1301,6 +1301,7 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits)
#ifdef CONFIG_SPI_HWFEATURES #ifdef CONFIG_SPI_HWFEATURES
static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features)
{ {
#ifdef CONFIG_SPI_BITORDER
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev; FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev;
uint16_t setbitscr1; uint16_t setbitscr1;
uint16_t clrbitscr1; uint16_t clrbitscr1;
@ -1330,6 +1331,9 @@ static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features)
/* Other H/W features are not supported */ /* Other H/W features are not supported */
return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS; return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS;
#else
return -ENOSYS;
#endif
} }
#endif #endif

View File

@ -1165,6 +1165,7 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits)
#ifdef CONFIG_SPI_HWFEATURES #ifdef CONFIG_SPI_HWFEATURES
static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features)
{ {
#ifdef CONFIG_SPI_BITORDER
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev; FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev;
uint16_t setbits; uint16_t setbits;
uint16_t clrbits; uint16_t clrbits;
@ -1191,6 +1192,9 @@ static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features)
/* Other H/W features are not supported */ /* Other H/W features are not supported */
return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS; return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS;
#else
return -ENOSYS;
#endif
} }
#endif #endif

View File

@ -59,10 +59,12 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* H/W features must be enabled in order to support LSB first operation */ /* Bit order H/W feature must be enabled in order to support LSB first
* operation.
*/
#ifndef CONFIG_SPI_HWFEATURES #if !defined(CONFIG_SPI_HWFEATURES) || !defined(CONFIG_SPI_BITORDER)
# error CONFIG_SPI_HWFEATURES=y required by this driver # error CONFIG_SPI_HWFEATURES=y and CONFIG_SPI_BITORDER=y required by this driver
#endif #endif
/* Cisplay resolution */ /* Cisplay resolution */

View File

@ -72,6 +72,14 @@ config SPI_CS_CONTROL
Enables possibilities to define the behavior of CS. Enables possibilities to define the behavior of CS.
Also enables the hwfeatures() interface method. Also enables the hwfeatures() interface method.
config SPI_BITORDER
bool "SPI Bit Order Control"
default n
select SPI_HWFEATURES
---help---
Enables capability to select MSB- or LSB-first hardware feature for
data transfers.
config SPI_CS_DELAY_CONTROL config SPI_CS_DELAY_CONTROL
bool "SPI CS Delay Control" bool "SPI CS Delay Control"
default n default n

View File

@ -57,10 +57,12 @@
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/ /* Configuration ************************************************************/
/* H/W features must be enabled in order to support LSB first operation */ /* Bit order H/W feature must be enabled in order to support LSB first
* operation.
*/
#ifndef CONFIG_SPI_HWFEATURES #if !defined(CONFIG_SPI_HWFEATURES) || !defined(CONFIG_SPI_BITORDER)
# error CONFIG_SPI_HWFEATURES=y required by this driver # error CONFIG_SPI_HWFEATURES=y and CONFIG_SPI_BITORDER=y required by this driver
#endif #endif
#ifdef CONFIG_WL_PN532_DEBUG #ifdef CONFIG_WL_PN532_DEBUG

View File

@ -232,13 +232,16 @@
# endif # endif
# ifdef CONFIG_SPI_CS_CONTROL # ifdef CONFIG_SPI_CS_CONTROL
# define HWFEAT_FORCE_CS_CONTROL_MASK (7 << 1)
# define HWFEAT_FORCE_CS_INACTIVE_AFTER_TRANSFER (1 << 1) # define HWFEAT_FORCE_CS_INACTIVE_AFTER_TRANSFER (1 << 1)
# define HWFEAT_FORCE_CS_ACTIVE_AFTER_TRANSFER (1 << 2) # define HWFEAT_FORCE_CS_ACTIVE_AFTER_TRANSFER (1 << 2)
# define HWFEAT_ESCAPE_LASTXFER (1 << 3) # define HWFEAT_ESCAPE_LASTXFER (1 << 3)
# endif # endif
# define HWFEAT_MSBFIRST (0 << 4) # ifdef CONFIG_SPI_BITORDER
# define HWFEAT_LSBFIRST (1 << 4) # define HWFEAT_MSBFIRST (0 << 4)
# define HWFEAT_LSBFIRST (1 << 4)
# endif
#else #else
/* Any attempt to select hardware features with CONFIG_SPI_HWFEATURES /* Any attempt to select hardware features with CONFIG_SPI_HWFEATURES