Search in sources :

Example 16 with Variable

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

the class ParseMenuXML method parseCommonAttributes.

/**
 * Parse attributes common to most variables<br>
 * Also creates model.
 * Processes the following attributes:
 * <li>name
 * <li>key
 * <li>description
 * <li>toolTip (processed)
 * <li>constant
 * <li>derived
 * <li>derivedFrom
 * <li>origin
 *
 * @param parent        Parent for model
 * @param varElement    Element obtain attributes from
 * @param clazz         Class of variable to create
 *
 * @return Variable created (or existing one)
 * @throws Exception
 */
private VariableModel parseCommonAttributes(BaseModel parent, Element varElement, Class<?> clazz) throws Exception {
    Variable variable = createVariable(varElement, clazz);
    Variable otherVariable = getDerived(varElement);
    if (otherVariable != null) {
        variable.setDescription(otherVariable.getDescription());
        variable.setToolTip(otherVariable.getToolTip());
        variable.setOrigin(otherVariable.getRawOrigin());
    }
    if (varElement.hasAttribute("description")) {
        variable.setDescription(varElement.getAttribute("description"));
    }
    if (varElement.hasAttribute("toolTip")) {
        variable.setToolTip(getToolTip(varElement));
    }
    if (varElement.hasAttribute("value")) {
        // Value is used as default and initial value
        String value = varElement.getAttribute("value");
        variable.setValue(value);
        variable.setDefault(value);
        variable.setDisabledValue(value);
    }
    if (varElement.hasAttribute("disabledValue")) {
        // Value is used as default and initial value
        String value = varElement.getAttribute("disabledValue");
        variable.setDisabledValue(value);
    }
    if (varElement.hasAttribute("origin")) {
        variable.setOrigin(varElement.getAttribute("origin"));
    }
    if (varElement.hasAttribute("hidden")) {
        // Value is used as default and initial value
        if (Boolean.valueOf(varElement.getAttribute("hidden"))) {
            parent = null;
        }
    }
    variable.setDerived(Boolean.valueOf(varElement.getAttribute("derived")));
    VariableModel model = variable.createModel(parent);
    model.setConstant(Boolean.valueOf(varElement.getAttribute("constant")));
    return model;
}
Also used : BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) PinListVariable(net.sourceforge.usbdm.deviceEditor.information.PinListVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable) IrqVariable(net.sourceforge.usbdm.deviceEditor.information.IrqVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) IndexedCategoryVariable(net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable) Variable(net.sourceforge.usbdm.deviceEditor.information.Variable) BitmaskVariable(net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) NumericListVariable(net.sourceforge.usbdm.deviceEditor.information.NumericListVariable) VariableModel(net.sourceforge.usbdm.deviceEditor.model.VariableModel)

Example 17 with Variable

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

the class ParseMenuXML method createVariable.

/**
 * @param varElement    Element to obtain attributes from
 * @param clazz         Class of variable to create
 *
 * @return Variable created (or existing one)
 * @throws Exception
 */
private Variable createVariable(Element varElement, Class<?> clazz) throws Exception {
    String name = varElement.getAttribute("name");
    String key = varElement.getAttribute("key");
    String indexSuffix = "";
    indexSuffix = "[" + Integer.toString(fIndex) + "]";
    if (key.isEmpty()) {
        key = name;
    }
    key = substituteKey(key);
    name = substituteKey(name);
    key = key.replaceAll("\\.$", indexSuffix);
    name = name.replaceAll("\\.$", indexSuffix);
    key = fProvider.makeKey(key);
    Variable newVariable = null;
    Variable existingVariable = safeGetVariable(key);
    if (existingVariable == null) {
        // New variable
        try {
            newVariable = (Variable) clazz.getConstructor(String.class, String.class).newInstance(name, key);
            fProvider.addVariable(newVariable);
        } catch (Exception e) {
            throw new Exception("Unable to create variable!");
        }
    } else {
        if (!existingVariable.getClass().equals(clazz)) {
            throw new Exception("Overridden variable " + key + " has wrong type");
        }
        newVariable = existingVariable;
    }
    return newVariable;
}
Also used : BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) PinListVariable(net.sourceforge.usbdm.deviceEditor.information.PinListVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable) IrqVariable(net.sourceforge.usbdm.deviceEditor.information.IrqVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) IndexedCategoryVariable(net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable) Variable(net.sourceforge.usbdm.deviceEditor.information.Variable) BitmaskVariable(net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) NumericListVariable(net.sourceforge.usbdm.deviceEditor.information.NumericListVariable) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) FileNotFoundException(java.io.FileNotFoundException)

