Search in sources :

Example 16 with LongVariable

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

the class AdcValidate method validate.

/**
 * Class to determine LPTMR settings
 * @throws Exception
 */
@Override
public void validate(Variable variable) throws Exception {
    super.validate(variable);
    // Clock Mapping
    // =================
    final StringVariable osc0_peripheralVar = getStringVariable("/SIM/osc0_peripheral");
    final LongVariable osc0_oscer_clockVar = getLongVariable(osc0_peripheralVar.getValueAsString() + "/oscer_clock");
    // Variables
    // =================================
    DoubleVariable clockFrequencyVar = (DoubleVariable) getVariable("clockFrequency");
    Variable adc_cfg1_adiclkVar = getVariable("adc_cfg1_adiclk");
    Variable adc_cfg1_adivVar = getVariable("adc_cfg1_adiv");
    Variable adcInternalClockVar = getVariable("adcInternalClock");
    Variable system_bus_clockVar = getVariable("/SIM/system_bus_clock");
    Variable adc_cfg1_adlpcVar = getVariable("adc_cfg1_adlpc");
    Variable adc_cfg2_adhscVar = getVariable("adc_cfg2_adhsc");
    Variable adc_cfg1_modeVar = getVariable("adc_cfg1_mode");
    BooleanVariable adc_cfg1_adlsmpVar = getBooleanVariable("adc_cfg1_adlsmp");
    ChoiceVariable adc_cfg2_adlstsVar = getChoiceVariable("adc_cfg2_adlsts");
    LongVariable low_comparison_valueVar = getLongVariable("low_comparison_value");
    LongVariable high_comparison_valueVar = getLongVariable("high_comparison_value");
    LongVariable adc_cv1Var = getLongVariable("adc_cv1");
    LongVariable adc_cv2Var = getLongVariable("adc_cv2");
    ChoiceVariable adc_sc2_compareVar = getChoiceVariable("adc_sc2_compare");
    LongVariable adc_sc2_acfeVar = getLongVariable("adc_sc2_acfe");
    LongVariable adc_sc2_acfgtVar = getLongVariable("adc_sc2_acfgt");
    LongVariable adc_sc2_acrenVar = getLongVariable("adc_sc2_acren");
    int cv1 = 0;
    int cv2 = 0;
    int low = (int) low_comparison_valueVar.getValueAsLong();
    int high = (int) high_comparison_valueVar.getValueAsLong();
    int compareChoice = (int) adc_sc2_compareVar.getValueAsLong();
    boolean adc_sc2_acfe = true;
    boolean adc_sc2_acfgt = false;
    boolean adc_sc2_acren = false;
    switch(compareChoice) {
        case // Disabled
        0:
            adc_sc2_acfe = false;
            break;
        case // ADC < low(CV1)
        1:
            cv1 = low;
            adc_sc2_acfgt = false;
            adc_sc2_acren = false;
            break;
        case // ADC >= low(CV1)
        2:
            cv1 = low;
            adc_sc2_acfgt = true;
            adc_sc2_acren = false;
            break;
        case // (ADC<low(CV1)) or (high(CV2)<ADC)      CV1<CV2
        3:
            cv1 = low;
            cv2 = high;
            adc_sc2_acfgt = false;
            adc_sc2_acren = true;
            break;
        case // (low(CV2)<ADC<high(CV1))             CV1>CV2 <==> CV2<CV1
        4:
            cv2 = low;
            cv1 = high;
            adc_sc2_acfgt = false;
            adc_sc2_acren = true;
            break;
        case // (low(CV1)<=ADC<=high(CV2)            CV1<CV2
        5:
            cv1 = low;
            cv2 = high;
            adc_sc2_acfgt = true;
            adc_sc2_acren = true;
            break;
        case // (ADC<=low(CV2)) or (high(CV1<=ADC))    CV1>CV2 <==> CV2<CV1
        6:
            cv2 = low;
            cv1 = high;
            adc_sc2_acfgt = true;
            adc_sc2_acren = true;
            break;
    }
    adc_cv1Var.enable(compareChoice >= 1);
    adc_cv2Var.enable(compareChoice >= 3);
    low_comparison_valueVar.enable(compareChoice >= 1);
    high_comparison_valueVar.enable(compareChoice >= 3);
    adc_cv1Var.setValue(cv1);
    adc_cv2Var.setValue(cv2);
    adc_sc2_acfeVar.setValue(adc_sc2_acfe);
    adc_cfg2_adlstsVar.enable(adc_cfg1_adlsmpVar.getValueAsBoolean());
    adc_sc2_acfeVar.setValue(adc_sc2_acfe);
    adc_sc2_acfgtVar.setValue(adc_sc2_acfgt);
    adc_sc2_acrenVar.setValue(adc_sc2_acren);
    // Varies with power settings etc
    adcInternalClockVar.setValue(ADC_CLOCK_VALUES[(int) (2 * adc_cfg1_adlpcVar.getValueAsLong() + adc_cfg2_adhscVar.getValueAsLong())]);
    LongVariable system_irc48m_clockVar = safeGetLongVariable("/MCG/system_irc48m_clock");
    Variable clockSourceVar = null;
    double clockFrequency;
    switch((int) adc_cfg1_adiclkVar.getValueAsLong()) {
        case 0:
            clockSourceVar = system_bus_clockVar;
            clockFrequency = system_bus_clockVar.getValueAsLong();
            break;
        case 1:
            /* 
          * TODO - better method of clock selection
          * ALTCLK2: Varies with device but assume irc48m if available else busClock/2
          */
            if (system_irc48m_clockVar != null) {
                clockSourceVar = system_irc48m_clockVar;
                clockFrequency = system_irc48m_clockVar.getValueAsLong();
            } else {
                clockSourceVar = system_bus_clockVar;
                clockFrequency = system_bus_clockVar.getValueAsLong() / 2.0;
            }
            break;
        case 2:
            clockSourceVar = osc0_oscer_clockVar;
            clockFrequency = osc0_oscer_clockVar.getValueAsLong();
            break;
        default:
            adc_cfg1_adiclkVar.setValue(1);
        case 3:
            clockSourceVar = adcInternalClockVar;
            clockFrequency = adcInternalClockVar.getValueAsLong();
            break;
    }
    // Set MIN and MAX before updating value
    if (adc_cfg1_modeVar.getValueAsLong() >= 2) {
        clockFrequencyVar.setMin(FADC_HIGH_RES_MIN);
        clockFrequencyVar.setMax(FADC_HIGH_RES_MAX);
    } else {
        clockFrequencyVar.setMin(FADC_LOW_RES_MIN);
        clockFrequencyVar.setMax(FADC_LOW_RES_MAX);
    }
    clockFrequency = clockFrequency / (1L << adc_cfg1_adivVar.getValueAsLong());
    clockFrequencyVar.setValue(clockFrequency);
    clockFrequencyVar.setStatus(clockSourceVar.getFilteredStatus());
    clockFrequencyVar.setOrigin(clockSourceVar.getOrigin() + " divided by adc_cfg1_adiv");
}
Also used : BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) 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) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)

