在 systemverilog 中具有真实数据类型的 inout 端口

inout port with real datatype in systemverilog

我需要在我的模块中使用 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.

wiretriwand等built-in网络对象不能有除由4状态类型组成的数据类型以外的数据类型logic。 built-in nets 都有 pre-defined 多个驱动时的解析函数。

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

您可以使用以下内容:

nettype real nreal;

module top (
  inout nreal vref1,
  ...

然而,real不是可综合的概念,不能用在gate-level逻辑中,所以下面是非法的: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 都必须是变量。 'initial' 块是程序块。 'net' 不是变量。

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

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;