Platform/ECM3532/M3/hw/csp/ecm3532/m3/csp/src/eta_csp_i2c.c
/***************************************************************************/
/**
 *
 * EtaCspI2cSpeedConfig - Configure the speed for the I2C module.
 *
 * @param iNum the I2C number.
 * @param iClockSpeed the I2C clock speed
 * @return the status.
 *
 ******************************************************************************/
Configure the speed for the I2C module.
@param iNum the I2C number.
@param iClockSpeed the I2C clock speed
@return the status.
Configure the speed for the I2C module . @param iNum the I2C number . @param iClockSpeed the I2C clock speed @return the status .
tEtaStatus
EtaCspI2cSpeedConfig(tI2cNum iNum, tI2cClk iClockSpeed)
{
    char CYCLE_TIME;
    char IBG_TIME;
    char PE_TIME;
    char NE_TIME;
    char TX_TIME;
    char RX_TIME;
    char MIN_SCL_HI;
    char SCL_HYSTERSIS_LEVEL;
    char SDA_HYSTERSIS_LEVEL;
    char TEMP_TIME;
     Use algorithm for lower speed interfaces.
    if(iClockSpeed < 500)
    {
        CYCLE_TIME = (4000 / iClockSpeed) - 1;  4MHz source clock.
        IBG_TIME = CYCLE_TIME;
        TEMP_TIME = ((400 - iClockSpeed) / 3);
        PE_TIME = 4 + ((TEMP_TIME * (16 - 4))) / 100;
        NE_TIME = 8 + ((TEMP_TIME * (31 - 8))) / 100;
        RX_TIME = 5 + ((TEMP_TIME * (25 - 5))) / 100;
        TX_TIME = 1 + ((TEMP_TIME * (1  - 1))) / 100;
        MIN_SCL_HI = 0 + ((TEMP_TIME * (4 - 0))) / 100;
        SCL_HYSTERSIS_LEVEL = 1 + ((TEMP_TIME * (8 - 1))) / 100;
        SDA_HYSTERSIS_LEVEL = 1 + ((TEMP_TIME * (8 - 1))) / 100;
         Enable hysteresis.
        if(SCL_HYSTERSIS_LEVEL > 0)
        {
            REGN_M1(iNum, I2C_CONFIG2, SCL_HYSTERISIS_LEVEL,
                    (16 - SCL_HYSTERSIS_LEVEL));
        }
        else
        {
            REGN_M1(iNum, I2C_CONFIG2, DISABLE_SCL_HYSTERSIS, 1);
        }
         Enable hysteresis.
        if(SDA_HYSTERSIS_LEVEL > 0)
        {
            REGN_M1(iNum, I2C_CONFIG2, SDA_HYSTERISIS_LEVEL,
                    (16 - SDA_HYSTERSIS_LEVEL));
        }
        else
        {
            REGN_M1(iNum, I2C_CONFIG2, DISABLE_SDA_HYSTERSIS, 1);
        }
    }
     If (iClockSpeed >= 500) Use prerecorded values.
    else
    {
        CYCLE_TIME = 3;
        IBG_TIME = CYCLE_TIME;
        PE_TIME = 1;
        NE_TIME = 2;
        RX_TIME = 3;
        TX_TIME = 0;
        MIN_SCL_HI = 0;
         Disable Hysteresis.
        SCL_HYSTERSIS_LEVEL = 0;
        SDA_HYSTERSIS_LEVEL = 0;
        REGN_M1(iNum, I2C_CONFIG2, DISABLE_SCL_HYSTERSIS, 1);
        REGN_M1(iNum, I2C_CONFIG2, DISABLE_SDA_HYSTERSIS, 1);
    }
    REGN_M2(iNum, I2C_CLK_CONFIG1, IBG_TIME, IBG_TIME, CYCLE_TIME,
            CYCLE_TIME);
    REGN_M2(iNum, I2C_CLK_CONFIG2, TX_TIME, TX_TIME, RX_TIME, RX_TIME);
    REGN_M2(iNum, I2C_CLK_CONFIG3, PE_TIME, PE_TIME, NE_TIME, NE_TIME);
    REGN_M1(iNum, I2C_SCL_CONFIG, MIN_SCL_HIGH, MIN_SCL_HI);
    return(eEtaSuccess);
}
tEtaStatus EtaCspI2cSpeedConfig ( tI2cNum iNum , tI2cClk iClockSpeed ) { char CYCLE_TIME ; char IBG_TIME ; char PE_TIME ; char NE_TIME ; char TX_TIME ; char RX_TIME ; char MIN_SCL_HI ; char SCL_HYSTERSIS_LEVEL ; char SDA_HYSTERSIS_LEVEL ; char TEMP_TIME ; if ( iClockSpeed < 500 ) { CYCLE_TIME = ( 4000 / iClockSpeed ) - 1 ; IBG_TIME = CYCLE_TIME ; TEMP_TIME = ( ( 400 - iClockSpeed ) / 3 ) ; PE_TIME = 4 + ( ( TEMP_TIME * ( 16 - 4 ) ) ) / 100 ; NE_TIME = 8 + ( ( TEMP_TIME * ( 31 - 8 ) ) ) / 100 ; RX_TIME = 5 + ( ( TEMP_TIME * ( 25 - 5 ) ) ) / 100 ; TX_TIME = 1 + ( ( TEMP_TIME * ( 1 - 1 ) ) ) / 100 ; MIN_SCL_HI = 0 + ( ( TEMP_TIME * ( 4 - 0 ) ) ) / 100 ; SCL_HYSTERSIS_LEVEL = 1 + ( ( TEMP_TIME * ( 8 - 1 ) ) ) / 100 ; SDA_HYSTERSIS_LEVEL = 1 + ( ( TEMP_TIME * ( 8 - 1 ) ) ) / 100 ; if ( SCL_HYSTERSIS_LEVEL > 0 ) { REGN_M1 ( iNum , I2C_CONFIG2 , SCL_HYSTERISIS_LEVEL , ( 16 - SCL_HYSTERSIS_LEVEL ) ) ; } else { REGN_M1 ( iNum , I2C_CONFIG2 , DISABLE_SCL_HYSTERSIS , 1 ) ; } if ( SDA_HYSTERSIS_LEVEL > 0 ) { REGN_M1 ( iNum , I2C_CONFIG2 , SDA_HYSTERISIS_LEVEL , ( 16 - SDA_HYSTERSIS_LEVEL ) ) ; } else { REGN_M1 ( iNum , I2C_CONFIG2 , DISABLE_SDA_HYSTERSIS , 1 ) ; } } else { CYCLE_TIME = 3 ; IBG_TIME = CYCLE_TIME ; PE_TIME = 1 ; NE_TIME = 2 ; RX_TIME = 3 ; TX_TIME = 0 ; MIN_SCL_HI = 0 ; SCL_HYSTERSIS_LEVEL = 0 ; SDA_HYSTERSIS_LEVEL = 0 ; REGN_M1 ( iNum , I2C_CONFIG2 , DISABLE_SCL_HYSTERSIS , 1 ) ; REGN_M1 ( iNum , I2C_CONFIG2 , DISABLE_SDA_HYSTERSIS , 1 ) ; } REGN_M2 ( iNum , I2C_CLK_CONFIG1 , IBG_TIME , IBG_TIME , CYCLE_TIME , CYCLE_TIME ) ; REGN_M2 ( iNum , I2C_CLK_CONFIG2 , TX_TIME , TX_TIME , RX_TIME , RX_TIME ) ; REGN_M2 ( iNum , I2C_CLK_CONFIG3 , PE_TIME , PE_TIME , NE_TIME , NE_TIME ) ; REGN_M1 ( iNum , I2C_SCL_CONFIG , MIN_SCL_HIGH , MIN_SCL_HI ) ; return ( eEtaSuccess ) ; }
EtaCspI2cSpeedConfig - Configure the speed for the I2C module.
EtaCspI2cSpeedConfig - Configure the speed for the I2C module .
// // Use algorithm for lower speed interfaces. // // 4MHz source clock. // // Enable hysteresis. // // // Enable hysteresis. // // // If (iClockSpeed >= 500) Use prerecorded values. // // // Disable Hysteresis. //