Search in sources :

Example 16 with ChoiceVariable

use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable 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 17 with ChoiceVariable

use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable 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;
    }
}
Also used : PinListVariable(net.sourceforge.usbdm.deviceEditor.information.PinListVariable) Status(net.sourceforge.usbdm.deviceEditor.model.Status) Signal(net.sourceforge.usbdm.deviceEditor.information.Signal) 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 18 with ChoiceVariable

use of net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable 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);
}
Also used : Signal(net.sourceforge.usbdm.deviceEditor.information.Signal) Pin(net.sourceforge.usbdm.deviceEditor.information.Pin) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) InfoTable(net.sourceforge.usbdm.deviceEditor.information.Peripheral.InfoTable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable) MappingInfo(net.sourceforge.usbdm.deviceEditor.information.MappingInfo)

Example 19 with ChoiceVariable

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

the class SimValidate method validateIndexVariables.

/**
 * Updates
 * - sim_sopt2_pllfllsel[x]
 * - system_peripheral_clock[x]
 * - system_core_clock[x]
 * - system_bus_clock[x]
 * - system_flexbus_clock[x]
 * - system_flash_clock[x]
 * - sim_clkdiv1_outdiv1[x]
 * - sim_clkdiv1_outdiv2[x]
 * - sim_clkdiv1_outdiv3[x]
 * - sim_clkdiv1_outdiv4[x]
 *
 * @param variable
 * @throws Exception
 */
