【问题标题】:inout port with real datatype in systemverilogsystemverilog 中具有真实数据类型的 inout 端口
【发布时间】:2020-09-16 01:17:25
【问题描述】:

我需要在我的模块中有一个带有real 数据类型的inout 端口。此外,我需要在该端口具有多个驱动程序解析能力。 (看到了nettype,但在 LRM 的模块端口中没有看到它的用法)

这是一个示例代码。

module abc (
  input real vref1, 
  output real vout);

  assign vout = vref1 * 3.17;
endmodule

module def (
  input logic out_en, 
  input logic data, 
  output logic vref1);

  bufif1 b1 (vref1, data, out_en);
endmodule

module top (
  inout real vref1,
  input logic out_en,
  input logic data,
  output real vout);
  
  logic vref1_dig_l;

  assign vref1 = (vref1_dig_l === 1'bz) ? 100.0 : ((vref1_dig_l == 1'b0) ? 0.0 : 20.0);

  abc a1 (vref1, vout);
  def d1 (out_en, data, vref1_dig_l);
endmodule

module temp ();
  real  vref1;
  logic out_en;
  logic data;
  real vout;

  top t1 (vref1, out_en, data, vout);

  initial 
    $monitor("vref1 - %0f, out_en - %0b, data - %0b, vout - %0f", vref1, out_en, data, vout);

  initial begin
    #1 vref1 = 5.0; out_en = $random()%2; data = $random();
    #1 vref1 = 5.0; out_en = $random()%2; data = $random();
    #1 vref1 = 5.0; out_en = $random()%2; data = $random();
    #1 vref1 = 5.0; out_en = $random()%2; data = $random();
    #1 vref1 = 5.0; out_en = $random()%2; data = $random();
    #1 vref1 = 5.0; out_en = $random()%2; data = $random();
    #1 vref1 = 5.0; out_en = $random()%2; data = $random();
    #1 vref1 = 5.0; out_en = $random()%2; data = $random();
  end
endmodule

这给了我以下错误-

  inout real vref1,
                 |
xmvlog: *E,SVNTRL (../b.sv,25|17): A module port that is a net cannot be of type 'real' or 'shortreal' by SystemVerilog language rules.

【问题讨论】:

    标签: verilog system-verilog register-transfer-level


    【解决方案1】:

    您可以使用以下内容:

    nettype real nreal;
    
    module top (
      inout nreal vref1,
      ...
    
    

    但是,real 不是一个可综合的概念,不能用于门级逻辑,因此以下是非法的:bufif1 b1 (vref1, data, out_en) with verif1 as real。

    解决您的问题的另一种方法是使用系统 verilog 函数将实数转换为位,反之亦然 (lrm 20.5)

        [63:0] $realtobits ( real_val )
        real $bitstoreal ( bit_val )
    

    临时模块的 init 块中的分配问题:

    根据verilog 规则,来自程序块的任何赋值的lhs 必须是变量。 “初始”块是一个程序块。 'net' 不是变量。

    在 temp 中,您必须将 vref1 声明为“nreal”,这是一种网络类型,您不能从程序块中分配它。您需要一个变量作为中间阶段:

    nreal vref1;
    real vref1_real;
    assign nreal = vref1_real;
    
    ...
    initial begin
        vref1_real = your expression;
    ...
    

    以上将解决您的分配问题。

    在您的情况下,看起来还需要解析功能。以下内容可能会有所帮助:

    function automatic real nres_avg (input real drivers[]);
        return drivers.sum/drivers.size(); // average of all drivers
    endfunction
    nettype real nreal with nres_avg;
    

    【讨论】:

    • 这不是可综合的代码。我大概可以为nreal 类型添加解析功能。对吗?
    • 不行,一使用real,代码就无法合成。你可以在TB中使用real,在处理到RTL的时候转换成bit;然后将其转换回以 TB 为单位的实数。
    • 很抱歉造成混淆。我只在 TB 中使用它,而不是 RTL。但是对于这个inout net。我还需要编写解析函数。对吗?
    • 这取决于你。您可以编写一个或依赖默认值。至少按照标准。我在那里没有经验。
    • 我收到此 nettype 的分配错误。你能展示一个带作业的工作示例吗?
    【解决方案2】:

    wiretriwand 等内置网络对象不能具有由 4 态类型 logic 组成的数据类型以外的数据类型。当有多个驱动程序时,内置网络都具有预定义的解析功能。

    inout 应该有多个驱动程序,因此这种端口上只允许使用网络。 如果您想在网络上使用real 数据类型,则需要使用用户定义的nettype 来定义它,以便解析函数可以与网络相关联。即您是否希望对各个驱动程序进行平均、求和、最大值等。1800-2017 中有一些示例,大多数工具都将这些作为现成的软件包提供。

    【讨论】:

    • 用户定义的nettype可以用作端口吗?我在 LRM 中看不到任何这样的例子。
    • 是的。 23.3.3 端口连接规则 节对此进行了定义,但 LRM 中没有示例。但是,有一个通用 interconnect 的示例,它通过端口传递真实的网络类型。
    • 如果可能的话,你能分享一下这个例子或者让我知道它在 LRM 中的位置吗?
    • 6.6.8 节通用互连.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2022-09-27
    • 1970-01-01
    相关资源
    最近更新 更多