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

Subversion Repositories igor

[/] [igor/] [trunk/] [processor/] [pl/] [rrwmem.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 atypic
library ieee;
2
 
3
use ieee.std_logic_1164.all;
4
use ieee.std_logic_unsigned.all;
5
use ieee.numeric_std.all;
6
use std.textio.all;
7
 
8
entity rrwmem is
9
    generic (
10
    memsize, addr_width, data_width : integer;
11
    initfile : string);
12
 
13
        port (
14
                clk : in std_logic;
15
                we : in std_logic;
16
                a : in std_logic_vector(addr_width - 1 downto 0);
17
                b : in std_logic_vector(addr_width - 1 downto 0);
18
        c : in std_logic_vector(addr_width - 1 downto 0);
19
                dia : in std_logic_vector(data_width - 1 downto 0);
20
                doa : out std_logic_vector(data_width - 1 downto 0);
21
                dob : out  std_logic_vector(data_width - 1 downto 0)
22
        );
23
end entity;
24
 
25
architecture behav of rrwmem is
26
        type ram_type is array (0 to memsize - 1) of bit_vector(data_width - 1
27
        downto 0);
28
 
29
        signal read_a : std_logic_vector(addr_width - 1 downto 0);
30
        signal read_b : std_logic_vector(addr_width - 1 downto 0);
31
 
32
 
33
        impure function init_ram(filename : in string) return ram_type is
34
        file ramfile : text is in filename;
35
        variable li : line;
36
        variable RAM : ram_type;
37
        begin
38
                for i in ram_type'range loop
39
                        readline(ramfile, li);
40
                        read(li, RAM(i));
41
                end loop;
42
        return RAM;
43
        end function;
44
 
45
signal RAM : ram_type := init_ram(initfile);
46
begin
47
        process(clk)
48
                begin
49
                        if rising_edge(clk) then
50
                                if (we = '1') then
51
                                        RAM(to_integer(unsigned(c))) <= to_bitvector(dia);
52
                                end if;
53
                                read_a <= a;
54
                                read_b <= b;
55
                        end if;
56
        end process;
57
        doa <= to_stdlogicvector(RAM(to_integer(unsigned(read_a))));
58
        dob <= to_stdlogicvector(RAM(to_integer(unsigned(read_b))));
59
end behav;
60
 
61
 
62
 
63
 

powered by: WebSVN 2.1.0

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