void validateIndexVariables(Variable variable) throws Exception {
    final ChoiceVariable sim_sopt2_pllfllselVar = safeGetChoiceVariable("sim_sopt2_pllfllsel");
    final LongVariable system_mcgfllclk_clockVar = safeGetLongVariable("/MCG/system_mcgfllclk_clock");
    final LongVariable system_mcgpllclk_clockVar = safeGetLongVariable("/MCG/system_mcgpllclk_clock");
    final LongVariable usb1pfdclk_ClockVar = safeGetLongVariable("/MCG/usb1pfdclk_Clock");
    final LongVariable system_irc48m_clockVar = safeGetLongVariable("/MCG/system_irc48m_clock");
    // Determine PLLFLLCLOCK
    // =====================================
    final LongVariable peripheralClockVar = getLongVariable("system_peripheral_clock");
    switch((int) sim_sopt2_pllfllselVar.getValueAsLong()) {
        default:
            sim_sopt2_pllfllselVar.setValue(0);
        case 0:
            if (system_mcgfllclk_clockVar != null) {
                peripheralClockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
                peripheralClockVar.setStatus(system_mcgfllclk_clockVar.getFilteredStatus());
                peripheralClockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
            } else {
                peripheralClockVar.setValue(0);
                peripheralClockVar.setStatus(new Status("FLL not present", Severity.ERROR));
                peripheralClockVar.setOrigin(null);
            }
            break;
        case 1:
            if (system_mcgpllclk_clockVar != null) {
                peripheralClockVar.setValue(system_mcgpllclk_clockVar.getValueAsLong());
                peripheralClockVar.setStatus(system_mcgpllclk_clockVar.getFilteredStatus());
                peripheralClockVar.setOrigin(system_mcgpllclk_clockVar.getOrigin());
            } else {
                sim_sopt2_pllfllselVar.setValue(0);
            }
            break;
        case 2:
            if (usb1pfdclk_ClockVar != null) {
                peripheralClockVar.setValue(usb1pfdclk_ClockVar.getValueAsLong());
                peripheralClockVar.setStatus(usb1pfdclk_ClockVar.getStatus());
                peripheralClockVar.setOrigin(usb1pfdclk_ClockVar.getOrigin());
            } else {
                sim_sopt2_pllfllselVar.setValue(0);
            }
            break;
        case 3:
            if (system_irc48m_clockVar != null) {
                peripheralClockVar.setValue(system_irc48m_clockVar.getValueAsLong());
                peripheralClockVar.setStatus(system_irc48m_clockVar.getStatus());
                peripheralClockVar.setOrigin(system_irc48m_clockVar.getOrigin());
            } else {
                sim_sopt2_pllfllselVar.setValue(0);
            }
            break;
    }
    // Check if CLKDIV3 Present
    // =====================================
    final Long pllPostDiv3Value;
    final String pllPostDiv3Origin;
    final Variable sim_clkdiv3_pllfllVar = safeGetVariable("sim_clkdiv3_pllfll");
    final Variable system_peripheral_postdivider_clockVar = safeGetVariable("system_peripheral_postdivider_clock");
    if (sim_clkdiv3_pllfllVar != null) {
        int pllValue = Long.decode(sim_clkdiv3_pllfllVar.getSubstitutionValue()).intValue();
        int pllfllfrac = pllValue & 0x1;
        int pllflldiv = (pllValue >> 1) & 0x7;
        pllPostDiv3Value = (peripheralClockVar.getValueAsLong() * (pllfllfrac + 1)) / (pllflldiv + 1);
        pllPostDiv3Origin = peripheralClockVar.getOrigin() + " after /CLKDIV3";
        system_peripheral_postdivider_clockVar.setValue(pllPostDiv3Value);
        system_peripheral_postdivider_clockVar.setOrigin(pllPostDiv3Origin);
    } else {
        pllPostDiv3Value = peripheralClockVar.getValueAsLong();
        pllPostDiv3Origin = peripheralClockVar.getOrigin();
    }
    // ======================================
    final LongVariable system_core_clockVar = getLongVariable("system_core_clock");
    final LongVariable system_bus_clockVar = getLongVariable("system_bus_clock");
    final LongVariable system_flexbus_clockVar = safeGetLongVariable("system_flexbus_clock");
    final LongVariable system_flash_clockVar = getLongVariable("system_flash_clock");
    final LongVariable sim_clkdiv1_outdiv1Var = getLongVariable("sim_clkdiv1_outdiv1");
    final LongVariable sim_clkdiv1_outdiv2Var = getLongVariable("sim_clkdiv1_outdiv2");
    final LongVariable sim_clkdiv1_outdiv3Var = safeGetLongVariable("sim_clkdiv1_outdiv3");
    final LongVariable sim_clkdiv1_outdiv4Var = getLongVariable("sim_clkdiv1_outdiv4");
    // Core Clock
    // ===========================================
    // Attempt to find acceptable divisor
    final LongVariable system_mcgoutclk_clockVar = getLongVariable("/MCG/system_mcgoutclk_clock");
    long inputFrequency = system_mcgoutclk_clockVar.getValueAsLong();
    final FindDivisor coreDivisor = new FindDivisor(inputFrequency, system_core_clockVar.getValueAsLong()) {

        @Override
        boolean okValue(int divisor, double frequency) {
            return frequency <= MAX_CORE_CLOCK_FREQ;
        }
    };
    Severity severity = Severity.OK;
    StringBuilder sb = new StringBuilder();
    if (variable == system_core_clockVar) {
        // Clock variable changed - replace with nearest value if found
        if (coreDivisor.divisor == 0) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(coreDivisor.divisors);
        system_core_clockVar.setValue(coreDivisor.nearestTargetFrequency);
        system_core_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
    } else {
        // Clock variable not changed - just validate
        if ((coreDivisor.divisor == 0) || (system_core_clockVar.getValueAsLong() != (coreDivisor.nearestTargetFrequency))) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(coreDivisor.divisors);
        system_core_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv1Var.setValue(coreDivisor.divisor);
    }
    // Bus Clock
    // ===========================================
    // Attempt to find acceptable divisor
    final FindDivisor busDivisor = new FindDivisor(inputFrequency, system_bus_clockVar.getValueAsLong()) {

        @Override
        boolean okValue(int divisor, double frequency) {
            return (frequency <= MAX_BUS_CLOCK_FREQ) && // Even multiple
            ((divisor % coreDivisor.divisor) == 0) && // Differ from core < 8
            ((divisor / coreDivisor.divisor) <= 8);
        }
    };
    severity = Severity.OK;
    sb = new StringBuilder();
    if (variable == system_bus_clockVar) {
        // Clock variable changed - replace with nearest value if found
        if (busDivisor.divisor == 0) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(busDivisor.divisors);
        system_bus_clockVar.setValue(busDivisor.nearestTargetFrequency);
        system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv2Var.setValue(busDivisor.divisor);
    } else {
        // Clock variable not changed - just validate
        if ((busDivisor.divisor == 0) || (system_bus_clockVar.getValueAsLong() != (busDivisor.nearestTargetFrequency))) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(busDivisor.divisors);
        system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv2Var.setValue(busDivisor.divisor);
    }
    // ===========================================
    if (sim_clkdiv1_outdiv3Var != null) {
        // Attempt to find acceptable divisor
        final FindDivisor flexDivisor = new FindDivisor(inputFrequency, system_flexbus_clockVar.getValueAsLong()) {

            @Override
            boolean okValue(int divisor, double frequency) {
                return (frequency <= MAX_FLEXBUS_CLOCK_FREQ) && (frequency <= busDivisor.nearestTargetFrequency) && // Even multiple
                ((divisor % coreDivisor.divisor) == 0) && // Differ from core < 8
                ((divisor / coreDivisor.divisor) <= 8);
            }
        };
        severity = Severity.OK;
        sb = new StringBuilder();
        if (variable == system_flexbus_clockVar) {
            // Clock variable changed - replace with nearest value if found
            if (flexDivisor.divisor == 0) {
                severity = Severity.ERROR;
                sb.append("Illegal Frequency\n");
            }
            sb.append(flexDivisor.divisors);
            system_flexbus_clockVar.setValue(flexDivisor.nearestTargetFrequency);
            system_flexbus_clockVar.setStatus(new Status(sb.toString(), severity));
            sim_clkdiv1_outdiv3Var.setValue(flexDivisor.divisor);
        } else {
            // Clock variable not changed - just validate
            if ((flexDivisor.divisor == 0) || (system_flexbus_clockVar.getValueAsLong() != (flexDivisor.nearestTargetFrequency))) {
                severity = Severity.ERROR;
                sb.append("Illegal Frequency\n");
            }
            sb.append(flexDivisor.divisors);
            system_flexbus_clockVar.setStatus(new Status(sb.toString(), severity));
            sim_clkdiv1_outdiv3Var.setValue(flexDivisor.divisor);
        }
    } else if (system_flexbus_clockVar != null) {
        system_flexbus_clockVar.enable(false);
        system_flexbus_clockVar.setStatus(new Status("Function not available on this device", Severity.OK));
    }
    // if (system_mcgoutclk_clockVar.getValueAsLong() == 12000000) {
    // System.err.println("system_mcgoutclk_clockVar[" +fIndex+"] = " + system_mcgoutclk_clockVar);
    // }
    // Flash Clock
    // ===========================================
    final FindDivisor flashDivisor = new FindDivisor(inputFrequency, system_flash_clockVar.getValueAsLong()) {

        @Override
        boolean okValue(int divisor, double frequency) {
            return (frequency <= MAX_FLASH_CLOCK_FREQ) && (frequency <= busDivisor.nearestTargetFrequency) && // Even multiple
            ((divisor % coreDivisor.divisor) == 0) && // Differ from core < 8
            ((divisor / coreDivisor.divisor) <= 8);
        }
    };
    severity = Severity.OK;
    sb = new StringBuilder();
    if (variable == system_flash_clockVar) {
        if (flashDivisor.divisor == 0) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(flashDivisor.divisors);
        system_flash_clockVar.setValue(flashDivisor.nearestTargetFrequency);
        system_flash_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
    } else {
        // Clock variable not changed - just validate
        if ((flashDivisor.divisor == 0) || (system_flash_clockVar.getValueAsLong() != (flashDivisor.nearestTargetFrequency))) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(flashDivisor.divisors);
        system_flash_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
    }
}
Also used : Status(net.sourceforge.usbdm.deviceEditor.model.Status) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) 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) Severity(net.sourceforge.usbdm.deviceEditor.model.Status.Severity) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)

Aggregations

ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)19 LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)17 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)13 Variable (net.sourceforge.usbdm.deviceEditor.information.Variable)11 Status (net.sourceforge.usbdm.deviceEditor.model.Status)7 DoubleVariable (net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)5 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)5 PinListVariable (net.sourceforge.usbdm.deviceEditor.information.PinListVariable)2 Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)2 Severity (net.sourceforge.usbdm.deviceEditor.model.Status.Severity)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 BitmaskVariable (net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable)1 IndexedCategoryVariable (net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable)1 IrqVariable (net.sourceforge.usbdm.deviceEditor.information.IrqVariable)1 MappingInfo (net.sourceforge.usbdm.deviceEditor.information.MappingInfo)1 NumericListVariable (net.sourceforge.usbdm.deviceEditor.information.NumericListVariable)1 InfoTable (net.sourceforge.usbdm.deviceEditor.information.Peripheral.InfoTable)1 Pin (net.sourceforge.usbdm.deviceEditor.information.Pin)1 Pair (net.sourceforge.usbdm.deviceEditor.information.Variable.Pair)1