diff --git a/src/main/java/de/neemann/digital/hdl/vhdl/boards/BoardProvider.java b/src/main/java/de/neemann/digital/hdl/vhdl/boards/BoardProvider.java index f556b33ac..26a3df699 100644 --- a/src/main/java/de/neemann/digital/hdl/vhdl/boards/BoardProvider.java +++ b/src/main/java/de/neemann/digital/hdl/vhdl/boards/BoardProvider.java @@ -45,7 +45,11 @@ public final class BoardProvider { return null; if (board.equals("basys3")) - return new Vivado("LVCMOS33", "W5", 10, new ClockIntegratorARTIX7(10)); + return new Vivado("LVCMOS33", + "W5", + 10, + new ClockIntegratorARTIX7(10), + "xc7a35ticpg236-1L"); return null; } diff --git a/src/main/java/de/neemann/digital/hdl/vhdl/boards/Vivado.java b/src/main/java/de/neemann/digital/hdl/vhdl/boards/Vivado.java index e4fd5a3a4..abcfc366a 100644 --- a/src/main/java/de/neemann/digital/hdl/vhdl/boards/Vivado.java +++ b/src/main/java/de/neemann/digital/hdl/vhdl/boards/Vivado.java @@ -7,9 +7,7 @@ import de.neemann.digital.hdl.model.Port; import de.neemann.digital.hdl.printer.CodePrinter; import de.neemann.digital.lang.Lang; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.*; /** * Creates the needed vivado files. @@ -21,6 +19,7 @@ public class Vivado implements BoardInterface { private final String clockPin; private final int periodns; private final ClockIntegrator clockIntegrator; + private final String device; /** * Creates a new instance @@ -29,20 +28,26 @@ public class Vivado implements BoardInterface { * @param clockPin the pin the clock is connected to * @param periodns the clock period in nano seconds * @param clockIntegrator the clock integrator to use + * @param device the xilinx device code */ - public Vivado(String pinIoType, String clockPin, int periodns, ClockIntegrator clockIntegrator) { + public Vivado(String pinIoType, String clockPin, int periodns, ClockIntegrator clockIntegrator, String device) { this.pinIoType = pinIoType; this.clockPin = clockPin; this.periodns = periodns; this.clockIntegrator = clockIntegrator; + this.device = device; } @Override public void writeFiles(File path, HDLModel model) throws IOException { - File f = new File(path.getParentFile(), path.getName().replace('.', '_') + "_constraints.xdc"); - try (CodePrinter out = new CodePrinter(new FileOutputStream(f))) { + String projectName = path.getName(); + if (projectName.endsWith(".vhdl")) + projectName = projectName.substring(0, projectName.length() - 5); + File constraints = new File(path.getParentFile(), projectName.replace('.', '_') + "_constraints.xdc"); + try (CodePrinter out = new CodePrinter(new FileOutputStream(constraints))) { writeConstraints(out, model); } + createVivadoProject(path.getParentFile(), projectName, path, constraints); } void writeConstraints(CodePrinter out, HDLModel model) throws IOException { @@ -83,4 +88,58 @@ public class Vivado implements BoardInterface { return clockIntegrator; } + private void createVivadoProject(File path, String projectName, File vhdl, File constraints) throws IOException { + String projectDir = projectName + "_vivado"; + File projectPath = new File(path, projectDir); + // don't overwrite existing projects! + if (!projectPath.exists()) { + if (projectPath.mkdirs()) { + File projectFile = new File(projectPath, projectName + ".xpr"); + try (BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(projectFile), "utf-8"))) { + writeVivadoProject(w, projectFile, vhdl, constraints); + } + } + } + } + + private void writeVivadoProject(BufferedWriter w, File project, File vhdl, File constraints) throws IOException { + w.write("\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""); + } + } diff --git a/src/test/java/de/neemann/digital/hdl/vhdl/boards/VivadoTest.java b/src/test/java/de/neemann/digital/hdl/vhdl/boards/VivadoTest.java index 3caa84f03..9a12a6eac 100644 --- a/src/test/java/de/neemann/digital/hdl/vhdl/boards/VivadoTest.java +++ b/src/test/java/de/neemann/digital/hdl/vhdl/boards/VivadoTest.java @@ -21,7 +21,7 @@ public class VivadoTest extends TestCase { CodePrinterStr cp = new CodePrinterStr(); - Vivado v = new Vivado("testType", "clockPin", 1, null); + Vivado v = new Vivado("testType", "clockPin", 1, null, "xc7a35ticpg236-1L"); v.writeConstraints(cp, model); assertEquals(