Verilog:通用参数

问题描述 投票:0回答:1

我有几个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个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.