added vhdl templates for async flip flops

This commit is contained in:
hneemann 2017-08-14 13:57:23 +02:00
parent 7827f6911c
commit cdb2eef854
11 changed files with 418 additions and 14 deletions

View File

@ -63,6 +63,7 @@ public class Port {
.replace('.', '_')
.replace('-', '_')
.replace("\u00AC", "not")
.replace("~", "not")
.replace("=", "eq")
.replace("<", "le")
.replace(">", "gr");

View File

@ -7,7 +7,7 @@ import java.io.IOException;
/**
* Used to create separators
*/
public final class Separator {
public class Separator {
private final String sep;
private boolean first = true;
@ -30,6 +30,13 @@ public final class Separator {
if (first)
first = false;
else
out.print(sep);
out.print(getSeperator());
}
/**
* @return the separator
*/
public String getSeperator() {
return sep;
}
}

View File

@ -67,7 +67,7 @@ public class VHDLTestBenchCreator {
else
testName = filename + "_tb";
testName=Port.getHDLName(testName);
testName = Port.getHDLName(testName);
File f = new File(file.getParentFile(), testName + ".vhdl");
testFileWritten.add(f);
@ -163,11 +163,17 @@ public class VHDLTestBenchCreator {
private final CodePrinter out;
private final ArrayList<Port> dataOrder;
private final Separator lineSep;
private int line = 0;
private LineListenerVHDL(CodePrinter out, ArrayList<Port> dataOrder) {
this.out = out;
this.dataOrder = dataOrder;
lineSep = new Separator(",\n");
lineSep = new Separator("") {
@Override
public String getSeperator() {
return ", -- i=" + (line++) + "\n";
}
};
}
@Override

View File

@ -0,0 +1,31 @@
LIBRARY ieee;
USE ieee.std_logic_1164.all;
entity DIG_D_FF_AS is
port (
PORT_Q: out {{data}};
PORT_notQ: out {{data}};
PORT_Set: in std_logic;
PORT_D: in {{data}};
PORT_C: in std_logic;
PORT_Clr: in std_logic );
end DIG_D_FF_AS;
architecture DIG_D_FF_AS_arch of DIG_D_FF_AS is
signal state : {{data}} := {{zero}};
begin
process ( PORT_Set, PORT_Clr, PORT_C )
begin
if (PORT_Set='1') then
state <= NOT({{zero}});
elsif (PORT_Clr='1') then
state <= {{zero}};
elsif rising_edge(PORT_C) then
state <= PORT_D;
end if;
end process;
PORT_Q <= state;
PORT_notQ <= NOT( state );
end DIG_D_FF_AS_arch;

View File

@ -17,9 +17,7 @@ begin
process (PORT_C)
begin
if rising_edge(PORT_C) then
if (PORT_J='0' and PORT_K='0') then
temp <= temp;
elsif (PORT_J='0' and PORT_K='1') then
if (PORT_J='0' and PORT_K='1') then
temp <= '0';
elsif (PORT_J='1' and PORT_K='0') then
temp <= '1';

View File

@ -0,0 +1,38 @@
LIBRARY ieee;
USE ieee.std_logic_1164.all;
entity DIG_JK_FF_AS is
generic (Default : std_logic);
port (
PORT_Q: out std_logic;
PORT_notQ: out std_logic;
PORT_Set: in std_logic;
PORT_J: in std_logic;
PORT_C: in std_logic;
PORT_K: in std_logic;
PORT_Clr: in std_logic );
end DIG_JK_FF_AS;
architecture DIG_JK_FF_AS_arch of DIG_JK_FF_AS is
signal state: std_logic := Default;
begin
process (PORT_C, PORT_Clr, PORT_Set)
begin
if (PORT_Set='1') then
state <= '1';
elsif (PORT_Clr='1') then
state <= '0';
elsif rising_edge(PORT_C) then
if (PORT_J='0' and PORT_K='1') then
state <= '0';
elsif (PORT_J='1' and PORT_K='0') then
state <= '1';
elsif (PORT_J='1' and PORT_K='1') then
state <= not (state);
end if;
end if;
end process;
PORT_Q <= state;
PORT_notQ <= NOT( state );
end DIG_JK_FF_AS_arch;

View File

@ -12,9 +12,9 @@ end DIG_Register;
architecture DIG_Register_arch of DIG_Register is
signal state : {{data}} := {{zero}};
begin
PORT_Q <= state;
PORT_Q <= state;
process(PORT_C)
process ( PORT_C )
begin
if rising_edge(PORT_C) and (PORT_en='1') then
state <= PORT_D;

View File

@ -18,7 +18,10 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
/**
* Test vhdl files in ghdl simulator
@ -34,8 +37,8 @@ public class TestInSimulator extends TestCase {
int tested = new FileScanner(this::check).scan(examples);
// if tested is negative, ghdl was not found and tests are skipped!
if (tested >= 0) {
assertEquals(5, tested);
assertEquals(5, testBenches);
assertEquals(7, tested);
assertEquals(7, testBenches);
}
}
@ -55,7 +58,7 @@ public class TestInSimulator extends TestCase {
private void check(File file) throws PinException, NodeException, ElementNotFoundException, IOException, FileScanner.SkipAllException, HDLException {
ToBreakRunner br = new ToBreakRunner(file);
File dir = Files.createTempDirectory("digital_vhdl_test_").toFile();
File dir = Files.createTempDirectory("digital_vhdl_"+getTime()+"_").toFile();
File vhdlFile = new File(dir, file.getName().replace('.', '_') + ".vhdl");
CodePrinter out = new CodePrinter(vhdlFile);
try (VHDLExporter vhdl = new VHDLExporter(br.getLibrary(), out){
@ -125,6 +128,11 @@ public class TestInSimulator extends TestCase {
}
}
private String getTime() {
DateFormat f = new SimpleDateFormat("YY-MM-dd_HH-mm_ss");
return f.format(new Date());
}
private static final class ReaderThread extends Thread {
private final ByteArrayOutputStream baos;
private final InputStream in;

View File

@ -40,8 +40,8 @@ public class TestExamples extends TestCase {
*/
public void testTestExamples() throws Exception {
File examples = new File(Resources.getRoot(), "/dig/test");
assertEquals(88, new FileScanner(this::check).scan(examples));
assertEquals(79, testCasesInFiles);
assertEquals(90, new FileScanner(this::check).scan(examples));
assertEquals(81, testCasesInFiles);
}

View File

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>CLK</string>
</entry>
</elementAttributes>
<pos x="300" y="240"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D</string>
</entry>
</elementAttributes>
<pos x="300" y="200"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>S</string>
</entry>
</elementAttributes>
<pos x="300" y="160"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>C</string>
</entry>
</elementAttributes>
<pos x="300" y="280"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q</string>
</entry>
</elementAttributes>
<pos x="440" y="200"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>~Q</string>
</entry>
</elementAttributes>
<pos x="520" y="220"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Testdata</string>
<testData>
<dataString>CLK D S C Q ~Q
0 0 0 0 0 1
0 1 0 0 0 1
C 1 0 0 1 0
0 0 0 0 1 0
C 0 0 0 0 1
0 0 0 1 0 1
0 0 0 0 0 1
0 0 1 0 1 0
0 0 0 0 1 0
</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="480" y="260"/>
</visualElement>
<visualElement>
<elementName>D_FF_AS</elementName>
<elementAttributes/>
<pos x="360" y="200"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="300" y="240"/>
<p2 x="360" y="240"/>
</wire>
<wire>
<p1 x="300" y="160"/>
<p2 x="340" y="160"/>
</wire>
<wire>
<p1 x="340" y="260"/>
<p2 x="360" y="260"/>
</wire>
<wire>
<p1 x="300" y="200"/>
<p2 x="320" y="200"/>
</wire>
<wire>
<p1 x="340" y="200"/>
<p2 x="360" y="200"/>
</wire>
<wire>
<p1 x="420" y="200"/>
<p2 x="440" y="200"/>
</wire>
<wire>
<p1 x="300" y="280"/>
<p2 x="340" y="280"/>
</wire>
<wire>
<p1 x="320" y="220"/>
<p2 x="360" y="220"/>
</wire>
<wire>
<p1 x="420" y="220"/>
<p2 x="520" y="220"/>
</wire>
<wire>
<p1 x="320" y="200"/>
<p2 x="320" y="220"/>
</wire>
<wire>
<p1 x="340" y="160"/>
<p2 x="340" y="200"/>
</wire>
<wire>
<p1 x="340" y="260"/>
<p2 x="340" y="280"/>
</wire>
</wires>
</circuit>

View File

@ -0,0 +1,171 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>JK_FF_AS</elementName>
<elementAttributes/>
<pos x="360" y="200"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>CLK</string>
</entry>
</elementAttributes>
<pos x="300" y="240"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>J</string>
</entry>
</elementAttributes>
<pos x="300" y="200"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>S</string>
</entry>
</elementAttributes>
<pos x="300" y="160"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>K</string>
</entry>
</elementAttributes>
<pos x="300" y="280"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>C</string>
</entry>
</elementAttributes>
<pos x="300" y="320"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q</string>
</entry>
</elementAttributes>
<pos x="440" y="200"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>~Q</string>
</entry>
</elementAttributes>
<pos x="520" y="220"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Testdata</string>
<testData>
<dataString>CLK J K S C Q ~Q
0 0 0 0 0 0 1
C 1 0 0 0 1 0
0 1 0 0 0 1 0
0 0 0 0 0 1 0
0 0 1 0 0 1 0
C 0 1 0 0 0 1
0 0 0 0 0 0 1
C 1 0 0 0 1 0
0 0 0 1 0 1 0
0 0 0 0 1 0 1
C 1 1 0 0 1 0
C 1 1 0 0 0 1
C 1 1 0 0 1 0
C 1 1 0 0 0 1
</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="480" y="300"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="300" y="240"/>
<p2 x="360" y="240"/>
</wire>
<wire>
<p1 x="300" y="160"/>
<p2 x="340" y="160"/>
</wire>
<wire>
<p1 x="300" y="320"/>
<p2 x="340" y="320"/>
</wire>
<wire>
<p1 x="320" y="260"/>
<p2 x="360" y="260"/>
</wire>
<wire>
<p1 x="300" y="200"/>
<p2 x="320" y="200"/>
</wire>
<wire>
<p1 x="340" y="200"/>
<p2 x="360" y="200"/>
</wire>
<wire>
<p1 x="420" y="200"/>
<p2 x="440" y="200"/>
</wire>
<wire>
<p1 x="300" y="280"/>
<p2 x="320" y="280"/>
</wire>
<wire>
<p1 x="340" y="280"/>
<p2 x="360" y="280"/>
</wire>
<wire>
<p1 x="320" y="220"/>
<p2 x="360" y="220"/>
</wire>
<wire>
<p1 x="420" y="220"/>
<p2 x="520" y="220"/>
</wire>
<wire>
<p1 x="320" y="200"/>
<p2 x="320" y="220"/>
</wire>
<wire>
<p1 x="320" y="260"/>
<p2 x="320" y="280"/>
</wire>
<wire>
<p1 x="340" y="160"/>
<p2 x="340" y="200"/>
</wire>
<wire>
<p1 x="340" y="280"/>
<p2 x="340" y="320"/>
</wire>
</wires>
</circuit>