use of com.bfh.logisim.fpgaboardeditor.FPGAIOInformationContainer in project logisim-evolution by reds-heig.
the class MappableResourcesContainer method BuildIOMappingInformation.
public void BuildIOMappingInformation() {
if (fpgaInputsList == null) {
fpgaInputsList = new HashMap<String, Integer>();
} else {
fpgaInputsList.clear();
}
if (fpgaInOutsList == null) {
fpgaInOutsList = new HashMap<String, Integer>();
} else {
fpgaInOutsList.clear();
}
if (fpgaOutputsList == null) {
fpgaOutputsList = new HashMap<String, Integer>();
} else {
fpgaOutputsList.clear();
}
nrOfFPGAInputPins = 0;
nrOfFPGAInOutPins = 0;
nrOfFPGAOutputPins = 0;
for (ArrayList<String> key : myMappableResources.keySet()) {
NetlistComponent comp = myMappableResources.get(key);
for (String Map : GetMapNamesList(key, comp)) {
FPGAIOInformationContainer BoardComp = currentUsedBoard.GetComponent(comp.getMap(Map));
if (BoardComp.GetType().equals(IOComponentTypes.Pin)) {
if (comp.getEnd(0).IsOutputEnd()) {
fpgaInputsList.put(Map, nrOfFPGAInputPins);
nrOfFPGAInputPins++;
} else {
fpgaOutputsList.put(Map, nrOfFPGAOutputPins);
nrOfFPGAOutputPins++;
}
} else {
int NrOfPins = IOComponentTypes.GetFPGAInputRequirement(BoardComp.GetType());
if (NrOfPins != 0) {
fpgaInputsList.put(Map, nrOfFPGAInputPins);
if (BoardComp.GetType().equals(IOComponentTypes.DIPSwitch)) {
nrOfFPGAInputPins += BoardComp.getNrOfPins();
} else if (BoardComp.GetType().equals(IOComponentTypes.PortIO)) {
nrOfFPGAInputPins += BoardComp.getNrOfPins();
} else {
nrOfFPGAInputPins += NrOfPins;
}
}
NrOfPins = IOComponentTypes.GetFPGAOutputRequirement(BoardComp.GetType());
if (NrOfPins != 0) {
fpgaOutputsList.put(Map, nrOfFPGAOutputPins);
nrOfFPGAOutputPins += NrOfPins;
}
NrOfPins = IOComponentTypes.GetFPGAInOutRequirement(BoardComp.GetType());
if (NrOfPins != 0) {
fpgaInOutsList.put(Map, nrOfFPGAInOutPins);
if (BoardComp.GetType().equals(IOComponentTypes.PortIO)) {
nrOfFPGAInOutPins += BoardComp.getNrOfPins();
} else {
nrOfFPGAInOutPins += NrOfPins;
}
}
}
}
}
}
use of com.bfh.logisim.fpgaboardeditor.FPGAIOInformationContainer in project logisim-evolution by reds-heig.
the class ComponentMapDialog method Load.
private void Load() {
JFileChooser fc = new JFileChooser(OldDirectory);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setDialogTitle("Choose XML board description file to use");
FileFilter XML_FILTER = new XMLFileFilter();
fc.setFileFilter(XML_FILTER);
fc.setAcceptAllFileFilterUsed(false);
panel.setVisible(false);
int retval = fc.showOpenDialog(null);
if (retval == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
String FileName = file.getName();
String AbsoluteFileName = file.getPath();
OldDirectory = AbsoluteFileName.substring(0, AbsoluteFileName.length() - FileName.length());
try {
// Create instance of DocumentBuilderFactory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Get the DocumentBuilder
DocumentBuilder parser = factory.newDocumentBuilder();
// Create blank DOM Document
File xml = new File(AbsoluteFileName);
Document MapDoc = parser.parse(xml);
NodeList Elements = MapDoc.getElementsByTagName("LogisimGoesFPGABoardMapInformation");
Node CircuitInfo = Elements.item(0);
NodeList CircuitInfoDetails = CircuitInfo.getChildNodes();
for (int i = 0; i < CircuitInfoDetails.getLength(); i++) {
if (CircuitInfoDetails.item(i).getNodeName().equals("GlobalMapInformation")) {
NamedNodeMap Attrs = CircuitInfoDetails.item(i).getAttributes();
for (int j = 0; j < Attrs.getLength(); j++) {
if (Attrs.item(j).getNodeName().equals("BoardName")) {
if (!BoardInfo.getBoardName().equals(Attrs.item(j).getNodeValue())) {
MessageLine.setForeground(Color.RED);
MessageLine.setText("LOAD ERROR: The selected Map file is not for the selected target board!");
panel.setVisible(true);
return;
}
} else if (Attrs.item(j).getNodeName().equals("ToplevelCircuitName")) {
if (!MappableComponents.GetToplevelName().equals(Attrs.item(j).getNodeValue())) {
MessageLine.setForeground(Color.RED);
MessageLine.setText("LOAD ERROR: The selected Map file is not for the selected toplevel circuit!");
panel.setVisible(true);
return;
}
}
}
break;
}
}
/* cleanup the current map */
UnMapAll();
for (int i = 0; i < CircuitInfoDetails.getLength(); i++) {
if (CircuitInfoDetails.item(i).getNodeName().startsWith("MAPPEDCOMPONENT")) {
int x = -1, y = -1, width = -1, height = -1;
String key = "";
NamedNodeMap Attrs = CircuitInfoDetails.item(i).getAttributes();
for (int j = 0; j < Attrs.getLength(); j++) {
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[0])) {
key = Attrs.item(j).getNodeValue();
}
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[1])) {
x = Integer.parseInt(Attrs.item(j).getNodeValue());
}
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[2])) {
y = Integer.parseInt(Attrs.item(j).getNodeValue());
}
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[3])) {
width = Integer.parseInt(Attrs.item(j).getNodeValue());
}
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[4])) {
height = Integer.parseInt(Attrs.item(j).getNodeValue());
}
}
if (!key.isEmpty() && (x > 0) && (y > 0) && (width > 0) && (height > 0)) {
BoardRectangle rect = null;
for (FPGAIOInformationContainer comp : BoardInfo.GetAllComponents()) {
if ((comp.GetRectangle().getXpos() == x) && (comp.GetRectangle().getYpos() == y) && (comp.GetRectangle().getWidth() == width) && (comp.GetRectangle().getHeight() == height)) {
rect = comp.GetRectangle();
break;
}
}
if (rect != null) {
MappableComponents.TryMap(key, rect, BoardInfo.GetComponentType(rect));
}
}
}
}
ClearSelections();
RebuildSelectionLists();
BoardPic.paintImmediately(0, 0, BoardPic.getWidth(), BoardPic.getHeight());
} catch (Exception e) {
/* TODO: handle exceptions */
logger.error("Exceptions not handled yet in Load(), but got an exception: {}", e.getMessage());
}
}
panel.setVisible(true);
}
use of com.bfh.logisim.fpgaboardeditor.FPGAIOInformationContainer in project logisim-evolution by reds-heig.
the class MappableResourcesContainer method GetFPGAPinLocs.
public ArrayList<String> GetFPGAPinLocs(int FPGAVendor) {
ArrayList<String> Contents = new ArrayList<String>();
for (String Map : fpgaInputsList.keySet()) {
int InputId = fpgaInputsList.get(Map);
if (!mappedList.containsKey(Map)) {
logger.warn("No mapping found for {}", Map);
return Contents;
}
BoardRectangle rect = mappedList.get(Map);
FPGAIOInformationContainer Comp = currentUsedBoard.GetComponent(rect);
Contents.addAll(Comp.GetPinlocStrings(FPGAVendor, "in", InputId));
}
for (String Map : fpgaInOutsList.keySet()) {
int InOutId = fpgaInOutsList.get(Map);
if (!mappedList.containsKey(Map)) {
logger.warn("No mapping found for {}", Map);
return Contents;
}
BoardRectangle rect = mappedList.get(Map);
FPGAIOInformationContainer Comp = currentUsedBoard.GetComponent(rect);
Contents.addAll(Comp.GetPinlocStrings(FPGAVendor, "inout", InOutId));
}
for (String Map : fpgaOutputsList.keySet()) {
int OutputId = fpgaOutputsList.get(Map);
if (!mappedList.containsKey(Map)) {
logger.warn("No mapping found for {}", Map);
return Contents;
}
BoardRectangle rect = mappedList.get(Map);
FPGAIOInformationContainer Comp = currentUsedBoard.GetComponent(rect);
Contents.addAll(Comp.GetPinlocStrings(FPGAVendor, "out", OutputId));
}
return Contents;
}
use of com.bfh.logisim.fpgaboardeditor.FPGAIOInformationContainer in project logisim-evolution by reds-heig.
the class MappableResourcesContainer method RequiresToplevelInversion.
public boolean RequiresToplevelInversion(ArrayList<String> ComponentIdentifier, String MapName) {
if (!mappedList.containsKey(MapName)) {
return false;
}
if (!myMappableResources.containsKey(ComponentIdentifier)) {
return false;
}
FPGAIOInformationContainer BoardComp = currentUsedBoard.GetComponent(mappedList.get(MapName));
NetlistComponent Comp = myMappableResources.get(ComponentIdentifier);
boolean BoardActiveHigh = (BoardComp.GetActivityLevel() == PinActivity.ActiveHigh);
boolean CompActiveHigh = Comp.GetComponent().getFactory().ActiveOnHigh(Comp.GetComponent().getAttributeSet());
boolean Invert = BoardActiveHigh ^ CompActiveHigh;
return Invert;
}
Aggregations