Search in sources :

Example 1 with Signal

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

the class WriteFamilyCpp method writeMappedSignals.

/**
 * Write declarations for simple peripheral signals (e.g. GPIO,ADC,PWM) that
 * are mapped to pins e.g.
 *
 * <pre>
 *    using adc_p53              = const USBDM::Adc1&lt;4&gt;;
 *    using adc_p54              = const USBDM::Adc1&lt;5&gt;;
 * </pre>
 *
 * @param writer
 *           Where to write
 *
 * @throws Exception
 */
private void writeMappedSignals(DocumentUtilities writer) throws IOException {
    writeIncludes(writer);
    writer.writeOpenNamespace(DeviceInfo.NAME_SPACE, "Namespace enclosing USBDM classes");
    writer.openUsbdmDocumentationGroup();
    DocumentationGroups startGroup = new DocumentationGroups(writer);
    for (String key : fDeviceInfo.getPeripherals().keySet()) {
        Peripheral peripheral = fDeviceInfo.getPeripherals().get(key);
        for (Entry<String, Pin> pinEntry : fDeviceInfo.getPins().entrySet()) {
            Pin pin = pinEntry.getValue();
            Map<MuxSelection, MappingInfo> mappedSignals = pin.getMappableSignals();
            if (mappedSignals == null) {
                continue;
            }
            for (Entry<MuxSelection, MappingInfo> muxEntry : mappedSignals.entrySet()) {
                if (muxEntry.getKey() == MuxSelection.unassigned) {
                    continue;
                }
                MappingInfo mappedSignal = muxEntry.getValue();
                for (int fnIndex = 0; fnIndex < mappedSignal.getSignals().size(); fnIndex++) {
                    Signal function = mappedSignal.getSignals().get(fnIndex);
                    if (function.getPeripheral() == peripheral) {
                        String template = getMappedSignals(peripheral, mappedSignal, fnIndex);
                        if (template != null) {
                            startGroup.openGroup(peripheral);
                            writer.write(template);
                            writer.flush();
                        }
                    }
                }
            }
        }
    }
    startGroup.closeGroup();
    writer.writeDocBanner("Used to configure pin-mapping before 1st use of peripherals");
    writer.write("extern void " + DO_PIN_MAPPING_FUNCTION + "();\n");
    writer.closeDocumentationGroup();
    writer.writeCloseNamespace();
    writer.flush();
}
Also used : MuxSelection(net.sourceforge.usbdm.deviceEditor.information.MuxSelection) Signal(net.sourceforge.usbdm.deviceEditor.information.Signal) Peripheral(net.sourceforge.usbdm.deviceEditor.information.Peripheral) Pin(net.sourceforge.usbdm.deviceEditor.information.Pin) MappingInfo(net.sourceforge.usbdm.deviceEditor.information.MappingInfo)

Example 2 with Signal

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

the class FamilyXmlWriter method writePin.

/**
 * Writes XML describing how peripheral signals are mapped to a pin
 * e.g.<pre>
 *   &lt;pin name=="PTD7"&gt;
 *      &lt;mux sel="mux1" signal="GPIOD_7" /&gt;
 *      &lt;mux sel="mux2" signal="CMT_IRO" /&gt;
 *      &lt;reset sel="Disabled" /&gt;
 *      &lt;default sel="mux1" /&gt;
 *   &lt;/pin&gt;
 * </pre>
 *
 * @param documentUtilities   Where to write
 * @param pin                 Pin to write definitions for
 *
 * @throws IOException
 */
