在读xilinx的AXI接口代码中发现了function,记录一下:
function integer clogb2 (input integer bit_depth);
begin
for(clogb2=0; bit_depth>0; clogb2=clogb2+1)
bit_depth = bit_depth >> 1;
end
endfunction
verilog中的function定义没有明确function的返回值,其实函数名就是返回值,上述代码中的clogb2就是,在调用时使用以下语法:
localparam bit_num = clogb2(NUMBER_OF_OUTPUT_WORDS);
localparam integer WAIT_COUNT_BITS = clogb2(C_M_START_COUNT-1);
上面的function的作用是计算位宽的,比如输入16,计算出的位宽将是4,也就是clogb2的值是4,返回值也是4。