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

Subversion Repositories heap_sorter

[/] [heap_sorter/] [trunk/] [high_speed_pipelined_4clk_per_word/] [src/] [sort_dpram.vhd_synth] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 wzab
-------------------------------------------------------------------------------
2
-- Title      : Parametrized DP RAM for heap-sorter
3
-- Project    : heap-sorter
4
-------------------------------------------------------------------------------
5
-- File       : sort_dpram.vhd
6
-- Author     : Wojciech M. Zabolotny 
7
-- Company    :
8
-- Created    : 2010-05-14
9
-- Last update: 2018-03-09
10
-- Platform   :
11
-- Standard   : VHDL'93
12
-------------------------------------------------------------------------------
13
-- Description:
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2010 Wojciech M. Zabolotny
16
-- This file is published under the BSD license, so you can freely adapt
17
-- it for your own purposes.
18
-- Additionally this design has been described in my article:
19
--    Wojciech M. Zabolotny, "Dual port memory based Heapsort implementation
20
--    for FPGA", Proc. SPIE 8008, 80080E (2011); doi:10.1117/12.905281
21
-- I'd be glad if you cite this article when you publish something based
22
-- on my design.
23
-------------------------------------------------------------------------------
24
-- Revisions  :
25
-- Date        Version  Author  Description
26
-- 2010-05-14  1.0      wzab    Created
27
-------------------------------------------------------------------------------
28
 
29
library ieee;
30
use ieee.std_logic_1164.all;
31
use ieee.numeric_std.all;
32
use ieee.std_logic_textio.all;
33
use std.textio.all;
34
library work;
35
use work.sorter_pkg.all;
36
use work.sys_config.all;
37
 
38
entity sort_dp_ram is
39
 
40
  generic
41
    (
42
      ADDR_WIDTH  : natural;
43
      NLEVELS     : natural;
44
      NAME        : string := "X";
45
      RAM_STYLE_G : string := "block"
46
      );
47
 
48
  port
49
    (
50
      clk    : in  std_logic;
51
      clk2   : in  std_logic;
52
      addr_a : in  std_logic_vector(NLEVELS-1 downto 0);
53
      addr_b : in  std_logic_vector(NLEVELS-1 downto 0);
54
      data_a : in  T_DATA_REC;
55
      data_b : in  T_DATA_REC;
56
      we_a   : in  std_logic;
57
      we_b   : in  std_logic;
58
      q_a    : out T_DATA_REC;
59
      q_b    : out T_DATA_REC
60
      );
61
 
62
end sort_dp_ram;
63
 
64
architecture rtl of sort_dp_ram is
65
 
66
  signal vq_a, vq_b, tdata_a, tdata_b : std_logic_vector(DATA_REC_WIDTH-1 downto 0);
67
  signal reg                          : T_DATA_REC := DATA_REC_INIT_DATA;
68
  signal det1, det2, det3             : std_logic  := '1';
69
  signal gwe_a, gwe_b                 : std_logic  := '1';
70
 
71
begin
72
 
73
  -- Convert our data records int std_logic_vector, so that
74
  -- standard DP RAM may handle it
75
  tdata_a <= tdrec2stlv(data_a);
76
  tdata_b <= tdrec2stlv(data_b);
77
 
78
  -- We need to ensure, that the memory is written only every second cycle (so
79
  -- that the external combinatorial net has two Clk2 cycles to settle)
80
  --
81
  rs1 : process (clk) is
82
  begin  -- process rs1
83
    if clk'event and clk = '1' then     -- rising clock edge
84
      det1 <= not det1;
85
    end if;
86
  end process rs1;
87
 
88
  rs2 : process (clk2) is
89
  begin  -- process rs1
90
    if clk2'event and clk2 = '1' then   -- rising clock edge
91
      det2 <= det1;
92
    end if;
93
  end process rs2;
94
  -- We should activate WE only when det1 and det2 are equal
95
  -- (i.e., after the clk2 pulse not associated with the clk pulse)
96
 
97
  gwe : process (det1, det2, we_a, we_b) is
98
  begin  -- process gwe
99
    gwe_a <= '0';
100
    gwe_b <= '0';
101
    if det2 = det1 then
102
      gwe_a <= we_a;
103
      gwe_b <= we_b;
104
    end if;
105
  end process gwe;
106
 