private void writePin(XmlDocumentUtilities documentUtilities, Pin pin) throws IOException {
    documentUtilities.openTag("pin");
    Map<MuxSelection, MappingInfo> mappingInfo = pin.getMappableSignals();
    Set<MuxSelection> sortedSelectionIndexes = mappingInfo.keySet();
    boolean isFixed = false;
    // Construct list of alternatives
    StringBuffer alternativeHint = new StringBuffer();
    for (MuxSelection selection : mappingInfo.keySet()) {
        if (selection == MuxSelection.fixed) {
            isFixed = true;
        }
        MappingInfo mInfo = mappingInfo.get(selection);
        StringBuffer name = new StringBuffer();
        name.append(mInfo.getSignalList());
        if (alternativeHint.length() != 0) {
            alternativeHint.append(", ");
        }
        alternativeHint.append(name);
    }
    documentUtilities.writeAttribute("name", pin.getName());
    if (isFixed) {
        documentUtilities.writeAttribute("isFixed", "true");
    }
    for (MuxSelection selection : sortedSelectionIndexes) {
        MappingInfo mInfo = mappingInfo.get(selection);
        StringBuffer name = new StringBuffer();
        name.append(mInfo.getSignalList());
        for (Signal fn : mInfo.getSignals()) {
            documentUtilities.openTag("mux");
            documentUtilities.writeAttribute("sel", selection.name());
            documentUtilities.writeAttribute("signal", fn.getName());
            documentUtilities.closeTag();
        }
    }
    documentUtilities.openTag("reset");
    documentUtilities.writeAttribute("sel", pin.getResetValue().name());
    documentUtilities.closeTag();
    // documentUtilities.openTag("default");
    // documentUtilities.writeAttribute("sel", pin.getDefaultValue().name());
    // documentUtilities.closeTag();
    documentUtilities.closeTag();
}
Also used : MuxSelection(net.sourceforge.usbdm.deviceEditor.information.MuxSelection) Signal(net.sourceforge.usbdm.deviceEditor.information.Signal) MappingInfo(net.sourceforge.usbdm.deviceEditor.information.MappingInfo)

Example 3 with Signal

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

the class ParseFamilyCSV method createSignalsFromString.

/**
 * Create a list of signals described by a string
 *
 * @param pinText Text of signal names e.g. <b><i>PTA4/LLWU_P3</b></i>
 *
 * @return List of signals created
 *
 * @throws Exception
 */
private ArrayList<Signal> createSignalsFromString(String pinText, Boolean convert) {
    ArrayList<Signal> signalList = new ArrayList<Signal>();
    pinText = pinText.trim();
    if (pinText.isEmpty()) {
        return signalList;
    }
    String[] signalNames = pinText.split("\\s*/\\s*");
    for (String signalName : signalNames) {
        signalName = signalName.trim();
        signalName = fixSignalName(signalName);
        if (signalName.isEmpty()) {
            continue;
        }
        if (convert) {
            signalName = convertName(signalName);
        }
        Signal signal = fDeviceInfo.findOrCreateSignal(signalName);
        if (signal != null) {
            // XXX Log creating signals
            // System.err.println("Added "+signalName+" to "+signal.getPeripheral());
            signalList.add(signal);
            if (signal != Signal.DISABLED_SIGNAL) {
                Peripheral x = signal.getPeripheral();
                if ((x == null) || x.getClass().equals(WriterForNull.class)) {
                    System.err.println("Signal \'" + signalName + "\' added to WriterForNull");
                }
            }
        } else {
            System.err.println("Signal not found for " + signalName);
        }
    }
    return signalList;
}
Also used : Signal(net.sourceforge.usbdm.deviceEditor.information.Signal) Peripheral(net.sourceforge.usbdm.deviceEditor.information.Peripheral) ArrayList(java.util.ArrayList)

Example 4 with Signal

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

the class ParseFamilyCSV method parsePinLine.

/**
 * Parse line containing Pin information
 *
 * @param line
 * @throws Exception
 */
