Altera_Forum
Honored Contributor
10 years agomodelsim compiling error:external function 'xxxxx' may not be used in a constant expr
Consider the following code:
package pkg;
function bit bitgen(int bit1idx);
automatic bit res = '0;
if (bit1idx >= 0 && bit1idx < 16)
res = 1'b1;
return res;
endfunction
function bit bit2test(bit bits2test);
if ((bits2test&bitgen(2)) != 0)
return 1'b1;
return 1'b0;
endfunction
endpackage
module mod2test# (
parameter para2test = 16'h000F
);
import pkg::*;
localparam bit2set_flag = bit2test(para2test);
initial begin
if (bit2set_flag == 0)
$error("bit2 of para2test is not set!);
end
endmodule
When compiling these code in modelsim, it reports some error message, one of them is: External function 'bit2test' may not be used in a constant expression. My purpose is: by defining a function to test the instantiate parameter of module , to obtain some state of instantiating of module and to make some special processing for it, the defined function should be used in many different module, for the testing work in them is same. But if the function defined in package can not be used in constant expression, how can I realize my purpose in design?