【发布时间】:2020-05-20 19:58:59
【问题描述】:
在 SystemVerilog IEEE Std 1800-2017 第 328 页中,显示了以下示例:
module ram_model (address, write, chip_select, data);
parameter data_width = 8;
parameter ram_depth = 256;
localparam addr_width = clogb2(ram_depth);
input [addr_width - 1:0] address;
input write, chip_select;
inout [data_width - 1:0] data;
//define the clogb2 function
function integer clogb2 (input [31:0] value);
value = value - 1;
for (clogb2 = 0; value > 0; clogb2 = clogb2 + 1)
value = value >> 1;
endfunction
logic [data_width - 1:0] data_store[0:ram_depth - 1];
//the rest of the ram model
endmodule: ram_model
“地址”输入宽度由“addr_width”确定,它是模块内部函数的输出,这有什么意义?
【问题讨论】:
-
基本上,函数在编译时执行,而不是在运行时执行。你也可以在 VHDL 中做这种事情。