Search in sources :

Example 1 with InfoTable

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

BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)1 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)1 MappingInfo (net.sourceforge.usbdm.deviceEditor.information.MappingInfo)1 InfoTable (net.sourceforge.usbdm.deviceEditor.information.Peripheral.InfoTable)1 Pin (net.sourceforge.usbdm.deviceEditor.information.Pin)1 Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)1 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)1