Search in sources :

Example 1 with DoubleVariable

use of net.sourceforge.usbdm.deviceEditor.information.DoubleVariable in project usbdm-eclipse-plugins by podonoghue.

the class TpmValidate method validate.

/**
 * Class to determine LPTMR settings
 * @throws Exception
 */
@Override
public void validate(Variable variable) throws Exception {
    super.validate(variable);
    // =================================
    LongVariable system_tpm_clockVar = getLongVariable("/SIM/system_tpm_clock");
    DoubleVariable clockFrequencyVar = getDoubleVariable("clockFrequency");
    DoubleVariable clockPeriodVar = getDoubleVariable("clockPeriod");
    ChoiceVariable tpm_sc_cmodVar = getChoiceVariable("tpm_sc_cmod");
    ChoiceVariable tpm_sc_psVar = getChoiceVariable("tpm_sc_ps");
    LongVariable tpm_modVar = getLongVariable("tpm_mod");
    DoubleVariable tpm_mod_periodVar = getDoubleVariable("tpm_mod_period");
    BooleanVariable tpm_sc_cpwmsVar = getBooleanVariable("tpm_sc_cpwms");
    LongVariable clockSourceVar = null;
    switch((int) tpm_sc_cmodVar.getValueAsLong()) {
        case 0:
        case 3:
            clockSourceVar = new LongVariable("Disabled", "/Tpm/Disabled");
            clockSourceVar.setOrigin("Disabled");
            clockSourceVar.setValue(0);
            break;
        default:
            tpm_sc_cmodVar.setValue(1);
        case 1:
            clockSourceVar = system_tpm_clockVar;
            break;
        case 2:
            clockSourceVar = getLongVariable("tpmExternalClock");
            ;
            break;
    }
    double clockFrequency = clockSourceVar.getValueAsDouble();
    String clockOrigin = clockSourceVar.getOrigin();
    clockFrequency = clockFrequency / (1L << tpm_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);
    tpm_mod_periodVar.enable(clockFrequency != 0);
    if (clockFrequency != 0) {
        long tpm_mod = tpm_modVar.getValueAsLong();
        double clockPeriod = 1.0 / clockFrequency;
        clockPeriodVar.setValue(clockPeriod);
        boolean tpm_sc_cpwms = tpm_sc_cpwmsVar.getValueAsBoolean();
        double tpm_mod_period = clockPeriod * (tpm_sc_cpwms ? (2 * (tpm_mod)) : ((tpm_mod + 1)));
        if (variable != null) {
            // Update selectively
            if (variable.equals(tpm_mod_periodVar)) {
                tpm_mod_period = tpm_mod_periodVar.getValueAsDouble();
                // Calculate rounded value
                if (tpm_sc_cpwms) {
                    tpm_mod = Math.max(0, Math.round((tpm_mod_period / clockPeriod) / 2));
                } else {
                    tpm_mod = Math.max(0, Math.round((tpm_mod_period / clockPeriod) - 1));
                }
                tpm_mod_period = clockPeriod * (tpm_sc_cpwms ? (2 * (tpm_mod)) : ((tpm_mod + 1)));
                // Update
                tpm_modVar.setValue(tpm_mod);
            }
        }
        double tpm_mod_periodMax = clockPeriod * (tpm_sc_cpwms ? (2 * (65535.5)) : ((65536.5)));
        tpm_mod_periodVar.setValue(tpm_mod_period);
        tpm_mod_periodVar.setMax(tpm_mod_periodMax);
    }
}
Also used : LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)

Example 2 with DoubleVariable

use of net.sourceforge.usbdm.deviceEditor.information.DoubleVariable in project usbdm-eclipse-plugins by podonoghue.

the class ParseMenuXML method parseDoubleOption.

/**
 * Parse &lt;doubleOption&gt; element<br>
 *
 * @param varElement
 * @throws Exception
 */
private void parseDoubleOption(BaseModel parent, Element varElement) throws Exception {
    DoubleVariable variable = (DoubleVariable) parseCommonAttributes(parent, varElement, DoubleVariable.class).getVariable();
    try {
        if (varElement.hasAttribute("min")) {
            variable.setMin(getLongAttribute(varElement, "min"));
        }
        if (varElement.hasAttribute("max")) {
            variable.setMax(getLongAttribute(varElement, "max"));
        }
    } catch (NumberFormatException e) {
        throw new Exception("Illegal min/max value in " + variable.getName(), e);
    }
    variable.setUnits(Units.valueOf(varElement.getAttribute("units")));
}
Also used : DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with DoubleVariable

use of net.sourceforge.usbdm.deviceEditor.information.DoubleVariable in project usbdm-eclipse-plugins by podonoghue.

the class PdbValidate method doClockValidate.

/**
 * Validate the PDB clock settings
 *
 * @param  variable   Variable that triggered change (may be null)
 *
 * @throws Exception
 */
