0
votes

Recently I am thinking pre-calculating all necessary parameters using simple mathematical equations before instantiating logic units in generate struct. In the case where I need to have a 2-D parameter, it's easy if the 2-D array is a set of fixed values, such as

parameter para_1[1:0][2:0] = '{2{3{0}}};.

But what I want is a function that dictates the values, such that complicated equations can be implemented inside the function before assigning the return values to the parameter.

Ideally I want something as follows:

function func01 [1:0][1:0] (input int test);
  int index;
  for (index=0; index<=2; index++) begin
    func01[index] = index + $floor(index/2) + $mod(index, 2) + test;
  end
endfunction

parameter test1 = 1;
parameter logic test2 [1:0][1:0] = func01(test1);

But ModelSim complains about the first line of code straightaway - ** Error: (vlog-13069) near "[": syntax error, unexpected '[', expecting ';' or '('.

Ultimately the idea is to have a block that calculates all parameters/constants at elaboration time, so that these can be used in generate block for instantiation, also at elaboration time.

Hope it makes sense, and thanks a lot in advance.

Best, Taihai

1

1 Answers

0
votes

First, if you want packed arrays, the dimension ranges goes to the left of the array name. And I suggest using an explicit data type.

parameter bit [1:0][2:0] para_1 = '{2{3{0}}};.

Then, the return type of function declaration comes before the function name.

function bit [1:0][1:0] func01  (input int test);

BTW if you want the return type of a function to have an unpacked dimension, you must use a typedef, which is a good practice in any case.

typedef bit [1:0] myParam_t [2:0];
parameter myParam_t para_1 = '{default:0};
function myParam_t func01  (input int test);