arch/arm/src/imx/imx_spi.c
/****************************************************************************
 * Name: spi_transfer
 *
 * Description:
 *   Exchange a block data with the SPI device
 *
 * Input Parameters:
 *   priv   - Device-specific state data
 *   txbuffer - The buffer of data to send to the device (may be NULL).
 *   rxbuffer - The buffer to receive data from the device (may be NULL).
 *   nwords   - The total number of words to be exchanged.  If the interface
 *              uses <= 8 bits per word, then this is the number of uint8_t's;
 *              if the interface uses >8 bits per word, then this is the
 *              number of uint16_t's
 *
 * Returned Value:
 *   0: success, <0:Negated error number on failure
 *
 ****************************************************************************/
spi_transfer
Description:
Exchange a block data with the SPI device

Input Parameters:
priv   - Device-specific state data
txbuffer - The buffer of data to send to the device (may be NULL).
rxbuffer - The buffer to receive data from the device (may be NULL).
nwords   - The total number of words to be exchanged.  If the interface
uses <= 8 bits per word, then this is the number of uint8_t's;
if the interface uses >8 bits per word, then this is the
number of uint16_t's

Returned Value:
0: success, <0:Negated error number on failure
spi_transfer Description : Exchange a block data with the SPI device Input Parameters : priv - Device - specific state data txbuffer - The buffer of data to send to the device ( may be NULL ) . rxbuffer - The buffer to receive data from the device ( may be NULL ) . nwords - The total number of words to be exchanged . If the interface uses < = 8 bits per word then this is the number of uint8_t ' s ; if the interface uses > 8 bits per word then this is the number of uint16_t ' s Returned Value : 0 : success <0 : Negated error number on failure
static int spi_transfer(struct imx_spidev_s *priv, const void *txbuffer,
                        void *rxbuffer, unsigned int nwords)
{
#ifndef CONFIG_SPI_POLLWAIT
  irqstate_t flags;
  uint32_t regval;
  int ret;
#endif
  int ntxd;
  priv->txbuffer     = (uint8_t*)txbuffer; 
  priv->rxbuffer     = (uint8_t*)rxbuffer; 
  priv->ntxwords     = nwords;           
  priv->nrxwords     = 0;                
  priv->nwords       = nwords;           
  if (priv->nbits > 8)
    {
      priv->txword = spi_txuint16;
      priv->rxword =spi_rxuint16;
    }
  else
    {
      priv->txword = spi_txuint8;
      priv->rxword = spi_rxuint8;
    }
  if (!txbuffer)
    {
      priv->txword = spi_txnull;
    }
  if (!rxbuffer)
    {
      priv->rxword = spi_rxnull;
    }
#ifndef CONFIG_SPI_POLLWAIT
  flags = irqsave();
  ntxd  = spi_performtx(priv);
  spi_startxfr(priv, ntxd);
  regval = spi_getreg(priv, CSPI_INTCS_OFFSET);
  regval |= CSPI_INTCS_TEEN;
  spi_putreg(priv, CSPI_INTCS_OFFSET, regval);
  irqrestore(flags);
  do
    {
      ret = sem_wait(&priv->sem);
    }
  while (ret < 0 && errno == EINTR);
#else
  do
    {
      ntxd = spi_performtx(priv);
      spi_performrx(priv);
      spi_startxfr(priv, ntxd);
      sched_yield();
    }
  while (priv->nrxwords < priv->nwords);
#endif
  return OK;
}
static int spi_transfer ( struct imx_spidev_s * priv , const void * txbuffer , void * rxbuffer , unsigned int nwords ) { #ifndef CONFIG_SPI_POLLWAIT irqstate_t flags ; uint32_t regval ; int ret ; #endif int ntxd ; priv -> txbuffer = ( uint8_t * ) txbuffer ; priv -> rxbuffer = ( uint8_t * ) rxbuffer ; priv -> ntxwords = nwords ; priv -> nrxwords = 0 ; priv -> nwords = nwords ; if ( priv -> nbits > 8 ) { priv -> txword = spi_txuint16 ; priv -> rxword = spi_rxuint16 ; } else { priv -> txword = spi_txuint8 ; priv -> rxword = spi_rxuint8 ; } if ( ! txbuffer ) { priv -> txword = spi_txnull ; } if ( ! rxbuffer ) { priv -> rxword = spi_rxnull ; } #ifndef CONFIG_SPI_POLLWAIT flags = irqsave ( ) ; ntxd = spi_performtx ( priv ) ; spi_startxfr ( priv , ntxd ) ; regval = spi_getreg ( priv , CSPI_INTCS_OFFSET ) ; regval |= CSPI_INTCS_TEEN ; spi_putreg ( priv , CSPI_INTCS_OFFSET , regval ) ; irqrestore ( flags ) ; do { ret = sem_wait ( & priv -> sem ) ; } while ( ret < 0 && errno == EINTR ) ; #else do { ntxd = spi_performtx ( priv ) ; spi_performrx ( priv ) ; spi_startxfr ( priv , ntxd ) ; sched_yield ( ) ; } while ( priv -> nrxwords < priv -> nwords ) ; #endif return OK ; }
Name: spi_transfer
 Description:
   Exchange a block data with the SPI device
Name : spi_transfer Description : Exchange a block data with the SPI device
/* Set up to perform the transfer */ /* Source buffer */ /* Destination buffer */ /* Number of words left to send */ /* Number of words received */ /* Total number of exchanges */ /* Set up the low-level data transfer function pointers */ /* Prime the Tx FIFO to start the sequence (saves one interrupt) */ /* Enable transmit empty interrupt */ /* Wait for the transfer to complete.  Since there is no handshake
   * with SPI, the following should complete even if there are problems
   * with the transfer, so it should be safe with no timeout.
   */ /* Wait to be signaled from the interrupt handler */ /* Perform the transfer using polling logic.  This will totally
   * dominate the CPU until the transfer is complete.  Only recommended
   * if (1) your SPI is very fast, and (2) if you only use very short
   * transfers.
   */ /* Handle outgoing Tx FIFO transfers */ /* Handle incoming Rx FIFO transfers */ /* Resume the transfer */ /* If there are other threads at this same priority level,
       * the following may help:
       */