mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-19 09:54:49 -04:00
Ff the clock frequency is set to the board frequency, the prescaler is omitted.
This commit is contained in:
parent
c7831429eb
commit
a6579f5d7e
@ -258,18 +258,20 @@ public class HDLModel implements HDLInterface, Iterable<HDLNode> {
|
||||
public void integrateClocks(int period) throws HDLException {
|
||||
for (HDLClock c : clocks) {
|
||||
int freq = c.getFrequency();
|
||||
int counter = 1000000000 / (period * freq * 2);
|
||||
int counter = (int) (1000000000L / (2L * period * freq));
|
||||
|
||||
Port cOut = new Port("out", Port.Direction.out).setBits(1);
|
||||
Port cIn = new Port("in", Port.Direction.in).setBits(1);
|
||||
if (counter >= 2) {
|
||||
Port cOut = new Port("out", Port.Direction.out).setBits(1);
|
||||
Port cIn = new Port("in", Port.Direction.in).setBits(1);
|
||||
|
||||
Signal oldSig = c.getClockPort().getSignal();
|
||||
Signal newSig = createSignal();
|
||||
oldSig.replaceWith(newSig);
|
||||
newSig.addPort(cOut);
|
||||
oldSig.addPort(cIn);
|
||||
Signal oldSig = c.getClockPort().getSignal();
|
||||
Signal newSig = createSignal();
|
||||
oldSig.replaceWith(newSig);
|
||||
newSig.addPort(cOut);
|
||||
oldSig.addPort(cIn);
|
||||
|
||||
nodeList.add(new HDLClockNode(counter, new Ports().add(cIn).add(cOut)));
|
||||
nodeList.add(new HDLClockNode(counter, new Ports().add(cIn).add(cOut)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class TestInSimulator extends TestCase {
|
||||
File examples = new File(Resources.getRoot(), "/dig/hdl");
|
||||
try {
|
||||
int tested = new FileScanner(this::check).scan(examples);
|
||||
assertEquals(24, tested);
|
||||
assertEquals(25, tested);
|
||||
} catch (FileScanner.SkipAllException e) {
|
||||
// if ghdl is not installed its also ok
|
||||
}
|
||||
|
@ -228,4 +228,62 @@ public class ClockTest extends TestCase {
|
||||
"end DIG_simpleClockDivider_arch;\n", vhdl);
|
||||
}
|
||||
|
||||
|
||||
// If frequency is high, the clock divider is omitted.
|
||||
public void testClock3() throws PinException, NodeException, ElementNotFoundException, IOException, HDLException {
|
||||
ToBreakRunner br = new ToBreakRunner("dig/hdl/Clock3.dig");
|
||||
String vhdl = new VHDLExporter(br.getLibrary()) {
|
||||
@Override
|
||||
protected void fixClocks(HDLModel model) throws HDLException {
|
||||
model.integrateClocks(10);
|
||||
}
|
||||
}.export(br.getCircuit()).toString();
|
||||
|
||||
assertEquals("-- auto generated by Digital\n" +
|
||||
"\n" +
|
||||
"LIBRARY ieee;\n" +
|
||||
"USE ieee.std_logic_1164.all;\n" +
|
||||
"USE ieee.numeric_std.all;\n" +
|
||||
"\n" +
|
||||
"entity main is\n" +
|
||||
" port (\n" +
|
||||
" PORT_OV: out std_logic;\n" +
|
||||
" PORT_C: in std_logic );\n" +
|
||||
"end main;\n" +
|
||||
"\n" +
|
||||
"architecture main_arch of main is\n" +
|
||||
"\n" +
|
||||
" component NOT_GATE\n" +
|
||||
" port (\n" +
|
||||
" PORT_out: out std_logic;\n" +
|
||||
" PORT_in: in std_logic );\n" +
|
||||
" end component;\n" +
|
||||
"\n" +
|
||||
"begin\n" +
|
||||
" gate0 : NOT_GATE\n" +
|
||||
" port map (\n" +
|
||||
" PORT_out => PORT_OV,\n" +
|
||||
" PORT_in => PORT_C );\n" +
|
||||
"end main_arch;\n" +
|
||||
"\n" +
|
||||
"-- library components\n" +
|
||||
"\n" +
|
||||
"-- NOT_GATE\n" +
|
||||
"\n" +
|
||||
"LIBRARY ieee;\n" +
|
||||
"USE ieee.std_logic_1164.all;\n" +
|
||||
"\n" +
|
||||
"entity NOT_GATE is\n" +
|
||||
" port (\n" +
|
||||
" PORT_out: out std_logic;\n" +
|
||||
" PORT_in: in std_logic );\n" +
|
||||
"end NOT_GATE;\n" +
|
||||
"\n" +
|
||||
"architecture NOT_GATE_arch of NOT_GATE is\n" +
|
||||
"begin\n" +
|
||||
" PORT_out <= NOT( PORT_in );\n" +
|
||||
"end NOT_GATE_arch;\n", vhdl);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
65
src/test/resources/dig/hdl/Clock3.dig
Normal file
65
src/test/resources/dig/hdl/Clock3.dig
Normal file
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes/>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>OV</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>pinNumber</string>
|
||||
<string>U18</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="360" y="180"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Clock</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>C</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>pinNumber</string>
|
||||
<string>W5</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Frequency</string>
|
||||
<int>100000000</int>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="280" y="180"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Not</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="300" y="180"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Text</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Description</string>
|
||||
<string>Board: BASYS3</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="160" y="100"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="280" y="180"/>
|
||||
<p2 x="300" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="340" y="180"/>
|
||||
<p2 x="360" y="180"/>
|
||||
</wire>
|
||||
</wires>
|
||||
<measurementOrdering/>
|
||||
</circuit>
|
Loading…
x
Reference in New Issue
Block a user