Example 18 with Variable

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

the class ClockValidator_MCG_no_pll method validateClocks.

protected void validateClocks(Variable variable) throws Exception {
    // System.err.println(getSimpleClassName()+" Var = "+variable);
    super.validate(variable);
    StringVariable clockConfig = safeGetStringVariable("ClockConfig");
    clockConfig.setStatus(isValidCIdentifier(clockConfig.getValueAsString()) ? (String) null : "Illegal C enum value");
    // OSC0 Clock monitor
    // =================================
    Variable mcg_c6_cme0Var = getVariable("mcg_c6_cme0");
    Variable mcg_c2_locre0Var = getVariable("mcg_c2_locre0");
    mcg_c2_locre0Var.enable(mcg_c6_cme0Var.getValueAsBoolean());
    // =================================
    Variable system_mcgfllclk_clockVar = getVariable("system_mcgfllclk_clock");
    Variable mcg_c4_dmx32Var = getVariable("mcg_c4_dmx32");
    Variable mcg_c1_frdivVar = getVariable("mcg_c1_frdiv");
    Variable mcg_c4_drst_drsVar = getVariable("mcg_c4_drst_drs");
    Variable system_mcgoutclk_clock_sourceVar = getVariable("system_mcgoutclk_clock_source");
    Variable system_mcgoutclk_clockVar = getVariable("system_mcgoutclk_clock");
    Variable mcg_c1_irefsVar = getVariable("mcg_c1_irefs");
    Variable mcg_c1_clksVar = getVariable("mcg_c1_clks");
    Variable mcg_c2_lpVar = getVariable("mcg_c2_lp");
    // Determine MCGIRCLK (not gated/undivided and gated)
    // ========================================
    Variable mcg_sc_fcrdivVar = safeGetVariable("mcg_sc_fcrdiv");
    Variable system_fast_irc_clockVar = getVariable("system_fast_irc_clock");
    Variable system_slow_irc_clockVar = getVariable("system_slow_irc_clock");
    Variable mcg_c2_ircsVar = getVariable("mcg_c2_ircs");
    Variable system_mcgir_ungated_clock = new LongVariable("system_mcgir_ungated", null);
    if (mcg_c2_ircsVar.getValueAsBoolean()) {
        // Fast IRC selected
        if (mcg_sc_fcrdivVar != null) {
            // Variable divisor
            long mcg_sc_fcrdiv = mcg_sc_fcrdivVar.getValueAsLong();
            system_mcgir_ungated_clock.setOrigin("(Fast IRC)/FCRDIV");
            system_mcgir_ungated_clock.setValue(system_fast_irc_clockVar.getValueAsLong() / (1 << mcg_sc_fcrdiv));
        } else {
            // Fixed divisor of 2
            system_mcgir_ungated_clock.setOrigin("(Fast IRC)/2");
            system_mcgir_ungated_clock.setValue(system_fast_irc_clockVar.getValueAsLong() / 2);
        }
    } else {
        // Slow IRC selected
        system_mcgir_ungated_clock.setOrigin("Slow IRC");
        system_mcgir_ungated_clock.setValue(system_slow_irc_clockVar.getValueAsLong());
    }
    Variable system_mcgirclk_clockVar = getVariable("system_mcgirclk_clock");
    system_mcgirclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
    Variable mcg_c1_irclkenVar = getVariable("mcg_c1_irclken");
    Variable mcg_c1_irefstenVar = getVariable("mcg_c1_irefsten");
    if (mcg_c1_irclkenVar.getValueAsBoolean()) {
        // Enabled
        system_mcgirclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
        system_mcgirclk_clockVar.setStatus((Status) null);
        system_mcgirclk_clockVar.enable(true);
        mcg_c1_irefstenVar.enable(true);
    } else {
        // Disabled
        system_mcgirclk_clockVar.setValue(0);
        system_mcgirclk_clockVar.setStatus(new Status("Disabled by mcg_c1_irclken", Severity.OK));
        system_mcgirclk_clockVar.enable(false);
        mcg_c1_irefstenVar.enable(false);
    }
    // Clock Mapping OSC0 always exists
    // ====================================
    String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
    LongVariable osc0_osc_clockVar = getLongVariable(osc0_peripheral + "/osc_clock");
    // Determine MCG external reference clock [mcg_erc_clock]
    // ========================================================
    ChoiceVariable mcg_c7_oscselVar = safeGetChoiceVariable("mcg_c7_oscsel");
    Variable mcg_erc_clockVar = getVariable("mcg_erc_clock");
    if (mcg_c7_oscselVar == null) {
        // ERC = fixed OSCCLK (OSC0 main oscillator)
        mcg_erc_clockVar.setValue(osc0_osc_clockVar.getValueAsLong());
        mcg_erc_clockVar.setStatus(osc0_osc_clockVar.getFilteredStatus());
        mcg_erc_clockVar.setOrigin(osc0_osc_clockVar.getOrigin());
    } else {
        // Get alternative oscillator Must exist if mcg_c7_oscsel exists
        String osc32k_peripheral = getStringVariable("/SIM/osc32k_peripheral").getValueAsString();
        LongVariable osc32k_osc_clockVar = getLongVariable(osc32k_peripheral + "/osc_clock");
        // Get alternative oscillator #2 may not exist
        Variable system_irc48m_clockVar = safeGetVariable("system_irc48m_clock");
        // Determine ERC
        switch((int) mcg_c7_oscselVar.getValueAsLong()) {
            case // ERC = IRC48MCLK (OSC2) if it exists
            2:
                if (system_irc48m_clockVar != null) {
                    mcg_erc_clockVar.setValue(system_irc48m_clockVar.getValueAsLong());
                    mcg_erc_clockVar.setStatus((Status) null);
                    mcg_erc_clockVar.setOrigin("IRC48MCLK");
                    break;
                }
                // Force legal selection
                mcg_c7_oscselVar.setValue(0);
            // no break
            default:
            case // ERC = OSCCLK (OSC0 main oscillator)
            0:
                mcg_erc_clockVar.setValue(osc0_osc_clockVar.getValueAsLong());
                mcg_erc_clockVar.setStatus(osc0_osc_clockVar.getFilteredStatus());
                mcg_erc_clockVar.setOrigin(osc0_osc_clockVar.getOrigin());
                break;
            case // ERC = RTCCLK (OSC1 oscillator)
            1:
                mcg_erc_clockVar.setValue(osc32k_osc_clockVar.getValueAsLong());
                mcg_erc_clockVar.setStatus(osc32k_osc_clockVar.getFilteredStatus());
                mcg_erc_clockVar.setOrigin(osc32k_osc_clockVar.getOrigin() + "[RTCCLK]");
                break;
        }
    }
    // Main clock mode
    // ===============================
    int mcg_c1_clks;
    int mcg_c2_lp;
    boolean mcg_c1_irefs;
    // Main clock mode
    // ====================
    ClockMode clock_mode = ClockMode.valueOf(getVariable("clock_mode").getSubstitutionValue());
    Variable fll_enabledVar = getVariable("fll_enabled");
    Variable fllInputFrequencyVar = getVariable("fllInputFrequency");
    switch(clock_mode) {
        default:
        case ClockMode_None:
            mcg_c1_clks = 0;
            mcg_c2_lp = 0;
            mcg_c1_irefs = true;
            system_mcgoutclk_clock_sourceVar.setValue("FLL output");
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_FEI:
            mcg_c1_clks = 0;
            mcg_c2_lp = 0;
            mcg_c1_irefs = true;
            system_mcgoutclk_clock_sourceVar.setValue("FLL output");
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_FEE:
            mcg_c1_clks = 0;
            mcg_c2_lp = 0;
            mcg_c1_irefs = false;
            system_mcgoutclk_clock_sourceVar.setValue("FLL output");
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_FBI:
            mcg_c1_clks = 1;
            mcg_c2_lp = 0;
            mcg_c1_irefs = true;
            system_mcgoutclk_clock_sourceVar.setValue("MCGIRCLK");
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_FBE:
            mcg_c1_clks = 2;
            mcg_c2_lp = 0;
            mcg_c1_irefs = false;
            system_mcgoutclk_clock_sourceVar.setValue("MCGERCLK");
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_BLPI:
            mcg_c1_clks = 1;
            mcg_c2_lp = 1;
            mcg_c1_irefs = true;
            system_mcgoutclk_clock_sourceVar.setValue("MCGIRCLK");
            fll_enabledVar.setValue(false);
            break;
        case ClockMode_BLPE:
            mcg_c1_clks = 2;
            mcg_c2_lp = 1;
            mcg_c1_irefs = false;
            system_mcgoutclk_clock_sourceVar.setValue("MCGERCLK");
            fll_enabledVar.setValue(false);
            break;
    }
    mcg_c1_clksVar.setValue(mcg_c1_clks);
    mcg_c2_lpVar.setValue(mcg_c2_lp);
    mcg_c1_irefsVar.setValue(mcg_c1_irefs);
    Variable osc0_osc_cr_erclkenVar = safeGetBooleanVariable(osc0_peripheral + "/osc_cr_erclken");
    // =======================================
    // Find FLL dividers
    FllConfigure fllCheck = new FllConfigure(osc0_osc_cr_erclkenVar, safeGetVariable(osc0_peripheral + "/oscillatorRange"), getVariable("mcg_c2_range"), mcg_c1_irefs, mcg_erc_clockVar, system_slow_irc_clockVar.getValueAsLong(), (mcg_c7_oscselVar == null) ? 0 : mcg_c7_oscselVar.getValueAsLong(), mcg_c4_dmx32Var.getValueAsBoolean(), fllInputFrequencyVar, system_mcgfllclk_clockVar, getVariable("system_mcgffclk_clock"), DRST_DRS_MAX);
    mcg_c1_frdivVar.setValue(fllCheck.mcg_c1_frdiv);
    mcg_c4_drst_drsVar.setValue(fllCheck.mcg_c4_drst_drs);
    // ======================================
    // FLL status
    boolean fllEnabled = fll_enabledVar.getValueAsBoolean();
    fllInputFrequencyVar.enable(fllEnabled);
    if (fllEnabled) {
        boolean fllInputIsOK = (fllInputFrequencyVar.getStatus() == null) || (fllCheck.getFllStatus().getSeverity().lessThan(Severity.WARNING));
        system_mcgfllclk_clockVar.enable(fllInputIsOK);
        system_mcgfllclk_clockVar.setStatus(fllCheck.getFllStatus());
    } else {
        system_mcgfllclk_clockVar.enable(false);
        system_mcgfllclk_clockVar.setStatus(new Status("FLL is disabled", Severity.WARNING));
    }
    mcg_c4_dmx32Var.enable(fllEnabled);
    mcg_c4_drst_drsVar.enable(fllEnabled);
    // Main clock mode
    // ===============================
    Status clock_mode_Status = null;
    switch(clock_mode) {
        default:
        case ClockMode_None:
            system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus((Status) null);
            clock_mode_Status = new Status("No clock settings are applied", Severity.WARNING);
            break;
        case ClockMode_FEI:
            system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgfllclk_clockVar.getFilteredStatus());
            break;
        case ClockMode_FEE:
            system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgfllclk_clockVar.getFilteredStatus());
            break;
        case ClockMode_FBI:
            system_mcgoutclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgir_ungated_clock.getFilteredStatus());
            break;
        case ClockMode_FBE:
            system_mcgoutclk_clockVar.setValue(mcg_erc_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(mcg_erc_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(mcg_erc_clockVar.getFilteredStatus());
            break;
        case ClockMode_BLPI:
            system_mcgoutclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgir_ungated_clock.getFilteredStatus());
            break;
        case ClockMode_BLPE:
            system_mcgoutclk_clockVar.setValue(mcg_erc_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(mcg_erc_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(mcg_erc_clockVar.getFilteredStatus());
            break;
    }
    system_mcgoutclk_clock_sourceVar.setStatus(clock_mode_Status);
    system_mcgoutclk_clock_sourceVar.setOrigin(system_mcgoutclk_clockVar.getOrigin());
}
Also used : Status(net.sourceforge.usbdm.deviceEditor.model.Status) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable) Variable(net.sourceforge.usbdm.deviceEditor.information.Variable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)

