Search in sources :

Example 21 with Variable

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

Variable (net.sourceforge.usbdm.deviceEditor.information.Variable)21 LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)20 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)17 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)17 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)11 DoubleVariable (net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)10 BitmaskVariable (net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable)7 IndexedCategoryVariable (net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable)7 IrqVariable (net.sourceforge.usbdm.deviceEditor.information.IrqVariable)7 NumericListVariable (net.sourceforge.usbdm.deviceEditor.information.NumericListVariable)7 PinListVariable (net.sourceforge.usbdm.deviceEditor.information.PinListVariable)7 Status (net.sourceforge.usbdm.deviceEditor.model.Status)7 FileNotFoundException (java.io.FileNotFoundException)6 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)6 VariableModel (net.sourceforge.usbdm.deviceEditor.model.VariableModel)2 Node (org.w3c.dom.Node)2 ArrayList (java.util.ArrayList)1 Pair (net.sourceforge.usbdm.deviceEditor.information.Variable.Pair)1 Severity (net.sourceforge.usbdm.deviceEditor.model.Status.Severity)1 ProjectAction (net.sourceforge.usbdm.packageParser.ProjectAction)1