【问题标题】:Verilog: generic parametersVerilog:通用参数
【发布时间】:2015-06-03 19:17:18
【问题描述】:

我有几个verilog(不是system-verilog)块,我想根据其他参数生成它们。举个例子:

module some_module (in, out)

realtime p = 3.5; // the parameter which I want to change

initial begin
if ('global_parameter == 1)
    p = 5.8;
if ('global_parameter == 2)
    p = 4.4;
end

core_module #(p) core (in, out);
endmodule

这里,“global_parameter”在头文件中定义,但在模拟时使用模拟器参数覆盖。我的核心模块使用“p”作为延迟值,如下例所示:

module core_module(in, out)

parameter p = 1;

always out <= #p in; // p should be constant

endmodule

因此,我希望核心模块具有更新的参数“p”。但是这种情况是不可模拟的。如果可能的话,你能推荐我一个可能的解决这个问题的方法吗?

谢谢

【问题讨论】:

  • “无法模拟”或无法编译?
  • 编译时出现错误,很抱歉造成混淆

标签: parameters verilog


【解决方案1】:

在整个设计中,参数必须是parameter 类型。您不能将变量作为参数传递。

您可以使用生成块来控制实例化:

module core_module#(parameter realtime P=1)(input in, output out);
  always @(in) out <= #(P) in; // p should be constant
endmodule

module some_module (input in, output out);
  generate
    if (GLOBAL_PARAMETER == 1) begin : cfg_1
      core_module #(5.8) core (in, out);
    end
    else if (GLOBAL_PARAMETER == 2) begin : cfg_2
      core_module #(4.4) core (in, out);
    end
    else begin : cfg_dflt
      core_module #(3.5) core (in, out); // default
    end
  endgenerate
endmodule

也可以单行计算参数:

module some_module (input in, output out);
  parameter P = (GLOBAL_PARAMETER == 1) ? 5.8 : (GLOBAL_PARAMETER == 2) ? 4.4 : 3.5;
  core_module #(P) core (in, out); // default
endmodule

或者(由于您无法合成),您可以将延迟值设为变量,然后通过分层引用强制该值。示例:

module core_module (input in, output out);
  realtime p = 1;
  always @(in) out <= #(p) in; // this p is a variable
endmodule

module some_module (input in, output out);
  realtime p = 3.5;
  core_module core (in, out);
  initial begin
    if (GLOBAL_PARAMETER == 1)
      p = 5.8;
    else if (GLOBAL_PARAMETER == 2)
      p = 4.4;
    force core.p = p; // force hierarchical variable assignment
  end
endmodule

注意:所有示例都与 IEEE Std 1364-2001 和 IEEE Std 1364-2005 兼容,使用 ANSI 标头样式并生成块。 IEEE Std 1364-1995 中不存在这些功能


我不知道有任何干净的仅 Verilog 解决方案。您可以尝试嵌入代码(例如 Perl 的 EP3、Ruby 的 eRuby/ruby_it、Python 的 prepro 等)。正如我在另一个类似问题的答案中提到的,here。嵌入式的一个挑战是需要预编译/处理,使它们更像`define 然后是参数。

如果 SystemVerilog 是一个选项,您可以执行以下操作:(请参阅 IEEE Std 1800-2012 § 6.20 常量;靠近 § 6.20.2 末尾的示例)

module some_module (input in, output out);
  parameter realtime P [3] = '{3.5, 5.8, 4.4};
  core_module #(P[GLOBAL_PARAMETER]) core (in, out);
endmodule

【讨论】:

  • 对于您的回答 Greg,我已经尝试过生成块,这似乎很好,但是以这种方式生成了太多块。你知道是否还有其他选择?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-04
相关资源
最近更新 更多