You need an additional parameter for the size:
module reg_slave
#(parameter
int SIZE=1,
reg_pkg::defval_pair [SIZE-1:0] REG_DEFVAL = '0 //param decl with size=1
)();
endmodule : reg_slave
You have a few errors in assigning REG_DEFVAL
in top
. REG_DEFVAL
is a packed array, therefore remove the single quite. defval_pair
is a packed struct
, therefore the entries need a cast assignment:
module top();
localparam int SIZE=2;
localparam reg_pkg::defval_pair [SIZE-1:0] REG_DEFVAL = { // no single quite
reg_pkg::defval_pair'{3,'h32}, // cast as defval_pair
reg_pkg::defval_pair'{0,'h1} // cast as defval_pair
}; //param of same type and size = 2
reg_slave #( .SIZE(SIZE), // override size
.REG_DEFVAL(REG_DEFVAL)
)
reg_slave_inst ();
endmodule : top
UPDATE: Passing a N size array parameter without passing a SIZE parameter.
Note: this is most likely not synthesisable. SystemVeilog support for this feature may vary between simulators.
module reg_slave
#(parameter
reg_pkg::defval_pair REG_DEFVAL [] = '{ reg_pkg::defval_pair'{0,'h0} } //param decl with size=1
)();
endmodule : reg_slave
module top();
localparam reg_pkg::defval_pair REG_DEFVAL [] = '{ // with single quite
reg_pkg::defval_pair'{3,'h32}, // cast as defval_pair
reg_pkg::defval_pair'{0,'h1} // cast as defval_pair
}; //param of same type and size = 2
reg_slave #(
.REG_DEFVAL(REG_DEFVAL)
)
reg_slave_inst ();
endmodule : top