【问题标题】:Dynamic Instantiation: How to dynamically wire interfaces in myHDL动态实例化:如何在 myHDL 中动态连接接口
【发布时间】:2016-06-28 17:58:15
【问题描述】:

我正在尝试使用 myHDL 1.0dev

使用 pySerial 创建一个 python 库,用于在 PC 和 FPGA 之间动态创建 UART 接口

它获取数据类型及其属性的名称,并实例化一个 RAM 块,并允许访问 PC 上的读/写命令。但是,我在动态连接 RAM 时遇到了问题。

对于一个最小的工作示例,我有这两个类。

class RamBus(object):
    def __init__(self):
        self.clk     = Signal(bool(0))

class UartBus(object):
    def __init__(self):
        self.interfaces = dict()
    def add(self, name, bus):
        self.interfaces[name] = bus
        setattr(self,name,bus)

UartBus 用于容纳许多 RamBus。现在我将尝试将它们与arbiter 块动态连接。

@block
def arbiter(clk,uartbus):
    modules = []
    for key in uartbus.interfaces:
        print key

        @block
        def electrician(rambus=uartbus.interfaces[key]):
            @always_comb
            def wiring():
                rambus.clk.next = clk
            return wiring
        f = electrician
        modules.append(electrician())
    return modules

如果我用这段代码转换它,我得到一个不正确的转换

uartbus = UartBus()

uartbus.add('power',RamBus())
uartbus.add('freq',RamBus())

#attempt conversion
clk = Signal(bool(0))
arbiter(clk,uartbus).convert()

这是不正确的verilog。

`timescale 1ns/10ps

module arbiter (
    clk
);


input clk;

wire electrician_0_rambus_clk;
wire electrician_0_rambus_clk;

assign electrician_0_rambus_clk = clk;
assign electrician_0_rambus_clk = clk;

endmodule

而且两条线的名称相同!在 @always_comb 中使用字典不起作用,因为到目前为止,任何版本的 myHDL 都不支持字典进行转换。如何正确实现动态布线?

【问题讨论】:

    标签: python fpga myhdl


    【解决方案1】:

    所以我在写这篇文章的时候找到了答案,因为我认为知道这是一个有用的技巧,所以我还是决定发布这个问题。

    @block
    def arbiter(clk,uartbus):
        modules = []
        for key in uartbus.interfaces:
    
            #note that there is no @block here!
            def electrician(rambus=uartbus.interfaces[key]):
                @always_comb
                def wiring():
                    rambus.clk.next = clk
                return wiring
    
            #here we can redefine the name that electrician 
            #has so that myHDL converts it with that name.
            electrician.func_name = key
            #then we apply the block decorator
            electrician = block(electrician)
    
            modules.append(electrician())
            print key
    
        return modules
    

    这是正确的verilog。

    // File: arbiter.v
    // Generated by MyHDL 1.0dev
    // Date: Tue Jun 28 14:03:01 2016
    
    `timescale 1ns/10ps
    
    module arbiter (
        clk
    );
    
    
    input clk;
    
    wire freq_0_rambus_clk;
    wire power_0_rambus_clk;
    
    assign freq_0_rambus_clk = clk;
    assign power_0_rambus_clk = clk;
    
    endmodule
    

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 2017-08-22
      • 2022-01-16
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多