use of net.sourceforge.usbdm.deviceEditor.information.BooleanVariable in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method parseChoices.
/**
* Parses the children of this element
*
* @param parentModel Model to attach children to
* @param menuElement Menu element to parse
*
* @throws Exception
*/
void parseChoices(Variable variable, Element menuElement) throws Exception {
ArrayList<Pair> entries = new ArrayList<Pair>();
String defaultValue = null;
NodeList choiceNodes = menuElement.getElementsByTagName("choice");
for (int index = 0; index < choiceNodes.getLength(); index++) {
Node node = choiceNodes.item(index);
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element element = (Element) node;
Pair entry = new Pair(element.getAttribute("name"), element.getAttribute("value"));
entries.add(entry);
if (defaultValue == null) {
defaultValue = entry.name;
}
if (element.getAttribute("isDefault").equalsIgnoreCase("true")) {
defaultValue = entry.name;
}
}
if (entries.size() == 0) {
/**
* Should be another variable of the same type to copy from
*/
Variable otherVariable = getDerived(menuElement);
if (otherVariable == null) {
throw new Exception("No choices found in <" + menuElement.getTagName() + " name=\"" + variable.getName() + "\">");
}
if (otherVariable.getClass() != variable.getClass()) {
throw new Exception("Referenced variable of wrong type <" + menuElement.getTagName() + " derivedFrom=\"" + variable.getName() + "\">");
}
if (variable instanceof BooleanVariable) {
BooleanVariable otherVar = (BooleanVariable) otherVariable;
BooleanVariable var = (BooleanVariable) variable;
var.setFalseValue(otherVar.getFalseValue());
var.setTrueValue(otherVar.getTrueValue());
var.setDefault(otherVar.getDefault());
var.setValue(otherVar.getDefault());
} else if (variable instanceof ChoiceVariable) {
ChoiceVariable otherVar = (ChoiceVariable) otherVariable;
ChoiceVariable var = (ChoiceVariable) variable;
var.setData(otherVar.getData());
var.setDefault(otherVar.getDefault());
var.setValue(otherVar.getDefault());
}
} else {
if (variable instanceof BooleanVariable) {
if (entries.size() > 2) {
throw new Exception("Wrong number of choices in <" + menuElement.getTagName() + " name=\"" + variable.getName() + "\">");
}
BooleanVariable var = (BooleanVariable) variable;
var.setFalseValue(entries.get(0));
var.setTrueValue(entries.get(1));
} else if (variable instanceof ChoiceVariable) {
Pair[] theEntries = entries.toArray(new Pair[entries.size()]);
ChoiceVariable var = (ChoiceVariable) variable;
var.setData(theEntries);
}
variable.setDefault(defaultValue);
variable.setValue(defaultValue);
}
}
use of net.sourceforge.usbdm.deviceEditor.information.BooleanVariable in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method parseBinaryOption.
/**
* Parse <binaryOption> element<br>
*
* @param varElement
* @throws Exception
*/
private void parseBinaryOption(BaseModel parent, Element varElement) throws Exception {
BooleanVariable variable = (BooleanVariable) parseCommonAttributes(parent, varElement, BooleanVariable.class).getVariable();
parseChoices(variable, varElement);
}
use of net.sourceforge.usbdm.deviceEditor.information.BooleanVariable in project usbdm-eclipse-plugins by podonoghue.
the class LcdValidate method validate.
/**
* Class to validate LCD settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
LongVariable osc0_oscer_clockVar = getLongVariable(osc0_peripheral + "/oscer_clock");
LongVariable system_erclk32k_clockVar = getLongVariable("/SIM/system_erclk32k_clock");
LongVariable system_mcgirclk_clockVar = getLongVariable("/MCG/system_mcgirclk_clock");
ChoiceVariable lcd_gcr_clockVar = getChoiceVariable("lcd_gcr_clock");
ChoiceVariable lcd_gcr_altdivVar = getChoiceVariable("lcd_gcr_altdiv");
DoubleVariable lcdClockVar = getDoubleVariable("lcdClock");
BooleanVariable lcd_gcr_rvenVar = getBooleanVariable("lcd_gcr_rven");
ChoiceVariable lcd_gcr_rvtrimVar = getChoiceVariable("lcd_gcr_rvtrim");
lcd_gcr_rvtrimVar.enable(lcd_gcr_rvenVar.getValueAsBoolean());
ChoiceVariable lcd_gcr_dutyVar = getChoiceVariable("lcd_gcr_duty");
PinListVariable backplanesVar = (PinListVariable) getVariable("backplanes");
PinListVariable frontplanesVar = (PinListVariable) getVariable("frontplanes");
Vector<Signal> table = getPeripheral().getSignalTables().get(0).table;
Status unmappedBackplanesMessage = null;
int[] backPlaneValues = backplanesVar.getValues();
for (int pinNum : backPlaneValues) {
Signal entry = table.get(pinNum);
if ((entry == null) || (entry.getMappedPin().getPin() == Pin.UNASSIGNED_PIN)) {
unmappedBackplanesMessage = UNMAPPED_PIN_STATUS;
break;
}
}
backplanesVar.setStatus(unmappedBackplanesMessage);
Status unmappedFrontplanesMessage = null;
int[] frontPlaneValues = frontplanesVar.getValues();
for (int pinNum : frontPlaneValues) {
Signal entry = table.get(pinNum);
if ((entry == null) || (entry.getMappedPin().getPin() == Pin.UNASSIGNED_PIN)) {
unmappedFrontplanesMessage = UNMAPPED_PIN_STATUS;
break;
}
}
frontplanesVar.setStatus(unmappedFrontplanesMessage);
// Number of back-planes is determined by duty-cycle
backplanesVar.setMinListLength(0);
backplanesVar.setListLength((int) lcd_gcr_dutyVar.getValueAsLong() + 1);
// Number of front-planes is determined by pins left over from back-planes
frontplanesVar.setMinListLength(0);
frontplanesVar.setMaxListLength(63 - ((int) lcd_gcr_dutyVar.getValueAsLong() + 1));
double divider = 1 << (3 * lcd_gcr_altdivVar.getValueAsLong());
switch((int) lcd_gcr_clockVar.getValueAsLong()) {
default:
lcd_gcr_clockVar.setValue(0);
case 0:
lcd_gcr_altdivVar.enable(false);
lcdClockVar.setValue(system_erclk32k_clockVar.getValueAsLong());
lcdClockVar.setOrigin(system_erclk32k_clockVar.getOrigin());
lcdClockVar.setStatus(system_erclk32k_clockVar.getFilteredStatus());
break;
case 1:
lcd_gcr_altdivVar.enable(true);
lcdClockVar.setValue(system_mcgirclk_clockVar.getValueAsLong() / divider);
lcdClockVar.setOrigin(system_mcgirclk_clockVar.getOrigin() + " / ALTDIV");
lcdClockVar.setStatus(system_mcgirclk_clockVar.getFilteredStatus());
break;
case 2:
lcd_gcr_altdivVar.enable(true);
lcdClockVar.setValue(osc0_oscer_clockVar.getValueAsLong() / divider);
lcdClockVar.setOrigin(osc0_oscer_clockVar.getOrigin() + " / ALTDIV");
lcdClockVar.setStatus(osc0_oscer_clockVar.getFilteredStatus());
break;
}
}
use of net.sourceforge.usbdm.deviceEditor.information.BooleanVariable in project usbdm-eclipse-plugins by podonoghue.
the class LlwuValidate method doPinNames.
/**
* Extract pin names and create LLWU pin and peripheral C enum tables.<br>
* The description for pins is also annotated with the pin number found or (Reserved)<br>
*
* Tables are added to the following Peripheral Variables:
* <li>LlwuPins
* <li>LlwuPeripherals
*/
private void doPinNames() {
final String RESERVED = "Reserved";
if (donePinNames) {
return;
}
donePinNames = true;
StringBuilder sb = new StringBuilder();
sb.append("/**\n" + " * LLWU pin sources\n" + " */\n" + "enum LlwuPin : uint32_t {\n");
InfoTable pinTable = getPeripheral().getSignalTables().get(0);
for (int index = 0; index < 32; index++) {
String choiceName = "llwu_pe" + ((index / 4) + 1) + "_wupe" + index;
ChoiceVariable choiceVar = safeGetChoiceVariable(choiceName);
if (choiceVar == null) {
continue;
}
String llwuPinName;
if (index >= pinTable.table.size()) {
// Pin not in table (doesn't exist)
choiceVar.enable(false);
llwuPinName = RESERVED;
} else {
// Look up possible pin mapping in table
Signal signal = pinTable.table.elementAt(index);
Pin mappablePin = null;
if (signal != null) {
TreeSet<MappingInfo> pinMappings = signal.getPinMapping();
for (MappingInfo pinMapping : pinMappings) {
if (pinMapping.getMux() == MuxSelection.mux1) {
mappablePin = pinMapping.getPin();
}
}
}
if (mappablePin == null) {
// No mappable pin
choiceVar.enable(false);
llwuPinName = RESERVED;
} else {
// Mappable pin
choiceVar.enable(true);
llwuPinName = mappablePin.getName();
}
}
if (llwuPinName != RESERVED) {
String llwuPinLine = String.format(" LlwuPin_%-15s = %2d, //!< Wake-up pin LLWU_P%d\n", capitalCase(llwuPinName), index, index);
sb.append(llwuPinLine);
}
choiceVar.setDescription(choiceVar.getDescription() + " - " + llwuPinName);
}
sb.append("};\n\n");
StringVariable llwuPinsVar = new StringVariable("LlwuPins", getPeripheral().makeKey("LlwuPins"));
llwuPinsVar.setValue(sb.toString());
llwuPinsVar.setDerived(true);
getPeripheral().addVariable(llwuPinsVar);
sb = new StringBuilder();
sb.append("/**\n" + " * LLWU peripheral sources\n" + " */\n" + "enum LlwuPeripheral : uint32_t {\n");
for (int index = 0; index <= 7; index++) {
String choiceName = "llwu_me_wume" + index;
BooleanVariable choiceVar = safeGetBooleanVariable(choiceName);
String llwuPeripheralName;
if (choiceVar != null) {
llwuPeripheralName = choiceVar.getDescription();
String llwuPeripheralLine = String.format(" LlwuPeripheral_%-15s = (1<<%d), //!< Wake-up peripheral LLWU_M%dIF\n", capitalCase(llwuPeripheralName), index, index);
sb.append(llwuPeripheralLine);
}
}
sb.append("};\n\n");
StringVariable llwuPeripheralsVar = new StringVariable("LlwuPeripherals", getPeripheral().makeKey("LlwuPeripherals"));
llwuPeripheralsVar.setValue(sb.toString());
llwuPeripheralsVar.setDerived(true);
getPeripheral().addVariable(llwuPeripheralsVar);
}
use of net.sourceforge.usbdm.deviceEditor.information.BooleanVariable in project usbdm-eclipse-plugins by podonoghue.
the class LptmrValidate method validate.
/**
* Class to determine LPTMR settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
// System.err.println("LptmrValidate.validate("+variable+")");
final String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
// Variables
// =================================
DoubleVariable clockFrequencyVar = getDoubleVariable("clockFrequency");
DoubleVariable clockPeriodVar = getDoubleVariable("clockPeriod");
DoubleVariable maximumPeriodVar = getDoubleVariable("maximumPeriod");
Variable lptmr_psr_pcsVar = getVariable("lptmr_psr_pcs");
BooleanVariable lptmr_psr_pbypVar = getBooleanVariable("lptmr_psr_pbyp");
Variable lptmr_psr_prescalerVar = getVariable("lptmr_psr_prescaler");
BooleanVariable lptmr_csr_tmsVar = getBooleanVariable("lptmr_csr_tms");
Variable lptmr_csr_tpsVar = getVariable("lptmr_csr_tps");
Variable lptmr_csr_tppVar = getVariable("lptmr_csr_tpp");
LongVariable lptmr_cmrVar = getLongVariable("lptmr_cmr");
DoubleVariable lptmr_cmrPeriodVar = getDoubleVariable("lptmr_cmrPeriod");
DoubleVariable lptmr_cmrFrequencyVar = getDoubleVariable("lptmr_cmrFrequency");
// Enable/disable parameters that depend on mode
boolean lptmr_csr_tms = lptmr_csr_tmsVar.getValueAsBoolean();
lptmr_csr_tpsVar.enable(lptmr_csr_tms);
lptmr_csr_tppVar.enable(lptmr_csr_tms);
lptmr_cmrPeriodVar.enable(!lptmr_csr_tms);
lptmr_cmrFrequencyVar.enable(!lptmr_csr_tms);
Variable clockSourceVar = null;
switch((int) lptmr_psr_pcsVar.getValueAsLong()) {
default:
lptmr_psr_pcsVar.setValue(0);
case 0:
clockSourceVar = getVariable("/MCG/system_mcgirclk_clock[0]");
break;
case 1:
clockSourceVar = getVariable("/MCG/system_low_power_clock");
break;
case 2:
clockSourceVar = getVariable("/SIM/system_erclk32k_clock");
break;
case 3:
clockSourceVar = getVariable(osc0_peripheral + "/oscer_clock");
break;
}
boolean clockChanged = // Initial setup
(variable == null) || // Clock source selection change
(variable == lptmr_psr_pcsVar) || // Change in the currently selected clock source
(variable == clockSourceVar) || // Prescaler bypass
(variable == lptmr_psr_pbypVar) || // Prescaler changed
(variable == lptmr_psr_prescalerVar);
if (variable == lptmr_psr_pbypVar) {
// Update bypass affected things
if (lptmr_psr_pbypVar.getValueAsBoolean()) {
// Clock divider bypassed
lptmr_psr_prescalerVar.enable(false);
lptmr_psr_prescalerVar.setOrigin("Disabled by lptmr_psr_pbyp");
clockFrequencyVar.setOrigin(clockSourceVar.getOrigin());
clockPeriodVar.setOrigin(clockSourceVar.getOrigin());
} else {
// Clock divider used
lptmr_psr_prescalerVar.enable(true);
lptmr_psr_prescalerVar.setOrigin(null);
clockFrequencyVar.setOrigin(clockSourceVar.getOrigin() + " frequency divided by lptmr_psr_prescaler");
clockPeriodVar.setOrigin(clockSourceVar.getOrigin() + " period multiplied by lptmr_psr_prescaler");
}
}
// Current values
double clockFrequency = clockSourceVar.getValueAsLong();
if (!lptmr_psr_pbypVar.getValueAsBoolean()) {
// Clock divider used
clockFrequency = clockFrequency / (1L << (lptmr_psr_prescalerVar.getValueAsLong() + 1));
}
double clockPeriod = (clockFrequency == 0) ? 0 : (1 / clockFrequency);
clockFrequencyVar.setStatus(clockSourceVar.getFilteredStatus());
if (clockChanged) {
// Update clockFrequency, clockPeriod
clockFrequencyVar.setValue(clockFrequency);
clockPeriodVar.setStatus(clockSourceVar.getStatus());
if (clockFrequency == 0) {
clockFrequencyVar.enable(false);
clockPeriodVar.enable(false);
clockPeriod = 0.0;
clockPeriodVar.setValue(clockPeriod);
} else {
clockFrequencyVar.enable(true);
clockPeriodVar.enable(true);
clockPeriod = 1 / clockFrequency;
clockPeriodVar.setValue(clockPeriod);
}
}
double maximumPeriod = clockPeriod * 65536;
maximumPeriodVar.setValue(maximumPeriod);
lptmr_cmrPeriodVar.setMax(maximumPeriod);
long lptmr_cmr = lptmr_cmrVar.getValueAsLong();
if (clockChanged) {
// cmr==0 produced infinity which is OK!
Double cmrFrequency = clockFrequency / lptmr_cmr;
Double cmrPeriod = clockPeriod * lptmr_cmr;
lptmr_cmrPeriodVar.setValue(cmrPeriod);
lptmr_cmrFrequencyVar.setValue(cmrFrequency);
} else if (variable != null) {
if (variable.equals(lptmr_cmrVar)) {
// cmr==0 produced infinity which is OK!
Double cmrFrequency = clockFrequency / lptmr_cmr;
Double cmrPeriod = clockPeriod * lptmr_cmr;
lptmr_cmrPeriodVar.setValue(cmrPeriod);
lptmr_cmrFrequencyVar.setValue(cmrFrequency);
} else if (variable.equals(lptmr_cmrPeriodVar)) {
// Calculate rounded value
lptmr_cmr = Math.round(lptmr_cmrPeriodVar.getValueAsDouble() * clockFrequency);
// cmr==0 produced infinity which is OK!
Double cmrFrequency = clockFrequency / lptmr_cmr;
Double cmrPeriod = clockPeriod * lptmr_cmr;
// Update
lptmr_cmrVar.setValue(lptmr_cmr);
// Need to show effect of rounding
lptmr_cmrPeriodVar.setValue(cmrPeriod);
lptmr_cmrFrequencyVar.setValue(cmrFrequency);
} else if (variable.equals(lptmr_cmrFrequencyVar)) {
// Calculate rounded value
Double cmrFrequency = lptmr_cmrFrequencyVar.getValueAsDouble();
if (cmrFrequency <= (clockFrequency / 65535)) {
lptmr_cmr = 65535;
} else {
lptmr_cmr = Math.round(clockFrequency / cmrFrequency);
}
// cmr==0 produced infinity which is OK!
cmrFrequency = clockFrequency / lptmr_cmr;
Double cmrPeriod = clockPeriod * lptmr_cmr;
// Update
lptmr_cmrVar.setValue(lptmr_cmr);
// Need to show effect of rounding
lptmr_cmrPeriodVar.setValue(cmrPeriod);
lptmr_cmrFrequencyVar.setValue(cmrFrequency);
}
}
}
Aggregations