107
  i1 : if ADDR_WIDTH > 0 generate
108
    -- When ADDR_WIDTH is above 0 embed the real DP RAM
109
    -- (even though synthesis tool may still replace it with
110
    -- registers during optimization for low ADDR_WIDTH)
111
 
112
    q_a <= stlv2tdrec(vq_a);
113
    q_b <= stlv2tdrec(vq_b);
114
    blockgen : if RAM_STYLE_G = "block" generate
115
      dp_ram_1 : entity work.dp_ram_scl_sorter
116
        generic map (
117
          DATA_WIDTH => DATA_REC_WIDTH,
118
          ADDR_WIDTH => ADDR_WIDTH)
119
        port map (
120
          clk    => clk2,
121
          addr_a => addr_a(ADDR_WIDTH-1 downto 0),
122
          addr_b => addr_b(ADDR_WIDTH-1 downto 0),
123
          data_a => tdata_a,
124
          data_b => tdata_b,
125
          we_a   => gwe_a,
126
          we_b   => gwe_b,
127
          q_a    => vq_a,
128
          q_b    => vq_b);
129
 
130
    end generate;
131
 
132
    distribgen : if RAM_STYLE_G = "distributed" generate
133
      dp_ram_1 : entity work.dp_ram_scl_sorter_distributed
134
        generic map (
135
          DATA_WIDTH => DATA_REC_WIDTH,
136
          ADDR_WIDTH => ADDR_WIDTH)
137
        port map (
138
          clk    => clk2,
139
          addr_a => addr_a(ADDR_WIDTH-1 downto 0),
140
          addr_b => addr_b(ADDR_WIDTH-1 downto 0),
141
          data_a => tdata_a,
142
          data_b => tdata_b,
143
          we_a   => gwe_a,
144
          we_b   => gwe_b,
145
          q_a    => vq_a,
146
          q_b    => vq_b);
147
 
148
    end generate;
149
 
150
 
151
  end generate i1;
152
 
153
  i2 : if ADDR_WIDTH = 0 generate
154
    -- When ADDR_WIDTH is 0, DP RAM should be simply replaced
155
    -- with a register implemented below
156
 
157
    p1 : process (clk)
158
    begin  -- process p1
159
      if clk'event and clk = '1' then   -- rising clock edge
160
        if we_a = '1' then
161
          reg <= data_a;
162
          q_a <= data_a;
163
          q_b <= data_a;
164
        elsif we_b = '1' then
165
          reg <= data_b;
166
          q_a <= data_b;
167
          q_b <= data_b;
168
        else
169
          q_a <= reg;
170
          q_b <= reg;
171
        end if;
172
      end if;
173
    end process p1;
174
 
175
  end generate i2;
176
 
177
  --dbg1 : if SORT_DEBUG generate
178
 
179
  --  -- Process monitoring read/write accesses to the memory (only for debugging)
180
  --  p3 : process (clk)
181
  --    variable rline : line;
182
  --  begin  -- process p1
183
  --    if clk'event and clk = '1' then   -- rising clock edge
184
  --      if(we_a = '1' and we_b = '1') then
185
  --        write(rline, NAME);
186
  --        write(rline, ADDR_WIDTH);
187
  --        write(rline, string'(" Possible write collision!"));
188
  --        writeline(reports, rline);
189
  --      end if;
190
 
191
--      if we_a = '1' then
192
--        write(rline, NAME);
193
--        write(rline, ADDR_WIDTH);
194
--        write(rline, string'(" WR_A:"));
195
--        wrstlv(rline, addr_a(ADDR_WIDTH-1 downto 0));
196
--        write(rline, string'(" VAL:"));
197
--        wrstlv(rline, tdata_a);
198
--        writeline(reports, rline);
199
--      end if;
200
--      if we_b = '1' then
201
--        write(rline, NAME);
202
--        write(rline, ADDR_WIDTH);
203
--        write(rline, string'(" WR_B:"));
204
--        wrstlv(rline, addr_b(ADDR_WIDTH-1 downto 0));
205
--        write(rline, string'(" VAL:"));
206
--        wrstlv(rline, tdata_b);
207
--        writeline(reports, rline);
208
--      end if;
209
--    end if;
210
--  end process p3;
211
--end generate dbg1;
212
end rtl;

powered by: WebSVN 2.1.0

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