use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable in project usbdm-eclipse-plugins by podonoghue.
the class FtmValidate method validate.
/**
* Class to determine LPTMR settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
// =================================
DoubleVariable clockFrequencyVar = getDoubleVariable("clockFrequency");
DoubleVariable clockPeriodVar = getDoubleVariable("clockPeriod");
ChoiceVariable ftm_sc_clksVar = getChoiceVariable("ftm_sc_clks");
ChoiceVariable ftm_sc_psVar = getChoiceVariable("ftm_sc_ps");
LongVariable ftm_modVar = getLongVariable("ftm_mod");
DoubleVariable ftm_mod_periodVar = getDoubleVariable("ftm_mod_period");
BooleanVariable ftm_sc_cpwmsVar = getBooleanVariable("ftm_sc_cpwms");
LongVariable clockSourceVar = null;
switch((int) ftm_sc_clksVar.getValueAsLong()) {
case 0:
clockSourceVar = new LongVariable("Disabled", "/Ftm/Disabled");
clockSourceVar.setOrigin("Disabled");
clockSourceVar.setValue(0);
break;
default:
ftm_sc_clksVar.setValue(1);
case 1:
clockSourceVar = getLongVariable("/SIM/system_bus_clock");
break;
case 2:
clockSourceVar = getLongVariable("/MCG/system_mcgffclk_clock");
break;
case 3:
clockSourceVar = getLongVariable("ftmExternalClock");
break;
}
double clockFrequency = clockSourceVar.getValueAsDouble();
String clockOrigin = clockSourceVar.getOrigin();
clockFrequency = clockFrequency / (1L << ftm_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);
ftm_mod_periodVar.enable(clockFrequency != 0);
if (clockFrequency != 0) {
long ftm_mod = ftm_modVar.getValueAsLong();
double clockPeriod = 1.0 / clockFrequency;
clockPeriodVar.setValue(clockPeriod);
boolean ftm_sc_cpwms = ftm_sc_cpwmsVar.getValueAsBoolean();
double ftm_mod_period = clockPeriod * (ftm_sc_cpwms ? (2 * (ftm_mod)) : ((ftm_mod + 1)));
if (variable != null) {
// Update selectively
if (variable.equals(ftm_mod_periodVar)) {
ftm_mod_period = ftm_mod_periodVar.getValueAsDouble();
// Calculate rounded value
if (ftm_sc_cpwms) {
ftm_mod = Math.max(0, Math.round((ftm_mod_period / clockPeriod) / 2));
} else {
ftm_mod = Math.max(0, Math.round((ftm_mod_period / clockPeriod) - 1));
}
ftm_mod_period = clockPeriod * (ftm_sc_cpwms ? (2 * (ftm_mod)) : ((ftm_mod + 1)));
// Update
ftm_modVar.setValue(ftm_mod);
}
}
double ftm_mod_periodMax = clockPeriod * (ftm_sc_cpwms ? (2 * (65535.5)) : ((65536.5)));
ftm_mod_periodVar.setValue(ftm_mod_period);
ftm_mod_periodVar.setMax(ftm_mod_periodMax);
}
}
use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable in project usbdm-eclipse-plugins by podonoghue.
the class LlwuValidate method validate.
/**
* Class to validate LLWU settings
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
doPinNames();
for (int index = 0; index < 8; index++) {
// Filter variables
ChoiceVariable llwu_filt_filteVar = safeGetChoiceVariable("llwu_filt" + index + "_filte");
LongVariable llwu_filt_filtselVar = safeGetLongVariable("llwu_filt" + index + "_filtsel");
if ((llwu_filt_filteVar != null) && ((variable == null) || (variable == llwu_filt_filteVar))) {
llwu_filt_filtselVar.enable(llwu_filt_filteVar.getValueAsLong() != 0);
}
}
// // Warn if Rx and Tx signals not mapped
// validateMappedPins(new int[]{0,1}, getPeripheral().getSignalTables().get(0).table);
}
use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable 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.ChoiceVariable in project usbdm-eclipse-plugins by podonoghue.
the class SimValidate_fll 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 osc32kClk_peripheral = getStringVariable("osc32k_peripheral").getValueAsString();
final LongVariable osc32kClk_osc_clockVar = getLongVariable(osc32kClk_peripheral + "/osc_clock");
final String oscClk_peripheral = getStringVariable("osc0_peripheral").getValueAsString();
final LongVariable oscClk_osc_clockVar = getLongVariable(oscClk_peripheral + "/osc_clock");
final String rtc_clkin = getStringVariable("rtc_clkin").getValueAsString();
final LongVariable rtcclkin_clockVar = safeGetLongVariable(rtc_clkin);
final LongVariable rtc_1hz_clockVar = safeGetLongVariable(osc32kClk_peripheral + "/rtc_1hz_clock");
// MCG
// =================
final LongVariable system_low_power_clockVar = getLongVariable("/MCG/system_low_power_clock");
final LongVariable system_mcgirclk_clockVar = getLongVariable("/MCG/system_mcgirclk_clock");
final LongVariable system_usb_clkin_clockVar = safeGetLongVariable("/MCG/system_usb_clkin_clock");
LongVariable clockVar = safeGetLongVariable("system_peripheral_clock");
if (clockVar == null) {
// Assume no PLL. Peripheral clock is FLL
clockVar = getLongVariable("/MCG/system_mcgfllclk_clock");
}
final LongVariable peripheralClockVar = clockVar;
// RTC
// =================
final LongVariable rtc_clkoutVar = safeGetLongVariable("rtc_clkout");
/**
* 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 // MCGFLLCLK
1:
clockVar.setValue(peripheralClockVar.getValueAsLong());
clockVar.setStatus(peripheralClockVar.getStatus());
clockVar.setOrigin(peripheralClockVar.getOrigin());
break;
case // OSCERCLK
2:
clockVar.setValue(oscClk_osc_clockVar.getValueAsLong());
clockVar.setStatus(oscClk_osc_clockVar.getStatus());
clockVar.setOrigin(oscClk_osc_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(osc32kClk_osc_clockVar.getValueAsLong());
system_erclk32k_clockVar.setOrigin(osc32kClk_osc_clockVar.getOrigin());
system_erclk32k_clockVar.setStatus(osc32kClk_osc_clockVar.getStatus());
break;
default:
sim_sopt1_osc32kselVar.setValue(2);
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;
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(oscClk_osc_clockVar.getValueAsLong());
rtc_clkoutVar.setStatus(oscClk_osc_clockVar.getStatus());
rtc_clkoutVar.setOrigin(oscClk_osc_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) {
ChoiceVariable sim_clkdiv2_usbVar = safeGetChoiceVariable("sim_clkdiv2_usb");
if (sim_clkdiv2_usbVar != null) {
// USB divider CLKDIV2 exists
int usbCalcValue = -1;
if (sim_sopt2_usbsrcVar.getValueAsLong() == 0) {
// Using USB CLKIN pin
sim_clkdiv2_usbVar.enable(false);
sim_clkdiv2_usbVar.setOrigin("Not used with external clock");
sim_clkdiv2_usbVar.setLocked(false);
} else {
// Using internal clock
// Try to auto calculate divisor
long clock = peripheralClockVar.getValueAsLong();
for (int usbdiv = 0; usbdiv <= 7; usbdiv++) {
for (int usbfrac = 0; usbfrac <= 1; usbfrac++) {
long testValue = Math.round(clock * (usbfrac + 1.0) / (usbdiv + 1.0));
if (testValue == 48000000) {
usbCalcValue = (usbdiv << 1) + usbfrac;
break;
}
}
if (usbCalcValue >= 0) {
break;
}
}
sim_clkdiv2_usbVar.enable(true);
if (usbCalcValue >= 0) {
sim_clkdiv2_usbVar.setRawValue(usbCalcValue);
sim_clkdiv2_usbVar.setOrigin("Automatically calculated from input clock");
sim_clkdiv2_usbVar.setLocked(true);
} else {
sim_clkdiv2_usbVar.setOrigin("Manually selected");
sim_clkdiv2_usbVar.setLocked(false);
}
}
}
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 {
// Using internal clock
if (sim_clkdiv2_usbVar != null) {
// Peripheral Clock / CLKDIV2
int usbValue = Long.decode(sim_clkdiv2_usbVar.getSubstitutionValue()).intValue();
int usbfrac = usbValue & 0x1;
int usbdiv = (usbValue >> 1) & 0x7;
long usbPostDiv2 = peripheralClockVar.getValueAsLong() * (usbfrac + 1) / (usbdiv + 1);
system_usbfs_clockVar.setValue(usbPostDiv2);
system_usbfs_clockVar.setStatus(peripheralClockVar.getStatus());
system_usbfs_clockVar.setOrigin(peripheralClockVar.getOrigin() + " after /CLKDIV2");
} else {
// Directly using peripheral clock
system_usbfs_clockVar.setValue(peripheralClockVar.getValueAsLong());
system_usbfs_clockVar.setStatus(peripheralClockVar.getStatus());
system_usbfs_clockVar.setOrigin(peripheralClockVar.getOrigin());
}
}
}
}
use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable 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);
}
}
Aggregations