Skip to content

Commit e157343

Browse files
committed
Thread.Stream with AXI-Stream
1 parent b3ab365 commit e157343

File tree

5 files changed

+1457
-25
lines changed

5 files changed

+1457
-25
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_axi_stream
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_axi_stream.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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
23+
axi_a = vthread.AXIStreamIn(m, 'axi_a', clk, rst, datawidth, with_last=True)
24+
axi_b = vthread.AXIStreamIn(m, 'axi_b', clk, rst, datawidth, with_last=True)
25+
axi_c = vthread.AXIStreamOut(m, 'axi_c', clk, rst, datawidth, with_last=True)
26+
27+
saxi = vthread.AXISLiteRegister(m, 'saxi', clk, rst, datawidth)
28+
29+
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth, numports=2)
30+
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth, numports=2)
31+
ram_c = vthread.RAM(m, 'ram_c', clk, rst, datawidth, addrwidth, numports=2)
32+
33+
strm = vthread.Stream(m, 'mystream', clk, rst)
34+
a = strm.source('a')
35+
b = strm.source('b')
36+
c = a + b
37+
strm.sink(c, 'c')
38+
39+
def comp_stream(size, offset):
40+
strm.set_source('a', ram_a, offset, size)
41+
strm.set_source('b', ram_b, offset, size)
42+
strm.set_sink('c', ram_c, offset, size)
43+
strm.run()
44+
strm.join()
45+
46+
def comp():
47+
while True:
48+
saxi.wait_flag(0, value=1, resetvalue=0)
49+
saxi.write(1, 1) # set busy
50+
size = saxi.read(2)
51+
offset = 0
52+
53+
axi_a.read_stream(ram_a, offset, size, port=1) # blocking read
54+
axi_b.read_stream(ram_b, offset, size, port=1) # blocking read
55+
comp_stream(size, offset)
56+
axi_c.write_stream(ram_c, offset, size, port=1) # blocking write
57+
58+
saxi.write(1, 0) # unset busy
59+
60+
vthread.finish()
61+
62+
th = vthread.Thread(m, 'th_comp', clk, rst, comp)
63+
fsm = th.start()
64+
65+
return m
66+
67+
68+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
69+
70+
test = mkLed()
71+
72+
if filename is not None:
73+
test.to_verilog(filename)
74+
75+
return '# verify: PASSED'
76+
77+
78+
if __name__ == '__main__':
79+
rslt = run(filename='tmp.v')
80+
print(rslt)

0 commit comments

Comments
 (0)