|
| 1 | +import sys |
| 2 | +import os |
| 3 | + |
| 4 | +# the next line can be removed after installation |
| 5 | +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) |
| 6 | + |
| 7 | +from veriloggen import * |
| 8 | + |
| 9 | +def mkLed(): |
| 10 | + m = Module('blinkled') |
| 11 | + interval = m.Parameter('INTERVAL', 16) |
| 12 | + clk = m.Input('CLK') |
| 13 | + rst = m.Input('RST') |
| 14 | + led = m.OutputReg('LED', 8, initval=0) |
| 15 | + count = m.Reg('count', 32, initval=0) |
| 16 | + |
| 17 | + seq = lib.Seq(m, 'seq', clk, rst) |
| 18 | + seq.add( Systask('display', 'LED:%d count:%d', led, count) ) |
| 19 | + seq.add( count(count + 1), cond=count<interval-1 ) |
| 20 | + seq.add( count(0), cond=count==interval-1 ) |
| 21 | + seq.add( led(led + 1), cond=count==interval-1 ) |
| 22 | + |
| 23 | + seq.make_always() |
| 24 | + |
| 25 | + return m |
| 26 | + |
| 27 | +def mkTest(): |
| 28 | + m = Module('test') |
| 29 | + |
| 30 | + # target instance |
| 31 | + led = mkLed() |
| 32 | + |
| 33 | + # copy paras and ports |
| 34 | + params = m.copy_params(led) |
| 35 | + ports = m.copy_sim_ports(led) |
| 36 | + |
| 37 | + clk = ports['CLK'] |
| 38 | + rst = ports['RST'] |
| 39 | + |
| 40 | + uut = m.Instance(led, 'uut', |
| 41 | + params=m.connect_params(led), |
| 42 | + ports=m.connect_ports(led)) |
| 43 | + |
| 44 | + #lib.simulation.setup_waveform(m, uut) |
| 45 | + lib.simulation.setup_clock(m, clk, hperiod=5) |
| 46 | + init = lib.simulation.setup_reset(m, rst, m.make_reset(), period=100) |
| 47 | + |
| 48 | + init.add( |
| 49 | + Delay(1000), |
| 50 | + Systask('finish'), |
| 51 | + ) |
| 52 | + |
| 53 | + return m |
| 54 | + |
| 55 | +if __name__ == '__main__': |
| 56 | + test = mkTest() |
| 57 | + verilog = test.to_verilog() |
| 58 | + print(verilog) |
0 commit comments