Search in sources :

Example 1 with Severity

use of net.sourceforge.usbdm.deviceEditor.model.Status.Severity in project usbdm-eclipse-plugins by podonoghue.

the class SimValidateMKL_lite method validateIndexVariables.

/**
 * Updates
 * - sim_sopt2_pllfllsel[x]
 * - system_peripheral_clock[x]
 * - system_core_clock[x]
 * - system_bus_clock[x]
 * - system_flexbus_clock[x]
 * - system_flash_clock[x]
 * - sim_clkdiv1_outdiv1[x]
 * - sim_clkdiv1_outdiv2[x]
 * - sim_clkdiv1_outdiv3[x]
 * - sim_clkdiv1_outdiv4[x]
 *
 * @param variable
 * @throws Exception
 */
void validateIndexVariables(Variable variable) throws Exception {
    // ======================================
    final LongVariable system_core_clockVar = getLongVariable("system_core_clock");
    final LongVariable system_bus_clockVar = getLongVariable("system_bus_clock");
    final LongVariable sim_clkdiv1_outdiv1Var = getLongVariable("sim_clkdiv1_outdiv1");
    final LongVariable sim_clkdiv1_outdiv4Var = getLongVariable("sim_clkdiv1_outdiv4");
    // Core & System Clock
    // ===========================================
    // Attempt to find acceptable divisor
    final LongVariable system_mcgoutclk_clockVar = getLongVariable("/MCG/system_mcgoutclk_clock");
    long inputFrequency = system_mcgoutclk_clockVar.getValueAsLong();
    final FindDivisor coreDivisor = new FindDivisor(inputFrequency, system_core_clockVar.getValueAsLong()) {

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

        @Override
        boolean okValue(int divisor, double frequency) {
            return (frequency <= MAX_BUS_CLOCK_FREQ) && (frequency <= coreFrequency);
        }
    };
    severity = Severity.OK;
    sb = new StringBuilder();
    if (variable == system_bus_clockVar) {
        // Clock variable changed - replace with nearest value if found
        if (flashDivisor.divisor == 0) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(flashDivisor.divisors);
        system_bus_clockVar.setValue(flashDivisor.nearestTargetFrequency);
        system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
    } else {
        // Clock variable not changed - just validate
        if ((flashDivisor.divisor == 0) || (system_bus_clockVar.getValueAsLong() != (flashDivisor.nearestTargetFrequency))) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(flashDivisor.divisors);
        system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
    }
}
Also used : Status(net.sourceforge.usbdm.deviceEditor.model.Status) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) Severity(net.sourceforge.usbdm.deviceEditor.model.Status.Severity)

Example 2 with Severity

use of net.sourceforge.usbdm.deviceEditor.model.Status.Severity in project usbdm-eclipse-plugins by podonoghue.

the class SimValidate_fll method validateIndexVariables.

/**
 * Updates
 * - system_peripheral_clock[x]
 * - system_core_clock[x]
 * - system_bus_clock[x]
 * - system_flexbus_clock[x]
 * - system_flash_clock[x]
 * - sim_clkdiv1_outdiv1[x]
 * - sim_clkdiv1_outdiv2[x]
 * - sim_clkdiv1_outdiv3[x]
 * - sim_clkdiv1_outdiv4[x]
 *
 * @param variable
 * @throws Exception
 */
void validateIndexVariables(Variable variable) throws Exception {
    // ======================================
    final LongVariable system_core_clockVar = getLongVariable("system_core_clock");
    final LongVariable system_bus_clockVar = getLongVariable("system_bus_clock");
    final LongVariable sim_clkdiv1_outdiv1Var = getLongVariable("sim_clkdiv1_outdiv1");
    final LongVariable sim_clkdiv1_outdiv4Var = getLongVariable("sim_clkdiv1_outdiv4");
    // Core & System Clock
    // ===========================================
    // Attempt to find acceptable divisor
    final LongVariable system_mcgoutclk_clockVar = getLongVariable("/MCG/system_mcgoutclk_clock");
    long inputFrequency = system_mcgoutclk_clockVar.getValueAsLong();
    final FindDivisor coreDivisor = new FindDivisor(inputFrequency, system_core_clockVar.getValueAsLong()) {

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

        @Override
        boolean okValue(int divisor, double frequency) {
            return (frequency <= MAX_BUS_CLOCK_FREQ) && (frequency <= coreFrequency);
        }
    };
    severity = Severity.OK;
    sb = new StringBuilder();
    if (variable == system_bus_clockVar) {
        // Clock variable changed - replace with nearest value if found
        if (flashDivisor.divisor == 0) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(flashDivisor.divisors);
        system_bus_clockVar.setValue(flashDivisor.nearestTargetFrequency);
        system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
    } else {
        // Clock variable not changed - just validate
        if ((flashDivisor.divisor == 0) || (system_bus_clockVar.getValueAsLong() != (flashDivisor.nearestTargetFrequency))) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(flashDivisor.divisors);
        system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
    }
}
Also used : Status(net.sourceforge.usbdm.deviceEditor.model.Status) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) Severity(net.sourceforge.usbdm.deviceEditor.model.Status.Severity)

