简体   繁体   English

数组作为模块参数

[英]Array as module parameter

How to pass a constant array as a module parameter?如何将常量数组作为模块参数传递?

I want to build a shift register width different shift widths.我想建立一个移位寄存器宽度不同的移位宽度。 The possible shift widths should be definable via a module parameter.可能的移位宽度应该可以通过模块参数来定义。 I tried something like the following, but this not working.我尝试了类似以下的方法,但这不起作用。

module ShiftReg
#(
  SHIFT_WIDTH = '{1, 2, 4, 8},
  WIDTH = $clog2($size(SHIFT_WIDTH))
)
(
  ...
  input  logic [WIDTH-1:0] shift_rate_i,
  ...
);
  ...
endmodule

This results in following error message:这会导致以下错误消息:

** Error: shift_reg.sv(3): Illegal concatenation of an unsized constant.

Is such a generic construction of a shift register with different widths possible in SystemVerilog?在 SystemVerilog 中,这种具有不同宽度的移位寄存器的通用结构是否可行?

Not every simulator supports arrayed parameters.并非每个模拟器都支持数组参数。 For those that do, the array needs to be defined with an array identifier (ex: [] , [SIZE] ) and a bit width for the entries;对于那些这样做的人,需要使用数组标识符(例如: [][SIZE] )和条目的位宽来定义数组; int SHIFT_WIDTH [] = '{1, 2, 4, 8} should work. int SHIFT_WIDTH [] = '{1, 2, 4, 8}应该可以工作。

I tried different combinations on EDAplaygroud .我在EDAplaygroud上尝试了不同的组合。 Queued arrays ( [$] ) was not accepted by any simulator.任何模拟器都不接受排队数组 ( [$] )。 VCS supported [] arrayed parameters, but it does not accept it with $size() or .size() in a parameter definition. VCS 支持[]数组参数,但它不接受参数定义中带有$size().size()的参数。 A fixed array size does work on VCS and Riviera-PRO.固定数组大小在 VCS 和 Riviera-PRO 上确实有效。 Declaring the size is an extra step, but it works.声明大小是一个额外的步骤,但它有效。

module ShiftReg
#(
  SIZE = 4,
  int SHIFT_WIDTH [SIZE] = '{1, 2, 4, 8},
  WIDTH = $clog2(SIZE)
//WIDTH = $clog2($size(SHIFT_WIDTH)) // <-- this also works if SHIFT_WIDTH is a fixed size
)
(
  ...
  input  logic [WIDTH-1:0] shift_rate_i,
  ...
);
  ...
endmodule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM