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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [verify/] [lxp32/] [src/] [platform/] [generic_dpram.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ring0_mipt
---------------------------------------------------------------------
2
-- Generic FPGA memory block
3
--
4
-- Copyright (c) 2015 by Alex I. Kuznetsov
5
--
6
-- Portable description of a dual-port memory block with one write
7
-- port.
8
--
9
-- Parameters:
10
--     * DATA_WIDTH:  data port width
11
--     * ADDR_WIDTH:  address port width
12
--     * SIZE:        memory size
13
--     * MODE:        read/write synchronization mode for port A
14
--                      DONTCARE: choose the most efficient design
15
--                      WR_FIRST: feed written value to the output
16
--                      RD_FIRST: read old value 
17
--                      NOCHANGE: don't change output during write
18
---------------------------------------------------------------------
19
 
20
library ieee;
21
use ieee.std_logic_1164.all;
22
use ieee.numeric_std.all;
23
 
24
entity generic_dpram is
25
        generic(
26
                DATA_WIDTH: integer;
27
                ADDR_WIDTH: integer;
28
                SIZE: integer;
29
                MODE: string:="DONTCARE"
30
        );
31
        port(
32
                clka_i: in std_logic;
33
                cea_i: in std_logic;
34
                wea_i: in std_logic;
35
                addra_i: in std_logic_vector(ADDR_WIDTH-1 downto 0);
36
                da_i: in std_logic_vector(DATA_WIDTH-1 downto 0);
37
                da_o: out std_logic_vector(DATA_WIDTH-1 downto 0);
38
 
39
                clkb_i: in std_logic;
40
                ceb_i: in std_logic;
41
                addrb_i: in std_logic_vector(ADDR_WIDTH-1 downto 0);
42
                db_o: out std_logic_vector(DATA_WIDTH-1 downto 0)
43
        );
44
end entity;
45
 
46
architecture rtl of generic_dpram is
47
 
48
type ram_type is array(SIZE-1 downto 0) of std_logic_vector(DATA_WIDTH-1 downto 0);
49
signal ram: ram_type;
50
 
51
attribute syn_ramstyle: string;
52
attribute syn_ramstyle of ram: signal is "block_ram,no_rw_check";
53
attribute ram_style: string; -- for Xilinx
54
attribute ram_style of ram: signal is "block";
55
 
56
begin
57
 
58
-- Ensure that generics have valid values
59
 
60
assert SIZE<=2**ADDR_WIDTH
61
        report "SIZE must be less or equal than 2^ADDR_WIDTH"
62
        severity failure;
63
 
64
assert MODE="DONTCARE" or MODE="WR_FIRST" or MODE="RD_FIRST" or MODE="NOCHANGE"
65
        report "Unrecognized MODE value (DONTCARE, WR_FIRST, RD_FIRST or NOCHANGE expected)"
66
        severity failure;
67
 
68
-- Port A (read/write)
69
 
70
port_a_dont_care_gen: if MODE="DONTCARE" generate
71
        process (clka_i) is
72
        begin
73
                if rising_edge(clka_i) then
74
                        if cea_i='1' then
75
                                if wea_i='1' then
76
                                        ram(to_integer(unsigned(addra_i)))<=da_i;
77
                                        da_o<=(others=>'-');
78
                                else
79
                                        da_o<=ram(to_integer(to_01(unsigned(addra_i))));
80
                                end if;
81
                        end if;
82
                end if;
83
        end process;
84
end generate;
85
 
86
port_a_write_first_gen: if MODE="WR_FIRST" generate
87
        process (clka_i) is
88
        begin
89
                if rising_edge(clka_i) then
90
                        if cea_i='1' then
91
                                if wea_i='1' then
92
                                        ram(to_integer(unsigned(addra_i)))<=da_i;
93
                                        da_o<=da_i;
94
                                else
95
                                        da_o<=ram(to_integer(to_01(unsigned(addra_i))));
96
                                end if;
97
                        end if;
98
                end if;
99
        end process;
100
end generate;
101
 
102
port_a_read_first_gen: if MODE="RD_FIRST" generate
103
        process (clka_i) is
104
        begin
105
                if rising_edge(clka_i) then
106
                        if cea_i='1' then
107
                                if wea_i='1' then
108
                                        ram(to_integer(unsigned(addra_i)))<=da_i;
109
                                end if;
110
                                da_o<=ram(to_integer(to_01(unsigned(addra_i))));
111
                        end if;
112
                end if;
113
        end process;
114
end generate;
115
 
116
port_a_no_change_gen: if MODE="NOCHANGE" generate
117
        process (clka_i) is
118
        begin
119
                if rising_edge(clka_i) then
120
                        if cea_i='1' then
121
                                if wea_i='1' then
122
                                        ram(to_integer(unsigned(addra_i)))<=da_i;
123
                                else
124
                                        da_o<=ram(to_integer(to_01(unsigned(addra_i))));
125
                                end if;
126
                        end if;
127
                end if;
128
        end process;
129
end generate;
130
 
131
-- Port B (read only)
132
 
133
process (clkb_i) is
134
begin
135
        if rising_edge(clkb_i) then
136
                if ceb_i='1' then
137
                        db_o<=ram(to_integer(to_01(unsigned(addrb_i))));
138
                end if;
139
        end if;
140
end process;
141
 
142
end architecture;

powered by: WebSVN 2.1.0

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