Skip to content

Commit 69b3c98

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

39 files changed

+4257
-177
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_dma_axim2
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_axi_dma_axim2.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: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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.AXIM2(m, 'myaxi', clk, rst, datawidth,
23+
num_cmd_delay=1, num_data_delay=1)
24+
myram = vthread.RAM(m, 'myram', clk, rst, datawidth, addrwidth,
25+
numports=2)
26+
27+
all_ok = m.TmpReg(initval=0)
28+
29+
def blink(size):
30+
all_ok.value = True
31+
32+
for i in range(4):
33+
print('# iter %d start' % i)
34+
# Test for 4KB boundary check
35+
offset = i * 1024 * 16 + (myaxi.boundary_size - 4)
36+
body(size, offset)
37+
print('# iter %d end' % i)
38+
39+
if all_ok:
40+
print('# verify: PASSED')
41+
else:
42+
print('# verify: FAILED')
43+
44+
vthread.finish()
45+
46+
def body(size, offset):
47+
# write
48+
for i in range(size):
49+
wdata = i + 100
50+
myram.write(i, wdata)
51+
52+
laddr = 0
53+
gaddr = offset
54+
myaxi.dma_write(myram, laddr, gaddr, size, port=0)
55+
print('dma_write: [%d] -> [%d]' % (laddr, gaddr))
56+
57+
# write
58+
for i in range(size):
59+
wdata = i + 1000
60+
myram.write(i, wdata)
61+
62+
laddr = 0
63+
gaddr = (size + size) * 4 + offset
64+
myaxi.dma_write(myram, laddr, gaddr, size, port=1)
65+
print('dma_write: [%d] -> [%d]' % (laddr, gaddr))
66+
67+
# read
68+
laddr = 0
69+
gaddr = offset
70+
myaxi.dma_read(myram, laddr, gaddr, size, port=1)
71+
print('dma_read: [%d] <- [%d]' % (laddr, gaddr))
72+
73+
for i in range(size):
74+
rdata = myram.read(i)
75+
if vthread.verilog.NotEql(rdata, i + 100):
76+
print('rdata[%d] = %d' % (i, rdata))
77+
all_ok.value = False
78+
79+
# read
80+
laddr = 0
81+
gaddr = (size + size) * 4 + offset
82+
myaxi.dma_read(myram, laddr, gaddr, size, port=0)
83+
print('dma_read: [%d] <- [%d]' % (laddr, gaddr))
84+
85+
for i in range(size):
86+
rdata = myram.read(i)
87+
if vthread.verilog.NotEql(rdata, i + 1000):
88+
print('rdata[%d] = %d' % (i, rdata))
89+
all_ok.value = False
90+
91+
th = vthread.Thread(m, 'th_blink', clk, rst, blink)
92+
fsm = th.start(16)
93+
94+
return m
95+
96+
97+
def mkTest(memimg_name=None):
98+
m = Module('test')
99+
100+
# target instance
101+
led = mkLed()
102+
103+
# copy paras and ports
104+
params = m.copy_params(led)
105+
ports = m.copy_sim_ports(led)
106+
107+
clk = ports['CLK']
108+
rst = ports['RST']
109+
110+
memory = axi.AxiMemoryModel(m, 'memory', clk, rst, memimg_name=memimg_name)
111+
memory.connect(ports, 'myaxi')
112+
113+
uut = m.Instance(led, 'uut',
114+
params=m.connect_params(led),
115+
ports=m.connect_ports(led))
116+
117+
# simulation.setup_waveform(m, uut)
118+
simulation.setup_clock(m, clk, hperiod=5)
119+
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
120+
121+
init.add(
122+
Delay(1000000),
123+
Systask('finish'),
124+
)
125+
126+
return m
127+
128+
129+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
130+
131+
if outputfile is None:
132+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
133+
134+
memimg_name = 'memimg_' + outputfile
135+
136+
test = mkTest(memimg_name=memimg_name)
137+
138+
if filename is not None:
139+
test.to_verilog(filename)
140+
141+
sim = simulation.Simulator(test, sim=simtype)
142+
rslt = sim.run(outputfile=outputfile)
143+
lines = rslt.splitlines()
144+
if simtype == 'verilator' and lines[-1].startswith('-'):
145+
rslt = '\n'.join(lines[:-1])
146+
return rslt
147+
148+
149+
if __name__ == '__main__':
150+
rslt = run(filename='tmp.v')
151+
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_axi_dma_axim2_narrow
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_axi_dma_axim2_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')

0 commit comments

Comments
 (0)