OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [hf-risc/] [sim/] [boot_ram.vhd] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 serginhofr
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
use ieee.std_logic_textio.all;
6
use std.textio.all;
7
 
8
entity boot_ram is
9
        generic(memory_file : string := "boot.txt";
10
                data_width: integer := 8;                       -- data width (fixed)
11
                address_width: integer := 12;                   -- address width
12
                bank: integer := 0);                                     -- memory bank (0,1,2,3)
13
        port(
14
        clk : in std_logic;                                     --clock
15
        addr : in std_logic_vector(address_width - 1 downto 2);         --address bus
16
        cs_n : in std_logic;                                    --chip select
17
        we_n : in std_logic;                                    --write enable
18
        data_i: in std_logic_vector(data_width - 1 downto 0);    --write data bus
19
        data_o: out std_logic_vector(data_width - 1 downto 0)    --read data bus
20
        );
21
end boot_ram;
22
 
23
architecture memory of boot_ram is
24
 
25
type ram is array(2 ** address_width - 1 downto 0) of std_logic_vector(data_width - 1 downto 0);
26
signal ram1 : ram := (others => (others => '0'));
27
 
28
begin
29
        process(clk)
30
                variable data : std_logic_vector(data_width*4 -1 downto 0);
31
                variable index : natural := 0;
32
                file load_file : text open read_mode is "boot.txt";
33
                variable hex_file_line : line;
34
        begin
35
                --Load in the ram executable image
36
                if index = 0 then
37
                        while not endfile(load_file) loop
38
                                readline(load_file, hex_file_line);
39
                                hread(hex_file_line, data);
40
                                ram1(conv_integer(index)) <= data(((bank+1)*data_width)-1 downto bank*data_width);
41
                                index := index + 1;
42
                        end loop;
43
                end if;
44
 
45
                if (clk'event and clk = '1') then
46
                        if(cs_n = '0') then
47
                                if(we_n = '0') then
48
                                        ram1(conv_integer(addr(address_width -1 downto 2))) <= data_i;
49
                                else
50
                                        data_o <= ram1(conv_integer(addr(address_width -1 downto 2)));
51
                                end if;
52
                        end if;
53
                end if;
54
 
55
        end process;
56
 
57
end memory;
58
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.