OSDN Git Service

sdram test >> failed...
[motonesfpga/motonesfpga.git] / tools / qt_proj_test5 / prg_rom.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.conv_integer;
4 use ieee.std_logic_arith.conv_std_logic_vector;
5 use std.textio.all;
6 use work.motonesfpga_common.all;
7
8 --syncronous rom
9 entity prg_rom is 
10     generic (abus_size : integer := 15; dbus_size : integer := 8);
11     port (
12             clk             : in std_logic;
13             ce_n            : in std_logic;     --active low.
14             addr            : in std_logic_vector (abus_size - 1 downto 0);
15             data            : out std_logic_vector (dbus_size - 1 downto 0)
16         );
17 end prg_rom;
18
19 architecture rtl of prg_rom is
20
21 --32k ROM
22 subtype rom_data is std_logic_vector (dbus_size -1 downto 0);
23 type rom_array is array (0 to 2**abus_size - 1) of rom_data;
24
25 --not used...
26 constant ROM_TACE : time := 100 ns;      --output enable access time
27 constant ROM_TOH : time := 10 ns;      --output hold time
28
29 --function is called only once at the array initialize.
30 function rom_fill return rom_array is 
31     type binary_file is file of character;
32     FILE nes_file : binary_file OPEN read_mode IS "rom-file.nes" ;
33     variable read_data : character;
34     variable i : integer;
35     variable ret : rom_array;
36     begin
37         --skip first 16 bit data(NES cardridge header part.)
38         for i in 0 to 15 loop
39             read(nes_file, read_data);
40         end loop;
41
42         for i in ret'range loop
43             read(nes_file, read_data);
44             ret(i) :=
45                 conv_std_logic_vector(character'pos(read_data), 8);
46         end loop;
47         d_print("file load success.");
48         return ret;
49     end rom_fill;
50
51 function init_rom
52     return rom_array is 
53     variable tmp : rom_array := (others => (others => '0'));
54     use ieee.numeric_std.to_unsigned;
55 begin 
56     for addr_pos in 0 to 2**abus_size - 1 loop 
57         -- Initialize each address with the address itself
58         tmp(addr_pos) := std_logic_vector(to_unsigned(addr_pos, dbus_size));
59     end loop;
60     return tmp;
61 end init_rom;
62
63 -- Declare the ROM signal and specify a default value.  Quartus II
64 -- will create a memory initialization file (.mif) based on the 
65 -- default value.
66
67 --for GHDL environment
68 --itinialize with the rom_fill function.
69 --signal p_rom : rom_array := rom_fill;
70
71 --for Quartus II environment
72 signal p_rom : rom_array;
73 attribute ram_init_file : string;
74 attribute ram_init_file of p_rom : signal is "sample1-prg.hex";
75
76 begin
77
78     p : process (clk)
79     begin
80     if (rising_edge(clk)) then
81         if (ce_n = '0') then
82             data <= p_rom(conv_integer(addr));
83         else
84             data <= (others => 'Z');
85         end if;
86     end if;
87     end process;
88 end rtl;
89