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

Subversion Repositories fat_32_file_parser

[/] [fat_32_file_parser/] [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_FILE             :string :="");--log2(SIZE_A/SIZE_B)
35
   Port ( CLK_A_IN      : in  STD_LOGIC;
36
          WE_A_IN       : in  STD_LOGIC;
37
          ADDR_A_IN     : in  STD_LOGIC_VECTOR (G_ADDR_A_SIZE-1 downto 0);
38
          DATA_A_IN     : in  STD_LOGIC_VECTOR (G_DATA_A_SIZE-1 downto 0);
39
          DATA_A_OUT    : out  STD_LOGIC_VECTOR (G_DATA_A_SIZE-1 downto 0);
40
          CLK_B_IN      : in  STD_LOGIC;
41
                         WE_B_IN        : in  STD_LOGIC;
42
          ADDR_B_IN     : in  STD_LOGIC_VECTOR (G_ADDR_A_SIZE+G_RELATION-1 downto 0);
43
          DATA_B_IN     : in  STD_LOGIC_VECTOR (G_DATA_A_SIZE/(2**G_RELATION)-1 downto 0);
44
          DATA_B_OUT : out STD_LOGIC_VECTOR (G_DATA_A_SIZE/(2**G_RELATION)-1 downto 0));
45
 
46
        attribute ram_style : string;
47
        attribute ram_style of TDP_RAM : entity is "block";
48
 
49
end TDP_RAM;
50
 
51
architecture Behavioral of TDP_RAM is
52
 
53
subtype slv   is std_logic_vector;
54
 
55
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);
56
 
57
impure function InitRamFromFile (RamFileName : in string) return RAM_TYPE is
58
        FILE RamFile : text;
59
        variable RamFileLine : line;
60
        variable RAM : RAM_TYPE;
61
        variable tmp : bit_vector(G_DATA_A_SIZE/(2**G_RELATION)-1 downto 0);
62
begin
63
        if RamFileName = "" then
64
                for I in 0 to (2**(G_ADDR_A_SIZE+G_RELATION))-1 loop
65
                        RAM(I) := (others => '0');
66
                end loop;
67
                return RAM;
68
        else
69
                file_open(RamFile, RamFileName, READ_MODE);
70
                for I in 0 to (2**(G_ADDR_A_SIZE+G_RELATION))-1 loop
71
                        readline(RamFile, RamFileLine);
72
                        read(RamFileLine, tmp);
73
                        RAM(I) := To_StdLogicVector(tmp);
74
                end loop;
75
                return RAM;
76
        end if;
77
end InitRamFromFile;
78
 
79
shared variable memory : RAM_TYPE  := InitRamFromFile(G_INIT_FILE);
80
 
81
begin
82
 
83
process(CLK_A_IN)  begin
84
        if rising_edge(CLK_A_IN)  then
85
                if G_RELATION = 0 then
86
                        if WE_A_IN = '1'  then
87
                                memory(to_integer(unsigned(ADDR_A_IN))) := DATA_A_IN;
88
                        end if;
89
                        DATA_A_OUT <= memory(to_integer(unsigned(ADDR_A_IN)));
90
                else
91
                        for I in 0 to 2**G_RELATION-1 loop
92
                                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)));
93
                                if WE_A_IN = '1'  then
94
                                        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));
95
                                end if;
96
                        end loop;
97
                end if;
98
        end if;
99
end process;
100
 
101
process(CLK_B_IN)  begin
102
        if rising_edge(CLK_B_IN)  then
103
                if WE_B_IN = '1'  then
104
                        memory(to_integer(unsigned(ADDR_B_IN))) := DATA_B_IN;
105
                end if;
106
                DATA_B_OUT <= memory(to_integer(unsigned(ADDR_B_IN)));
107
        end if;
108
end process;
109
 
110
end Behavioral;
111
 

powered by: WebSVN 2.1.0

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