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

Subversion Repositories ourisc

[/] [ourisc/] [trunk/] [rtl/] [common/] [ram.vhd] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 joaocarlos
----------------------------------------------------------------------------------
2
-------------------------- Componente memoria ------------------------------------
3
----------------------------------------------------------------------------------
4
-- Entrada de configuracao:                                                                                                             --
5
--  dim - dimensao da memoria (numero de palavra de 16 bits)                                    --
6
--                                                                                                                                                              --
7
-- Portos de entrada de controlo de leitura e escrita nos ficheiros:                    --
8
--      read_file  - carrega a memoria com os dados presentes no ficheiro "rom.out"     --
9
--  write_file - carrega no ficheiro "data.out" os dados presentes na memoria   --
10
--                                                                                                                                                              --
11
-- Portos de acesso a memoria:                                                                                                  --
12
--   we         - enable de escrita                                                                                                     --
13
--   clk    - sinal de relogio                                                                                                  --
14
--   address - endereo de acesso a memoria                                                                              --
15
--       data   - entrada de daos para escrita                                                                          --
16
--   q      - saida de dados para leitura                                                                           --
17
----------------------------------------------------------------------------------
18
--           Componente memoria desenvolvida para a disciplina de                           --
19
--                 Arquitecturas Avanadas de Computadores                                               --
20
----------------------------------------------------------------------------------
21
-- Non synthetizable                                                                                                                    --
22
----------------------------------------------------------------------------------
23
 
24
library ieee;
25
use ieee.std_logic_1164.all;
26
use ieee.std_logic_unsigned.all;
27
use std.textio.all;
28
use std.textio;
29
use ieee.stc_logic_textio.all;
30
 
31
entity ram is
32
        generic (dim : integer := 1024) ;
33
        port (
34
                -- control bits for file manipulation ---------
35
                read_file : in std_logic;
36
                write_file : in std_logic;
37
                ----------------------------------------------- 
38
                we : in std_logic;
39
                clk: in std_logic;
40
                address : in std_logic_vector(15 downto 0);
41
                data : in std_logic_vector (15 downto 0);
42
                q : out std_logic_vector (15 downto 0)
43
        );
44
 
45
end ram;
46
 
47
architecture behavioral of ram is
48
        type ram_mem_type is array (dim-1 downto 0) of std_logic_vector (15 downto 0);
49
        signal ram_mem, ram_mem2 : ram_mem_type;
50
begin
51
 
52
        ------------------------------------------------------------------------------
53
        -- memory access -------------------------------------------------------------
54
        ------------------------------------------------------------------------------
55
        process (clk)
56
                variable addr_wr_temp: integer;
57
        begin
58
                if((clk'event) and (clk='1')) then
59
                        if (read_file = '1') then
60
                                ram_mem <= ram_mem2;
61
                        elsif ((we = '1') and (not (read_file = '1'))) then
62
                                addr_wr_temp := conv_integer(address);
63
                                assert(dim > addr_wr_temp)
64
                                report " Tentou aceder a uma posicao de memoria nao defenida!"
65
                        severity ERROR; --FAILURE; --WARNING;
66
                                ram_mem(addr_wr_temp) <= data;
67
                        end if;
68
                end if;
69
        end process;
70
 
71
        q <= ram_mem(conv_integer(address));
72
 
73
        ------------------------------------------------------------------------------
74
        -- when read_file is '1' the file rom.out is writen in memory ----------------
75
        ------------------------------------------------------------------------------
76
        read : process(read_file)
77
                file in_file : TEXT  is in "/home/joaocarlos/workspace/xilinx-ise/uRISC/MEM/rom.out";
78
                variable data_temp : std_logic_vector(15 downto 0);
79
                variable in_line: LINE;
80
                variable index :integer;
81
        begin
82
                if((read_file'event) and (read_file='1')) then
83
                        index := 0;
84
                        while NOT(endfile(in_file)) loop
85
                                readline(in_file,in_line);
86
                                hread(in_line, data_temp)
87
                                ram_mem2(index) <= data_tem
88
                                index := index + 1
89
                        end loop;
90
                end if;
91
 
92
        end process read;
93
 
94
        --------------------------------------------------------------------------------
95
        -- when write_file is '1' the memory is writen in file data.out ----------------
96
        --------------------------------------------------------------------------------
97
        write : process( write_file)
98
                file out_file : TEXT is out "/home/joaocarlos/workspace/xilinx-ise/uRISC/MEM/data.out";
99
                variable out_line : LINE;
100
                variable index :integer;
101
        begin
102
                if((write_file'event) and (write_file='1')) then
103
                        index := 0;
104
                        while (index < dim) loop
105
                --              write(out_line,index);
106
                --              write(out_line,":");
107
                                hwrite(out_line,ram_mem(index));
108
                                writeline(out_file,out_line);
109
                                index := index + 1;
110
                        end loop;
111
                end if;
112
        end process write;
113
 
114
end behavioral;
115
 

powered by: WebSVN 2.1.0

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