File: rom_test.vhdl

package info (click to toggle)
ghdl 5.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,000 kB
  • sloc: ada: 309,826; vhdl: 209,727; ansic: 31,072; python: 19,213; sh: 14,214; cpp: 2,345; makefile: 1,542; pascal: 585; asm: 45; exp: 40; fortran: 33
file content (58 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download | duplicates (2)
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;