void doClockValidate(Variable variable) throws Exception {
    // In
    Variable clockVar = getVariable("/SIM/system_bus_clock");
    Variable pdb_sc_prescalerVar = getVariable("pdb_sc_prescaler");
    Variable pdb_sc_multVar = getVariable("pdb_sc_mult");
    // Out
    DoubleVariable pdb_periodVar = getDoubleVariable("pdb_period");
    DoubleVariable pdb_frequencyVar = getDoubleVariable("pdb_frequency");
    pdbClockOrigin = "PDB Clock";
    clockChanged = (variable == null) || ((variable.equals(clockVar)) || (variable.equals(pdb_sc_prescalerVar)) || (variable.equals(pdb_sc_multVar)));
    long busFrequency = clockVar.getValueAsLong();
    long pdb_sc_prescaler = pdb_sc_prescalerVar.getValueAsLong();
    long pdb_sc_mult = pdb_sc_multVar.getValueAsLong();
    // MULT divider values
    final long[] multValues = { 1, 10, 20, 40 };
    pdb_frequency = pdb_frequencyVar.getValueAsDouble();
    pdb_period = pdb_periodVar.getValueAsDouble();
    if (clockChanged) {
        // Update everything
        pdb_frequency = busFrequency / ((1 << pdb_sc_prescaler) * multValues[(int) pdb_sc_mult]);
        if (pdb_frequency == 0) {
            // For safety
            pdb_period = 1;
        } else {
            pdb_period = 1 / pdb_frequency;
        }
        pdb_frequencyVar.setValue(pdb_frequency);
        pdb_frequencyVar.setOrigin(pdbClockOrigin + " frequency / (prescaler * divider)");
        pdb_periodVar.setValue(pdb_period);
        pdb_periodVar.setOrigin(pdbClockOrigin + " period * prescaler * divider");
    }
}
Also used : BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) Variable(net.sourceforge.usbdm.deviceEditor.information.Variable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)

Example 4 with DoubleVariable

use of net.sourceforge.usbdm.deviceEditor.information.DoubleVariable in project usbdm-eclipse-plugins by podonoghue.

the class PdbValidate method doChannelValidate.

/**
 * Validate a PDB channel settings
 *
 * @param  variable   Variable that triggered change (may be null)
 * @param channel     The channel to validate e.g. "0", "1" etc
 *
 * @throws Exception
 */
void doChannelValidate(Variable variable, String channel) throws Exception {
    // In/Out
    LongVariable pdb_chX_dly0Var = safeGetLongVariable("pdb_ch" + channel + "_dly0");
    if (pdb_chX_dly0Var == null) {
        // Channel doesn't exit
        return;
    }
    LongVariable pdb_chX_dly1Var = getLongVariable("pdb_ch" + channel + "_dly1");
    LongVariable pdb_chX_c1_tosVar = getLongVariable("pdb_ch" + channel + "_c1_tos");
    LongVariable pdb_chX_c1_enVar = getLongVariable("pdb_ch" + channel + "_c1_en");
    // In/Out
    DoubleVariable pdb_chX_dly0_delayVar = getDoubleVariable("pdb_ch" + channel + "_dly0_delay");
    DoubleVariable pdb_chX_dly1_delayVar = getDoubleVariable("pdb_ch" + channel + "_dly1_delay");
    boolean pt0Enable = (pdb_chX_c1_enVar.getValueAsLong() & (1 << 0)) != 0;
    boolean pt1Enable = (pdb_chX_c1_enVar.getValueAsLong() & (1 << 1)) != 0;
    boolean dly0Enable = pt0Enable && ((pdb_chX_c1_tosVar.getValueAsLong() & (1 << 0)) != 0);
    boolean dly1Enable = pt1Enable && ((pdb_chX_c1_tosVar.getValueAsLong() & (1 << 1)) != 0);
    // Do enable/disable first
    pdb_chX_dly0Var.enable(dly0Enable);
    pdb_chX_dly0_delayVar.enable(dly0Enable);
    pdb_chX_dly1Var.enable(dly1Enable);
    pdb_chX_dly1_delayVar.enable(dly1Enable);
    // Get current values
    long pdb_chX_dly0 = pdb_chX_dly0Var.getRawValueAsLong();
    double pdb_chX_dly0_delay = pdb_chX_dly0_delayVar.getRawValueAsDouble();
    long pdb_chX_dly1 = pdb_chX_dly1Var.getRawValueAsLong();
    double pdb_chX_dly1_delay = pdb_chX_dly1_delayVar.getRawValueAsDouble();
    if (clockChanged) {
        pdb_chX_dly0_delayVar.setOrigin(pdbClockOrigin + " period * pdb_ch" + channel + "_dly0");
        pdb_chX_dly1_delayVar.setOrigin(pdbClockOrigin + " period * pdb_ch" + channel + "_dly1");
    }
    if (modChanged) {
        pdb_chX_dly0Var.setMax(pdb_mod);
        pdb_chX_dly1Var.setMax(pdb_mod);
    }
    if (variable != null) {
        if (variable.equals(pdb_chX_dly0_delayVar)) {
            // Calculate rounded value
            pdb_chX_dly0 = Math.max(0, Math.round((pdb_chX_dly0_delay / pdb_period) - 1));
            // Update
            pdb_chX_dly0Var.setValue(pdb_chX_dly0);
        } else if (variable.equals(pdb_chX_dly1_delayVar)) {
            // Calculate rounded value
            pdb_chX_dly1 = Math.max(0, Math.round((pdb_chX_dly1_delay / pdb_period) - 1));
            // Update
            pdb_chX_dly1Var.setValue(pdb_chX_dly1);
        }
    }
    pdb_chX_dly0_delayVar.setValue(pdb_period * (pdb_chX_dly0 + 1));
    pdb_chX_dly1_delayVar.setValue(pdb_period * (pdb_chX_dly1 + 1));
    pdb_chX_dly0_delayVar.setMax((pdb_mod + 1.5) * pdb_period);
    pdb_chX_dly1_delayVar.setMax((pdb_mod + 1.5) * pdb_period);
}
Also used : LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)

