88
99from veriloggen import *
1010
11+
1112def mkChatterClear (length = 1024 ):
1213 m = Module ("chatter_clear" )
1314
1415 length = m .Parameter ('length' , length )
15-
16+
1617 clk = m .Input ('CLK' )
1718 rst = m .Input ('RST' )
1819
@@ -22,28 +23,29 @@ def mkChatterClear(length=1024):
2223 seq = Seq (m , 'seq' , clk , rst )
2324
2425 count = m .TmpReg (32 )
25-
26- seq .If (din == dout )(
26+
27+ seq .If (din == dout )(
2728 count (0 )
2829 )
29- seq .If (din != dout )(
30+ seq .If (din != dout )(
3031 count .inc ()
3132 )
32-
33- seq .If (count == length )(
33+
34+ seq .If (count == length )(
3435 count (0 )
3536 )
36- seq .If (count == length )(
37+ seq .If (count == length )(
3738 dout (din )
3839 )
3940
4041 seq .make_always ()
4142
4243 return m
4344
45+
4446def mkTest (length = 1024 ):
4547 m = Module ('test' )
46-
48+
4749 main = mkChatterClear (length )
4850 params = m .copy_params (main )
4951 ports = m .copy_sim_ports (main )
@@ -56,76 +58,78 @@ def mkTest(length=1024):
5658 fsm = FSM (m , 'fsm' , clk , rst )
5759 count = m .TmpReg (32 , initval = 0 )
5860
59- fsm ( din (0 ) )
60- fsm ( count .inc () )
61- fsm .If (count == 2000 )( count (0 ) )
62- fsm .goto_next (count == 2000 )
63-
64- fsm ( din (1 ) )
65- fsm ( count .inc () )
66- fsm .If (count == 10 )( count (0 ) )
67- fsm .goto_next (count == 10 )
68-
69- fsm ( din (0 ) )
70- fsm ( count .inc () )
71- fsm .If (count == 10 )( count (0 ) )
72- fsm .goto_next (count == 10 )
73-
74- fsm ( din (1 ) )
75- fsm ( count .inc () )
76- fsm .If (count == 2000 )( count (0 ) )
77- fsm .goto_next (count == 2000 )
78-
79- fsm ( din (0 ) )
80- fsm ( count .inc () )
81- fsm .If (count == 10 )( count (0 ) )
82- fsm .goto_next (count == 10 )
83-
84- fsm ( din (1 ) )
85- fsm ( count .inc () )
86- fsm .If (count == 10 )( count (0 ) )
87- fsm .goto_next (count == 10 )
88-
89- fsm ( din (0 ) )
90- fsm ( count .inc () )
91- fsm .If (count == 2000 )( count (0 ) )
92- fsm .goto_next (count == 2000 )
61+ fsm (din (0 ))
62+ fsm (count .inc ())
63+ fsm .If (count == 2000 )(count (0 ))
64+ fsm .goto_next (count == 2000 )
65+
66+ fsm (din (1 ))
67+ fsm (count .inc ())
68+ fsm .If (count == 10 )(count (0 ))
69+ fsm .goto_next (count == 10 )
70+
71+ fsm (din (0 ))
72+ fsm (count .inc ())
73+ fsm .If (count == 10 )(count (0 ))
74+ fsm .goto_next (count == 10 )
75+
76+ fsm (din (1 ))
77+ fsm (count .inc ())
78+ fsm .If (count == 2000 )(count (0 ))
79+ fsm .goto_next (count == 2000 )
80+
81+ fsm (din (0 ))
82+ fsm (count .inc ())
83+ fsm .If (count == 10 )(count (0 ))
84+ fsm .goto_next (count == 10 )
85+
86+ fsm (din (1 ))
87+ fsm (count .inc ())
88+ fsm .If (count == 10 )(count (0 ))
89+ fsm .goto_next (count == 10 )
90+
91+ fsm (din (0 ))
92+ fsm (count .inc ())
93+ fsm .If (count == 2000 )(count (0 ))
94+ fsm .goto_next (count == 2000 )
9395
9496 fsm .make_always ()
95-
97+
9698 uut = m .Instance (main , 'uut' ,
9799 params = m .connect_params (main ),
98100 ports = m .connect_ports (main ))
99101
100- simulation .setup_waveform (m , uut , m .get_vars ())
102+ vcd_name = os .path .splitext (os .path .basename (__file__ ))[0 ] + '.vcd'
103+ simulation .setup_waveform (m , uut , m .get_vars (), dumpfile = vcd_name )
101104 simulation .setup_clock (m , clk , hperiod = 5 )
102105 init = simulation .setup_reset (m , rst , m .make_reset (), period = 100 )
103106
104107 nclk = simulation .next_clock
105-
108+
106109 init .add (
107110 Delay (1000 * 100 ),
108111 Systask ('finish' ),
109112 )
110113
111114 return m
112115
116+
113117if __name__ == '__main__' :
114118 #main = mkChatterClear()
115119 #verilog = main.to_verilog('tmp.v')
116- #print(verilog)
117- #exit()
118-
120+ # print(verilog)
121+ # exit()
122+
119123 test = mkTest ()
120124 verilog = test .to_verilog ('tmp.v' )
121125 print (verilog )
122126
123127 # run simulator (Icarus Verilog)
124128 sim = simulation .Simulator (test )
125- rslt = sim .run () # display=False
129+ rslt = sim .run () # display=False
126130 #rslt = sim.run(display=True)
127131 print (rslt )
128132
129133 # launch waveform viewer (GTKwave)
130- #sim.view_waveform() # background=False
131- #sim.view_waveform(background=True)
134+ # sim.view_waveform() # background=False
135+ # sim.view_waveform(background=True)
0 commit comments