-
Notifications
You must be signed in to change notification settings - Fork 58
/
hello_led.py
68 lines (50 loc) · 1.34 KB
/
hello_led.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from __future__ import absolute_import
from __future__ import print_function
import sys
import os
from veriloggen import *
def mkLed():
m = Module('blinkled')
width = m.Parameter('WIDTH', 8)
clk = m.Input('CLK')
rst = m.Input('RST')
led = m.OutputReg('LED', width, initval=0)
count = m.Reg('count', 32, initval=0)
seq = Seq(m, 'seq', clk, rst)
seq.If(count == 1024 - 1)(
count(0)
).Else(
count.inc()
)
seq.If(count == 1024 - 1)(
led.inc()
)
seq(
Systask('display', "LED:%d count:%d", led, count)
)
return m
def mkTest():
m = Module('test')
# target instance
led = mkLed()
uut = Submodule(m, led, name='uut')
clk = uut['CLK']
rst = uut['RST']
vcd_name = os.path.splitext(os.path.basename(__file__))[0] + '.vcd'
simulation.setup_waveform(m, uut, m.get_vars(), dumpfile=vcd_name)
simulation.setup_clock(m, clk, hperiod=5)
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
init.add(
Delay(1000 * 100),
Systask('finish'),
)
return m
if __name__ == '__main__':
test = mkTest()
verilog = test.to_verilog(filename='tmp.v')
#verilog = test.to_verilog()
print(verilog)
sim = simulation.Simulator(test)
rslt = sim.run()
print(rslt)
# sim.view_waveform()