Example 3 with Severity

use of net.sourceforge.usbdm.deviceEditor.model.Status.Severity in project usbdm-eclipse-plugins by podonoghue.

the class PllConfigure method validate.

protected void validate(Variable mcg_erc_clockNode, Variable pllInputFrequencyNode, Variable system_mcgpllclk_clockVar, Variable mcg_c5_prdiv0Node, Variable mcg_c6_vdiv0Node) {
    // Main clock used by FLL
    long mcg_erc_clock = mcg_erc_clockNode.getValueAsLong();
    long pllTargetFrequency = system_mcgpllclk_clockVar.getRawValueAsLong();
    // System.err.println(String.format("\nPllClockValidater.validate(): mcg_erc_clock = %d, pllTargetFrequency = %d", mcg_erc_clock, pllTargetFrequency));
    int mcg_prdiv = PRDIV_MIN;
    int mcg_vdiv = VDIV_MIN;
    boolean pllInputValid = false;
    boolean pllOutputValid = false;
    Set<Long> pllFrequencies = new TreeSet<Long>();
    StringBuilder sb = new StringBuilder();
    long nearest_PllOutFrequency = Long.MAX_VALUE;
    // Try each prescale value
    for (int mcg_prdiv_probe = PRDIV_MIN; mcg_prdiv_probe <= PRDIV_MAX; mcg_prdiv_probe++) {
        if (sb.length() > 0) {
            // System.err.println(sb.toString());
            sb = new StringBuilder();
        }
        double pllInFrequency = mcg_erc_clock / mcg_prdiv_probe;
        sb.append(String.format("(prdiv = %d, pllIn=%f) => ", mcg_prdiv_probe, pllInFrequency));
        if (pllInFrequency > PLL_IN_MAX) {
            // Invalid as input to PLL
            sb.append("too high");
            continue;
        }
        if (pllInFrequency < PLL_IN_MIN) {
            // Invalid as input to PLL
            sb.append("too low");
            break;
        }
        pllInputValid = true;
        // Try each multiplier value
        for (int mcg_vdiv_probe = VDIV_MIN; mcg_vdiv_probe <= VDIV_MAX; mcg_vdiv_probe++) {
            long pllOutFrequency = Math.round((mcg_vdiv_probe * pllInFrequency) / PLL_POST_DIV);
            sb.append(pllOutFrequency);
            if (pllOutFrequency < PLL_OUT_MIN) {
                sb.append("<, ");
                continue;
            }
            if (pllOutFrequency > PLL_OUT_MAX) {
                sb.append(">, ");
                break;
            }
            sb.append("*,");
            pllFrequencies.add(pllOutFrequency);
            // Best so far
            if (Math.abs(pllOutFrequency - pllTargetFrequency) < Math.abs(nearest_PllOutFrequency - pllTargetFrequency)) {
                nearest_PllOutFrequency = pllOutFrequency;
                mcg_prdiv = mcg_prdiv_probe;
                mcg_vdiv = mcg_vdiv_probe;
            }
            // Accept value within ~2.5% of desired
            if (Math.abs(pllOutFrequency - pllTargetFrequency) < (pllTargetFrequency / 50)) {
                sb.append("=");
                pllOutputValid = true;
            }
        }
        if (sb.length() > 0) {
            sb = new StringBuilder();
        }
    }
    // Update with 'best value' - irrespective of whether they are acceptable
    mcg_c5_prdiv0Node.setValue(mcg_prdiv);
    mcg_c6_vdiv0Node.setValue(mcg_vdiv);
    pllInputFrequencyNode.setValue(mcg_erc_clock / mcg_prdiv);
    pllInputFrequencyNode.setOrigin("(" + mcg_erc_clockNode.getOrigin() + " via MCG_ERC)/PRDIV");
    system_mcgpllclk_clockVar.setOrigin(mcg_erc_clockNode.getOrigin() + " via PLL");
    if (!pllInputValid) {
        String msg = String.format("PLL not usable with input clock frequency %sHz\nRange: [%s,%s]", EngineeringNotation.convert(mcg_erc_clock, 3), EngineeringNotation.convert(PLL_IN_MIN, 3), EngineeringNotation.convert(PLL_IN_MAX, 3));
        Status status = new Status(msg, Severity.WARNING);
        pllInputFrequencyNode.setStatus(status);
        pllStatus = status;
    } else {
        // PLL in is valid
        pllInputFrequencyNode.setStatus((Status) null);
        // Check PLL out
        StringBuilder status = new StringBuilder();
        Status.Severity severity = Severity.OK;
        if (!pllOutputValid) {
            // PLL Output invalid
            status.append("Not possible to generate desired PLL frequency from input clock\n");
            severity = Severity.WARNING;
        // Update PLL in case it was approximated
        } else {
            // PLL Output valid
            if (pllTargetFrequency != nearest_PllOutFrequency) {
                // Update PLL as it was approximated
                pllTargetFrequency = nearest_PllOutFrequency;
                if (system_mcgpllclk_clockVar.isEnabled()) {
                    system_mcgpllclk_clockVar.setValue(pllTargetFrequency);
                }
            }
        }
        status.append("Possible values = \n");
        boolean needComma = false;
        int lineCount = -1;
        for (Long freq : pllFrequencies) {
            if (needComma) {
                status.append(", ");
            }
            if (lineCount++ >= 10) {
                status.append("\n");
                lineCount = 0;
            }
            needComma = true;
            status.append(EngineeringNotation.convert(freq, 3) + "Hz");
        }
        pllStatus = new Status(status.toString(), severity);
    }
}
Also used : Status(net.sourceforge.usbdm.deviceEditor.model.Status) TreeSet(java.util.TreeSet) Severity(net.sourceforge.usbdm.deviceEditor.model.Status.Severity)

Example 4 with Severity

use of net.sourceforge.usbdm.deviceEditor.model.Status.Severity in project usbdm-eclipse-plugins by podonoghue.

the class SimValidateMKL method validateIndexVariables.

/**
 * Updates
 * - sim_sopt2_pllfllsel[x]
 * - system_peripheral_clock[x]
 * - system_core_clock[x]
 * - system_bus_clock[x]
 * - system_flexbus_clock[x]
 * - system_flash_clock[x]
 * - sim_clkdiv1_outdiv1[x]
 * - sim_clkdiv1_outdiv2[x]
 * - sim_clkdiv1_outdiv3[x]
 * - sim_clkdiv1_outdiv4[x]
 *
 * @param variable
 * @throws Exception
 */
void validateIndexVariables(Variable variable) throws Exception {
    final ChoiceVariable sim_sopt2_pllfllselVar = safeGetChoiceVariable("sim_sopt2_pllfllsel");
    if (sim_sopt2_pllfllselVar != null) {
        final LongVariable system_mcgfllclk_clockVar = safeGetLongVariable("/MCG/system_mcgfllclk_clock");
        final LongVariable system_mcgpllclk_clockVar = safeGetLongVariable("/MCG/system_mcgpllclk_clock");
        final LongVariable usb1pfdclk_ClockVar = safeGetLongVariable("/MCG/usb1pfdclk_Clock");
        final LongVariable system_irc48m_clockVar = safeGetLongVariable("/MCG/system_irc48m_clock");
        // Determine PLLFLLCLOCK
        // =====================================
        final LongVariable peripheralClockVar = getLongVariable("system_peripheral_clock");
        switch((int) sim_sopt2_pllfllselVar.getValueAsLong()) {
            default:
                sim_sopt2_pllfllselVar.setValue(0);
            case 0:
                if (system_mcgfllclk_clockVar != null) {
                    peripheralClockVar.setValue(system_mcgfllclk_clockVar.getValueAsLong());
                    peripheralClockVar.setStatus(system_mcgfllclk_clockVar.getFilteredStatus());
                    peripheralClockVar.setOrigin(system_mcgfllclk_clockVar.getOrigin());
                } else {
                    peripheralClockVar.setValue(0);
                    peripheralClockVar.setStatus(new Status("FLL not present", Severity.ERROR));
                    peripheralClockVar.setOrigin(null);
                }
                break;
            case 1:
                if (system_mcgpllclk_clockVar != null) {
                    peripheralClockVar.setValue(system_mcgpllclk_clockVar.getValueAsLong() / 2);
                    peripheralClockVar.setStatus(system_mcgpllclk_clockVar.getFilteredStatus());
                    peripheralClockVar.setOrigin(system_mcgpllclk_clockVar.getOrigin() + "/2");
                } else {
                    sim_sopt2_pllfllselVar.setValue(0);
                }
                break;
            case 2:
                if (usb1pfdclk_ClockVar != null) {
                    peripheralClockVar.setValue(usb1pfdclk_ClockVar.getValueAsLong());
                    peripheralClockVar.setStatus(usb1pfdclk_ClockVar.getStatus());
                    peripheralClockVar.setOrigin(usb1pfdclk_ClockVar.getOrigin());
                } else {
                    sim_sopt2_pllfllselVar.setValue(0);
                }
                break;
            case 3:
                if (system_irc48m_clockVar != null) {
                    peripheralClockVar.setValue(system_irc48m_clockVar.getValueAsLong());
                    peripheralClockVar.setStatus(system_irc48m_clockVar.getStatus());
                    peripheralClockVar.setOrigin(system_irc48m_clockVar.getOrigin());
                } else {
                    sim_sopt2_pllfllselVar.setValue(0);
                }
                break;
        }
    }
    // ======================================
    final LongVariable system_core_clockVar = getLongVariable("system_core_clock");
    final LongVariable system_bus_clockVar = getLongVariable("system_bus_clock");
    final LongVariable sim_clkdiv1_outdiv1Var = getLongVariable("sim_clkdiv1_outdiv1");
    final LongVariable sim_clkdiv1_outdiv4Var = getLongVariable("sim_clkdiv1_outdiv4");
    // Core & System Clock
    // ===========================================
    // Attempt to find acceptable divisor
    final LongVariable system_mcgoutclk_clockVar = getLongVariable("/MCG/system_mcgoutclk_clock");
    long inputFrequency = system_mcgoutclk_clockVar.getValueAsLong();
    final FindDivisor coreDivisor = new FindDivisor(inputFrequency, system_core_clockVar.getValueAsLong()) {

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

        @Override
        boolean okValue(int divisor, double frequency) {
            return (frequency <= MAX_BUS_CLOCK_FREQ) && (frequency <= coreFrequency);
        }
    };
    severity = Severity.OK;
    sb = new StringBuilder();
    if (variable == system_bus_clockVar) {
        // Clock variable changed - replace with nearest value if found
        if (flashDivisor.divisor == 0) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(flashDivisor.divisors);
        system_bus_clockVar.setValue(flashDivisor.nearestTargetFrequency);
        system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
    } else {
        // Clock variable not changed - just validate
        if ((flashDivisor.divisor == 0) || (system_bus_clockVar.getValueAsLong() != (flashDivisor.nearestTargetFrequency))) {
            severity = Severity.ERROR;
            sb.append("Illegal Frequency\n");
        }
        sb.append(flashDivisor.divisors);
        system_bus_clockVar.setStatus(new Status(sb.toString(), severity));
        sim_clkdiv1_outdiv4Var.setValue(flashDivisor.divisor);
    }
}
Also used : Status(net.sourceforge.usbdm.deviceEditor.model.Status) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) Severity(net.sourceforge.usbdm.deviceEditor.model.Status.Severity) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)

Example 5 with Severity

use of net.sourceforge.usbdm.deviceEditor.model.Status.Severity in project usbdm-eclipse-plugins by podonoghue.

the class SimValidate method validateIndexVariables.

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

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

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

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

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

Aggregations

Status (net.sourceforge.usbdm.deviceEditor.model.Status)5 Severity (net.sourceforge.usbdm.deviceEditor.model.Status.Severity)5 LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)4 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)2 TreeSet (java.util.TreeSet)1 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)1 Variable (net.sourceforge.usbdm.deviceEditor.information.Variable)1