blob: e5c2917f36e8765324c56ff8f1f30fb65d81df6b (
plain)
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
|
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity rom_test is
generic (
CONFIG : std_ulogic_vector(0 to 7)
);
port (
clk : in std_ulogic;
reset_n : in std_ulogic;
valid : out std_ulogic
);
end rom_test;
architecture struct of rom_test is
type entry_t is record
value : unsigned(7 downto 0);
valid : std_ulogic;
end record;
type rom_t is array(natural range<>) of entry_t;
function generate_rom(input : std_ulogic_vector) return rom_t is
variable ret : rom_t(0 to input'length-1);
begin
for i in input'range loop
ret(i).valid := input(i);
if input(i) = '1' then
ret(i).value := to_unsigned(i, 8);
end if;
end loop;
return ret;
end function;
constant ROM : rom_t := generate_rom(CONFIG);
signal index : natural range 0 to ROM'length-1;
signal entry : entry_t;
begin
process(clk, reset_n)
begin
if reset_n = '0' then
index <= 0;
elsif rising_edge(clk) then
if index = ROM'length-1 then
index <= 0;
else
index <= index + 1;
end if;
end if;
end process;
entry <= ROM(index);
valid <= entry.valid;
end architecture;
|