Example 19 with Variable

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

the class ClockValidator_MKL method validateClocks.

protected void validateClocks(Variable variable) throws Exception {
    // System.err.println(getSimpleClassName()+" Var = "+variable);
    super.validate(variable);
    StringVariable clockConfig = safeGetStringVariable("ClockConfig");
    clockConfig.setStatus(isValidCIdentifier(clockConfig.getValueAsString()) ? (String) null : "Illegal C enum value");
    // OSC0 Clock monitor
    // =================================
    Variable mcg_c6_cme0Var = getVariable("mcg_c6_cme0");
    Variable mcg_c2_locre0Var = getVariable("mcg_c2_locre0");
    mcg_c2_locre0Var.enable(mcg_c6_cme0Var.getValueAsBoolean());
    // =================================
    Variable system_mcgfllclk_clockVar = getVariable("system_mcgfllclk_clock");
    Variable mcg_c4_dmx32Var = getVariable("mcg_c4_dmx32");
    Variable mcg_c1_frdivVar = getVariable("mcg_c1_frdiv");
    Variable mcg_c4_drst_drsVar = getVariable("mcg_c4_drst_drs");
    Variable pll0EnabledVar = getVariable("pll0Enabled");
    Variable pll0InputFrequencyVar = getVariable("pll0InputFrequency");
    Variable pll0OutputFrequency = getVariable("pll0OutputFrequency");
    Variable mcg_c5_pllclkenVar = getVariable("mcg_c5_pllclken");
    Variable mcg_c5_pllstenVar = getVariable("mcg_c5_pllsten");
    Variable mcg_c5_prdiv0Var = getVariable("mcg_c5_prdiv0");
    Variable mcg_c6_vdiv0Var = getVariable("mcg_c6_vdiv0");
    Variable system_mcgpllclk_clockVar = getVariable("system_mcgpllclk_clock");
    Variable system_mcgoutclk_clock_sourceVar = getVariable("system_mcgoutclk_clock_source");
    Variable system_mcgoutclk_clockVar = getVariable("system_mcgoutclk_clock");
    Variable mcg_c1_irefsVar = getVariable("mcg_c1_irefs");
    Variable mcg_c1_clksVar = getVariable("mcg_c1_clks");
    Variable mcg_c2_lpVar = getVariable("mcg_c2_lp");
    Variable mcg_c6_pllsVar = getVariable("mcg_c6_plls");
    // Determine MCGIRCLK (not gated/undivided and gated)
    // ========================================
    Variable mcg_sc_fcrdivVar = safeGetVariable("mcg_sc_fcrdiv");
    Variable system_fast_irc_clockVar = getVariable("system_fast_irc_clock");
    Variable system_slow_irc_clockVar = getVariable("system_slow_irc_clock");
    Variable mcg_c2_ircsVar = getVariable("mcg_c2_ircs");
    Variable system_mcgir_ungated_clock = new LongVariable("system_mcgir_ungated", null);
    if (mcg_c2_ircsVar.getValueAsBoolean()) {
        // Fast IRC selected
        if (mcg_sc_fcrdivVar != null) {
            // Variable divisor
            long mcg_sc_fcrdiv = mcg_sc_fcrdivVar.getValueAsLong();
            system_mcgir_ungated_clock.setOrigin("(Fast IRC)/FCRDIV");
            system_mcgir_ungated_clock.setValue(system_fast_irc_clockVar.getValueAsLong() / (1 << mcg_sc_fcrdiv));
        } else {
            // Fixed divisor of 2
            system_mcgir_ungated_clock.setOrigin("(Fast IRC)/2");
            system_mcgir_ungated_clock.setValue(system_fast_irc_clockVar.getValueAsLong() / 2);
        }
    } else {
        // Slow IRC selected
        system_mcgir_ungated_clock.setOrigin("Slow IRC");
        system_mcgir_ungated_clock.setValue(system_slow_irc_clockVar.getValueAsLong());
    }
    Variable system_mcgirclk_clockVar = getVariable("system_mcgirclk_clock");
    system_mcgirclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
    Variable mcg_c1_irclkenVar = getVariable("mcg_c1_irclken");
    Variable mcg_c1_irefstenVar = getVariable("mcg_c1_irefsten");
    if (mcg_c1_irclkenVar.getValueAsBoolean()) {
        // Enabled
        system_mcgirclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
        system_mcgirclk_clockVar.setStatus((Status) null);
        system_mcgirclk_clockVar.enable(true);
        mcg_c1_irefstenVar.enable(true);
    } else {
        // Disabled
        system_mcgirclk_clockVar.setValue(0);
        system_mcgirclk_clockVar.setStatus(new Status("Disabled by mcg_c1_irclken", Severity.OK));
        system_mcgirclk_clockVar.enable(false);
        mcg_c1_irefstenVar.enable(false);
    }
    // Clock Mapping
    // =================
    String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
    LongVariable osc0_osc_clockVar = getLongVariable(osc0_peripheral + "/osc_clock");
    // Only MCG external reference clock on device
    // ========================================================
    Variable mcg_erc_clockVar = getVariable("mcg_erc_clock");
    mcg_erc_clockVar.setValue(osc0_osc_clockVar.getValueAsLong());
    mcg_erc_clockVar.setStatus(osc0_osc_clockVar.getFilteredStatus());
    mcg_erc_clockVar.setOrigin(osc0_osc_clockVar.getOrigin());
    // Main clock mode
    // ===============================
    int mcg_c1_clks;
    int mcg_c6_plls;
    int mcg_c2_lp;
    boolean mcg_c1_irefs;
    // Main clock mode
    // ====================
    ClockMode clock_mode = ClockMode.valueOf(getVariable("clock_mode").getSubstitutionValue());
    Variable fll_enabledVar = getVariable("fll_enabled");
    Variable fllInputFrequencyVar = getVariable("fllInputFrequency");
    switch(clock_mode) {
        default:
        case ClockMode_None:
            mcg_c1_clks = 0;
            mcg_c6_plls = 0;
            mcg_c2_lp = 0;
            mcg_c1_irefs = true;
            system_mcgoutclk_clock_sourceVar.setValue("FLL output");
            pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_FEI:
            mcg_c1_clks = 0;
            mcg_c6_plls = 0;
            mcg_c2_lp = 0;
            mcg_c1_irefs = true;
            system_mcgoutclk_clock_sourceVar.setValue("FLL output");
            pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_FEE:
            mcg_c1_clks = 0;
            mcg_c6_plls = 0;
            mcg_c2_lp = 0;
            mcg_c1_irefs = false;
            system_mcgoutclk_clock_sourceVar.setValue("FLL output");
            pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_FBI:
            mcg_c1_clks = 1;
            mcg_c6_plls = 0;
            mcg_c2_lp = 0;
            mcg_c1_irefs = true;
            system_mcgoutclk_clock_sourceVar.setValue("MCGIRCLK");
            pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_FBE:
            mcg_c1_clks = 2;
            mcg_c6_plls = 0;
            mcg_c2_lp = 0;
            mcg_c1_irefs = false;
            system_mcgoutclk_clock_sourceVar.setValue("MCGERCLK");
            pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
            fll_enabledVar.setValue(true);
            break;
        case ClockMode_BLPI:
            mcg_c1_clks = 1;
            mcg_c6_plls = 0;
            mcg_c2_lp = 1;
            mcg_c1_irefs = true;
            system_mcgoutclk_clock_sourceVar.setValue("MCGIRCLK");
            pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
            fll_enabledVar.setValue(false);
            break;
        case ClockMode_BLPE:
            mcg_c1_clks = 2;
            mcg_c6_plls = 0;
            mcg_c2_lp = 1;
            mcg_c1_irefs = false;
            system_mcgoutclk_clock_sourceVar.setValue("MCGERCLK");
            pll0EnabledVar.setValue(mcg_c5_pllclkenVar.getValueAsBoolean());
            fll_enabledVar.setValue(false);
            break;
        case ClockMode_PBE:
            mcg_c1_clks = 2;
            mcg_c6_plls = 1;
            mcg_c2_lp = 0;
            mcg_c1_irefs = false;
            system_mcgoutclk_clock_sourceVar.setValue("MCGERCLK");
            pll0EnabledVar.setValue(true);
            fll_enabledVar.setValue(false);
            break;
        case ClockMode_PEE:
            mcg_c1_clks = 0;
            mcg_c6_plls = 1;
            mcg_c2_lp = 0;
            mcg_c1_irefs = false;
            system_mcgoutclk_clock_sourceVar.setValue("PLL output");
            pll0EnabledVar.setValue(true);
            fll_enabledVar.setValue(false);
            break;
    }
    mcg_c1_clksVar.setValue(mcg_c1_clks);
    mcg_c6_pllsVar.setValue(mcg_c6_plls);
    mcg_c2_lpVar.setValue(mcg_c2_lp);
    mcg_c1_irefsVar.setValue(mcg_c1_irefs);
    Variable osc0_osc_cr_erclkenVar = safeGetBooleanVariable(osc0_peripheral + "/osc_cr_erclken");
    // =======================================
    // Find FLL dividers
    FllConfigure fllCheck = new FllConfigure(osc0_osc_cr_erclkenVar, safeGetVariable(osc0_peripheral + "/oscillatorRange"), getVariable("mcg_c2_range"), mcg_c1_irefs, mcg_erc_clockVar, system_slow_irc_clockVar.getValueAsLong(), // Always uses OSC0
    0, mcg_c4_dmx32Var.getValueAsBoolean(), fllInputFrequencyVar, system_mcgfllclk_clockVar, getVariable("system_mcgffclk_clock"), DRST_DRS_MAX);
    mcg_c1_frdivVar.setValue(fllCheck.mcg_c1_frdiv);
    mcg_c4_drst_drsVar.setValue(fllCheck.mcg_c4_drst_drs);
    // Internal PLL
    // ========================================
    // Find PLL divider
    PllConfigure pllConfigure = new PllConfigure(PLL_OUT_MIN, PLL_OUT_MAX, PLL_IN_MIN, PLL_IN_MAX, PRDIV_MIN, PRDIV_MAX, VDIV_MIN, VDIV_MAX, PLL_POST_DIV);
    pllConfigure.validate(mcg_erc_clockVar, pll0InputFrequencyVar, pll0OutputFrequency, mcg_c5_prdiv0Var, mcg_c6_vdiv0Var);
    boolean pll0Enabled = pll0EnabledVar.getValueAsBoolean();
    pll0InputFrequencyVar.enable(pll0Enabled);
    mcg_c5_prdiv0Var.enable(pll0Enabled);
    mcg_c6_vdiv0Var.enable(pll0Enabled);
    mcg_c5_pllstenVar.enable(pll0Enabled);
    if (pll0Enabled) {
        pll0OutputFrequency.enable(pll0InputFrequencyVar.getFilteredStatus() == null);
        pll0OutputFrequency.setStatus(pllConfigure.getPllStatus());
    } else {
        pll0OutputFrequency.enable(false);
        pll0OutputFrequency.setStatus(new Status("PLL is disabled", Severity.WARNING));
    }
    // Internal PLL
    system_mcgpllclk_clockVar.setValue(pll0OutputFrequency.getValueAsLong());
    system_mcgpllclk_clockVar.setOrigin(pll0OutputFrequency.getOrigin());
    system_mcgpllclk_clockVar.setStatus(pll0OutputFrequency.getFilteredStatus());
    // ======================================
    // FLL status
    boolean fllEnabled = fll_enabledVar.getValueAsBoolean();
    fllInputFrequencyVar.enable(fllEnabled);
    if (fllEnabled) {
        boolean fllInputIsOK = (fllInputFrequencyVar.getStatus() == null) || (fllCheck.getFllStatus().getSeverity().lessThan(Severity.WARNING));
        system_mcgfllclk_clockVar.enable(fllInputIsOK);
        system_mcgfllclk_clockVar.setStatus(fllCheck.getFllStatus());
    } else {
        system_mcgfllclk_clockVar.enable(false);
        system_mcgfllclk_clockVar.setStatus(new Status("FLL is disabled", Severity.WARNING));
    }
    mcg_c4_dmx32Var.enable(fllEnabled);
    mcg_c4_drst_drsVar.enable(fllEnabled);
    // Main clock mode
    // ===============================
    Status clock_mode_Status = null;
    switch(clock_mode) {
        default:
        case ClockMode_None:
            system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus((Status) null);
            clock_mode_Status = new Status("No clock settings are applied", Severity.WARNING);
            break;
        case ClockMode_FEI:
            system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgfllclk_clockVar.getFilteredStatus());
            break;
        case ClockMode_FEE:
            system_mcgoutclk_clockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgfllclk_clockVar.getFilteredStatus());
            break;
        case ClockMode_FBI:
            system_mcgoutclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgir_ungated_clock.getFilteredStatus());
            break;
        case ClockMode_FBE:
            system_mcgoutclk_clockVar.setValue(mcg_erc_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(mcg_erc_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(mcg_erc_clockVar.getFilteredStatus());
            break;
        case ClockMode_BLPI:
            system_mcgoutclk_clockVar.setValue(system_mcgir_ungated_clock.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgir_ungated_clock.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgir_ungated_clock.getFilteredStatus());
            break;
        case ClockMode_BLPE:
            system_mcgoutclk_clockVar.setValue(mcg_erc_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(mcg_erc_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(mcg_erc_clockVar.getFilteredStatus());
            break;
        case ClockMode_PBE:
            system_mcgoutclk_clockVar.setValue(mcg_erc_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(mcg_erc_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(mcg_erc_clockVar.getFilteredStatus());
            break;
        case ClockMode_PEE:
            system_mcgoutclk_clockVar.setValue(system_mcgpllclk_clockVar.getValueAsLong());
            system_mcgoutclk_clockVar.setOrigin(system_mcgpllclk_clockVar.getOrigin());
            system_mcgoutclk_clockVar.setStatus(system_mcgpllclk_clockVar.getFilteredStatus());
            break;
    }
    system_mcgoutclk_clock_sourceVar.setStatus(clock_mode_Status);
    system_mcgoutclk_clock_sourceVar.setOrigin(system_mcgoutclk_clockVar.getOrigin());
}
Also used : Status(net.sourceforge.usbdm.deviceEditor.model.Status) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) Variable(net.sourceforge.usbdm.deviceEditor.information.Variable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable)

Example 20 with Variable

use of net.sourceforge.usbdm.deviceEditor.information.Variable 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);
        }
    }
}
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) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)

Aggregations

Variable (net.sourceforge.usbdm.deviceEditor.information.Variable)21 LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)20 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)17 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)17 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)11 DoubleVariable (net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)10 BitmaskVariable (net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable)7 IndexedCategoryVariable (net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable)7 IrqVariable (net.sourceforge.usbdm.deviceEditor.information.IrqVariable)7 NumericListVariable (net.sourceforge.usbdm.deviceEditor.information.NumericListVariable)7 PinListVariable (net.sourceforge.usbdm.deviceEditor.information.PinListVariable)7 Status (net.sourceforge.usbdm.deviceEditor.model.Status)7 FileNotFoundException (java.io.FileNotFoundException)6 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)6 VariableModel (net.sourceforge.usbdm.deviceEditor.model.VariableModel)2 Node (org.w3c.dom.Node)2 ArrayList (java.util.ArrayList)1 Pair (net.sourceforge.usbdm.deviceEditor.information.Variable.Pair)1 Severity (net.sourceforge.usbdm.deviceEditor.model.Status.Severity)1 ProjectAction (net.sourceforge.usbdm.packageParser.ProjectAction)1