![](/img/trans.png)
[英]verilog/systemverilog passing parameters upwards through generated module hierarchy
[英]Use SystemVerilog parameters to decide which module to instantiate
有没有一种方法可以使用传递给父模块的参数值来选择要实例化的模块? 下面的例子
module parent ();
parameter WORD = 1;
child_`WORD child (); // obviously does not work
endmodule
如果WORD == 1
,我想实例化child_1模块,对于WORD == 2
,child_2模块,依此类推。 当然,以前有人需要这样做吗?
如果要有条件地实例化模块,则需要使用generate
块。
generate
if (WORD == 1) begin
child_1 child();
end
if (WORD == 2) begin
child_2 child();
end
endgenerate
下面是一个完整的工作示例。 请注意,它仅说明child_1和child_2的存在。 您不能将参数用作要实例化的模块类型名称的一部分。 如果您有N个子模块,并且不想在generate块中显式枚举所有子模块,则可能需要创建一个辅助宏。
顺便说一句,这是有效的Verilog代码; 它不使用任何SystemVerilog功能。
module child_1();
initial begin
$display("child_1 %m");
end
endmodule
module child_2();
initial begin
$display("child_2 %m");
end
endmodule
module parent();
parameter WORD = 1;
// Conditionally instantiate child_1 or child_2 depending
// depending on value of WORD parameter.
generate
if (WORD == 1) begin
child_1 child();
end
if (WORD == 2) begin
child_2 child();
end
endgenerate
endmodule
module top();
parent #(.WORD(1)) p1();
parent #(.WORD(2)) p2();
endmodule
Incisive的输出:
child_1 top.p1.genblk1.child
child_2 top.p2.genblk2.child
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.