1 |
31 |
wfjm |
-- $Id: ram_2swsr_rfirst_gen.vhd 686 2015-06-04 21:08:08Z mueller $
|
2 |
|
|
--
|
3 |
|
|
-- Copyright 2006-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
4 |
|
|
--
|
5 |
|
|
-- This program is free software; you may redistribute and/or modify it under
|
6 |
|
|
-- the terms of the GNU General Public License as published by the Free
|
7 |
|
|
-- Software Foundation, either version 2, or at your option any later version.
|
8 |
|
|
--
|
9 |
|
|
-- This program is distributed in the hope that it will be useful, but
|
10 |
|
|
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
11 |
|
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
12 |
|
|
-- for complete details.
|
13 |
|
|
--
|
14 |
|
|
------------------------------------------------------------------------------
|
15 |
|
|
-- Module Name: ram_2swsr_rfirst_gen - syn
|
16 |
|
|
-- Description: Dual-Port RAM with with two synchronous read/write ports
|
17 |
|
|
-- and 'read-before-write' semantics (as block RAM).
|
18 |
|
|
-- The code is inspired by Xilinx example rams_16.vhd. The
|
19 |
|
|
-- 'ram_style' attribute is set to 'block', this will
|
20 |
|
|
-- force in XST a synthesis as block RAM.
|
21 |
|
|
--
|
22 |
|
|
-- Dependencies: -
|
23 |
|
|
-- Test bench: -
|
24 |
|
|
-- Target Devices: generic Spartan, Virtex
|
25 |
|
|
-- Tool versions: xst 8.2-14.7; ghdl 0.18-0.31
|
26 |
|
|
-- Revision History:
|
27 |
|
|
-- Date Rev Version Comment
|
28 |
|
|
-- 2011-11-08 422 1.0.4 now numeric_std clean
|
29 |
|
|
-- 2010-06-03 299 1.0.3 use sv_ prefix for shared variables
|
30 |
|
|
-- 2008-03-08 123 1.0.2 use std_..._arith, not _unsigned; use unsigned();
|
31 |
|
|
-- now initialize DO to all '0' at start
|
32 |
|
|
-- 2008-03-02 122 1.0.1 change generic default for BRAM models
|
33 |
|
|
-- 2007-06-03 45 1.0 Initial version
|
34 |
|
|
------------------------------------------------------------------------------
|
35 |
|
|
|
36 |
|
|
library ieee;
|
37 |
|
|
use ieee.std_logic_1164.all;
|
38 |
|
|
use ieee.numeric_std.all;
|
39 |
|
|
|
40 |
|
|
use work.slvtypes.all;
|
41 |
|
|
|
42 |
|
|
entity ram_2swsr_rfirst_gen is -- RAM, 2 sync r/w ports, read first
|
43 |
|
|
generic (
|
44 |
|
|
AWIDTH : positive := 11; -- address port width
|
45 |
|
|
DWIDTH : positive := 9); -- data port width
|
46 |
|
|
port(
|
47 |
|
|
CLKA : in slbit; -- clock port A
|
48 |
|
|
CLKB : in slbit; -- clock port B
|
49 |
|
|
ENA : in slbit; -- enable port A
|
50 |
|
|
ENB : in slbit; -- enable port B
|
51 |
|
|
WEA : in slbit; -- write enable port A
|
52 |
|
|
WEB : in slbit; -- write enable port B
|
53 |
|
|
ADDRA : in slv(AWIDTH-1 downto 0); -- address port A
|
54 |
|
|
ADDRB : in slv(AWIDTH-1 downto 0); -- address port B
|
55 |
|
|
DIA : in slv(DWIDTH-1 downto 0); -- data in port A
|
56 |
|
|
DIB : in slv(DWIDTH-1 downto 0); -- data in port B
|
57 |
|
|
DOA : out slv(DWIDTH-1 downto 0); -- data out port A
|
58 |
|
|
DOB : out slv(DWIDTH-1 downto 0) -- data out port B
|
59 |
|
|
);
|
60 |
|
|
end ram_2swsr_rfirst_gen;
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
architecture syn of ram_2swsr_rfirst_gen is
|
64 |
|
|
constant memsize : positive := 2**AWIDTH;
|
65 |
|
|
constant datzero : slv(DWIDTH-1 downto 0) := (others=>'0');
|
66 |
|
|
type ram_type is array (0 to memsize-1) of slv(DWIDTH-1 downto 0);
|
67 |
|
|
shared variable sv_ram : ram_type := (others=>datzero);
|
68 |
|
|
|
69 |
|
|
attribute ram_style : string;
|
70 |
|
|
attribute ram_style of sv_ram : variable is "block";
|
71 |
|
|
|
72 |
|
|
signal R_DOA : slv(DWIDTH-1 downto 0) := datzero;
|
73 |
|
|
signal R_DOB : slv(DWIDTH-1 downto 0) := datzero;
|
74 |
|
|
|
75 |
|
|
begin
|
76 |
|
|
|
77 |
|
|
proc_clka: process (CLKA)
|
78 |
|
|
begin
|
79 |
|
|
if rising_edge(CLKA) then
|
80 |
|
|
if ENA = '1' then
|
81 |
|
|
R_DOA <= sv_ram(to_integer(unsigned(ADDRA)));
|
82 |
|
|
if WEA = '1' then
|
83 |
|
|
sv_ram(to_integer(unsigned(ADDRA))) := DIA;
|
84 |
|
|
end if;
|
85 |
|
|
end if;
|
86 |
|
|
end if;
|
87 |
|
|
end process proc_clka;
|
88 |
|
|
|
89 |
|
|
proc_clkb: process (CLKB)
|
90 |
|
|
begin
|
91 |
|
|
if rising_edge(CLKB) then
|
92 |
|
|
if ENB = '1' then
|
93 |
|
|
R_DOB <= sv_ram(to_integer(unsigned(ADDRB)));
|
94 |
|
|
if WEB = '1' then
|
95 |
|
|
sv_ram(to_integer(unsigned(ADDRB))) := DIB;
|
96 |
|
|
end if;
|
97 |
|
|
end if;
|
98 |
|
|
end if;
|
99 |
|
|
end process proc_clkb;
|
100 |
|
|
|
101 |
|
|
DOA <= R_DOA;
|
102 |
|
|
DOB <= R_DOB;
|
103 |
|
|
|
104 |
|
|
end syn;
|