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 6

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 6 ring0_mipt
attribute syn_ramstyle of ram: signal is "no_rw_check";
53 2 ring0_mipt
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 6 ring0_mipt
                                        if is_x(addra_i) then
80
                                                da_o<=(others=>'X');
81
                                        else
82
                                                da_o<=ram(to_integer(unsigned(addra_i)));
83
                                        end if;
84 2 ring0_mipt
                                end if;
85
                        end if;
86
                end if;
87
        end process;
88
end generate;
89
 
90
port_a_write_first_gen: if MODE="WR_FIRST" generate
91
        process (clka_i) is
92
        begin
93
                if rising_edge(clka_i) then
94
                        if cea_i='1' then
95
                                if wea_i='1' then
96
                                        ram(to_integer(unsigned(addra_i)))<=da_i;
97
                                        da_o<=da_i;
98
                                else
99 6 ring0_mipt
                                        if is_x(addra_i) then
100
                                                da_o<=(others=>'X');
101
                                        else
102
                                                da_o<=ram(to_integer(unsigned(addra_i)));
103
                                        end if;
104 2 ring0_mipt
                                end if;
105
                        end if;
106
                end if;
107
        end process;
108
end generate;
109
 
110
port_a_read_first_gen: if MODE="RD_FIRST" generate
111
        process (clka_i) is
112
        begin
113
                if rising_edge(clka_i) then
114
                        if cea_i='1' then
115
                                if wea_i='1' then
116
                                        ram(to_integer(unsigned(addra_i)))<=da_i;
117
                                end if;
118 6 ring0_mipt
                                if is_x(addra_i) then
119
                                        da_o<=(others=>'X');
120
                                else
121
                                        da_o<=ram(to_integer(unsigned(addra_i)));
122
                                end if;
123 2 ring0_mipt
                        end if;
124
                end if;
125
        end process;
126
end generate;
127
 
128
port_a_no_change_gen: if MODE="NOCHANGE" generate
129
        process (clka_i) is
130
        begin
131
                if rising_edge(clka_i) then
132
                        if cea_i='1' then
133
                                if wea_i='1' then
134
                                        ram(to_integer(unsigned(addra_i)))<=da_i;
135
                                else
136 6 ring0_mipt
                                        if is_x(addra_i) then
137
                                                da_o<=(others=>'X');
138
                                        else
139
                                                da_o<=ram(to_integer(unsigned(addra_i)));
140
                                        end if;
141 2 ring0_mipt
                                end if;
142
                        end if;
143
                end if;
144
        end process;
145
end generate;
146
 
147
-- Port B (read only)
148
 
149
process (clkb_i) is
150
begin
151
        if rising_edge(clkb_i) then
152
                if ceb_i='1' then
153 6 ring0_mipt
                        if is_x(addrb_i) then
154
                                db_o<=(others=>'X');
155
                        else
156
                                db_o<=ram(to_integer(unsigned(addrb_i)));
157
                        end if;
158 2 ring0_mipt
                end if;
159
        end if;
160
end process;
161
 
162
end architecture;

powered by: WebSVN 2.1.0

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