Skip to content

Commit 3e82821

Browse files
committed
A new example for AXI-stream and thread.Stream
1 parent a2e5956 commit 3e82821

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-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_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: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
import sys
4+
import os
5+
import numpy as np
6+
7+
# the next line can be removed after installation
8+
sys.path.insert(0, os.path.dirname(os.path.dirname(
9+
os.path.dirname(os.path.abspath(__file__)))))
10+
11+
from veriloggen import *
12+
import veriloggen.thread as vthread
13+
import veriloggen.types.axi as axi
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+
24+
maxi = vthread.AXIM(m, 'maxi', clk, rst, datawidth)
25+
saxi = vthread.AXISLiteRegister(m, 'saxi', clk, rst,
26+
datawidth=32, length=8)
27+
28+
axi_in = vthread.AXIStreamInFifo(m, 'axi_in', clk, rst, datawidth,
29+
with_last=True)
30+
axi_out = vthread.AXIStreamOutFifo(m, 'axi_out', clk, rst, datawidth,
31+
with_last=True)
32+
33+
fifo_addrwidth = 8
34+
fifo_a = vthread.FIFO(m, 'fifo_a', clk, rst, datawidth, fifo_addrwidth)
35+
fifo_b = vthread.FIFO(m, 'fifo_b', clk, rst, datawidth, fifo_addrwidth)
36+
fifo_c = vthread.FIFO(m, 'fifo_c', clk, rst, datawidth, fifo_addrwidth)
37+
38+
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth)
39+
40+
strm0 = vthread.Stream(m, 'mystream_reduce', clk, rst)
41+
a = strm0.source('a')
42+
reduce_size = strm0.constant('reduce_size')
43+
v = a * a
44+
sum, sum_valid = strm0.ReduceAddValid(v, reduce_size)
45+
strm0.sink(sum, 'sum', when=sum_valid, when_name='sum_valid')
46+
47+
strm1 = vthread.Stream(m, 'mystream_bias', clk, rst)
48+
x = strm1.source('x')
49+
y = strm1.source('y')
50+
z = x + y
51+
strm1.sink(z, 'z')
52+
53+
def comp():
54+
55+
while True:
56+
saxi.wait_flag(0, value=1, resetvalue=0)
57+
58+
saxi.write(1, 1) # set busy
59+
60+
read_size = saxi.read(2)
61+
write_size = saxi.read(3)
62+
reduce_size = saxi.read(4)
63+
offset = saxi.read(5)
64+
65+
if read_size <= 0:
66+
read_size = 1
67+
if write_size <= 0:
68+
write_size = 1
69+
if reduce_size <= 0:
70+
reduce_size = 1
71+
72+
maxi.dma_read(ram_b, offset, 0, write_size)
73+
74+
axi_in.write_fifo(fifo_a, read_size)
75+
axi_out.read_fifo(fifo_c, write_size)
76+
77+
strm0.set_source_fifo('a', fifo_a, read_size)
78+
strm0.set_constant('reduce_size', reduce_size)
79+
strm0.set_sink_fifo('sum', fifo_b, write_size)
80+
81+
strm1.set_source_fifo('x', fifo_b, write_size)
82+
strm1.set_source('y', ram_b, 0, write_size)
83+
strm1.set_sink_fifo('z', fifo_c, write_size)
84+
85+
strm0.run()
86+
strm1.run()
87+
88+
strm0.join()
89+
strm1.join()
90+
91+
saxi.write(1, 0) # unset busy
92+
93+
th = vthread.Thread(m, 'th_comp', clk, rst, comp)
94+
fsm = th.start()
95+
96+
return m
97+
98+
99+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
100+
101+
test = mkLed()
102+
103+
if filename is not None:
104+
test.to_verilog(filename)
105+
106+
return '# verify: PASSED'
107+
108+
109+
if __name__ == '__main__':
110+
rslt = run(filename='tmp.v')
111+
print(rslt)

0 commit comments

Comments
 (0)