├── .gitignore ├── COPYING ├── Doxyfile ├── Makefile ├── README.md ├── Sopc2DTS.java ├── boardinfo_neek.xml ├── sopc2dts ├── LogEntry.java ├── LogListener.java ├── Logger.java ├── generators │ ├── AbstractSopcGenerator.java │ ├── DTBCCharArray.java │ ├── DTBGenerator2.java │ ├── DTBHex32Generator.java │ ├── DTBHex8Generator.java │ ├── DTGenerator.java │ ├── DTSGenerator2.java │ ├── GeneratorFactory.java │ ├── GraphGenerator.java │ ├── KernelHeadersGenerator.java │ ├── SopcCreateHeaderFilesImitator.java │ └── UBootHeaderGenerator.java ├── gui │ ├── BasicComponentComboBoxModel.java │ ├── BasicComponentListItem.java │ ├── BasicComponentRenderer.java │ ├── BoardInfoPanel.java │ ├── InputPanel.java │ ├── LogPanel.java │ ├── OutputPanel.java │ ├── Sopc2DTSGui.java │ ├── ThreadedLoadPanel.java │ └── boardinfo │ │ ├── BISComponentGroup.java │ │ ├── BISEthernet.java │ │ ├── BISFlash.java │ │ ├── BISGeneral.java │ │ ├── BISI2C.java │ │ ├── BISSpi.java │ │ ├── BISSubComponentTable.java │ │ └── BoardInfoSubPanel.java ├── lib │ ├── AvalonSystem.java │ ├── BasicElement.java │ ├── Bin2IHex.java │ ├── BoardInfo.java │ ├── Connection.java │ ├── Parameter.java │ ├── SopcComponentLib.java │ ├── boardinfo │ │ ├── BICDTAppend.java │ │ ├── BICEthernet.java │ │ ├── BICI2C.java │ │ ├── BICSpi.java │ │ ├── BoardInfoComponent.java │ │ ├── I2CSlave.java │ │ ├── SpiSlave.java │ │ └── SpiSlaveMMC.java │ ├── components │ │ ├── BasicComponent.java │ │ ├── Interface.java │ │ ├── InterruptReceiver.java │ │ ├── MemoryBlock.java │ │ ├── SopcComponentDescription.java │ │ ├── altera │ │ │ ├── A10InterfaceGenerator.java │ │ │ ├── GenericTristateController.java │ │ │ ├── InterfaceGenerator.java │ │ │ ├── InterruptBridge.java │ │ │ ├── InterruptLatencyCounter.java │ │ │ ├── MultiBridge.java │ │ │ ├── PCIeCompiler.java │ │ │ ├── PCIeRootPort.java │ │ │ ├── SICEpcs.java │ │ │ ├── SICLan91c111.java │ │ │ ├── SICSgdma.java │ │ │ ├── SICTrippleSpeedEthernet.java │ │ │ ├── TSEMonolithic.java │ │ │ ├── VIPFrameBuffer.java │ │ │ ├── VIPMixer.java │ │ │ └── hps │ │ │ │ ├── ClockManager.java │ │ │ │ ├── ClockManagerA10.java │ │ │ │ ├── ClockManagerV.java │ │ │ │ ├── SocFpgaGateClock.java │ │ │ │ ├── SocFpgaPeripClock.java │ │ │ │ ├── SocFpgaPllClock.java │ │ │ │ └── VirtualClockElement.java │ │ ├── arm │ │ │ └── CortexA9GIC.java │ │ ├── base │ │ │ ├── ClockSource.java │ │ │ ├── CpuComponent.java │ │ │ ├── FlashPartition.java │ │ │ ├── GpioController.java │ │ │ ├── MailBox.java │ │ │ ├── SCDSelfDescribing.java │ │ │ ├── SICBridge.java │ │ │ ├── SICEthernet.java │ │ │ ├── SICEthernet.java.orig │ │ │ ├── SICFlash.java │ │ │ ├── SICI2CMaster.java │ │ │ ├── SICSpiMaster.java │ │ │ └── SICUnknown.java │ │ ├── labx │ │ │ └── LabXEthernet.java │ │ ├── nxp │ │ │ └── USBHostControllerISP1xxx.java │ │ └── snps │ │ │ └── DwGpio.java │ ├── devicetree │ │ ├── DTBlob.java │ │ ├── DTElement.java │ │ ├── DTHelper.java │ │ ├── DTNode.java │ │ ├── DTPropByteVal.java │ │ ├── DTPropHexNumVal.java │ │ ├── DTPropNumVal.java │ │ ├── DTPropPHandleVal.java │ │ ├── DTPropStringVal.java │ │ ├── DTPropVal.java │ │ └── DTProperty.java │ └── uboot │ │ ├── UBootComponentLib.java │ │ └── UBootLibComponent.java └── parsers │ ├── BasicSystemLoader.java │ ├── qsys │ ├── QSysSubSystem.java │ └── QSysSystemLoader.java │ └── sopcinfo │ ├── SopcInfoAssignment.java │ ├── SopcInfoComponent.java │ ├── SopcInfoConnection.java │ ├── SopcInfoElement.java │ ├── SopcInfoElementIgnoreAll.java │ ├── SopcInfoElementWithParams.java │ ├── SopcInfoInterface.java │ ├── SopcInfoParameter.java │ └── SopcInfoSystemLoader.java ├── sopc_components_altera.xml ├── sopc_components_fps.xml ├── sopc_components_labx.xml ├── sopc_components_nxp.xml └── sopc_components_others.xml /.gitignore: -------------------------------------------------------------------------------- 1 | sopc2dts.jar 2 | *.class 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | sopc2dts 2 | ======== 3 | 4 | Tool to create a devicetree from a sopcinfo file generated by Altera 5 | 6 | More info available at: 7 | http://www.alterawiki.com/wiki/Sopc2dts 8 | http://rocketboards.org/foswiki/Documentation/DeviceTreeGenerator140 9 | -------------------------------------------------------------------------------- /boardinfo_neek.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sopc2dts/LogEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts; 21 | 22 | import java.util.Date; 23 | 24 | import sopc2dts.Logger.LogLevel; 25 | import sopc2dts.lib.components.BasicComponent; 26 | import sopc2dts.lib.components.Interface; 27 | 28 | public class LogEntry { 29 | StackTraceElement[] trace; 30 | Date timestamp; 31 | Object source; 32 | String message; 33 | LogLevel level; 34 | 35 | public LogEntry(Object src, String msg, LogLevel ll) { 36 | timestamp = new Date(); 37 | trace = new Throwable().getStackTrace(); 38 | source = src; 39 | message = msg; 40 | level = ll; 41 | } 42 | 43 | public Object getSource() { 44 | return source; 45 | } 46 | public String getSourceStr() { 47 | if(source == null) { 48 | return ""; 49 | } else if(source instanceof BasicComponent) 50 | { 51 | BasicComponent bc = (BasicComponent)source; 52 | return "Component: " + bc.getInstanceName() + '(' + bc.getClassName() + ')'; 53 | } else if(source instanceof Interface) { 54 | Interface intf = (Interface)source; 55 | return "Interface: " + intf.getName() + " of " + intf.getOwner().getInstanceName() + '(' + intf.getOwner().getClassName() + ')'; 56 | } else { 57 | return source.toString(); 58 | } 59 | } 60 | public StackTraceElement[] getTrace() { 61 | return trace; 62 | } 63 | public String getMessage() { 64 | return message; 65 | } 66 | 67 | public LogLevel getLevel() { 68 | return level; 69 | } 70 | 71 | public Date getTimestamp() { 72 | return timestamp; 73 | } 74 | @Override 75 | public String toString() { 76 | if(source != null) { 77 | return getSourceStr() + ": " + message; 78 | } else { 79 | return message; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /sopc2dts/LogListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011-2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts; 21 | 22 | public interface LogListener { 23 | public void messageLogged(LogEntry log); 24 | } 25 | -------------------------------------------------------------------------------- /sopc2dts/Logger.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts; 21 | 22 | import java.util.Vector; 23 | 24 | public class Logger { 25 | public enum LogLevel { ERROR, WARNING, INFO, DEBUG }; 26 | private static LogLevel verbosity = LogLevel.WARNING; 27 | private static Vector vListeners = new Vector(); 28 | 29 | public static void increaseVerbosity() 30 | { 31 | switch (verbosity) { 32 | case ERROR: verbosity = LogLevel.WARNING; break; 33 | case WARNING: verbosity = LogLevel.INFO; break; 34 | case INFO: verbosity = LogLevel.DEBUG; break; 35 | default: 36 | break; 37 | } 38 | } 39 | public static void decreaseVerbosity() 40 | { 41 | switch (verbosity) { 42 | case WARNING: verbosity = LogLevel.ERROR; break; 43 | case INFO: verbosity = LogLevel.WARNING; break; 44 | case DEBUG: verbosity = LogLevel.INFO; break; 45 | default: 46 | break; 47 | } 48 | } 49 | public static LogLevel getVerbosity() 50 | { 51 | return verbosity; 52 | } 53 | public static void setVerbosity(LogLevel v) 54 | { 55 | verbosity = v; 56 | } 57 | private static void log(LogEntry log) 58 | { 59 | for(LogListener l: vListeners) 60 | { 61 | l.messageLogged(log); 62 | } 63 | } 64 | public static void logln(String log) 65 | { 66 | logln(log,LogLevel.INFO); 67 | } 68 | public static void logln(Object src, String log) 69 | { 70 | logln(src,log,LogLevel.INFO); 71 | } 72 | public static void logln(String log, LogLevel ll) 73 | { 74 | logln(null,log,ll); 75 | } 76 | public static void logln(Object src, String log, LogLevel ll) 77 | { 78 | log(new LogEntry(src, log, ll)); 79 | } 80 | public static void logException(Exception e) 81 | { 82 | logln(e.getMessage(), LogLevel.INFO); 83 | if(verbosity == LogLevel.DEBUG) 84 | { 85 | e.printStackTrace(); 86 | } else { 87 | logln("Exception occurred: use -v for more information", LogLevel.WARNING); 88 | } 89 | } 90 | public static void addLogListener(LogListener ll) 91 | { 92 | vListeners.add(ll); 93 | } 94 | public static void removeLogListener(LogListener ll) 95 | { 96 | vListeners.remove(ll); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /sopc2dts/generators/DTBCCharArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.generators; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.BoardInfo; 24 | 25 | public class DTBCCharArray extends AbstractSopcGenerator { 26 | static final int ENTRIES_PER_LINE = 12; 27 | private DTBGenerator2 dtbGen; 28 | public DTBCCharArray(AvalonSystem s) { 29 | super(s, true); 30 | dtbGen = new DTBGenerator2(s); 31 | } 32 | 33 | @Override 34 | public String getTextOutput(BoardInfo bi) { 35 | byte[] dtb = dtbGen.getBinaryOutput(bi); 36 | String res = "unsigned char dtbData[] = {\n"; 37 | for(int i=0; i 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.generators; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.BoardInfo; 24 | import sopc2dts.lib.BoardInfo.PovType; 25 | import sopc2dts.lib.devicetree.DTBlob; 26 | import sopc2dts.lib.devicetree.DTNode; 27 | 28 | /** @brief Generator for DTB files 29 | * 30 | * This generator extends DTGenerator and uses the tree of DTElement's generated 31 | * by DTGenerator to create a dtb file directly without the need of an external 32 | * dtc. 33 | * 34 | * @note This generator uses it's own dtb creation process, not the "official" 35 | * dtc. When in doubt, generate a DTS using DTSGenerator2, pass that to dtc and 36 | * compare the results. 37 | * 38 | * @author Walter Goossens 39 | * 40 | */ 41 | public class DTBGenerator2 extends DTGenerator { 42 | 43 | /** @brief Constructor for the DTBGenerator2 44 | * 45 | * @param s The AvalonSystem to generate for 46 | */ 47 | public DTBGenerator2(AvalonSystem s) { 48 | super(s, false); 49 | } 50 | 51 | @Override 52 | public String getTextOutput(BoardInfo bi) { 53 | return null; 54 | } 55 | 56 | @Override 57 | public byte[] getBinaryOutput(BoardInfo bi) 58 | { 59 | DTBlob dtb = new DTBlob((bi.getPovType() != PovType.CPU ? 0x100 : 0)); 60 | DTNode root = getDTOutput(bi); 61 | root.setName(""); 62 | dtb.setRootNode(root); 63 | return dtb.getBytes(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /sopc2dts/generators/DTBHex32Generator.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.generators; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.Bin2IHex; 24 | import sopc2dts.lib.Bin2IHex.AddressingMode; 25 | import sopc2dts.lib.Bin2IHex.ByteOrder; 26 | import sopc2dts.lib.Bin2IHex.HexTypes; 27 | import sopc2dts.lib.BoardInfo; 28 | 29 | public class DTBHex32Generator extends AbstractSopcGenerator { 30 | private DTBGenerator2 dtbGen; 31 | public DTBHex32Generator(AvalonSystem s) { 32 | super(s, true); 33 | dtbGen = new DTBGenerator2(s); 34 | } 35 | 36 | @Override 37 | public String getTextOutput(BoardInfo bi) { 38 | return Bin2IHex.toHex(dtbGen.getBinaryOutput(bi), HexTypes.I32Hex,ByteOrder.LE,AddressingMode.AddrMode32); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sopc2dts/generators/DTBHex8Generator.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.generators; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.Bin2IHex; 24 | import sopc2dts.lib.Bin2IHex.HexTypes; 25 | import sopc2dts.lib.BoardInfo; 26 | 27 | /** @brief Generate an intel-Hex8 file for a dtb 28 | * 29 | * @author Walter Goossens 30 | * 31 | */ 32 | public class DTBHex8Generator extends DTBGenerator2 { 33 | public DTBHex8Generator(AvalonSystem s) { 34 | super(s); 35 | generateTextOutput = true; 36 | } 37 | 38 | @Override 39 | public String getTextOutput(BoardInfo bi) { 40 | return Bin2IHex.toHex(getBinaryOutput(bi), HexTypes.I8Hex); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /sopc2dts/generators/DTSGenerator2.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.generators; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.BoardInfo; 24 | import sopc2dts.lib.devicetree.DTNode; 25 | 26 | public class DTSGenerator2 extends DTGenerator { 27 | 28 | public DTSGenerator2(AvalonSystem s) { 29 | super(s, true); 30 | } 31 | 32 | @Override 33 | public String getTextOutput(BoardInfo bi) { 34 | String res = getSmallCopyRightNotice("devicetree", bi.isIncludeTime()) 35 | + "/dts-v1/;\n"; 36 | DTNode rootNode = getDTOutput(bi); 37 | res += rootNode.toString(); 38 | return res; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sopc2dts/generators/GeneratorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011-2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.generators; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | 24 | public class GeneratorFactory { 25 | public enum GeneratorType { DTS, DTB, DTB_IHEX8, DTB_IHEX32, GRAPH, U_BOOT, KERNEL_HEADERS, DTB_CHAR_ARR }; 26 | 27 | public static String getGeneratorNameByType(GeneratorType genType) 28 | { 29 | switch(genType) 30 | { 31 | case DTS: { 32 | return "dts"; 33 | } 34 | case DTB: { 35 | return "dtb"; 36 | } 37 | case DTB_IHEX8: { 38 | return "dtb-hex8"; 39 | } 40 | case DTB_IHEX32: { 41 | return "dtb-hex32"; 42 | } 43 | case DTB_CHAR_ARR: { 44 | return "dtb-char-arr"; 45 | } 46 | case GRAPH: { 47 | return "graph"; 48 | } 49 | case U_BOOT: { 50 | return "u-boot"; 51 | } 52 | case KERNEL_HEADERS: { 53 | return "kernel"; 54 | } 55 | } 56 | return null; 57 | } 58 | public static String getGeneratorDescriptionByType(GeneratorType genType) 59 | { 60 | switch(genType) 61 | { 62 | case DTS: { 63 | return "Device Tree Source
A textual representation of the system."; 64 | } 65 | case DTB_CHAR_ARR: 66 | case DTB: { 67 | return "Device Tree Blob
A compiled version of the dts"; 68 | } 69 | case DTB_IHEX8: { 70 | return "Intel hex8 containing the dtb"; 71 | } 72 | case DTB_IHEX32: { 73 | return "Intel hex32 containing the dtb
compatible with Altera 32bits onchip rom"; 74 | } 75 | case GRAPH: { 76 | return "DOT Graph of the system"; 77 | } 78 | case U_BOOT: { 79 | return "U-Boot headers"; 80 | } 81 | case KERNEL_HEADERS: { 82 | return "Linux Kernel headers.
Not really needed anymore"; 83 | } 84 | } 85 | return null; 86 | } 87 | public static GeneratorType getGeneratorTypeByName(String type) 88 | { 89 | if(type.equalsIgnoreCase("dts")) 90 | { 91 | return GeneratorType.DTS; 92 | } else if(type.equalsIgnoreCase("dtb")) 93 | { 94 | return GeneratorType.DTB; 95 | } else if(type.equalsIgnoreCase("dtb-hex8")) 96 | { 97 | return GeneratorType.DTB_IHEX8; 98 | } else if(type.equalsIgnoreCase("dtb-hex32")) 99 | { 100 | return GeneratorType.DTB_IHEX32; 101 | } else if(type.equalsIgnoreCase("dtb-char-arr")) 102 | { 103 | return GeneratorType.DTB_CHAR_ARR; 104 | } else if(type.equalsIgnoreCase("graph")) 105 | { 106 | return GeneratorType.GRAPH; 107 | } else if(type.equalsIgnoreCase("u-boot") || type.equalsIgnoreCase("uboot")) { 108 | return GeneratorType.U_BOOT; 109 | } else if(type.equalsIgnoreCase("kernel")) 110 | { 111 | return GeneratorType.KERNEL_HEADERS; 112 | } 113 | return null; 114 | } 115 | public static AbstractSopcGenerator createGeneratorFor(AvalonSystem sys, String type) 116 | { 117 | return createGeneratorFor(sys, getGeneratorTypeByName(type)); 118 | } 119 | public static AbstractSopcGenerator createGeneratorFor(AvalonSystem sys, GeneratorType genType) 120 | { 121 | if(genType != null) 122 | { 123 | switch(genType) 124 | { 125 | case DTS: { 126 | return new DTSGenerator2(sys); 127 | } 128 | case DTB: { 129 | return new DTBGenerator2(sys); 130 | } 131 | case DTB_IHEX8: { 132 | return new DTBHex8Generator(sys); 133 | } 134 | case DTB_IHEX32: { 135 | return new DTBHex32Generator(sys); 136 | } 137 | case DTB_CHAR_ARR: { 138 | return new DTBCCharArray(sys); 139 | } 140 | case GRAPH: { 141 | return new GraphGenerator(sys); 142 | } 143 | case U_BOOT: { 144 | return new UBootHeaderGenerator(sys); 145 | } 146 | case KERNEL_HEADERS: { 147 | return new KernelHeadersGenerator(sys); 148 | } 149 | } 150 | } 151 | return null; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /sopc2dts/generators/GraphGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.generators; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.AvalonSystem.SystemDataType; 24 | import sopc2dts.lib.BoardInfo; 25 | import sopc2dts.lib.Connection; 26 | import sopc2dts.lib.components.BasicComponent; 27 | import sopc2dts.lib.components.Interface; 28 | import sopc2dts.lib.devicetree.DTHelper; 29 | 30 | public class GraphGenerator extends AbstractSopcGenerator { 31 | 32 | public GraphGenerator(AvalonSystem s) { 33 | super(s,true); 34 | } 35 | 36 | @Override 37 | public String getTextOutput(BoardInfo bi) { 38 | String res = "digraph sopc2dot {\n" + 39 | " node [shape=rect]\n"; 40 | for(BasicComponent comp : sys.getSystemComponents()) { 41 | res += " " + comp.getInstanceName() + " [label=<\n" + 42 | "\t\n" + 43 | "\t\n"; 44 | for(Interface intf : comp.getInterfaces()) { 45 | String color = getColorForInterface(intf, bi); 46 | if(color!=null) { 47 | res+="\t\n"; 48 | } 49 | } 50 | res += "\t
" + comp.getInstanceName() + "
Class: " + comp.getClassName() + "
" + intf.getName() + "
>]\n"; 51 | } 52 | for(BasicComponent comp : sys.getSystemComponents()) { 53 | for(Interface masterIf : comp.getInterfaces()) { 54 | String color = getColorForInterface(masterIf,bi); 55 | if(masterIf.isMaster() && color !=null) { 56 | for(Connection conn : masterIf.getConnections()) { 57 | Interface slaveIf = conn.getSlaveInterface(); 58 | res += comp.getInstanceName() + ":" + undashify(masterIf.getName()) + " -> " + 59 | slaveIf.getOwner().getInstanceName() + ":" + undashify(slaveIf.getName()); 60 | res +=" [color=\"" + color + "\""; 61 | if(conn.getType() == SystemDataType.MEMORY_MAPPED) { 62 | res += " label=\"" + DTHelper.longArrToHexString(conn.getConnValue()) + "\"]\n"; 63 | } else if (conn.getType() == SystemDataType.INTERRUPT) { 64 | res += " label=\"" + DTHelper.longArrToLong(conn.getConnValue()) + "\"]\n"; 65 | } else { 66 | res += "]\n"; 67 | } 68 | } 69 | } 70 | } 71 | } 72 | res += "}\n"; 73 | return res; 74 | } 75 | String getColorForInterface(Interface intf, BoardInfo bi) { 76 | switch(intf.getType()) { 77 | case CLOCK: return (bi.isShowClockTree() ? "green" : null); 78 | case CONDUIT: return (bi.isShowConduits() ? "salmon" : null); 79 | case MEMORY_MAPPED: return "blue"; 80 | case RESET: return (bi.isShowResets() ? "gray" : null); 81 | case STREAMING: return (bi.isShowStreaming() ? "yellow" : null); 82 | case INTERRUPT: return "pink"; 83 | case CUSTOM_INSTRUCTION: return "seagreen"; 84 | default: System.err.println("Not drawing type: " + intf.getType());return null; 85 | } 86 | } 87 | static String undashify(String in) { 88 | /* HTML Version seems to choke on both _ and - so just use a letter... */ 89 | return in.replace('-','d').replace('_', 'u'); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /sopc2dts/generators/KernelHeadersGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.generators; 21 | 22 | import sopc2dts.lib.Parameter; 23 | import sopc2dts.lib.AvalonSystem; 24 | import sopc2dts.lib.BoardInfo; 25 | import sopc2dts.lib.components.BasicComponent; 26 | 27 | public class KernelHeadersGenerator extends AbstractSopcGenerator { 28 | boolean minimal = true; 29 | public KernelHeadersGenerator(AvalonSystem s) { 30 | super(s,true); 31 | } 32 | 33 | @Override 34 | public String getTextOutput(BoardInfo bi) { 35 | String res = null; 36 | for(BasicComponent comp : sys.getSystemComponents()) 37 | { 38 | if((!minimal) || comp.getScd().getGroup().equalsIgnoreCase("cpu")) 39 | { 40 | //Only dump nios stuff if REALLY needed 41 | if(res==null) 42 | { 43 | res = copyRightNotice + 44 | "#ifndef _ALTERA_CPU_H_\n" + 45 | "#define _ALTERA_CPU_H_\n\n" + 46 | "/*\n" + 47 | " * Warning:\n" + 48 | " * from kernel 2.6.38 onwards this is not really needed anymore\n" + 49 | " * Just choose \"Generic devicetree based NiosII system\" as your \n" + 50 | " * target board and you should be fine.\n" + 51 | " */\n\n"; 52 | } 53 | res += "/*\n" + 54 | " * Dumping parameters for " + comp.getInstanceName() + " (type " + comp.getScd().getGroup() + ")\n" + 55 | " * This is not as clean as I hoped but FDT is just a tad late\n" + 56 | " */\n"; 57 | for(Parameter ass : comp.getParams()) 58 | { 59 | if(ass.getName().toUpperCase().startsWith("EMBEDDEDSW.CMACRO.")) 60 | { 61 | res += "#define " + ass.getName().substring(18).toUpperCase() + "\t" + ass.getValue() + "\n"; 62 | } 63 | } 64 | } 65 | } 66 | if(res!=null) 67 | { 68 | res += "\n#endif //_ALTERA_CPU_H_\n"; 69 | } 70 | return res; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /sopc2dts/gui/BasicComponentComboBoxModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui; 21 | 22 | import java.util.Vector; 23 | 24 | import javax.swing.AbstractListModel; 25 | import javax.swing.ComboBoxModel; 26 | 27 | import sopc2dts.lib.AvalonSystem; 28 | import sopc2dts.lib.components.BasicComponent; 29 | 30 | public class BasicComponentComboBoxModel extends AbstractListModel implements ComboBoxModel { 31 | private static final long serialVersionUID = 7471198219999627210L; 32 | Vector vList; 33 | String selected; 34 | 35 | public BasicComponentComboBoxModel(AvalonSystem sys, boolean mastersOnly, String selectedCompName) 36 | { 37 | if(sys==null) 38 | { 39 | vList = new Vector(); 40 | } else { 41 | if(mastersOnly) 42 | { 43 | vList = sys.getMasterComponents(); 44 | } else { 45 | vList = sys.getSystemComponents(); 46 | } 47 | if(selectedCompName!=null) 48 | { 49 | BasicComponent comp = sys.getComponentByName(selectedCompName); 50 | if(comp!=null) 51 | { 52 | if(vList.contains(comp)) 53 | { 54 | selected = basicComponent2Item(comp); 55 | } 56 | } 57 | } 58 | } 59 | } 60 | public String basicComponent2Item(BasicComponent comp) 61 | { 62 | return comp.getScd().getGroup() + ": " + comp.getInstanceName(); 63 | } 64 | public Object getElementAt(int index) { 65 | return basicComponent2Item(vList.get(index)); 66 | } 67 | 68 | public int getSize() { 69 | return vList.size(); 70 | } 71 | 72 | public Object getSelectedItem() { 73 | return selected; 74 | } 75 | 76 | public void setSelectedItem(Object anItem) { 77 | selected = anItem.toString(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /sopc2dts/gui/BasicComponentListItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui; 21 | 22 | import java.awt.Color; 23 | import java.awt.Dimension; 24 | import java.awt.GridLayout; 25 | 26 | import javax.swing.BorderFactory; 27 | import javax.swing.JLabel; 28 | import javax.swing.JPanel; 29 | 30 | import sopc2dts.lib.components.BasicComponent; 31 | import sopc2dts.lib.components.base.SCDSelfDescribing; 32 | import sopc2dts.lib.components.base.SICUnknown; 33 | 34 | public class BasicComponentListItem extends JPanel { 35 | private static final long serialVersionUID = 3548406165403921773L; 36 | 37 | public BasicComponentListItem(BasicComponent bc, boolean selected) 38 | { 39 | super(); 40 | this.setLayout(new GridLayout(3,2)); 41 | setPreferredSize(new Dimension(270, 80)); 42 | this.setBorder(BorderFactory.createTitledBorder(bc.getInstanceName())); 43 | if(bc.getScd() instanceof SCDSelfDescribing) 44 | { 45 | this.setBackground(new Color(0, 255, 0, (selected ? 128 : 64))); 46 | } else if(bc.getScd() instanceof SICUnknown) 47 | { 48 | this.setBackground(new Color(255, 0, 0, (selected ? 128 : 64))); 49 | } else { 50 | this.setOpaque(selected); 51 | } 52 | this.add(new JLabel("Type")); 53 | this.add(new JLabel(bc.getScd().getDevice())); 54 | this.add(new JLabel("Group")); 55 | this.add(new JLabel(bc.getScd().getGroup())); 56 | this.add(new JLabel("SOPC-Class")); 57 | this.add(new JLabel(bc.getClassName())); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sopc2dts/gui/BasicComponentRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui; 21 | 22 | import java.awt.Component; 23 | 24 | import javax.swing.JLabel; 25 | import javax.swing.JList; 26 | import javax.swing.ListCellRenderer; 27 | 28 | import sopc2dts.lib.components.BasicComponent; 29 | 30 | public class BasicComponentRenderer implements ListCellRenderer { 31 | 32 | public Component getListCellRendererComponent(JList list, Object value, 33 | int index, boolean isSelected, boolean cellHasFocus) { 34 | if(value instanceof BasicComponent) 35 | { 36 | BasicComponent bc = (BasicComponent)value; 37 | return new BasicComponentListItem(bc,isSelected); 38 | } else { 39 | return new JLabel(value.toString()); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /sopc2dts/gui/InputPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui; 21 | 22 | import java.awt.BorderLayout; 23 | import java.awt.Dimension; 24 | import java.io.BufferedReader; 25 | import java.io.File; 26 | import java.io.FileReader; 27 | import java.io.IOException; 28 | 29 | import javax.swing.BorderFactory; 30 | import javax.swing.JList; 31 | import javax.swing.JScrollPane; 32 | import javax.swing.JTextArea; 33 | 34 | import sopc2dts.Logger; 35 | import sopc2dts.lib.AvalonSystem; 36 | import sopc2dts.parsers.BasicSystemLoader; 37 | 38 | public class InputPanel extends ThreadedLoadPanel { 39 | private static final long serialVersionUID = -2627231677508843875L; 40 | JTextArea txtSource = new JTextArea(); 41 | JList componentList = new JList(); 42 | 43 | public InputPanel(String fName, Sopc2DTSGui parent) 44 | { 45 | super(fName, parent); 46 | componentList.setCellRenderer(new BasicComponentRenderer()); 47 | JScrollPane jsp = new JScrollPane(componentList); 48 | jsp.setPreferredSize(new Dimension(300, 400)); 49 | jsp.setBorder(BorderFactory.createTitledBorder("Component list")); 50 | this.add(jsp, BorderLayout.EAST); 51 | jsp = new JScrollPane(txtSource); 52 | jsp.setBorder(BorderFactory.createTitledBorder("Input source")); 53 | this.add(jsp, BorderLayout.CENTER); 54 | } 55 | 56 | public void setSys(AvalonSystem sys) { 57 | mainGui.setSys(sys); 58 | if(sys!=null) 59 | { 60 | componentList.setListData(sys.getSystemComponents()); 61 | } 62 | } 63 | @Override 64 | protected void threadedLoadFile(File f) { 65 | componentList.setListData(new Object[]{}); 66 | StringBuilder contents = new StringBuilder(); 67 | try { 68 | BufferedReader input = new BufferedReader(new FileReader(f)); 69 | try { 70 | String line = null; 71 | while (( line = input.readLine()) != null){ 72 | contents.append(line).append(System.getProperty("line.separator")); 73 | } 74 | } 75 | finally { 76 | input.close(); 77 | } 78 | } 79 | catch (IOException ex){ 80 | Logger.logException(ex); 81 | } 82 | txtSource.setText(contents.toString()); 83 | setSys(BasicSystemLoader.loadSystem(f)); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /sopc2dts/gui/LogPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui; 21 | 22 | import java.awt.BorderLayout; 23 | import java.awt.Color; 24 | import java.awt.Component; 25 | 26 | import javax.swing.DefaultListModel; 27 | import javax.swing.JButton; 28 | import javax.swing.JLabel; 29 | import javax.swing.JList; 30 | import javax.swing.JPanel; 31 | import javax.swing.JScrollPane; 32 | import javax.swing.ListCellRenderer; 33 | 34 | import sopc2dts.LogEntry; 35 | import sopc2dts.LogListener; 36 | import sopc2dts.Logger; 37 | import sopc2dts.Logger.LogLevel; 38 | 39 | public class LogPanel extends JPanel implements LogListener { 40 | private static final long serialVersionUID = -2484383142821969553L; 41 | JButton btnClear = new JButton("clear"); 42 | DefaultListModel lm = new DefaultListModel(); 43 | JList logList = new JList(lm); 44 | 45 | public LogPanel() { 46 | logList.setCellRenderer(new LogListCellRenderer()); 47 | Logger.addLogListener(this); 48 | this.setLayout(new BorderLayout()); 49 | JPanel pnlButtons = new JPanel(); 50 | pnlButtons.add(btnClear); 51 | this.add(pnlButtons, BorderLayout.NORTH); 52 | this.add(new JScrollPane(logList)); 53 | } 54 | public void messageLogged(LogEntry log) { 55 | lm.addElement(log); 56 | } 57 | class LogListCellRenderer implements ListCellRenderer { 58 | 59 | public Component getListCellRendererComponent(JList list, Object val, 60 | int idx, boolean selected, boolean focus) { 61 | LogEntry log = (LogEntry)val; 62 | JLabel lbl = new JLabel(log.getMessage()); 63 | if(selected) 64 | lbl.setBackground(list.getSelectionBackground()); 65 | lbl.setForeground(logLevel2Color(log.getLevel())); 66 | return lbl; 67 | } 68 | public Color logLevel2Color(LogLevel ll) { 69 | switch(ll) { 70 | case ERROR: return Color.RED; 71 | case INFO: return Color.GREEN; 72 | case WARNING: return Color.BLUE; 73 | case DEBUG: return Color.GRAY; 74 | default: 75 | return Color.BLACK; 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sopc2dts/gui/Sopc2DTSGui.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011-2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui; 21 | 22 | import java.awt.BorderLayout; 23 | import java.awt.Dimension; 24 | 25 | import javax.swing.JFrame; 26 | import javax.swing.JTabbedPane; 27 | 28 | import sopc2dts.generators.GeneratorFactory.GeneratorType; 29 | import sopc2dts.lib.AvalonSystem; 30 | import sopc2dts.lib.BoardInfo; 31 | 32 | public class Sopc2DTSGui extends JFrame { 33 | private static final long serialVersionUID = 8613192420393857538L; 34 | JTabbedPane jtp = new JTabbedPane(); 35 | LogPanel pnlLog = new LogPanel(); 36 | InputPanel pnlInput; 37 | BoardInfoPanel pnlBoardInfo; 38 | OutputPanel pnlOutput; 39 | private AvalonSystem sys; 40 | private BoardInfo boardInfo; 41 | 42 | public Sopc2DTSGui(String inpFile, BoardInfo bInfo) { 43 | super("Sopc2DTS"); 44 | boardInfo = bInfo; 45 | pnlInput = new InputPanel(inpFile, this); 46 | pnlBoardInfo = new BoardInfoPanel( 47 | (bInfo.getSourceFile() == null ? null : bInfo.getSourceFile().getName()), this); 48 | pnlOutput = new OutputPanel(GeneratorType.DTS, sys, boardInfo); 49 | jtp.addTab("Input", pnlInput); 50 | jtp.addTab("Boardinfo", pnlBoardInfo); 51 | jtp.addTab("Output", pnlOutput); 52 | pnlLog.setPreferredSize(new Dimension(800,200)); 53 | this.getContentPane().setLayout(new BorderLayout()); 54 | this.getContentPane().add(pnlLog, BorderLayout.SOUTH); 55 | this.getContentPane().add(jtp, BorderLayout.CENTER); 56 | this.pack(); 57 | } 58 | public void setSys(AvalonSystem sys) { 59 | this.sys = sys; 60 | pnlBoardInfo.setBoardInfoAndSys(boardInfo, sys); 61 | pnlOutput.setSys(sys); 62 | } 63 | public AvalonSystem getSys() { 64 | return sys; 65 | } 66 | public BoardInfo getBoardInfo() { 67 | return boardInfo; 68 | } 69 | public void setBoardInfo(BoardInfo boardInfo) { 70 | this.boardInfo = boardInfo; 71 | pnlOutput.setBoardInfo(boardInfo); 72 | pnlBoardInfo.setBoardInfoAndSys(boardInfo, sys); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /sopc2dts/gui/ThreadedLoadPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui; 21 | 22 | import java.awt.BorderLayout; 23 | import java.awt.event.ActionEvent; 24 | import java.awt.event.ActionListener; 25 | import java.io.File; 26 | 27 | import javax.swing.JButton; 28 | import javax.swing.JFileChooser; 29 | import javax.swing.JPanel; 30 | import javax.swing.JTextField; 31 | 32 | import sopc2dts.Logger; 33 | import sopc2dts.Logger.LogLevel; 34 | 35 | public abstract class ThreadedLoadPanel extends JPanel implements ActionListener { 36 | private static final long serialVersionUID = 6543239157358674037L; 37 | JButton btnChoose = new JButton("Choose file"); 38 | JTextField txtFileName = new JTextField(); 39 | JButton btnLoad = new JButton("Load file"); 40 | Sopc2DTSGui mainGui; 41 | public ThreadedLoadPanel(String fName, Sopc2DTSGui parent) 42 | { 43 | this(fName,parent,true); 44 | } 45 | public ThreadedLoadPanel(String fName, Sopc2DTSGui parent, boolean autoload) 46 | { 47 | mainGui = parent; 48 | txtFileName.setText(fName); 49 | btnChoose.addActionListener(this); 50 | btnLoad.addActionListener(this); 51 | JPanel pnlTop = new JPanel(new BorderLayout()); 52 | pnlTop.add(btnChoose, BorderLayout.WEST); 53 | pnlTop.add(btnLoad, BorderLayout.EAST); 54 | pnlTop.add(txtFileName, BorderLayout.CENTER); 55 | this.setLayout(new BorderLayout()); 56 | this.add(pnlTop, BorderLayout.NORTH); 57 | if(autoload && (fName!=null)) 58 | { 59 | loadFile(fName,500); 60 | } 61 | } 62 | protected abstract void threadedLoadFile(File f); 63 | 64 | void loadFile(String fName, int delay) 65 | { 66 | File f = new File(fName); 67 | if(f.exists()) 68 | { 69 | Thread t = new Thread(new ThreadedLoader(f,delay)); 70 | t.start(); 71 | } else { 72 | Logger.logln("Refusing to load " + fName + ". It does not exist", 73 | LogLevel.WARNING); 74 | } 75 | } 76 | public void actionPerformed(ActionEvent e) { 77 | if(e.getSource().equals(btnLoad)) 78 | { 79 | loadFile(txtFileName.getText(), 0); 80 | } else if(e.getSource().equals(btnChoose)) 81 | { 82 | JFileChooser jfc = new JFileChooser("."); 83 | if(jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 84 | { 85 | txtFileName.setText(jfc.getSelectedFile().getAbsolutePath()); 86 | loadFile(jfc.getSelectedFile().getAbsolutePath(), 0); 87 | } 88 | } 89 | } 90 | protected class ThreadedLoader implements Runnable { 91 | File f; 92 | int delayMillis; 93 | protected ThreadedLoader(File inp) 94 | { 95 | this(inp, 0); 96 | } 97 | protected ThreadedLoader(File inp, int delay) 98 | { 99 | f = inp; 100 | delayMillis = delay; 101 | } 102 | public void run() { 103 | if(delayMillis>0) 104 | { 105 | try { 106 | Thread.sleep(delayMillis); 107 | } catch (InterruptedException e) { 108 | e.printStackTrace(); 109 | } 110 | } 111 | threadedLoadFile(f); 112 | } 113 | 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /sopc2dts/gui/boardinfo/BISComponentGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui.boardinfo; 21 | 22 | import java.awt.BorderLayout; 23 | import java.util.Vector; 24 | 25 | import javax.swing.BorderFactory; 26 | import javax.swing.JList; 27 | import javax.swing.JOptionPane; 28 | import javax.swing.JScrollPane; 29 | import javax.swing.ListSelectionModel; 30 | import javax.swing.event.ListSelectionEvent; 31 | import javax.swing.event.ListSelectionListener; 32 | 33 | import sopc2dts.gui.BasicComponentRenderer; 34 | import sopc2dts.lib.AvalonSystem; 35 | import sopc2dts.lib.BoardInfo; 36 | import sopc2dts.lib.components.BasicComponent; 37 | import sopc2dts.lib.components.SopcComponentDescription; 38 | 39 | public abstract class BISComponentGroup extends BoardInfoSubPanel implements ListSelectionListener{ 40 | private static final long serialVersionUID = 6266428894255737000L; 41 | String group; 42 | BasicComponent wildCardComp; 43 | private JList componentList = new JList(); 44 | protected BasicComponent currComp; 45 | 46 | public BISComponentGroup(String name, String group, boolean useWildcard) { 47 | super(name); 48 | this.group = group; 49 | if(useWildcard) 50 | { 51 | wildCardComp = new BasicComponent(group,"all","0", 52 | new SopcComponentDescription(group, group, "none", "any")); 53 | componentList.setListData(new BasicComponent[]{ wildCardComp }); 54 | } 55 | componentList.setCellRenderer(new BasicComponentRenderer()); 56 | componentList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 57 | componentList.addListSelectionListener(this); 58 | JScrollPane pnlWest = new JScrollPane(componentList); 59 | pnlWest.setBorder(BorderFactory.createTitledBorder("Choose component")); 60 | this.setLayout(new BorderLayout()); 61 | this.add(pnlWest, BorderLayout.WEST); 62 | } 63 | 64 | protected abstract boolean isSaveNeeded(); 65 | protected abstract void selectedComponent(BasicComponent comp); 66 | 67 | @Override 68 | public boolean setBoardInfoAndSys(BoardInfo bi, AvalonSystem s) 69 | { 70 | super.setBoardInfoAndSys(bi, s); 71 | Vector vComp = new Vector(); 72 | if(wildCardComp!=null) 73 | { 74 | vComp.add(wildCardComp); 75 | } 76 | if(s!=null) 77 | { 78 | for(BasicComponent comp : s.getSystemComponents()) 79 | { 80 | if(matchComponent(comp)) 81 | { 82 | vComp.add(comp); 83 | } 84 | } 85 | } 86 | componentList.setListData(vComp); 87 | return (vComp.size()>1) || ((vComp.size()>0) && (wildCardComp == null)); 88 | } 89 | protected boolean matchComponent(BasicComponent comp) 90 | { 91 | return comp.getScd().getGroup().equalsIgnoreCase(group); 92 | } 93 | @Override 94 | public void setGuiEnabled(boolean ena) { 95 | componentList.setEnabled(ena); 96 | } 97 | 98 | public void valueChanged(ListSelectionEvent e) { 99 | if(!e.getValueIsAdjusting()) 100 | { 101 | BasicComponent comp = (BasicComponent)componentList.getSelectedValue(); 102 | if(comp!=null) 103 | { 104 | if(comp.equals(wildCardComp)) 105 | { 106 | comp = null; 107 | } 108 | if(isSaveNeeded()) 109 | { 110 | int res = JOptionPane.showConfirmDialog(this, "Apply changes?"); 111 | if(res == JOptionPane.YES_OPTION) 112 | { 113 | save(bInfo); 114 | } 115 | if(res != JOptionPane.CANCEL_OPTION) 116 | { 117 | selectedComponent(comp); 118 | } 119 | } else { 120 | selectedComponent(comp); 121 | } 122 | } 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /sopc2dts/gui/boardinfo/BISEthernet.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui.boardinfo; 21 | 22 | import java.awt.BorderLayout; 23 | import java.awt.GridLayout; 24 | 25 | import javax.swing.BorderFactory; 26 | import javax.swing.JComboBox; 27 | import javax.swing.JLabel; 28 | import javax.swing.JPanel; 29 | import javax.swing.JTextField; 30 | 31 | import sopc2dts.lib.BoardInfo; 32 | import sopc2dts.lib.boardinfo.BICEthernet; 33 | import sopc2dts.lib.components.BasicComponent; 34 | import sopc2dts.lib.components.altera.TSEMonolithic; 35 | import sopc2dts.lib.components.base.SICEthernet; 36 | 37 | public class BISEthernet extends BISComponentGroup { 38 | private static final long serialVersionUID = -3161034882365005048L; 39 | JTextField txtMac = new JTextField(); 40 | JComboBox cbMII = new JComboBox(); 41 | JComboBox cbPHY = new JComboBox(); 42 | JPanel pnlEdit; 43 | 44 | protected SICEthernet currEth; 45 | public BISEthernet() { 46 | super("Ethernet","ethernet",false); 47 | for(int i=0; i<0x20; i++) 48 | { 49 | cbMII.addItem("" + i); 50 | cbPHY.addItem("" + i); 51 | } 52 | cbPHY.addItem("Auto"); 53 | } 54 | 55 | @Override 56 | protected boolean isSaveNeeded() { 57 | return (currEth != null); 58 | } 59 | 60 | @Override 61 | protected void selectedComponent(BasicComponent comp) { 62 | if(comp instanceof SICEthernet) 63 | { 64 | BICEthernet be = bInfo.getEthernetForChip(comp.getInstanceName()); 65 | int rows = 1; 66 | if(pnlEdit != null) 67 | { 68 | this.remove(pnlEdit); 69 | } 70 | currEth = (SICEthernet)comp; 71 | if(comp instanceof TSEMonolithic) 72 | { 73 | rows += 2; 74 | } 75 | pnlEdit = new JPanel(new GridLayout(rows,2)); 76 | pnlEdit.setBorder(BorderFactory.createTitledBorder(comp.getInstanceName())); 77 | txtMac.setText(be.getMacString()); 78 | pnlEdit.add(new JLabel("MAC-Adress")); 79 | pnlEdit.add(txtMac); 80 | if(comp instanceof TSEMonolithic) 81 | { 82 | cbMII.setSelectedIndex((be.getMiiID() == null ? 0 : be.getMiiID())); 83 | cbPHY.setSelectedIndex((be.getPhyID() == null ? cbPHY.getItemCount() -1 : be.getPhyID())); 84 | pnlEdit.add(new JLabel("MII-Id")); 85 | pnlEdit.add(cbMII); 86 | pnlEdit.add(new JLabel("PHY-Id")); 87 | pnlEdit.add(cbPHY); 88 | } 89 | this.add(pnlEdit, BorderLayout.CENTER); 90 | this.revalidate(); 91 | } 92 | } 93 | 94 | @Override 95 | public void save(BoardInfo bi) { 96 | if(currEth != null) 97 | { 98 | BICEthernet be = bi.getEthernetForChip(currEth.getInstanceName()); 99 | if(currEth instanceof TSEMonolithic) 100 | { 101 | be.setMac(txtMac.getText()); 102 | be.setMiiID(new Integer(cbMII.getSelectedIndex())); 103 | if(cbPHY.getSelectedIndex()<(cbPHY.getItemCount()-1)) 104 | { 105 | be.setPhyID(new Integer(cbPHY.getSelectedIndex())); 106 | } else { 107 | be.setPhyID(null); 108 | } 109 | } else { 110 | be.setMiiID(null); 111 | be.setPhyID(null); 112 | } 113 | bi.setEthernetForChip(be); 114 | } 115 | } 116 | 117 | @Override 118 | public void load(BoardInfo bi) { 119 | if(currEth!=null) 120 | { 121 | selectedComponent(currEth); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /sopc2dts/gui/boardinfo/BISSubComponentTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui.boardinfo; 21 | 22 | import java.awt.BorderLayout; 23 | import java.awt.Color; 24 | import java.awt.event.ActionEvent; 25 | import java.awt.event.ActionListener; 26 | 27 | import javax.swing.JButton; 28 | import javax.swing.JOptionPane; 29 | import javax.swing.JPanel; 30 | import javax.swing.JScrollPane; 31 | import javax.swing.JTable; 32 | import javax.swing.table.TableModel; 33 | 34 | import sopc2dts.lib.BoardInfo; 35 | import sopc2dts.lib.components.BasicComponent; 36 | 37 | public abstract class BISSubComponentTable extends BISComponentGroup implements ActionListener { 38 | private static final long serialVersionUID = -6542453793278126674L; 39 | JPanel pnlCenter = new JPanel(new BorderLayout()); 40 | private JTable tblSubComps = new JTable(); 41 | JButton btnAdd = new JButton("Add"); 42 | JButton btnRemove = new JButton("Remove"); 43 | 44 | public BISSubComponentTable(String name, String group) { 45 | this(name,group,true); 46 | } 47 | public BISSubComponentTable(String name, String group, boolean useWildcard) { 48 | super(name,group,useWildcard); 49 | tblSubComps.setAutoCreateRowSorter(true); 50 | tblSubComps.setShowGrid(true); 51 | tblSubComps.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); 52 | tblSubComps.setGridColor(Color.LIGHT_GRAY); 53 | JPanel pnlBtns = new JPanel(); 54 | btnAdd.setEnabled(false); 55 | btnRemove.setEnabled(false); 56 | btnAdd.addActionListener(this); 57 | btnRemove.addActionListener(this); 58 | pnlBtns.add(btnAdd); 59 | pnlBtns.add(btnRemove); 60 | pnlCenter.add(pnlBtns, BorderLayout.NORTH); 61 | pnlCenter.add(new JScrollPane(tblSubComps), BorderLayout.CENTER); 62 | this.add(pnlCenter, BorderLayout.CENTER); 63 | } 64 | 65 | protected void addSubComponent(TableModel mod) 66 | { 67 | String name = JOptionPane.showInputDialog("Please give the name"); 68 | if(name!=null) 69 | { 70 | addSubComponent(mod, name); 71 | } 72 | } 73 | 74 | public void actionPerformed(ActionEvent e) 75 | { 76 | if(e.getSource().equals(btnAdd)) 77 | { 78 | addSubComponent(tblSubComps.getModel()); 79 | } else if(e.getSource().equals(btnRemove)) 80 | { 81 | int index = tblSubComps.getSelectedRow(); 82 | if(index>=0) 83 | { 84 | if(JOptionPane.showConfirmDialog(this, "Remove selected entry?", 85 | "Confirm remove",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) 86 | { 87 | removeSubComponent(tblSubComps.getModel(), index); 88 | } 89 | } 90 | } 91 | } 92 | protected void selectedComponent(BasicComponent comp) 93 | { 94 | tblSubComps.setModel(tableModelForComponent(comp)); 95 | btnAdd.setEnabled(true); 96 | btnRemove.setEnabled(true); 97 | } 98 | protected abstract void addSubComponent(TableModel mod, String name); 99 | protected abstract void removeSubComponent(TableModel mod, int index); 100 | protected abstract TableModel tableModelForComponent(BasicComponent comp); 101 | protected abstract boolean isSaveNeeded(TableModel tm); 102 | 103 | @Override 104 | public void load(BoardInfo bi) { 105 | bInfo = bi; 106 | if(currComp!=null) 107 | { 108 | selectedComponent(currComp); 109 | } 110 | } 111 | protected abstract void save(BoardInfo bi, TableModel tm); 112 | @Override 113 | public void save(BoardInfo bi) 114 | { 115 | save(bi, tblSubComps.getModel()); 116 | } 117 | protected boolean isSaveNeeded() 118 | { 119 | return isSaveNeeded(tblSubComps.getModel()); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /sopc2dts/gui/boardinfo/BoardInfoSubPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.gui.boardinfo; 21 | 22 | import javax.swing.JPanel; 23 | 24 | import sopc2dts.lib.AvalonSystem; 25 | import sopc2dts.lib.BoardInfo; 26 | 27 | public abstract class BoardInfoSubPanel extends JPanel { 28 | private static final long serialVersionUID = -663003741974804172L; 29 | protected BoardInfo bInfo; 30 | AvalonSystem sys; 31 | 32 | public BoardInfoSubPanel(String name) { 33 | this.setName(name); 34 | } 35 | public boolean setBoardInfoAndSys(BoardInfo bi, AvalonSystem s) 36 | { 37 | bInfo = bi; 38 | sys = s; 39 | load(bi); 40 | if(bInfo != null) 41 | { 42 | return true; 43 | } else { 44 | return false; 45 | } 46 | } 47 | public abstract void save(BoardInfo bi); 48 | public abstract void load(BoardInfo bi); 49 | public abstract void setGuiEnabled(boolean ena); 50 | } 51 | -------------------------------------------------------------------------------- /sopc2dts/lib/BasicElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib; 21 | 22 | import java.util.Vector; 23 | 24 | /** @brief Basic building block for an SOPCInfo hierarchy 25 | * 26 | * This is the base class for all elements in an sopcinfo file we're going to 27 | * use. This is basically \"an object with optional paramters\". 28 | * 29 | * @see sopc2dts.lib.Parameter 30 | * @see sopc2dts.lib.components.BasicComponent 31 | * @see sopc2dts.lib.Connection 32 | * @see sopc2dts.lib.components.Interface 33 | * @author Walter Goossens 34 | * 35 | */ 36 | public class BasicElement { 37 | /** @brief The list of Parameters for this object 38 | * 39 | * This is a list of Parameter objects belonging to this Object. 40 | */ 41 | protected Vector vParameters; 42 | 43 | /** @brief Basic constructor 44 | * 45 | * This contructor creates a new empty BasicElement object. 46 | */ 47 | protected BasicElement() 48 | { 49 | vParameters = new Vector(); 50 | } 51 | 52 | /** @brief Copy constructor 53 | * 54 | * This contructor creates a new BasicElement object with the same parameters 55 | * as be. 56 | * 57 | * @param be The BasicElement to clone 58 | */ 59 | protected BasicElement(BasicElement be) 60 | { 61 | //Shallow copy 62 | this.vParameters = be.vParameters; 63 | } 64 | 65 | /** @brief Adds a parameter 66 | * 67 | * This function adds param to vParameters. 68 | * 69 | * @param param The Parameter to add. 70 | * @return true 71 | */ 72 | public boolean addParam(Parameter param) 73 | { 74 | return vParameters.add(param); 75 | } 76 | /** @brief Remove parameter 77 | * 78 | * This function removes param from vParameters. 79 | * 80 | * @param param The Parameter to remove 81 | * @return true if the parameter was in vParameters 82 | */ 83 | public boolean removeParam(Parameter param) 84 | { 85 | return vParameters.remove(param); 86 | } 87 | /** @brief Get a Parameter by it's name 88 | * 89 | * This function returns the first parameter in vParameters that is named 90 | * name. If you're only interested in the value of the parameter you might 91 | * want to use getParamValByName. 92 | * 93 | * @see getParamValByName 94 | * @param name 95 | * @return The Parameter if found, null otherwise 96 | */ 97 | public Parameter getParamByName(String name) 98 | { 99 | for(Parameter p : vParameters) 100 | { 101 | if(p.getName().equalsIgnoreCase(name)) 102 | { 103 | return p; 104 | } 105 | } 106 | return null; 107 | } 108 | /** @brief Get the Parameter list. 109 | * 110 | * This function directly returns vParameters. In general you should avoid 111 | * using this function and use addParam, removeParam, getParamByName etc. 112 | * There are however some cases (iterating over the parameter list for 113 | * instance) where it is justifiable to use the list. 114 | * 115 | * @return vParameters 116 | */ 117 | public Vector getParams() 118 | { 119 | return vParameters; 120 | } 121 | /** @brief Get named Parameter value 122 | * 123 | * This function uses getParamByName to find a Parameter named name. When 124 | * found it's value is returned. 125 | * 126 | * @param name The name of the parameter 127 | * @return The parameter value or null if the parameter was not found. 128 | */ 129 | public String getParamValByName(String name) 130 | { 131 | Parameter p = getParamByName(name); 132 | if(p!=null) 133 | { 134 | return p.getValue(); 135 | } else { 136 | return null; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /sopc2dts/lib/Connection.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib; 21 | 22 | import sopc2dts.Logger; 23 | import sopc2dts.Logger.LogLevel; 24 | import sopc2dts.lib.AvalonSystem.SystemDataType; 25 | import sopc2dts.lib.components.BasicComponent; 26 | import sopc2dts.lib.components.Interface; 27 | 28 | 29 | public class Connection extends BasicElement { 30 | protected Interface masterInterface; 31 | protected Interface slaveInterface; 32 | protected SystemDataType type = SystemDataType.CONDUIT; 33 | protected long connValue[]; 34 | 35 | public Connection(Interface master, Interface slave) { 36 | this(master,slave, master.getType()); 37 | } 38 | public Connection(Interface master, Interface slave, boolean connect) { 39 | this(master,slave, master.getType(), connect); 40 | } 41 | public Connection(Interface master, Interface slave, SystemDataType t) 42 | { 43 | this(master, slave, t, false); 44 | } 45 | public Connection(Interface master, Interface slave, SystemDataType t, boolean connect) 46 | { 47 | type = t; 48 | if(connect) 49 | { 50 | connectMaster(master); 51 | connectSlave(slave); 52 | } else { 53 | masterInterface = master; 54 | slaveInterface = slave; 55 | } 56 | } 57 | 58 | public Connection(Connection org) { 59 | type = org.type; 60 | masterInterface = org.masterInterface; 61 | slaveInterface = org.slaveInterface; 62 | connValue = org.connValue; 63 | } 64 | 65 | public void connect(Interface intf) 66 | { 67 | if(intf.isMaster()) 68 | { 69 | connectMaster(intf); 70 | } else { 71 | connectSlave(intf); 72 | } 73 | } 74 | public void connectMaster(Interface intf) 75 | { 76 | if(masterInterface!=null) 77 | { 78 | masterInterface.getConnections().remove(this); 79 | } 80 | masterInterface = intf; 81 | masterInterface.getConnections().add(this); 82 | } 83 | public void connectSlave(Interface intf) 84 | { 85 | if(slaveInterface!=null) 86 | { 87 | slaveInterface.getConnections().remove(this); 88 | } 89 | slaveInterface = intf; 90 | slaveInterface.getConnections().add(this); 91 | } 92 | public void disconnect() { 93 | disconnect(masterInterface); 94 | disconnect(slaveInterface); 95 | } 96 | public void disconnect(Interface intf) { 97 | if(intf!=null) { 98 | intf.getConnections().remove(this); 99 | if(slaveInterface==intf) { 100 | slaveInterface = null; 101 | } 102 | if(masterInterface==intf) { 103 | masterInterface = null; 104 | } 105 | } 106 | } 107 | public long[] getConnValue() 108 | { 109 | return connValue; 110 | } 111 | public void setConnValue(long[] val) 112 | { 113 | if(getMasterInterface().getPrimaryWidth()==val.length) { 114 | connValue = val; 115 | } else { 116 | Logger.logln("Passed incorrect connValue parameter!!! Width was " + val.length + " expexted: " + masterInterface.getPrimaryWidth(), LogLevel.ERROR); 117 | } 118 | } 119 | 120 | public Interface getMasterInterface() { 121 | return masterInterface; 122 | } 123 | public BasicComponent getMasterModule() { 124 | if(masterInterface!=null) 125 | { 126 | return masterInterface.getOwner(); 127 | } else { 128 | return null; 129 | } 130 | } 131 | public void setMasterInterface(Interface masterInterface) { 132 | this.masterInterface = masterInterface; 133 | } 134 | 135 | public Interface getSlaveInterface() { 136 | return slaveInterface; 137 | } 138 | 139 | public BasicComponent getSlaveModule() { 140 | if(slaveInterface!=null) 141 | { 142 | return slaveInterface.getOwner(); 143 | } else { 144 | return null; 145 | } 146 | } 147 | 148 | public void setSlaveInterface(Interface slaveInterface) { 149 | this.slaveInterface = slaveInterface; 150 | } 151 | public SystemDataType getType() 152 | { 153 | return type; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /sopc2dts/lib/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib; 21 | 22 | import sopc2dts.lib.devicetree.DTPropHexNumVal; 23 | import sopc2dts.lib.devicetree.DTPropNumVal; 24 | import sopc2dts.lib.devicetree.DTPropStringVal; 25 | import sopc2dts.lib.devicetree.DTPropVal; 26 | import sopc2dts.lib.devicetree.DTProperty; 27 | 28 | public class Parameter { 29 | public enum DataType { NUMBER, UNSIGNED, BOOLEAN, STRING, BOOLEAN_TRUE_WHEN_PRESENT }; 30 | String name; 31 | String value; 32 | DataType dataType = DataType.BOOLEAN; 33 | 34 | public Parameter(String name, String value, DataType t) 35 | { 36 | this.name = name; 37 | this.dataType = t; 38 | switch(t) 39 | { 40 | case BOOLEAN_TRUE_WHEN_PRESENT: { 41 | this.dataType = DataType.BOOLEAN; 42 | this.value = "true"; 43 | } break; 44 | case UNSIGNED: { 45 | if(value.charAt(0) == '-') 46 | { 47 | this.value = String.format("0x%08x", Integer.decode(value)); 48 | } else { 49 | this.value = value; 50 | } 51 | } break; 52 | default: { 53 | this.value = value; 54 | } 55 | } 56 | } 57 | public static DataType getDataTypeByName(String dtName) 58 | { 59 | if(dtName == null) 60 | { 61 | return null; 62 | } else if(dtName.equalsIgnoreCase("BOOLEAN_TRUE_WHEN_PRESENT")) { 63 | return DataType.BOOLEAN_TRUE_WHEN_PRESENT; 64 | } else if(dtName.equalsIgnoreCase("BOOLEAN") || 65 | dtName.equalsIgnoreCase("BOOL")) 66 | { 67 | return DataType.BOOLEAN; 68 | } else if(dtName.equalsIgnoreCase("NUMBER")) 69 | { 70 | return DataType.NUMBER; 71 | } else if(dtName.equalsIgnoreCase("UNSIGNED")) 72 | { 73 | return DataType.UNSIGNED; 74 | } 75 | return null; 76 | } 77 | public String getName() 78 | { 79 | return name; 80 | } 81 | public String getValue() 82 | { 83 | return value; 84 | } 85 | public DataType getType() 86 | { 87 | return dataType; 88 | } 89 | public boolean getValueAsBoolean() { 90 | if(value==null) return false; 91 | if(value.length()==0) return false; 92 | try { 93 | if(Integer.decode(value)==0) 94 | { 95 | return false; 96 | } 97 | } catch (NumberFormatException e) { 98 | if(value.equalsIgnoreCase("false")) 99 | { 100 | return false; 101 | } 102 | } 103 | //Treat all other strings and numbers as true 104 | return true; 105 | } 106 | public DTProperty toDTProperty() 107 | { 108 | return toDTProperty(name, dataType); 109 | } 110 | public DTProperty toDTProperty(String dtsName) 111 | { 112 | return toDTProperty(dtsName, dataType); 113 | } 114 | public DTProperty toDTProperty(String dtsName, DataType dt) 115 | { 116 | DTProperty prop = new DTProperty(dtsName, null,name + " type " + dataType); 117 | DTPropVal propVal = null; 118 | if(dt==null) 119 | { 120 | dt = dataType; 121 | } 122 | switch(dt) 123 | { 124 | case UNSIGNED: { 125 | propVal = new DTPropHexNumVal(Long.decode(value)); 126 | } break; 127 | case NUMBER: { 128 | propVal = new DTPropNumVal(Long.decode(value)); 129 | } break; 130 | case BOOLEAN_TRUE_WHEN_PRESENT: 131 | /* No value needed */ 132 | break; 133 | case BOOLEAN: { 134 | if(!getValueAsBoolean()) 135 | { 136 | prop = null; 137 | } 138 | } break; 139 | case STRING: { 140 | String tmpVal = value.trim(); 141 | if (tmpVal.startsWith("\"")) 142 | { 143 | tmpVal = tmpVal.substring(1); 144 | } 145 | if(tmpVal.endsWith("\"")) 146 | { 147 | tmpVal = tmpVal.substring(0, tmpVal.length()-1); 148 | } 149 | propVal = new DTPropStringVal(tmpVal); 150 | } break; 151 | default:{ 152 | prop = null; 153 | } 154 | } 155 | if((prop != null)&&(propVal!=null)) { 156 | prop.addValue(propVal); 157 | } 158 | return prop; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /sopc2dts/lib/boardinfo/BICEthernet.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2015 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.boardinfo; 21 | 22 | import org.xml.sax.Attributes; 23 | 24 | public class BICEthernet extends BoardInfoComponent { 25 | public static final String TAG_NAME = "Ethernet"; 26 | Integer miiID = null; 27 | Integer phyID = null; 28 | int[] mac = { 0, 0, 0, 0, 0, 0 }; 29 | 30 | public BICEthernet(String iName) { 31 | super(TAG_NAME, iName); 32 | } 33 | public BICEthernet(String tag, Attributes atts) { 34 | super(tag, atts); 35 | String sVal = atts.getValue("mii_id"); 36 | if(sVal != null) 37 | { 38 | miiID = Integer.decode(sVal); 39 | } 40 | sVal = atts.getValue("phy_id"); 41 | if(sVal != null) 42 | { 43 | phyID = Integer.decode(sVal); 44 | } 45 | setMac(atts.getValue("mac")); 46 | } 47 | 48 | public String getXml() { 49 | String res = '<' + TAG_NAME + " name=\"" + instanceName + "\" mac=\"" + getMacString() + "\""; 50 | if(miiID!=null) 51 | { 52 | res += " mii_id=\"" + miiID + "\""; 53 | } 54 | if(phyID!=null) 55 | { 56 | res += " phy_id=\"" + phyID + "\""; 57 | } 58 | res +=">\n"; 59 | return res; 60 | } 61 | public String getMacString() 62 | { 63 | return String.format("%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], 64 | mac[2], mac[3], mac[4], mac[5]); 65 | } 66 | 67 | public Integer getMiiID() { 68 | return miiID; 69 | } 70 | 71 | public void setMiiID(Integer miiID) { 72 | this.miiID = miiID; 73 | } 74 | 75 | public Integer getPhyID() { 76 | return phyID; 77 | } 78 | 79 | public void setPhyID(Integer phyID) { 80 | this.phyID = phyID; 81 | } 82 | 83 | public int[] getMac() { 84 | return mac; 85 | } 86 | 87 | public void setMac(int[] mac) { 88 | if(mac.length == 6) 89 | { 90 | this.mac = mac; 91 | } 92 | } 93 | public void setMac(String sVal) 94 | { 95 | if(sVal != null) 96 | { 97 | String[] sMac = sVal.split(":"); 98 | if(sMac.length==6) 99 | { 100 | for(int i=0; i<6; i++) 101 | { 102 | mac[i] = Integer.parseInt(sMac[i], 16); 103 | } 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /sopc2dts/lib/boardinfo/BICI2C.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 - 2015 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.boardinfo; 21 | 22 | import java.util.Vector; 23 | 24 | import org.xml.sax.Attributes; 25 | import org.xml.sax.SAXException; 26 | 27 | public class BICI2C extends BoardInfoComponent { 28 | public static final String TAG_NAME = "I2CBus"; 29 | Vector vSlaves = new Vector(); 30 | 31 | public BICI2C(String iName) { 32 | super(TAG_NAME, iName); 33 | } 34 | public BICI2C(String tag, Attributes atts) { 35 | super(tag, atts); 36 | instanceName = atts.getValue("master"); 37 | } 38 | public Vector getSlaves() { 39 | return vSlaves; 40 | } 41 | @Override 42 | public String getXml() { 43 | String xml = "\t<" + TAG_NAME; 44 | if(instanceName!=null) { 45 | xml += " master=\"" + instanceName + "\""; 46 | } 47 | xml += ">\n"; 48 | for(I2CSlave s : vSlaves) { 49 | xml += s.getXml(); 50 | } 51 | xml += "\t\n"; 52 | return xml; 53 | } 54 | public void startElement(String uri, String localName, String qName, 55 | Attributes atts) throws SAXException { 56 | if(localName.equals(I2CSlave.TAG_NAME)) 57 | { 58 | vSlaves.add(new I2CSlave(atts)); 59 | } 60 | } 61 | public void setSlaves(Vector vs) { 62 | vSlaves = vs; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sopc2dts/lib/boardinfo/BICSpi.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2015 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.boardinfo; 21 | 22 | import java.util.Vector; 23 | 24 | import org.xml.sax.Attributes; 25 | import org.xml.sax.SAXException; 26 | 27 | public class BICSpi extends BoardInfoComponent { 28 | public static final String TAG_NAME = "SpiMaster"; 29 | Vector vSlaves = new Vector(); 30 | public BICSpi(String iName) { 31 | super(TAG_NAME, iName); 32 | } 33 | public BICSpi(String tag, Attributes atts) { 34 | super(tag, atts); 35 | } 36 | 37 | @Override 38 | public String getXml() { 39 | String res = "\t<" + TAG_NAME + " name=\"" + instanceName + "\">\n"; 40 | for(SpiSlave slave : vSlaves) 41 | { 42 | res += slave.getXml(); 43 | } 44 | res += "\t\n"; 45 | return res; 46 | } 47 | 48 | public Vector getSlaves() { 49 | return vSlaves; 50 | } 51 | public void setSlaves(Vector vSlaves) { 52 | this.vSlaves = vSlaves; 53 | } 54 | public void startElement(String uri, String localName, String qName, 55 | Attributes atts) throws SAXException { 56 | if(localName.equals("SpiSlave")) 57 | { 58 | String className = atts.getValue("class"); 59 | if(className!=null) { 60 | if(className.equals(SpiSlaveMMC.class.getCanonicalName())) 61 | { 62 | vSlaves.add(new SpiSlaveMMC(atts)); 63 | } else { 64 | vSlaves.add(new SpiSlave(atts)); 65 | } 66 | } else { 67 | vSlaves.add(new SpiSlave(atts)); 68 | } 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /sopc2dts/lib/boardinfo/BoardInfoComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2015 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.boardinfo; 21 | 22 | import org.xml.sax.Attributes; 23 | import org.xml.sax.ContentHandler; 24 | import org.xml.sax.Locator; 25 | import org.xml.sax.SAXException; 26 | 27 | public abstract class BoardInfoComponent implements ContentHandler { 28 | String instanceName; 29 | String xmlTagName; 30 | 31 | protected BoardInfoComponent(String tag, String iName) 32 | { 33 | instanceName = iName; 34 | xmlTagName = tag; 35 | } 36 | public BoardInfoComponent(String tag, Attributes atts) 37 | { 38 | this(tag,atts.getValue("name")); 39 | } 40 | public abstract String getXml(); 41 | 42 | public static BoardInfoComponent getBicFor(String localName, Attributes atts) 43 | { 44 | BoardInfoComponent bic = null; 45 | if(localName.equalsIgnoreCase(BICEthernet.TAG_NAME)) 46 | { 47 | bic = new BICEthernet(localName,atts); 48 | } else if(localName.equalsIgnoreCase(BICSpi.TAG_NAME)) 49 | { 50 | bic = new BICSpi(localName, atts); 51 | } else if(localName.equalsIgnoreCase(BICDTAppend.TAG_NAME)) 52 | { 53 | bic = new BICDTAppend(localName, atts); 54 | } else if(localName.equalsIgnoreCase(BICI2C.TAG_NAME)) 55 | { 56 | bic = new BICI2C(localName, atts); 57 | } 58 | return bic; 59 | } 60 | /* Define some ContentHandler functions that are usually not needed when 61 | * parsing boardinfo files, so subclasses don't need to. 62 | */ 63 | public void startElement(String uri, String localName, String qName, 64 | Attributes atts) throws SAXException { 65 | } 66 | public void characters(char[] ch, int start, int length) 67 | throws SAXException { 68 | } 69 | public void endElement(String uri, String localName, String qName) 70 | throws SAXException { 71 | } 72 | public void endDocument() throws SAXException { 73 | } 74 | 75 | public void endPrefixMapping(String prefix) throws SAXException { 76 | } 77 | 78 | public void ignorableWhitespace(char[] ch, int start, int length) 79 | throws SAXException { 80 | } 81 | 82 | public void processingInstruction(String target, String data) 83 | throws SAXException { 84 | } 85 | 86 | public void setDocumentLocator(Locator locator) { 87 | } 88 | 89 | public void skippedEntity(String name) throws SAXException { 90 | } 91 | 92 | public void startDocument() throws SAXException { 93 | } 94 | 95 | public void startPrefixMapping(String prefix, String uri) 96 | throws SAXException { 97 | } 98 | 99 | public String getInstanceName() { 100 | return instanceName; 101 | } 102 | 103 | public String getXmlTagName() { 104 | return xmlTagName; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /sopc2dts/lib/boardinfo/I2CSlave.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.boardinfo; 21 | 22 | import org.xml.sax.Attributes; 23 | 24 | import sopc2dts.lib.BoardInfo; 25 | import sopc2dts.lib.devicetree.DTNode; 26 | import sopc2dts.lib.devicetree.DTPropHexNumVal; 27 | import sopc2dts.lib.devicetree.DTProperty; 28 | 29 | public class I2CSlave implements Comparable { 30 | public static final String TAG_NAME = "I2CChip"; 31 | int addr; 32 | String label; 33 | String name; 34 | 35 | public I2CSlave(Attributes atts) { 36 | this(Integer.decode(atts.getValue("addr")), atts.getValue("name"), atts.getValue("label")); 37 | } 38 | public I2CSlave(int a, String n, String l) { 39 | addr = a; 40 | name = n; 41 | label = l; 42 | } 43 | public String getXml() { 44 | String xml= "\t\t<" + TAG_NAME + " addr=\"" + addr + "\" name=\"" + name + "\""; 45 | if((label != null) && (!label.isEmpty())) { 46 | xml += " label=\"" + label + '"'; 47 | } 48 | xml += "/>\n"; 49 | return xml; 50 | } 51 | public DTNode toDTNode(BoardInfo bi) 52 | { 53 | DTNode node = new DTNode(name + "@0x" + Integer.toHexString(addr),label); 54 | node.addProperty(new DTProperty("compatible", name)); 55 | node.addProperty(new DTProperty("reg", new DTPropHexNumVal(Long.valueOf(addr)))); 56 | return node; 57 | } 58 | public int compareTo(I2CSlave o) { 59 | return this.addr - o.addr; 60 | } 61 | public int getAddr() { 62 | return addr; 63 | } 64 | public void setAddr(int addr) { 65 | this.addr = addr; 66 | } 67 | public String getLabel() { 68 | return label; 69 | } 70 | public void setLabel(String label) { 71 | this.label = label; 72 | } 73 | public String getName() { 74 | return name; 75 | } 76 | public void setName(String name) { 77 | this.name = name; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sopc2dts/lib/boardinfo/SpiSlave.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.boardinfo; 21 | 22 | import org.xml.sax.Attributes; 23 | 24 | import sopc2dts.lib.BoardInfo; 25 | import sopc2dts.lib.devicetree.DTNode; 26 | import sopc2dts.lib.devicetree.DTPropHexNumVal; 27 | import sopc2dts.lib.devicetree.DTProperty; 28 | 29 | public class SpiSlave { 30 | public static String[] slaveTypeNames = { 31 | "MMC Slot", 32 | "Custom", 33 | }; 34 | int spiMaxFrequency = 10000000; //10MHz 35 | int reg; 36 | String name; 37 | String compatible; 38 | boolean cpol; 39 | boolean cpha; 40 | boolean csHigh; 41 | 42 | public SpiSlave(Attributes atts) 43 | { 44 | reg = Integer.decode(atts.getValue("reg")); 45 | name = atts.getValue("name"); 46 | compatible = atts.getValue("compatible"); 47 | spiMaxFrequency = Integer.decode(atts.getValue("maxfreq")); 48 | cpol = Boolean.getBoolean(atts.getValue("cpol")); 49 | cpha = Boolean.getBoolean(atts.getValue("cpha")); 50 | csHigh = Boolean.getBoolean(atts.getValue("csHigh")); 51 | } 52 | public SpiSlave(String name, int reg, String compat) 53 | { 54 | this(name,reg,compat,10000000,false,false,false); 55 | } 56 | 57 | public SpiSlave(String name, int reg, String compat, int max_freq) 58 | { 59 | this(name,reg,compat,max_freq,false,false,false); 60 | } 61 | 62 | protected SpiSlave(String name, int reg, String compat, int max_freq, 63 | boolean cpol, boolean cpha, boolean csHigh) 64 | { 65 | this.name = name; 66 | this.reg = reg; 67 | this.compatible = compat; 68 | this.spiMaxFrequency = max_freq; 69 | this.cpol = cpol; 70 | this.cpha = cpha; 71 | this.csHigh = csHigh; 72 | } 73 | 74 | public String getXml() { 75 | return "\t\t" + 79 | "\n"; 80 | } 81 | public DTNode toDTNode(BoardInfo bi) 82 | { 83 | DTNode node = new DTNode(name + "@0x" + Integer.toHexString(reg)); 84 | node.addProperty(new DTProperty("compatible", compatible)); 85 | node.addProperty(new DTProperty("spi-max-frequency", Long.valueOf(spiMaxFrequency))); 86 | node.addProperty(new DTProperty("reg", new DTPropHexNumVal(Long.valueOf(reg)))); 87 | return node; 88 | } 89 | 90 | public int getSpiMaxFrequency() { 91 | return spiMaxFrequency; 92 | } 93 | public void setSpiMaxFrequency(int spiMaxFrequency) { 94 | this.spiMaxFrequency = spiMaxFrequency; 95 | } 96 | public int getReg() { 97 | return reg; 98 | } 99 | public void setReg(int reg) { 100 | this.reg = reg; 101 | } 102 | public String getName() { 103 | return name; 104 | } 105 | public void setName(String name) { 106 | this.name = name; 107 | } 108 | public String getCompatible() { 109 | return compatible; 110 | } 111 | public void setCompatible(String compatible) { 112 | this.compatible = compatible; 113 | } 114 | public boolean isCpol() { 115 | return cpol; 116 | } 117 | public void setCpol(boolean cpol) { 118 | this.cpol = cpol; 119 | } 120 | public boolean isCpha() { 121 | return cpha; 122 | } 123 | public void setCpha(boolean cpha) { 124 | this.cpha = cpha; 125 | } 126 | public boolean isCsHigh() { 127 | return csHigh; 128 | } 129 | public void setCsHigh(boolean csHigh) { 130 | this.csHigh = csHigh; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /sopc2dts/lib/boardinfo/SpiSlaveMMC.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.boardinfo; 21 | 22 | 23 | import org.xml.sax.Attributes; 24 | 25 | import sopc2dts.lib.BoardInfo; 26 | import sopc2dts.lib.devicetree.DTNode; 27 | import sopc2dts.lib.devicetree.DTProperty; 28 | 29 | public class SpiSlaveMMC extends SpiSlave { 30 | 31 | public SpiSlaveMMC(Attributes atts) 32 | { 33 | super(atts); 34 | } 35 | 36 | public SpiSlaveMMC(int reg) { 37 | this("mmc-slot",reg); 38 | } 39 | 40 | protected SpiSlaveMMC(String name, int reg) { 41 | super(name, reg, "mmc-spi-slot", 30000000); 42 | } 43 | @Override 44 | public DTNode toDTNode(BoardInfo bi) 45 | { 46 | DTNode node = super.toDTNode(bi); 47 | DTProperty p = new DTProperty("voltage-ranges"); 48 | p.addNumberValues(new long[] { 3200L, 3400L }); 49 | node.addProperty(p); 50 | return node; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/InterruptReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Matthew Gerlach 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.Logger; 25 | import sopc2dts.Logger.LogLevel; 26 | import sopc2dts.lib.AvalonSystem; 27 | import sopc2dts.lib.AvalonSystem.SystemDataType; 28 | import sopc2dts.lib.Connection; 29 | import sopc2dts.lib.components.Interface; 30 | import sopc2dts.lib.components.BasicComponent; 31 | import sopc2dts.lib.components.SopcComponentDescription; 32 | 33 | public class InterruptReceiver extends BasicComponent 34 | { 35 | private boolean removed = false; 36 | 37 | public InterruptReceiver(String cName, String iName, String ver, SopcComponentDescription scd) { 38 | super(cName, iName, ver, scd); 39 | } 40 | 41 | protected void removeConnection(Connection conn) 42 | { 43 | conn.disconnect(); 44 | } 45 | @Override 46 | public boolean removeFromSystemIfPossible(AvalonSystem sys) 47 | { 48 | if (!removed) { 49 | removed = true; 50 | Vector vIrqMasters = getInterfaces(SystemDataType.INTERRUPT, true); 51 | if (vIrqMasters.size() != 1) { 52 | Logger.logln("Invalid number of interrupt receivers: "+vIrqMasters, LogLevel.ERROR); 53 | return false; 54 | } 55 | Interface irqMaster = vIrqMasters.firstElement(); 56 | Logger.logln("irq receiver is " + irqMaster.getName(),LogLevel.DEBUG); 57 | while(!irqMaster.getConnections().isEmpty()) { 58 | removeConnection(irqMaster.getConnections().firstElement()); 59 | } 60 | return true; 61 | } else { 62 | return false; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/MemoryBlock.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components; 21 | 22 | public class MemoryBlock { 23 | long base[]; 24 | long size[]; 25 | BasicComponent owner; 26 | public MemoryBlock(BasicComponent owner, long base[], long size[]) 27 | { 28 | this.base = base; 29 | this.size = size; 30 | this.owner = owner; 31 | } 32 | public long[] getBase() { 33 | return base; 34 | } 35 | public void setStart(long[] base) { 36 | this.base = base; 37 | } 38 | public long[] getSize() { 39 | return size; 40 | } 41 | public void setSize(long[] size) { 42 | this.size = size; 43 | } 44 | public BasicComponent getModule() { 45 | return owner; 46 | } 47 | public String getModuleName() { 48 | return owner.getInstanceName(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/A10InterfaceGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2015 Matthew Gerlach 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.Logger; 25 | import sopc2dts.Logger.LogLevel; 26 | import sopc2dts.lib.AvalonSystem; 27 | import sopc2dts.lib.components.BasicComponent; 28 | import sopc2dts.lib.components.Interface; 29 | import sopc2dts.lib.components.SopcComponentDescription; 30 | 31 | public class A10InterfaceGenerator extends BasicComponent 32 | { 33 | private boolean removed = false; 34 | 35 | public A10InterfaceGenerator(String cName, String iName, String ver, SopcComponentDescription scd) { 36 | super(cName, iName, ver, scd); 37 | } 38 | private void moveEmacs(AvalonSystem sys) 39 | { 40 | final String[] signal_suffix = {"", "_md_clk", "_rx_clk_in", "_tx_clk_in", "_gtx_clk", "_tx_reset", "_rx_reset"}; 41 | String hpsName = null; 42 | Vector vHPS = sys.getComponentsByClass("altera_arria10_hps"); 43 | for(int i=0; i 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.Logger; 23 | import sopc2dts.Logger.LogLevel; 24 | import sopc2dts.lib.AvalonSystem; 25 | import sopc2dts.lib.SopcComponentLib; 26 | import sopc2dts.lib.components.BasicComponent; 27 | import sopc2dts.lib.components.base.SICFlash; 28 | import sopc2dts.lib.components.base.SICUnknown; 29 | 30 | public class GenericTristateController extends BasicComponent { 31 | 32 | public GenericTristateController(String cName, String iName, String ver) { 33 | super(cName, iName, ver, new SICUnknown(cName)); 34 | } 35 | 36 | /** 37 | * This is kinda abusing the function, because we _will_ try to remove ourselve 38 | * but also add ourselves in a new form.... 39 | */ 40 | @Override 41 | public boolean removeFromSystemIfPossible(AvalonSystem sys) 42 | { 43 | boolean bChanged = false; 44 | String driverType = getParamValByName(BasicComponent.EMBSW_CONF + ".softwareDriver"); 45 | if(driverType==null) 46 | { 47 | driverType = getParamValByName(BasicComponent.EMBSW_CONF + ".hwClassnameDriverSupportDefault"); 48 | } 49 | if(driverType==null) 50 | { 51 | Logger.logln("GenericTristateController: " + getInstanceName() 52 | + " failed to detect driver type.", LogLevel.WARNING); 53 | } else { 54 | if(driverType.equalsIgnoreCase("altera_avalon_cfi_flash_driver") || 55 | driverType.equalsIgnoreCase("altera_avalon_cfi_flash")) 56 | { 57 | Logger.logln("GenericTristateController: " + getInstanceName() 58 | + " seems to be a CFI-Flash chip.", LogLevel.INFO); 59 | SICFlash flash = new SICFlash(this); 60 | 61 | flash.setScd(SopcComponentLib.getInstance().getScdByClassName("altera_avalon_cfi_flash")); 62 | sys.removeSystemComponent(this); 63 | sys.addSystemComponent(flash); 64 | bChanged = true; 65 | } else if(driverType.equalsIgnoreCase("altera_avalon_lan91c111")) 66 | { 67 | Logger.logln("GenericTristateController: " + getInstanceName() 68 | + " seems to be a SMSC LAN91c111 chip.", LogLevel.INFO); 69 | SICLan91c111 lan = new SICLan91c111(this); 70 | 71 | lan.setScd(SopcComponentLib.getInstance().getScdByClassName("altera_avalon_lan91c111")); 72 | sys.removeSystemComponent(this); 73 | sys.addSystemComponent(lan); 74 | bChanged = true; 75 | } else { 76 | Logger.logln("GenericTristateController: " + getInstanceName() 77 | + " is of unsupported type: " + driverType, LogLevel.WARNING); 78 | } 79 | } 80 | return bChanged; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/InterfaceGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Matthew Gerlach 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.components.Interface; 24 | import sopc2dts.lib.components.BasicComponent; 25 | import sopc2dts.lib.components.SopcComponentDescription; 26 | import sopc2dts.lib.components.base.ClockSource; 27 | 28 | public class InterfaceGenerator extends BasicComponent 29 | { 30 | static SopcComponentDescription h2f_userclk_scd = new SopcComponentDescription("clock", "clock", "altr", "clock"); 31 | private boolean removed = false; 32 | 33 | public InterfaceGenerator(String cName, String iName, String ver, SopcComponentDescription scd) { 34 | super(cName, iName, ver, scd); 35 | } 36 | private void removeUserNClock(int num, AvalonSystem sys) 37 | { 38 | String ifName = String.format("h2f_user%d_clock", num); 39 | Interface intf = getInterfaceByName(ifName); 40 | if (intf != null) { 41 | getInterfaces().remove(intf); 42 | ClockSource newclk = new ClockSource(ifName, ifName, null, h2f_userclk_scd); 43 | newclk.addInterface(intf); 44 | } 45 | } 46 | @Override 47 | public boolean removeFromSystemIfPossible(AvalonSystem sys) 48 | { 49 | if (!removed) { 50 | removed = true; 51 | for (int i = 0; i < 3; i++) { 52 | removeUserNClock(i, sys); 53 | } 54 | return true; 55 | } else { 56 | return false; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/InterruptBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Matthew Gerlach 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.Logger; 23 | import sopc2dts.Logger.LogLevel; 24 | import sopc2dts.lib.components.InterruptReceiver; 25 | import sopc2dts.lib.AvalonSystem.SystemDataType; 26 | import sopc2dts.lib.Connection; 27 | import sopc2dts.lib.components.Interface; 28 | import sopc2dts.lib.components.SopcComponentDescription; 29 | 30 | public class InterruptBridge extends InterruptReceiver 31 | { 32 | private boolean removed = false; 33 | 34 | public InterruptBridge(String cName, String iName, String ver, SopcComponentDescription scd) { 35 | super(cName, iName, ver, scd); 36 | } 37 | private Interface getIrqSlaveInterfaceWithBridgeOffset(long off) { 38 | for (Interface intf : getInterfaces(SystemDataType.INTERRUPT,false)) { 39 | String offset = intf.getParamValByName("bridgedReceiverOffset"); 40 | if(offset!=null) { 41 | if(Long.decode(offset) == off) { 42 | return intf; 43 | } 44 | } else { 45 | if(intf.getName().equalsIgnoreCase("sender" + off + "_irq")) { 46 | return intf; 47 | } 48 | } 49 | } 50 | return null; 51 | } 52 | protected void removeConnection(Connection conn) 53 | { 54 | Interface irqSlave = getIrqSlaveInterfaceWithBridgeOffset(conn.getConnValue()[0]); 55 | if(irqSlave == null) { 56 | Logger.logln(this, "Failed to find irqSlave interface responding to nr: " + conn.getConnValue()[0], LogLevel.ERROR); 57 | } else { 58 | /* Connect upstream and downstream directly */ 59 | while(!irqSlave.getConnections().isEmpty()) { 60 | irqSlave.getConnections().firstElement().connect(conn.getSlaveInterface()); 61 | } 62 | } 63 | /* Dispose of useless connection */ 64 | conn.disconnect(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/InterruptLatencyCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Matthew Gerlach 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.Logger; 23 | import sopc2dts.Logger.LogLevel; 24 | import sopc2dts.lib.components.InterruptReceiver; 25 | import sopc2dts.lib.AvalonSystem.SystemDataType; 26 | import sopc2dts.lib.Connection; 27 | import sopc2dts.lib.components.Interface; 28 | import sopc2dts.lib.components.SopcComponentDescription; 29 | 30 | public class InterruptLatencyCounter extends InterruptReceiver 31 | { 32 | 33 | public InterruptLatencyCounter(String cName, String iName, String ver, SopcComponentDescription scd) { 34 | super(cName, iName, ver, scd); 35 | } 36 | 37 | protected void removeConnection(Connection conn) 38 | { 39 | Interface irq_sender = conn.getSlaveInterface(); 40 | Interface new_sender = new Interface(irq_sender.getOwner().getInstanceName(),SystemDataType.INTERRUPT,false,this); 41 | addInterface(new_sender); 42 | conn.disconnect(); 43 | new_sender.setConnections(irq_sender.getConnections()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/PCIeCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2016 Tien Hock Loh 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.lib.components.BasicComponent; 23 | import sopc2dts.lib.components.SopcComponentDescription; 24 | import sopc2dts.lib.components.base.SCDSelfDescribing; 25 | 26 | public class PCIeCompiler { 27 | 28 | public static BasicComponent getPCIeComponent(BasicComponent comp) { 29 | if(comp.getClassName().equalsIgnoreCase("altera_pcie_a10_hip") || 30 | comp.getClassName().equalsIgnoreCase("altera_pcie_cv_hip_avmm") || 31 | comp.getClassName().equalsIgnoreCase("altera_pcie_av_hip_avmm")) { 32 | if(comp.getScd().getDevice().equalsIgnoreCase("pcie-root-port")) { 33 | return new PCIeRootPort(comp); 34 | } 35 | } 36 | return comp; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/SICEpcs.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.lib.AvalonSystem; 25 | import sopc2dts.lib.AvalonSystem.SystemDataType; 26 | import sopc2dts.lib.BoardInfo; 27 | import sopc2dts.lib.Connection; 28 | import sopc2dts.lib.SopcComponentLib; 29 | import sopc2dts.lib.components.Interface; 30 | import sopc2dts.lib.components.base.SICFlash; 31 | import sopc2dts.lib.devicetree.DTHelper; 32 | import sopc2dts.lib.devicetree.DTNode; 33 | import sopc2dts.lib.devicetree.DTProperty; 34 | 35 | public class SICEpcs extends SICFlash { 36 | boolean bAddressFixed = false; 37 | public SICEpcs(String cName, String iName, String ver) { 38 | super(cName, iName, ver, SopcComponentLib.getInstance().getScdByClassName("altera_avalon_spi")); 39 | } 40 | 41 | @Override 42 | public DTNode toDTNode(BoardInfo bi, Connection conn) 43 | { 44 | DTNode node = super.toDTNode(bi, conn); 45 | node.addProperty(new DTProperty("#address-cells", 1L)); 46 | node.addProperty(new DTProperty("#size-cells", 0L)); 47 | DTNode m25p80 = new DTNode("m25p80@0"); 48 | m25p80.addProperty(new DTProperty("compatible", "m25p80")); 49 | m25p80.addProperty(new DTProperty("spi-max-frequency", 25000000L)); 50 | m25p80.addProperty(new DTProperty("reg", 0L)); 51 | addPartitionsToDTNode(bi, m25p80); 52 | node.addChild(m25p80); 53 | return node; 54 | } 55 | 56 | @Override 57 | public boolean removeFromSystemIfPossible(AvalonSystem sys) 58 | { 59 | if(!bAddressFixed) { 60 | bAddressFixed = true; 61 | try { 62 | long regOffset = Long.decode(getParamValByName(EMBSW_CMACRO + ".REGISTER_OFFSET")); 63 | if(regOffset>0) { 64 | Vector vintf = getInterfaces(SystemDataType.MEMORY_MAPPED, false); 65 | for(Interface intf : vintf) { 66 | for(Connection conn : intf.getConnections()) { 67 | conn.setConnValue(DTHelper.longArrAdd(conn.getConnValue(), regOffset)); 68 | } 69 | intf.setInterfaceValue(DTHelper.longArrSubtract(intf.getInterfaceValue(), regOffset)); 70 | } 71 | } 72 | } catch(Exception e) { 73 | } 74 | return true; 75 | } else { 76 | return false; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/SICLan91c111.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.lib.Connection; 23 | import sopc2dts.lib.components.SopcComponentDescription; 24 | import sopc2dts.lib.components.BasicComponent; 25 | import sopc2dts.lib.components.base.SICEthernet; 26 | import sopc2dts.lib.devicetree.DTHelper; 27 | 28 | public class SICLan91c111 extends SICEthernet { 29 | 30 | public SICLan91c111(BasicComponent comp) { 31 | super(comp); 32 | } 33 | 34 | public SICLan91c111(String cName, String iName, String ver, SopcComponentDescription scd) { 35 | super(cName, iName, ver, scd); 36 | } 37 | 38 | @Override 39 | protected long[] getAddrFromConnection(Connection conn) 40 | { 41 | //Yes this is REALLY ugly. But it just might work :) 42 | long regOffset; 43 | try { 44 | String v = getParamValByName("registerOffset"); 45 | if (v == null) 46 | v = getParamValByName(EMBSW_CMACRO + ".LAN91C111_REGISTERS_OFFSET"); 47 | 48 | regOffset = Long.decode(v); 49 | } catch(Exception e) 50 | { 51 | regOffset = 0; 52 | } 53 | return DTHelper.longArrAdd(conn.getConnValue(), regOffset); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/SICSgdma.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.lib.BoardInfo; 23 | import sopc2dts.lib.Connection; 24 | import sopc2dts.lib.components.SopcComponentDescription; 25 | import sopc2dts.lib.components.BasicComponent; 26 | import sopc2dts.lib.devicetree.DTNode; 27 | import sopc2dts.lib.devicetree.DTProperty; 28 | 29 | public class SICSgdma extends BasicComponent { 30 | 31 | public static final String[] TYPE_NAMES = { 32 | "MEMORY_TO_MEMORY", 33 | "MEMORY_TO_STREAM", 34 | "STREAM_TO_MEMORY", 35 | "STREAM_TO_STREAM", 36 | "UNKNOWN" 37 | }; 38 | 39 | public SICSgdma(String cName, String iName, String ver, SopcComponentDescription scd) { 40 | super(cName, iName, ver, scd); 41 | } 42 | 43 | @Override 44 | public DTNode toDTNode(BoardInfo bi, Connection conn) 45 | { 46 | DTNode node = super.toDTNode(bi, conn); 47 | int iType = 0; 48 | while(iType<(TYPE_NAMES.length-1)) 49 | { 50 | if(TYPE_NAMES[iType].equals(getParamValByName("transferMode"))) 51 | { 52 | break; 53 | } 54 | iType++; 55 | } 56 | node.addProperty(new DTProperty("type",null,TYPE_NAMES[iType],Long.valueOf(iType))); 57 | return node; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/SICTrippleSpeedEthernet.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.Logger; 23 | import sopc2dts.Logger.LogLevel; 24 | import sopc2dts.lib.AvalonSystem; 25 | import sopc2dts.lib.Parameter; 26 | import sopc2dts.lib.boardinfo.BICEthernet; 27 | import sopc2dts.lib.components.BasicComponent; 28 | import sopc2dts.lib.components.Interface; 29 | import sopc2dts.lib.components.SopcComponentDescription; 30 | import sopc2dts.lib.components.base.SICEthernet; 31 | import sopc2dts.lib.devicetree.DTNode; 32 | import sopc2dts.lib.devicetree.DTPropHexNumVal; 33 | import sopc2dts.lib.devicetree.DTPropNumVal; 34 | import sopc2dts.lib.devicetree.DTPropPHandleVal; 35 | import sopc2dts.lib.devicetree.DTPropStringVal; 36 | import sopc2dts.lib.devicetree.DTProperty; 37 | 38 | public class SICTrippleSpeedEthernet extends SICEthernet { 39 | 40 | private boolean removed = false; 41 | 42 | public SICTrippleSpeedEthernet(String cName, String iName, String ver, SopcComponentDescription scd) { 43 | super(cName, iName, ver, scd); 44 | } 45 | 46 | protected BasicComponent getDMAEngineForIntf(Interface intf) 47 | { 48 | if((intf!=null) && (intf.getConnections().size()>0)) 49 | { 50 | BasicComponent comp = null; 51 | if(intf.isMaster()) 52 | { 53 | comp = intf.getConnections().firstElement().getSlaveModule(); 54 | } else { 55 | comp = intf.getConnections().firstElement().getMasterModule(); 56 | } 57 | return comp; 58 | } else if (intf!=null) 59 | { 60 | Logger.logln("Interface " + intf.getName() + " has no connections.", LogLevel.INFO); 61 | } 62 | return null; 63 | } 64 | 65 | @Override 66 | public boolean removeFromSystemIfPossible(AvalonSystem sys) 67 | { 68 | if (!removed) { 69 | removed = true; 70 | String phyModeString = getParamValByName("ifGMII"); 71 | String phyModeStringsgmii = getParamValByName("enable_sgmii"); 72 | setPhyMode(PhyMode.RGMII); 73 | if(phyModeStringsgmii.equals("true")) 74 | { 75 | Logger.logln("enable_sgmii"); 76 | setPhyMode(PhyMode.SGMII); 77 | } else { 78 | if(phyModeString.equals("MII")) 79 | { 80 | setPhyMode(PhyMode.MII); 81 | } else if(phyModeString.equals("MII_GMII")) 82 | { 83 | setPhyMode(PhyMode.GMII); 84 | } else if(phyModeString.equals("RGMII")) 85 | { 86 | setPhyMode(PhyMode.RGMII); 87 | } 88 | } 89 | return true; 90 | } else { 91 | return false; 92 | } 93 | } 94 | 95 | private boolean isMdioMaster() { 96 | Parameter param = getParamByName("useMDIO"); 97 | if(param == null) { 98 | param = getParamByName(EMBSW_CMACRO+".USE_MDIO"); 99 | } 100 | if(param != null) { 101 | return param.getValueAsBoolean(); 102 | } 103 | 104 | return false; 105 | } 106 | 107 | @Override 108 | protected DTNode getMdioNode(BICEthernet be) { 109 | if(this.isMdioMaster()) { 110 | DTNode mdioNode = new DTNode("mdio", getInstanceName()+"_mdio"); 111 | mdioNode.addProperty(new DTProperty("compatible", new DTPropStringVal( "altr,tse-mdio"))); 112 | mdioNode.addProperty(new DTProperty("#address-cells", new DTPropNumVal(1))); 113 | mdioNode.addProperty(new DTProperty("#size-cells", new DTPropNumVal(0))); 114 | 115 | if(be.getPhyID() != null) { 116 | DTNode mdioPhyNode = new DTNode("phy", getInstanceName()+"_phy"); 117 | mdioPhyNode.addProperty(new DTProperty("reg", new DTPropHexNumVal(be.getPhyID()))); 118 | mdioNode.addProperty(new DTProperty("phy-handle", new DTPropPHandleVal(getInstanceName()+"_phy"))); 119 | mdioNode.addChild(mdioPhyNode); 120 | } 121 | 122 | return mdioNode; 123 | } 124 | 125 | return null; 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/VIPFrameBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.BoardInfo; 24 | import sopc2dts.lib.Connection; 25 | import sopc2dts.lib.Parameter; 26 | import sopc2dts.lib.components.BasicComponent; 27 | import sopc2dts.lib.components.Interface; 28 | import sopc2dts.lib.components.SopcComponentDescription; 29 | import sopc2dts.lib.devicetree.DTNode; 30 | import sopc2dts.lib.devicetree.DTProperty; 31 | 32 | public class VIPFrameBuffer extends BasicComponent { 33 | SICSgdma dmaEngine = null; 34 | 35 | public VIPFrameBuffer(String cName, String iName, String ver, SopcComponentDescription scd) { 36 | super(cName, iName, ver, scd); 37 | } 38 | protected void encapsulateSGDMA(SICSgdma dma, AvalonSystem sys) 39 | { 40 | sys.removeSystemComponent(dma); 41 | //CSR MM interface 42 | Interface intf = dma.getInterfaceByName("csr"); 43 | dma.removeInterface(intf); 44 | vInterfaces.add(intf); 45 | intf.setOwner(this); 46 | //IRQ 47 | intf = dma.getInterfaceByName("csr_irq"); 48 | dma.removeInterface(intf); 49 | vInterfaces.add(intf); 50 | intf.setOwner(this); 51 | } 52 | public boolean removeFromSystemIfPossible(AvalonSystem sys) 53 | { 54 | Interface intf = getInterfaceByName("in"); 55 | for(Connection conn : intf.getConnections()) { 56 | if((dmaEngine == null) && (conn.getMasterModule() instanceof SICSgdma)) { 57 | dmaEngine = (SICSgdma)conn.getMasterModule(); 58 | encapsulateSGDMA(dmaEngine, sys); 59 | return true; 60 | } 61 | } 62 | return false; 63 | } 64 | @Override 65 | public DTNode toDTNode(BoardInfo bi, Connection conn) 66 | { 67 | DTNode node = super.toDTNode(bi, conn); 68 | Long bpp = 32L; 69 | Parameter symbolWidth = getParamByName("DATA_STREAM_BIT_WIDTH"); 70 | Parameter numSymbols = getParamByName("BEATS_PER_PIXEL"); 71 | if((symbolWidth!=null) && (numSymbols!=null)) { 72 | bpp = Long.decode(symbolWidth.getValue()) * Long.decode(numSymbols.getValue()); 73 | } 74 | node.addProperty(new DTProperty("bpp", bpp)); 75 | return node; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/VIPMixer.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera; 21 | 22 | import sopc2dts.lib.AvalonSystem; 23 | import sopc2dts.lib.BoardInfo; 24 | import sopc2dts.lib.AvalonSystem.SystemDataType; 25 | import sopc2dts.lib.Connection; 26 | import sopc2dts.lib.components.BasicComponent; 27 | import sopc2dts.lib.components.Interface; 28 | import sopc2dts.lib.components.SopcComponentDescription; 29 | import sopc2dts.lib.devicetree.DTNode; 30 | import sopc2dts.lib.devicetree.DTProperty; 31 | 32 | public class VIPMixer extends BasicComponent { 33 | boolean connectedOthers = false; 34 | public VIPMixer(String cName, String iName, String ver, SopcComponentDescription scd) { 35 | super(cName, iName, ver, scd); 36 | } 37 | 38 | @Override 39 | public DTNode toDTNode(BoardInfo bi, Connection conn) 40 | { 41 | DTNode node = super.toDTNode(bi, conn); 42 | node.addProperty(new DTProperty("num-channels", Long.valueOf(getInterfaces(SystemDataType.STREAMING, false).size()))); 43 | return node; 44 | } 45 | 46 | @Override 47 | public boolean removeFromSystemIfPossible(AvalonSystem sys) 48 | { 49 | if(!connectedOthers) { 50 | connectedOthers=true; 51 | Interface ifMaster = getInterfaceByName("dout"); 52 | for(Connection conn2NewSlave : ifMaster.getConnections()) { 53 | for(Interface ifSlave : getInterfaces(SystemDataType.STREAMING, false)) 54 | { 55 | for(Connection conn2NewMaster : ifSlave.getConnections()) { 56 | new Connection(conn2NewMaster.getMasterInterface(), conn2NewSlave.getSlaveInterface(), SystemDataType.STREAMING, true); 57 | } 58 | } 59 | } 60 | return true; 61 | } else { 62 | return false; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/hps/SocFpgaGateClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera.hps; 21 | 22 | import sopc2dts.lib.BoardInfo; 23 | import sopc2dts.lib.Connection; 24 | import sopc2dts.lib.components.SopcComponentDescription; 25 | import sopc2dts.lib.components.altera.hps.ClockManager.ClockManagerGateClk; 26 | import sopc2dts.lib.devicetree.DTNode; 27 | import sopc2dts.lib.devicetree.DTProperty; 28 | 29 | public class SocFpgaGateClock extends VirtualClockElement { 30 | 31 | long[] gateReg; 32 | long[] divReg; 33 | Long fixedDivider; 34 | 35 | public SocFpgaGateClock(ClockManagerGateClk cmGClk, String version, SopcComponentDescription scdGClk) { 36 | super(cmGClk.name, cmGClk.name,version,scdGClk); 37 | gateReg = null; 38 | divReg = cmGClk.divReg; 39 | fixedDivider = cmGClk.fixedDivider; 40 | } 41 | @Override 42 | public DTNode toDTNode(BoardInfo bi, Connection conn) { 43 | DTNode node = super.toDTNode(bi, conn); 44 | if(gateReg!=null) { 45 | DTProperty prop = new DTProperty("clk-gate"); 46 | prop.addHexValues(gateReg); 47 | node.addProperty(prop); 48 | } 49 | if(divReg!=null) { 50 | DTProperty prop = new DTProperty("div-reg"); 51 | prop.addHexValues(divReg); 52 | node.addProperty(prop); 53 | } 54 | if(fixedDivider!=null) { 55 | node.addProperty(new DTProperty("fixed-divider", fixedDivider.longValue())); 56 | } 57 | return node; 58 | } 59 | @Override 60 | protected String getAddrFromConnectionStr(Connection conn) { 61 | if(conn == null) { 62 | if(gateReg!=null) { 63 | return Long.toHexString(gateReg[0]) + "." + gateReg[1]; 64 | } else if(divReg!=null) { 65 | return Long.toHexString(divReg[0]) + "." + divReg[1]; 66 | } else { 67 | return "00"; 68 | } 69 | } else { 70 | return super.getAddrFromConnectionStr(conn); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/hps/SocFpgaPeripClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera.hps; 21 | 22 | import sopc2dts.lib.BoardInfo; 23 | import sopc2dts.lib.Connection; 24 | import sopc2dts.lib.components.SopcComponentDescription; 25 | import sopc2dts.lib.devicetree.DTNode; 26 | import sopc2dts.lib.devicetree.DTPropHexNumVal; 27 | import sopc2dts.lib.devicetree.DTProperty; 28 | 29 | public class SocFpgaPeripClock extends VirtualClockElement { 30 | 31 | Long fixedDivider; 32 | long[] divReg; 33 | /* Constructor for discovered pll */ 34 | public SocFpgaPeripClock(String cName, String iName, String ver, 35 | SopcComponentDescription scd) { 36 | super(cName, iName, ver, scd); 37 | } 38 | /* Constructor for virtual pll */ 39 | public SocFpgaPeripClock(String cName, String iName, String ver, Long reg, Long div, long[]divreg, SopcComponentDescription scdPClk) { 40 | super(cName, iName, ver, scdPClk, reg); 41 | fixedDivider = div; 42 | divReg = divreg; 43 | } 44 | public DTNode toDTNode(BoardInfo bi, Connection conn) { 45 | DTNode node = super.toDTNode(bi, conn); 46 | Long reg = getRegOffset(); 47 | if (reg != null) { 48 | node.addProperty(new DTProperty("reg", new DTPropHexNumVal(reg.longValue())), true); 49 | } 50 | if(fixedDivider!=null) { 51 | node.addProperty(new DTProperty("fixed-divider", fixedDivider.longValue())); 52 | } 53 | if (divReg != null) { 54 | DTProperty prop = new DTProperty("div-reg"); 55 | prop.addHexValues(divReg); 56 | node.addProperty(prop); 57 | } 58 | return node; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/altera/hps/SocFpgaPllClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.altera.hps; 21 | 22 | import sopc2dts.Logger; 23 | import sopc2dts.Logger.LogLevel; 24 | import sopc2dts.lib.BoardInfo; 25 | import sopc2dts.lib.Connection; 26 | import sopc2dts.lib.AvalonSystem.SystemDataType; 27 | import sopc2dts.lib.components.Interface; 28 | import sopc2dts.lib.components.SopcComponentDescription; 29 | import sopc2dts.lib.devicetree.DTNode; 30 | import sopc2dts.lib.devicetree.DTProperty; 31 | 32 | public class SocFpgaPllClock extends VirtualClockElement { 33 | 34 | /* Constructor for virtual pll */ 35 | public SocFpgaPllClock(String cName, String iName, String ver, SopcComponentDescription scdPLL) { 36 | super(cName, iName, ver, scdPLL); 37 | Interface mmIf = new Interface(MM_MASTER_NAME, SystemDataType.MEMORY_MAPPED, true,this); 38 | mmIf.setSecondaryWidth(0); 39 | mmIf.setInterfaceValue(new long[]{}); 40 | vInterfaces.add(mmIf); 41 | } 42 | @Override 43 | public DTNode toDTNode(BoardInfo bi, Connection conn) { 44 | DTNode node = super.toDTNode(bi, conn); 45 | node.addProperty(new DTProperty("#address-cells", 1L)); 46 | node.addProperty(new DTProperty("#size-cells", 0L)); 47 | return node; 48 | } 49 | 50 | public void addClockOutput(SocFpgaPeripClock pClk) { 51 | /* Reg first */ 52 | Interface master = getRegInterface(true); 53 | Interface slave = pClk.getRegInterface(false); 54 | if((master!=null)&&(slave!=null)) { 55 | Connection connMM = new Connection(master, slave, true); 56 | connMM.setConnValue(new long[]{pClk.getRegOffset()}); 57 | /* Then clocks */ 58 | pClk.addClockInput(getClockInterface(true)); 59 | } else { 60 | Logger.logln(this, "can't find interface to connect this register to", LogLevel.WARNING); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/arm/CortexA9GIC.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.arm; 21 | 22 | import sopc2dts.Logger; 23 | import sopc2dts.Logger.LogLevel; 24 | import sopc2dts.lib.AvalonSystem; 25 | import sopc2dts.lib.Connection; 26 | import sopc2dts.lib.AvalonSystem.SystemDataType; 27 | import sopc2dts.lib.components.BasicComponent; 28 | import sopc2dts.lib.components.Interface; 29 | import sopc2dts.lib.components.SopcComponentDescription; 30 | 31 | public class CortexA9GIC extends BasicComponent { 32 | public static final int GIC_IRQ_CLASS_SPI = 0; 33 | public static final int GIC_IRQ_CLASS_PPI = 1; 34 | public static final int GIC_IRQ_TYPE_RISING = 1; 35 | public static final int GIC_IRQ_TYPE_FALLING = 2; 36 | public static final int GIC_IRQ_TYPE_HIGH = 4; 37 | public static final int GIC_IRQ_TYPE_LOW = 8; 38 | private boolean irqsRenumbered = false; 39 | static SopcComponentDescription scdArmGIC = 40 | new SopcComponentDescription("arm_gic", "intc", "arm", "cortex-a9-gic"); 41 | 42 | public CortexA9GIC(String iName, String ver) { 43 | super("arm_gic", iName, ver, scdArmGIC); 44 | } 45 | static int getIrqClassFromIf(Interface intf) { 46 | final String RX_TYPE = EMBSW_DTS_IRQ + ".rx_type"; 47 | int irqClass = (intf.getName().equalsIgnoreCase("arm_gic_ppi") ? 48 | GIC_IRQ_CLASS_PPI : GIC_IRQ_CLASS_SPI); 49 | String irqClassStr= intf.getParamValByName(RX_TYPE); 50 | if(irqClassStr!=null) { 51 | if (irqClassStr.contentEquals("arm_gic_ppi")) { 52 | irqClass = GIC_IRQ_CLASS_PPI; 53 | } else if (irqClassStr.contentEquals("arm_gic_spi")) { 54 | irqClass = GIC_IRQ_CLASS_SPI; 55 | } else { 56 | Logger.logln("unknown " + RX_TYPE + ": " + irqClassStr,LogLevel.ERROR); 57 | } 58 | } 59 | return irqClass; 60 | } 61 | 62 | static int getIrqTypeFromIf(Interface intf) { 63 | final String TX_TYPE = EMBSW_DTS_IRQ + ".tx_type"; 64 | int irqType = GIC_IRQ_TYPE_HIGH; 65 | String irqTypeStr = intf.getParamValByName(TX_TYPE); 66 | if (irqTypeStr!=null) { 67 | if(irqTypeStr.contentEquals("ACTIVE_HIGH")) { 68 | irqType = GIC_IRQ_TYPE_HIGH; 69 | } else if (irqTypeStr.contentEquals("ACTIVE_LOW")) { 70 | irqType = GIC_IRQ_TYPE_LOW; 71 | } else if (irqTypeStr.contentEquals("FALLING_EDGE")) { 72 | irqType = GIC_IRQ_TYPE_FALLING; 73 | } else if (irqTypeStr.contentEquals("RISING_EDGE")) { 74 | irqType = GIC_IRQ_TYPE_RISING; 75 | } else { 76 | Logger.logln("unknown " + TX_TYPE + ": " + irqTypeStr,LogLevel.ERROR); 77 | } 78 | } 79 | String txMask = intf.getParamValByName(EMBSW_DTS_IRQ + ".tx_mask"); 80 | if (txMask != null) { 81 | Logger.logln("got mask "+txMask, LogLevel.DEBUG); 82 | irqType |= Integer.decode(txMask); 83 | } 84 | return irqType; 85 | } 86 | 87 | @Override 88 | public Integer getPreferredPriWidthForIf(String iName, SystemDataType dt, boolean master) { 89 | if(master && dt.equals(SystemDataType.INTERRUPT)) { 90 | return new Integer(3); 91 | } else { 92 | return super.getPreferredPriWidthForIf(iName, dt, master); 93 | } 94 | } 95 | 96 | @Override 97 | public Integer getPreferredSecWidthForIf(String iName, SystemDataType dt, boolean master) { 98 | if(master && dt.equals(SystemDataType.INTERRUPT)) { 99 | return new Integer(0); 100 | } else { 101 | return super.getPreferredSecWidthForIf(iName, dt, master); 102 | } 103 | } 104 | 105 | @Override 106 | public boolean removeFromSystemIfPossible(AvalonSystem sys) 107 | { 108 | if(!irqsRenumbered) { 109 | for(Interface intf : vInterfaces) { 110 | if(intf.isIRQMaster()) 111 | { 112 | int irqClass = getIrqClassFromIf(intf); 113 | for(Connection conn : intf.getConnections()) { 114 | int irqType = getIrqTypeFromIf(conn.getSlaveInterface()); 115 | long[] connVal = conn.getConnValue(); 116 | connVal[0] = irqClass; 117 | /* By default irqnr is stored in last value... */ 118 | connVal[1] = connVal[2]; 119 | connVal[2] = irqType; 120 | } 121 | } 122 | } 123 | irqsRenumbered = true; 124 | } 125 | return false; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/ClockSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.lib.AvalonSystem.SystemDataType; 25 | import sopc2dts.lib.BoardInfo; 26 | import sopc2dts.lib.Connection; 27 | import sopc2dts.lib.components.BasicComponent; 28 | import sopc2dts.lib.components.Interface; 29 | import sopc2dts.lib.components.SopcComponentDescription; 30 | import sopc2dts.lib.devicetree.DTNode; 31 | import sopc2dts.lib.devicetree.DTProperty; 32 | 33 | public class ClockSource extends BasicComponent { 34 | long clockIndex; 35 | public ClockSource(BasicComponent cs) { 36 | super(cs); 37 | } 38 | public ClockSource(String cName, String iName, String ver, 39 | SopcComponentDescription scd) { 40 | super(cName, iName, ver, scd); 41 | } 42 | public void setClockIndex(long idx) { 43 | clockIndex = idx; 44 | } 45 | public long getClockIndex() { 46 | return clockIndex; 47 | } 48 | protected DTNode createClockOutputNode(Interface cm, long idx, String lbl) 49 | { 50 | DTNode node = new DTNode(lbl, lbl); 51 | node.addProperty(new DTProperty("compatible", "fixed-clock")); 52 | node.addProperty(new DTProperty("#clock-cells", 0L)); 53 | node.addProperty(new DTProperty("clock-frequency",null,freq2String(cm.getInterfaceValue()[0]), cm.getInterfaceValue()[0])); 54 | node.addProperty(new DTProperty("clock-output-names",getInstanceName() + '-' + cm.getName())); 55 | return node; 56 | } 57 | public static String freq2String(long freq) { 58 | float ffreq; 59 | String sXhz; 60 | if(freq > 1000000000) { 61 | ffreq = freq/1000000000.0f; 62 | sXhz = "GHz"; 63 | } else if(freq > 1000000) { 64 | ffreq = freq/1000000.0f; 65 | sXhz = "MHz"; 66 | } else if(freq > 1000) { 67 | ffreq = freq/1000.0f; 68 | sXhz = "kHz"; 69 | } else { 70 | ffreq = freq; 71 | sXhz = "Hz"; 72 | } 73 | return String.format("%.2f %s", ffreq,sXhz); 74 | } 75 | public DTNode toDTNode(BoardInfo bi,Connection conn) 76 | { 77 | Vector vClkMasters = getInterfaces(SystemDataType.CLOCK, true); 78 | if(vClkMasters.size()==1) { 79 | return createClockOutputNode(vClkMasters.get(0), clockIndex, getInstanceName()); 80 | } else { 81 | DTNode node = new DTNode(getInstanceName(), getInstanceName()); 82 | long subIdx = 0; 83 | node.addProperty(new DTProperty("compatible", 84 | getScd().getCompatibles(version).toArray(new String[]{}))); 85 | node.addProperty(new DTProperty("#clock-cells", 1L)); 86 | for(Interface clkIf : vClkMasters) { 87 | node.addChild(createClockOutputNode(clkIf, subIdx++, getInstanceName() + "_" + clkIf.getName())); 88 | } 89 | return node; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/CpuComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2012-2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.lib.Connection; 25 | import sopc2dts.lib.components.BasicComponent; 26 | import sopc2dts.lib.components.SopcComponentDescription; 27 | 28 | public class CpuComponent extends BasicComponent { 29 | long cpuIndex = 0; 30 | static String[] smpBlackList = { "altera_nios2", "altera_nios2_qsys" }; 31 | 32 | public CpuComponent(BasicComponent comp) { 33 | super(comp); 34 | } 35 | public CpuComponent(String cName, String iName, String ver, 36 | SopcComponentDescription scd) { 37 | super(cName, iName, ver, scd); 38 | } 39 | public void setCpuIndex(long idx) { 40 | cpuIndex = idx; 41 | } 42 | public long getCpuIndex() { 43 | return cpuIndex; 44 | } 45 | @Override 46 | protected Vector getReg(BasicComponent master, Vector vRegNames) 47 | { 48 | if(master == null) { 49 | Vector vRegs = new Vector(); 50 | vRegs.add(cpuIndex); 51 | return vRegs; 52 | } else { 53 | return super.getReg(master,vRegNames); 54 | } 55 | } 56 | protected long[] getAddrFromConnection(Connection conn) 57 | { 58 | if(conn == null) { 59 | return new long[]{ cpuIndex }; 60 | } else { 61 | return super.getAddrFromConnection(conn); 62 | } 63 | } 64 | public boolean isSmpCapableWith(CpuComponent otherCpu) { 65 | if(scd.isSupportingClassName(otherCpu.getClassName())) { 66 | //Same type of CPU, might be OK to SMP 67 | for(String sbl : smpBlackList) { 68 | // Check for blacklisted uni-processors... 69 | if(scd.isSupportingClassName(sbl)) { 70 | return false; 71 | } 72 | } 73 | return true; 74 | } 75 | return false; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/FlashPartition.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | public class FlashPartition { 23 | private String name; 24 | private int address; 25 | private int size; 26 | private boolean readonly = false; 27 | 28 | public FlashPartition() { 29 | } 30 | 31 | public FlashPartition(FlashPartition fp) { 32 | this.name = fp.name; 33 | this.address = fp.address; 34 | this.size = fp.size; 35 | this.readonly = fp.readonly; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public int getAddress() { 47 | return address; 48 | } 49 | 50 | public void setAddress(int address) { 51 | this.address = address; 52 | } 53 | 54 | public int getSize() { 55 | return size; 56 | } 57 | 58 | public void setSize(int size) { 59 | this.size = size; 60 | } 61 | 62 | public boolean isReadonly() { 63 | return readonly; 64 | } 65 | 66 | public void setReadonly(boolean readonly) { 67 | this.readonly = readonly; 68 | } 69 | 70 | @Override 71 | public boolean equals(Object o) 72 | { 73 | if(!(o instanceof FlashPartition)) 74 | return false; 75 | 76 | FlashPartition fp = (FlashPartition)o; 77 | 78 | if(readonly != fp.isReadonly()) 79 | return false; 80 | 81 | if(address != fp.getAddress()) 82 | return false; 83 | 84 | if(size != fp.getSize()) 85 | return false; 86 | 87 | return name.equals(fp.getName()); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/GpioController.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import sopc2dts.lib.BoardInfo; 23 | import sopc2dts.lib.Connection; 24 | import sopc2dts.lib.components.BasicComponent; 25 | import sopc2dts.lib.components.SopcComponentDescription; 26 | import sopc2dts.lib.devicetree.DTNode; 27 | import sopc2dts.lib.devicetree.DTProperty; 28 | 29 | public class GpioController extends BasicComponent { 30 | 31 | public GpioController(String cName, String iName, String ver, 32 | SopcComponentDescription scd) { 33 | super(cName, iName, ver, scd); 34 | } 35 | public GpioController(BasicComponent comp) { 36 | super(comp); 37 | } 38 | @Override 39 | public DTNode toDTNode(BoardInfo bi,Connection conn) 40 | { 41 | DTNode n = super.toDTNode(bi, conn); 42 | n.addProperty(new DTProperty("#gpio-cells", 2L)); 43 | n.addProperty(new DTProperty("gpio-controller")); 44 | return n; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/MailBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import sopc2dts.lib.BoardInfo; 23 | import sopc2dts.lib.Connection; 24 | import sopc2dts.lib.components.BasicComponent; 25 | import sopc2dts.lib.components.SopcComponentDescription; 26 | import sopc2dts.lib.devicetree.DTNode; 27 | import sopc2dts.lib.devicetree.DTProperty; 28 | 29 | public class MailBox extends BasicComponent { 30 | 31 | public MailBox(BasicComponent comp) { 32 | super(comp); 33 | } 34 | public MailBox(String cName, String iName, String ver, 35 | SopcComponentDescription scd) { 36 | super(cName, iName, ver, scd); 37 | } 38 | @Override 39 | public DTNode toDTNode(BoardInfo bi,Connection conn) 40 | { 41 | DTNode n = super.toDTNode(bi, conn); 42 | n.addProperty(new DTProperty("linux,mailbox-name", getInstanceName())); 43 | return n; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/SCDSelfDescribing.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import sopc2dts.lib.components.BasicComponent; 23 | import sopc2dts.lib.components.SopcComponentDescription; 24 | 25 | public class SCDSelfDescribing extends SopcComponentDescription { 26 | 27 | public SCDSelfDescribing(BasicComponent comp) 28 | { 29 | super(comp.getClassName(), 30 | comp.getParamValByName(BasicComponent.EMBSW_DTS_GROUP), 31 | comp.getParamValByName(BasicComponent.EMBSW_DTS_VENDOR), 32 | comp.getParamValByName(BasicComponent.EMBSW_DTS_NAME)); 33 | if(device == null) { 34 | device = comp.getClassName(); 35 | } 36 | } 37 | 38 | /* 39 | * Scans a BasicComponent for parameters given through the _hw.tcl file that 40 | * describe the usage of that component in the device-tree. 41 | * Those parameters are named embeddedsw.dts.* and some are mandatory and 42 | * some are optional. When there are enough parameters in the component, 43 | * those parameters will be used instead of the ones defined in the 44 | * sopc_component_*.xml files. 45 | * In the long run this will remove the need for those xml-files. 46 | */ 47 | public static boolean isSelfDescribing(BasicComponent comp) { 48 | String pVal = comp.getParamValByName(BasicComponent.EMBSW_DTS_VENDOR); 49 | if((pVal == null) || (pVal.length() == 0)) { 50 | //Vendor info is mandatory 51 | return false; 52 | } 53 | pVal = comp.getParamValByName(BasicComponent.EMBSW_DTS_GROUP); 54 | if((pVal == null) || (pVal.length() == 0)) { 55 | //group/type info is mandatory 56 | return false; 57 | } 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/SICEthernet.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import sopc2dts.lib.AvalonSystem.SystemDataType; 23 | import sopc2dts.lib.BoardInfo; 24 | import sopc2dts.lib.Connection; 25 | import sopc2dts.lib.components.SopcComponentDescription; 26 | import sopc2dts.lib.boardinfo.BICEthernet; 27 | import sopc2dts.lib.components.BasicComponent; 28 | import sopc2dts.lib.devicetree.DTNode; 29 | import sopc2dts.lib.devicetree.DTProperty; 30 | import sopc2dts.lib.devicetree.DTPropPHandleVal; 31 | /* 32 | * This class handles all default network stuff, subclasses can override 33 | * defaults declared in this class, or just don't and keep 'm simple. 34 | * This is not really a special case (as are most classes in these packages) but 35 | * rather a convenience class to help the lazy people such as myself. 36 | */ 37 | public class SICEthernet extends BasicComponent { 38 | protected enum PhyMode { MII, GMII, RGMII, SGMII, NONE }; 39 | private PhyMode phymode = PhyMode.NONE; 40 | 41 | public SICEthernet(String cName, String iName, String version, SopcComponentDescription scd) { 42 | super(cName, iName, version, scd); 43 | } 44 | 45 | public SICEthernet(BasicComponent comp) { 46 | super(comp); 47 | } 48 | protected void setPhyMode(PhyMode pm) 49 | { 50 | phymode = pm; 51 | } 52 | protected PhyMode getPhyMode() 53 | { 54 | return phymode; 55 | } 56 | protected String getPhyModeString() 57 | { 58 | switch(getPhyMode()) 59 | { 60 | case MII: return "mii"; 61 | case GMII: return "gmii"; 62 | case RGMII: return "rgmii"; 63 | case SGMII: return "sgmii"; 64 | default: return "unknown"; 65 | } 66 | } 67 | @Override 68 | public DTNode toDTNode(BoardInfo bi, Connection conn) 69 | { 70 | DTNode node = super.toDTNode(bi, conn); 71 | node.addProperty(new DTProperty("address-bits", Long.valueOf(getAddressBits()))); 72 | node.addProperty(new DTProperty("max-frame-size", Long.valueOf(getMaxFrameSize()))); 73 | DTProperty dtpb = new DTProperty("local-mac-address"); 74 | dtpb.addByteValues(getMacAddress(bi)); 75 | node.addProperty(dtpb); 76 | 77 | for (Connection iconn : getConnections(SystemDataType.CONDUIT, false)) { 78 | if (iconn.getSlaveModule().getClassName().equalsIgnoreCase("altera_gmii_to_sgmii_converter")) { 79 | node.addProperty(new DTProperty("altr,gmii-to-sgmii-converter", 80 | new DTPropPHandleVal(iconn.getSlaveModule().getInstanceName()))); 81 | node.addProperty(new DTProperty("altr,gmii_to_sgmii_converter", 82 | new DTPropPHandleVal(iconn.getSlaveModule().getInstanceName()))); 83 | setPhyMode(PhyMode.SGMII); 84 | 85 | } 86 | } 87 | if (phymode != PhyMode.NONE) { 88 | node.addProperty(new DTProperty("phy-mode", getPhyModeString())); 89 | } 90 | return node; 91 | } 92 | protected int[] getMacAddress(BoardInfo bi) 93 | { 94 | return bi.getEthernetForChip(getInstanceName()).getMac(); 95 | } 96 | protected int getAddressBits() 97 | { 98 | return 48; 99 | } 100 | protected int getMaxFrameSize() 101 | { 102 | return 1518; 103 | } 104 | protected DTNode getMdioNode(BICEthernet be) { 105 | return null; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/SICEthernet.java.orig: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import sopc2dts.lib.AvalonSystem.SystemDataType; 23 | import sopc2dts.lib.BoardInfo; 24 | import sopc2dts.lib.Connection; 25 | import sopc2dts.lib.components.SopcComponentDescription; 26 | import sopc2dts.lib.components.BasicComponent; 27 | import sopc2dts.lib.devicetree.DTNode; 28 | import sopc2dts.lib.devicetree.DTProperty; 29 | import sopc2dts.lib.devicetree.DTPropPHandleVal; 30 | /* 31 | * This class handles all default network stuff, subclasses can override 32 | * defaults declared in this class, or just don't and keep 'm simple. 33 | * This is not really a special case (as are most classes in these packages) but 34 | * rather a convenience class to help the lazy people such as myself. 35 | */ 36 | public class SICEthernet extends BasicComponent { 37 | protected enum PhyMode { MII, GMII, RGMII, SGMII, NONE }; 38 | private PhyMode phymode = PhyMode.NONE; 39 | 40 | public SICEthernet(String cName, String iName, String version, SopcComponentDescription scd) { 41 | super(cName, iName, version, scd); 42 | } 43 | 44 | public SICEthernet(BasicComponent comp) { 45 | super(comp); 46 | } 47 | protected void setPhyMode(PhyMode pm) 48 | { 49 | phymode = pm; 50 | } 51 | protected PhyMode getPhyMode() 52 | { 53 | return phymode; 54 | } 55 | protected String getPhyModeString() 56 | { 57 | switch(getPhyMode()) 58 | { 59 | case MII: return "mii"; 60 | case GMII: return "gmii"; 61 | case RGMII: return "rgmii"; 62 | case SGMII: return "sgmii"; 63 | default: return "unknown"; 64 | } 65 | } 66 | @Override 67 | public DTNode toDTNode(BoardInfo bi, Connection conn) 68 | { 69 | DTNode node = super.toDTNode(bi, conn); 70 | node.addProperty(new DTProperty("address-bits", Long.valueOf(getAddressBits()))); 71 | node.addProperty(new DTProperty("max-frame-size", Long.valueOf(getMaxFrameSize()))); 72 | DTProperty dtpb = new DTProperty("local-mac-address"); 73 | dtpb.addByteValues(getMacAddress(bi)); 74 | node.addProperty(dtpb); 75 | 76 | for (Connection iconn : getConnections(SystemDataType.CONDUIT, false)) { 77 | if (iconn.getSlaveModule().getClassName().equalsIgnoreCase("altera_gmii_to_sgmii_converter")) { 78 | node.addProperty(new DTProperty("altr,gmii-to-sgmii-converter", 79 | new DTPropPHandleVal(iconn.getSlaveModule().getInstanceName()))); 80 | node.addProperty(new DTProperty("altr,gmii_to_sgmii_converter", 81 | new DTPropPHandleVal(iconn.getSlaveModule().getInstanceName()))); 82 | setPhyMode(PhyMode.SGMII); 83 | 84 | } 85 | } 86 | if (phymode != PhyMode.NONE) { 87 | node.addProperty(new DTProperty("phy-mode", getPhyModeString())); 88 | } 89 | return node; 90 | } 91 | protected int[] getMacAddress(BoardInfo bi) 92 | { 93 | return bi.getEthernetForChip(getInstanceName()).getMac(); 94 | } 95 | protected int getAddressBits() 96 | { 97 | return 48; 98 | } 99 | protected int getMaxFrameSize() 100 | { 101 | return 1518; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/SICFlash.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.lib.BoardInfo; 25 | import sopc2dts.lib.Connection; 26 | import sopc2dts.lib.components.SopcComponentDescription; 27 | import sopc2dts.lib.components.BasicComponent; 28 | import sopc2dts.lib.devicetree.DTNode; 29 | import sopc2dts.lib.devicetree.DTProperty; 30 | 31 | public class SICFlash extends BasicComponent { 32 | 33 | public SICFlash(BasicComponent bc) 34 | { 35 | super(bc); 36 | } 37 | public SICFlash(String cName, String iName, String version, SopcComponentDescription scd) { 38 | super(cName, iName, version, scd); 39 | } 40 | 41 | protected DTNode addPartitionsToDTNode(BoardInfo bi, DTNode node) 42 | { 43 | Vector vPartitions = bi.getPartitionsForChip(this.getInstanceName()); 44 | if(vPartitions != null) 45 | { 46 | if(vPartitions.size()>0) 47 | { 48 | node.addProperty(new DTProperty("#address-cells", 1L)); 49 | node.addProperty(new DTProperty("#size-cells", 1L)); 50 | } 51 | for(FlashPartition part : vPartitions) 52 | { 53 | DTNode dtPart = new DTNode(part.getName() + '@' + Integer.toHexString(part.getAddress())); 54 | DTProperty p; 55 | Vector vReg = new Vector(); 56 | vReg.add(Long.valueOf(part.getAddress())); 57 | vReg.add(Long.valueOf(part.getSize())); 58 | p = new DTProperty("reg"); 59 | p.addHexValues(vReg); 60 | p.setNumValuesPerRow(2); //Addr + size 61 | dtPart.addProperty(p); 62 | if(part.isReadonly()) 63 | { 64 | dtPart.addProperty(new DTProperty("read-only")); 65 | } 66 | node.addChild(dtPart); 67 | } 68 | } 69 | return node; 70 | } 71 | @Override 72 | public DTNode toDTNode(BoardInfo bi, Connection conn) 73 | { 74 | //XXX Refactor to get cfi stuff to seperate class 75 | DTNode node = super.toDTNode(bi, conn); 76 | node.addProperty(new DTProperty("bank-width", Long.valueOf(getBankWidth()))); 77 | node.addProperty(new DTProperty("device-width", 1L)); 78 | node = addPartitionsToDTNode(bi, node); 79 | return node; 80 | } 81 | 82 | protected int getBankWidth() 83 | { 84 | int bankw = 2; 85 | try { 86 | String sdw = getParamValByName("dataWidth"); 87 | //Try other param name if dataWidth did not exist 88 | if(sdw==null) 89 | { 90 | sdw = getParamValByName("TCM_DATA_W"); 91 | } 92 | if(sdw!=null) 93 | { 94 | bankw = Integer.decode(sdw)/8; 95 | } 96 | }catch(Exception e) { 97 | //Default to 16bit on failure 98 | bankw = 2; 99 | } 100 | return bankw; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/SICI2CMaster.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import java.util.Collections; 23 | import java.util.Vector; 24 | 25 | import sopc2dts.lib.BoardInfo; 26 | import sopc2dts.lib.Connection; 27 | import sopc2dts.lib.boardinfo.BICI2C; 28 | import sopc2dts.lib.boardinfo.I2CSlave; 29 | import sopc2dts.lib.components.BasicComponent; 30 | import sopc2dts.lib.components.SopcComponentDescription; 31 | import sopc2dts.lib.devicetree.DTNode; 32 | import sopc2dts.lib.devicetree.DTProperty; 33 | 34 | public class SICI2CMaster extends BasicComponent { 35 | 36 | public SICI2CMaster(String cName, String iName, String ver, SopcComponentDescription scd) { 37 | super(cName, iName, ver, scd); 38 | } 39 | public SICI2CMaster(BasicComponent comp) { 40 | super(comp); 41 | } 42 | @Override 43 | public DTNode toDTNode(BoardInfo bi, Connection conn) 44 | { 45 | DTNode node = super.toDTNode(bi, conn); 46 | BICI2C bi2c = bi.getI2CForChip(this.getInstanceName()); 47 | Vector vSlaves = bi2c.getSlaves(); 48 | if(!vSlaves.isEmpty()) { 49 | node.addProperty(new DTProperty("#address-cells", 1L)); 50 | node.addProperty(new DTProperty("#size-cells", 0L)); 51 | Collections.sort(vSlaves); 52 | for(I2CSlave s : vSlaves) { 53 | node.addChild(s.toDTNode(bi)); 54 | } 55 | } 56 | return node; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/SICSpiMaster.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import sopc2dts.lib.BoardInfo; 23 | import sopc2dts.lib.Connection; 24 | import sopc2dts.lib.boardinfo.BICSpi; 25 | import sopc2dts.lib.boardinfo.BoardInfoComponent; 26 | import sopc2dts.lib.boardinfo.SpiSlave; 27 | import sopc2dts.lib.components.BasicComponent; 28 | import sopc2dts.lib.components.SopcComponentDescription; 29 | import sopc2dts.lib.devicetree.DTNode; 30 | import sopc2dts.lib.devicetree.DTProperty; 31 | 32 | public class SICSpiMaster extends BasicComponent { 33 | 34 | public SICSpiMaster(String cName, String iName, String ver, SopcComponentDescription scd) { 35 | super(cName, iName, ver, scd); 36 | } 37 | public SICSpiMaster(BasicComponent comp) { 38 | super(comp); 39 | } 40 | @Override 41 | public DTNode toDTNode(BoardInfo bi, Connection conn) 42 | { 43 | DTNode node = super.toDTNode(bi, conn); 44 | BoardInfoComponent bs = bi.getBicForChip(getInstanceName()); 45 | if(bs!=null) 46 | { 47 | if(bs instanceof BICSpi) 48 | { 49 | BICSpi bSpi = (BICSpi)bs; 50 | if(!bSpi.getSlaves().isEmpty()) 51 | { 52 | node.addProperty(new DTProperty("#address-cells", 1L)); 53 | node.addProperty(new DTProperty("#size-cells", 0L)); 54 | for(SpiSlave slave : bSpi.getSlaves()) 55 | { 56 | node.addChild(slave.toDTNode(bi)); 57 | } 58 | } 59 | } 60 | } 61 | return node; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/base/SICUnknown.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.base; 21 | 22 | import sopc2dts.lib.components.SopcComponentDescription; 23 | 24 | public class SICUnknown extends SopcComponentDescription { 25 | 26 | public SICUnknown(String sopcClassName) 27 | { 28 | super(sopcClassName,"unknown","unknown","unknown"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/labx/LabXEthernet.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.labx; 21 | 22 | import sopc2dts.lib.BoardInfo; 23 | import sopc2dts.lib.Connection; 24 | import sopc2dts.lib.components.BasicComponent; 25 | import sopc2dts.lib.components.Interface; 26 | import sopc2dts.lib.components.SopcComponentDescription; 27 | import sopc2dts.lib.components.base.SICEthernet; 28 | import sopc2dts.lib.devicetree.DTNode; 29 | import sopc2dts.lib.devicetree.DTProperty; 30 | 31 | public class LabXEthernet extends SICEthernet { 32 | 33 | private static final String SUPPORTED_MACS[] = { 34 | "labx_eth_mac", 35 | "labx_10g_eth_mac", 36 | }; 37 | 38 | public LabXEthernet(String cName, String iName, String version, SopcComponentDescription sdc) { 39 | super(cName, iName, version, sdc); 40 | } 41 | 42 | @Override 43 | public DTNode toDTNode(BoardInfo bi,Connection conn) 44 | { 45 | DTNode res = super.toDTNode(bi, conn); 46 | // Add our custom properties 47 | res.addProperty(new DTProperty("phy-mode", getPhyModeString())); 48 | return res; 49 | } 50 | 51 | private BasicComponent findLabXEthMac(Interface intf) 52 | { 53 | BasicComponent comp = null; 54 | if(intf!=null) 55 | { 56 | if(!intf.getConnections().isEmpty()) 57 | { 58 | comp = intf.getConnections().firstElement().getSlaveModule(); 59 | if(intf.getOwner().equals(comp)) { 60 | //We've found ourselves... 61 | comp = intf.getConnections().firstElement().getMasterModule(); 62 | } 63 | 64 | // Traverse the slave connections until we find one of our 65 | // supported MAC components 66 | boolean foundMac = false; 67 | for(String typeString : SUPPORTED_MACS) { 68 | if(comp.getClassName().equalsIgnoreCase(typeString)) { 69 | foundMac = true; 70 | break; 71 | } 72 | } 73 | 74 | if(foundMac == false) { 75 | if(comp.getClassName().equalsIgnoreCase("labx_eth_tx_arbiter")) 76 | { 77 | comp = findLabXEthMac(comp.getInterfaceByName("mac_tx")); 78 | } else { 79 | // Fail... 80 | comp = null; 81 | } 82 | } 83 | } 84 | } 85 | return comp; 86 | } 87 | 88 | protected String getPhyModeString() 89 | { 90 | String res = "UNKNOWN"; 91 | BasicComponent labx_eth_mac = findLabXEthMac(getInterfaceByName("mac_tx")); 92 | if(labx_eth_mac != null) { 93 | res = labx_eth_mac.getParamValByName("MII_TYPE"); 94 | } 95 | return res; 96 | } 97 | 98 | // Protected overrides from base class SICEthernet 99 | @Override 100 | protected int getMaxFrameSize() 101 | { 102 | // Not that this should matter, but we support VLAN tags 103 | return 1522; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /sopc2dts/lib/components/nxp/USBHostControllerISP1xxx.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.nxp; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.lib.Connection; 25 | import sopc2dts.lib.components.BasicComponent; 26 | import sopc2dts.lib.components.Interface; 27 | import sopc2dts.lib.components.SopcComponentDescription; 28 | import sopc2dts.lib.devicetree.DTHelper; 29 | 30 | public class USBHostControllerISP1xxx extends BasicComponent { 31 | 32 | public USBHostControllerISP1xxx(String cName, String iName, String ver, 33 | SopcComponentDescription scd) { 34 | super(cName, iName, ver, scd); 35 | } 36 | 37 | 38 | /** @todo Find out regnames */ 39 | @Override 40 | protected Vector getReg(BasicComponent master, Vector vRegNames) 41 | { 42 | Vector vRegs = new Vector(); 43 | for(Interface intf : vInterfaces) 44 | { 45 | if(intf.isMemorySlave()) 46 | { 47 | //Check all interfaces for a connection to master 48 | Connection conn = null; 49 | for(int i=0; (i 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.components.snps; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.lib.BoardInfo; 25 | import sopc2dts.lib.Connection; 26 | import sopc2dts.lib.Parameter; 27 | import sopc2dts.lib.components.BasicComponent; 28 | import sopc2dts.lib.components.SopcComponentDescription; 29 | import sopc2dts.lib.components.base.GpioController; 30 | import sopc2dts.lib.devicetree.DTNode; 31 | import sopc2dts.lib.devicetree.DTPropNumVal; 32 | import sopc2dts.lib.devicetree.DTPropVal; 33 | import sopc2dts.lib.devicetree.DTPropStringVal; 34 | import sopc2dts.lib.devicetree.DTProperty; 35 | import sopc2dts.Logger; 36 | import sopc2dts.Logger.LogLevel; 37 | 38 | public class DwGpio 39 | extends GpioController 40 | { 41 | public DwGpio(String cName, String iName, String ver, 42 | SopcComponentDescription scd) { 43 | super(cName, iName, ver, scd); 44 | } 45 | public DwGpio(BasicComponent comp) { 46 | super(comp); 47 | } 48 | @Override 49 | public DTNode toDTNode(BoardInfo bi,Connection conn) 50 | { 51 | DTNode n = super.toDTNode(bi, conn); 52 | 53 | DTProperty prop = n.getPropertyByName("compatible"); 54 | Vector vals = prop.getValues(); 55 | vals.add(0, new DTPropStringVal("snps,dw-apb-gpio")); 56 | n.addProperty(new DTProperty("#address-cells", new DTPropNumVal(1))); 57 | n.addProperty(new DTProperty("#size-cells", new DTPropNumVal(0))); 58 | String[] ports = {"A","B", "C", "D"}; 59 | int i = 0; 60 | for (String port : ports) { 61 | Parameter p = getParamByName(EMBSW_DTS+".instance.GPIO_PWIDTH_"+port); 62 | int width = 0; 63 | if (p == null) { 64 | if (i == 0) { 65 | width = 27; 66 | } 67 | } else { 68 | width = Integer.parseInt(p.getValue()); 69 | } 70 | if (width <= 0){ 71 | continue; 72 | } 73 | 74 | DTNode subNode = new DTNode("gpio-controller@"+i, getInstanceName()+"_port"+port.toLowerCase()); 75 | subNode.addProperty(new DTProperty("compatible",new DTPropStringVal("snps,dw-apb-gpio-port"))); 76 | subNode.addProperty(new DTProperty("gpio-controller")); 77 | subNode.addProperty(new DTProperty("#gpio-cells", new DTPropNumVal(2))); 78 | subNode.addProperty(new DTProperty("snps,nr-gpios",new DTPropNumVal(width))); 79 | subNode.addProperty(new DTProperty("reg", new DTPropNumVal(i))); 80 | if (i == 0) { 81 | Parameter pint = getParamByName(EMBSW_DTS+".instance.GPIO_PORTA_INTR"); 82 | if ((null == pint) || (pint.getValueAsBoolean())) { 83 | subNode.addProperty(new DTProperty("interrupt-controller")); 84 | subNode.addProperty(new DTProperty("#interrupt-cells", new DTPropNumVal(2))); 85 | subNode.addProperty(n.getPropertyByName("interrupts")); 86 | subNode.addProperty(n.getPropertyByName("interrupt-parent")); 87 | } 88 | } 89 | n.addChild(subNode); 90 | i++; 91 | } 92 | return n; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /sopc2dts/lib/devicetree/DTElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.devicetree; 21 | 22 | public abstract class DTElement { 23 | String label; 24 | String name; 25 | String comment; 26 | 27 | public DTElement(String name) 28 | { 29 | this(name,null,null); 30 | } 31 | public DTElement(String name, String label) 32 | { 33 | this(name,label,null); 34 | } 35 | public DTElement(String name, String label, String comment) 36 | { 37 | this.name = name; 38 | this.label = label; 39 | this.comment = comment; 40 | } 41 | public String getLabel() { 42 | return label; 43 | } 44 | public void setLabel(String label) { 45 | this.label = label; 46 | } 47 | public String getName() { 48 | return name; 49 | } 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | public abstract byte[] getBytes(DTBlob dtb); 54 | public String getComment() { 55 | return comment; 56 | } 57 | public void setComment(String comment) { 58 | this.comment = comment; 59 | } 60 | public abstract String toString(int indent); 61 | public String toString() { 62 | return toString(0); 63 | } 64 | /** @brief Helper function to do indentation 65 | * 66 | * This is a helper function for generating formatted text. It generates a 67 | * string that can be prepended to a source string consisting of level 68 | * indentation characters. 69 | * 70 | * @param level The indentation depth 71 | * @return A String containing indentation characters 72 | */ 73 | protected static String indent(int level) 74 | { 75 | String res = ""; 76 | while(level-->0) 77 | { 78 | res += "\t"; 79 | } 80 | return res; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /sopc2dts/lib/devicetree/DTNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2012 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.devicetree; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.Logger; 25 | import sopc2dts.Logger.LogLevel; 26 | 27 | public class DTNode extends DTElement { 28 | public static final int OF_DT_BEGIN_NODE = 0x01; 29 | public static final int OF_DT_END_NODE = 0x02; 30 | Vector vChildren = new Vector(); 31 | Vector vProps = new Vector(); 32 | 33 | public DTNode(String name) { 34 | super(name); 35 | } 36 | public DTNode(String name, String label) { 37 | super(name, label); 38 | } 39 | public DTNode(String name, String label, String comment) { 40 | super(name, label, comment); 41 | } 42 | public void addChild(DTNode child) 43 | { 44 | if(child!=null) 45 | { 46 | vChildren.add(child); 47 | } 48 | } 49 | public void addProperty(DTProperty prop) { 50 | addProperty(prop,false); 51 | } 52 | public void addProperty(DTProperty prop, boolean replaceExising) 53 | { 54 | if(prop!=null) 55 | { 56 | DTProperty propOrg = getPropertyByName(prop.getName()); 57 | if(propOrg!=null) { 58 | if(replaceExising) { 59 | int idx = vProps.indexOf(propOrg); 60 | vProps.remove(propOrg); 61 | vProps.insertElementAt(prop,idx); 62 | } else { 63 | Logger.logln("Unable to add duplicate property '" + prop.getName() + '\'' + 64 | " to node '" + getName() + "' labeled '" + getLabel() + '\'' , LogLevel.ERROR); 65 | } 66 | } else { 67 | vProps.add(prop); 68 | } 69 | } 70 | } 71 | public Vector getChildren() 72 | { 73 | return vChildren; 74 | } 75 | public Vector getProperties() 76 | { 77 | return vProps; 78 | } 79 | public DTProperty getPropertyByName(String name) 80 | { 81 | for(DTProperty prop : vProps) 82 | { 83 | if(prop.getName().equals(name)) 84 | { 85 | return prop; 86 | } 87 | } 88 | return null; 89 | } 90 | @Override 91 | public String toString(int indent) { 92 | String res = "\n" + (comment !=null ? indent(indent) + "/*" + comment + "*/\n" : "") + 93 | indent(indent) + (label != null ? label + ": " : "") + name + " {\n"; 94 | indent++; 95 | for(DTProperty prop : vProps) 96 | { 97 | res += prop.toString(indent); 98 | } 99 | for(DTNode child : vChildren) 100 | { 101 | res += child.toString(indent); 102 | } 103 | indent--; 104 | res += indent(indent) + "}; //end " + name + (label != null ? " (" + label + ")\n" : "\n"); 105 | return res; 106 | } 107 | @Override 108 | public byte[] getBytes(DTBlob dtb) { 109 | byte[] dt; 110 | int size = 0; 111 | int pos = 0; 112 | Vector vBytes = new Vector(); 113 | String tmpName = (name == null ? "" : name); 114 | byte[] header = new byte[4 + ((tmpName.length() + 4) & ~3)]; 115 | byte[] footer = new byte[4]; 116 | DTBlob.putU32(OF_DT_BEGIN_NODE, header, 0); 117 | DTBlob.putStringAligned(tmpName, header, 4); 118 | DTBlob.putU32(OF_DT_END_NODE, footer, 0); 119 | vBytes.add(header); 120 | size += header.length; 121 | for(DTProperty prop : vProps) { 122 | byte b[] = prop.getBytes(dtb); 123 | vBytes.add(b); 124 | size+=b.length; 125 | } 126 | for(DTNode child : vChildren) { 127 | byte b[] = child.getBytes(dtb); 128 | vBytes.add(b); 129 | size+=b.length; 130 | } 131 | vBytes.add(footer); 132 | size += footer.length; 133 | dt = new byte[size]; 134 | for(byte[] b : vBytes) 135 | { 136 | System.arraycopy(b, 0, dt, pos, b.length); 137 | pos += b.length; 138 | } 139 | return dt; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /sopc2dts/lib/devicetree/DTPropByteVal.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 - 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.devicetree; 21 | 22 | public class DTPropByteVal extends DTPropVal { 23 | int val; 24 | public DTPropByteVal(int v) { 25 | super(DTPropType.BYTE, "[", "]", " "); 26 | val = v; 27 | } 28 | @Override 29 | protected byte[] getValueBytes() { 30 | byte[] res = new byte[1]; 31 | res[0] = (byte)(val&0xFF); 32 | return res; 33 | } 34 | @Override 35 | public String toString() { 36 | return String.format("%02x", val&0xFF); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sopc2dts/lib/devicetree/DTPropHexNumVal.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 - 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.devicetree; 21 | 22 | public class DTPropHexNumVal extends DTPropNumVal { 23 | 24 | public DTPropHexNumVal(long v) { 25 | super(v); 26 | } 27 | 28 | public String toString() 29 | { 30 | if(val<0) 31 | { 32 | return String.format("0x%08x", val+0x100000000L); 33 | /* } else if(val<0x100) 34 | { 35 | return String.format("0x%02x", val); 36 | } else if(val<0x10000) 37 | { 38 | return String.format("0x%04x", val); 39 | */ } else { 40 | return String.format("0x%08x", val); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sopc2dts/lib/devicetree/DTPropNumVal.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.devicetree; 21 | 22 | public class DTPropNumVal extends DTPropVal { 23 | long val; 24 | public DTPropNumVal(long v) { 25 | super(DTPropType.NUMBER, "<", ">", " "); 26 | val = v; 27 | } 28 | @Override 29 | protected byte[] getValueBytes() { 30 | byte[] res = new byte[4]; 31 | DTBlob.putU32(val, res, 0); 32 | return res; 33 | } 34 | @Override 35 | public String toString() { 36 | return ""+val; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sopc2dts/lib/devicetree/DTPropPHandleVal.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 - 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.devicetree; 21 | 22 | import sopc2dts.lib.components.BasicComponent; 23 | 24 | public class DTPropPHandleVal extends DTPropVal { 25 | String label; 26 | long pHandle; 27 | 28 | public DTPropPHandleVal(BasicComponent comp) { 29 | this(comp.getInstanceName()); 30 | } 31 | public DTPropPHandleVal(String lab) { 32 | this(lab,0); 33 | } 34 | public DTPropPHandleVal(String lab, long ph) { 35 | super(DTPropType.PHANDLE, "<", ">", " "); 36 | label = lab; 37 | pHandle = ph; 38 | } 39 | 40 | @Override 41 | protected byte[] getValueBytes() { 42 | byte[] buff = new byte[4]; 43 | DTBlob.putU32(pHandle, buff, 0); 44 | return buff; 45 | } 46 | public String getLabel() { 47 | return label; 48 | } 49 | public void setLabel(String l) { 50 | this.label = l; 51 | } 52 | public long getpHandle() { 53 | return pHandle; 54 | } 55 | public void setpHandle(long pHandle) { 56 | this.pHandle = pHandle; 57 | } 58 | @Override 59 | public String toString() { 60 | return '&' + label; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /sopc2dts/lib/devicetree/DTPropStringVal.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 - 2015 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.devicetree; 21 | 22 | public class DTPropStringVal extends DTPropVal { 23 | public DTPropStringVal(String sVal) { 24 | super(DTPropType.STRING, "", "", ", "); 25 | value = sVal; 26 | } 27 | String value; 28 | @Override 29 | protected byte[] getValueBytes() { 30 | byte[] buff = new byte[value.length()+1]; 31 | System.arraycopy(value.getBytes(), 0, buff, 0, value.length()); 32 | buff[value.length()] = 0; 33 | return buff; 34 | } 35 | public String getStringValue() { 36 | return value; 37 | } 38 | public void setStringValue(String value) { 39 | this.value = value; 40 | } 41 | @Override 42 | public String toString() { 43 | return '"' + value + '"'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sopc2dts/lib/devicetree/DTPropVal.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2013 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.lib.devicetree; 21 | 22 | public abstract class DTPropVal { 23 | enum DTPropType { STRING, NUMBER, BYTE, BOOL, PHANDLE }; 24 | DTPropType type; 25 | String opening; 26 | String closing; 27 | String seperator; 28 | public DTPropVal(DTPropType t, String open, String close, String sep) { 29 | type = t; 30 | opening = open; 31 | closing = close; 32 | seperator = sep; 33 | } 34 | protected abstract byte[] getValueBytes(); 35 | boolean isTypeCompatible(DTPropType t) { 36 | if(type == t) { 37 | return true; 38 | } else { 39 | if(((type == DTPropType.NUMBER) && (t == DTPropType.PHANDLE)) || 40 | ((t == DTPropType.NUMBER) && (type == DTPropType.PHANDLE))) 41 | { 42 | return true; 43 | } 44 | } 45 | return false; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sopc2dts/parsers/BasicSystemLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 - 2014 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.parsers; 21 | 22 | import java.io.File; 23 | 24 | import sopc2dts.Logger; 25 | import sopc2dts.Logger.LogLevel; 26 | import sopc2dts.lib.AvalonSystem; 27 | import sopc2dts.parsers.qsys.QSysSystemLoader; 28 | import sopc2dts.parsers.sopcinfo.SopcInfoSystemLoader; 29 | 30 | public class BasicSystemLoader { 31 | public static AvalonSystem loadSystem(File source) 32 | { 33 | if(source.exists()) 34 | { 35 | if(source.getName().endsWith(".sopcinfo")) 36 | { 37 | Logger.logln("Loading " + source.getName() + " using SopcInfoSystemLoader", 38 | LogLevel.DEBUG); 39 | SopcInfoSystemLoader sisl = new SopcInfoSystemLoader(); 40 | return sisl.loadSystem(source); 41 | } else if(source.getName().endsWith(".qsys")) 42 | { 43 | Logger.logln("Loading " + source.getName() + " using QSysSystemLoader", 44 | LogLevel.DEBUG); 45 | QSysSystemLoader qsl = new QSysSystemLoader(); 46 | return qsl.loadSystem(source); 47 | } else { 48 | Logger.logln("Don't know how to parse " + source.getName(), 49 | LogLevel.ERROR); 50 | } 51 | } 52 | Logger.logln("Loading of system failed.", LogLevel.ERROR); 53 | return null; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sopc2dts/parsers/qsys/QSysSubSystem.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.parsers.qsys; 21 | 22 | import java.util.Vector; 23 | 24 | import sopc2dts.lib.components.BasicComponent; 25 | import sopc2dts.lib.components.SopcComponentDescription; 26 | 27 | public class QSysSubSystem extends BasicComponent { 28 | protected Vector vSystemComponents = new Vector(); 29 | 30 | public QSysSubSystem(BasicComponent comp) 31 | { 32 | super(comp); 33 | } 34 | public QSysSubSystem(String iName, String ver) { 35 | super(iName, iName, ver, new SopcComponentDescription(iName, "QSys", "ALTR", iName)); 36 | } 37 | 38 | public void addModule(BasicComponent bc) { 39 | vSystemComponents.add(bc); 40 | } 41 | 42 | public BasicComponent getComponentByName(String name) { 43 | for(BasicComponent bc : vSystemComponents) 44 | { 45 | if(bc.getInstanceName().equalsIgnoreCase(name)) 46 | { 47 | return bc; 48 | } 49 | } 50 | return null; 51 | } 52 | public Vector getSystemComponents() 53 | { 54 | return vSystemComponents; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sopc2dts/parsers/sopcinfo/SopcInfoAssignment.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.parsers.sopcinfo; 21 | 22 | import org.xml.sax.Attributes; 23 | import org.xml.sax.ContentHandler; 24 | import org.xml.sax.SAXException; 25 | import org.xml.sax.XMLReader; 26 | 27 | import sopc2dts.lib.BasicElement; 28 | import sopc2dts.lib.Parameter; 29 | import sopc2dts.lib.Parameter.DataType; 30 | 31 | public class SopcInfoAssignment extends SopcInfoElement { 32 | protected String name; 33 | protected String value; 34 | String currTag; 35 | DataType dataType = DataType.BOOLEAN; 36 | BasicElement basicElement; 37 | 38 | public SopcInfoAssignment(ContentHandler p, XMLReader xr, BasicElement be) 39 | { 40 | super(p,xr); 41 | basicElement = be; 42 | } 43 | @Override 44 | public String getElementName() { 45 | return "assignment"; 46 | } 47 | public void startElement(String uri, String localName, String qName, 48 | Attributes atts) throws SAXException { 49 | currTag = localName; 50 | } 51 | public void endElement(String uri, String localName, String qName) 52 | throws SAXException { 53 | // TODO Auto-generated method stub 54 | if(localName.equalsIgnoreCase(currTag)) 55 | { 56 | currTag = null; 57 | } else { 58 | if(localName.equalsIgnoreCase(getElementName()) && 59 | (basicElement!=null)) 60 | { 61 | Parameter bp = new Parameter(name, value, dataType); 62 | basicElement.addParam(bp); 63 | } 64 | super.endElement(uri, localName, qName); 65 | } 66 | } 67 | 68 | public void characters(char[] ch, int start, int length) 69 | throws SAXException { 70 | if(currTag!=null) 71 | { 72 | if(currTag.equalsIgnoreCase("name")) 73 | { 74 | name = (String.copyValueOf(ch, start, length)); 75 | } else if(currTag.equalsIgnoreCase("value")) 76 | { 77 | value = parseValue(String.copyValueOf(ch, start, length)); 78 | } 79 | } 80 | } 81 | protected String parseValueAsNumber(String val) 82 | { 83 | int strip = 0; 84 | if(val.endsWith("u")||val.endsWith("U")) 85 | { 86 | strip = 1; 87 | } else if(val.endsWith("UL")) 88 | { 89 | strip = 2; 90 | } else if(val.endsWith("ULL")) 91 | { 92 | strip = 3; 93 | } 94 | if((strip>0)&&(val.length()>strip)) 95 | { 96 | val = val.substring(0, val.length() - strip); 97 | } 98 | return val; 99 | } 100 | /* 101 | * Note: This stuff is decimal ONLY 102 | */ 103 | protected String parseValue(String val) 104 | { 105 | if((val==null)||(val.length()==0)) 106 | { 107 | dataType = DataType.BOOLEAN; 108 | } else { 109 | int start = 0; 110 | boolean is_hex = false; 111 | dataType = DataType.NUMBER; 112 | String tmpVal = parseValueAsNumber(val); 113 | if (tmpVal.length() > 2 && tmpVal.substring(0, 2).equals("0x")) { 114 | start = 2; 115 | is_hex = true; 116 | } 117 | for(int i=start; i'9')) 122 | { 123 | dataType = DataType.STRING; 124 | } 125 | } else { 126 | if ((tmpVal.charAt(i)<'0')||(tmpVal.charAt(i)>'9')) 127 | { 128 | if ((tmpVal.toLowerCase().charAt(i) < 'a') && (tmpVal.toLowerCase().charAt(i) > 'f')) 129 | dataType = DataType.STRING; 130 | } 131 | 132 | } 133 | } 134 | if(dataType == DataType.NUMBER) 135 | { 136 | val = tmpVal; 137 | } 138 | } 139 | return val; 140 | } 141 | public String getName() { 142 | return name; 143 | } 144 | public String getValue() { 145 | return value; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /sopc2dts/parsers/sopcinfo/SopcInfoComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.parsers.sopcinfo; 21 | 22 | import org.xml.sax.Attributes; 23 | import org.xml.sax.ContentHandler; 24 | import org.xml.sax.SAXException; 25 | import org.xml.sax.XMLReader; 26 | 27 | import sopc2dts.lib.BasicElement; 28 | import sopc2dts.lib.components.BasicComponent; 29 | 30 | public class SopcInfoComponent extends SopcInfoElementWithParams { 31 | 32 | public SopcInfoComponent(ContentHandler p, XMLReader xr, BasicElement be) { 33 | super(p, xr, be); 34 | } 35 | @Override 36 | public void startElement(String uri, String localName, String qName, 37 | Attributes atts) throws SAXException { 38 | if(localName.equalsIgnoreCase("interface")) 39 | { 40 | @SuppressWarnings("unused") 41 | SopcInfoInterface intf = new SopcInfoInterface(this, xmlReader, 42 | atts.getValue("name"), (BasicComponent)basicElement, atts); 43 | } else { 44 | super.startElement(uri, localName, qName, atts); 45 | } 46 | } 47 | 48 | @Override 49 | public String getElementName() { 50 | return "module"; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /sopc2dts/parsers/sopcinfo/SopcInfoElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.parsers.sopcinfo; 21 | import org.xml.sax.Attributes; 22 | import org.xml.sax.ContentHandler; 23 | import org.xml.sax.Locator; 24 | import org.xml.sax.SAXException; 25 | import org.xml.sax.XMLReader; 26 | 27 | 28 | public abstract class SopcInfoElement implements ContentHandler { 29 | protected ContentHandler parentElement = null; 30 | protected XMLReader xmlReader = null; 31 | 32 | public SopcInfoElement(ContentHandler p, XMLReader xr) 33 | { 34 | parentElement = p; 35 | xmlReader = xr; 36 | xmlReader.setContentHandler(this); 37 | } 38 | public abstract String getElementName(); 39 | 40 | public void startElement(String uri, String localName, String qName, 41 | Attributes atts) throws SAXException { 42 | System.out.println("Unhandled SopcInfo element: " + localName); 43 | } 44 | 45 | public void endElement(String uri, String localName, String qName) 46 | throws SAXException { 47 | if(localName.equalsIgnoreCase(getElementName())) 48 | { 49 | if((xmlReader!=null)&&(parentElement!=null)) 50 | { 51 | xmlReader.setContentHandler(parentElement); 52 | } 53 | } 54 | } 55 | 56 | 57 | public void characters(char[] ch, int start, int length) 58 | throws SAXException { 59 | } 60 | 61 | public void endDocument() throws SAXException { 62 | } 63 | 64 | public void endPrefixMapping(String prefix) throws SAXException { 65 | } 66 | 67 | public void ignorableWhitespace(char[] ch, int start, int length) 68 | throws SAXException { 69 | } 70 | 71 | public void processingInstruction(String target, String data) 72 | throws SAXException { 73 | } 74 | 75 | public void setDocumentLocator(Locator locator) { 76 | } 77 | 78 | public void skippedEntity(String name) throws SAXException { 79 | } 80 | 81 | public void startDocument() throws SAXException { 82 | } 83 | 84 | public void startPrefixMapping(String prefix, String uri) 85 | throws SAXException { 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /sopc2dts/parsers/sopcinfo/SopcInfoElementIgnoreAll.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.parsers.sopcinfo; 21 | 22 | import org.xml.sax.Attributes; 23 | import org.xml.sax.ContentHandler; 24 | import org.xml.sax.SAXException; 25 | import org.xml.sax.XMLReader; 26 | 27 | 28 | 29 | public class SopcInfoElementIgnoreAll extends SopcInfoElement { 30 | String elementName; 31 | public SopcInfoElementIgnoreAll(ContentHandler p, XMLReader xr, String name) { 32 | super(p, xr); 33 | elementName = name; 34 | } 35 | @Override 36 | public String getElementName() { 37 | // TODO Auto-generated method stub 38 | return elementName; 39 | } 40 | 41 | public void startElement(String uri, String localName, String qName, 42 | Attributes atts) throws SAXException { 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /sopc2dts/parsers/sopcinfo/SopcInfoElementWithParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.parsers.sopcinfo; 21 | 22 | import java.util.Vector; 23 | 24 | import org.xml.sax.Attributes; 25 | import org.xml.sax.ContentHandler; 26 | import org.xml.sax.SAXException; 27 | import org.xml.sax.XMLReader; 28 | 29 | import sopc2dts.lib.BasicElement; 30 | 31 | 32 | 33 | public abstract class SopcInfoElementWithParams extends SopcInfoElement { 34 | Vector vParams = new Vector(); 35 | BasicElement basicElement; 36 | public SopcInfoElementWithParams(ContentHandler p, XMLReader xr, BasicElement be) { 37 | super(p, xr); 38 | basicElement = be; 39 | } 40 | public String getParamValue(String paramName) 41 | { 42 | for(SopcInfoAssignment ass : vParams) 43 | { 44 | if(ass.getName().equalsIgnoreCase(paramName)) 45 | { 46 | return ass.getValue(); 47 | } 48 | } 49 | return null; 50 | } 51 | 52 | public SopcInfoAssignment getParam(String paramName) 53 | { 54 | for(SopcInfoAssignment ass : vParams) 55 | { 56 | if(ass.getName().equalsIgnoreCase(paramName)) 57 | { 58 | return ass; 59 | } 60 | } 61 | return null; 62 | } 63 | public Vector getParams() 64 | { 65 | return vParams; 66 | } 67 | 68 | @Override 69 | public void startElement(String uri, String localName, String qName, 70 | Attributes atts) throws SAXException { 71 | if(localName.equalsIgnoreCase("assignment")) 72 | { 73 | vParams.add(new SopcInfoAssignment(this, xmlReader,basicElement)); 74 | } else if(localName.equalsIgnoreCase("parameter")) 75 | { 76 | vParams.add(new SopcInfoParameter(this, xmlReader, atts.getValue("name"), basicElement)); 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /sopc2dts/parsers/sopcinfo/SopcInfoParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | sopc2dts - Devicetree generation for Altera systems 3 | 4 | Copyright (C) 2011 Walter Goossens 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package sopc2dts.parsers.sopcinfo; 21 | 22 | import org.xml.sax.ContentHandler; 23 | import org.xml.sax.SAXException; 24 | import org.xml.sax.XMLReader; 25 | 26 | import sopc2dts.lib.BasicElement; 27 | import sopc2dts.lib.Parameter.DataType; 28 | 29 | 30 | public class SopcInfoParameter extends SopcInfoAssignment { 31 | String type; 32 | Boolean derived; 33 | Boolean enabled; 34 | Boolean visible; 35 | Boolean valid; 36 | 37 | public SopcInfoParameter(ContentHandler p, XMLReader xr, String name, BasicElement be) 38 | { 39 | super(p,xr,be); 40 | this.name = name; 41 | } 42 | @Override 43 | public String getElementName() { 44 | return "parameter"; 45 | } 46 | protected String parseValue(String val) 47 | { 48 | if(this.type==null) 49 | { 50 | return super.parseValue(val); 51 | } else { 52 | if(type.equalsIgnoreCase("int")|| 53 | type.equalsIgnoreCase("long")) 54 | { 55 | if(val.endsWith("u") && (val.length()>1)) 56 | { 57 | String tmpVal = val.substring(0, val.length()-1); 58 | if(tmpVal.equalsIgnoreCase(Long.decode(tmpVal).toString())) 59 | { 60 | val = tmpVal; 61 | } 62 | } 63 | dataType = DataType.NUMBER; 64 | } else if(type.equalsIgnoreCase("boolean")) 65 | { 66 | dataType = DataType.BOOLEAN; 67 | } 68 | } 69 | return val; 70 | } 71 | public void characters(char[] ch, int start, int length) 72 | throws SAXException { 73 | if(currTag!=null) 74 | { 75 | if(currTag.equalsIgnoreCase("type")) 76 | { 77 | type = String.copyValueOf(ch, start, length); 78 | } else if(currTag.equalsIgnoreCase("derived")) 79 | { 80 | derived = Boolean.parseBoolean( 81 | String.copyValueOf(ch, start, length)); 82 | } else if(currTag.equalsIgnoreCase("enabled")) 83 | { 84 | enabled = Boolean.parseBoolean( 85 | String.copyValueOf(ch, start, length)); 86 | } else if(currTag.equalsIgnoreCase("visible")) 87 | { 88 | visible = Boolean.parseBoolean( 89 | String.copyValueOf(ch, start, length)); 90 | } else if(currTag.equalsIgnoreCase("valid")) 91 | { 92 | valid = Boolean.parseBoolean( 93 | String.copyValueOf(ch, start, length)); 94 | } else { 95 | super.characters(ch, start, length); 96 | } 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /sopc_components_fps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sopc_components_labx.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sopc_components_nxp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sopc_components_others.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | --------------------------------------------------------------------------------