Skip to content

Commit f7ca646

Browse files
committed
First example "hello_led.py is updated."
1 parent acfb4bb commit f7ca646

File tree

4 files changed

+285
-39
lines changed

4 files changed

+285
-39
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ clean:
44
make clean -C ./utils
55
make clean -C ./examples
66
make clean -C ./tests
7-
rm -rf *.pyc __pycache__ *.out uut.vcd veriloggen.egg-info build dist
7+
rm -rf *.pyc __pycache__ *.out uut.vcd tmp.v veriloggen.egg-info build dist
88

99
.PHONY: release
1010
release:

README.md

Lines changed: 120 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ Install on your platform. For exmple, on Ubuntu:
4343

4444
- Jinja2: 2.8 or later
4545

46-
Install on your python environment by using pip.
46+
Install on your python environment by using pip:
4747

4848
pip install jinja2
4949

50-
- Pyverilog: 1.0.1 or later
50+
- Pyverilog: 1.0.2 or later
5151

52-
Install from pip:
52+
Install from pip (or download from GitHub):
5353

5454
pip install pyverilog
5555

@@ -59,22 +59,22 @@ Options
5959
- pytest: 2.8.2 or later
6060
- pytest-pythonpath: 0.7 or later
6161

62-
These softwares are required for running the tests in tests and examples.
62+
These softwares are required for running the tests in tests and examples:
6363

6464
pip install pytest pytest-pythonpath
6565

6666
- Graphviz: 2.38.0 or later
6767
- Pygraphviz: 1.3.1 or later
6868

69-
These softwares are required for graph visualization by lib.dataflow.
69+
These softwares are required for graph visualization by lib.dataflow:
7070

7171
sudo apt-get install graphviz
7272
pip install pygraphviz
7373

7474
Install
7575
--------------------
7676

77-
Install Veriloggen.
77+
Install Veriloggen:
7878

7979
python setup.py install
8080

@@ -101,6 +101,8 @@ Let's begin veriloggen by an example. Create a example Python script in Python a
101101
Open 'hello_led.py' in the root directory.
102102

103103
```python
104+
from __future__ import absolute_import
105+
from __future__ import print_function
104106
import sys
105107
import os
106108
from veriloggen import *
@@ -133,44 +135,137 @@ def mkLed():
133135
)
134136
))
135137

138+
m.Always(Posedge(clk))(
139+
If(rst)(
140+
).Else(
141+
Systask('display', "LED:%d count:%d", led, count)
142+
))
143+
136144
return m
137145

138-
if __name__ == '__main__':
146+
def mkTest():
147+
m = Module('test')
148+
149+
# target instance
139150
led = mkLed()
140-
# led.to_verilog(filename='tmp.v')
141-
verilog = led.to_verilog()
151+
152+
# copy paras and ports
153+
params = m.copy_params(led)
154+
ports = m.copy_sim_ports(led)
155+
156+
clk = ports['CLK']
157+
rst = ports['RST']
158+
159+
uut = m.Instance(led, 'uut',
160+
params=m.connect_params(led),
161+
ports=m.connect_ports(led))
162+
163+
lib.simulation.setup_waveform(m, uut, m.get_vars())
164+
lib.simulation.setup_clock(m, clk, hperiod=5)
165+
init = lib.simulation.setup_reset(m, rst, m.make_reset(), period=100)
166+
167+
init.add(
168+
Delay(1000 * 100),
169+
Systask('finish'),
170+
)
171+
172+
return m
173+
174+
if __name__ == '__main__':
175+
test = mkTest()
176+
verilog = test.to_verilog(filename='tmp.v')
177+
#verilog = test.to_verilog()
142178
print(verilog)
179+
180+
sim = lib.simulation.Simulator(test)
181+
rslt = sim.run()
182+
print(rslt)
183+
184+
#sim.view_waveform()
143185
```
144186

145187
Run the script.
146188

147189
```
148-
python led.py
190+
python hello_led.py
149191
```
150192

151-
You will have a complete Verilog HDL source code that is generated by the source code generator.
193+
You will have a complete Verilog HDL source code named 'tmp.v' in the root directory, which is generated by the source code generator.
152194

153195
```verilog
196+
module test #
197+
(
198+
parameter WIDTH = 8
199+
)
200+
(
201+
202+
);
203+
204+
reg CLK;
205+
reg RST;
206+
wire [WIDTH - 1:0] LED;
207+
208+
blinkled
209+
#(
210+
.WIDTH(WIDTH)
211+
)
212+
uut
213+
(
214+
.CLK(CLK),
215+
.RST(RST),
216+
.LED(LED)
217+
);
218+
219+
220+
initial begin
221+
$dumpfile("uut.vcd");
222+
$dumpvars(0, uut, CLK, RST, LED);
223+
end
224+
225+
226+
initial begin
227+
CLK = 0;
228+
forever begin
229+
#5 CLK = !CLK;
230+
end
231+
end
232+
233+
234+
initial begin
235+
RST = 0;
236+
#100;
237+
RST = 1;
238+
#100;
239+
RST = 0;
240+
#100000;
241+
$finish;
242+
end
243+
244+
245+
endmodule
246+
247+
248+
154249
module blinkled #
155250
(
156251
parameter WIDTH = 8
157252
)
158253
(
159254
input CLK,
160255
input RST,
161-
output reg [(WIDTH - 1):0] LED
256+
output reg [WIDTH - 1:0] LED
162257
);
163258
164-
reg [(32 - 1):0] count;
259+
reg [32 - 1:0] count;
165260
166261
always @(posedge CLK) begin
167262
if(RST) begin
168263
count <= 0;
169264
end else begin
170-
if((count == 1023)) begin
265+
if(count == 1023) begin
171266
count <= 0;
172267
end else begin
173-
count <= (count + 1);
268+
count <= count + 1;
174269
end
175270
end
176271
end
@@ -180,13 +275,21 @@ module blinkled #
180275
if(RST) begin
181276
LED <= 0;
182277
end else begin
183-
if((count == 1023)) begin
184-
LED <= (LED + 1);
278+
if(count == 1023) begin
279+
LED <= LED + 1;
185280
end
186281
end
187282
end
188283
189284
285+
always @(posedge CLK) begin
286+
if(RST) begin
287+
end else begin
288+
$display("LED:%d count:%d", LED, count);
289+
end
290+
end
291+
292+
190293
endmodule
191294
```
192295

0 commit comments

Comments
 (0)