1

SystemVerilog中Configuration的用法

1. Config

configuration是一套用来描述设计中实例来源的一套显式规则, 它的规则如下:

77f38da5-bf0c-4ff8-8f2a-1fdd290eb4fe

2. 语法

config < config_name >;
design [< library >.]< cell >
default liblist [{< libraries >}];
cell [< library >.]< cell > liblist [{< libraries >}];
cell [< library >.]< cell > use [< library >.]< cell >[:config];
instance < full_hierarchical_path > liblist [{< libraries >}];
instance < full_hierarchical_path > use [< library >.]< cell >[:config];
endconfig

3. example

149290c4-2e10-4a87-8785-418ea3a0163e

lib.map :

library rtlLib *.v; // matches all files in the current directory with a .v suffix
library gateLib ./*.vg; // matches all files in the current directory with a .vg suffix

config cfg1; // specify rtl adder for top.a1, gate-level adder for top.a2
    design rtlLib.top;
    default liblist rtlLib;
    instance top.a2 liblist gateLib; 
endconfig

上面就是一个最简单的例子,通过configuration来选择对于某个instance使用哪个module的实现

4. 讲解

一个configuration的基本元素包含:

  • config/endconfig
  • design
  • default + liblist : 这两个通常是一起出现来指定默认搜索库
  • instance + liblist: 绑定某个instance到某个库

高级元素包含:
use : 只用于instance和cell后面来指定精确的lib和cell

config bot;
    design lib1.bot;
    default liblist lib1 lib2;
    instance bot.a1 liblist lib3;
endconfig
config top;
    design lib1.top;
    default liblist lib2 lib1;
    instance top.bot use lib1.bot:config;
    instance top.bot.a1 liblist lib4;   // ERROR - cannot set liblist for top.bot.a1 from this config
    cell adder use gateLib.adder;
endconfig

5. 参数设置

adder.sv

module adder #(parameter ID = "id",
W = 8,
D = 512)
(...);
...
$display("ID = %s, W = %d, D = %d", ID, W, D);
...
endmodule: adder

top.sv

module top (...);
parameter WIDTH = 16;
adder a1 (...); 
endmodule 

module top4 ();
parameter S = 16;
adder a1 #(.ID("a1"))(...);
adder a2 #(.ID("a2"))(...);
adder a3 #(.ID("a3"))(...);
adder a4 #(.ID("a4"))(...);
endmodule

Case 1

config cfgl;
design rtlLib.top;
instance top use #(.WIDTH(32));
instance top.a1 use #(.W(top.WIDTH));
endconfig

输出结果是:

ID = id, W=32, D = 512

Case 2

config cfg2;
localparam S = 24
design rtlLib.top4;
instance top4.a1 use #(.W(top4.S));
instance top4.a2 use #(.W(S));
endconfig

输出结果是:

ID = a1, W=16, D = 512
ID = a2, W=24, D = 512
ID = a3, W=8, D = 512
ID = a4, W=8, D = 512

Case 3

module top5 (...);
parameter WIDTH = 64, DEPTH = 1024, ID = "A1"; 
adder a1 #(.ID(ID), .W(WIDTH), .D(DEPTH))(...);
endmodule

输出结果是:

ID = A1, W=64, D = 1024

Case 4

config cfg3;
design rtlLib.top5;
instance top5.a1 use #(.W()); // set only parameter W back to its default 
endconfig

输出结果是:

ID = A1, W=8, D = 1024

Case 5

config cfg4;
design rtlLib.top;
instance top.a1 use #(); // set all parameters in instance a1 
// back to their defaults
endconfig

输出结果是:

ID = id, W=8, D = 512

Case 6

test.sv
module test;
...
top8 t(...);
defparam t.WIDTH = 64;
defparam t.a1.W = 16;
...
endmodule
top8.sv
module top8 (...);
parameter WIDTH = 32;
adder a1 #(.ID("a1")) (...);
adder a2 #(.ID("a2"),.W(WIDTH))(...);
endmodule
adder.sv
module adder #(parameter ID = "id",
W = 8,
D = 512)
(...);
...
$display("ID = %s, W = %d, D = %d", ID, W, D);
...
endmodule
cfg6.sv
config cfg6;
design rtlLib.test;
instance test.t use #(.WIDTH(48));
endconfig

输出结果是:

ID = a1, W=16, D = 512
ID = a2, W=48, D = 512

总结

如果设计中有声明一样,实现不一样的两个模块被不同的模块使用,这个时候Configuration是非常必要的。
虽然各个工具也有各自的方法,但它们毕竟不通用,无法被其他工具使用。所以最好的方法还是使用Configuration.


harriszh
338 声望131 粉丝

做些有趣的事,留些有用的存在


引用和评论

0 条评论