Skip to content

Commit 991a114

Browse files
committed
AXI-Stream In and Out are updated for the bug fix of the FIFO interfaces.
1 parent 2b85f96 commit 991a114

File tree

9 files changed

+499
-52
lines changed

9 files changed

+499
-52
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_fifo_narrow
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_fifo_narrow.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: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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(axi_datawidth=32, fifo_datawidth=64):
16+
m = Module('blinkled')
17+
clk = m.Input('CLK')
18+
rst = m.Input('RST')
19+
20+
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, axi_datawidth)
21+
22+
axi_in = vthread.AXIStreamInFifo(m, 'axi_in', clk, rst, axi_datawidth,
23+
with_last=True, noio=True)
24+
maxi_in = vthread.AXIM_for_AXIStreamIn(axi_in, 'maxi_in')
25+
26+
axi_out = vthread.AXIStreamOutFifo(m, 'axi_out', clk, rst, axi_datawidth,
27+
with_last=True, noio=True)
28+
maxi_out = vthread.AXIM_for_AXIStreamOut(axi_out, 'maxi_out')
29+
30+
fifo_addrwidth = 8
31+
32+
fifo_a = vthread.FIFO(m, 'fifo_a', clk, rst, fifo_datawidth, fifo_addrwidth)
33+
fifo_b = vthread.FIFO(m, 'fifo_b', clk, rst, fifo_datawidth, fifo_addrwidth)
34+
35+
# for comp_sequential
36+
ram_a = vthread.RAM(m, 'ram_a', clk, rst, fifo_datawidth, fifo_addrwidth)
37+
ram_b = vthread.RAM(m, 'ram_b', clk, rst, fifo_datawidth, fifo_addrwidth)
38+
39+
strm = vthread.Stream(m, 'mystream', clk, rst)
40+
a = strm.source('a')
41+
b = a * strm.Int(2)
42+
strm.sink(b, 'b')
43+
44+
def comp_stream(size, offset):
45+
strm.set_source_fifo('a', fifo_a, size)
46+
strm.set_sink_fifo('b', fifo_b, size)
47+
strm.run()
48+
# strm.join()
49+
50+
def comp_sequential(size, offset):
51+
for i in range(size):
52+
a = ram_a.read(i + offset)
53+
b = a * 2
54+
ram_b.write(i + offset, b)
55+
56+
def check(size, offset_stream, offset_seq):
57+
all_ok = True
58+
for i in range(size):
59+
st = ram_b.read(i + offset_stream)
60+
sq = ram_b.read(i + offset_seq)
61+
if vthread.verilog.NotEql(st, sq):
62+
all_ok = False
63+
if all_ok:
64+
print('# verify: PASSED')
65+
else:
66+
print('# verify: FAILED')
67+
68+
def comp(size):
69+
# initialization
70+
for i in range(size):
71+
ram_b.write(i, 1024 + i)
72+
73+
myaxi.dma_write(ram_b, 0, 512, size)
74+
75+
# stream
76+
offset = 0
77+
78+
dma_size = size * fifo_datawidth // axi_datawidth
79+
80+
# trial 1
81+
# AXI-stream read -> FIFO -> Stream
82+
# fifo_a
83+
maxi_in.dma_read_async(512, dma_size)
84+
axi_in.write_fifo(fifo_a, size)
85+
86+
comp_stream(size, offset)
87+
88+
# Stream -> FIFO -> AXI-stream write
89+
# fifo_b
90+
maxi_out.dma_write_async(1024, dma_size)
91+
axi_out.read_fifo(fifo_b, size)
92+
93+
strm.join()
94+
95+
# trial 2
96+
# AXI-stream read -> FIFO -> Stream
97+
# fifo_a
98+
maxi_in.dma_read_async(512, dma_size)
99+
axi_in.write_fifo(fifo_a, size)
100+
101+
comp_stream(size, offset)
102+
103+
# Stream -> FIFO -> AXI-stream write
104+
# fifo_b
105+
maxi_out.dma_write_async(1024, dma_size)
106+
axi_out.read_fifo(fifo_b, size)
107+
108+
strm.join()
109+
110+
# sequential
111+
offset = size
112+
myaxi.dma_read(ram_a, offset, 512, size)
113+
comp_sequential(size, offset)
114+
myaxi.dma_write(ram_b, offset, 1024 * 2, size)
115+
116+
# verification
117+
myaxi.dma_read(ram_b, 0, 1024, size)
118+
myaxi.dma_read(ram_b, offset, 1024 * 2, size)
119+
check(size, 0, offset)
120+
121+
vthread.finish()
122+
123+
th = vthread.Thread(m, 'comp', clk, rst, comp)
124+
fsm = th.start(16)
125+
126+
return m
127+
128+
129+
def mkTest(memimg_name=None, axi_datawidth=32, fifo_datawidth=64):
130+
m = Module('test')
131+
132+
# target instance
133+
led = mkLed(axi_datawidth, fifo_datawidth)
134+
135+
# copy paras and ports
136+
params = m.copy_params(led)
137+
ports = m.copy_sim_ports(led)
138+
139+
clk = ports['CLK']
140+
rst = ports['RST']
141+
142+
memory = axi.AxiMultiportMemoryModel(m, 'memory', clk, rst, axi_datawidth, numports=3,
143+
memimg_name=memimg_name)
144+
memory.connect(0, ports, 'myaxi')
145+
memory.connect(1, ports, 'maxi_in')
146+
memory.connect(2, ports, 'maxi_out')
147+
148+
uut = m.Instance(led, 'uut',
149+
params=m.connect_params(led),
150+
ports=m.connect_ports(led))
151+
152+
# simulation.setup_waveform(m, uut)
153+
simulation.setup_clock(m, clk, hperiod=5)
154+
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
155+
156+
init.add(
157+
Delay(1000000),
158+
Systask('finish'),
159+
)
160+
161+
return m
162+
163+
164+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
165+
166+
if outputfile is None:
167+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
168+
169+
memimg_name = 'memimg_' + outputfile
170+
171+
test = mkTest(memimg_name=memimg_name)
172+
173+
if filename is not None:
174+
test.to_verilog(filename)
175+
176+
sim = simulation.Simulator(test, sim=simtype)
177+
rslt = sim.run(outputfile=outputfile)
178+
lines = rslt.splitlines()
179+
if simtype == 'verilator' and lines[-1].startswith('-'):
180+
rslt = '\n'.join(lines[:-1])
181+
return rslt
182+
183+
184+
if __name__ == '__main__':
185+
rslt = run(filename='tmp.v')
186+
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_fifo_wide
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_fifo_wide.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)