Example 17 with LongVariable

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

the class SimValidate_fll method validateNonindexedVariables.

/**
 * Updates
 *  - srcVar
 *  - clockVar
 *  - system_erclk32k_clockVar
 *  - sim_sopt1_osc32kselVar
 *  - sim_sopt2_rtcclkoutselVar
 *  - rtc_clkoutVar
 *  - system_usbfs_clockVar
 *
 * @param variable
 * @throws Exception
 */
public void validateNonindexedVariables(Variable variable) throws Exception {
    super.validate(variable);
    // Clock Mapping
    // =================
    final String osc32kClk_peripheral = getStringVariable("osc32k_peripheral").getValueAsString();
    final LongVariable osc32kClk_osc_clockVar = getLongVariable(osc32kClk_peripheral + "/osc_clock");
    final String oscClk_peripheral = getStringVariable("osc0_peripheral").getValueAsString();
    final LongVariable oscClk_osc_clockVar = getLongVariable(oscClk_peripheral + "/osc_clock");
    final String rtc_clkin = getStringVariable("rtc_clkin").getValueAsString();
    final LongVariable rtcclkin_clockVar = safeGetLongVariable(rtc_clkin);
    final LongVariable rtc_1hz_clockVar = safeGetLongVariable(osc32kClk_peripheral + "/rtc_1hz_clock");
    // MCG
    // =================
    final LongVariable system_low_power_clockVar = getLongVariable("/MCG/system_low_power_clock");
    final LongVariable system_mcgirclk_clockVar = getLongVariable("/MCG/system_mcgirclk_clock");
    final LongVariable system_usb_clkin_clockVar = safeGetLongVariable("/MCG/system_usb_clkin_clock");
    LongVariable clockVar = safeGetLongVariable("system_peripheral_clock");
    if (clockVar == null) {
        // Assume no PLL. Peripheral clock is FLL
        clockVar = getLongVariable("/MCG/system_mcgfllclk_clock");
    }
    final LongVariable peripheralClockVar = clockVar;
    // RTC
    // =================
    final LongVariable rtc_clkoutVar = safeGetLongVariable("rtc_clkout");
    /**
     * Clock selector used for LPUARTs, TPMs and FlexIO
     */
    LpClockSelector clockSelector = new LpClockSelector() {

        @Override
        public void lpClockSelect(String sourceVar, String clockVarId) throws Exception {
            // Clock source select (if present)
            // ===================================
            Variable srcVar = safeGetVariable(sourceVar);
            if (srcVar != null) {
                Variable clockVar = getVariable(clockVarId);
                switch((int) srcVar.getValueAsLong()) {
                    default:
                        srcVar.setValue(0);
                    case // Disabled
                    0:
                        clockVar.setValue(0);
                        clockVar.setStatus((Status) null);
                        clockVar.setOrigin("Disabled");
                        break;
                    case // MCGFLLCLK
                    1:
                        clockVar.setValue(peripheralClockVar.getValueAsLong());
                        clockVar.setStatus(peripheralClockVar.getStatus());
                        clockVar.setOrigin(peripheralClockVar.getOrigin());
                        break;
                    case // OSCERCLK
                    2:
                        clockVar.setValue(oscClk_osc_clockVar.getValueAsLong());
                        clockVar.setStatus(oscClk_osc_clockVar.getStatus());
                        clockVar.setOrigin(oscClk_osc_clockVar.getOrigin());
                        break;
                    case // MCGIRCLK
                    3:
                        clockVar.setValue(system_mcgirclk_clockVar.getValueAsLong());
                        clockVar.setStatus(system_mcgirclk_clockVar.getStatus());
                        clockVar.setOrigin(system_mcgirclk_clockVar.getOrigin());
                        break;
                }
            }
        }
    };
    // Determine ERCLK32K
    // ==================================
    LongVariable system_erclk32k_clockVar = getLongVariable("system_erclk32k_clock");
    ChoiceVariable sim_sopt1_osc32kselVar = getChoiceVariable("sim_sopt1_osc32ksel");
    switch((int) sim_sopt1_osc32kselVar.getValueAsLong()) {
        case // System oscillator (OSC32KCLK)
        0:
            system_erclk32k_clockVar.setValue(osc32kClk_osc_clockVar.getValueAsLong());
            system_erclk32k_clockVar.setOrigin(osc32kClk_osc_clockVar.getOrigin());
            system_erclk32k_clockVar.setStatus(osc32kClk_osc_clockVar.getStatus());
            break;
        default:
            sim_sopt1_osc32kselVar.setValue(2);
        case // RTC CLK_IN
        2:
            system_erclk32k_clockVar.setValue(rtcclkin_clockVar.getValueAsLong());
            system_erclk32k_clockVar.setOrigin(rtcclkin_clockVar.getOrigin());
            system_erclk32k_clockVar.setStatus(rtcclkin_clockVar.getStatus());
            break;
        case // LPO 1 kHz
        3:
            system_erclk32k_clockVar.setValue(system_low_power_clockVar.getValueAsLong());
            system_erclk32k_clockVar.setOrigin(system_low_power_clockVar.getOrigin());
            system_erclk32k_clockVar.setStatus(system_low_power_clockVar.getStatus());
            break;
    }
    // RTC Clock out pin select
    // ============================
    BooleanVariable sim_sopt2_rtcclkoutselVar = safeGetBooleanVariable("sim_sopt2_rtcclkoutsel");
    if (sim_sopt2_rtcclkoutselVar != null) {
        switch((int) sim_sopt2_rtcclkoutselVar.getValueAsLong()) {
            default:
                sim_sopt2_rtcclkoutselVar.setValue(0);
            case // RTC seconds clock = 1Hz
            0:
                rtc_clkoutVar.setValue(rtc_1hz_clockVar.getValueAsLong());
                rtc_clkoutVar.setStatus(rtc_1hz_clockVar.getStatus());
                rtc_clkoutVar.setOrigin(rtc_1hz_clockVar.getOrigin());
                break;
            case // OSCERCLK
            1:
                rtc_clkoutVar.setValue(oscClk_osc_clockVar.getValueAsLong());
                rtc_clkoutVar.setStatus(oscClk_osc_clockVar.getStatus());
                rtc_clkoutVar.setOrigin(oscClk_osc_clockVar.getOrigin());
                break;
        }
    }
    // UART0 Clock source select (if present)
    // ==========================================
    clockSelector.lpClockSelect("sim_sopt2_uart0src", "system_uart0_clock");
    // LPUARTx Clock source select (if present)
    // ==========================================
    final String[] lpUartInstances = { "", "0", "1", "2" };
    for (String lpUartInstance : lpUartInstances) {
        clockSelector.lpClockSelect("sim_sopt2_lpuart" + lpUartInstance + "src", "system_lpuart" + lpUartInstance + "_clock");
    }
    // TPMx Clock source select (if present)
    // ==========================================
    final String[] tpmInstances = { "", "0", "1", "2" };
    for (String tpmInstance : tpmInstances) {
        clockSelector.lpClockSelect("sim_sopt2_tpm" + tpmInstance + "src", "system_tpm" + tpmInstance + "_clock");
    }
    // FLEXIO Clock source select (if present)
    // ==========================================
    clockSelector.lpClockSelect("sim_sopt2_flexiosrc", "system_flexio_clock");
    // USB FS Clock source select
    // ============================
    ChoiceVariable sim_sopt2_usbsrcVar = safeGetChoiceVariable("sim_sopt2_usbsrc");
    if (sim_sopt2_usbsrcVar != null) {
        ChoiceVariable sim_clkdiv2_usbVar = safeGetChoiceVariable("sim_clkdiv2_usb");
        if (sim_clkdiv2_usbVar != null) {
            // USB divider CLKDIV2 exists
            int usbCalcValue = -1;
            if (sim_sopt2_usbsrcVar.getValueAsLong() == 0) {
                // Using USB CLKIN pin
                sim_clkdiv2_usbVar.enable(false);
                sim_clkdiv2_usbVar.setOrigin("Not used with external clock");
                sim_clkdiv2_usbVar.setLocked(false);
            } else {
                // Using internal clock
                // Try to auto calculate divisor
                long clock = peripheralClockVar.getValueAsLong();
                for (int usbdiv = 0; usbdiv <= 7; usbdiv++) {
                    for (int usbfrac = 0; usbfrac <= 1; usbfrac++) {
                        long testValue = Math.round(clock * (usbfrac + 1.0) / (usbdiv + 1.0));
                        if (testValue == 48000000) {
                            usbCalcValue = (usbdiv << 1) + usbfrac;
                            break;
                        }
                    }
                    if (usbCalcValue >= 0) {
                        break;
                    }
                }
                sim_clkdiv2_usbVar.enable(true);
                if (usbCalcValue >= 0) {
                    sim_clkdiv2_usbVar.setRawValue(usbCalcValue);
                    sim_clkdiv2_usbVar.setOrigin("Automatically calculated from input clock");
                    sim_clkdiv2_usbVar.setLocked(true);
                } else {
                    sim_clkdiv2_usbVar.setOrigin("Manually selected");
                    sim_clkdiv2_usbVar.setLocked(false);
                }
            }
        }
        LongVariable system_usbfs_clockVar = getLongVariable("system_usbfs_clock");
        if (sim_sopt2_usbsrcVar.getValueAsLong() == 0) {
            // Using USB_CLKIN
            system_usbfs_clockVar.setValue(system_usb_clkin_clockVar.getValueAsLong());
            system_usbfs_clockVar.setStatus(system_usb_clkin_clockVar.getStatus());
            system_usbfs_clockVar.setOrigin(system_usb_clkin_clockVar.getOrigin());
        } else {
            // Using internal clock
            if (sim_clkdiv2_usbVar != null) {
                // Peripheral Clock / CLKDIV2
                int usbValue = Long.decode(sim_clkdiv2_usbVar.getSubstitutionValue()).intValue();
                int usbfrac = usbValue & 0x1;
                int usbdiv = (usbValue >> 1) & 0x7;
                long usbPostDiv2 = peripheralClockVar.getValueAsLong() * (usbfrac + 1) / (usbdiv + 1);
                system_usbfs_clockVar.setValue(usbPostDiv2);
                system_usbfs_clockVar.setStatus(peripheralClockVar.getStatus());
                system_usbfs_clockVar.setOrigin(peripheralClockVar.getOrigin() + " after /CLKDIV2");
            } else {
                // Directly using peripheral clock
                system_usbfs_clockVar.setValue(peripheralClockVar.getValueAsLong());
                system_usbfs_clockVar.setStatus(peripheralClockVar.getStatus());
                system_usbfs_clockVar.setOrigin(peripheralClockVar.getOrigin());
            }
        }
    }
}
Also used : 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) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)

