将层次结构传递到Verilog模块中
时间:2020-03-05 18:54:39 来源:igfitidea点击:
我有一个"观察程序"模块,当前在其中使用全局层次结构。我需要使用第二个全局层次结构实例化此实例的第二个实例。
目前:
module watcher; wire sig = `HIER.sig; wire bar = `HIER.foo.bar; ... endmodule watcher w; // instantiation
期望的:
module watcher(input base_hier); wire sig = base_hier.sig; wire bar = base_hier.foo.bar; ... endmodule watcher w1(`HIER1); // instantiation watcher w2(`HIER2); // second instantiation, except with a different hierarchy
我最好的主意是使用vpp(Verilog预处理器)强行生成两个几乎相同的模块(每个层次结构一个),但是还有一种更优雅的方法吗?
解决方案
回答
我的首选是在测试平台中只有一个模块(或者少量模块),其中包含所有探针,但没有其他功能。然后,测试台中需要探针的所有其他模块都将连接到该"探针模块"。如果可以的话,请优先使用SystemVerilog接口而不是裸线。这避免了问题,因为没有观察者会需要全局层次结构,并且测试台整体上将更易于维护。参见得墨meter耳定律。
或者...(但是这会将层次结构放入实例中...)
module watcher(sig, bar); input sig; input bar; ... endmodule watcher w1(`HIER1.sig, `HIER1.foo.bar); // instantiation watcher w2(`HIER2.sig, `HIER2.foo.bar); // second instantiation, except with a different hierarchy
随后,我们还可以:
`define WATCHER_INST(NAME, HIER) watcher NAME(HIER.sig, HIER.foo.sig) `WATCHER_INST(w1, `HIER1); `WATCHER_INST(w2, `HIER2);
回答
我们可以使用SystemVerilogbind
关键字将模块绑定到需要它的每个层次结构中吗? (这要求我们使用SystemVerilog,并具有模拟器的许可证。)
使用bind就像以常规方式实例化模块一样,不同之处在于我们提供了将模块"远程"实例化到的层次结构的路径:
bind top.my.hier my_module instance_name(.*); bind top.my_other.hier my_module instance_name(.*);
更好的是:假定绑定到的每个层次结构都是同一模块的单独实例。然后:
bind remote_module my_module instance_name(.*);
不管模块在设计中的什么位置,这都将模块绑定到目标的每个实例中。如果模块是验证检查器,则此功能非常强大。