Define all the parameters for the function for word matrix size:
Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function slv2matrix2d(a :instd_logic_vector; n_rows, n_cols :integer)return byte_2d_matrix_t isvariable ret : byte_2d_matrix_t(0to n_rows-1, 0to n_cols-1);beginassert(a rem8)=0and n_rows*n_cols*8= a'lengthreport"Specified paramters do name match input word length"severity failure;for i in0to n_rows-1loopfor j in0to n_cols-1loop
ret(i,j)= a((i*n_cols + j)*8+7downto(i*n_cols + j)*8);endloop;endloopreturn ret;endfunction;
This way, it doesnt matter what the range of the output is, because this will already be known. the 0 to n_rows etc will just map onto whatever the output is:
Code:
signal my_byte2d : byte_2d_matrix_t(123 downto 77, 5 to 104732464);
my_byte2d <= slv2matrix2d( a, my_byte2d'length(1), my_byte2d'length(2));