Skip to content

Commit 2e9c479

Browse files
committed
Merge branch 'develop' into feature_axi_stream
2 parents 803643a + 6aae207 commit 2e9c479

File tree

11 files changed

+826
-2
lines changed

11 files changed

+826
-2
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_read_modify_write
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_read_modify_write.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: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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+
14+
15+
def mkLed():
16+
m = Module('blinkled')
17+
clk = m.Input('CLK')
18+
rst = m.Input('RST')
19+
20+
datawidth = 32
21+
addrwidth = 10
22+
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth)
23+
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
24+
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth, numports=2)
25+
26+
strm = vthread.Stream(m, 'mystream', clk, rst)
27+
numbins = strm.constant('numbins')
28+
offset = strm.constant('offset')
29+
a = strm.source('a')
30+
a = strm.Mux(a < 0, 0, a)
31+
a.latency = 0
32+
a = strm.Mux(a >= numbins, numbins - 1, a)
33+
a.latency = 0
34+
35+
raddr = a + offset
36+
raddrs = (raddr,)
37+
waddr = raddr
38+
op = strm.Add
39+
op_args = (1,)
40+
strm.read_modify_write_RAM('ext', raddrs, waddr, op, op_args)
41+
42+
def comp_stream(numbins, size, offset):
43+
for i in range(numbins):
44+
ram_b.write(i + offset, 0)
45+
46+
strm.set_constant('numbins', numbins)
47+
strm.set_constant('offset', offset)
48+
strm.set_source('a', ram_a, offset, size)
49+
strm.set_read_modify_write_RAM('ext', ram_b, read_ports=(0,), write_port=1)
50+
strm.run()
51+
strm.join()
52+
53+
def comp_sequential(numbins, size, offset):
54+
for i in range(numbins):
55+
ram_b.write(i + offset, 0)
56+
57+
for i in range(size):
58+
a = ram_a.read(i + offset)
59+
a = 0 if a < 0 else a
60+
a = numbins - 1 if a >= numbins else a
61+
current = ram_b.read(a + offset)
62+
updated = current + 1
63+
ram_b.write(a + offset, updated)
64+
65+
def check(size, offset_stream, offset_seq):
66+
all_ok = True
67+
for i in range(size):
68+
st = ram_b.read(i + offset_stream)
69+
sq = ram_b.read(i + offset_seq)
70+
if vthread.verilog.NotEql(st, sq):
71+
all_ok = False
72+
if all_ok:
73+
print('# verify: PASSED')
74+
else:
75+
print('# verify: FAILED')
76+
77+
def comp(size):
78+
numbins = 8
79+
80+
# stream
81+
offset = 0
82+
myaxi.dma_read(ram_a, offset, 0, size)
83+
comp_stream(numbins, size, offset)
84+
myaxi.dma_write(ram_b, offset, 1024, numbins)
85+
86+
# sequential
87+
offset = size * 4
88+
myaxi.dma_read(ram_a, offset, 0, size * 2)
89+
comp_sequential(numbins, size, offset)
90+
myaxi.dma_write(ram_b, offset, 1024 * 2, numbins)
91+
92+
# verification
93+
check(numbins, 0, offset)
94+
95+
vthread.finish()
96+
97+
th = vthread.Thread(m, 'th_comp', clk, rst, comp)
98+
fsm = th.start(32)
99+
100+
return m
101+
102+
103+
def mkTest(memimg_name=None):
104+
m = Module('test')
105+
106+
# target instance
107+
led = mkLed()
108+
109+
# copy paras and ports
110+
params = m.copy_params(led)
111+
ports = m.copy_sim_ports(led)
112+
113+
clk = ports['CLK']
114+
rst = ports['RST']
115+
116+
memory = axi.AxiMemoryModel(m, 'memory', clk, rst, memimg_name=memimg_name)
117+
memory.connect(ports, 'myaxi')
118+
119+
uut = m.Instance(led, 'uut',
120+
params=m.connect_params(led),
121+
ports=m.connect_ports(led))
122+
123+
# simulation.setup_waveform(m, uut)
124+
simulation.setup_clock(m, clk, hperiod=5)
125+
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
126+
127+
init.add(
128+
Delay(1000000),
129+
Systask('finish'),
130+
)
131+
132+
return m
133+
134+
135+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
136+
137+
if outputfile is None:
138+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
139+
140+
memimg_name = 'memimg_' + outputfile
141+
142+
test = mkTest(memimg_name=memimg_name)
143+
144+
if filename is not None:
145+
test.to_verilog(filename)
146+
147+
sim = simulation.Simulator(test, sim=simtype)
148+
rslt = sim.run(outputfile=outputfile)
149+
lines = rslt.splitlines()
150+
if simtype == 'verilator' and lines[-1].startswith('-'):
151+
rslt = '\n'.join(lines[:-1])
152+
return rslt
153+
154+
155+
if __name__ == '__main__':
156+
rslt = run(filename='tmp.v')
157+
print(rslt)
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_sync
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_sync.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')

0 commit comments

Comments
 (0)