arch/arm/src/sam34/sam_twi.c
/*******************************************************************************
 * Name: twi_hw_initialize
 *
 * Description:
 *   Initialize one TWI peripheral for I2C operation
 *
 *******************************************************************************/
twi_hw_initialize
Description:
Initialize one TWI peripheral for I2C operation
twi_hw_initialize Description : Initialize one TWI peripheral for I2C operation
static void twi_hw_initialize(struct twi_dev_s *priv, unsigned int pid,
                              uint32_t frequency)
{
  i2cvdbg("TWI%d Initializing\n", priv->twi);
  twi_putrel(priv, SAM_TWI_CR_OFFSET, TWI_CR_SVEN);
  twi_putrel(priv, SAM_TWI_CR_OFFSET, TWI_CR_SWRST);
  (void)twi_getrel(priv, SAM_TWI_RHR_OFFSET);
  twi_putrel(priv, SAM_TWI_CR_OFFSET, TWI_CR_SVDIS);
  twi_putrel(priv, SAM_TWI_CR_OFFSET, TWI_CR_MSDIS);
  twi_putrel(priv, SAM_TWI_CR_OFFSET, TWI_CR_MSEN);
  priv->frequency = BOARD_MCK_FREQUENCY;
#if 0
  mck = BOARD_MCK_FREQUENCY;
  DEBUGASSERT((mck >> 3) <= TWI_MAX_FREQUENCY);
  if (mck <= TWI_MAX_FREQUENCY)
    {
      priv->frequency = mck;
      regval          = PMC_PCR_DIV1;
    }
  else if ((mck >> 1) <= TWI_MAX_FREQUENCY)
    {
      priv->frequency = (mck >> 1);
      regval          = PMC_PCR_DIV2;
    }
  else if ((mck >> 2) <= TWI_MAX_FREQUENCY)
    {
      priv->frequency = (mck >> 2);
      regval          = PMC_PCR_DIV4;
    }
  else 
    {
      priv->frequency = (mck >> 3);
      regval          = PMC_PCR_DIV8;
    }
  regval |= PMC_PCR_PID(pid) | PMC_PCR_CMD | PMC_PCR_EN;
  twi_putabs(priv, SAM_PMC_PCR, regval);
#endif
  (void)twi_hw_setfrequency(priv, frequency);
}
static void twi_hw_initialize ( struct twi_dev_s * priv , unsigned int pid , uint32_t frequency ) { i2cvdbg ( " \n " , priv -> twi ) ; twi_putrel ( priv , SAM_TWI_CR_OFFSET , TWI_CR_SVEN ) ; twi_putrel ( priv , SAM_TWI_CR_OFFSET , TWI_CR_SWRST ) ; ( void ) twi_getrel ( priv , SAM_TWI_RHR_OFFSET ) ; twi_putrel ( priv , SAM_TWI_CR_OFFSET , TWI_CR_SVDIS ) ; twi_putrel ( priv , SAM_TWI_CR_OFFSET , TWI_CR_MSDIS ) ; twi_putrel ( priv , SAM_TWI_CR_OFFSET , TWI_CR_MSEN ) ; priv -> frequency = BOARD_MCK_FREQUENCY ; #if 0 mck = BOARD_MCK_FREQUENCY ; DEBUGASSERT ( ( mck >> 3 ) <= TWI_MAX_FREQUENCY ) ; if ( mck <= TWI_MAX_FREQUENCY ) { priv -> frequency = mck ; regval = PMC_PCR_DIV1 ; } else if ( ( mck >> 1 ) <= TWI_MAX_FREQUENCY ) { priv -> frequency = ( mck >> 1 ) ; regval = PMC_PCR_DIV2 ; } else if ( ( mck >> 2 ) <= TWI_MAX_FREQUENCY ) { priv -> frequency = ( mck >> 2 ) ; regval = PMC_PCR_DIV4 ; } else { priv -> frequency = ( mck >> 3 ) ; regval = PMC_PCR_DIV8 ; } regval |= PMC_PCR_PID ( pid ) | PMC_PCR_CMD | PMC_PCR_EN ; twi_putabs ( priv , SAM_PMC_PCR , regval ) ; #endif ( void ) twi_hw_setfrequency ( priv , frequency ) ; }
Name: twi_hw_initialize
 Description:
   Initialize one TWI peripheral for I2C operation
Name : twi_hw_initialize Description : Initialize one TWI peripheral for I2C operation
//uint32_t regval; //uint32_t mck; /* SVEN: TWI Slave Mode Enabled */ /* Reset the TWI */ /* TWI Slave Mode Disabled, TWI Master Mode Disabled. */ /* Set master mode */ /* Set base frequency */ /* Determine the maximum valid frequency setting */ /* if ((mck >> 3) <= TWI_MAX_FREQUENCY) */ /* Set the TWI peripheral input clock to the maximum, valid frequency */ /* Set the initial TWI data transfer frequency */