Search in sources :

Example 1 with ConnectionPoint

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

the class AbstractHDLGeneratorFactory method GetNetMap.

public Map<String, String> GetNetMap(String SourceName, boolean FloatingPinTiedToGround, NetlistComponent comp, int EndIndex, FPGAReport Reporter, String HDLType, Netlist TheNets) {
    Map<String, String> NetMap = new HashMap<String, String>();
    if ((EndIndex < 0) || (EndIndex >= comp.NrOfEnds())) {
        Reporter.AddFatalError("INTERNAL ERROR: Component tried to index non-existing SolderPoint");
        return NetMap;
    }
    ConnectionEnd ConnectionInformation = comp.getEnd(EndIndex);
    boolean IsOutput = ConnectionInformation.IsOutputEnd();
    int NrOfBits = ConnectionInformation.NrOfBits();
    if (NrOfBits == 1) {
        /* Here we have the easy case, just a single bit net */
        NetMap.put(SourceName, GetNetName(comp, EndIndex, FloatingPinTiedToGround, HDLType, TheNets));
    } else {
        /*
			 * Here we have the more difficult case, it is a bus that needs to
			 * be mapped
			 */
        /* First we check if the bus has a connection */
        boolean Connected = false;
        for (int i = 0; i < NrOfBits; i++) {
            if (ConnectionInformation.GetConnection((byte) i).GetParrentNet() != null) {
                Connected = true;
            }
        }
        if (!Connected) {
            /* Here is the easy case, the bus is unconnected */
            if (IsOutput) {
                if (HDLType.equals(VHDL)) {
                    NetMap.put(SourceName, "OPEN");
                } else {
                    NetMap.put(SourceName, "");
                }
            } else {
                NetMap.put(SourceName, GetZeroVector(NrOfBits, FloatingPinTiedToGround, HDLType));
            }
        } else {
            /*
				 * There are connections, we detect if it is a continues bus
				 * connection
				 */
            if (TheNets.IsContinuesBus(comp, EndIndex)) {
                /* Another easy case, the continues bus connection */
                NetMap.put(SourceName, GetBusNameContinues(comp, EndIndex, HDLType, TheNets));
            } else {
                /* The last case, we have to enumerate through each bit */
                if (HDLType.equals(VHDL)) {
                    StringBuffer SourceNetName = new StringBuffer();
                    for (int i = 0; i < NrOfBits; i++) {
                        /* First we build the Line information */
                        SourceNetName.setLength(0);
                        SourceNetName.append(SourceName + "(" + Integer.toString(i) + ") ");
                        ConnectionPoint SolderPoint = ConnectionInformation.GetConnection((byte) i);
                        if (SolderPoint.GetParrentNet() == null) {
                            /* The net is not connected */
                            if (IsOutput) {
                                NetMap.put(SourceNetName.toString(), "OPEN");
                            } else {
                                NetMap.put(SourceNetName.toString(), GetZeroVector(1, FloatingPinTiedToGround, HDLType));
                            }
                        } else {
                            /*
								 * The net is connected, we have to find out if
								 * the connection is to a bus or to a normal net
								 */
                            if (SolderPoint.GetParrentNet().BitWidth() == 1) {
                                /* The connection is to a Net */
                                NetMap.put(SourceNetName.toString(), NetName + Integer.toString(TheNets.GetNetId(SolderPoint.GetParrentNet())));
                            } else {
                                /* The connection is to an entry of a bus */
                                NetMap.put(SourceNetName.toString(), BusName + Integer.toString(TheNets.GetNetId(SolderPoint.GetParrentNet())) + "(" + Integer.toString(SolderPoint.GetParrentNetBitIndex()) + ")");
                            }
                        }
                    }
                } else {
                    ArrayList<String> SeperateSignals = new ArrayList<String>();
                    /*
						 * First we build an array with all the signals that
						 * need to be concatenated
						 */
                    for (int i = 0; i < NrOfBits; i++) {
                        ConnectionPoint SolderPoint = ConnectionInformation.GetConnection((byte) i);
                        if (SolderPoint.GetParrentNet() == null) {
                            /* this entry is not connected */
                            if (IsOutput) {
                                SeperateSignals.add("1'bz");
                            } else {
                                SeperateSignals.add(GetZeroVector(1, FloatingPinTiedToGround, HDLType));
                            }
                        } else {
                            /*
								 * The net is connected, we have to find out if
								 * the connection is to a bus or to a normal net
								 */
                            if (SolderPoint.GetParrentNet().BitWidth() == 1) {
                                /* The connection is to a Net */
                                SeperateSignals.add(NetName + Integer.toString(TheNets.GetNetId(SolderPoint.GetParrentNet())));
                            } else {
                                /* The connection is to an entry of a bus */
                                SeperateSignals.add(BusName + Integer.toString(TheNets.GetNetId(SolderPoint.GetParrentNet())) + "[" + Integer.toString(SolderPoint.GetParrentNetBitIndex()) + "]");
                            }
                        }
                    }
                    /* Finally we can put all together */
                    StringBuffer Vector = new StringBuffer();
                    Vector.append("{");
                    for (int i = NrOfBits; i > 0; i++) {
                        Vector.append(SeperateSignals.get(i - 1));
                        if (i != 1) {
                            Vector.append(",");
                        }
                    }
                    Vector.append("}");
                    NetMap.put(SourceName, Vector.toString());
                }
            }
        }
    }
    return NetMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConnectionEnd(com.bfh.logisim.designrulecheck.ConnectionEnd) ConnectionPoint(com.bfh.logisim.designrulecheck.ConnectionPoint) ConnectionPoint(com.bfh.logisim.designrulecheck.ConnectionPoint)

Example 2 with ConnectionPoint

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

the class AbstractHDLGeneratorFactory method GetNetName.

public String GetNetName(NetlistComponent comp, int EndIndex, boolean FloatingNetTiedToGround, String HDLType, Netlist MyNetlist) {
    StringBuffer Contents = new StringBuffer();
    String ZeroValue = (HDLType.equals(VHDL)) ? "'0'" : "1'b0";
    String OneValue = (HDLType.equals(VHDL)) ? "'1'" : "1'b1";
    String BracketOpen = (HDLType.equals(VHDL)) ? "(" : "[";
    String BracketClose = (HDLType.equals(VHDL)) ? ")" : "]";
    String Unconnected = (HDLType.equals(VHDL)) ? "OPEN" : "";
    String FloatingValue = (FloatingNetTiedToGround) ? ZeroValue : OneValue;
    if ((EndIndex >= 0) && (EndIndex < comp.NrOfEnds())) {
        ConnectionEnd ThisEnd = comp.getEnd(EndIndex);
        boolean IsOutput = ThisEnd.IsOutputEnd();
        if (ThisEnd.NrOfBits() == 1) {
            ConnectionPoint SolderPoint = ThisEnd.GetConnection((byte) 0);
            if (SolderPoint.GetParrentNet() == null) {
                /* The net is not connected */
                if (IsOutput) {
                    Contents.append(Unconnected);
                } else {
                    Contents.append(FloatingValue);
                }
            } else {
                /*
					 * The net is connected, we have to find out if the
					 * connection is to a bus or to a normal net
					 */
                if (SolderPoint.GetParrentNet().BitWidth() == 1) {
                    /* The connection is to a Net */
                    Contents.append(NetName + Integer.toString(MyNetlist.GetNetId(SolderPoint.GetParrentNet())));
                } else {
                    /* The connection is to an entry of a bus */
                    Contents.append(BusName + Integer.toString(MyNetlist.GetNetId(SolderPoint.GetParrentNet())) + BracketOpen + Integer.toString(SolderPoint.GetParrentNetBitIndex()) + BracketClose);
                }
            }
        }
    }
    return Contents.toString();
}
Also used : ConnectionEnd(com.bfh.logisim.designrulecheck.ConnectionEnd) ConnectionPoint(com.bfh.logisim.designrulecheck.ConnectionPoint)

Example 3 with ConnectionPoint

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

the class CircuitHDLGeneratorFactory method GetSignalMap.

private String GetSignalMap(String PortName, NetlistComponent comp, int EndIndex, int TabSize, FPGAReport Reporter, String HDLType, Netlist TheNets) {
    StringBuffer Contents = new StringBuffer();
    StringBuffer Source = new StringBuffer();
    StringBuffer Destination = new StringBuffer();
    StringBuffer Tab = new StringBuffer();
    String AssignCommand = (HDLType.equals(VHDL)) ? "" : "assign ";
    String AssignOperator = (HDLType.equals(VHDL)) ? "<= " : "= ";
    String BracketOpen = (HDLType.equals(VHDL)) ? "(" : "[";
    String BracketClose = (HDLType.equals(VHDL)) ? ")" : "]";
    if ((EndIndex < 0) || (EndIndex >= comp.NrOfEnds())) {
        Reporter.AddFatalError("INTERNAL ERROR: Component tried to index non-existing SolderPoint: '" + comp.GetComponent().getAttributeSet().getValue(StdAttr.LABEL) + "'");
        return "";
    }
    for (int i = 0; i < TabSize; i++) {
        Tab.append(" ");
    }
    ConnectionEnd ConnectionInformation = comp.getEnd(EndIndex);
    boolean IsOutput = ConnectionInformation.IsOutputEnd();
    int NrOfBits = ConnectionInformation.NrOfBits();
    if (NrOfBits == 1) {
        /* Here we have the easy case, just a single bit net */
        if (IsOutput) {
            if (!comp.EndIsConnected(EndIndex)) {
                return " ";
            }
            Source.append(PortName);
            Destination.append(GetNetName(comp, EndIndex, true, HDLType, TheNets));
        } else {
            if (!comp.EndIsConnected(EndIndex)) {
                Reporter.AddSevereWarning("Found an unconnected output pin, tied the pin to ground!");
            }
            Source.append(GetNetName(comp, EndIndex, true, HDLType, TheNets));
            Destination.append(PortName);
            if (!comp.EndIsConnected(EndIndex)) {
                return Contents.toString();
            }
        }
        while (Destination.length() < SallignmentSize) {
            Destination.append(" ");
        }
        Contents.append(Tab.toString() + AssignCommand + Destination + AssignOperator + Source + ";");
    } else {
        /*
			 * Here we have the more difficult case, it is a bus that needs to
			 * be mapped
			 */
        /* First we check if the bus has a connection */
        boolean Connected = false;
        for (int i = 0; i < NrOfBits; i++) {
            if (ConnectionInformation.GetConnection((byte) i).GetParrentNet() != null) {
                Connected = true;
            }
        }
        if (!Connected) {
            /* Here is the easy case, the bus is unconnected */
            if (IsOutput) {
                return Contents.toString();
            } else {
                Reporter.AddSevereWarning("Found an unconnected output bus pin, tied all the pin bits to ground!");
            }
            Destination.append(PortName);
            while (Destination.length() < SallignmentSize) {
                Destination.append(" ");
            }
            Contents.append(Tab.toString() + AssignCommand + Destination.toString() + AssignOperator + GetZeroVector(NrOfBits, true, HDLType) + ";");
        } else {
            /*
				 * There are connections, we detect if it is a continues bus
				 * connection
				 */
            if (TheNets.IsContinuesBus(comp, EndIndex)) {
                Destination.setLength(0);
                Source.setLength(0);
                /* Another easy case, the continues bus connection */
                if (IsOutput) {
                    Source.append(PortName);
                    Destination.append(GetBusNameContinues(comp, EndIndex, HDLType, TheNets));
                } else {
                    Destination.append(PortName);
                    Source.append(GetBusNameContinues(comp, EndIndex, HDLType, TheNets));
                }
                while (Destination.length() < SallignmentSize) {
                    Destination.append(" ");
                }
                Contents.append(Tab.toString() + AssignCommand + Destination + AssignOperator + Source + ";");
            } else {
                /* The last case, we have to enumerate through each bit */
                for (int bit = 0; bit < NrOfBits; bit++) {
                    Source.setLength(0);
                    Destination.setLength(0);
                    if (IsOutput) {
                        Source.append(PortName + BracketOpen + Integer.toString(bit) + BracketClose);
                    } else {
                        Destination.append(PortName + BracketOpen + Integer.toString(bit) + BracketClose);
                    }
                    ConnectionPoint SolderPoint = ConnectionInformation.GetConnection((byte) bit);
                    if (SolderPoint.GetParrentNet() == null) {
                        /* The net is not connected */
                        if (IsOutput) {
                            continue;
                        } else {
                            Reporter.AddSevereWarning("Found an unconnected output bus pin, tied bit " + Integer.toString(bit) + " to ground!");
                            Source.append(GetZeroVector(1, true, HDLType));
                        }
                    } else {
                        /*
							 * The net is connected, we have to find out if the
							 * connection is to a bus or to a normal net
							 */
                        if (SolderPoint.GetParrentNet().BitWidth() == 1) {
                            /* The connection is to a Net */
                            if (IsOutput) {
                                Destination.append(NetName + Integer.toString(TheNets.GetNetId(SolderPoint.GetParrentNet())));
                            } else {
                                Source.append(NetName + Integer.toString(TheNets.GetNetId(SolderPoint.GetParrentNet())));
                            }
                        } else {
                            /* The connection is to an entry of a bus */
                            if (IsOutput) {
                                Destination.append(BusName + Integer.toString(TheNets.GetNetId(SolderPoint.GetParrentNet())) + BracketOpen + Integer.toString(SolderPoint.GetParrentNetBitIndex()) + BracketClose);
                            } else {
                                Source.append(BusName + Integer.toString(TheNets.GetNetId(SolderPoint.GetParrentNet())) + BracketOpen + Integer.toString(SolderPoint.GetParrentNetBitIndex()) + BracketClose);
                            }
                        }
                    }
                    while (Destination.length() < SallignmentSize) {
                        Destination.append(" ");
                    }
                    if (bit != 0) {
                        Contents.append("\n");
                    }
                    Contents.append(Tab.toString() + AssignCommand + Destination + AssignOperator + Source + ";");
                }
            }
        }
    }
    return Contents.toString();
}
Also used : ConnectionEnd(com.bfh.logisim.designrulecheck.ConnectionEnd) ConnectionPoint(com.bfh.logisim.designrulecheck.ConnectionPoint) ConnectionPoint(com.bfh.logisim.designrulecheck.ConnectionPoint)

Example 4 with ConnectionPoint

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

the class CircuitHDLGeneratorFactory method GetHDLWiring.

public ArrayList<String> GetHDLWiring(String HDLType, Netlist TheNets) {
    ArrayList<String> Contents = new ArrayList<String>();
    StringBuffer OneLine = new StringBuffer();
    String BracketOpen = (HDLType.equals(VHDL)) ? "(" : "[";
    String BracketClose = (HDLType.equals(VHDL)) ? ")" : "]";
    /* we cycle through all nets with a forcedrootnet annotation */
    for (Net ThisNet : TheNets.GetAllNets()) {
        if (ThisNet.IsForcedRootNet()) {
            /* now we cycle through all the bits */
            for (int bit = 0; bit < ThisNet.BitWidth(); bit++) {
                /* First we perform all source connections */
                for (ConnectionPoint Source : ThisNet.GetSourceNets(bit)) {
                    OneLine.setLength(0);
                    if (ThisNet.isBus()) {
                        OneLine.append(BusName + Integer.toString(TheNets.GetNetId(ThisNet)) + BracketOpen + bit + BracketClose);
                    } else {
                        OneLine.append(NetName + Integer.toString(TheNets.GetNetId(ThisNet)));
                    }
                    while (OneLine.length() < SallignmentSize) {
                        OneLine.append(" ");
                    }
                    if (HDLType.equals(VHDL)) {
                        String line = "   " + OneLine.toString() + "<= " + BusName + Integer.toString(TheNets.GetNetId(Source.GetParrentNet())) + BracketOpen + Source.GetParrentNetBitIndex() + BracketClose + ";";
                        if (!Contents.contains(line))
                            Contents.add(line);
                    } else {
                        String line = "   assign " + OneLine.toString() + "= " + BusName + Integer.toString(TheNets.GetNetId(Source.GetParrentNet())) + BracketOpen + Source.GetParrentNetBitIndex() + BracketClose + ";";
                        if (!Contents.contains(line))
                            Contents.add(line);
                    }
                }
                /* Next we perform all sink connections */
                for (ConnectionPoint Source : ThisNet.GetSinkNets(bit)) {
                    OneLine.setLength(0);
                    OneLine.append(BusName + Integer.toString(TheNets.GetNetId(Source.GetParrentNet())) + BracketOpen + Source.GetParrentNetBitIndex() + BracketClose);
                    while (OneLine.length() < SallignmentSize) {
                        OneLine.append(" ");
                    }
                    if (HDLType.equals(VHDL)) {
                        OneLine.append("<= ");
                    } else {
                        OneLine.append("= ");
                    }
                    if (ThisNet.isBus()) {
                        OneLine.append(BusName + Integer.toString(TheNets.GetNetId(ThisNet)) + BracketOpen + bit + BracketClose);
                    } else {
                        OneLine.append(NetName + Integer.toString(TheNets.GetNetId(ThisNet)));
                    }
                    if (HDLType.equals(VHDL)) {
                        String line = "   " + OneLine.toString() + ";";
                        if (!Contents.contains(line))
                            Contents.add(line);
                    } else {
                        String line = "   assign " + OneLine.toString() + ";";
                        if (!Contents.contains(line))
                            Contents.add(line);
                    }
                }
            }
        }
    }
    return Contents;
}
Also used : ArrayList(java.util.ArrayList) Net(com.bfh.logisim.designrulecheck.Net) ConnectionPoint(com.bfh.logisim.designrulecheck.ConnectionPoint) ConnectionPoint(com.bfh.logisim.designrulecheck.ConnectionPoint)

Aggregations

ConnectionPoint (com.bfh.logisim.designrulecheck.ConnectionPoint)4 ConnectionEnd (com.bfh.logisim.designrulecheck.ConnectionEnd)3 ArrayList (java.util.ArrayList)2 Net (com.bfh.logisim.designrulecheck.Net)1 HashMap (java.util.HashMap)1