Skip to content

Commit 680c059

Browse files
committed
New example
1 parent e62e8f4 commit 680c059

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TARGET=$(shell ls *.py | grep -v test | grep -v parsetab.py)
2+
ARGS=
3+
4+
PYTHON=python3
5+
#PYTHON=python
6+
#OPT=-m pdb
7+
#OPT=-m cProfile -s time
8+
#OPT=-m cProfile -o profile.rslt
9+
10+
.PHONY: all
11+
all: test
12+
13+
.PHONY: run
14+
run:
15+
$(PYTHON) $(OPT) $(TARGET) $(ARGS)
16+
17+
.PHONY: test
18+
test:
19+
$(PYTHON) -m pytest -vv
20+
21+
.PHONY: check
22+
check:
23+
$(PYTHON) $(OPT) $(TARGET) $(ARGS) > tmp.v
24+
iverilog -tnull -Wall tmp.v
25+
rm -f tmp.v
26+
27+
.PHONY: clean
28+
clean:
29+
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v uut.vcd
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
4+
import os
5+
import veriloggen
6+
import thread_stream_terminate_search_stall
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_terminate_search_stall.run(filename=None, simtype=simtype,
15+
outputfile=os.path.splitext(os.path.basename(__file__))[0] + '.out')
16+
17+
verify_rslt = rslt.splitlines()[-1]
18+
assert(verify_rslt == '# verify: PASSED')
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
import sys
4+
import os
5+
6+
# the next line can be removed after installation
7+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(
8+
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))))
9+
10+
from veriloggen import *
11+
import veriloggen.thread as vthread
12+
import veriloggen.types.axi as axi
13+
import veriloggen.types.util as util
14+
15+
16+
def mkLed():
17+
m = Module('blinkled')
18+
clk = m.Input('CLK')
19+
rst = m.Input('RST')
20+
21+
datawidth = 32
22+
addrwidth = 10
23+
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth)
24+
myaxi.disable_write()
25+
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
26+
27+
strm = vthread.Stream(m, 'mystream', clk, rst)
28+
a = strm.source('a')
29+
i = strm.Counter()
30+
term = a == 270
31+
strm.sink(i, 'i')
32+
strm.terminate(term)
33+
34+
# add a stall condition
35+
count = m.Reg('count', 4, initval=0)
36+
seq = Seq(m, 'seq', clk, rst)
37+
seq(
38+
count.inc()
39+
)
40+
41+
util.add_disable_cond(strm.oready, 1, count == 0)
42+
43+
def comp_stream(size, offset):
44+
strm.set_source('a', ram_a, offset, size)
45+
strm.set_sink_immediate('i', 0)
46+
strm.run()
47+
strm.join()
48+
i = strm.read_sink('i')
49+
return i
50+
51+
def comp_sequential(size, offset):
52+
for i in range(size):
53+
a = ram_a.read(i + offset)
54+
if a == 270:
55+
return i
56+
return size - 1
57+
58+
def check(size_stream, size_seq):
59+
all_ok = True
60+
if vthread.verilog.NotEql(size_stream, size_seq):
61+
all_ok = False
62+
print(size_stream, size_seq)
63+
if all_ok:
64+
print('# verify: PASSED')
65+
else:
66+
print('# verify: FAILED')
67+
68+
def comp(size):
69+
# stream
70+
offset = 0
71+
myaxi.dma_read(ram_a, offset, 1024, size)
72+
st_i = comp_stream(size, offset)
73+
st_i = comp_stream(size, offset)
74+
75+
# sequential
76+
offset = size
77+
myaxi.dma_read(ram_a, offset, 1024, size)
78+
sq_i = comp_sequential(size, offset)
79+
80+
# verification
81+
check(st_i, sq_i)
82+
83+
vthread.finish()
84+
85+
th = vthread.Thread(m, 'th_comp', clk, rst, comp)
86+
fsm = th.start(32)
87+
88+
return m
89+
90+
91+
def mkTest(memimg_name=None):
92+
m = Module('test')
93+
94+
# target instance
95+
led = mkLed()
96+
97+
# copy paras and ports
98+
params = m.copy_params(led)
99+
ports = m.copy_sim_ports(led)
100+
101+
clk = ports['CLK']
102+
rst = ports['RST']
103+
104+
memory = axi.AxiMemoryModel(m, 'memory', clk, rst, memimg_name=memimg_name)
105+
memory.connect(ports, 'myaxi')
106+
107+
uut = m.Instance(led, 'uut',
108+
params=m.connect_params(led),
109+
ports=m.connect_ports(led))
110+
111+
# simulation.setup_waveform(m, uut)
112+
simulation.setup_clock(m, clk, hperiod=5)
113+
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
114+
115+
init.add(
116+
Delay(1000000),
117+
Systask('finish'),
118+
)
119+
120+
return m
121+
122+
123+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
124+
125+
if outputfile is None:
126+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
127+
128+
memimg_name = 'memimg_' + outputfile
129+
130+
test = mkTest(memimg_name=memimg_name)
131+
132+
if filename is not None:
133+
test.to_verilog(filename)
134+
135+
sim = simulation.Simulator(test, sim=simtype)
136+
rslt = sim.run(outputfile=outputfile)
137+
lines = rslt.splitlines()
138+
if simtype == 'verilator' and lines[-1].startswith('-'):
139+
rslt = '\n'.join(lines[:-1])
140+
return rslt
141+
142+
143+
if __name__ == '__main__':
144+
rslt = run(filename='tmp.v')
145+
print(rslt)

0 commit comments

Comments
 (0)