【问题标题】:SystemVerilog: virtual modules verse virtual interfacesSystemVerilog:虚拟模块与虚拟接口
【发布时间】:2020-02-29 14:33:40
【问题描述】:

我知道 SystemVerilog 允许您通过将 SystemVerilog 类中的接口声明为“虚拟”来保存对接口的引用。总线,是否也可以将模块声明为“虚拟”以保存对 SystemVerilog 类中模块的引用?示例:

    `timescale 1 ns / 10 ps

    // Verilog-95 style BFM (with verilog 2001 style ports)
    module BFM1(
        input  wire        clk,
        output reg [15:0]  data
    );

        task write(input [15:0] data1);
            data = data1;
            @(posedge clk); 
            #1;
        endtask;

    endmodule
    class MyClass

        //"Virtual module" (instead of a "virtual interface")
        virtual BFM1 vBFM1;

        function new(virtual BFM1 vvBFM1);
            // save virtual module reference
            vBFM1 = vvBFM1;
        endfunction

        function write(input [15:0] data);
            vBFM.write(data);
        endfunction
    endclass
    // Testbench top-level
    module top;
        reg        clk;
        reg [15:0] data;

        initial begin
            clk = 0;
            forever #5 !clk = clk; 
        end

        BFM1 BFM1(
            .clk  (clk),
            .data (data)
        );

        DUT DUT(
            .clk  (clk), 
            .data (data)
        );

        initial begin

            //Verilog-95 Style BFM call
            BFM1.write(16'h12340);

            // SystemVerilog Class style
            MyClass MyClass1 = new(BFM1);

            MyClass.write(16'hDEAD);
            MyClass.write(16'hBEEF);

            $finish;
        end
    endmodule
    // Design under Test
    module DUT(
        input wire        clk,
        input wire [15:0] data
    );
        //insert design under test logic
    endmodule

我只是好奇,我是否可以省去使用 SystemVerilog 接口的形式,而只使用 SystemVerilog 类中的旧 verilog-95 样式 BFM?

我只是认为,如果您的 DUT 使用 VHDL,旧式 BFM 在 SystemVerilog 测试平台中会更好地工作,因为 VHDL 没有 SystemVerilog 接口。创建不必要的接口和包只是为了将 SystemVerilog 测试台插入不使用它们的 VHDL DUT 是一种冗余。

【问题讨论】:

    标签: system-verilog uvm


    【解决方案1】:

    您的问题的直接答案是否定的,SystemVerilog 具有有限的构造,您可以获取 句柄(接口、类和事件)。最大的问题是模块不像在被引用之前必须定义的数据类型。当您不知道标识符的类型时,创建对标识符的引用是非常困难且非最佳的。

    最初的 SystemVerilog interface 规范比现在简单得多。它的功能已经变得更像一个模块,但仍然更具限制性。

    但是,虚拟接口的替代方案,尤其是在与旧版 Verilog BFM 通信时,是一个经常讨论的话题。 link1link2link3

    【讨论】:

    • 不想重述显而易见的问题,但它是一个常见问题的原因是因为 SystemVerilog 标准缺少将模块类型的引用保存到变量中的功能......接口只是残废了具有一些额外 modport 语法的模块...您以与模块相同的方式实例化接口...因为它们实际上是相同的静态结构...标准人们在保存句柄时应该将模块与接口相同,在我的意见...
    • 另外,在我看来,旧式 Verilog-BFM 并不是遗留的......它的 SystemVerilog 标准通过试图强制所有测试台对所有事物使用接口来打破向后兼容性,即使设计没有’不需要它们...结果是人们需要维护完全相同代码的两个版本...具有相同的 BFM 任务...许多接口很简单,设计人员更喜欢将它们作为单独的信号来维护...要么方式...它实际上是相同的,而不是旧代码...只是缺少一个功能。
    【解决方案2】:
        `timescale 1 ns / 10 ps
    
        // The best why to solve this problem since the SystemVerilog
        //  language standard people did't give us a handle to a module
        //  is to create a define that points to full hierarchical path to
        //  the verilog module. Example:
    
        `define   DEF_BFM1   $root.top.BFM1
    
        // Verilog-95 style BFM (with verilog 2001 style ports)
        module BFM1(
            input  wire        clk,
            output reg [15:0]  data
        );
    
            task write(input [15:0] data1);
                data = data1;
                @(posedge clk); 
                #1;
            endtask;
    
        endmodule
    
        class MyClass
    
            function write(input [15:0] data);
                `DEF_BFM1.write(data);
            endfunction
        endclass
    
        // Testbench top-level
        module top;
            reg        clk;
            reg [15:0] data;
    
            initial begin
                clk = 0;
                forever #5 !clk = clk; 
            end
    
            BFM1 BFM1(
                .clk  (clk),
                .data (data)
            );
    
            DUT DUT(
                .clk  (clk), 
                .data (data)
            );
    
            initial begin
    
                //Verilog-95 Style BFM call
                `DEF_BFM1.write(16'h12340);
    
                // SystemVerilog Class style
                MyClass MyClass1 = new();
    
                MyClass.write(16'hDEAD);
                MyClass.write(16'hBEEF);
    
                $finish;
            end
        endmodule
    
        // Design under Test
        module DUT(
            input wire        clk,
            input wire [15:0] data
        );
            //insert design under test logic
        endmodule
    

    【讨论】:

    • 当您的设计有多个数据端口并希望为每个端口重用相同的类时,此答案无法扩展。它还阻止您将类放在包中,因为您不能将分层引用放在包中。使用包可以让你做一些事情,比如单独编译你的测试台和 DUT。
    • 不需要使用实例路径来访问模块中的功能/任务。 BFM1.write() 就足够了,在这种情况下不需要宏,也不需要模块实例化。如果类是用包定义的,它仍然不起作用。
    • 包含文件的工作方式几乎与包文件相同... ifndef MY_INCLUDE 定义 MY_INCLUDE 定义 DEF_BFM1 $root.top.BFM1 endif
    • 那是因为 systemVerlog 标准的人们是想要打破 verilog-95 而不问人们当时真正想要什么的混蛋……一个句柄只适用于“接口”而不是“模块 BFM” ..(他们还给了一个句柄一个可怕的关键字名称,叫做“virtual”)......因此,我需要用层次结构引用来破解它......这仍然有效,因为 SystemVerlog 也需要以同样的方式作弊......个人我认为 threy 搞砸了接口......在我看来实现它们的愚蠢方式......
    猜你喜欢
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 2013-11-21
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 2012-05-09
    • 1970-01-01
    相关资源
    最近更新 更多