Search in sources :

Example 26 with LongVariable

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

the class PdbValidate method doPulseValidate.

/**
 * Validate a PDB pulse output settings
 *
 * @param  variable   Variable that triggered change (may be null)
 * @param  channel    The pulse output to validate e.g. 0, 1 etc
 *
 * @throws Exception
 */
void doPulseValidate(Variable variable, int channel) throws Exception {
    // In/Out
    LongVariable pdb_poX_dly_dly1Var = safeGetLongVariable("pdb_po" + channel + "_dly_dly1");
    if (pdb_poX_dly_dly1Var == null) {
        // Channel doesn't exit
        return;
    }
    LongVariable pdb_poX_dly_dly2Var = getLongVariable("pdb_po" + channel + "_dly_dly2");
    // Out/Out
    DoubleVariable pdb_poX_dly_dly1_delayVar = getDoubleVariable("pdb_po" + channel + "_dly_dly1_delay");
    DoubleVariable pdb_poX_dly_dly2_delayVar = getDoubleVariable("pdb_po" + channel + "_dly_dly2_delay");
    LongVariable pdb_poenVar = getLongVariable("pdb_poen");
    boolean dlyEnable = (pdb_poenVar.getRawValueAsLong() & (1 << channel)) != 0;
    // Do enable/disable first
    pdb_poX_dly_dly1Var.enable(dlyEnable);
    pdb_poX_dly_dly1_delayVar.enable(dlyEnable);
    pdb_poX_dly_dly2Var.enable(dlyEnable);
    pdb_poX_dly_dly2_delayVar.enable(dlyEnable);
    // Get current values
    long pdb_poX_dly_dly1 = pdb_poX_dly_dly1Var.getRawValueAsLong();
    double pdb_poX_dly_dly1_delay = pdb_poX_dly_dly1_delayVar.getRawValueAsDouble();
    long pdb_poX_dly_dly2 = pdb_poX_dly_dly2Var.getRawValueAsLong();
    double pdb_poX_dly_dly2_delay = pdb_poX_dly_dly2_delayVar.getRawValueAsDouble();
    if (clockChanged) {
        pdb_poX_dly_dly1_delayVar.setOrigin(pdbClockOrigin + " period * pdb_po" + channel + "_dly_dly1");
        pdb_poX_dly_dly2_delayVar.setOrigin(pdbClockOrigin + " period * pdb_po" + channel + "_dly_dly2");
    }
    if (variable != null) {
        if (variable.equals(pdb_poX_dly_dly1_delayVar)) {
            // Calculate rounded value
            pdb_poX_dly_dly1 = Math.max(0, Math.round((pdb_poX_dly_dly1_delay / pdb_period) - 1));
            // Update
            pdb_poX_dly_dly1Var.setValue(pdb_poX_dly_dly1);
        } else if (variable.equals(pdb_poX_dly_dly2_delayVar)) {
            // Calculate rounded value
            pdb_poX_dly_dly2 = Math.max(0, Math.round((pdb_poX_dly_dly2_delay / pdb_period) - 1));
            // Update
            pdb_poX_dly_dly2Var.setValue(pdb_poX_dly_dly2);
        }
    }
    pdb_poX_dly_dly1Var.setMax(pdb_mod);
    pdb_poX_dly_dly1_delayVar.setMax((pdb_mod + 1.5) * pdb_period);
    pdb_poX_dly_dly2Var.setMax(pdb_mod);
    pdb_poX_dly_dly2_delayVar.setMax((pdb_mod + 1.5) * pdb_period);
    pdb_poX_dly_dly1_delayVar.setValue(pdb_period * (pdb_poX_dly_dly1 + 1));
    pdb_poX_dly_dly2_delayVar.setValue(pdb_period * (pdb_poX_dly_dly2 + 1));
}
Also used : LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)

Example 27 with LongVariable

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

the class PitValidate method validate.

/**
 * Class to determine PIT settings
 *
 * Outputs pit_ldval
 *
 * @throws Exception
 */
@Override
public void validate(Variable variable) throws Exception {
    super.validate(variable);
    // Clocks
    // =================================
    LongVariable clockVar = getLongVariable("/SIM/system_bus_clock");
    LongVariable pit_ldvalVar = getLongVariable("pit_ldval");
    DoubleVariable pit_periodVar = getDoubleVariable("pit_period");
    DoubleVariable pit_frequencyVar = getDoubleVariable("pit_frequency");
    double busFrequency = clockVar.getValueAsDouble();
    long pit_ldval = pit_ldvalVar.getValueAsLong();
    if (variable != null) {
        if (variable.equals(pit_periodVar)) {
            // Default period ->  ldval, frequency
            // System.err.println("pit_period");
            double pit_period = pit_periodVar.getValueAsDouble();
            if (pit_period == 0) {
                pit_ldval = 0;
            } else {
                pit_ldval = Math.max(0, Math.round((pit_period * busFrequency) - 1));
            }
        } else if (variable.equals(pit_frequencyVar)) {
            // Default frequency ->  period, ldval
            // System.err.println("pit_frequency");
            double pit_frequency = pit_frequencyVar.getValueAsDouble();
            if (pit_frequency == 0) {
                pit_ldval = 0;
            } else {
                pit_ldval = Math.max(0, Math.round(busFrequency / pit_frequency - 1));
            }
        }
    }
    pit_periodVar.setMax((pit_ldvalVar.getMax() + 1) / busFrequency);
    pit_ldvalVar.setValue(pit_ldval);
    if (pit_ldval == 0) {
        pit_periodVar.setValue(0);
        pit_frequencyVar.setValue(0);
    } else {
        pit_periodVar.setValue((pit_ldval + 1) / busFrequency);
        pit_frequencyVar.setValue(busFrequency / (pit_ldval + 1));
    }
}
Also used : LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)

Example 28 with LongVariable

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

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