drivers/spi/spi_bitbang.c: Fix typos and nxstyle complaints.
This commit is contained in:
parent
bd82486f1c
commit
530cad304f
4 changed files with 48 additions and 36 deletions
|
@ -93,7 +93,7 @@
|
|||
|
||||
/* Calibration value for timing loop */
|
||||
|
||||
#define SPI_BITBAND_LOOPSPERMSEC CONFIG_BOARD_LOOPSPERMSEC
|
||||
#define SPI_BITBANG_LOOPSPERMSEC CONFIG_BOARD_LOOPSPERMSEC
|
||||
|
||||
/* SPI_PERBIT_NSEC is the minimum time to transfer one bit. This determines
|
||||
* the maximum frequency and is also used to calculate delays to achieve
|
||||
|
@ -275,7 +275,8 @@ int sam_sdinitialize(int minor)
|
|||
ret = mmcsd_spislotinitialize(minor, SAM34_MMCSDSLOTNO, spi);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to bind bit bang SPI device to MMC/SD slot %d: %d\n",
|
||||
ferr("ERROR: Failed to bind bit bang SPI device"
|
||||
" to MMC/SD slot %d: %d\n",
|
||||
SAM34_MMCSDSLOTNO, ret);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@
|
|||
|
||||
/* Calibration value for timing loop */
|
||||
|
||||
#define SPI_BITBAND_LOOPSPERMSEC CONFIG_BOARD_LOOPSPERMSEC
|
||||
#define SPI_BITBANG_LOOPSPERMSEC CONFIG_BOARD_LOOPSPERMSEC
|
||||
|
||||
/* SPI_PERBIT_NSEC is the minimum time to transfer one bit. This determines
|
||||
* the maximum frequency and is also used to calculate delays to achieve
|
||||
|
|
|
@ -55,8 +55,8 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* This file holds the static, device-independ portion of the generica SPI-
|
||||
* bit-bang driver. The full driver consists of 5 files:
|
||||
/* This file holds the static, device-independent portion of the generic
|
||||
* SPI-bit-bang driver. The full driver consists of 5 files:
|
||||
*
|
||||
* 1. drivers/spi/spi_bitbang.c: This file. This file holds the basic
|
||||
* SPI driver framework and not perform any direct bit-bang operations.
|
||||
|
@ -68,17 +68,17 @@
|
|||
* 3. boards/<arch>/<chip>/<board>/src/<file>: The implementation of the
|
||||
* low-level bit-bang logic resides in some file in the board source
|
||||
* directory. This board-specific logic includes the bit-bang skeleton
|
||||
* logic provided in include/nuttx/spi/spi_bitband.c.
|
||||
* 4. include/nuttx/spi/spi_bitband.c. Despite the .c extension, this
|
||||
* logic provided in include/nuttx/spi/spi_bitbang.c.
|
||||
* 4. include/nuttx/spi/spi_bitbang.c. Despite the .c extension, this is
|
||||
* really an included file. It is used in this way: 1) The board-
|
||||
* specific logic in boards/<arch>/<chip>/<board>/src/<file> provides
|
||||
* some definitions then 2) includes include/nuttx/spi/spi_bitband.c.
|
||||
* some definitions then 2) includes include/nuttx/spi/spi_bitbang.c.
|
||||
* That file will then use those definitions to implement the low-level
|
||||
* bit-bang logic. the board-specific logic then calls
|
||||
* bit-bang logic. The board-specific logic then calls
|
||||
* spi_create_bitbang() in this file to instantiate the complete SPI
|
||||
* driver.
|
||||
*
|
||||
* See include/nuttx/spi/spi_bitband.c for more detailed usage
|
||||
* See include/nuttx/spi/spi_bitbang.c for more detailed usage
|
||||
* information.
|
||||
*/
|
||||
|
||||
|
|
|
@ -44,7 +44,9 @@
|
|||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Usage ********************************************************************/
|
||||
|
||||
/* To use this logic, you should provide a C file that does the following:
|
||||
*
|
||||
* - Defines SPI_SETSCK and SPI_CLRSCK to set and clear the SCK signal
|
||||
|
@ -53,12 +55,12 @@
|
|||
* - Defines SPI_PERBIT_NSEC which is the minimum time to transfer one bit.
|
||||
* This determines the maximum frequency.
|
||||
* - Other configuration options:
|
||||
* SPI_BITBAND_LOOPSPERMSEC - Delay loop calibration
|
||||
* SPI_BITBANG_LOOPSPERMSEC - Delay loop calibration
|
||||
* SPI_BITBANG_DISABLEMODE0 - Define to disable Mode 0 support
|
||||
* SPI_BITBANG_DISABLEMODE1 - Define to disable Mode 1 support
|
||||
* SPI_BITBANG_DISABLEMODE2 - Define to disable Mode 2 support
|
||||
* SPI_BITBANG_DISABLEMODE3 - Define to disable Mode 3 support
|
||||
* - Provide implementations of spi_select(), spi_status(), and spi_cmddata().
|
||||
* - Provide implementations of spi_select(), spi_status() and spi_cmddata().
|
||||
* - Then include this file
|
||||
* - Provide an initialization function that initializes the GPIO pins used
|
||||
* in the bit bang interface and calls spi_create_bitbang().
|
||||
|
@ -115,6 +117,7 @@ static const struct spi_bitbang_ops_s g_spiops =
|
|||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: spi_delay
|
||||
*
|
||||
|
@ -122,10 +125,10 @@ static const struct spi_bitbang_ops_s g_spiops =
|
|||
* Delay for a specified number of loops
|
||||
*
|
||||
* Input Parameters:
|
||||
* count - The number of loops
|
||||
* holdtime - The number of loops
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns the actual frequency selected
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -143,7 +146,7 @@ static void spi_delay(uint32_t holdtime)
|
|||
* Set the SPI frequency.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* priv - Device-specific state data
|
||||
* frequency - The SPI frequency requested
|
||||
*
|
||||
* Returned Value:
|
||||
|
@ -151,7 +154,8 @@ static void spi_delay(uint32_t holdtime)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv, uint32_t frequency)
|
||||
static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv,
|
||||
uint32_t frequency)
|
||||
{
|
||||
uint32_t pnsec;
|
||||
|
||||
|
@ -160,11 +164,14 @@ static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv, uint32_t freque
|
|||
* wait, set low, wait, set high, wait, etc.
|
||||
*
|
||||
* Here we calcalute the half period of the frequency in nanoseconds (i.e.,
|
||||
* the amount of time that the clock should remain in the high or low state).
|
||||
* the amount of time that the clock should remain in the high or low
|
||||
* state).
|
||||
*
|
||||
* frequency = psec / 1 sec psec = full period in seconds
|
||||
* frequency = psec / 1 sec
|
||||
* psec = full period in seconds
|
||||
* psec = 1 sec / frequency
|
||||
* pnsec = 1000000000 nsec / (2 * frequency) pnsec = full period in nsec
|
||||
* pnsec = 1000000000 nsec / (2 * frequency)
|
||||
* pnsec = full period in nsec
|
||||
*
|
||||
* As examples:
|
||||
* 1) frequency = 400KHz; SPI_PERBIT_NSEC = 100
|
||||
|
@ -190,41 +197,43 @@ static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv, uint32_t freque
|
|||
|
||||
pnsec = (pnsec + 1) >> 1;
|
||||
|
||||
/* But what we really want is the hold time in loop counts. We know that
|
||||
* SPI_BITBAND_LOOPSPERMSEC is the number of times through a delay loop
|
||||
/* But what we really want is the hold time in loop counts. We know that
|
||||
* SPI_BITBANG_LOOPSPERMSEC is the number of times through a delay loop
|
||||
* to get 1 millisecond.
|
||||
*
|
||||
* SPI_BITBAND_LOOPSPERMSEC / 1000000 is then the number of counts
|
||||
* SPI_BITBANG_LOOPSPERMSEC / 1000000 is then the number of counts
|
||||
* to get 1 nanosecond. In reality, this is a number less than zero. But
|
||||
* then we can use this to calculate:
|
||||
*
|
||||
* holdtime loops/hold = pnsec nsec/hold * (SPI_BITBAND_LOOPSPERMSEC / 1000000) loops/nsec
|
||||
* holdtime loops/hold = pnsec nsec/hold * (SPI_BITBANG_LOOPSPERMSEC /
|
||||
* 1000000) loops/nsec
|
||||
*
|
||||
* As examples:
|
||||
* 1) frequency = 400KHz; SPI_PERBIT_NSEC = 100; pnsec = 1200;
|
||||
* SPI_BITBAND_LOOPSPERMSEC = 5000
|
||||
* SPI_BITBANG_LOOPSPERMSEC = 5000
|
||||
* holdtime = (1200 * 5000 + 500000) / 1000000 = 6
|
||||
* 2) frequency = 20MHz; SPI_PERBIT_NSEC = 100; pnsec = 0;
|
||||
* SPI_BITBAND_LOOPSPERMSEC = 5000
|
||||
* SPI_BITBANG_LOOPSPERMSEC = 5000
|
||||
* holdtime = (0 * 5000 + 500000) / 1000000 = 0
|
||||
*/
|
||||
|
||||
priv->holdtime = (pnsec * SPI_BITBAND_LOOPSPERMSEC + 500000) / 1000000;
|
||||
priv->holdtime = (pnsec * SPI_BITBANG_LOOPSPERMSEC + 500000) / 1000000;
|
||||
|
||||
/* Let's do our best to calculate the actual frequency
|
||||
*
|
||||
* As examples:
|
||||
* 1) frequency = 400KHz; SPI_PERBIT_NSEC = 100;
|
||||
* SPI_BITBAND_LOOPSPERMSEC = 5000; holdtime = 6
|
||||
* SPI_BITBANG_LOOPSPERMSEC = 5000; holdtime = 6
|
||||
* pnsec = 2 * 1000000 * 6 / 5000 + 100 = 2500 nsec
|
||||
* frequency = 400KHz
|
||||
* 2) frequency = 20MHz; SPI_PERBIT_NSEC = 100; holdtime = 0
|
||||
* SPI_BITBAND_LOOPSPERMSEC = 5000; holdtime = 0
|
||||
* SPI_BITBANG_LOOPSPERMSEC = 5000; holdtime = 0
|
||||
* pnsec = 2 * 0 * 6 / 5000 + 100 = 100 nsec
|
||||
* frequency = 10MHz
|
||||
*/
|
||||
|
||||
pnsec = 2 * 1000000 * priv->holdtime / SPI_BITBAND_LOOPSPERMSEC + SPI_PERBIT_NSEC;
|
||||
pnsec = 2 * 1000000 * priv->holdtime / SPI_BITBANG_LOOPSPERMSEC +
|
||||
SPI_PERBIT_NSEC;
|
||||
frequency = 1000000000ul / pnsec;
|
||||
return frequency;
|
||||
}
|
||||
|
@ -236,8 +245,8 @@ static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv, uint32_t freque
|
|||
* Select the current SPI mode
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* mode - the new SPI mode
|
||||
* priv - Device-specific state data
|
||||
* mode - The new SPI mode
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
|
@ -466,8 +475,8 @@ static uint16_t spi_bitexchange2(uint16_t dataout, uint32_t holdtime)
|
|||
{
|
||||
uint16_t datain;
|
||||
|
||||
/* Here the clock is is in the resting set (high). Set MOSI output and wait
|
||||
* for the hold time
|
||||
/* Here the clock is is in the resting set (high). Set MOSI output and
|
||||
* wait for the hold time
|
||||
*/
|
||||
|
||||
if (dataout != 0)
|
||||
|
@ -568,7 +577,7 @@ static uint16_t spi_bitexchange3(uint16_t dataout, uint32_t holdtime)
|
|||
* Name: spi_exchange
|
||||
*
|
||||
* Description:
|
||||
* Exahange on word of data on SPI
|
||||
* Exahange one word of data on SPI
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - Device-specific state data
|
||||
|
@ -580,7 +589,8 @@ static uint16_t spi_bitexchange3(uint16_t dataout, uint32_t holdtime)
|
|||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SPI_BITBANG_VARWIDTH
|
||||
static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv, uint16_t dataout)
|
||||
static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv,
|
||||
uint16_t dataout)
|
||||
{
|
||||
bitexchange_t exchange = priv->exchange;
|
||||
uint32_t holdtime = priv->holdtime;
|
||||
|
@ -609,7 +619,8 @@ static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv, uint16_t dataout)
|
|||
}
|
||||
|
||||
#else
|
||||
static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv, uint16_t dataout)
|
||||
static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv,
|
||||
uint16_t dataout)
|
||||
{
|
||||
bitexchange_t exchange = priv->exchange;
|
||||
uint32_t holdtime = priv->holdtime;
|
||||
|
|
Loading…
Reference in a new issue