1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| library ieee;
use IEEE.STD_LOGIC_1164.ALL;
use std.textio.all;
use ieee.numeric_std.all;
use ieee.std_logic_textio.all;
use ieee.std_logic_unsigned.all;
entity ROM_act_func is
generic(
C_ROM_DEPTH: integer;
C_ROM_WIDTH: integer
);
port(
--addr_ROM : in std_logic_vector(((2**C_ROM_DEPTH)-1) downto 0); -- Write address bus, width determined from RAM_DEPTH
addr_ROM_activate : in std_logic_vector(C_ROM_DEPTH downto 0);
clk : in std_logic; -- Clock
enable : in std_logic; --Enable
rst : in std_logic;
dout : out std_logic_vector(C_ROM_WIDTH-1 downto 0)
);
end ROM_act_func;
architecture Behavioral of ROM_act_func is
constant C_INIT_FILE : string := "actfunc.mif";
type rom_type is array (C_ROM_DEPTH downto 0) of std_logic_vector(C_ROM_WIDTH-1 downto 0);
signal rom_data : std_logic_vector(C_ROM_WIDTH-1 downto 0) ;
impure function initromfromfile (romfilename : in string) return rom_type is
file romfile : text is in romfilename;
variable romfileline : line;
variable rom_name : rom_type;
variable bitvec : bit_vector(C_ROM_WIDTH-1 downto 0);
begin
for i in 0 to (rom_type'length-1) loop
readline(romfile, romfileline);
read(romfileline, bitvec);
rom_name(i) := to_stdlogicvector(bitvec);
end loop;
return rom_name;
end function;
impure function init_from_file_or_zeroes(romfile : string) return rom_type is
begin
if romfile = C_INIT_FILE then
return InitRomFromFile(C_INIT_FILE);
else
return (others => (others => '0'));
end if;
end;
signal rom_name : rom_type := init_from_file_or_zeroes(C_INIT_FILE);
signal signal_addr : std_logic_vector(((2**C_ROM_DEPTH)-1) downto 0):= (others=>'0') ;
begin
process(clk, rst)
begin
if (rst = '1') then
rom_data <= (others =>'0');
elsif rising_edge(clk) then
if (enable = '1') then
signal_addr <= addr_ROM_activate;
rom_data <= rom_name(to_integer(unsigned(signal_addr)));
end if;
end if;
end process;
dout<=rom_data;
end Behavioral; |
Partager