Search in sources :

Example 1 with BooleanVariable

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

the class SimValidateMKL_lite 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 osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
    final LongVariable osc0_oscer_clockVar = getLongVariable(osc0_peripheral + "/oscer_clock");
    final LongVariable osc0_osc32k_clockVar = getLongVariable(osc0_peripheral + "/osc32k_clock");
    final String rtcclkin_clock = getStringVariable("/SIM/rtc_clkin").getValueAsString();
    final LongVariable rtcclkin_clockVar = safeGetLongVariable(rtcclkin_clock);
    final LongVariable rtc_1hz_clockVar = safeGetLongVariable("/RTC/rtc_1hz_clock");
    final LongVariable rtc_clkoutVar = safeGetLongVariable("rtc_clkout");
    // MCG
    // =================
    final LongVariable system_low_power_clockVar = getLongVariable("/MCG/system_low_power_clock");
    final LongVariable system_mcgpclk_clockVar = getLongVariable("/MCG/system_mcgpclk_clock");
    final LongVariable system_mcgirclk_clockVar = getLongVariable("/MCG/system_mcgirclk_clock");
    final LongVariable system_usb_clkin_clockVar = safeGetLongVariable("/MCG/system_usb_clkin_clock");
    // Check if CLKDIV3 Present
    // =====================================
    final Long pllPostDiv3Value;
    final String pllPostDiv3Origin;
    final Variable system_peripheral_postdivider_clockVar = safeGetVariable("system_peripheral_postdivider_clock");
    if (system_peripheral_postdivider_clockVar != null) {
        // After divider
        pllPostDiv3Value = system_peripheral_postdivider_clockVar.getValueAsLong();
        pllPostDiv3Origin = system_peripheral_postdivider_clockVar.getOrigin();
    } else {
        // Direct (no divider)
        pllPostDiv3Value = system_mcgpclk_clockVar.getValueAsLong();
        pllPostDiv3Origin = system_mcgpclk_clockVar.getOrigin();
    }
    /**
     * 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 // Peripheral Clock / CLKDIV3
                    1:
                        clockVar.setValue(pllPostDiv3Value);
                        clockVar.setStatus(system_mcgpclk_clockVar.getStatus());
                        clockVar.setOrigin(pllPostDiv3Origin);
                        break;
                    case // OSCERCLK
                    2:
                        clockVar.setValue(osc0_oscer_clockVar.getValueAsLong());
                        clockVar.setStatus(osc0_oscer_clockVar.getStatus());
                        clockVar.setOrigin(osc0_oscer_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(osc0_osc32k_clockVar.getValueAsLong());
            system_erclk32k_clockVar.setOrigin(osc0_osc32k_clockVar.getOrigin());
            system_erclk32k_clockVar.setStatus(osc0_osc32k_clockVar.getStatus());
            break;
        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;
        default:
            sim_sopt1_osc32kselVar.setValue(3);
        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(osc0_oscer_clockVar.getValueAsLong());
                rtc_clkoutVar.setStatus(osc0_oscer_clockVar.getStatus());
                rtc_clkoutVar.setOrigin(osc0_oscer_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) {
        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 {
            // MCGPCLK
            system_usbfs_clockVar.setValue(system_mcgpclk_clockVar.getValueAsLong());
            system_usbfs_clockVar.setStatus(system_mcgpclk_clockVar.getStatus());
            system_usbfs_clockVar.setOrigin(system_mcgpclk_clockVar.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 2 with BooleanVariable

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

the class TpmValidate method validate.

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

Example 3 with BooleanVariable

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

the class OscValidate method validate.

/**
 * Class to determine oscillator settings
 * @throws Exception
 */
@Override
public void validate(Variable variable) throws Exception {
    super.validate(variable);
    // OSC
    // =================================
    BooleanVariable osc_cr_erclkenVar = getBooleanVariable("osc_cr_erclken");
    BooleanVariable mcg_c2_erefs0Var = getBooleanVariable("/MCG/mcg_c2_erefs0");
    BooleanVariable mcg_c2_hgo0Var = getBooleanVariable("/MCG/mcg_c2_hgo0");
    ChoiceVariable osc_cr_scpVar = getChoiceVariable("osc_cr_scp");
    Variable osc_cr_erefstenVar = getVariable("osc_cr_erefsten");
    Variable oscillatorRangeVar = getVariable("oscillatorRange");
    LongVariable system_oscer_undiv_clockVar = safeGetLongVariable("oscer_undiv_clock");
    LongVariable system_oscer_clockVar = null;
    if (system_oscer_undiv_clockVar == null) {
        system_oscer_undiv_clockVar = getLongVariable("oscer_clock");
    } else {
        system_oscer_clockVar = getLongVariable("oscer_clock");
    }
    ChoiceVariable osc_div_erpsVar = safeGetChoiceVariable("osc_div_erps");
    LongVariable osc32k_clockVar = getLongVariable("osc32k_clock");
    LongVariable osc_clockVar = getLongVariable("osc_clock");
    LongVariable osc_input_freqVar = getLongVariable("osc_input_freq");
    // Check if RTC has control of oscillator pins
    boolean rtcForcing = getVariable("/SIM/rtcSharesPins").getValueAsBoolean() && getBooleanVariable("/RTC/rtc_cr_osce").getValueAsBoolean();
    String rangeOrigin = "Unused";
    int range = UNCONSTRAINED_RANGE;
    if (rtcForcing) {
        // RTC controlling XTAL pins
        Status rtcInUseMessage = new Status("Feature is controlled by RTC which shares XTAL/EXTAL pins", Severity.WARNING);
        oscillatorRangeVar.enable(false);
        oscillatorRangeVar.setStatus(rtcInUseMessage);
        osc_cr_erclkenVar.enable(false);
        osc_cr_erclkenVar.setStatus(rtcInUseMessage);
        osc_cr_erefstenVar.enable(false);
        osc_cr_erefstenVar.setStatus(rtcInUseMessage);
        osc_cr_scpVar.enable(false);
        osc_cr_scpVar.setStatus(rtcInUseMessage);
        mcg_c2_erefs0Var.enable(false);
        mcg_c2_erefs0Var.setStatus(rtcInUseMessage);
        mcg_c2_hgo0Var.enable(false);
        mcg_c2_hgo0Var.setStatus(rtcInUseMessage);
        rangeOrigin = "Determined by RTC";
        range = 0;
    } else {
        // OSC controlling XTAL pins
        oscillatorRangeVar.enable(true);
        oscillatorRangeVar.clearStatus();
        osc_cr_erclkenVar.enable(true);
        osc_cr_erclkenVar.clearStatus();
        osc_cr_erefstenVar.enable(osc_cr_erclkenVar.getValueAsBoolean());
        osc_cr_erefstenVar.clearStatus();
        mcg_c2_erefs0Var.enable(true);
        mcg_c2_erefs0Var.clearStatus();
        osc_input_freqVar.clearStatus();
        String oscclk_clockOrg;
        Status oscclk_clockStatus = null;
        boolean oscillatorInUse = mcg_c2_erefs0Var.getValueAsBoolean();
        long osc_input_freq = osc_input_freqVar.getValueAsLong();
        if (oscillatorInUse) {
            // Using oscillator - range is chosen to suit crystal frequency (or forced by RTC)
            if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE1_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE1_MAX)) {
                oscclk_clockOrg = "OSCCLK (low range oscillator)";
                rangeOrigin = "Determined by Crystal Frequency";
                range = 0;
            } else if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE2_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE2_MAX)) {
                oscclk_clockOrg = "OSCCLK (high range oscillator)";
                rangeOrigin = "Determined by Crystal Frequency";
                range = 1;
            } else if ((osc_input_freq >= EXTERNAL_EXTAL_RANGE3_MIN) && (osc_input_freq <= EXTERNAL_EXTAL_RANGE3_MAX)) {
                oscclk_clockOrg = "OSCCLK (very high range oscillator)";
                rangeOrigin = "Determined by Crystal Frequency";
                range = 2;
            } else {
                // Not suitable as OSC Crystal frequency
                oscclk_clockOrg = "OSCCLK (invalid range)";
                oscclk_clockStatus = FLL_CLOCK_ERROR_MSG;
                range = UNCONSTRAINED_RANGE;
            }
        } else {
            // Using external clock
            oscclk_clockOrg = "OSCCLK (External clock)";
            // Range has no effect on Oscillator
            range = UNCONSTRAINED_RANGE;
            // Check suitable clock range
            if (osc_input_freq > EXTERNAL_CLOCK_MAX) {
                // Not suitable as external clock
                oscclk_clockStatus = CLOCK_RANGE_ERROR_MSG;
            }
        }
        osc_cr_scpVar.enable(oscillatorInUse);
        osc_cr_scpVar.clearStatus();
        mcg_c2_hgo0Var.enable(oscillatorInUse);
        mcg_c2_hgo0Var.clearStatus();
        boolean oscclkOK = (oscclk_clockStatus == null) || oscclk_clockStatus.getSeverity().lessThan(Severity.WARNING);
        osc_clockVar.setOrigin(oscclk_clockOrg);
        osc_clockVar.setStatus(oscclk_clockStatus);
        osc_clockVar.setValue(oscclkOK ? osc_input_freq : 0);
        osc_clockVar.enable(oscclkOK);
    }
    oscillatorRangeVar.setValue(range);
    oscillatorRangeVar.setOrigin(rangeOrigin);
    // Check suitability of OSC for OSC32KCLK
    // =========================================
    // Initially assume suitable
    long osc32kclk_clockFreq = osc_clockVar.getValueAsLong();
    Status osc32kclk_clockStatus = osc_clockVar.getStatus();
    String osc32kclk_clockOrg = osc_clockVar.getOrigin();
    if ((osc32kclk_clockFreq < EXTERNAL_EXTAL_RANGE1_MIN) || (osc32kclk_clockFreq > EXTERNAL_EXTAL_RANGE1_MAX)) {
        if ((osc32kclk_clockStatus == null) || osc32kclk_clockStatus.lessThan(Severity.ERROR)) {
            osc32kclk_clockStatus = new Status(OSCCLK32K_CLOCK_MSG, Severity.WARNING);
        }
        osc32kclk_clockOrg = osc32kclk_clockOrg + "(invalid range)";
    }
    osc32k_clockVar.setValue((osc32kclk_clockStatus != null) ? 0 : osc32kclk_clockFreq);
    osc32k_clockVar.setStatus(osc32kclk_clockStatus);
    osc32k_clockVar.setOrigin(osc32kclk_clockOrg);
    // Determine OSCERCLK, OSCERCLK_UNDIV
    // ==================================
    long osc_clockFreq = osc_clockVar.getValueAsLong();
    String osc_clockOrg = osc_clockVar.getOrigin();
    if (osc_cr_erclkenVar.getValueAsBoolean()) {
        // Oscillator/clock enabled
        system_oscer_undiv_clockVar.setValue(osc_clockFreq);
        system_oscer_undiv_clockVar.setStatus(osc_clockVar.getFilteredStatus());
        system_oscer_undiv_clockVar.setOrigin(osc_clockVar.getOrigin());
        system_oscer_undiv_clockVar.enable(true);
        long system_oscerclk = osc_clockFreq;
        if (osc_div_erpsVar != null) {
            // If divider exists
            system_oscerclk /= 1 << osc_div_erpsVar.getValueAsLong();
            osc_clockOrg += "/osc_div_erps";
            system_oscer_clockVar.setValue(system_oscerclk);
            system_oscer_clockVar.setStatus(osc_clockVar.getFilteredStatus());
            system_oscer_clockVar.setOrigin(osc_clockVar.getOrigin());
            system_oscer_clockVar.enable(true);
            osc_div_erpsVar.enable(true);
        }
    } else {
        Status osc_crMessage = new Status("Disabled by osc_cr_erclken", Severity.OK);
        // Oscillator/clock disabled
        // system_oscerclk_undiv_clockVar.setValue(0);
        system_oscer_undiv_clockVar.setStatus(osc_crMessage);
        system_oscer_undiv_clockVar.setOrigin(osc_clockOrg);
        system_oscer_undiv_clockVar.enable(false);
        if (osc_div_erpsVar != null) {
            // system_oscer_clockVar.setValue(0);
            system_oscer_clockVar.setStatus(osc_crMessage);
            system_oscer_clockVar.setOrigin(osc_clockOrg);
            system_oscer_clockVar.enable(false);
            osc_div_erpsVar.enable(false);
        }
    }
    // Warn if EXTAL and XTAL signals not mapped
    validateMappedPins(new int[] { 0, 1 }, getPeripheral().getSignalTables().get(0).table);
}
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) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)

Example 4 with BooleanVariable

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

the class RtcValidate method validate.

/**
 * Class to determine RTC oscillator settings
 *
 * Outputs rtcclk_clock, rtcclk_gated_clock,
 * @throws Exception
 */
@Override
public void validate(Variable variable) throws Exception {
    // Indicates RTC uses main oscillator XTAL/EXTAL pins
    Variable rtcSharesPinsVar = safeGetVariable("/SIM/rtcSharesPins");
    boolean rtcSharesPins = (safeGetVariable("/SIM/rtcSharesPins") != null) && rtcSharesPinsVar.getValueAsBoolean();
    super.validate(variable);
    // RTC
    // =================================
    BooleanVariable rtc_cr_osceVar = getBooleanVariable("rtc_cr_osce");
    ChoiceVariable rtc_cr_scpVar = getChoiceVariable("rtc_cr_scp");
    Variable rtc_cr_umVar = getVariable("rtc_cr_um");
    Variable rtc_cr_supVar = getVariable("rtc_cr_sup");
    Variable rtc_cr_wpeVar = getVariable("rtc_cr_wpe");
    LongVariable rtc_1hz_clockVar = getLongVariable("rtc_1hz_clock");
    long osc_input_freq = 0;
    LongVariable osc_input_freqVar = null;
    LongVariable osc_clockVar = null;
    Status status = null;
    String origin = "RTCCLK";
    if (rtcSharesPins) {
        // RTC uses main oscillator XTAL/EXTAL pins
        // ===================================================
        String osc0_peripheral = getStringVariable("/SIM/osc0_peripheral").getValueAsString();
        osc_input_freqVar = getLongVariable(osc0_peripheral + "/osc_input_freq");
        osc_clockVar = getLongVariable(osc0_peripheral + "/osc_clock");
        origin = "RTCCLK";
        rtc_cr_osceVar.setToolTip("Enable main oscillator as 32kHz RTC oscillator\n" + "Note: this disables OSC control by MCG");
    } else {
        // RTC uses separate XTAL32/EXTAL32 pins
        // ===================================================
        osc_input_freqVar = getLongVariable("osc_input_freq");
        osc_clockVar = getLongVariable("osc_clock");
        origin = "RTCCLK";
        rtc_cr_osceVar.setToolTip("Enable 32kHz RTC oscillator");
        // Warn if SCL and SDA signals not mapped
        validateMappedPins(new int[] { 0, 1 }, getPeripheral().getSignalTables().get(0).table);
    }
    osc_input_freq = osc_input_freqVar.getValueAsLong();
    // =========================================
    // Check input clock/oscillator ranges
    // 
    long rtcClockFrequency = osc_input_freq;
    if ((osc_input_freq < RtcValidate.EXTERNAL_EXTAL_RANGE_MIN) || (osc_input_freq > RtcValidate.EXTERNAL_EXTAL_RANGE_MAX)) {
        status = OSCCLK32K_CLOCK_WARNING_MSG;
        origin = origin + " (invalid range)";
        rtcClockFrequency = 0L;
        rtc_cr_osceVar.setValue(false);
        rtc_cr_osceVar.setStatus(status);
        if (!rtcSharesPins) {
            osc_input_freqVar.setStatus(status);
        }
    } else {
        rtc_cr_osceVar.setStatus((Status) null);
        if (!rtcSharesPins) {
            osc_input_freqVar.setStatus((Status) null);
        }
        if (!rtc_cr_osceVar.getValueAsBoolean()) {
            status = new Status("Disabled by rtc_cr_osce", Severity.WARNING);
            origin = origin + " (disabled)";
            rtcClockFrequency = 0L;
        }
    }
    // =========================================
    // Check and propagate enabled
    // 
    boolean rtc_cr_osce = rtc_cr_osceVar.isEnabled() && rtc_cr_osceVar.getValueAsBoolean();
    rtc_cr_scpVar.enable(rtc_cr_osce);
    rtc_cr_umVar.enable(rtc_cr_osce);
    rtc_cr_supVar.enable(rtc_cr_osce);
    rtc_cr_wpeVar.enable(rtc_cr_osce);
    osc_clockVar.enable(rtc_cr_osce);
    rtc_1hz_clockVar.enable(rtc_cr_osce);
    if (!rtcSharesPins || rtc_cr_osce) {
        // Only update if owned by RTC
        osc_clockVar.setValue(rtcClockFrequency);
        osc_clockVar.setStatus(status);
        osc_clockVar.setOrigin(origin);
    }
    rtc_1hz_clockVar.setValue((rtcClockFrequency > 0) ? 1 : 0);
    rtc_1hz_clockVar.setStatus(status);
    rtc_1hz_clockVar.setOrigin(origin);
    // RTC Clocks
    // ==============================
    // Check if gating option
    BooleanVariable rtc_cr_clkoVar = getBooleanVariable("rtc_cr_clko");
    LongVariable rtcclk_gated_clockVar = getLongVariable("rtcclk_gated_clock");
    rtc_cr_clkoVar.enable(rtc_cr_osce);
    if (rtc_cr_clkoVar.isEnabled() && rtc_cr_clkoVar.getValueAsBoolean()) {
        rtcclk_gated_clockVar.setValue(rtcClockFrequency);
        rtcclk_gated_clockVar.setStatus(status);
        rtcclk_gated_clockVar.setOrigin(origin);
        rtcclk_gated_clockVar.enable(rtc_cr_osce);
    } else {
        rtcclk_gated_clockVar.setValue(0L);
        rtcclk_gated_clockVar.setStatus(new Status("Disabled by rtc_cr_clko", Severity.WARNING));
        rtcclk_gated_clockVar.setOrigin("RTCCLK (disabled)");
        rtcclk_gated_clockVar.enable(false);
    }
}
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) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)

Example 5 with BooleanVariable

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

the class SimValidate 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 osc0_peripheral = getStringVariable("osc0_peripheral").getValueAsString();
    final LongVariable osc0_oscer_clockVar = getLongVariable(osc0_peripheral + "/oscer_clock");
    final LongVariable osc0_osc32k_clockVar = getLongVariable(osc0_peripheral + "/osc32k_clock");
    final String osc32k_peripheral = getStringVariable("/SIM/osc32k_peripheral").getValueAsString();
    final LongVariable rtcclk_gated_clockVar = safeGetLongVariable(osc32k_peripheral + "/rtcclk_gated_clock");
    final LongVariable rtc_1hz_clockVar = safeGetLongVariable(osc32k_peripheral + "/rtc_1hz_clock");
    final LongVariable rtc_clkoutVar = safeGetLongVariable("rtc_clkout");
    // 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");
    final LongVariable peripheralClockVar = getLongVariable("system_peripheral_clock");
    // Check if CLKDIV3 Present
    // =====================================
    final Long pllPostDiv3Value;
    final String pllPostDiv3Origin;
    final Variable system_peripheral_postdivider_clockVar = safeGetVariable("system_peripheral_postdivider_clock");
    if (system_peripheral_postdivider_clockVar != null) {
        // After divider
        pllPostDiv3Value = system_peripheral_postdivider_clockVar.getValueAsLong();
        pllPostDiv3Origin = system_peripheral_postdivider_clockVar.getOrigin();
    } else {
        // Direct (no divider)
        pllPostDiv3Value = peripheralClockVar.getValueAsLong();
        pllPostDiv3Origin = peripheralClockVar.getOrigin();
    }
    /**
     * 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 // Peripheral Clock / CLKDIV3
                    1:
                        clockVar.setValue(pllPostDiv3Value);
                        clockVar.setStatus(peripheralClockVar.getStatus());
                        clockVar.setOrigin(pllPostDiv3Origin);
                        break;
                    case // OSCERCLK
                    2:
                        clockVar.setValue(osc0_oscer_clockVar.getValueAsLong());
                        clockVar.setStatus(osc0_oscer_clockVar.getStatus());
                        clockVar.setOrigin(osc0_oscer_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(osc0_osc32k_clockVar.getValueAsLong());
            system_erclk32k_clockVar.setOrigin(osc0_osc32k_clockVar.getOrigin());
            system_erclk32k_clockVar.setStatus(osc0_osc32k_clockVar.getStatus());
            break;
        case // RTC 32.768kHz oscillator
        2:
            system_erclk32k_clockVar.setValue(rtcclk_gated_clockVar.getValueAsLong());
            system_erclk32k_clockVar.setOrigin(rtcclk_gated_clockVar.getOrigin());
            system_erclk32k_clockVar.setStatus(rtcclk_gated_clockVar.getStatus());
            break;
        default:
            sim_sopt1_osc32kselVar.setValue(3);
        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 // RTC 32.768kHz oscillator
            1:
                rtc_clkoutVar.setValue(rtcclk_gated_clockVar.getValueAsLong());
                rtc_clkoutVar.setStatus(rtcclk_gated_clockVar.getStatus());
                rtc_clkoutVar.setOrigin(rtcclk_gated_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");
    }
    // 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) {
                    long temp = sim_clkdiv2_usbVar.getValueAsLong();
                    sim_clkdiv2_usbVar.setRawValue(usbCalcValue);
                    if (sim_clkdiv2_usbVar.getValueAsLong() != temp) {
                        // Trigger update on change
                        sim_clkdiv2_usbVar.notifyListeners();
                    }
                    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)

Aggregations

BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)17 LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)15 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)12 Variable (net.sourceforge.usbdm.deviceEditor.information.Variable)9 DoubleVariable (net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)7 IrqVariable (net.sourceforge.usbdm.deviceEditor.information.IrqVariable)3 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)3 Status (net.sourceforge.usbdm.deviceEditor.model.Status)3 PinListVariable (net.sourceforge.usbdm.deviceEditor.information.PinListVariable)2 Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)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 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 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1