use of net.sourceforge.usbdm.deviceEditor.information.DoubleVariable in project usbdm-eclipse-plugins by podonoghue.
the class PdbValidate method doPulseValidate.
/**
* Validate a PDB pulse output settings
*
* @param variable Variable that triggered change (may be null)
* @param channel The pulse output to validate e.g. 0, 1 etc
*
* @throws Exception
*/
void doPulseValidate(Variable variable, int channel) throws Exception {
// In/Out
LongVariable pdb_poX_dly_dly1Var = safeGetLongVariable("pdb_po" + channel + "_dly_dly1");
if (pdb_poX_dly_dly1Var == null) {
// Channel doesn't exit
return;
}
LongVariable pdb_poX_dly_dly2Var = getLongVariable("pdb_po" + channel + "_dly_dly2");
// Out/Out
DoubleVariable pdb_poX_dly_dly1_delayVar = getDoubleVariable("pdb_po" + channel + "_dly_dly1_delay");
DoubleVariable pdb_poX_dly_dly2_delayVar = getDoubleVariable("pdb_po" + channel + "_dly_dly2_delay");
LongVariable pdb_poenVar = getLongVariable("pdb_poen");
boolean dlyEnable = (pdb_poenVar.getRawValueAsLong() & (1 << channel)) != 0;
// Do enable/disable first
pdb_poX_dly_dly1Var.enable(dlyEnable);
pdb_poX_dly_dly1_delayVar.enable(dlyEnable);
pdb_poX_dly_dly2Var.enable(dlyEnable);
pdb_poX_dly_dly2_delayVar.enable(dlyEnable);
// Get current values
long pdb_poX_dly_dly1 = pdb_poX_dly_dly1Var.getRawValueAsLong();
double pdb_poX_dly_dly1_delay = pdb_poX_dly_dly1_delayVar.getRawValueAsDouble();
long pdb_poX_dly_dly2 = pdb_poX_dly_dly2Var.getRawValueAsLong();
double pdb_poX_dly_dly2_delay = pdb_poX_dly_dly2_delayVar.getRawValueAsDouble();
if (clockChanged) {
pdb_poX_dly_dly1_delayVar.setOrigin(pdbClockOrigin + " period * pdb_po" + channel + "_dly_dly1");
pdb_poX_dly_dly2_delayVar.setOrigin(pdbClockOrigin + " period * pdb_po" + channel + "_dly_dly2");
}
if (variable != null) {
if (variable.equals(pdb_poX_dly_dly1_delayVar)) {
// Calculate rounded value
pdb_poX_dly_dly1 = Math.max(0, Math.round((pdb_poX_dly_dly1_delay / pdb_period) - 1));
// Update
pdb_poX_dly_dly1Var.setValue(pdb_poX_dly_dly1);
} else if (variable.equals(pdb_poX_dly_dly2_delayVar)) {
// Calculate rounded value
pdb_poX_dly_dly2 = Math.max(0, Math.round((pdb_poX_dly_dly2_delay / pdb_period) - 1));
// Update
pdb_poX_dly_dly2Var.setValue(pdb_poX_dly_dly2);
}
}
pdb_poX_dly_dly1Var.setMax(pdb_mod);
pdb_poX_dly_dly1_delayVar.setMax((pdb_mod + 1.5) * pdb_period);
pdb_poX_dly_dly2Var.setMax(pdb_mod);
pdb_poX_dly_dly2_delayVar.setMax((pdb_mod + 1.5) * pdb_period);
pdb_poX_dly_dly1_delayVar.setValue(pdb_period * (pdb_poX_dly_dly1 + 1));
pdb_poX_dly_dly2_delayVar.setValue(pdb_period * (pdb_poX_dly_dly2 + 1));
}
use of net.sourceforge.usbdm.deviceEditor.information.DoubleVariable in project usbdm-eclipse-plugins by podonoghue.
the class PitValidate method validate.
/**
* Class to determine PIT settings
*
* Outputs pit_ldval
*
* @throws Exception
*/
@Override
public void validate(Variable variable) throws Exception {
super.validate(variable);
// Clocks
// =================================
LongVariable clockVar = getLongVariable("/SIM/system_bus_clock");
LongVariable pit_ldvalVar = getLongVariable("pit_ldval");
DoubleVariable pit_periodVar = getDoubleVariable("pit_period");
DoubleVariable pit_frequencyVar = getDoubleVariable("pit_frequency");
double busFrequency = clockVar.getValueAsDouble();
long pit_ldval = pit_ldvalVar.getValueAsLong();
if (variable != null) {
if (variable.equals(pit_periodVar)) {
// Default period -> ldval, frequency
// System.err.println("pit_period");
double pit_period = pit_periodVar.getValueAsDouble();
if (pit_period == 0) {
pit_ldval = 0;
} else {
pit_ldval = Math.max(0, Math.round((pit_period * busFrequency) - 1));
}
} else if (variable.equals(pit_frequencyVar)) {
// Default frequency -> period, ldval
// System.err.println("pit_frequency");
double pit_frequency = pit_frequencyVar.getValueAsDouble();
if (pit_frequency == 0) {
pit_ldval = 0;
} else {
pit_ldval = Math.max(0, Math.round(busFrequency / pit_frequency - 1));
}
}
}
pit_periodVar.setMax((pit_ldvalVar.getMax() + 1) / busFrequency);
pit_ldvalVar.setValue(pit_ldval);
if (pit_ldval == 0) {
pit_periodVar.setValue(0);
pit_frequencyVar.setValue(0);
} else {
pit_periodVar.setValue((pit_ldval + 1) / busFrequency);
pit_frequencyVar.setValue(busFrequency / (pit_ldval + 1));
}
}
Aggregations