Search in sources :

Example 1 with MappingInfo

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

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

the class WriteFamilyCpp method writeDocumentation.

/**
 * Write pin mapping documentation
 *
 * @param writer
 *           Where to write
 *
 * @throws IOException
 */
private void writeDocumentation(DocumentUtilities writer) throws IOException {
    Map<String, Pin> pinsByLocation = new TreeMap<String, Pin>(Signal.comparator);
    Map<String, Pin> pinsByFunction = new TreeMap<String, Pin>(Signal.comparator);
    writer.write(DOCUMENTATION_OPEN);
    writer.write(String.format(TABLE_OPEN, "PinsByPinName", "Pins by Pin Name"));
    for (String pinName : fDeviceInfo.getPins().keySet()) {
        Pin pin = fDeviceInfo.getPins().get(pinName);
        if (!pin.isAvailableInPackage()) {
            // Discard pins without package location
            continue;
        }
        String useDescription = pin.getPinUseDescription();
        if (useDescription.isEmpty()) {
            useDescription = "-";
        }
        Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
        MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
        String signalList;
        if (mappedSignal == null) {
            signalList = "-";
        } else {
            signalList = mappedSignal.getSignalList();
        }
        writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
        if ((pin.getLocation() != null) && !pin.getLocation().isEmpty()) {
            pinsByLocation.put(pin.getLocation(), pin);
        }
        pinsByFunction.put(signalList, pin);
    }
    writer.write(TABLE_CLOSE);
    writer.write(String.format(TABLE_OPEN, "PinsByLocation", "Pins by Location"));
    for (String pinName : pinsByLocation.keySet()) {
        Pin pin = pinsByLocation.get(pinName);
        String useDescription = pin.getPinUseDescription();
        if (useDescription.isEmpty()) {
            useDescription = "-";
        }
        Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
        MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
        String signalList;
        if (mappedSignal == null) {
            signalList = "-";
        } else {
            signalList = mappedSignal.getSignalList();
        }
        writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
    }
    writer.write(TABLE_CLOSE);
    writer.write(String.format(TABLE_OPEN, "PinsByFunction", "Pins by Function"));
    for (String pinName : pinsByFunction.keySet()) {
        Pin pin = pinsByFunction.get(pinName);
        String useDescription = pin.getPinUseDescription();
        if (useDescription.isEmpty()) {
            useDescription = "-";
        }
        Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
        MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
        String signalList;
        if (mappedSignal == null) {
            signalList = "-";
        } else {
            signalList = mappedSignal.getSignalList();
        }
        writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
    }
    writer.write(TABLE_CLOSE);
    writer.write(DOCUMENTATION_CLOSE);
    writer.flush();
}
Also used : MuxSelection(net.sourceforge.usbdm.deviceEditor.information.MuxSelection) Pin(net.sourceforge.usbdm.deviceEditor.information.Pin) TreeMap(java.util.TreeMap) MappingInfo(net.sourceforge.usbdm.deviceEditor.information.MappingInfo)

Example 3 with MappingInfo

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

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

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

the class DeviceSignalsModel method createModels.

private void createModels(DeviceInfo fDeviceInfo) {
    fMappingInfos = new ArrayList<MappingInfo>();
    final ArrayList<PinCategory> categories = new ArrayList<PinCategory>();
    // Construct categories
    for (char c = 'A'; c <= 'I'; c++) {
        categories.add(new PinCategory("Port " + c, "PT" + c + ".*"));
    }
    categories.add(new PinCategory("Power", "((VDD|VSS|VREGIN|VBAT|VOUT|(VREF(H|L)))).*"));
    categories.add(new PinCategory("Miscellaneous", ".*"));
    // Group pins into categories
    for (String pName : fDeviceInfo.getPins().keySet()) {
        Pin pinInformation = fDeviceInfo.getPins().get(pName);
        if (pinInformation.isAvailableInPackage()) {
            // Only add if available in package
            for (PinCategory category : categories) {
                if (category.tryAdd(pinInformation)) {
                    break;
                }
            }
        }
    }
    for (PinCategory pinCategory : categories) {
        if (pinCategory.getPins().isEmpty()) {
            continue;
        }
        CategoryModel categoryModel = new CategoryModel(this, pinCategory.getName(), "");
        for (Pin pinInformation : pinCategory.getPins()) {
            new PinModel(categoryModel, pinInformation);
            for (MappingInfo mappingInfo : pinInformation.getMappableSignals().values()) {
                if (mappingInfo.getMux() == MuxSelection.fixed) {
                    continue;
                }
                if (mappingInfo.getMux() == MuxSelection.unassigned) {
                    continue;
                }
                if (mappingInfo.getSignals().get(0) == Signal.DISABLED_SIGNAL) {
                    continue;
                }
                fMappingInfos.add(mappingInfo);
            }
        }
    }
}
Also used : Pin(net.sourceforge.usbdm.deviceEditor.information.Pin) ArrayList(java.util.ArrayList) MappingInfo(net.sourceforge.usbdm.deviceEditor.information.MappingInfo) PinCategory(net.sourceforge.usbdm.deviceEditor.model.ModelFactory.PinCategory)

Aggregations

MappingInfo (net.sourceforge.usbdm.deviceEditor.information.MappingInfo)8 Pin (net.sourceforge.usbdm.deviceEditor.information.Pin)5 MuxSelection (net.sourceforge.usbdm.deviceEditor.information.MuxSelection)4 Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)4 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)1 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)1 DevicePackage (net.sourceforge.usbdm.deviceEditor.information.DevicePackage)1 Peripheral (net.sourceforge.usbdm.deviceEditor.information.Peripheral)1 InfoTable (net.sourceforge.usbdm.deviceEditor.information.Peripheral.InfoTable)1 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)1 PinCategory (net.sourceforge.usbdm.deviceEditor.model.ModelFactory.PinCategory)1 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1