Example 18 with LongVariable

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

the class UartValidate method validate.

/**
 * Class to validate UART settings
 * @throws Exception
 */
@Override
public void validate(Variable variable) throws Exception {
    super.validate(variable);
    // Variables
    // =================================
    BooleanVariable uartClassVar = getBooleanVariable("uartClass");
    LongVariable receiveBufferSizeVar = getLongVariable("receiveBufferSize");
    LongVariable transmitBufferSizeVar = getLongVariable("transmitBufferSize");
    IrqVariable txrxHandlerVar = getIrqVariable("irqHandlers");
    // Enable/disable parameters that depend on mode
    boolean uartClass = uartClassVar.getValueAsBoolean();
    if (variable == uartClassVar) {
        // System.err.println("uartClassVar = "+uartClassVar.getValueAsBoolean());
        // Changed buffering
        receiveBufferSizeVar.enable(uartClass);
        transmitBufferSizeVar.enable(uartClass);
        txrxHandlerVar.setLocked(uartClass);
        if (uartClass) {
            txrxHandlerVar.setValue(IrqVariable.CLASS_VALUE);
        }
    }
    // Warn if Rx and Tx signals not mapped
    validateMappedPins(new int[] { 0, 1 }, getPeripheral().getSignalTables().get(0).table);
}
Also used : LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) IrqVariable(net.sourceforge.usbdm.deviceEditor.information.IrqVariable)

