Search in sources :

Example 16 with NetlistComponent

use of com.bfh.logisim.designrulecheck.NetlistComponent in project logisim-evolution by reds-heig.

the class CircuitHDLGeneratorFactory method GetPortMap.

@Override
public SortedMap<String, String> GetPortMap(Netlist Nets, NetlistComponent ComponentInfo, FPGAReport Reporter, String HDLType) {
    SortedMap<String, String> PortMap = new TreeMap<String, String>();
    if (ComponentInfo != null) {
        SubcircuitFactory sub = (SubcircuitFactory) ComponentInfo.GetComponent().getFactory();
        Netlist MyNetList = sub.getSubcircuit().getNetList();
        int NrOfClockTrees = MyNetList.NumberOfClockTrees();
        int NrOfInputBubbles = MyNetList.NumberOfInputBubbles();
        int NrOfOutputBubbles = MyNetList.NumberOfOutputBubbles();
        int NrOfInputPorts = MyNetList.NumberOfInputPorts();
        int NrOfInOutPorts = MyNetList.NumberOfInOutPorts();
        int NrOfOutputPorts = MyNetList.NumberOfOutputPorts();
        /* First we instantiate the Clock tree busses when present */
        for (int i = 0; i < NrOfClockTrees; i++) {
            PortMap.put(ClockTreeName + Integer.toString(i), ClockTreeName + Integer.toString(i));
        }
        if (MyNetList.RequiresGlobalClockConnection()) {
            PortMap.put(TickComponentHDLGeneratorFactory.FPGAClock, TickComponentHDLGeneratorFactory.FPGAClock);
        }
        if (NrOfInputBubbles > 0) {
            PortMap.put(HDLGeneratorFactory.LocalInputBubbleBusname, HDLGeneratorFactory.LocalInputBubbleBusname + GetBubbleIndex(ComponentInfo, HDLType, true));
        }
        if (NrOfOutputBubbles > 0) {
            PortMap.put(HDLGeneratorFactory.LocalOutputBubbleBusname, HDLGeneratorFactory.LocalOutputBubbleBusname + GetBubbleIndex(ComponentInfo, HDLType, false));
        }
        if (NrOfInputPorts > 0) {
            for (int i = 0; i < NrOfInputPorts; i++) {
                NetlistComponent selected = MyNetList.GetInputPin(i);
                if (selected != null) {
                    String PinLabel = CorrectLabel.getCorrectLabel(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                    int endid = Nets.GetEndIndex(ComponentInfo, PinLabel, false);
                    if (endid < 0) {
                        Reporter.AddFatalError("INTERNAL ERROR! Could not find the end-index of a sub-circuit component : '" + PinLabel + "'");
                    } else {
                        PortMap.putAll(GetNetMap(PinLabel, true, ComponentInfo, endid, Reporter, HDLType, Nets));
                    }
                }
            }
        }
        if (NrOfInOutPorts > 0) {
            for (int i = 0; i < NrOfInOutPorts; i++) {
                NetlistComponent selected = MyNetList.GetInOutPin(i);
                if (selected != null) {
                    String PinLabel = CorrectLabel.getCorrectLabel(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                    int endid = Nets.GetEndIndex(ComponentInfo, PinLabel, false);
                    if (endid < 0) {
                        Reporter.AddFatalError("INTERNAL ERROR! Could not find the end-index of a sub-circuit component : '" + PinLabel + "'");
                    } else {
                        PortMap.putAll(GetNetMap(PinLabel, true, ComponentInfo, endid, Reporter, HDLType, Nets));
                    }
                }
            }
        }
        if (NrOfOutputPorts > 0) {
            for (int i = 0; i < NrOfOutputPorts; i++) {
                NetlistComponent selected = MyNetList.GetOutputPin(i);
                if (selected != null) {
                    String PinLabel = CorrectLabel.getCorrectLabel(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                    int endid = Nets.GetEndIndex(ComponentInfo, PinLabel, true);
                    if (endid < 0) {
                        Reporter.AddFatalError("INTERNAL ERROR! Could not find the end-index of a sub-circuit component : '" + PinLabel + "'");
                    } else {
                        PortMap.putAll(GetNetMap(PinLabel, true, ComponentInfo, endid, Reporter, HDLType, Nets));
                    }
                }
            }
        }
    } else {
        int NrOfClockTrees = Nets.NumberOfClockTrees();
        int NrOfInputBubbles = Nets.NumberOfInputBubbles();
        int NrOfOutputBubbles = Nets.NumberOfOutputBubbles();
        int NrOfInputPorts = Nets.NumberOfInputPorts();
        int NrOfInOutPorts = Nets.NumberOfInOutPorts();
        int NrOfOutputPorts = Nets.NumberOfOutputPorts();
        for (int i = 0; i < NrOfClockTrees; i++) {
            PortMap.put(ClockTreeName + Integer.toString(i), "s_" + ClockTreeName + Integer.toString(i));
        }
        if (Nets.RequiresGlobalClockConnection()) {
            PortMap.put(TickComponentHDLGeneratorFactory.FPGAClock, TickComponentHDLGeneratorFactory.FPGAClock);
        }
        if (NrOfInputBubbles > 0) {
            PortMap.put(HDLGeneratorFactory.LocalInputBubbleBusname, "s_LOGISIM_INPUT_BUBBLES");
        }
        if (NrOfOutputBubbles > 0) {
            PortMap.put(HDLGeneratorFactory.LocalOutputBubbleBusname, "s_LOGISIM_OUTPUT_BUBBLES");
        }
        if (NrOfInputPorts > 0) {
            for (int i = 0; i < NrOfInputPorts; i++) {
                NetlistComponent selected = Nets.GetInputPin(i);
                if (selected != null) {
                    if (selected.GetComponent().getFactory() instanceof ReptarLocalBus) {
                        MappableResourcesContainer mapInfo = ((ReptarLocalBus) selected.GetComponent().getFactory()).getMapInfo();
                        int start = mapInfo.GetFPGAInputPinId(mapInfo.currentBoardName + ":/" + selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                        for (int j = 0; j < 13; j++) {
                            PortMap.put(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL) + "_i(" + j + ")", FPGAInputPinName + "_" + (start + j));
                        }
                    } else {
                        String PinLabel = CorrectLabel.getCorrectLabel(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                        PortMap.put(PinLabel, "s_" + PinLabel);
                    }
                }
            }
        }
        if (NrOfInOutPorts > 0) {
            for (int i = 0; i < NrOfInOutPorts; i++) {
                NetlistComponent selected = Nets.GetInOutPin(i);
                if (selected != null) {
                    if (selected.GetComponent().getFactory() instanceof PortIO) {
                        ArrayList<String> name = new ArrayList<String>();
                        MappableResourcesContainer mapInfo = ((PortIO) selected.GetComponent().getFactory()).getMapInfo();
                        int start = mapInfo.GetFPGAInOutPinId(mapInfo.currentBoardName + ":/" + selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                        int k = 0;
                        name.add(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                        for (int j = selected.GetGlobalBubbleId(name).GetInOutStartIndex(); j <= selected.GetGlobalBubbleId(name).GetInOutEndIndex(); j++) {
                            PortMap.put(LocalInOutBubbleBusname + "(" + j + ")", FPGAInOutPinName + "_" + (start + k));
                            k++;
                        }
                    } else if (selected.GetComponent().getFactory() instanceof ReptarLocalBus) {
                        ArrayList<String> name = new ArrayList<String>();
                        name.add(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                        for (int j = selected.GetGlobalBubbleId(name).GetInOutStartIndex(); j <= selected.GetGlobalBubbleId(name).GetInOutEndIndex(); j++) {
                            PortMap.put(LocalInOutBubbleBusname + "(" + j + ")", FPGAInOutPinName + "_" + j);
                        }
                    } else {
                        String PinLabel = CorrectLabel.getCorrectLabel(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                        PortMap.put(PinLabel, "s_" + PinLabel);
                    }
                }
            }
        }
        if (NrOfOutputPorts > 0) {
            for (int i = 0; i < NrOfOutputPorts; i++) {
                NetlistComponent selected = Nets.GetOutputPin(i);
                if (selected != null) {
                    if (selected.GetComponent().getFactory() instanceof ReptarLocalBus) {
                        ArrayList<String> name = new ArrayList<String>();
                        name.add(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                        int k = 0;
                        for (int j = selected.GetGlobalBubbleId(name).GetOutputStartIndex(); j <= selected.GetGlobalBubbleId(name).GetOutputEndIndex(); j++) {
                            PortMap.put(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL) + "_o(" + k + ")", "FPGA_LB_OUT_" + k);
                            k++;
                        }
                    // for (int j =
                    // selected.GetGlobalBubbleId(name).GetOutputStartIndex();
                    // j <=
                    // selected.GetGlobalBubbleId(name).GetOutputEndIndex();
                    // j++) {
                    // PortMap.put(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL)
                    // + "_o", FPGAOutputPinName + "_" + j);
                    // }
                    } else {
                        String PinLabel = CorrectLabel.getCorrectLabel(selected.GetComponent().getAttributeSet().getValue(StdAttr.LABEL));
                        PortMap.put(PinLabel, "s_" + PinLabel);
                    }
                }
            }
        }
    }
    return PortMap;
}
Also used : PortIO(com.cburch.logisim.std.io.PortIO) ReptarLocalBus(com.cburch.logisim.std.io.ReptarLocalBus) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) MappableResourcesContainer(com.bfh.logisim.fpgagui.MappableResourcesContainer) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ConnectionPoint(com.bfh.logisim.designrulecheck.ConnectionPoint) Netlist(com.bfh.logisim.designrulecheck.Netlist)

Example 17 with NetlistComponent

use of com.bfh.logisim.designrulecheck.NetlistComponent in project logisim-evolution by reds-heig.

the class ToplevelHDLGeneratorFactory method GetModuleFunctionality.

@Override
public ArrayList<String> GetModuleFunctionality(Netlist TheNetlist, AttributeSet attrs, FPGAReport Reporter, String HDLType) {
    ArrayList<String> Contents = new ArrayList<String>();
    int NrOfClockTrees = TheNetlist.NumberOfClockTrees();
    String Preamble = (HDLType.equals(VHDL)) ? "" : "assign ";
    String BracketOpen = (HDLType.equals(VHDL)) ? "(" : "[";
    String BracketClose = (HDLType.equals(VHDL)) ? ")" : "]";
    String AssignOperator = (HDLType.equals(VHDL)) ? " <= " : " = ";
    String NotOperator = (HDLType.equals(VHDL)) ? "NOT " : "~";
    StringBuffer Temp = new StringBuffer();
    /* First we process all pins */
    Contents.addAll(MakeRemarkBlock("Here all signal adaptations are performed", 3, HDLType));
    for (ArrayList<String> CompId : MyIOComponents.GetComponents()) {
        if (MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof Pin) {
            Component ThisPin = MyIOComponents.GetComponent(CompId).GetComponent();
            ArrayList<String> MyMaps = MyIOComponents.GetMapNamesList(CompId);
            if (MyMaps == null) {
                Reporter.AddFatalError("Component has no map information, bizar! " + CompId.toString());
                return Contents;
            }
            int PinPinId = 0;
            for (int MapOffset = 0; MapOffset < MyMaps.size(); MapOffset++) {
                String map = MyMaps.get(MapOffset);
                int InputId = MyIOComponents.GetFPGAInputPinId(map);
                int OutputId = MyIOComponents.GetFPGAOutputPinId(map);
                int NrOfPins = MyIOComponents.GetNrOfPins(map);
                boolean Invert = MyIOComponents.RequiresToplevelInversion(CompId, map);
                for (int PinId = 0; PinId < NrOfPins; PinId++) {
                    Temp.setLength(0);
                    Temp.append("   " + Preamble);
                    if (InputId >= 0) {
                        Temp.append("s_" + CorrectLabel.getCorrectLabel(ThisPin.getAttributeSet().getValue(StdAttr.LABEL)));
                        if (ThisPin.getEnd(0).getWidth().getWidth() > 1) {
                            Temp.append(BracketOpen + PinPinId + BracketClose);
                        }
                        PinPinId++;
                        Temp.append(AssignOperator);
                        if (Invert) {
                            Temp.append(NotOperator);
                        }
                        Temp.append(HDLGeneratorFactory.FPGAInputPinName);
                        Temp.append("_" + Integer.toString(InputId + PinId));
                        Temp.append(";");
                        Contents.add(Temp.toString());
                    }
                    if (OutputId >= 0) {
                        Temp.append(HDLGeneratorFactory.FPGAOutputPinName);
                        Temp.append("_" + Integer.toString(OutputId + PinId));
                        Temp.append(AssignOperator);
                        if (Invert) {
                            Temp.append(NotOperator);
                        }
                        Temp.append("s_" + CorrectLabel.getCorrectLabel(ThisPin.getAttributeSet().getValue(StdAttr.LABEL)));
                        if (ThisPin.getEnd(0).getWidth().getWidth() > 1) {
                            Temp.append(BracketOpen + PinPinId + BracketClose);
                        }
                        PinPinId++;
                        Temp.append(";");
                        Contents.add(Temp.toString());
                    }
                }
            }
        }
    }
    /* Now we process the bubbles */
    Contents.addAll(MakeRemarkBlock("Here all inlined adaptations are performed", 3, HDLType));
    for (ArrayList<String> CompId : MyIOComponents.GetComponents()) {
        if (!(MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof Pin) && !(MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof PortIO) && !(MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof ReptarLocalBus)) {
            HDLGeneratorFactory Generator = MyIOComponents.GetComponent(CompId).GetComponent().getFactory().getHDLGenerator(HDLType, MyIOComponents.GetComponent(CompId).GetComponent().getAttributeSet());
            if (Generator == null) {
                Reporter.AddError("No generator for component " + CompId.toString());
            } else {
                Contents.addAll(Generator.GetInlinedCode(HDLType, CompId, Reporter, MyIOComponents));
            }
        } else if (MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof ReptarLocalBus) {
            ((ReptarLocalBus) MyIOComponents.GetComponent(CompId).GetComponent().getFactory()).setMapInfo(MyIOComponents);
        } else if (MyIOComponents.GetComponent(CompId).GetComponent().getFactory() instanceof PortIO) {
            ((PortIO) MyIOComponents.GetComponent(CompId).GetComponent().getFactory()).setMapInfo(MyIOComponents);
        }
    }
    if (NrOfClockTrees > 0) {
        Contents.addAll(MakeRemarkBlock("Here the clock tree components are defined", 3, HDLType));
        TickComponentHDLGeneratorFactory Ticker = new TickComponentHDLGeneratorFactory(FpgaClockFrequency, TickFrequency);
        Contents.addAll(Ticker.GetComponentMap(null, (long) 0, null, Reporter, "", HDLType));
        long index = 0;
        for (Component Clockgen : TheNetlist.GetAllClockSources()) {
            NetlistComponent ThisClock = new NetlistComponent(Clockgen);
            Contents.addAll(Clockgen.getFactory().getHDLGenerator(HDLType, ThisClock.GetComponent().getAttributeSet()).GetComponentMap(TheNetlist, index++, ThisClock, Reporter, "Bla", HDLType));
        }
    }
    Contents.add("");
    /* Here the map is performed */
    Contents.addAll(MakeRemarkBlock("Here the toplevel component is connected", 3, HDLType));
    CircuitHDLGeneratorFactory DUT = new CircuitHDLGeneratorFactory(MyCircuit);
    Contents.addAll(DUT.GetComponentMap(TheNetlist, (long) 0, null, Reporter, CorrectLabel.getCorrectLabel(MyCircuit.getName()), HDLType));
    return Contents;
}
Also used : ArrayList(java.util.ArrayList) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) PortIO(com.cburch.logisim.std.io.PortIO) Pin(com.cburch.logisim.std.wiring.Pin) ReptarLocalBus(com.cburch.logisim.std.io.ReptarLocalBus) ClockHDLGeneratorFactory(com.cburch.logisim.std.wiring.ClockHDLGeneratorFactory) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) Component(com.cburch.logisim.comp.Component)

Example 18 with NetlistComponent

use of com.bfh.logisim.designrulecheck.NetlistComponent in project logisim-evolution by reds-heig.

the class PortHDLGeneratorFactory method GetEntity.

// #2
@Override
public ArrayList<String> GetEntity(Netlist TheNetlist, AttributeSet attrs, String ComponentName, FPGAReport Reporter, String HDLType) {
    NetlistComponent ComponentInfo = null;
    compMap.put(ComponentName, new HashMap<Integer, InOutMap>());
    for (NetlistComponent comp : TheNetlist.GetNormalComponents()) {
        if (comp.GetComponent().getAttributeSet().equals(attrs)) {
            ComponentInfo = comp;
            break;
        }
    }
    int mapIdx = 0;
    for (int portNr = 0; portNr < ComponentInfo.GetComponent().getEnds().size(); portNr++) {
        Location splitterLoc = findEndConnection(ComponentInfo.GetComponent().getEnd(portNr).getLocation(), TheNetlist.getCircuit());
        if (splitterLoc == null) {
            Reporter.AddFatalError("Found 0, 2 or more connections on PortIO's splitter (" + ComponentName + ")");
            return null;
        }
        for (Splitter split : TheNetlist.getSplitters()) {
            if (split.getLocation().equals(splitterLoc)) {
                // trouve le
                // premier
                // splitter du
                // Port
                compMap.get(ComponentName).put(mapIdx, new InOutMap(Type.INOUT, new Point(0, split.GetEndpoints().length - 1), portNr));
                int splitPortNr = 0;
                for (EndData end : split.getEnds()) {
                    if (!end.getLocation().equals(splitterLoc)) {
                        // parcours
                        // les
                        // sortie
                        // du
                        // splitter
                        Location compLoc = findEndConnection(end.getLocation(), TheNetlist.getCircuit());
                        if (compLoc == null) {
                            Reporter.AddFatalError("Found 0, 2 or more connections on PortIO's splitter (" + ComponentName + ")");
                            return null;
                        }
                        for (Component comp : TheNetlist.getCircuit().getNonWires(compLoc)) {
                            // splitter
                            for (EndData port : comp.getEnds()) {
                                if (port.getLocation().equals(compLoc)) {
                                    // splitter
                                    if (!(comp instanceof Splitter) && !(comp instanceof PortIO)) {
                                        if (port.isInput()) {
                                            compMap.get(ComponentName).put(mapIdx, new InOutMap(Type.OUT, getBitRange(split.GetEndpoints(), splitPortNr), portNr));
                                        } else if (port.isOutput()) {
                                            compMap.get(ComponentName).put(mapIdx, new InOutMap(Type.IN, getBitRange(split.GetEndpoints(), splitPortNr), portNr));
                                        }
                                    } else {
                                        Reporter.AddFatalError("Cannot connect PortIO's splitter to other splitter or PortIO (" + ComponentName + ")");
                                        return null;
                                    }
                                }
                            }
                        }
                    }
                    mapIdx++;
                    splitPortNr++;
                }
            }
        }
    }
    ArrayList<String> Contents = new ArrayList<String>();
    Contents.addAll(FileWriter.getGenerateRemark(ComponentName, VHDL, TheNetlist.projName()));
    Contents.addAll(FileWriter.getExtendedLibrary());
    Contents.add("ENTITY " + ComponentName + " IS");
    Contents.add("   PORT ( ");
    for (int i = 0; i < compMap.get(ComponentName).size(); i++) {
        String line = "          ";
        switch(compMap.get(ComponentName).get(i).getType()) {
            case IN:
                line += inBusName + "_" + i + "  : IN ";
                break;
            case OUT:
                line += outBusName + "_" + i + "  : OUT ";
                break;
            case INOUT:
                line += inOutBusName + "_" + i + "  : INOUT ";
                break;
            default:
                Reporter.AddFatalError("Found component of unknown type (" + compMap.get(ComponentName).get(i).toString() + ")");
        }
        if (compMap.get(ComponentName).get(i).getSize() == 1) {
            line += "std_logic";
        } else {
            line += "std_logic_vector (" + (compMap.get(ComponentName).get(i).getSize() - 1) + " DOWNTO 0)";
        }
        if (i == (compMap.get(ComponentName).size() - 1)) {
            line += ")";
        }
        line += ";";
        Contents.add(line);
    }
    Contents.add("END " + ComponentName + ";");
    Contents.add("");
    return Contents;
}
Also used : EndData(com.cburch.logisim.comp.EndData) Splitter(com.cburch.logisim.circuit.Splitter) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) ArrayList(java.util.ArrayList) Point(java.awt.Point) Point(java.awt.Point) NetlistComponent(com.bfh.logisim.designrulecheck.NetlistComponent) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Aggregations

NetlistComponent (com.bfh.logisim.designrulecheck.NetlistComponent)18 ArrayList (java.util.ArrayList)6 ConnectionPoint (com.bfh.logisim.designrulecheck.ConnectionPoint)5 ReptarLocalBus (com.cburch.logisim.std.io.ReptarLocalBus)5 ClockHDLGeneratorFactory (com.cburch.logisim.std.wiring.ClockHDLGeneratorFactory)4 PortIO (com.cburch.logisim.std.io.PortIO)3 TreeMap (java.util.TreeMap)3 Netlist (com.bfh.logisim.designrulecheck.Netlist)2 FPGAIOInformationContainer (com.bfh.logisim.fpgaboardeditor.FPGAIOInformationContainer)2 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)2 Component (com.cburch.logisim.comp.Component)2 Pin (com.cburch.logisim.std.wiring.Pin)2 BubbleInformationContainer (com.bfh.logisim.designrulecheck.BubbleInformationContainer)1 BoardRectangle (com.bfh.logisim.fpgaboardeditor.BoardRectangle)1 IOComponentTypes (com.bfh.logisim.fpgaboardeditor.FPGAIOInformationContainer.IOComponentTypes)1 MappableResourcesContainer (com.bfh.logisim.fpgagui.MappableResourcesContainer)1 Splitter (com.cburch.logisim.circuit.Splitter)1 EndData (com.cburch.logisim.comp.EndData)1 Location (com.cburch.logisim.data.Location)1 DipSwitch (com.cburch.logisim.std.io.DipSwitch)1