首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python myhdl包如何生成verilog初始块

python myhdl包如何生成verilog初始块
EN

Stack Overflow用户
提问于 2017-07-05 17:43:41
回答 1查看 258关注 0票数 1

主要来自myhdl示例的代码:

代码语言:javascript
复制
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程序,如下所示:

代码语言:javascript
复制
module HelloWorld(...)
reg [31:0] counts;
initial begin
    counts = 32'h3
end
always @(...

怎样才能生成initial块呢?

请注意,在google的old.myhdl.org/doku.php/dev:initial_values缓存中,它链接到示例https://bitbucket.org/cfelton/examples/src/tip/ramrom/。所以看起来这个特性应该是被支持的。然而,rom示例生成静态case语句。这不是我要找的。

EN

回答 1

Stack Overflow用户

发布于 2017-07-06 00:23:05

解决这个问题需要三个步骤:

  • 更新到master上的最新myhdl或包含散列87784ad的版本,该版本在问题#105#150下添加了该功能。作为virtualenv的示例,运行一个git克隆,然后运行pip install -e <path-to-myhdl-dir>
  • 将信号更改为列表。
  • 在调用toVerilog之前设置toVerilog.initial_values=True

下面是代码片段。

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44922574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档