use of net.sourceforge.usbdm.deviceEditor.information.StringVariable in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method parseControlItem.
/**
* Parse element: <ul>
* <li> <fragment> referencing only elements below
* <li> <validate>
* <li> <template>
* <li> <projectActionList>
*</ul>
*
* Items found are recorded
*
* @param menuElement Menu element to parse
*
* @throws Exception
*/
private void parseControlItem(Element element) throws Exception {
String tagName = element.getTagName();
if (tagName == "fragment") {
for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
parseControlItem((Element) node);
}
} else if (tagName == "validate") {
fValidators.add(parseValidate(element));
} else if (tagName == "template") {
/**
* namespace:
* class - Template is available in
*/
String name = element.getAttribute("name");
String namespace = element.getAttribute("namespace");
if (namespace.isEmpty()) {
throw new Exception("Template is missing namespace, name='" + name + "'");
}
if (!name.isEmpty() && !namespace.equals("all")) {
throw new Exception("Named templates must have 'all' namespace, name='" + name + "'");
}
int dimension = getIntAttribute(element, "dim");
addTemplate(name, namespace, dimension, element.getTextContent().replaceAll("^\n\\s*", "").replaceAll("(\\\\n|\\n)\\s*", "\n").replaceAll("\\\\t", " "));
// System.err.println(fTemplate.toString().substring(0, 40)+"\n");
} else if (tagName == "projectActionList") {
ProjectActionList pal = PackageParser.parseRestrictedProjectActionList(element, RESOURCE_PATH);
pal.visit(new Visitor() {
@Override
public Result applyTo(ProjectAction action, Value result, IProgressMonitor monitor) {
if (action instanceof ProjectConstant) {
ProjectConstant constant = (ProjectConstant) action;
Variable var = new StringVariable(constant.getId(), constant.getId());
var.setValue(constant.getValue());
System.err.println("Adding " + var);
fProvider.addVariable(var);
}
return Visitor.CONTINUE;
}
}, null);
fProjectActionList.addProjectAction(pal);
} else {
throw new Exception("Unexpected field in parseControlItem(), value = \'" + tagName + "\'");
}
}
use of net.sourceforge.usbdm.deviceEditor.information.StringVariable in project usbdm-eclipse-plugins by podonoghue.
the class ClockValidator_MCG_no_pll method createDependencies.
@Override
protected void createDependencies() throws Exception {
// Clock Mapping
// =================
final String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
final StringVariable osc32k_peripheralVar = safeGetStringVariable("/SIM/osc32k_peripheral");
if (osc32k_peripheralVar != null) {
// RTC
addToWatchedVariables(osc32k_peripheralVar.getValueAsString() + "/osc_clock");
}
final String[] externalVariables = { osc0_peripheral + "/osc_clock", osc0_peripheral + "/osc_cr_erclken", osc0_peripheral + "/oscillatorRange" };
addToWatchedVariables(externalVariables);
}
use of net.sourceforge.usbdm.deviceEditor.information.StringVariable in project usbdm-eclipse-plugins by podonoghue.
the class ClockValidator_MK_ICS48M method validateClocks.
protected void validateClocks(Variable variable) throws Exception {
// System.err.println(getSimpleClassName()+" Var = "+variable);
super.validate(variable);
StringVariable clockConfig = safeGetStringVariable("ClockConfig");
clockConfig.setStatus(isValidCIdentifier(clockConfig.getValueAsString()) ? (String) null : "Illegal C enum value");
// OSC0 Clock monitor
// =================================
Variable mcg_c6_cme0Var = getVariable("mcg_c6_cme0");
Variable mcg_c2_locre0Var = getVariable("mcg_c2_locre0");
mcg_c2_locre0Var.enable(mcg_c6_cme0Var.getValueAsBoolean());
// OSC1 (RTC) Clock monitor
// =================================
Variable mcg_c8_cme1Var = getVariable("mcg_c8_cme1");
Variable mcg_c8_locre1Var = getVariable("mcg_c8_locre1");
mcg_c8_locre1Var.enable(mcg_c8_cme1Var.getValueAsBoolean());
// PLL monitor
// =================================
Variable mcg_c9_pll_cmeVar = safeGetVariable("mcg_c9_pll_cme");
if (mcg_c9_pll_cmeVar != null) {
getVariable("mcg_c9_pll_locre").enable(mcg_c9_pll_cmeVar.getValueAsBoolean());
}
// =================================
Variable system_irc48m_clockVar = safeGetVariable("system_irc48m_clock");
Variable system_mcgfllclk_clockVar = getVariable("system_mcgfllclk_clock");
Variable mcg_c4_dmx32Var = getVariable("mcg_c4_dmx32");
Variable mcg_c1_frdivVar = getVariable("mcg_c1_frdiv");
Variable mcg_c4_drst_drsVar = getVariable("mcg_c4_drst_drs");
Variable pll0EnabledVar = getVariable("pll0Enabled");
Variable pll0InputFrequencyVar = getVariable("pll0InputFrequency");
Variable pll0OutputFrequency = getVariable("pll0OutputFrequency");
Variable mcg_c5_pllclkenVar = getVariable("mcg_c5_pllclken");
Variable mcg_c5_pllstenVar = getVariable("mcg_c5_pllsten");
Variable mcg_c5_prdiv0Var = getVariable("mcg_c5_prdiv0");
Variable mcg_c6_vdiv0Var = getVariable("mcg_c6_vdiv0");
Variable system_mcgpllclk_clockVar = getVariable("system_mcgpllclk_clock");
Variable system_mcgoutclk_clock_sourceVar = getVariable("system_mcgoutclk_clock_source");
Variable system_mcgoutclk_clockVar = getVariable("system_mcgoutclk_clock");
Variable mcg_c1_irefsVar = getVariable("mcg_c1_irefs");
Variable mcg_c1_clksVar = getVariable("mcg_c1_clks");
Variable mcg_c2_lpVar = getVariable("mcg_c2_lp");
Variable mcg_c6_pllsVar = getVariable("mcg_c6_plls");
// Determine MCGIRCLK (not gated/undivided and gated)
// ========================================
Variable mcg_sc_fcrdivVar = safeGetVariable("mcg_sc_fcrdiv");
Variable system_fast_irc_clockVar = getVariable("system_fast_irc_clock");
Variable system_slow_irc_clockVar = getVariable("system_slow_irc_clock");
Variable mcg_c2_ircsVar = getVariable("mcg_c2_ircs");
Variable system_mcgir_ungated_clock = new LongVariable("system_mcgir_ungated", null);
if (mcg_c2_ircsVar.getValueAsBoolean()) {
// Fast IRC selected
if (mcg_sc_fcrdivVar != null) {
// Variable divisor
long mcg_sc_fcrdiv = mcg_sc_fcrdivVar.getValueAsLong();
system_mcgir_ungated_clock.setOrigin("(Fast IRC)/FCRDIV");
system_mcgir_ungated_clock.setValue(system_fast_irc_clockVar.getValueAsLong() / (1 << mcg_sc_fcrdiv));
} else {
// Fixed divisor of 2
system_mcgir_ungated_clock.setOrigin("(Fast IRC)/2");
system_mcgir_ungated_clock.setValue(system_fast_irc_clockVar.getValueAsLong() / 2);
}
} else {
// Slow IRC selected
system_mcgir_ungated_clock.setOrigin("Slow IRC");
system_mcgir_ungated_clock.setValue(system_slow_irc_clockVar.getValueAsLong());
}
Variable system_mcgirclk_clockVar = getVariable("system_mcgirclk_clock");
system_mcgirclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
Variable mcg_c1_irclkenVar = getVariable("mcg_c1_irclken");
Variable mcg_c1_irefstenVar = getVariable("mcg_c1_irefsten");
if (mcg_c1_irclkenVar.getValueAsBoolean()) {
// Enabled
system_mcgirclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
system_mcgirclk_clockVar.setStatus((Status) null);
system_mcgirclk_clockVar.enable(true);
mcg_c1_irefstenVar.enable(true);
} else {
// Disabled
system_mcgirclk_clockVar.setValue(0);
system_mcgirclk_clockVar.setStatus(new Status("Disabled by mcg_c1_irclken", Severity.OK));
system_mcgirclk_clockVar.enable(false);
mcg_c1_irefstenVar.enable(false);
}
// Clock Mapping
// =================
String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
LongVariable osc0_osc_clockVar = getLongVariable(osc0_peripheral + "/osc_clock");
String osc32k_peripheral = getStringVariable("/SIM/osc32k_peripheral").getValueAsString();
LongVariable osc32k_osc_clockVar = getLongVariable(osc32k_peripheral + "/osc_clock");
// Determine MCG external reference clock [mcg_erc_clock]
// ========================================================
ChoiceVariable mcg_c7_oscselVar = safeGetChoiceVariable("mcg_c7_oscsel");
Variable mcg_erc_clockVar = getVariable("mcg_erc_clock");
switch((int) mcg_c7_oscselVar.getValueAsLong()) {
default:
case // ERC = OSCCLK (OSC0 main oscillator)
0:
mcg_erc_clockVar.setValue(osc0_osc_clockVar.getValueAsLong());
mcg_erc_clockVar.setStatus(osc0_osc_clockVar.getFilteredStatus());
mcg_erc_clockVar.setOrigin(osc0_osc_clockVar.getOrigin());
break;
case // ERC = RTCCLK (OSC1 oscillator)
1:
mcg_erc_clockVar.setValue(osc32k_osc_clockVar.getValueAsLong());
mcg_erc_clockVar.setStatus(osc32k_osc_clockVar.getFilteredStatus());
mcg_erc_clockVar.setOrigin(osc32k_osc_clockVar.getOrigin() + "[RTCCLK]");
break;
case // ERC = IRC48MCLK (OSC2)
2:
mcg_erc_clockVar.setValue(system_irc48m_clockVar.getValueAsLong());
mcg_erc_clockVar.setStatus((Status) null);
mcg_erc_clockVar.setOrigin("IRC48MCLK");
break;
}
Variable mcg_c11_pllcsVar = safeGetVariable("mcg_c11_pllcs");
boolean pllIsInternal = (mcg_c11_pllcsVar == null) || !mcg_c11_pllcsVar.getValueAsBoolean();
// Main clock mode
// ===============================
int mcg_c1_clks;
int mcg_c6_plls;
int mcg_c2_lp;
boolean mcg_c1_irefs;
// Main clock mode
// ====================
ClockMode clock_mode = ClockMode.valueOf(getVariable("clock_mode").getSubstitutionValue());
Variable fll_enabledVar = getVariable("fll_enabled");
Variable fllInputFrequencyVar = getVariable("fllInputFrequency");
switch(clock_mode) {
default:
case ClockMode_None:
mcg_c1_clks = 0;
mcg_c6_plls = 0;
mcg_c2_lp = 0;
mcg_c1_irefs = true;
system_mcgoutclk_clock_sourceVar.setValue("FLL output");
pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(true);
break;
case ClockMode_FEI:
mcg_c1_clks = 0;
mcg_c6_plls = 0;
mcg_c2_lp = 0;
mcg_c1_irefs = true;
system_mcgoutclk_clock_sourceVar.setValue("FLL output");
pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(true);
break;
case ClockMode_FEE:
mcg_c1_clks = 0;
mcg_c6_plls = 0;
mcg_c2_lp = 0;
mcg_c1_irefs = false;
system_mcgoutclk_clock_sourceVar.setValue("FLL output");
pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(true);
break;
case ClockMode_FBI:
mcg_c1_clks = 1;
mcg_c6_plls = 0;
mcg_c2_lp = 0;
mcg_c1_irefs = true;
system_mcgoutclk_clock_sourceVar.setValue("MCGIRCLK");
pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(true);
break;
case ClockMode_FBE:
mcg_c1_clks = 2;
mcg_c6_plls = 0;
mcg_c2_lp = 0;
mcg_c1_irefs = false;
system_mcgoutclk_clock_sourceVar.setValue("MCGERCLK");
pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(true);
break;
case ClockMode_BLPI:
mcg_c1_clks = 1;
mcg_c6_plls = 0;
mcg_c2_lp = 1;
mcg_c1_irefs = true;
system_mcgoutclk_clock_sourceVar.setValue("MCGIRCLK");
pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(false);
break;
case ClockMode_BLPE:
mcg_c1_clks = 2;
mcg_c6_plls = 0;
mcg_c2_lp = 1;
mcg_c1_irefs = false;
system_mcgoutclk_clock_sourceVar.setValue("MCGERCLK");
pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(false);
break;
case ClockMode_PBE:
mcg_c1_clks = 2;
mcg_c6_plls = 1;
mcg_c2_lp = 0;
mcg_c1_irefs = false;
system_mcgoutclk_clock_sourceVar.setValue("MCGERCLK");
pll0EnabledVar.setValue(pllIsInternal || mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(false);
break;
case ClockMode_PEE:
mcg_c1_clks = 0;
mcg_c6_plls = 1;
mcg_c2_lp = 0;
mcg_c1_irefs = false;
system_mcgoutclk_clock_sourceVar.setValue("PLL output");
pll0EnabledVar.setValue(pllIsInternal || mcg_c5_pllclkenVar.getValueAsBoolean());
fll_enabledVar.setValue(false);
break;
}
mcg_c1_clksVar.setValue(mcg_c1_clks);
mcg_c6_pllsVar.setValue(mcg_c6_plls);
mcg_c2_lpVar.setValue(mcg_c2_lp);
mcg_c1_irefsVar.setValue(mcg_c1_irefs);
Variable osc0_osc_cr_erclkenVar = safeGetBooleanVariable(osc0_peripheral + "/osc_cr_erclken");
// =======================================
// Find FLL dividers
FllConfigure fllCheck = new FllConfigure(osc0_osc_cr_erclkenVar, safeGetVariable(osc0_peripheral + "/oscillatorRange"), getVariable("mcg_c2_range"), mcg_c1_irefs, mcg_erc_clockVar, system_slow_irc_clockVar.getValueAsLong(), mcg_c7_oscselVar.getValueAsLong(), mcg_c4_dmx32Var.getValueAsBoolean(), fllInputFrequencyVar, system_mcgfllclk_clockVar, getVariable("system_mcgffclk_clock"), DRST_DRS_MAX);
mcg_c1_frdivVar.setValue(fllCheck.mcg_c1_frdiv);
mcg_c4_drst_drsVar.setValue(fllCheck.mcg_c4_drst_drs);
// External PLLs
// =================================================
Variable usb1pfdclk_ClockVar = safeGetVariable("usb1pfdclk_Clock");
if (usb1pfdclk_ClockVar != null) {
// Check USB HS PLL
long irClockFreq = osc0_osc_clockVar.getValueAsLong();
String failedPreCondition = null;
if (!osc0_osc_cr_erclkenVar.getValueAsBoolean()) {
failedPreCondition = "Disabled: to use PFDCLK, OSCCLK clock must be enabled by osc_cr_erclkenVar";
} else if (!mcg_c1_irclkenVar.getValueAsBoolean()) {
failedPreCondition = "Disabled: to use PFDCLK, IRC clock must be enabled by mcg_c1_irclken";
} else if ((irClockFreq != 12000000) && (irClockFreq != 16000000) && (irClockFreq != 24000000)) {
failedPreCondition = "Disabled: to use PFDCLK, OSCCLK must be in [12Mhz, 16MHz, 24MHz]";
}
if (failedPreCondition == null) {
usb1pfdclk_ClockVar.enable(true);
usb1pfdclk_ClockVar.setOrigin("Clock from USB HS PLL");
usb1pfdclk_ClockVar.setStatus((Status) null);
} else {
usb1pfdclk_ClockVar.enable(false);
usb1pfdclk_ClockVar.setOrigin("Clock from USB HS PLL (disabled)");
usb1pfdclk_ClockVar.setStatus(new Status(failedPreCondition, Severity.WARNING));
}
}
// Internal PLL
// ========================================
// Find PLL divider
PllConfigure pllConfigure = new PllConfigure(PLL_OUT_MIN, PLL_OUT_MAX, PLL_IN_MIN, PLL_IN_MAX, PRDIV_MIN, PRDIV_MAX, VDIV_MIN, VDIV_MAX, PLL_POST_DIV);
pllConfigure.validate(mcg_erc_clockVar, pll0InputFrequencyVar, pll0OutputFrequency, mcg_c5_prdiv0Var, mcg_c6_vdiv0Var);
boolean pll0Enabled = pll0EnabledVar.getValueAsBoolean();
pll0InputFrequencyVar.enable(pll0Enabled);
mcg_c5_prdiv0Var.enable(pll0Enabled);
mcg_c6_vdiv0Var.enable(pll0Enabled);
mcg_c5_pllstenVar.enable(pll0Enabled);
if (pll0Enabled) {
pll0OutputFrequency.enable(pll0InputFrequencyVar.getFilteredStatus() == null);
pll0OutputFrequency.setStatus(pllConfigure.getPllStatus());
} else {
pll0OutputFrequency.enable(false);
pll0OutputFrequency.setStatus(new Status("PLL is disabled", Severity.WARNING));
}
if (pllIsInternal) {
// Internal PLL
system_mcgpllclk_clockVar.setValue(pll0OutputFrequency.getValueAsLong());
system_mcgpllclk_clockVar.setOrigin(pll0OutputFrequency.getOrigin());
system_mcgpllclk_clockVar.setStatus(pll0OutputFrequency.getFilteredStatus());
} else {
// External PLL (USB1 (HS) PHY)
system_mcgpllclk_clockVar.setValue(usb1pfdclk_ClockVar.getValueAsLong());
system_mcgpllclk_clockVar.setOrigin(usb1pfdclk_ClockVar.getOrigin());
system_mcgpllclk_clockVar.setStatus(usb1pfdclk_ClockVar.getFilteredStatus());
}
// ======================================
// FLL status
boolean fllEnabled = fll_enabledVar.getValueAsBoolean();
fllInputFrequencyVar.enable(fllEnabled);
if (fllEnabled) {
boolean fllInputIsOK = (fllInputFrequencyVar.getStatus() == null) || (fllCheck.getFllStatus().getSeverity().lessThan(Severity.WARNING));
system_mcgfllclk_clockVar.enable(fllInputIsOK);
system_mcgfllclk_clockVar.setStatus(fllCheck.getFllStatus());
} else {
system_mcgfllclk_clockVar.enable(false);
system_mcgfllclk_clockVar.setStatus(new Status("FLL is disabled", Severity.WARNING));
}
mcg_c4_dmx32Var.enable(fllEnabled);
mcg_c4_drst_drsVar.enable(fllEnabled);
// Main clock mode
// ===============================
Status clock_mode_Status = null;
switch(clock_mode) {
default:
case ClockMode_None:
system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
system_mcgoutclk_clockVar.setStatus((Status) null);
clock_mode_Status = new Status("No clock settings are applied", Severity.WARNING);
break;
case ClockMode_FEI:
system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
system_mcgoutclk_clockVar.setStatus(system_mcgfllclk_clockVar.getFilteredStatus());
break;
case ClockMode_FEE:
system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
system_mcgoutclk_clockVar.setStatus(system_mcgfllclk_clockVar.getFilteredStatus());
break;
case ClockMode_FBI:
system_mcgoutclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
system_mcgoutclk_clockVar.setStatus(system_mcgir_ungated_clock.getFilteredStatus());
break;
case ClockMode_FBE:
system_mcgoutclk_clockVar.setValue(mcg_erc_clockVar.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(mcg_erc_clockVar.getOrigin());
system_mcgoutclk_clockVar.setStatus(mcg_erc_clockVar.getFilteredStatus());
break;
case ClockMode_BLPI:
system_mcgoutclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
system_mcgoutclk_clockVar.setStatus(system_mcgir_ungated_clock.getFilteredStatus());
break;
case ClockMode_BLPE:
system_mcgoutclk_clockVar.setValue(mcg_erc_clockVar.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(mcg_erc_clockVar.getOrigin());
system_mcgoutclk_clockVar.setStatus(mcg_erc_clockVar.getFilteredStatus());
break;
case ClockMode_PBE:
system_mcgoutclk_clockVar.setValue(mcg_erc_clockVar.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(mcg_erc_clockVar.getOrigin());
system_mcgoutclk_clockVar.setStatus(mcg_erc_clockVar.getFilteredStatus());
break;
case ClockMode_PEE:
system_mcgoutclk_clockVar.setValue(system_mcgpllclk_clockVar.getValueAsLong());
system_mcgoutclk_clockVar.setOrigin(system_mcgpllclk_clockVar.getOrigin());
system_mcgoutclk_clockVar.setStatus(system_mcgpllclk_clockVar.getFilteredStatus());
break;
}
system_mcgoutclk_clock_sourceVar.setStatus(clock_mode_Status);
system_mcgoutclk_clock_sourceVar.setOrigin(system_mcgoutclk_clockVar.getOrigin());
}
use of net.sourceforge.usbdm.deviceEditor.information.StringVariable in project usbdm-eclipse-plugins by podonoghue.
the class AdcValidate method validate.
/**
* Class to determine LPTMR settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
// Clock Mapping
// =================
final StringVariable osc0_peripheralVar = getStringVariable("/SIM/osc0_peripheral");
final LongVariable osc0_oscer_clockVar = getLongVariable(osc0_peripheralVar.getValueAsString() + "/oscer_clock");
// Variables
// =================================
DoubleVariable clockFrequencyVar = (DoubleVariable) getVariable("clockFrequency");
Variable adc_cfg1_adiclkVar = getVariable("adc_cfg1_adiclk");
Variable adc_cfg1_adivVar = getVariable("adc_cfg1_adiv");
Variable adcInternalClockVar = getVariable("adcInternalClock");
Variable system_bus_clockVar = getVariable("/SIM/system_bus_clock");
Variable adc_cfg1_adlpcVar = getVariable("adc_cfg1_adlpc");
Variable adc_cfg2_adhscVar = getVariable("adc_cfg2_adhsc");
Variable adc_cfg1_modeVar = getVariable("adc_cfg1_mode");
BooleanVariable adc_cfg1_adlsmpVar = getBooleanVariable("adc_cfg1_adlsmp");
ChoiceVariable adc_cfg2_adlstsVar = getChoiceVariable("adc_cfg2_adlsts");
LongVariable low_comparison_valueVar = getLongVariable("low_comparison_value");
LongVariable high_comparison_valueVar = getLongVariable("high_comparison_value");
LongVariable adc_cv1Var = getLongVariable("adc_cv1");
LongVariable adc_cv2Var = getLongVariable("adc_cv2");
ChoiceVariable adc_sc2_compareVar = getChoiceVariable("adc_sc2_compare");
LongVariable adc_sc2_acfeVar = getLongVariable("adc_sc2_acfe");
LongVariable adc_sc2_acfgtVar = getLongVariable("adc_sc2_acfgt");
LongVariable adc_sc2_acrenVar = getLongVariable("adc_sc2_acren");
int cv1 = 0;
int cv2 = 0;
int low = (int) low_comparison_valueVar.getValueAsLong();
int high = (int) high_comparison_valueVar.getValueAsLong();
int compareChoice = (int) adc_sc2_compareVar.getValueAsLong();
boolean adc_sc2_acfe = true;
boolean adc_sc2_acfgt = false;
boolean adc_sc2_acren = false;
switch(compareChoice) {
case // Disabled
0:
adc_sc2_acfe = false;
break;
case // ADC < low(CV1)
1:
cv1 = low;
adc_sc2_acfgt = false;
adc_sc2_acren = false;
break;
case // ADC >= low(CV1)
2:
cv1 = low;
adc_sc2_acfgt = true;
adc_sc2_acren = false;
break;
case // (ADC<low(CV1)) or (high(CV2)<ADC) CV1<CV2
3:
cv1 = low;
cv2 = high;
adc_sc2_acfgt = false;
adc_sc2_acren = true;
break;
case // (low(CV2)<ADC<high(CV1)) CV1>CV2 <==> CV2<CV1
4:
cv2 = low;
cv1 = high;
adc_sc2_acfgt = false;
adc_sc2_acren = true;
break;
case // (low(CV1)<=ADC<=high(CV2) CV1<CV2
5:
cv1 = low;
cv2 = high;
adc_sc2_acfgt = true;
adc_sc2_acren = true;
break;
case // (ADC<=low(CV2)) or (high(CV1<=ADC)) CV1>CV2 <==> CV2<CV1
6:
cv2 = low;
cv1 = high;
adc_sc2_acfgt = true;
adc_sc2_acren = true;
break;
}
adc_cv1Var.enable(compareChoice >= 1);
adc_cv2Var.enable(compareChoice >= 3);
low_comparison_valueVar.enable(compareChoice >= 1);
high_comparison_valueVar.enable(compareChoice >= 3);
adc_cv1Var.setValue(cv1);
adc_cv2Var.setValue(cv2);
adc_sc2_acfeVar.setValue(adc_sc2_acfe);
adc_cfg2_adlstsVar.enable(adc_cfg1_adlsmpVar.getValueAsBoolean());
adc_sc2_acfeVar.setValue(adc_sc2_acfe);
adc_sc2_acfgtVar.setValue(adc_sc2_acfgt);
adc_sc2_acrenVar.setValue(adc_sc2_acren);
// Varies with power settings etc
adcInternalClockVar.setValue(ADC_CLOCK_VALUES[(int) (2 * adc_cfg1_adlpcVar.getValueAsLong() + adc_cfg2_adhscVar.getValueAsLong())]);
LongVariable system_irc48m_clockVar = safeGetLongVariable("/MCG/system_irc48m_clock");
Variable clockSourceVar = null;
double clockFrequency;
switch((int) adc_cfg1_adiclkVar.getValueAsLong()) {
case 0:
clockSourceVar = system_bus_clockVar;
clockFrequency = system_bus_clockVar.getValueAsLong();
break;
case 1:
/*
* TODO - better method of clock selection
* ALTCLK2: Varies with device but assume irc48m if available else busClock/2
*/
if (system_irc48m_clockVar != null) {
clockSourceVar = system_irc48m_clockVar;
clockFrequency = system_irc48m_clockVar.getValueAsLong();
} else {
clockSourceVar = system_bus_clockVar;
clockFrequency = system_bus_clockVar.getValueAsLong() / 2.0;
}
break;
case 2:
clockSourceVar = osc0_oscer_clockVar;
clockFrequency = osc0_oscer_clockVar.getValueAsLong();
break;
default:
adc_cfg1_adiclkVar.setValue(1);
case 3:
clockSourceVar = adcInternalClockVar;
clockFrequency = adcInternalClockVar.getValueAsLong();
break;
}
// Set MIN and MAX before updating value
if (adc_cfg1_modeVar.getValueAsLong() >= 2) {
clockFrequencyVar.setMin(FADC_HIGH_RES_MIN);
clockFrequencyVar.setMax(FADC_HIGH_RES_MAX);
} else {
clockFrequencyVar.setMin(FADC_LOW_RES_MIN);
clockFrequencyVar.setMax(FADC_LOW_RES_MAX);
}
clockFrequency = clockFrequency / (1L << adc_cfg1_adivVar.getValueAsLong());
clockFrequencyVar.setValue(clockFrequency);
clockFrequencyVar.setStatus(clockSourceVar.getFilteredStatus());
clockFrequencyVar.setOrigin(clockSourceVar.getOrigin() + " divided by adc_cfg1_adiv");
}
use of net.sourceforge.usbdm.deviceEditor.information.StringVariable in project usbdm-eclipse-plugins by podonoghue.
the class ParseFamilyXML method parsePeripheral.
private void parsePeripheral(Element peripheralElement) throws Exception {
String baseName = peripheralElement.getAttribute("baseName");
String instance = peripheralElement.getAttribute("instance");
String version = peripheralElement.getAttribute("version");
Peripheral peripheral = null;
for (Node node = peripheralElement.getFirstChild(); node != null; node = node.getNextSibling()) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element element = (Element) node;
if (element.getTagName() == "handler") {
if (peripheral != null) {
throw new Exception("Peripheral already created");
}
peripheral = fDeviceInfo.createPeripheral(baseName, instance, element.getAttribute("class"), element.getAttribute("parameters"));
} else if (element.getTagName() == "clock") {
if (peripheral == null) {
peripheral = fDeviceInfo.createPeripheral(baseName, instance);
}
peripheral.setClockInfo(element.getAttribute("reg"), element.getAttribute("mask"));
} else if (element.getTagName() == "irq") {
peripheral.addIrqNum(element.getAttribute("num"));
} else if (element.getTagName() == "dma") {
peripheral.addDmaChannel(getIntAttribute(element, "num"), element.getAttribute("source"));
} else if (element.getTagName() == "param") {
String key = element.getAttribute("key");
String value = element.getAttribute("value");
PeripheralWithState p = (PeripheralWithState) peripheral;
StringVariable v = new StringVariable(key, p.makeKey(key));
p.addVariable(v);
v.setValue(value);
p.addParam(p.makeKey(key), value);
} else {
throw new Exception("Unexpected field in PERIPHERAL, value = \'" + element.getTagName() + "\'");
}
}
peripheral.setVersion(version);
}
Aggregations