не совсем в курсе о каких функциях речь... но чтение из "бинарника в память" у меня выглядит так:
CODE
GENERIC (
addr_bits : INTEGER := 21;
data_bits : INTEGER := 18;
file_name : string:="RKP1x32.bin";
mem_sizes : INTEGER := 4194303;
width_bin : integer:=32;
file_type : string:="bin");
TYPE memory IS ARRAY (mem_sizes DOWNTO 0) OF STD_LOGIC_VECTOR (data_bits - 1 DOWNTO 0);
TYPE memory_2 IS ARRAY (mem_sizes/2 DOWNTO 0) OF STD_LOGIC_VECTOR (data_bits - 1 DOWNTO 0);
type char_file is file of character; -- one byte each
type char_array is array(natural range <>) of character;
impure function InitRamFromFile (RamFileName : in string) return memory is
file RamFile_bin : char_file;
FILE RamFile_txt : text;
variable RAM : memory;
variable RamFileLine, buf_out, buf_in : line;
variable i,j, up_border : integer;
variable my_char_v : character;
variable file_status:file_open_status;
variable s_byte : std_logic_vector (7 downto 0);
variable s_4byte : std_logic_vector (31 downto 0);
begin
if RamFileName(RamFileName'length-2)='b' then
--заполнение из бинарника
file_open(file_status, RamFile_bin, RamFileName, read_mode);
if width_bin=16 then up_border:=2;
elsif width_bin=8 then up_border:=0;
else up_border:=3;
end if;
for I in memory_2'reverse_range loop
for j in 0 to up_border loop
read(RamFile_bin, my_char_v);
s_byte := std_logic_vector (to_unsigned (character'pos(my_char_v), s_byte'length));
if j=3 then s_4byte(31 downto 24):=s_byte;
elsif j=2 then s_4byte(23 downto 16):=s_byte;
elsif j=1 then s_4byte(15 downto 8):=s_byte;
elsif j=0 then s_4byte(7 downto 0):=s_byte;
end if;
end loop;--j
RAM(I*2):="00"&s_4byte(31 downto 16);
RAM(I*2+1):="00"&s_4byte(15 downto 0);
if endfile(RamFile_bin) then exit; end if;
end loop;
file_close(RamFile_bin);
else
--заполнение из текстовика
file_open(RamFile_txt, RamFileName, read_mode);
for I in memory'reverse_range loop
readline (RamFile_txt, RamFileLine);
read (RamFileLine, RAM(I));
if endfile(RamFile_txt) then
-- assert not(i<memory'length) report "MY WORNING - MEMORY ISN'T FILLED" severity failure;
exit;
end if;
end loop;
file_close(RamFile_txt);
end if;
return RAM;
end function;
-----------------------------------------------------------------------------------------
shared variable Bank0 : memory:= InitRamFromFile(file_name);