use of net.sourceforge.usbdm.deviceEditor.information.Variable 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.Variable 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.Variable in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method createModelFromAlias.
/**
* @param provider Provider to look up variables
* @param parent Parent model needed to replace child in
* @param aliasModel Information for model to instantiate
*
* @return New model created
*
* @throws Exception
*/
static BaseModel createModelFromAlias(VariableProvider provider, BaseModel parent, AliasPlaceholderModel aliasModel) throws Exception {
String key = aliasModel.getKey();
boolean isOptional = aliasModel.isOptional();
Variable variable = provider.safeGetVariable(key);
if (variable == null) {
if (!isOptional) {
throw new Exception("Alias not found for " + key + " within " + parent.getName() + ", provider = " + provider);
}
return null;
}
String description = aliasModel.getDescription();
if (!description.isEmpty()) {
if ((variable.getDescription() != null) && !variable.getDescription().isEmpty()) {
throw new Exception("Alias tries to change description for " + key);
}
variable.setDescription(description);
}
String toolTip = aliasModel.getToolTip();
if ((toolTip != null) && !toolTip.isEmpty()) {
if ((variable.getDisplayToolTip() != null) && !variable.getDisplayToolTip().isEmpty()) {
throw new Exception("Alias tries to change toolTip for " + key);
}
variable.setToolTip(toolTip);
}
VariableModel model = variable.createModel(null);
boolean isConstant = aliasModel.isConstant();
model.setConstant(isConstant);
String displayName = aliasModel.getName();
if (!displayName.isEmpty()) {
model.setName(displayName);
}
return model;
}
use of net.sourceforge.usbdm.deviceEditor.information.Variable in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method getDerived.
/**
* Check if element has derivedFrom
*
* @param varElement Element to parse
*
* @return Derived from variable if it exists
* @throws Exception
*/
Variable getDerived(Element varElement) throws Exception {
Variable otherVariable = null;
String derivedFromName = varElement.getAttribute("derivedFrom");
if (!derivedFromName.isEmpty()) {
derivedFromName = fProvider.makeKey(derivedFromName);
otherVariable = safeGetVariable(derivedFromName);
if (otherVariable == null) {
throw new Exception("derivedFromName variable not found for " + derivedFromName);
}
}
return otherVariable;
}
use of net.sourceforge.usbdm.deviceEditor.information.Variable 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