Skip to content

Commit c0d79eb

Browse files
committed
Updated ready signal definition in pipeline lib
1 parent 5f95748 commit c0d79eb

File tree

9 files changed

+2077
-1
lines changed

9 files changed

+2077
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
TARGET=led.py
2+
TEST=test_led.py
3+
ARGS=
4+
5+
PYTHON=python3
6+
#PYTHON=python
7+
#OPT=-m pdb
8+
#OPT=-m cProfile -s time
9+
#OPT=-m cProfile -o profile.rslt
10+
11+
.PHONY: all
12+
all: test
13+
14+
.PHONY: run
15+
run:
16+
$(PYTHON) $(OPT) $(TARGET) $(ARGS)
17+
18+
.PHONY: test
19+
test:
20+
$(PYTHON) -m pytest -vv $(TEST)
21+
22+
.PHONY: check
23+
check:
24+
$(PYTHON) $(OPT) $(TARGET) $(ARGS) > tmp.v
25+
iverilog -tnull -Wall tmp.v
26+
rm -f tmp.v
27+
28+
.PHONY: clean
29+
clean:
30+
rm -rf *.pyc __pycache__ parsetab.py *.out tmp.v uut.vcd
31+
32+
.PHONY: sim
33+
sim:
34+
iverilog -Wall tmp.v
35+
./a.out
36+
37+
.PHONY: view
38+
view:
39+
gtkwave --giga uut.vcd &
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import sys
2+
import os
3+
4+
from veriloggen import *
5+
6+
def mkLed():
7+
m = Module('blinkled')
8+
clk = m.Input('CLK')
9+
rst = m.Input('RST')
10+
11+
x = m.Input('x', 32)
12+
vx = m.Input('vx')
13+
rx = m.Output('rx')
14+
15+
y = m.Input('y', 32)
16+
vy = m.Input('vy')
17+
ry = m.Output('ry')
18+
19+
z = m.Output('z', 32)
20+
vz = m.Output('vz')
21+
rz = m.Input('rz')
22+
23+
pipe = lib.Pipeline(m, 'pipe')
24+
25+
px = pipe.input(x, valid=vx, ready=rx)
26+
py = pipe.input(y, valid=vy, ready=ry)
27+
pz = pipe(px + py)
28+
pz.output(z, valid=vz, ready=rz)
29+
30+
pipe.make_always(clk, rst)
31+
32+
return m
33+
34+
def mkTest(numports=8):
35+
m = Module('test')
36+
37+
# target instance
38+
led = mkLed()
39+
40+
# copy paras and ports
41+
params = m.copy_params(led)
42+
ports = m.copy_sim_ports(led)
43+
44+
clk = ports['CLK']
45+
rst = ports['RST']
46+
47+
x = ports['x']
48+
vx = ports['vx']
49+
rx = ports['rx']
50+
y = ports['y']
51+
vy = ports['vy']
52+
ry = ports['ry']
53+
z = ports['z']
54+
vz = ports['vz']
55+
rz = ports['rz']
56+
57+
uut = m.Instance(led, 'uut',
58+
params=m.connect_params(led),
59+
ports=m.connect_ports(led))
60+
61+
reset_stmt = []
62+
reset_stmt.append( x(0) )
63+
reset_stmt.append( y(0) )
64+
reset_stmt.append( vx(0) )
65+
reset_stmt.append( vy(0) )
66+
reset_stmt.append( rz(0) )
67+
68+
lib.simulation.setup_waveform(m, uut)
69+
lib.simulation.setup_clock(m, clk, hperiod=5)
70+
init = lib.simulation.setup_reset(m, rst, reset_stmt, period=100)
71+
72+
nclk = lib.simulation.next_clock
73+
74+
init.add(
75+
Delay(1000),
76+
nclk(clk),
77+
Delay(10000),
78+
Systask('finish'),
79+
)
80+
81+
m.Initial(
82+
Delay(2000),
83+
nclk(clk),
84+
[( nclk(clk), Delay(3), rz(1),
85+
nclk(clk), nclk(clk),
86+
nclk(clk), Delay(3), rz(0),
87+
nclk(clk), nclk(clk))
88+
for _ in range(20) ],
89+
rz(1),
90+
)
91+
92+
m.Initial(
93+
Delay(1000),
94+
nclk(clk),
95+
vx(1),
96+
[ (While(Not(rx))(nclk(clk)), x(x + 1), nclk(clk)) for _ in range(10) ],
97+
nclk(clk),
98+
vx(0),
99+
)
100+
101+
m.Initial(
102+
Delay(1000),
103+
nclk(clk),
104+
vy(1),
105+
[ (While(Not(ry))(nclk(clk)), y(y + 2), nclk(clk)) for _ in range(10) ],
106+
nclk(clk),
107+
vy(0),
108+
)
109+
110+
return m
111+
112+
if __name__ == '__main__':
113+
test = mkTest()
114+
verilog = test.to_verilog('tmp.v')
115+
print(verilog)

0 commit comments

Comments
 (0)