Skip to content

Commit 7e6fe4c

Browse files
committed
active low
1 parent ead49b7 commit 7e6fe4c

File tree

3 files changed

+267
-0
lines changed

3 files changed

+267
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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
30+
rm -rf *_v1_0
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_ipxact_axi_active_low_reset
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_ipxact_axi_active_low_reset.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: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
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+
import veriloggen.types.ipxact as ipxact
15+
16+
17+
def mkLed():
18+
m = Module('blinkled')
19+
clk = m.Input('CLK')
20+
21+
# active low
22+
rst_x = m.Input('RST_X')
23+
24+
# active low -> active high
25+
rst = m.Wire('RST')
26+
rst.assign(Not(rst_x))
27+
28+
datawidth = 32
29+
addrwidth = 10
30+
id_width = 0
31+
user_width = 0
32+
33+
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth,
34+
id_width=id_width, user_width=user_width)
35+
myram = vthread.RAM(m, 'myram', clk, rst, datawidth, addrwidth)
36+
37+
saxi = vthread.AXISLiteRegister(m, 'saxi', clk, rst, datawidth)
38+
39+
all_ok = m.TmpReg(initval=0)
40+
41+
def blink(size):
42+
# wait start
43+
saxi.wait_flag(0, value=1, resetvalue=0)
44+
# reset done
45+
saxi.write(1, 0)
46+
47+
all_ok.value = True
48+
49+
for i in range(4):
50+
print('# iter %d start' % i)
51+
# Test for 4KB boundary check
52+
offset = i * 1024 * 16 + (myaxi.boundary_size - 4)
53+
body(size, offset)
54+
print('# iter %d end' % i)
55+
56+
if all_ok:
57+
print('# verify (local): PASSED')
58+
else:
59+
print('# verify (local): FAILED')
60+
61+
# result
62+
saxi.write(2, all_ok)
63+
64+
# done
65+
saxi.write_flag(1, 1, resetvalue=0)
66+
67+
def body(size, offset):
68+
# write
69+
for i in range(size):
70+
wdata = i + 100
71+
myram.write(i, wdata)
72+
73+
laddr = 0
74+
gaddr = offset
75+
myaxi.dma_write(myram, laddr, gaddr, size)
76+
print('dma_write: [%d] -> [%d]' % (laddr, gaddr))
77+
78+
# write
79+
for i in range(size):
80+
wdata = i + 1000
81+
myram.write(i, wdata)
82+
83+
laddr = 0
84+
gaddr = (size + size) * 4 + offset
85+
myaxi.dma_write(myram, laddr, gaddr, size)
86+
print('dma_write: [%d] -> [%d]' % (laddr, gaddr))
87+
88+
# read
89+
laddr = 0
90+
gaddr = offset
91+
myaxi.dma_read(myram, laddr, gaddr, size)
92+
print('dma_read: [%d] <- [%d]' % (laddr, gaddr))
93+
94+
for i in range(size):
95+
rdata = myram.read(i)
96+
if vthread.verilog.NotEql(rdata, i + 100):
97+
print('rdata[%d] = %d' % (i, rdata))
98+
all_ok.value = False
99+
100+
# read
101+
laddr = 0
102+
gaddr = (size + size) * 4 + offset
103+
myaxi.dma_read(myram, laddr, gaddr, size)
104+
print('dma_read: [%d] <- [%d]' % (laddr, gaddr))
105+
106+
for i in range(size):
107+
rdata = myram.read(i)
108+
if vthread.verilog.NotEql(rdata, i + 1000):
109+
print('rdata[%d] = %d' % (i, rdata))
110+
all_ok.value = False
111+
112+
th = vthread.Thread(m, 'th_blink', clk, rst, blink)
113+
fsm = th.start(16)
114+
115+
return m
116+
117+
118+
def mkTest(memimg_name=None):
119+
m = Module('test')
120+
121+
# target instance
122+
led = mkLed()
123+
124+
# copy paras and ports
125+
params = m.copy_params(led)
126+
ports = m.copy_sim_ports(led)
127+
128+
clk = ports['CLK']
129+
130+
# active low
131+
rst_x = ports['RST_X']
132+
133+
# active low -> active high
134+
rst = m.Wire('RST')
135+
rst.assign(Not(rst_x))
136+
137+
memory = axi.AxiMemoryModel(m, 'memory', clk, rst, memimg_name=memimg_name)
138+
memory.connect(ports, 'myaxi')
139+
140+
# AXI-Slave controller
141+
_saxi = vthread.AXIMLite(m, '_saxi', clk, rst, noio=True)
142+
_saxi.connect(ports, 'saxi')
143+
144+
def ctrl():
145+
for i in range(100):
146+
pass
147+
148+
awaddr = 0
149+
_saxi.write(awaddr, 1)
150+
151+
araddr = 4
152+
v = _saxi.read(araddr)
153+
while v == 0:
154+
v = _saxi.read(araddr)
155+
156+
araddr = 8
157+
v = _saxi.read(araddr)
158+
if v:
159+
print('# verify: PASSED')
160+
else:
161+
print('# verify: FAILED')
162+
163+
th = vthread.Thread(m, 'th_ctrl', clk, rst, ctrl)
164+
fsm = th.start()
165+
166+
uut = m.Instance(led, 'uut',
167+
params=m.connect_params(led),
168+
ports=m.connect_ports(led))
169+
170+
#simulation.setup_waveform(m, uut)
171+
simulation.setup_clock(m, clk, hperiod=5)
172+
init = simulation.setup_reset(m, rst_x, m.make_reset(), period=100, polarity='low')
173+
174+
init.add(
175+
Delay(1000000),
176+
Systask('finish'),
177+
)
178+
179+
return m
180+
181+
182+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
183+
184+
if outputfile is None:
185+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
186+
187+
memimg_name = 'memimg_' + outputfile
188+
189+
if outputfile is None:
190+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
191+
192+
memimg_name = 'memimg_' + outputfile
193+
194+
if outputfile is None:
195+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
196+
197+
memimg_name = 'memimg_' + outputfile
198+
199+
test = mkTest(memimg_name=memimg_name)
200+
201+
if filename is not None:
202+
test.to_verilog(filename)
203+
204+
sim = simulation.Simulator(test, sim=simtype)
205+
rslt = sim.run(outputfile=outputfile)
206+
lines = rslt.splitlines()
207+
if simtype == 'verilator' and lines[-1].startswith('-'):
208+
rslt = '\n'.join(lines[:-1])
209+
return rslt
210+
211+
212+
if __name__ == '__main__':
213+
rslt = run(filename='tmp.v')
214+
print(rslt)
215+
216+
m = mkLed()
217+
ipxact.to_ipxact(m,
218+
clk_ports=[('CLK', ('RST_X',))],
219+
rst_ports=[('RST_X', 'ACTIVE_LOW')])

0 commit comments

Comments
 (0)