簡體   English   中英

python myhdl包如何生成verilog初始塊

[英]python myhdl package how to generate verilog initial block

從大部分來自myhdl示例的代碼中:

from myhdl import Signal, intbv, delay, always, now, Simulation, toVerilog

__debug = True

def ClkDriver(clk):
    halfPeriod = delay(10)
    @always(halfPeriod)
    def driveClk():
        clk.next = not clk
    return driveClk

def HelloWorld(clk, outs):

    counts = intbv(3)[32:]

    @always(clk.posedge)
    def sayHello():
        outs.next = not outs
        if counts >= 3 - 1:
            counts.next = 0
        else:
            counts.next = counts + 1
        if __debug__:
            print "%s Hello World! outs %s %s" % (
              now(), str(outs), str(outs.next))

    return sayHello

clk = Signal(bool(0))
outs = Signal(intbv(0)[1:])
clkdriver_inst = ClkDriver(clk)
hello_inst = toVerilog(HelloWorld, clk, outs)
sim = Simulation(clkdriver_inst, hello_inst)
sim.run(150)

我希望它生成一個包含initial塊的verilog程序,例如:

module HelloWorld(...)
reg [31:0] counts;
initial begin
    counts = 32'h3
end
always @(...

如何獲得initial塊?

請注意,在old.myhdl.org/doku.php/dev:initial_values的Google緩存上,它鏈接到示例https://bitbucket.org/cfelton/examples/src/tip/ramrom/ 因此,看起來應該支持該功能。 但是,rom示例會生成靜態case語句。 那不是我要找的東西。

解決此問題的三個步驟:

  • 更新到最新的master或包含哈希值87784ad的版本的87784ad ,該哈希值87784ad在問題#105#150下添加了功能。 作為virtualenv的示例,運行git clone,然后運行pip install -e <path-to-myhdl-dir>
  • 將信號更改為列表。
  • 在調用toVerilog之前將toVerilog.initial_values=True設置toVerilog.initial_values=True

代碼段如下。

def HelloWorld(clk, outs):

    counts = [Signal(intbv(3)[32:])]

    @always(clk.posedge)
    def sayHello():
        outs.next = not outs
        if counts[0] >= 3 - 1:
            counts[0].next = 0
        else:
            counts[0].next = counts[0] + 1
        if __debug__:
            print "%s Hello World! outs %s %s %d" % (
                  now(), str(outs), str(outs.next), counts[0])
    return sayHello

clk = Signal(bool(0))
outs = Signal(intbv(0)[1:])
clkdriver_inst = ClkDriver(clk)
toVerilog.initial_values=True
hello_inst = toVerilog(HelloWorld, clk, outs)
sim = Simulation(clkdriver_inst, hello_inst)
sim.run(150)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM