use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable 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.ChoiceVariable 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.ChoiceVariable in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method parseChoiceOption.
/**
* Parse <choiceOption> element<br>
*
* @param varElement
* @throws Exception
*/
private void parseChoiceOption(BaseModel parent, Element varElement) throws Exception {
ChoiceVariable variable = (ChoiceVariable) parseCommonAttributes(parent, varElement, ChoiceVariable.class).getVariable();
parseChoices(variable, varElement);
}
use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable 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);
}
use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable in project usbdm-eclipse-plugins by podonoghue.
the class OscValidate method validate.
/**
* Class to determine oscillator settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
// OSC
// =================================
BooleanVariable osc_cr_erclkenVar = getBooleanVariable("osc_cr_erclken");
BooleanVariable mcg_c2_erefs0Var = getBooleanVariable("/MCG/mcg_c2_erefs0");
BooleanVariable mcg_c2_hgo0Var = getBooleanVariable("/MCG/mcg_c2_hgo0");
ChoiceVariable osc_cr_scpVar = getChoiceVariable("osc_cr_scp");
Variable osc_cr_erefstenVar = getVariable("osc_cr_erefsten");
Variable oscillatorRangeVar = getVariable("oscillatorRange");
LongVariable system_oscer_undiv_clockVar = safeGetLongVariable("oscer_undiv_clock");
LongVariable system_oscer_clockVar = null;
if (system_oscer_undiv_clockVar == null) {
system_oscer_undiv_clockVar = getLongVariable("oscer_clock");
} else {
system_oscer_clockVar = getLongVariable("oscer_clock");
}
ChoiceVariable osc_div_erpsVar = safeGetChoiceVariable("osc_div_erps");
LongVariable osc32k_clockVar = getLongVariable("osc32k_clock");
LongVariable osc_clockVar = getLongVariable("osc_clock");
LongVariable osc_input_freqVar = getLongVariable("osc_input_freq");
// Check if RTC has control of oscillator pins
boolean rtcForcing = getVariable("/SIM/rtcSharesPins").getValueAsBoolean() && getBooleanVariable("/RTC/rtc_cr_osce").getValueAsBoolean();
String rangeOrigin = "Unused";
int range = UNCONSTRAINED_RANGE;
if (rtcForcing) {
// RTC controlling XTAL pins
Status rtcInUseMessage = new Status("Feature is controlled by RTC which shares XTAL/EXTAL pins", Severity.WARNING);
oscillatorRangeVar.enable(false);
oscillatorRangeVar.setStatus(rtcInUseMessage);
osc_cr_erclkenVar.enable(false);
osc_cr_erclkenVar.setStatus(rtcInUseMessage);
osc_cr_erefstenVar.enable(false);
osc_cr_erefstenVar.setStatus(rtcInUseMessage);
osc_cr_scpVar.enable(false);
osc_cr_scpVar.setStatus(rtcInUseMessage);
mcg_c2_erefs0Var.enable(false);
mcg_c2_erefs0Var.setStatus(rtcInUseMessage);
mcg_c2_hgo0Var.enable(false);
mcg_c2_hgo0Var.setStatus(rtcInUseMessage);
rangeOrigin = "Determined by RTC";
range = 0;
} else {
// OSC controlling XTAL pins
oscillatorRangeVar.enable(true);
oscillatorRangeVar.clearStatus();
osc_cr_erclkenVar.enable(true);
osc_cr_erclkenVar.clearStatus();
osc_cr_erefstenVar.enable(osc_cr_erclkenVar.getValueAsBoolean());
osc_cr_erefstenVar.clearStatus();
mcg_c2_erefs0Var.enable(true);
mcg_c2_erefs0Var.clearStatus();
osc_input_freqVar.clearStatus();
String oscclk_clockOrg;
Status oscclk_clockStatus = null;
boolean oscillatorInUse = mcg_c2_erefs0Var.getValueAsBoolean();
long osc_input_freq = osc_input_freqVar.getValueAsLong();
if (oscillatorInUse) {
// Using oscillator - range is chosen to suit crystal frequency (or forced by RTC)
if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE1_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE1_MAX)) {
oscclk_clockOrg = "OSCCLK (low range oscillator)";
rangeOrigin = "Determined by Crystal Frequency";
range = 0;
} else if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE2_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE2_MAX)) {
oscclk_clockOrg = "OSCCLK (high range oscillator)";
rangeOrigin = "Determined by Crystal Frequency";
range = 1;
} else if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE3_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE3_MAX)) {
oscclk_clockOrg = "OSCCLK (very high range oscillator)";
rangeOrigin = "Determined by Crystal Frequency";
range = 2;
} else {
// Not suitable as OSC Crystal frequency
oscclk_clockOrg = "OSCCLK (invalid range)";
oscclk_clockStatus = FLL_CLOCK_ERROR_MSG;
range = UNCONSTRAINED_RANGE;
}
} else {
// Using external clock
oscclk_clockOrg = "OSCCLK (External clock)";
// Range has no effect on Oscillator
range = UNCONSTRAINED_RANGE;
// Check suitable clock range
if (osc_input_freq > EXTERNAL_CLOCK_MAX) {
// Not suitable as external clock
oscclk_clockStatus = CLOCK_RANGE_ERROR_MSG;
}
}
osc_cr_scpVar.enable(oscillatorInUse);
osc_cr_scpVar.clearStatus();
mcg_c2_hgo0Var.enable(oscillatorInUse);
mcg_c2_hgo0Var.clearStatus();
boolean oscclkOK = (oscclk_clockStatus == null) || oscclk_clockStatus.getSeverity().lessThan(Severity.WARNING);
osc_clockVar.setOrigin(oscclk_clockOrg);
osc_clockVar.setStatus(oscclk_clockStatus);
osc_clockVar.setValue(oscclkOK ? osc_input_freq : 0);
osc_clockVar.enable(oscclkOK);
}
oscillatorRangeVar.setValue(range);
oscillatorRangeVar.setOrigin(rangeOrigin);
// Check suitability of OSC for OSC32KCLK
// =========================================
// Initially assume suitable
long osc32kclk_clockFreq = osc_clockVar.getValueAsLong();
Status osc32kclk_clockStatus = osc_clockVar.getStatus();
String osc32kclk_clockOrg = osc_clockVar.getOrigin();
if ((osc32kclk_clockFreq < EXTERNAL_EXTAL_RANGE1_MIN) || (osc32kclk_clockFreq > EXTERNAL_EXTAL_RANGE1_MAX)) {
if ((osc32kclk_clockStatus == null) || osc32kclk_clockStatus.lessThan(Severity.ERROR)) {
osc32kclk_clockStatus = new Status(OSCCLK32K_CLOCK_MSG, Severity.WARNING);
}
osc32kclk_clockOrg = osc32kclk_clockOrg + "(invalid range)";
}
osc32k_clockVar.setValue((osc32kclk_clockStatus != null) ? 0 : osc32kclk_clockFreq);
osc32k_clockVar.setStatus(osc32kclk_clockStatus);
osc32k_clockVar.setOrigin(osc32kclk_clockOrg);
// Determine OSCERCLK, OSCERCLK_UNDIV
// ==================================
long osc_clockFreq = osc_clockVar.getValueAsLong();
String osc_clockOrg = osc_clockVar.getOrigin();
if (osc_cr_erclkenVar.getValueAsBoolean()) {
// Oscillator/clock enabled
system_oscer_undiv_clockVar.setValue(osc_clockFreq);
system_oscer_undiv_clockVar.setStatus(osc_clockVar.getFilteredStatus());
system_oscer_undiv_clockVar.setOrigin(osc_clockVar.getOrigin());
system_oscer_undiv_clockVar.enable(true);
long system_oscerclk = osc_clockFreq;
if (osc_div_erpsVar != null) {
// If divider exists
system_oscerclk /= 1 << osc_div_erpsVar.getValueAsLong();
osc_clockOrg += "/osc_div_erps";
system_oscer_clockVar.setValue(system_oscerclk);
system_oscer_clockVar.setStatus(osc_clockVar.getFilteredStatus());
system_oscer_clockVar.setOrigin(osc_clockVar.getOrigin());
system_oscer_clockVar.enable(true);
osc_div_erpsVar.enable(true);
}
} else {
Status osc_crMessage = new Status("Disabled by osc_cr_erclken", Severity.OK);
// Oscillator/clock disabled
// system_oscerclk_undiv_clockVar.setValue(0);
system_oscer_undiv_clockVar.setStatus(osc_crMessage);
system_oscer_undiv_clockVar.setOrigin(osc_clockOrg);
system_oscer_undiv_clockVar.enable(false);
if (osc_div_erpsVar != null) {
// system_oscer_clockVar.setValue(0);
system_oscer_clockVar.setStatus(osc_crMessage);
system_oscer_clockVar.setOrigin(osc_clockOrg);
system_oscer_clockVar.enable(false);
osc_div_erpsVar.enable(false);
}
}
// Warn if EXTAL and XTAL signals not mapped
validateMappedPins(new int[] { 0, 1 }, getPeripheral().getSignalTables().get(0).table);
}
Aggregations