Example 19 with LongVariable

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

the class ParseMenuXML method parseLongOption.

/**
 * Parse &lt;longOption&gt; element<br>
 *
 * @param varElement
 * @throws Exception
 */
private void parseLongOption(BaseModel parent, Element varElement) throws Exception {
    LongVariable variable = (LongVariable) parseCommonAttributes(parent, varElement, LongVariable.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")));
    variable.setStep(getLongAttribute(varElement, "step"));
    variable.setOffset(getLongAttribute(varElement, "offset"));
}
Also used : LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) FileNotFoundException(java.io.FileNotFoundException)

Example 20 with LongVariable

use of net.sourceforge.usbdm.deviceEditor.information.LongVariable 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)

Aggregations

LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)28 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)16 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)15 Variable (net.sourceforge.usbdm.deviceEditor.information.Variable)12 DoubleVariable (net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)10 Status (net.sourceforge.usbdm.deviceEditor.model.Status)10 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)4 Severity (net.sourceforge.usbdm.deviceEditor.model.Status.Severity)4 IrqVariable (net.sourceforge.usbdm.deviceEditor.information.IrqVariable)2 FileNotFoundException (java.io.FileNotFoundException)1 PinListVariable (net.sourceforge.usbdm.deviceEditor.information.PinListVariable)1 Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)1 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1