Search in sources :

Example 11 with Pin

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

the class LlwuValidate method doPinNames.

/**
 * Extract pin names and create LLWU pin and peripheral C enum tables.<br>
 * The description for pins is also annotated with the pin number found or (Reserved)<br>
 *
 * Tables are added to the following Peripheral Variables:
 *  <li>LlwuPins
 *  <li>LlwuPeripherals
 */
private void doPinNames() {
    final String RESERVED = "Reserved";
    if (donePinNames) {
        return;
    }
    donePinNames = true;
    StringBuilder sb = new StringBuilder();
    sb.append("/**\n" + " * LLWU pin sources\n" + " */\n" + "enum LlwuPin : uint32_t {\n");
    InfoTable pinTable = getPeripheral().getSignalTables().get(0);
    for (int index = 0; index < 32; index++) {
        String choiceName = "llwu_pe" + ((index / 4) + 1) + "_wupe" + index;
        ChoiceVariable choiceVar = safeGetChoiceVariable(choiceName);
        if (choiceVar == null) {
            continue;
        }
        String llwuPinName;
        if (index >= pinTable.table.size()) {
            // Pin not in table (doesn't exist)
            choiceVar.enable(false);
            llwuPinName = RESERVED;
        } else {
            // Look up possible pin mapping in table
            Signal signal = pinTable.table.elementAt(index);
            Pin mappablePin = null;
            if (signal != null) {
                TreeSet<MappingInfo> pinMappings = signal.getPinMapping();
                for (MappingInfo pinMapping : pinMappings) {
                    if (pinMapping.getMux() == MuxSelection.mux1) {
                        mappablePin = pinMapping.getPin();
                    }
                }
            }
            if (mappablePin == null) {
                // No mappable pin
                choiceVar.enable(false);
                llwuPinName = RESERVED;
            } else {
                // Mappable pin
                choiceVar.enable(true);
                llwuPinName = mappablePin.getName();
            }
        }
        if (llwuPinName != RESERVED) {
            String llwuPinLine = String.format("   LlwuPin_%-15s = %2d, //!< Wake-up pin LLWU_P%d\n", capitalCase(llwuPinName), index, index);
            sb.append(llwuPinLine);
        }
        choiceVar.setDescription(choiceVar.getDescription() + " - " + llwuPinName);
    }
    sb.append("};\n\n");
    StringVariable llwuPinsVar = new StringVariable("LlwuPins", getPeripheral().makeKey("LlwuPins"));
    llwuPinsVar.setValue(sb.toString());
    llwuPinsVar.setDerived(true);
    getPeripheral().addVariable(llwuPinsVar);
    sb = new StringBuilder();
    sb.append("/**\n" + " * LLWU peripheral sources\n" + " */\n" + "enum LlwuPeripheral : uint32_t {\n");
    for (int index = 0; index <= 7; index++) {
        String choiceName = "llwu_me_wume" + index;
        BooleanVariable choiceVar = safeGetBooleanVariable(choiceName);
        String llwuPeripheralName;
        if (choiceVar != null) {
            llwuPeripheralName = choiceVar.getDescription();
            String llwuPeripheralLine = String.format("   LlwuPeripheral_%-15s = (1<<%d), //!< Wake-up peripheral LLWU_M%dIF\n", capitalCase(llwuPeripheralName), index, index);
            sb.append(llwuPeripheralLine);
        }
    }
    sb.append("};\n\n");
    StringVariable llwuPeripheralsVar = new StringVariable("LlwuPeripherals", getPeripheral().makeKey("LlwuPeripherals"));
    llwuPeripheralsVar.setValue(sb.toString());
    llwuPeripheralsVar.setDerived(true);
    getPeripheral().addVariable(llwuPeripheralsVar);
}
Also used : Signal(net.sourceforge.usbdm.deviceEditor.information.Signal) Pin(net.sourceforge.usbdm.deviceEditor.information.Pin) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) InfoTable(net.sourceforge.usbdm.deviceEditor.information.Peripheral.InfoTable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable) MappingInfo(net.sourceforge.usbdm.deviceEditor.information.MappingInfo)

Aggregations

Pin (net.sourceforge.usbdm.deviceEditor.information.Pin)11 MappingInfo (net.sourceforge.usbdm.deviceEditor.information.MappingInfo)5 Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)5 MuxSelection (net.sourceforge.usbdm.deviceEditor.information.MuxSelection)4 DevicePackage (net.sourceforge.usbdm.deviceEditor.information.DevicePackage)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)1 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)1 DeviceVariantInformation (net.sourceforge.usbdm.deviceEditor.information.DeviceVariantInformation)1 PcrInitialiser (net.sourceforge.usbdm.deviceEditor.information.PcrInitialiser)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