use of net.sourceforge.usbdm.deviceEditor.information.LongVariable in project usbdm-eclipse-plugins by podonoghue.
the class SimValidateMKL_lite method validateIndexVariables.
/**
* Updates
* - sim_sopt2_pllfllsel[x]
* - system_peripheral_clock[x]
* - system_core_clock[x]
* - system_bus_clock[x]
* - system_flexbus_clock[x]
* - system_flash_clock[x]
* - sim_clkdiv1_outdiv1[x]
* - sim_clkdiv1_outdiv2[x]
* - sim_clkdiv1_outdiv3[x]
* - sim_clkdiv1_outdiv4[x]
*
* @param variable
* @throws Exception
*/
void validateIndexVariables(Variable variable) throws Exception {
// ======================================
final LongVariable system_core_clockVar = getLongVariable("system_core_clock");
final LongVariable system_bus_clockVar = getLongVariable("system_bus_clock");
final LongVariable sim_clkdiv1_outdiv1Var = getLongVariable("sim_clkdiv1_outdiv1");
final LongVariable sim_clkdiv1_outdiv4Var = getLongVariable("sim_clkdiv1_outdiv4");
// Core & System Clock
// ===========================================
// Attempt to find acceptable divisor
final LongVariable system_mcgoutclk_clockVar = getLongVariable("/MCG/system_mcgoutclk_clock");
long inputFrequency = system_mcgoutclk_clockVar.getValueAsLong();
final FindDivisor coreDivisor = new FindDivisor(inputFrequency, system_core_clockVar.getValueAsLong()) {
@Override
boolean okValue(int divisor, double frequency) {
return frequency <= MAX_CORE_CLOCK_FREQ;
}
};
Severity severity = Severity.OK;
StringBuilder sb = new StringBuilder();
if (variable == system_core_clockVar) {
// Clock variable changed - replace with nearest value if found
if (coreDivisor.divisor == 0) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(coreDivisor.divisors);
system_core_clockVar.setValue(coreDivisor.nearestTargetFrequency);
system_core_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
} else {
// Clock variable not changed - just validate
if ((coreDivisor.divisor == 0) || (system_core_clockVar.getValueAsLong() != (coreDivisor.nearestTargetFrequency))) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(coreDivisor.divisors);
system_core_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
}
// Bus & Flash Clock
// ===========================================
// Attempt to find acceptable divisor
final long coreFrequency = system_core_clockVar.getValueAsLong();
inputFrequency = coreFrequency;
final FindDivisor flashDivisor = new FindDivisor(inputFrequency, system_bus_clockVar.getValueAsLong()) {
@Override
boolean okValue(int divisor, double frequency) {
return (frequency <= MAX_BUS_CLOCK_FREQ) && (frequency <= coreFrequency);
}
};
severity = Severity.OK;
sb = new StringBuilder();
if (variable == system_bus_clockVar) {
// Clock variable changed - replace with nearest value if found
if (flashDivisor.divisor == 0) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(flashDivisor.divisors);
system_bus_clockVar.setValue(flashDivisor.nearestTargetFrequency);
system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
} else {
// Clock variable not changed - just validate
if ((flashDivisor.divisor == 0) || (system_bus_clockVar.getValueAsLong() != (flashDivisor.nearestTargetFrequency))) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(flashDivisor.divisors);
system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
}
}
use of net.sourceforge.usbdm.deviceEditor.information.LongVariable in project usbdm-eclipse-plugins by podonoghue.
the class SimValidateMKL_lite method validateNonindexedVariables.
/**
* Updates
* - srcVar
* - clockVar
* - system_erclk32k_clockVar
* - sim_sopt1_osc32kselVar
* - sim_sopt2_rtcclkoutselVar
* - rtc_clkoutVar
* - system_usbfs_clockVar
*
* @param variable
* @throws Exception
*/
public void validateNonindexedVariables(Variable variable) throws Exception {
super.validate(variable);
// Clock Mapping
// =================
final String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
final LongVariable osc0_oscer_clockVar = getLongVariable(osc0_peripheral + "/oscer_clock");
final LongVariable osc0_osc32k_clockVar = getLongVariable(osc0_peripheral + "/osc32k_clock");
final String rtcclkin_clock = getStringVariable("/SIM/rtc_clkin").getValueAsString();
final LongVariable rtcclkin_clockVar = safeGetLongVariable(rtcclkin_clock);
final LongVariable rtc_1hz_clockVar = safeGetLongVariable("/RTC/rtc_1hz_clock");
final LongVariable rtc_clkoutVar = safeGetLongVariable("rtc_clkout");
// MCG
// =================
final LongVariable system_low_power_clockVar = getLongVariable("/MCG/system_low_power_clock");
final LongVariable system_mcgpclk_clockVar = getLongVariable("/MCG/system_mcgpclk_clock");
final LongVariable system_mcgirclk_clockVar = getLongVariable("/MCG/system_mcgirclk_clock");
final LongVariable system_usb_clkin_clockVar = safeGetLongVariable("/MCG/system_usb_clkin_clock");
// Check if CLKDIV3 Present
// =====================================
final Long pllPostDiv3Value;
final String pllPostDiv3Origin;
final Variable system_peripheral_postdivider_clockVar = safeGetVariable("system_peripheral_postdivider_clock");
if (system_peripheral_postdivider_clockVar != null) {
// After divider
pllPostDiv3Value = system_peripheral_postdivider_clockVar.getValueAsLong();
pllPostDiv3Origin = system_peripheral_postdivider_clockVar.getOrigin();
} else {
// Direct (no divider)
pllPostDiv3Value = system_mcgpclk_clockVar.getValueAsLong();
pllPostDiv3Origin = system_mcgpclk_clockVar.getOrigin();
}
/**
* Clock selector used for LPUARTs, TPMs and FlexIO
*/
LpClockSelector clockSelector = new LpClockSelector() {
@Override
public void lpClockSelect(String sourceVar, String clockVarId) throws Exception {
// Clock source select (if present)
// ===================================
Variable srcVar = safeGetVariable(sourceVar);
if (srcVar != null) {
Variable clockVar = getVariable(clockVarId);
switch((int) srcVar.getValueAsLong()) {
default:
srcVar.setValue(0);
case // Disabled
0:
clockVar.setValue(0);
clockVar.setStatus((Status) null);
clockVar.setOrigin("Disabled");
break;
case // Peripheral Clock / CLKDIV3
1:
clockVar.setValue(pllPostDiv3Value);
clockVar.setStatus(system_mcgpclk_clockVar.getStatus());
clockVar.setOrigin(pllPostDiv3Origin);
break;
case // OSCERCLK
2:
clockVar.setValue(osc0_oscer_clockVar.getValueAsLong());
clockVar.setStatus(osc0_oscer_clockVar.getStatus());
clockVar.setOrigin(osc0_oscer_clockVar.getOrigin());
break;
case // MCGIRCLK
3:
clockVar.setValue(system_mcgirclk_clockVar.getValueAsLong());
clockVar.setStatus(system_mcgirclk_clockVar.getStatus());
clockVar.setOrigin(system_mcgirclk_clockVar.getOrigin());
break;
}
}
}
};
// Determine ERCLK32K
// ==================================
LongVariable system_erclk32k_clockVar = getLongVariable("system_erclk32k_clock");
ChoiceVariable sim_sopt1_osc32kselVar = getChoiceVariable("sim_sopt1_osc32ksel");
switch((int) sim_sopt1_osc32kselVar.getValueAsLong()) {
case // System oscillator (OSC32KCLK)
0:
system_erclk32k_clockVar.setValue(osc0_osc32k_clockVar.getValueAsLong());
system_erclk32k_clockVar.setOrigin(osc0_osc32k_clockVar.getOrigin());
system_erclk32k_clockVar.setStatus(osc0_osc32k_clockVar.getStatus());
break;
case // RTC CLK_IN
2:
system_erclk32k_clockVar.setValue(rtcclkin_clockVar.getValueAsLong());
system_erclk32k_clockVar.setOrigin(rtcclkin_clockVar.getOrigin());
system_erclk32k_clockVar.setStatus(rtcclkin_clockVar.getStatus());
break;
default:
sim_sopt1_osc32kselVar.setValue(3);
case // LPO 1 kHz
3:
system_erclk32k_clockVar.setValue(system_low_power_clockVar.getValueAsLong());
system_erclk32k_clockVar.setOrigin(system_low_power_clockVar.getOrigin());
system_erclk32k_clockVar.setStatus(system_low_power_clockVar.getStatus());
break;
}
// RTC Clock out pin select
// ============================
BooleanVariable sim_sopt2_rtcclkoutselVar = safeGetBooleanVariable("sim_sopt2_rtcclkoutsel");
if (sim_sopt2_rtcclkoutselVar != null) {
switch((int) sim_sopt2_rtcclkoutselVar.getValueAsLong()) {
default:
sim_sopt2_rtcclkoutselVar.setValue(0);
case // RTC seconds clock = 1Hz
0:
rtc_clkoutVar.setValue(rtc_1hz_clockVar.getValueAsLong());
rtc_clkoutVar.setStatus(rtc_1hz_clockVar.getStatus());
rtc_clkoutVar.setOrigin(rtc_1hz_clockVar.getOrigin());
break;
case // OSCERCLK
1:
rtc_clkoutVar.setValue(osc0_oscer_clockVar.getValueAsLong());
rtc_clkoutVar.setStatus(osc0_oscer_clockVar.getStatus());
rtc_clkoutVar.setOrigin(osc0_oscer_clockVar.getOrigin());
break;
}
}
// UART0 Clock source select (if present)
// ==========================================
clockSelector.lpClockSelect("sim_sopt2_uart0src", "system_uart0_clock");
// LPUARTx Clock source select (if present)
// ==========================================
final String[] lpUartInstances = { "", "0", "1", "2" };
for (String lpUartInstance : lpUartInstances) {
clockSelector.lpClockSelect("sim_sopt2_lpuart" + lpUartInstance + "src", "system_lpuart" + lpUartInstance + "_clock");
}
// TPMx Clock source select (if present)
// ==========================================
final String[] tpmInstances = { "", "0", "1", "2" };
for (String tpmInstance : tpmInstances) {
clockSelector.lpClockSelect("sim_sopt2_tpm" + tpmInstance + "src", "system_tpm" + tpmInstance + "_clock");
}
// FLEXIO Clock source select (if present)
// ==========================================
clockSelector.lpClockSelect("sim_sopt2_flexiosrc", "system_flexio_clock");
// USB FS Clock source select
// ============================
ChoiceVariable sim_sopt2_usbsrcVar = safeGetChoiceVariable("sim_sopt2_usbsrc");
if (sim_sopt2_usbsrcVar != null) {
LongVariable system_usbfs_clockVar = getLongVariable("system_usbfs_clock");
if (sim_sopt2_usbsrcVar.getValueAsLong() == 0) {
// Using USB_CLKIN
system_usbfs_clockVar.setValue(system_usb_clkin_clockVar.getValueAsLong());
system_usbfs_clockVar.setStatus(system_usb_clkin_clockVar.getStatus());
system_usbfs_clockVar.setOrigin(system_usb_clkin_clockVar.getOrigin());
} else {
// MCGPCLK
system_usbfs_clockVar.setValue(system_mcgpclk_clockVar.getValueAsLong());
system_usbfs_clockVar.setStatus(system_mcgpclk_clockVar.getStatus());
system_usbfs_clockVar.setOrigin(system_mcgpclk_clockVar.getOrigin());
}
}
}
use of net.sourceforge.usbdm.deviceEditor.information.LongVariable in project usbdm-eclipse-plugins by podonoghue.
the class SimValidate_fll method validateIndexVariables.
/**
* Updates
* - system_peripheral_clock[x]
* - system_core_clock[x]
* - system_bus_clock[x]
* - system_flexbus_clock[x]
* - system_flash_clock[x]
* - sim_clkdiv1_outdiv1[x]
* - sim_clkdiv1_outdiv2[x]
* - sim_clkdiv1_outdiv3[x]
* - sim_clkdiv1_outdiv4[x]
*
* @param variable
* @throws Exception
*/
void validateIndexVariables(Variable variable) throws Exception {
// ======================================
final LongVariable system_core_clockVar = getLongVariable("system_core_clock");
final LongVariable system_bus_clockVar = getLongVariable("system_bus_clock");
final LongVariable sim_clkdiv1_outdiv1Var = getLongVariable("sim_clkdiv1_outdiv1");
final LongVariable sim_clkdiv1_outdiv4Var = getLongVariable("sim_clkdiv1_outdiv4");
// Core & System Clock
// ===========================================
// Attempt to find acceptable divisor
final LongVariable system_mcgoutclk_clockVar = getLongVariable("/MCG/system_mcgoutclk_clock");
long inputFrequency = system_mcgoutclk_clockVar.getValueAsLong();
final FindDivisor coreDivisor = new FindDivisor(inputFrequency, system_core_clockVar.getValueAsLong()) {
@Override
boolean okValue(int divisor, double frequency) {
return frequency <= MAX_CORE_CLOCK_FREQ;
}
};
Severity severity = Severity.OK;
StringBuilder sb = new StringBuilder();
if (variable == system_core_clockVar) {
// Clock variable changed - replace with nearest value if found
if (coreDivisor.divisor == 0) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(coreDivisor.divisors);
system_core_clockVar.setValue(coreDivisor.nearestTargetFrequency);
system_core_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
} else {
// Clock variable not changed - just validate
if ((coreDivisor.divisor == 0) || (system_core_clockVar.getValueAsLong() != (coreDivisor.nearestTargetFrequency))) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(coreDivisor.divisors);
system_core_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
}
// Bus & Flash Clock
// ===========================================
// Attempt to find acceptable divisor
final long coreFrequency = system_core_clockVar.getValueAsLong();
inputFrequency = coreFrequency;
final FindDivisor flashDivisor = new FindDivisor(inputFrequency, system_bus_clockVar.getValueAsLong()) {
@Override
boolean okValue(int divisor, double frequency) {
return (frequency <= MAX_BUS_CLOCK_FREQ) && (frequency <= coreFrequency);
}
};
severity = Severity.OK;
sb = new StringBuilder();
if (variable == system_bus_clockVar) {
// Clock variable changed - replace with nearest value if found
if (flashDivisor.divisor == 0) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(flashDivisor.divisors);
system_bus_clockVar.setValue(flashDivisor.nearestTargetFrequency);
system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
} else {
// Clock variable not changed - just validate
if ((flashDivisor.divisor == 0) || (system_bus_clockVar.getValueAsLong() != (flashDivisor.nearestTargetFrequency))) {
severity = Severity.ERROR;
sb.append("Illegal Frequency\n");
}
sb.append(flashDivisor.divisors);
system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
}
}
use of net.sourceforge.usbdm.deviceEditor.information.LongVariable in project usbdm-eclipse-plugins by podonoghue.
the class TpmValidate method validate.
/**
* Class to determine LPTMR settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
// =================================
LongVariable system_tpm_clockVar = getLongVariable("/SIM/system_tpm_clock");
DoubleVariable clockFrequencyVar = getDoubleVariable("clockFrequency");
DoubleVariable clockPeriodVar = getDoubleVariable("clockPeriod");
ChoiceVariable tpm_sc_cmodVar = getChoiceVariable("tpm_sc_cmod");
ChoiceVariable tpm_sc_psVar = getChoiceVariable("tpm_sc_ps");
LongVariable tpm_modVar = getLongVariable("tpm_mod");
DoubleVariable tpm_mod_periodVar = getDoubleVariable("tpm_mod_period");
BooleanVariable tpm_sc_cpwmsVar = getBooleanVariable("tpm_sc_cpwms");
LongVariable clockSourceVar = null;
switch((int) tpm_sc_cmodVar.getValueAsLong()) {
case 0:
case 3:
clockSourceVar = new LongVariable("Disabled", "/Tpm/Disabled");
clockSourceVar.setOrigin("Disabled");
clockSourceVar.setValue(0);
break;
default:
tpm_sc_cmodVar.setValue(1);
case 1:
clockSourceVar = system_tpm_clockVar;
break;
case 2:
clockSourceVar = getLongVariable("tpmExternalClock");
;
break;
}
double clockFrequency = clockSourceVar.getValueAsDouble();
String clockOrigin = clockSourceVar.getOrigin();
clockFrequency = clockFrequency / (1L << tpm_sc_psVar.getValueAsLong());
clockFrequencyVar.setValue(clockFrequency);
clockFrequencyVar.setOrigin(clockOrigin + " frequency / prescaler");
clockFrequencyVar.setStatus(clockSourceVar.getFilteredStatus());
clockPeriodVar.setOrigin(clockOrigin + " period * prescaler");
clockPeriodVar.setStatus(clockSourceVar.getFilteredStatus());
clockFrequencyVar.enable(clockFrequency != 0);
clockPeriodVar.enable(clockFrequency != 0);
tpm_mod_periodVar.enable(clockFrequency != 0);
if (clockFrequency != 0) {
long tpm_mod = tpm_modVar.getValueAsLong();
double clockPeriod = 1.0 / clockFrequency;
clockPeriodVar.setValue(clockPeriod);
boolean tpm_sc_cpwms = tpm_sc_cpwmsVar.getValueAsBoolean();
double tpm_mod_period = clockPeriod * (tpm_sc_cpwms ? (2 * (tpm_mod)) : ((tpm_mod + 1)));
if (variable != null) {
// Update selectively
if (variable.equals(tpm_mod_periodVar)) {
tpm_mod_period = tpm_mod_periodVar.getValueAsDouble();
// Calculate rounded value
if (tpm_sc_cpwms) {
tpm_mod = Math.max(0, Math.round((tpm_mod_period / clockPeriod) / 2));
} else {
tpm_mod = Math.max(0, Math.round((tpm_mod_period / clockPeriod) - 1));
}
tpm_mod_period = clockPeriod * (tpm_sc_cpwms ? (2 * (tpm_mod)) : ((tpm_mod + 1)));
// Update
tpm_modVar.setValue(tpm_mod);
}
}
double tpm_mod_periodMax = clockPeriod * (tpm_sc_cpwms ? (2 * (65535.5)) : ((65536.5)));
tpm_mod_periodVar.setValue(tpm_mod_period);
tpm_mod_periodVar.setMax(tpm_mod_periodMax);
}
}
use of net.sourceforge.usbdm.deviceEditor.information.LongVariable in project usbdm-eclipse-plugins by podonoghue.
the class OscRfValidate method validate.
/**
* Class to determine oscillator settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
// OSC
// =================================
ChoiceVariable osc_input_freqVar = getChoiceVariable("osc_input_freq");
LongVariable oscclk_clockVar = getLongVariable("osc_clock");
LongVariable oscerclk_clockVar = getLongVariable("oscer_clock");
long oscclk_clock_freq = Integer.parseInt(osc_input_freqVar.getSubstitutionValue());
oscclk_clockVar.setValue(oscclk_clock_freq);
oscclk_clockVar.setOrigin("RF Oscillator");
oscclk_clockVar.setStatus((Status) null);
oscerclk_clockVar.setValue(oscclk_clock_freq);
oscerclk_clockVar.setOrigin("RF Oscillator");
oscerclk_clockVar.setStatus((Status) null);
}
Aggregations