--MMS-- said:
Is it possible to initialize a memory (array) to random numbers, in
VHDL?
Here's how I make a vhdl constant array with a function.
This one happens to be characters instead of vectors.
type char_file_t is file of character; -- one byte each
function spew(i_arg : integer) return char_array_t is
variable result : char_array_t(0 to i_arg-1);
variable index : char_index;
begin
for i in 0 to i_arg-1 loop
index := i mod (1+char_index'right);
result(i) := character'val(index);
end loop;
return result;
end function spew;
constant box_o_chars_c : char_array_t := spew(512);
You could do something similar with a vector array
and use a function like this for the data:
function randomize (arg_byte : char_t)
return char_t is
variable result_v : char_t;
begin
result_v := arg_byte; -- here it is
result_v := shift_left(result_v, 1); -- shift it
if (result_v(result_v'left)) = '1' then -- maybe invert mask
result_v := result_v xor mask_c;
end if;
return result_v;
end function randomize;
Good luck.
-- Mike Treseler