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

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [trunk/] [rtl/] [vhdl/] [ram/] [dpram_asym.vhd] - Blame information for rev 67

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

Line No. Rev Author Line
1 66 JonasDC
----------------------------------------------------------------------  
2
----  dpram_asym                                                  ---- 
3
----                                                              ---- 
4
----  This file is part of the                                    ----
5
----    Modular Simultaneous Exponentiation Core project          ---- 
6
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
7
----                                                              ---- 
8
----  Description                                                 ---- 
9
----    behavorial description of an asymmetric dual port ram     ----
10
----    with one (wrwidth)-bit write port and one 32-bit read     ----
11
----    port. Made using the templates of xilinx and altera for   ----
12
----    asymmetric ram.                                           ----            
13
----                                                              ---- 
14
----  Dependencies: none                                          ----
15
----                                                              ----
16
----  Authors:                                                    ----
17
----      - Geoffrey Ottoy, DraMCo research group                 ----
18
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
19
----                                                              ---- 
20
---------------------------------------------------------------------- 
21
----                                                              ---- 
22
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
23
----                                                              ---- 
24
---- This source file may be used and distributed without         ---- 
25
---- restriction provided that this copyright statement is not    ---- 
26
---- removed from the file and that any derivative work contains  ---- 
27
---- the original copyright notice and the associated disclaimer. ---- 
28
----                                                              ---- 
29
---- This source file is free software; you can redistribute it   ---- 
30
---- and/or modify it under the terms of the GNU Lesser General   ---- 
31
---- Public License as published by the Free Software Foundation; ---- 
32
---- either version 2.1 of the License, or (at your option) any   ---- 
33
---- later version.                                               ---- 
34
----                                                              ---- 
35
---- This source is distributed in the hope that it will be       ---- 
36
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
37
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
38
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
39
---- details.                                                     ---- 
40
----                                                              ---- 
41
---- You should have received a copy of the GNU Lesser General    ---- 
42
---- Public License along with this source; if not, download it   ---- 
43
---- from http://www.opencores.org/lgpl.shtml                     ---- 
44
----                                                              ---- 
45
----------------------------------------------------------------------
46
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49
use ieee.std_logic_unsigned.all;
50
use ieee.std_logic_arith.all;
51
 
52
library mod_sim_exp;
53
use mod_sim_exp.std_functions.all;
54
 
55
-- altera infers ramblocks from a depth of 9 (or 2 with any ram size recognition 
56
-- option on or contstraint below on) and wrwidth 1,2,4,8,16
57
-- xilinx infers ramblocks from a depth of 2 and wrwidth 1,2,4,8,16,32
58
entity dpram_asym is
59
  generic (
60
    rddepth : integer := 4; -- nr of 32-bit words
61
    wrwidth : integer := 2; -- write width, must be smaller than or equal to 32
62
    device  : string  := "xilinx"  -- device template to use
63
  );
64
  port  (
65
    clk : in std_logic;
66
    -- write port
67
    waddr : in std_logic_vector(log2((rddepth*32)/wrwidth)-1 downto 0);
68
    we    : in std_logic;
69
    din   : in std_logic_vector(wrwidth-1 downto 0);
70
    -- read port
71
    raddr : in std_logic_vector(log2(rddepth)-1 downto 0);
72
    dout  : out std_logic_vector(31 downto 0)
73
  );
74
end dpram_asym;
75
 
76
architecture behavorial of dpram_asym is
77
  -- constants
78
  constant R       : natural := 32/wrwidth; -- ratio
79
  constant wrdepth : integer := (rddepth*32)/wrwidth;
80
begin
81
 
82
  xilinx_device : if device="xilinx" generate
83
    -- the memory
84
    type ram_type is array (wrdepth-1 downto 0) of std_logic_vector (wrwidth-1 downto 0);
85
    signal RAM : ram_type := (others => (others => '0'));
86
 
87
    -- xilinx constraint to use blockram resources
88
    attribute ram_style : string;
89
    attribute ram_style of ram:signal is "block";
90
  begin
91
    process (clk)
92
    begin
93
      if (clk'event and clk = '1') then
94
        if (we = '1') then
95
          RAM(conv_integer(waddr)) <= din;
96
        end if;
97
        for i in 0 to R-1 loop
98
          dout((i+1)*wrwidth-1 downto i*wrwidth)
99
                <= RAM(conv_integer(raddr & conv_std_logic_vector(i,log2(R))));
100
        end loop;
101
      end if;
102
    end process;
103
  end generate;
104
 
105
  altera_device : if device="altera" generate
106
    -- Use a multidimensional array to model mixed-width 
107
    type word_t is array(R-1 downto 0) of std_logic_vector(wrwidth-1 downto 0);
108
    type ram_t is array (0 to rddepth-1) of word_t;
109
 
110
    signal ram : ram_t;
111
    signal q_local : word_t;
112
    -- altera constraints:
113
    -- for smal depths:
114
    --  if the synthesis option "allow any size of RAM to be inferred" is on, these lines 
115
    --  may be left commented.
116
    --  uncomment this attribute if that option is off and you know wich primitives should be used.
117
    --attribute ramstyle : string;
118
    --attribute ramstyle of RAM : signal is "M9K, no_rw_check";
119
  begin
120
    unpack: for i in 0 to R - 1 generate
121
      dout(wrwidth*(i+1) - 1 downto wrwidth*i) <= q_local(i);
122
    end generate unpack;
123
 
124
    process(clk, we)
125
    begin
126
      if(rising_edge(clk)) then
127
        if(we = '1') then
128
          ram(conv_integer(waddr)/R)(conv_integer(waddr) mod R) <= din;
129
        end if;
130
        q_local <= ram(conv_integer(raddr));
131
      end if;
132
    end process;
133
  end generate;
134
 
135
end behavorial;

powered by: WebSVN 2.1.0

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