Skip to content

Commit 8a33eec

Browse files
committed
AXI-Stream with AXI-Master
1 parent 7436f6d commit 8a33eec

File tree

5 files changed

+1164
-9
lines changed

5 files changed

+1164
-9
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_axi_stream_with_master
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_axi_stream_with_master.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: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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)
25+
ram_c = vthread.RAM(m, 'ram_c', clk, rst, datawidth, addrwidth)
26+
27+
axi_a = vthread.AXIStreamIn(m, 'axi_a', clk, rst, datawidth, with_last=True, noio=True)
28+
axi_b = vthread.AXIStreamIn(m, 'axi_b', clk, rst, datawidth, with_last=True, noio=True)
29+
axi_c = vthread.AXIStreamOut(m, 'axi_c', clk, rst, datawidth, with_last=True, noio=True)
30+
31+
maxi_a = vthread.AXIM_AXIStreamIn(axi_a, 'maxi_a')
32+
maxi_b = vthread.AXIM_AXIStreamIn(axi_b, 'maxi_b')
33+
maxi_c = vthread.AXIM_AXIStreamOut(axi_c, 'maxi_c')
34+
35+
def comp_sequential(size, offset):
36+
sum = 0
37+
for i in range(size):
38+
a = ram_a.read(i + offset)
39+
b = ram_b.read(i + offset)
40+
sum = a + b + 100
41+
ram_c.write(i + offset, sum)
42+
43+
def check(size, offset_stream, offset_seq):
44+
all_ok = True
45+
for i in range(size):
46+
st = ram_c.read(i + offset_stream)
47+
sq = ram_c.read(i + offset_seq)
48+
if vthread.verilog.NotEql(st, sq):
49+
all_ok = False
50+
if all_ok:
51+
print('# verify: PASSED')
52+
else:
53+
print('# verify: FAILED')
54+
55+
def comp(size):
56+
# stream
57+
offset = 0
58+
maxi_a.dma_read_async(0, size) # only 1st transaction is non-blocking
59+
maxi_b.dma_read_async(512, size) # only 1st transaction is non-blocking
60+
maxi_c.dma_write_async(1024, size) # only 1st transaction is non-blocking
61+
62+
for i in range(size):
63+
a, a_last = axi_a.read()
64+
b, b_last = axi_b.read()
65+
c = a + b + 100
66+
c_last = a_last
67+
axi_c.write(c, c_last)
68+
69+
# sequential
70+
offset = size
71+
myaxi.dma_read(ram_a, offset, 0, size)
72+
myaxi.dma_read(ram_b, offset, 512, size)
73+
comp_sequential(size, offset)
74+
myaxi.dma_write(ram_c, offset, 1024 * 2, size)
75+
76+
# verification
77+
myaxi.dma_read(ram_c, 0, 1024, size)
78+
myaxi.dma_read(ram_c, offset, 1024 * 2, size)
79+
check(size, 0, offset)
80+
81+
vthread.finish()
82+
83+
th = vthread.Thread(m, 'th_comp', clk, rst, comp)
84+
fsm = th.start(32)
85+
86+
return m
87+
88+
89+
def mkTest(memimg_name=None):
90+
m = Module('test')
91+
92+
# target instance
93+
led = mkLed()
94+
95+
# copy paras and ports
96+
params = m.copy_params(led)
97+
ports = m.copy_sim_ports(led)
98+
99+
clk = ports['CLK']
100+
rst = ports['RST']
101+
102+
memory = axi.AxiMultiportMemoryModel(m, 'memory', clk, rst, numports=4,
103+
memimg_name=memimg_name)
104+
memory.connect(0, ports, 'myaxi')
105+
memory.connect(1, ports, 'maxi_a')
106+
memory.connect(2, ports, 'maxi_b')
107+
memory.connect(3, ports, 'maxi_c')
108+
109+
uut = m.Instance(led, 'uut',
110+
params=m.connect_params(led),
111+
ports=m.connect_ports(led))
112+
113+
# simulation.setup_waveform(m, uut)
114+
simulation.setup_clock(m, clk, hperiod=5)
115+
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
116+
117+
init.add(
118+
Delay(1000000),
119+
Systask('finish'),
120+
)
121+
122+
return m
123+
124+
125+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
126+
127+
if outputfile is None:
128+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
129+
130+
memimg_name = 'memimg_' + outputfile
131+
132+
test = mkTest(memimg_name=memimg_name)
133+
134+
if filename is not None:
135+
test.to_verilog(filename)
136+
137+
sim = simulation.Simulator(test, sim=simtype)
138+
rslt = sim.run(outputfile=outputfile)
139+
lines = rslt.splitlines()
140+
if simtype == 'verilator' and lines[-1].startswith('-'):
141+
rslt = '\n'.join(lines[:-1])
142+
return rslt
143+
144+
145+
if __name__ == '__main__':
146+
rslt = run(filename='tmp.v')
147+
print(rslt)

0 commit comments

Comments
 (0)