fanwel
Full Member level 3
Hi all;
I found a memory code,but I think it is not synthesis because it use file command. Is it the code below is synthesis? If not, how to make it synthesis? Thank you
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use std.textio.all;
use ieee.std_logic_textio.all;
entity Memory is
generic
(
WIDTH : integer := 512;
HEIGHT : integer := 512; -- IMAGE_MEMORY_SIZE
ADDR_BUS_WIDTH : integer := 19;
INPUT_FILENAME : string := "TestData.txt";
OUTPUT_FILENAME : string := "DWTResult.txt"
);
port
(
cs : in std_logic;
rd : in std_logic;
wr : in std_logic;
dump : in std_logic;
addr : in std_logic_vector(ADDR_BUS_WIDTH - 1 downto 0);
datain : in std_logic_vector(7 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end Memory;
architecture Behavioral of Memory is
type memory_type is array(0 to WIDTH*HEIGHT - 1) of std_logic_vector(7 downto 0);
signal mem : memory_type; -- instance of memory: image data
procedure FillMemory(signal omem: out memory_type; file_name: string) is
file ifile : TEXT is in file_name;
variable l_in : LINE;
variable dt : std_logic_vector(7 downto 0);
begin
for ty in 0 to HEIGHT/2 - 1 loop
readline(ifile, l_in);
for tx in 0 to WIDTH - 1 loop
hread(l_in, dt);
omem(tx + WIDTH*ty) <= dt;
end loop;
end loop;
end;
procedure DumpMemory(imem: in memory_type; file_name: string; lower_addr_half: boolean) is
file ofile : TEXT is out file_name;
variable l_out : LINE;
variable dt : std_logic_vector(7 downto 0);
begin
if lower_addr_half then
for ty in 0 to HEIGHT/2 - 1 loop
for tx in 0 to WIDTH - 1 loop
dt := imem(tx + WIDTH*ty);
hwrite(l_out, dt);
write(l_out, ' ');
end loop;
writeline(ofile, l_out);
end loop;
else
for ty in HEIGHT/2 to HEIGHT - 1 loop
for tx in 0 to WIDTH - 1 loop
dt := imem(tx + WIDTH*ty);
hwrite(l_out, dt);
write(l_out, ' ');
end loop;
writeline(ofile, l_out);
end loop;
end if;
end;
begin
process(cs, rd, wr, dump, addr, datain)
variable mem_init : boolean := false;
variable reorder_mem : memory_type;
begin
if (not mem_init) then
mem_init := true;
if INPUT_FILENAME'length > 0 then
FillMemory(mem,INPUT_FILENAME);
end if;
end if;
if (dump'event and dump = '1') then
if OUTPUT_FILENAME'length > 0 then
DumpMemory(mem,OUTPUT_FILENAME,TRUE);
DumpMemory(mem,"DWT_VERSD.txt",FALSE);
end if;
end if;
if (cs = '1') then
if (wr = '1') then
mem(CONV_INTEGER(UNSIGNED(addr))) <= datain;
elsif (rd = '1') then
dataout <= mem(CONV_INTEGER(UNSIGNED(addr)));
else
dataout <= (others => 'Z');
end if;
end if;
end process;
end Behavioral;
I found a memory code,but I think it is not synthesis because it use file command. Is it the code below is synthesis? If not, how to make it synthesis? Thank you
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use std.textio.all;
use ieee.std_logic_textio.all;
entity Memory is
generic
(
WIDTH : integer := 512;
HEIGHT : integer := 512; -- IMAGE_MEMORY_SIZE
ADDR_BUS_WIDTH : integer := 19;
INPUT_FILENAME : string := "TestData.txt";
OUTPUT_FILENAME : string := "DWTResult.txt"
);
port
(
cs : in std_logic;
rd : in std_logic;
wr : in std_logic;
dump : in std_logic;
addr : in std_logic_vector(ADDR_BUS_WIDTH - 1 downto 0);
datain : in std_logic_vector(7 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end Memory;
architecture Behavioral of Memory is
type memory_type is array(0 to WIDTH*HEIGHT - 1) of std_logic_vector(7 downto 0);
signal mem : memory_type; -- instance of memory: image data
procedure FillMemory(signal omem: out memory_type; file_name: string) is
file ifile : TEXT is in file_name;
variable l_in : LINE;
variable dt : std_logic_vector(7 downto 0);
begin
for ty in 0 to HEIGHT/2 - 1 loop
readline(ifile, l_in);
for tx in 0 to WIDTH - 1 loop
hread(l_in, dt);
omem(tx + WIDTH*ty) <= dt;
end loop;
end loop;
end;
procedure DumpMemory(imem: in memory_type; file_name: string; lower_addr_half: boolean) is
file ofile : TEXT is out file_name;
variable l_out : LINE;
variable dt : std_logic_vector(7 downto 0);
begin
if lower_addr_half then
for ty in 0 to HEIGHT/2 - 1 loop
for tx in 0 to WIDTH - 1 loop
dt := imem(tx + WIDTH*ty);
hwrite(l_out, dt);
write(l_out, ' ');
end loop;
writeline(ofile, l_out);
end loop;
else
for ty in HEIGHT/2 to HEIGHT - 1 loop
for tx in 0 to WIDTH - 1 loop
dt := imem(tx + WIDTH*ty);
hwrite(l_out, dt);
write(l_out, ' ');
end loop;
writeline(ofile, l_out);
end loop;
end if;
end;
begin
process(cs, rd, wr, dump, addr, datain)
variable mem_init : boolean := false;
variable reorder_mem : memory_type;
begin
if (not mem_init) then
mem_init := true;
if INPUT_FILENAME'length > 0 then
FillMemory(mem,INPUT_FILENAME);
end if;
end if;
if (dump'event and dump = '1') then
if OUTPUT_FILENAME'length > 0 then
DumpMemory(mem,OUTPUT_FILENAME,TRUE);
DumpMemory(mem,"DWT_VERSD.txt",FALSE);
end if;
end if;
if (cs = '1') then
if (wr = '1') then
mem(CONV_INTEGER(UNSIGNED(addr))) <= datain;
elsif (rd = '1') then
dataout <= mem(CONV_INTEGER(UNSIGNED(addr)));
else
dataout <= (others => 'Z');
end if;
end if;
end process;
end Behavioral;