OpenCores
URL https://opencores.org/ocsvn/riscompatible/riscompatible/trunk

Subversion Repositories riscompatible

[/] [riscompatible/] [trunk/] [rtl/] [memory.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 borin
-------------------------------------------------------------------------------------------------------------------
2
library ieee;
3
use ieee.std_logic_1164.all;
4
use ieee.numeric_std.all;
5
use work.riscompatible_package.all;
6
-- synopsys translate_off;
7
use std.textio.all;
8
use ieee.std_logic_textio.all;
9
-- synopsys translate_on;
10
-------------------------------------------------------------------------------------------------------------------
11
entity Memory is
12
    generic
13
    (
14
-- synopsys translate_off;
15
        FileName    : String:="dummie.txt";
16
-- synopsys translate_on;        
17
        NumBitsAddr : natural:=4;
18
        DataWidth   : natural:=32
19
    );
20
    port
21
    (
22
        Clk_I        : in std_logic;
23
        Enable_I     : in std_logic;
24
        Write_I      : in std_logic;
25
        Address_I    : in std_logic_vector(NumBitsAddr-1 downto 0);
26
        InputData_I  : in std_logic_vector(DataWidth-1 downto 0);
27
        OutputData_O : out std_logic_vector(DataWidth-1 downto 0)
28
    );
29
end Memory;
30
-------------------------------------------------------------------------------------------------------------------
31
architecture behavioral of Memory is
32
-- synopsys translate_off;
33
    file arq_in_0 : TEXT open READ_MODE is FileName;
34
-- synopsys translate_on;
35
    type TMemory is array (natural range <> ) of TRiscoWord;
36
    signal Memory : TMemory (2**NumBitsAddr-1 downto 0) := (others => (others=>'Z'));
37
begin
38
 
39
process (Clk_I,Address_I)
40
-- synopsys translate_off;
41
    variable file_line : LINE := NULL;
42
    variable dvalue    : std_logic_vector(31 downto 0);
43
    variable counter,i   : integer:=0;
44
-- synopsys translate_on;
45
begin
46
    if Clk_I'event and Clk_I = '1' then
47
        if (Enable_I = '1') then
48
            if (Write_I = '1') then
49
                Memory(to_integer(unsigned(Address_I))) <= InputData_I;
50
            end if;
51
-- synopsys translate_off;
52
        else
53
            while not endfile(arq_in_0) loop
54
                readline(arq_in_0, file_line); --read line of file
55
                Hread(file_line,dvalue);       --extract value from line
56
                Memory(counter)<=dvalue;
57
                counter:=counter+1;
58
            end loop;
59
-- synopsys translate_on;
60
        end if;
61
        OutputData_O <= Memory(to_integer(unsigned(Address_I)));
62
    end if;
63
end process;
64
 
65
end behavioral;
66
-------------------------------------------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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