简体   繁体   English

是否可以在Verilog / SystemVerilog中通过模块层次结构传递常量参数UPWARDS?

[英]Is it possible to pass constant parameters UPWARDS through module hierarchy in Verilog / SystemVerilog?

Assume you have a module at a low-level in your hierarchy that has a fairly complex parameter calculation. 假设您的层次结构中有一个低级别的模块,该模块具有相当复杂的参数计算。 This parameter calculation can not be conveniently replicated in a higher-level module, because it uses information from other parameters at the low-level. 此参数计算无法在更高级别的模块中方便地复制,因为它使用来自低级别的其他参数的信息。 Now assume you also have a module at a higher level in the hierarchy that requires referring to that parameter to calculate a different parameter. 现在假设您在层次结构中还有一个更高级别的模块,需要引用该参数来计算不同的参数。

Is there a way in (System)Verilog to read a parameter from a lower-level module's instantiation in the calculation of a higher-level module's parameter? (System)Verilog中是否有一种方法可以在计算更高级别模块的参数时从较低级别模块的实例中读取参数?

Of course, you could attempt to use an 'interface' here... 当然,您可以尝试在这里使用“界面”......

interface interface_low ();                                                                         

        localparam VERY_COMPLEX_PARAM = 1 + 1;                                                           

endinterface;                                                                                       

interface interface_high (interface_low if_low);                                                    

        localparam OTHER_PARAM = if_low.VERY_COMPLEX_PARAM + 1;                                          

endinterface

... but attempting to compile this snippet for simulation with Riviera-PRO will return the error "Parameter initial value cannot contain external references: if_low.COMPLEX_PARAM+1.". ...但是尝试使用Riviera-PRO编译此片段以进行模拟将返回错误“参数初始值不能包含外部引用:if_low.COMPLEX_PARAM + 1。”。 Alternatively, you can try something like... 或者,您可以尝试类似......

module low_level #(parameter SOME_NUM = 1, localparam VERY_COMPLEX_PARAM = SOME_NUM + 1) (output logic [31 : 0] out);

        always_comb                                                                                 
        begin                                                                                       
                out = VERY_COMPLEX_PARAM;                                                           
        end                                                                                         

endmodule                                                                                           


module high_level (output logic [31:0] out);                                                        

        logic [31:0] low_out;                                                                       

        low_level #(.SOME_NUM (4)) ll (low_out);                                                    


        localparam OTHER_PARAM = ll.VERY_COMPLEX_PARAM + 1;                                         

        always_comb                                                                                 
        begin                                                                                       
                out = OTHER_PARAM;                                                                  
        end                                                                                         

endmodule  

... but again it leads to the error "Parameter initial value cannot contain external references: ll.VERY_COMPLEX_PARAM+1." ...但同样会导致错误“参数初始值不能包含外部引用:ll.VERY_COMPLEX_PARAM + 1”。

It is always possible to simply re-organize the implementation so that constant parameters are strictly passed downwards, but I feel this is a lackluster solution. 总是可以简单地重新组织实现,以便不断向下传递常量参数,但我觉得这是一个平淡无奇的解决方案。 In that case, the higher level modules are now calculating constants that refer to implementation details much lower in the hierarchy. 在这种情况下,更高级别的模块现在正在计算常量,这些常量引用层次结构中低得多的实现细节。 It seems silly to add dependencies in low-level modules to higher-level modules simply to satisfy restrictions regarding the calculation of constants . 将低级模块中的依赖项添加到更高级别的模块似乎很愚蠢,只是为了满足有关常量计算的限制。

So, is there a better way? 那么,有更好的方法吗?

Parameter evaluation must flow top to bottom. 参数评估必须自上而下。 Your interface example should have worked as an interface port is not considered a hierarchical reference (it does work on two other tools I tried). 您的接口示例应该作为接口端口工作,不被视为分层引用(它可以在我尝试的其他两个工具上工作)。

For your particular example, you could have used 对于您的特定示例,您可以使用

const int OTHER_PARAM = ll.VERY_COMPLEX_PARAM + 1;  

As long as OTHER_PARAM is not being used in a place where a constant is required. 只要OTHER_PARAM不在需要常量的地方使用。 You might have the same problem with synthesis tool support. 您可能在综合工具支持方面遇到同样的问题。

Another option is to put the parameters in a package and have both lower and upper modules import the same package. 另一种选择是将参数放在一个包中,让下层和上层模块导入同一个包。

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

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