2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
9 --------------------------------------------------------------------------------
12 -- It's based on behavioral description of full synchronous RAM, so it should be
13 -- mapped into FPGA BRAM. Interface is Wishbone like. Data and address bus width
16 -- Table is initialized from file specified by 'init_file' parameter. This is a
17 -- text file which contains one value per line. Values are typed in binary
18 -- format. Sample file 'sin.lut' together with Matlab generation function
19 -- 'gen_lut_sin.m' is enclosed.
20 --------------------------------------------------------------------------------
24 data_width : integer := 10;
25 addr_width : integer := 9;
26 init_file : string := "reci_tab_a.lut");
28 ack_o : out std_logic;
29 addr_i : in std_logic_vector (addr_width-1 downto 0);
31 data_o : out std_logic_vector (data_width-1 downto 0);
36 --------------------------------------------------------------------------------
38 architecture behavioral of rom_table is
40 constant table_size : integer := 2**addr_width;
42 type rom_table_t is array (0 to table_size-1) of bit_vector (data_width-1 downto 0);
44 impure function init_table_from_file (file_name : string) return rom_table_t is
45 file table_file : text open read_mode is file_name;
46 variable file_line : line;
47 variable table : rom_table_t;
49 for i in rom_table_t'range loop
51 if (endfile(table_file)) and (i /= 0) then
52 -- Repeat file data when not enough data to fill
53 file_close(table_file);
54 file_open(table_file, file_name, read_mode);
56 readline(table_file, file_line);
57 exit when file_line'length /= 0;
60 read(file_line, table(i));
65 end function init_table_from_file;
67 constant ram : rom_table_t := init_table_from_file(init_file);
69 signal stb_delayed : std_logic;
71 --------------------------------------------------------------------------------
75 mem_context : process (clk_i, addr_i) is
76 variable address : integer;
78 address := conv_integer(addr_i);
80 if rising_edge(clk_i) then
84 data_o <= to_stdLogicVector(ram(address));
91 end architecture behavioral;