private void parsePinLine(String[] line) throws Exception {
    StringBuffer sb = new StringBuffer();
    if (!line[0].equals("Pin")) {
        return;
    }
    String pinName = line[fPinIndex];
    if ((pinName == null) || (pinName.isEmpty())) {
        throw new Exception("No pin name");
    }
    pinName = fixSignalName(pinName);
    // Use first name on pin as Pin name e.g. PTC4/LLWU_P8 => PTC4
    Pattern p = Pattern.compile("(.+?)/.*");
    Matcher m = p.matcher(pinName);
    if (m.matches()) {
        pinName = m.group(1);
    }
    final Pin pin = fDeviceInfo.createPin(pinName);
    sb.append(String.format("%-10s => ", pin.getName()));
    boolean pinIsMapped = false;
    for (int col = fAltStartIndex; col <= fAltEndIndex; col++) {
        if (col >= line.length) {
            break;
        }
        ArrayList<Signal> signals = createSignalsFromString(line[col], true);
        for (Signal signal : signals) {
            sb.append(signal.getName() + ", ");
            if ((signal != null)) {
                MuxSelection muxValue = MuxSelection.valueOf(col - fAltStartIndex);
                fDeviceInfo.createMapping(signal, pin, muxValue);
                pinIsMapped = true;
            }
        }
    }
    if ((line.length > fResetIndex) && (line[fResetIndex] != null) && (!line[fResetIndex].isEmpty())) {
        String resetName = line[fResetIndex];
        ArrayList<Signal> resetSignals = createSignalsFromString(resetName, true);
        if (!pinIsMapped) {
            for (Signal resetSignal : resetSignals) {
                sb.append("R:" + resetSignal.getName() + ", ");
                // Pin is not mapped to this signal in the ALT columns - must be a non-mappable pin
                MappingInfo mapping = fDeviceInfo.createMapping(resetSignal, pin, MuxSelection.fixed);
                for (Signal signal : mapping.getSignals()) {
                    signal.setResetPin(mapping);
                }
            }
        }
        pin.setResetSignals(fDeviceInfo, resetName);
    } else {
        sb.append("R:" + Signal.DISABLED_SIGNAL.getName() + ", ");
        fDeviceInfo.createMapping(Signal.DISABLED_SIGNAL, pin, MuxSelection.unassigned);
        pin.setResetSignals(fDeviceInfo, Signal.DISABLED_SIGNAL.getName());
    }
    for (PackageColumnInfo pkgIndex : fPackageIndexes) {
        String pinNum = line[pkgIndex.index];
        if (pinNum.equals("*")) {
            continue;
        }
        DevicePackage devicePackage = fDeviceInfo.findDevicePackage(pkgIndex.name);
        if (devicePackage == null) {
            throw new RuntimeException("Failed to find package " + pkgIndex.name + ", for " + pinName);
        }
        devicePackage.addPin(pin, pinNum);
        sb.append("(" + pkgIndex.name + ":" + pinNum + ") ");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) DevicePackage(net.sourceforge.usbdm.deviceEditor.information.DevicePackage) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) IOException(java.io.IOException) MuxSelection(net.sourceforge.usbdm.deviceEditor.information.MuxSelection) Signal(net.sourceforge.usbdm.deviceEditor.information.Signal) Pin(net.sourceforge.usbdm.deviceEditor.information.Pin) MappingInfo(net.sourceforge.usbdm.deviceEditor.information.MappingInfo)

Example 5 with Signal

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

the class PinListDialogue method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayout gl = new GridLayout(5, true);
    gl.marginLeft = 10;
    gl.marginRight = 10;
    gl.marginTop = 10;
    container.setLayout(gl);
    container.layout();
    String[] initialSelections = fInitialSelections.split("[, ]+");
    Vector<Signal> pinTable = fPeripheral.getSignalTables().get(0).table;
    for (int i = 0; i < fCombos.length; i++) {
        try {
            fCombos[i] = new Combo(container, SWT.CHECK);
            fCombos[i].setItems(fPinList);
            if (i < initialSelections.length) {
                int signalIndex = Integer.parseInt(initialSelections[i]);
                Signal entry = pinTable.elementAt(signalIndex);
                String item = String.format(PIN_TEMPLATE, entry.getName(), entry.getMappedPin().getPin().getName());
                int sel = fCombos[i].indexOf(item);
                if (sel > 0) {
                    fCombos[i].select(sel);
                } else {
                    fCombos[i].select(0);
                }
            }
        } catch (NumberFormatException e) {
        }
    }
    parent.layout(true);
    return container;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Signal(net.sourceforge.usbdm.deviceEditor.information.Signal) Composite(org.eclipse.swt.widgets.Composite) Combo(org.eclipse.swt.widgets.Combo)

Aggregations

Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)12 Pin (net.sourceforge.usbdm.deviceEditor.information.Pin)5 MappingInfo (net.sourceforge.usbdm.deviceEditor.information.MappingInfo)4 MuxSelection (net.sourceforge.usbdm.deviceEditor.information.MuxSelection)4 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)2 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)2 Peripheral (net.sourceforge.usbdm.deviceEditor.information.Peripheral)2 Status (net.sourceforge.usbdm.deviceEditor.model.Status)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DevicePackage (net.sourceforge.usbdm.deviceEditor.information.DevicePackage)1 DoubleVariable (net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)1 LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)1 InfoTable (net.sourceforge.usbdm.deviceEditor.information.Peripheral.InfoTable)1 PinListVariable (net.sourceforge.usbdm.deviceEditor.information.PinListVariable)1 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)1 CategoryModel (net.sourceforge.usbdm.deviceEditor.model.CategoryModel)1 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1