library ieee; use std.textio.all; use ieee.std_logic_textio.all; use ieee.std_logic_1164.all; use ieee.numeric_std.all; ---------------------------------------------------------------------------- -- This function block describes a simple model of RAM. ---------------------------------------------------------------------------- entity ram is generic ( Size : integer := 64; -- number of memory words AddrWidth: integer := 8; -- number of address bits DataWidth: integer := 8; -- number of bits per memory word download_on_power_up: boolean := true; -- if TRUE, RAM is downloaded at start of simulation download_filename: IN string := "ram_data.txt" ); port ( ce : in std_logic; -- Chip-Enable memread, memwrite: in std_logic; -- read and write commands clk: in std_logic; -- clock for write operation addr : in std_logic_vector (AddrWidth-1 downto 0); dbus : inout std_logic_vector (DataWidth-1 downto 0); dump : in std_logic; -- 0-to-1 transaction downloads the content of memory -- (dump_start to dump_end) to the log file dump_start: in integer; dump_end: in integer ); end; architecture behavior of ram is type memory is array (0 to Size-1) of std_logic_vector (DataWidth-1 downto 0); begin memory_process: process (ce, memread, memwrite, clk, addr, dbus, dump) variable init_done: boolean := false; variable mem: memory; function stdvec2int(stdvec: std_logic_vector) return integer is variable result : integer := 0; begin for i in stdvec'range loop result := result * 2; if (stdvec(i) = '1') then result := result + 1; end if; end loop; return result; end; procedure load_mem is file infile: text is in download_filename; variable inbuf: line; variable outbuf: line; variable good : boolean; variable ch: character; variable iaddr: integer; variable ram_data: std_logic_vector(DataWidth-1 downto 0); begin write(outbuf,string'("Loading SRAM from file ")); write(outbuf,download_filename & string'(" ... ")); writeline (output, outbuf); while not endfile(infile) loop readline(infile, inbuf); read(inbuf, ch, good); if (not good) or (ch /= ' ') then next; end if; read(inbuf, iaddr); read(inbuf, ch); read(inbuf, ram_data); if (iaddr