mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
first verilog inout test has passed, see #394
This commit is contained in:
parent
a78fa95764
commit
ca6c9a9794
@ -56,12 +56,17 @@ public class VerilogCreator {
|
||||
/**
|
||||
* Returns the verilog type for a signal
|
||||
*
|
||||
* @param dir the signal type (input or output)
|
||||
* @param def the signal type (input or output) used if dir is not "inout"
|
||||
* @param dir used to check if direction is "inout"
|
||||
* @param bits the number of bits
|
||||
* @return the verilog signal type
|
||||
*/
|
||||
public static String getType(HDLPort.Direction dir, int bits) {
|
||||
String result = (dir == HDLPort.Direction.IN) ? "input" : "output";
|
||||
public static String getType(HDLPort.Direction def, HDLPort.Direction dir, int bits) {
|
||||
String result;
|
||||
if (dir == HDLPort.Direction.INOUT)
|
||||
result = "inout";
|
||||
else
|
||||
result = (def == HDLPort.Direction.IN) ? "input" : "output";
|
||||
|
||||
if (bits > 1) {
|
||||
result += " [" + (bits - 1) + ":0]";
|
||||
@ -181,12 +186,12 @@ public class VerilogCreator {
|
||||
|
||||
for (HDLPort i : circuit.getInputs()) {
|
||||
sep.check();
|
||||
out.print(getType(HDLPort.Direction.IN, i.getBits())).print(" ").print(i.getName());
|
||||
out.print(getType(HDLPort.Direction.IN, i.getDirection(), i.getBits())).print(" ").print(i.getName());
|
||||
if (i.hasDescription()) sep.setLineFinalizer(ou -> ou.printComment(" // ", i.getDescription()));
|
||||
}
|
||||
for (HDLPort o : circuit.getOutputs()) {
|
||||
sep.check();
|
||||
out.print(getType(HDLPort.Direction.OUT, o.getBits())).print(" ").print(o.getName());
|
||||
out.print(getType(HDLPort.Direction.OUT, o.getDirection(), o.getBits())).print(" ").print(o.getName());
|
||||
if (o.hasDescription()) sep.setLineFinalizer(ou -> ou.printComment(" // ", o.getDescription()));
|
||||
}
|
||||
sep.close();
|
||||
@ -260,6 +265,12 @@ public class VerilogCreator {
|
||||
sep.check();
|
||||
out.print(".").print(o.getName()).print("( ").print(o.getNet().getName()).print(" )");
|
||||
}
|
||||
|
||||
for (HDLPort o : node.getInOutputs())
|
||||
if (o.getNet() != null) {
|
||||
sep.check();
|
||||
out.print(".").print(o.getName()).print("( ").print(o.getNet().getName()).print(" )");
|
||||
}
|
||||
out.dec();
|
||||
out.println().println(");");
|
||||
}
|
||||
|
26
src/main/resources/verilog/DIG_PinControl.v
Normal file
26
src/main/resources/verilog/DIG_PinControl.v
Normal file
@ -0,0 +1,26 @@
|
||||
<?
|
||||
if (elem.Bits > 1) {
|
||||
generics[0] := "Bits";
|
||||
export bitRange := "[(Bits-1):0] ";
|
||||
export zval := "{Bits{1'bz}}";
|
||||
}
|
||||
else {
|
||||
moduleName = moduleName+"_BUS";
|
||||
export bitRange := "";
|
||||
export zval := "1'bz";
|
||||
}
|
||||
?>module <?= moduleName ?><?
|
||||
if (elem.Bits > 1) { ?>
|
||||
#(
|
||||
parameter Bits = 2
|
||||
)
|
||||
<? } ?>(
|
||||
inout <?= bitRange ?>pin,
|
||||
input oe,
|
||||
input <?= bitRange ?>wr,
|
||||
output <?= bitRange ?>rd
|
||||
);
|
||||
|
||||
assign pin = oe ? wr : <?= zval ?>;
|
||||
assign rd = oe ? wr : pin ;
|
||||
endmodule
|
@ -14,6 +14,7 @@ import de.neemann.digital.draw.library.ElementNotFoundException;
|
||||
import de.neemann.digital.gui.Settings;
|
||||
import de.neemann.digital.hdl.model2.HDLException;
|
||||
import de.neemann.digital.hdl.printer.CodePrinter;
|
||||
import de.neemann.digital.hdl.printer.CodePrinterStr;
|
||||
import de.neemann.digital.integration.FileScanner;
|
||||
import de.neemann.digital.integration.Resources;
|
||||
import de.neemann.digital.integration.TestExamples;
|
||||
@ -42,13 +43,13 @@ public class VerilogSimulatorTest extends TestCase {
|
||||
|
||||
/*
|
||||
public void testDebug() throws Exception {
|
||||
File file = new File(Resources.getRoot(), "dig/test/vhdl/lut.dig");
|
||||
File file = new File(Resources.getRoot(), "/dig/test/vhdl/pinControl/simple.dig");
|
||||
|
||||
ToBreakRunner br = new ToBreakRunner(file);
|
||||
System.out.println(new VerilogGenerator(br.getLibrary(), new CodePrinterStr(true)).export(br.getCircuit()));
|
||||
|
||||
checkVerilogExport(file);
|
||||
}*/
|
||||
}/**/
|
||||
|
||||
public void testInSimulator() throws Exception {
|
||||
File examples = new File(Resources.getRoot(), "/dig/test/vhdl");
|
||||
@ -71,6 +72,19 @@ public class VerilogSimulatorTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void testInSimulatorInOut() throws Exception {
|
||||
File examples = new File(Resources.getRoot(), "/dig/test/pinControl");
|
||||
try {
|
||||
int tested = new FileScanner(this::checkVerilogExport).noOutput().scan(examples);
|
||||
assertEquals(2, tested);
|
||||
assertEquals(2, testBenches);
|
||||
} catch (FileScanner.SkipAllException e) {
|
||||
// if iverilog is not installed its also ok
|
||||
}
|
||||
}/**/
|
||||
|
||||
|
||||
public void testDistributedInSimulator() throws Exception {
|
||||
File examples = new File(Resources.getRoot(), "../../main/dig/hdl");
|
||||
try {
|
||||
|
@ -14,7 +14,6 @@ import de.neemann.digital.draw.library.ElementNotFoundException;
|
||||
import de.neemann.digital.gui.Settings;
|
||||
import de.neemann.digital.hdl.model2.HDLException;
|
||||
import de.neemann.digital.hdl.printer.CodePrinter;
|
||||
import de.neemann.digital.hdl.printer.CodePrinterStr;
|
||||
import de.neemann.digital.integration.FileScanner;
|
||||
import de.neemann.digital.integration.Resources;
|
||||
import de.neemann.digital.integration.TestExamples;
|
||||
@ -33,7 +32,7 @@ public class VHDLSimulatorTest extends TestCase {
|
||||
private static final String GHDL = System.getProperty("ghdl", "ghdl");
|
||||
private int testBenches;
|
||||
|
||||
//*
|
||||
/*
|
||||
public void testDebug() throws Exception {
|
||||
File file = new File(Resources.getRoot(), "/dig/test/pinControl/simple.dig");
|
||||
|
||||
@ -64,6 +63,17 @@ public class VHDLSimulatorTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testInSimulatorInOut() throws Exception {
|
||||
File examples = new File(Resources.getRoot(), "/dig/test/pinControl");
|
||||
try {
|
||||
int tested = new FileScanner(this::checkVHDLExport).noOutput().scan(examples);
|
||||
assertEquals(2, tested);
|
||||
assertEquals(2, testBenches);
|
||||
} catch (FileScanner.SkipAllException e) {
|
||||
// if ghdl is not installed its also ok
|
||||
}
|
||||
}
|
||||
|
||||
public void testDistributedInSimulator() throws Exception {
|
||||
File examples = new File(Resources.getRoot(), "../../main/dig/hdl");
|
||||
try {
|
||||
|
@ -43,8 +43,8 @@ public class TestExamples extends TestCase {
|
||||
*/
|
||||
public void testTestExamples() throws Exception {
|
||||
File examples = new File(Resources.getRoot(), "/dig/test");
|
||||
assertEquals(185, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(173, testCasesInFiles);
|
||||
assertEquals(186, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(174, testCasesInFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
98
src/test/resources/dig/test/pinControl/uniTest.dig
Normal file
98
src/test/resources/dig/test/pinControl/uniTest.dig
Normal file
@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes/>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>wr</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="320" y="160"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>oe</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="320" y="240"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>PinControl</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="360" y="200"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="2"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>rd</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="320" y="200"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>pin</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="420" y="200"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Testcase</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Testdata</string>
|
||||
<testData>
|
||||
<dataString>oe wr rd pin
|
||||
1 0 0 0
|
||||
1 1 1 1
|
||||
</dataString>
|
||||
</testData>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="360" y="240"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="340" y="160"/>
|
||||
<p2 x="360" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="340" y="240"/>
|
||||
<p2 x="360" y="220"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="160"/>
|
||||
<p2 x="340" y="160"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="240"/>
|
||||
<p2 x="340" y="240"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="400" y="200"/>
|
||||
<p2 x="420" y="200"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="200"/>
|
||||
<p2 x="360" y="200"/>
|
||||
</wire>
|
||||
</wires>
|
||||
<measurementOrdering/>
|
||||
</circuit>
|
Loading…
x
Reference in New Issue
Block a user