Skip to content

Commit 8634475

Browse files
committed
The number of skid buffer stages can be modified.
1 parent fed9b07 commit 8634475

File tree

5 files changed

+374
-111
lines changed

5 files changed

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

veriloggen/thread/axim.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ def __init__(self, m, name, clk, rst, datawidth=32, addrwidth=32,
4343
waddr_prot_mode=axi.AxPROT_NONCOHERENT, raddr_prot_mode=axi.AxPROT_NONCOHERENT,
4444
waddr_user_mode=axi.AxUSER_NONCOHERENT, wdata_user_mode=axi.xUSER_DEFAULT,
4545
raddr_user_mode=axi.AxUSER_NONCOHERENT,
46-
noio=False,
46+
noio=False, sb_depth=1,
4747
use_global_base_addr=False,
48-
op_sel_width=8, req_fifo_addrwidth=3, fsm_as_module=False):
48+
op_sel_width=8, req_fifo_addrwidth=3,
49+
fsm_as_module=False):
4950

51+
outstanding_wcount_width = req_fifo_addrwidth
5052
axi.AxiMaster.__init__(self, m, name, clk, rst, datawidth, addrwidth,
5153
waddr_id_width, wdata_id_width, wresp_id_width,
5254
raddr_id_width, rdata_id_width,
@@ -57,7 +59,7 @@ def __init__(self, m, name, clk, rst, datawidth=32, addrwidth=32,
5759
waddr_prot_mode, raddr_prot_mode,
5860
waddr_user_mode, wdata_user_mode,
5961
raddr_user_mode,
60-
noio, req_fifo_addrwidth)
62+
noio, outstanding_wcount_width, sb_depth)
6163

6264
self.use_global_base_addr = use_global_base_addr
6365
self.op_sel_width = op_sel_width
@@ -1807,14 +1809,15 @@ class AXIMLite(axi.AxiLiteMaster, _MutexFunction):
18071809
def __init__(self, m, name, clk, rst, datawidth=32, addrwidth=32,
18081810
waddr_cache_mode=axi.AxCACHE_NONCOHERENT, raddr_cache_mode=axi.AxCACHE_NONCOHERENT,
18091811
waddr_prot_mode=axi.AxPROT_NONCOHERENT, raddr_prot_mode=axi.AxPROT_NONCOHERENT,
1810-
noio=False,
1812+
noio=False, sb_depth=1,
18111813
use_global_base_addr=False,
18121814
fsm_as_module=False):
18131815

1816+
outstanding_wcount_width = 3
18141817
axi.AxiLiteMaster.__init__(self, m, name, clk, rst, datawidth, addrwidth,
18151818
waddr_cache_mode, raddr_cache_mode,
18161819
waddr_prot_mode, raddr_prot_mode,
1817-
noio)
1820+
noio, outstanding_wcount_width, sb_depth)
18181821

18191822
self.use_global_base_addr = use_global_base_addr
18201823
self.fsm_as_module = fsm_as_module

0 commit comments

Comments
 (0)