Example 5 with DoubleVariable

use of net.sourceforge.usbdm.deviceEditor.information.DoubleVariable in project usbdm-eclipse-plugins by podonoghue.

the class PdbValidate method doCounterValidate.

/**
 * Validate the PDB counter settings
 *
 * @param  variable   Variable that triggered change (may be null)
 *
 * @throws Exception
 */
public void doCounterValidate(Variable variable) throws Exception {
    // In/Out
    LongVariable pdb_modVar = getLongVariable("pdb_mod");
    LongVariable pdb_idlyVar = getLongVariable("pdb_idly");
    DoubleVariable pdb_mod_periodVar = getDoubleVariable("pdb_mod_period");
    DoubleVariable pdb_idly_delayVar = getDoubleVariable("pdb_idly_delay");
    pdb_mod = pdb_modVar.getValueAsLong();
    pdb_mod_period = pdb_mod_periodVar.getValueAsDouble();
    long pdb_idly = pdb_idlyVar.getValueAsLong();
    double pdb_idly_delay = pdb_idly_delayVar.getValueAsDouble();
    if (clockChanged) {
        // Update everything
        pdb_mod_period = (pdb_mod + 1) * pdb_period;
        pdb_mod_periodVar.setValue(pdb_mod_period);
        pdb_mod_periodVar.setOrigin(pdbClockOrigin + " period * PDB modulo");
        pdb_mod_periodVar.setMax((pdb_modVar.getMax() + 1.5) * pdb_period);
        pdb_idly_delayVar.setValue((pdb_idly + 1) * pdb_period);
        pdb_idly_delayVar.setOrigin(pdbClockOrigin + " period * PDB idly");
        modChanged = true;
    } else if (variable != null) {
        // Update selectively
        if (variable.equals(pdb_modVar)) {
            pdb_mod_period = (pdb_mod + 1) * pdb_period;
            pdb_mod_periodVar.setValue(pdb_mod_period);
            modChanged = true;
        } else if (variable.equals(pdb_mod_periodVar)) {
            // Calculate rounded value
            pdb_mod = Math.max(0, Math.round((pdb_mod_period / pdb_period) - 1));
            pdb_mod_period = (pdb_mod + 1) * pdb_period;
            // Update
            pdb_modVar.setValue(pdb_mod);
            // Need to show effect of rounding
            pdb_mod_periodVar.setValue(pdb_mod_period);
            modChanged = true;
        } else if (variable.equals(pdb_idlyVar)) {
            pdb_idly_delayVar.setValue((pdb_idly + 1) * pdb_period);
        } else if (variable.equals(pdb_idly_delayVar)) {
            // Calculate rounded value
            pdb_idly = Math.max(0, Math.round((pdb_idly_delay / pdb_period) - 1));
            // Update
            pdb_idlyVar.setValue(pdb_idly);
            // Need to show effect of rounding
            pdb_idly_delayVar.setValue((pdb_idly + 1) * pdb_period);
        }
    }
    if (modChanged) {
        pdb_idly_delayVar.setMax((pdb_mod + 1.5) * pdb_period);
        pdb_idlyVar.setMax(pdb_mod);
    }
}
Also used : LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)

Aggregations

DoubleVariable (net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)12 LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)11 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)7 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)4 Variable (net.sourceforge.usbdm.deviceEditor.information.Variable)3 FileNotFoundException (java.io.FileNotFoundException)1 PinListVariable (net.sourceforge.usbdm.deviceEditor.information.PinListVariable)1 Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)1 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)1 Status (net.sourceforge.usbdm.deviceEditor.model.Status)1 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1