1

I want to have universal function to initialize same module with different parameters. One of them is packed array with size depends on another parameter. I've tried something like this:

package my_pkg;

    class helper #(
        parameter seed = 0
    );
        
    static function int GetRand();
        return seed + 10;
    endfunction

    endclass : helper

endpackage : my_pkg

module myModule #(
    parameter myParam = 0
);

    initial begin
        $display("My value = %d", myParam);
    end

endmodule : myModule

module test_class #(
);

    myModule #(
        .myParam(my_pkg::helper #(.seed(5))::GetRand())
    ) i_myModule ();

endmodule : test_class 

Vivado synthesis tool builds it without any errors, but Questa Sim doesn't allow to simulate this code. I'm getting following errors:

\*\* Error: ../../../..TEST.sv(54): External function '\<class-spec#1\>::GetRand' may not be used in a constant expression.
\*\* Error: ../../../../TEST.sv(54): The expression for a parameter actual associated with the parameter name ('myParam') for the module instance ('i_myModule') must be constant.

May be some one could advice some workaround for this trouble?

Same code with class without any parameters simulates with no problems. But function stops be universal...

toolic
  • 57,801
  • 17
  • 75
  • 117
Don Rumata
  • 11
  • 2

1 Answers1

0

You can just declare the function in the package without a class:

package my_pkg;

    function int GetRand(int seed);
        return seed + 10;
    endfunction

endpackage : my_pkg

module test_class #();
    myModule #(
        .myParam( my_pkg::GetRand(5) )
    ) i_myModule ();
endmodule : test_class 

This compiled for me on questa without errors.

toolic
  • 57,801
  • 17
  • 75
  • 117