1

myHDL 1.0devを使ってpySerialでPCとFPGA間のUARTインターフェースを動的に作るためのpythonライブラリを作ろうとしています。

データ型とそのプロパティの名前を取り、RAM ブロックをインスタンス化するだけでなく、PC で読み取り/書き込みコマンドにアクセスできるようにします。ただし、RAM を動的に配線する際に問題が発生しています。

最小限の実例として、これら 2 つのクラスがあります。

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()

これが間違ったベリログです。

`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 のどのバージョンでも変換用にサポートされていないためです。動的配線を正しく実装するにはどうすればよいですか?

4

1 に答える 1

2

それで、これを書いているときに答えを見つけました。知っておくと便利なトリックだと思うので、とにかく質問を投稿することにしました。

@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

そして、これが正しいベリログです。

// 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
于 2016-06-28T18:04:07.113 に答える