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

Subversion Repositories tcp_ip_core_w_dhcp

[/] [tcp_ip_core_w_dhcp/] [trunk/] [TDP_RAM.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 craighaywo
----------------------------------------------------------------------------------
2
-- Company: SDO
3
-- Engineer: CW
4
-- 
5
-- Create Date:    13:26:28 09/05/2013 
6
-- Design Name: 
7
-- Module Name:    TDport_RAM - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
use ieee.numeric_std.all;
23
 
24
library std;
25
use std.textio.all;
26
 
27
library UNISIM;
28
use UNISIM.VComponents.all;
29
 
30
entity TDP_RAM is
31
        Generic (G_DATA_A_SIZE  :natural :=32;
32
                                G_ADDR_A_SIZE   :natural :=9;
33
                                G_RELATION              :natural :=3;
34
                                G_INIT_ZERO             :boolean := true;
35
                                G_INIT_FILE             :string :="");--log2(SIZE_A/SIZE_B)
36
   Port ( CLK_A_IN      : in  STD_LOGIC;
37
          WE_A_IN       : in  STD_LOGIC;
38
          ADDR_A_IN     : in  STD_LOGIC_VECTOR (G_ADDR_A_SIZE-1 downto 0);
39
          DATA_A_IN     : in  STD_LOGIC_VECTOR (G_DATA_A_SIZE-1 downto 0);
40
          DATA_A_OUT    : out  STD_LOGIC_VECTOR (G_DATA_A_SIZE-1 downto 0);
41
          CLK_B_IN      : in  STD_LOGIC;
42
                         WE_B_IN        : in  STD_LOGIC;
43
          ADDR_B_IN     : in  STD_LOGIC_VECTOR (G_ADDR_A_SIZE+G_RELATION-1 downto 0);
44
          DATA_B_IN     : in  STD_LOGIC_VECTOR (G_DATA_A_SIZE/(2**G_RELATION)-1 downto 0);
45
          DATA_B_OUT : out STD_LOGIC_VECTOR (G_DATA_A_SIZE/(2**G_RELATION)-1 downto 0));
46
 
47
        attribute ram_style : string;
48
        attribute ram_style of TDP_RAM : entity is "block";
49
 
50
end TDP_RAM;
51
 
52
architecture Behavioral of TDP_RAM is
53
 
54
subtype slv   is std_logic_vector;
55
 
56
type RAM_TYPE is array(2**(G_ADDR_A_SIZE+G_RELATION)-1 downto 0) of std_logic_vector(G_DATA_A_SIZE/(2**G_RELATION)-1 downto 0);
57
 
58
impure function InitRamFromFile (InitZero : in boolean; RamFileName : in string) return RAM_TYPE is
59
        FILE RamFile : text;
60
        variable RamFileLine : line;
61
        variable RAM : RAM_TYPE;
62
        variable tmp : bit_vector(G_DATA_A_SIZE/(2**G_RELATION)-1 downto 0);
63
begin
64
        if InitZero = true then
65
                for I in 0 to (2**(G_ADDR_A_SIZE+G_RELATION))-1 loop
66
                        RAM(I) := (others => '0');
67
                end loop;
68
                return RAM;
69
        else
70
                file_open(RamFile, RamFileName, READ_MODE);
71
                for I in 0 to (2**(G_ADDR_A_SIZE+G_RELATION))-1 loop
72
                        readline(RamFile, RamFileLine);
73
                        read(RamFileLine, tmp);
74
                        RAM(I) := To_StdLogicVector(tmp);
75
                end loop;
76
                return RAM;
77
        end if;
78
end InitRamFromFile;
79
 
80
shared variable memory : RAM_TYPE  := InitRamFromFile(G_INIT_ZERO, G_INIT_FILE);
81
 
82
begin
83
 
84
process(CLK_A_IN)  begin
85
        if rising_edge(CLK_A_IN)  then
86
                if G_RELATION = 0 then
87
                        if WE_A_IN = '1'  then
88
                                memory(to_integer(unsigned(ADDR_A_IN))) := DATA_A_IN;
89
                        end if;
90
                        DATA_A_OUT <= memory(to_integer(unsigned(ADDR_A_IN)));
91
                else
92
                        for I in 0 to 2**G_RELATION-1 loop
93
                                DATA_A_OUT(G_DATA_A_SIZE/(2**G_RELATION)*(I+1)-1 downto G_DATA_A_SIZE/(2**G_RELATION)*(I)) <= memory(to_integer(unsigned(ADDR_A_IN) & to_unsigned(I,G_RELATION)));
94
                                if WE_A_IN = '1'  then
95
                                        memory(to_integer(unsigned(ADDR_A_IN) & to_unsigned(I,G_RELATION))) := DATA_A_IN(G_DATA_A_SIZE/(2**G_RELATION)*(I+1)-1 downto G_DATA_A_SIZE/(2**G_RELATION)*(I));
96
                                end if;
97
                        end loop;
98
                end if;
99
        end if;
100
end process;
101
 
102
process(CLK_B_IN)  begin
103
        if rising_edge(CLK_B_IN)  then
104
                if WE_B_IN = '1'  then
105
                        memory(to_integer(unsigned(ADDR_B_IN))) := DATA_B_IN;
106
                end if;
107
                DATA_B_OUT <= memory(to_integer(unsigned(ADDR_B_IN)));
108
        end if;
109
end process;
110
 
111
end Behavioral;
112
 

powered by: WebSVN 2.1.0

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