【问题标题】:Debug help : enum reg is incompatible with reg port调试帮助:枚举 reg 与 reg 端口不兼容
【发布时间】:2016-12-06 07:02:32
【问题描述】:

在我的模块中,我有一个名为 Cmd 的输出端口,它属于“reg”类型。

module ddesign (clk, rst, addr, data, Cmd);
    input          clk;
    input          rst;
    input [31:0]   addr;
    input [31:0]   data;
   ... 
    output reg [2:0]   Cmd; // this is the signal concerned
   ...
    always @(posedge clk) begin
        if (rst == 0) begin
            Cmd = IDLE; // I wanted to drive enum values 
        end
        else begin
            Cmd = WR;
            ...
         end
     end 

endmodule;

我还在另一个文件中使用 typedef 定义了信号 Cmd,如下所示。

typedef enum logic [2:0] {
    IDLE,
    WR,
    RD,
    RDX,
    RDL,
    WRN,
    WRC,
    BROADCAST
} Cmd_t;

接口是这样定义的

Interface intf (input clk);
   Cmd_t Cmd;
   ...
endinterface

在我实例化模块的顶层文件中,

module top;
     ...
    intf vif(clk); // interface instantiation

     ddesign dut(
        ...
     .Cmd(vif.Cmd), // the module port and interface are connected like this, but here is the incompatibility problem 
        ...
      );
endmodule

所以我收到以下错误:

** 错误: (vsim-3906) F:/folder1/project1/DV/top/top.sv(79): Connection type 'file_list_svh_unit.enum reg[2:0] ' is incompatible with 'reg[2 :0]' 用于端口 (Cmd)。

如果我可以在我的设计模块中驱动 Cmd 信号上的枚举类型值,如何解决此错误?

【问题讨论】:

  • 你可以构造一个MCVE。我在EDA Playground 上这样做了,没有发现错误。我也在 Questa 上试过,没有发现错误。

标签: interface system-verilog


【解决方案1】:

由于Cmd 是您设计的输出端口,您正试图将不是enum 的变量分配给另一个enum 变量。没有演员表是不合法的。并且 SystemVerilog 无法指定对赋值目标(或左值)的强制转换。

所以你需要做两件事之一:

  • 使用 Cmd_t 类型声明您的 Cmd 端口
  • 将 Cmd 端口连接到接口中兼容的变量类型,并使用连续赋值将其转换为 Cmd_t 类型。

【讨论】:

    【解决方案2】:

    通常不进行强制转换,将enum 分配给不同类型的值是不合法的。但是,可以通过在枚举上指定位范围来解决此问题。它适用于我尝试过的模拟器。我不确定此解决方法是模拟器还是 LRM 本身的有意或无意功能。

    ddesign dut(
      .Cmd(vif.Cmd[2:0]), 
      .* );
    

    【讨论】:

      猜你喜欢
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多