Created
September 22, 2020 07:51
-
-
Save MathiasKoch/1f070458054d1e3811d53b49be0b6f93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Decompiled by Procyon v0.5.32 | |
// | |
package com.st.microxplorer.plugins.ip.i2c.gui; | |
import java.util.ArrayList; | |
import org.apache.log4j.Logger; | |
public class I2cTimingTraitement implements I2cConstants | |
{ | |
static final Logger log; | |
public int[] SCLL_T; | |
public int[] SCLH_T; | |
public int[] SCLDEL_T; | |
public int[] SDADEL_T; | |
public int[] PRESC_T; | |
public int[] PRESC_VALID_T; | |
ArrayList<I2cModel> PrescSDLDELSCLDEL_possiblecombination; | |
public double[] TFALL_MAX_T; | |
public double[] TRISE_MAX_T; | |
public double[] THDDAT_MAX_T; | |
public double[] TSUDAT_MIN_T; | |
public double[] TLOW_MIN; | |
public double[] THIGH_MIN; | |
public double I2C_TargetSpeed; | |
public double TI2C_TargetSpeed; | |
public double SCLDEL_tmp1; | |
public double SDADEL_tmp; | |
public double CLK_MAX; | |
public double CLK_MIN; | |
public int idx; | |
public double I2C_CLK; | |
public double TI2C_CLK; | |
public double AF_delay; | |
public int DNF_N; | |
public double DNF_delay; | |
public double Filter_Delay; | |
public double Rise_Time; | |
public double Fall_Time; | |
public double SDADEL_MIN_tmp; | |
public double SDADEL_MAX_tmp; | |
public double SCLDEL_MIN_tmp; | |
public int N_VALID; | |
public int PRESC_tmp; | |
public I2cTimingTraitement(final String I2CSpeedMode, final int speedFrequence, final double ClockSource, final int DNF_N, final int RiseTime, final int FallTime, final String AnalogFilter) { | |
this.SCLL_T = new int[256]; | |
this.SCLH_T = new int[256]; | |
this.SCLDEL_T = new int[16]; | |
this.SDADEL_T = new int[16]; | |
this.PRESC_T = new int[16]; | |
this.PRESC_VALID_T = new int[16]; | |
this.PrescSDLDELSCLDEL_possiblecombination = new ArrayList<I2cModel>(); | |
this.TFALL_MAX_T = new double[3]; | |
this.TRISE_MAX_T = new double[3]; | |
this.THDDAT_MAX_T = new double[3]; | |
this.TSUDAT_MIN_T = new double[3]; | |
this.TLOW_MIN = new double[3]; | |
this.THIGH_MIN = new double[3]; | |
boolean AF = false; | |
if (AnalogFilter.equals("I2C_ANALOGFILTER_ENABLED") || AnalogFilter.equals("I2C_ANALOGFILTER_ENABLE") || AnalogFilter.equals("SMBUS_ANALOGFILTER_ENABLE") || AnalogFilter.equals("SMBUS_ANALOGFILTER_ENABLED") || AnalogFilter.equals("FMPI2C_ANALOGFILTER_ENABLE")) { | |
AF = true; | |
} | |
for (int i = 0; i < 256; ++i) { | |
this.SCLL_T[i] = i; | |
this.SCLH_T[i] = i; | |
} | |
for (int i = 0; i < 16; ++i) { | |
this.PRESC_T[i] = i; | |
this.SCLDEL_T[i] = i; | |
this.SDADEL_T[i] = i; | |
this.PRESC_VALID_T[i] = 99; | |
} | |
this.TFALL_MAX_T[0] = I2cTimingTraitement.TFALL_MAX_T0; | |
this.TFALL_MAX_T[1] = I2cTimingTraitement.TFALL_MAX_T1; | |
this.TFALL_MAX_T[2] = I2cTimingTraitement.TFALL_MAX_T2; | |
this.TRISE_MAX_T[0] = I2cTimingTraitement.TRISE_MAX_T0; | |
this.TRISE_MAX_T[1] = I2cTimingTraitement.TRISE_MAX_T1; | |
this.TRISE_MAX_T[2] = I2cTimingTraitement.TRISE_MAX_T2; | |
this.THDDAT_MAX_T[0] = I2cTimingTraitement.THDDAT_MAX_T0; | |
this.THDDAT_MAX_T[1] = I2cTimingTraitement.THDDAT_MAX_T1; | |
this.THDDAT_MAX_T[2] = I2cTimingTraitement.THDDAT_MAX_T2; | |
this.TSUDAT_MIN_T[0] = I2cTimingTraitement.TSUDAT_MIN_T0; | |
this.TSUDAT_MIN_T[1] = I2cTimingTraitement.TSUDAT_MIN_T1; | |
this.TSUDAT_MIN_T[2] = I2cTimingTraitement.TSUDAT_MIN_T2; | |
this.TLOW_MIN[0] = I2cTimingTraitement.TLOW_MIN0; | |
this.TLOW_MIN[1] = I2cTimingTraitement.TLOW_MIN1; | |
this.TLOW_MIN[2] = I2cTimingTraitement.TLOW_MIN2; | |
this.THIGH_MIN[0] = I2cTimingTraitement.THIGH_MIN0; | |
this.THIGH_MIN[1] = I2cTimingTraitement.THIGH_MIN1; | |
this.THIGH_MIN[2] = I2cTimingTraitement.THIGH_MIN2; | |
this.I2C_TargetSpeed = speedFrequence * 1000; | |
this.TI2C_TargetSpeed = 1.0 / this.I2C_TargetSpeed; | |
this.CLK_MAX = this.I2C_TargetSpeed + this.I2C_TargetSpeed * 0.2; | |
this.CLK_MIN = this.I2C_TargetSpeed - this.I2C_TargetSpeed * 0.2; | |
this.I2C_CLK = ClockSource; | |
this.TI2C_CLK = 1.0 / (this.I2C_CLK * 1000.0); | |
if (I2CSpeedMode.equals("I2C_Standard") || I2CSpeedMode.equals("FMPI2C_Standard")) { | |
this.idx = 0; | |
} | |
if (I2CSpeedMode.equals("I2C_Fast") || I2CSpeedMode.equals("FMPI2C_Fast")) { | |
this.idx = 1; | |
} | |
if (I2CSpeedMode.equals("I2C_Fast_Plus") || I2CSpeedMode.equals("FMPI2C_Fast_Plus")) { | |
this.idx = 2; | |
} | |
if (AF) { | |
this.AF_delay = 50.0 / Math.pow(10.0, 9.0) * 1.0; | |
} | |
else { | |
this.AF_delay = 50.0 / Math.pow(10.0, 9.0) * 0.0; | |
} | |
this.DNF_N = DNF_N; | |
this.DNF_delay = DNF_N * this.TI2C_CLK; | |
this.Filter_Delay = this.AF_delay + this.DNF_delay; | |
this.Rise_Time = RiseTime / Math.pow(10.0, 9.0); | |
this.Fall_Time = FallTime / Math.pow(10.0, 9.0); | |
this.SDADEL_MIN_tmp = this.Fall_Time - 50.0 / Math.pow(10.0, 9.0) - (DNF_N + 3) * this.TI2C_CLK; | |
this.SDADEL_MAX_tmp = this.THDDAT_MAX_T[this.idx] - this.Rise_Time - 1.0 * (260.0 / Math.pow(10.0, 9.0)) - (DNF_N + 4) * this.TI2C_CLK; | |
if (this.SDADEL_MAX_tmp < 0.0) { | |
this.SDADEL_MAX_tmp = 0.0; | |
} | |
if (this.SDADEL_MIN_tmp < 0.0) { | |
this.SDADEL_MIN_tmp = 0.0; | |
} | |
this.SCLDEL_MIN_tmp = this.Rise_Time + this.TSUDAT_MIN_T[this.idx]; | |
if (this.SCLDEL_MIN_tmp < 0.0) { | |
this.SCLDEL_MIN_tmp = 0.0; | |
} | |
this.N_VALID = 0; | |
this.PRESC_tmp = 99; | |
} | |
public void CalculSDLDEL_SCLDEL() { | |
for (int i1 = 0; i1 < 16; ++i1) { | |
for (int i2 = 0; i2 < 16; ++i2) { | |
this.SCLDEL_tmp1 = (this.SCLDEL_T[i2] + 1) * ((this.PRESC_T[i1] + 1) * this.TI2C_CLK); | |
for (int i3 = 0; i3 < 16; ++i3) { | |
this.SDADEL_tmp = this.SDADEL_T[i3] * ((this.PRESC_T[i1] + 1) * this.TI2C_CLK); | |
if (this.SDADEL_tmp >= this.SDADEL_MIN_tmp && this.SDADEL_tmp <= this.SDADEL_MAX_tmp && this.SCLDEL_tmp1 >= this.SCLDEL_MIN_tmp) { | |
if (this.PRESC_T[i1] != this.PRESC_tmp) { | |
this.PRESC_VALID_T[this.N_VALID] = this.PRESC_T[i1]; | |
this.PRESC_tmp = this.PRESC_VALID_T[this.N_VALID]; | |
++this.N_VALID; | |
final I2cModel resultat = new I2cModel(i1, i3, i2, 1.0); | |
this.PrescSDLDELSCLDEL_possiblecombination.add(resultat); | |
} | |
} | |
else { | |
final I2cModel i2cModel = new I2cModel(i1, i3, i2, 0.0); | |
} | |
} | |
} | |
} | |
} | |
public String calculeSCLL_SCLH() { | |
this.CalculSDLDEL_SCLDEL(); | |
int l = 0; | |
double Solution = 0.0; | |
double PRESC_R = 99.0; | |
int SDADEL = 0; | |
int SCLDEL = 0; | |
int i1_Sel = 0; | |
int i2_Sel = 0; | |
int i3_Sel = 0; | |
double Error_target = 0.2; | |
final double TSYNC = this.Filter_Delay + 2.0 * this.TI2C_CLK; | |
if (this.N_VALID != 0) { | |
for (int i3 = this.N_VALID - 1; i3 >= 0; --i3) { | |
for (int i4 = 0; i4 < 256; ++i4) { | |
for (int i5 = 0; i5 < 256; ++i5) { | |
final double PRESC = (this.PRESC_VALID_T[i3] + 1) * this.TI2C_CLK; | |
double TSCL_LOW = (this.SCLL_T[i4] + 1) * PRESC; | |
double TSCL_HIGH = (this.SCLH_T[i5] + 1) * PRESC; | |
TSCL_LOW += TSYNC; | |
TSCL_HIGH += TSYNC; | |
final double TSCL = TSCL_LOW + TSCL_HIGH + this.Rise_Time + this.Fall_Time; | |
final double Speed = 1.0 / TSCL; | |
I2cModel s; | |
if (Speed >= this.CLK_MIN && Speed <= this.CLK_MAX && TSCL_LOW >= this.TLOW_MIN[this.idx] && TSCL_HIGH >= this.THIGH_MIN[this.idx] && this.TI2C_CLK < (TSCL_LOW - this.Filter_Delay) / 4.0 && this.TI2C_CLK < TSCL_HIGH) { | |
final double Error_tmp = (Speed - this.I2C_TargetSpeed) / this.I2C_TargetSpeed; | |
if (Error_tmp < 0.0) { | |
final double x = 0.0 - Error_tmp; | |
s = new I2cModel(i4, i5, i3, x); | |
} | |
else { | |
s = new I2cModel(i4, i5, i3, Error_tmp); | |
} | |
} | |
else { | |
s = new I2cModel(i4, i5, i3, 1.0); | |
} | |
if (s.resultat <= Error_target && this.PRESC_VALID_T[i3] <= PRESC_R) { | |
PRESC_R = this.PRESC_VALID_T[i3]; | |
Solution = 1.0; | |
Error_target = s.resultat; | |
i1_Sel = i4; | |
i2_Sel = i5; | |
i3_Sel = i3; | |
} | |
} | |
} | |
} | |
int x2 = 0; | |
for (int i6 = 0; i6 < 16; ++i6) { | |
for (int i7 = 0; i7 < 16; ++i7) { | |
for (int j = 0; j < this.PrescSDLDELSCLDEL_possiblecombination.size(); ++j) { | |
if (this.PrescSDLDELSCLDEL_possiblecombination.get(j).resultat == 1.0 && this.PrescSDLDELSCLDEL_possiblecombination.get(j).prescaler == this.PRESC_VALID_T[i3_Sel] && this.PrescSDLDELSCLDEL_possiblecombination.get(j).SDLDEL == i6 && this.PrescSDLDELSCLDEL_possiblecombination.get(j).SCLDEL == i7 && x2 == 0) { | |
l = this.PRESC_VALID_T[i3_Sel]; | |
SDADEL = i6; | |
SCLDEL = i7; | |
++x2; | |
} | |
} | |
} | |
} | |
} | |
this.PrescSDLDELSCLDEL_possiblecombination.clear(); | |
String resultat = "0x00000000"; | |
if (Solution == 1.0) { | |
final String spresc = Integer.toHexString(this.PRESC_VALID_T[i3_Sel]); | |
final String sSDADEL = Integer.toHexString(SDADEL); | |
final String sSCLDEL = Integer.toHexString(SCLDEL); | |
String sscl = Integer.toHexString(i1_Sel); | |
String ssdl = Integer.toHexString(i2_Sel); | |
if (i1_Sel < 16) { | |
sscl = "0" + sscl; | |
} | |
if (i2_Sel < 16) { | |
ssdl = "0" + ssdl; | |
} | |
resultat = spresc + "0" + sSCLDEL + sSDADEL + ssdl + sscl; | |
resultat = "0x" + resultat.toUpperCase(); | |
I2cTimingTraitement.log.info((Object)resultat); | |
} | |
return resultat; | |
} | |
static { | |
log = Logger.getLogger(I2cTimingTraitement.class.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment