Search in sources :

Example 6 with BooleanVariable

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

the class SimValidateMKL 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 rtc_clkin = getStringVariable("rtc_clkin").getValueAsString();
    final LongVariable rtcclkin_clockVar = safeGetLongVariable(rtc_clkin);
    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_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;
    // 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 = safeGetChoiceVariable("sim_sopt1_osc32ksel");
    if (sim_sopt1_osc32kselVar == null) {
        // No RTC etc
        system_erclk32k_clockVar.setValue(osc0_osc32k_clockVar.getValueAsLong());
        system_erclk32k_clockVar.setOrigin(osc0_osc32k_clockVar.getOrigin());
        system_erclk32k_clockVar.setStatus(osc0_osc32k_clockVar.getStatus());
    } else {
        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) {
        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)

Example 7 with BooleanVariable

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

the class FtmValidate method validate.

/**
 * Class to determine LPTMR settings
 * @throws Exception
 */
@Override
public void validate(Variable variable) throws Exception {
    super.validate(variable);
    // =================================
    DoubleVariable clockFrequencyVar = getDoubleVariable("clockFrequency");
    DoubleVariable clockPeriodVar = getDoubleVariable("clockPeriod");
    ChoiceVariable ftm_sc_clksVar = getChoiceVariable("ftm_sc_clks");
    ChoiceVariable ftm_sc_psVar = getChoiceVariable("ftm_sc_ps");
    LongVariable ftm_modVar = getLongVariable("ftm_mod");
    DoubleVariable ftm_mod_periodVar = getDoubleVariable("ftm_mod_period");
    BooleanVariable ftm_sc_cpwmsVar = getBooleanVariable("ftm_sc_cpwms");
    LongVariable clockSourceVar = null;
    switch((int) ftm_sc_clksVar.getValueAsLong()) {
        case 0:
            clockSourceVar = new LongVariable("Disabled", "/Ftm/Disabled");
            clockSourceVar.setOrigin("Disabled");
            clockSourceVar.setValue(0);
            break;
        default:
            ftm_sc_clksVar.setValue(1);
        case 1:
            clockSourceVar = getLongVariable("/SIM/system_bus_clock");
            break;
        case 2:
            clockSourceVar = getLongVariable("/MCG/system_mcgffclk_clock");
            break;
        case 3:
            clockSourceVar = getLongVariable("ftmExternalClock");
            break;
    }
    double clockFrequency = clockSourceVar.getValueAsDouble();
    String clockOrigin = clockSourceVar.getOrigin();
    clockFrequency = clockFrequency / (1L << ftm_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);
    ftm_mod_periodVar.enable(clockFrequency != 0);
    if (clockFrequency != 0) {
        long ftm_mod = ftm_modVar.getValueAsLong();
        double clockPeriod = 1.0 / clockFrequency;
        clockPeriodVar.setValue(clockPeriod);
        boolean ftm_sc_cpwms = ftm_sc_cpwmsVar.getValueAsBoolean();
        double ftm_mod_period = clockPeriod * (ftm_sc_cpwms ? (2 * (ftm_mod)) : ((ftm_mod + 1)));
        if (variable != null) {
            // Update selectively
            if (variable.equals(ftm_mod_periodVar)) {
                ftm_mod_period = ftm_mod_periodVar.getValueAsDouble();
                // Calculate rounded value
                if (ftm_sc_cpwms) {
                    ftm_mod = Math.max(0, Math.round((ftm_mod_period / clockPeriod) / 2));
                } else {
                    ftm_mod = Math.max(0, Math.round((ftm_mod_period / clockPeriod) - 1));
                }
                ftm_mod_period = clockPeriod * (ftm_sc_cpwms ? (2 * (ftm_mod)) : ((ftm_mod + 1)));
                // Update
                ftm_modVar.setValue(ftm_mod);
            }
        }
        double ftm_mod_periodMax = clockPeriod * (ftm_sc_cpwms ? (2 * (65535.5)) : ((65536.5)));
        ftm_mod_periodVar.setValue(ftm_mod_period);
        ftm_mod_periodVar.setMax(ftm_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 8 with BooleanVariable

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

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

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

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