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

Subversion Repositories heap_sorter

[/] [heap_sorter/] [trunk/] [standard_version/] [src/] [sort_dpram.vhd] - Blame information for rev 7

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

Line No. Rev Author Line
1 2 wzab
-------------------------------------------------------------------------------
2
-- Title      : Parametrized DP RAM for heap-sorter
3
-- Project    : heap-sorter
4
-------------------------------------------------------------------------------
5
-- File       : sort_dpram.vhd
6
-- Author     : Wojciech M. Zabolotny <wzab@ise.pw.edu.pl>
7
-- Company    : 
8
-- Created    : 2010-05-14
9
-- Last update: 2011-07-06
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
      );
46
 
47
  port
48
    (
49
      clk    : in  std_logic;
50
      addr_a : in  std_logic_vector(NLEVELS-1 downto 0);
51
      addr_b : in  std_logic_vector(NLEVELS-1 downto 0);
52
      data_a : in  T_DATA_REC;
53
      data_b : in  T_DATA_REC;
54
      we_a   : in  std_logic;
55
      we_b   : in  std_logic;
56
      q_a    : out T_DATA_REC;
57
      q_b    : out T_DATA_REC
58
      );
59
 
60
end sort_dp_ram;
61
 
62
architecture rtl of sort_dp_ram is
63
 
64
  signal vq_a, vq_b, tdata_a, tdata_b : std_logic_vector(DATA_REC_WIDTH-1 downto 0);
65
  signal reg                          : T_DATA_REC := DATA_REC_INIT_DATA;
66
 
67
  component dp_ram_scl
68
    generic (
69
      DATA_WIDTH : natural;
70
      ADDR_WIDTH : natural);
71
    port (
72
      clk    : in  std_logic;
73
      addr_a : in  std_logic_vector(ADDR_WIDTH-1 downto 0);
74
      addr_b : in  std_logic_vector(ADDR_WIDTH-1 downto 0);
75
      data_a : in  std_logic_vector((DATA_WIDTH-1) downto 0);
76
      data_b : in  std_logic_vector((DATA_WIDTH-1) downto 0);
77
      we_a   : in  std_logic := '1';
78
      we_b   : in  std_logic := '1';
79
      q_a    : out std_logic_vector((DATA_WIDTH -1) downto 0);
80
      q_b    : out std_logic_vector((DATA_WIDTH -1) downto 0));
81
  end component;
82
 
83
begin
84
 
85
  -- Convert our data records int std_logic_vector, so that
86
  -- standard DP RAM may handle it
87
  tdata_a <= tdrec2stlv(data_a);
88
  tdata_b <= tdrec2stlv(data_b);
89
 
90
 
91
  i1 : if ADDR_WIDTH > 0 generate
92
    -- When ADDR_WIDTH is above 0 embed the real DP RAM
93
    -- (even though synthesis tool may still replace it with
94
    -- registers during optimization for low ADDR_WIDTH)
95
 
96
    q_a <= stlv2tdrec(vq_a);
97
    q_b <= stlv2tdrec(vq_b);
98
 
99
    dp_ram_1 : dp_ram_scl
100
      generic map (
101
        DATA_WIDTH => DATA_REC_WIDTH,
102
        ADDR_WIDTH => ADDR_WIDTH)
103
      port map (
104
        clk    => clk,
105
        addr_a => addr_a(ADDR_WIDTH-1 downto 0),
106
        addr_b => addr_b(ADDR_WIDTH-1 downto 0),
107
        data_a => tdata_a,
108
        data_b => tdata_b,
109
        we_a   => we_a,
110
        we_b   => we_b,
111
        q_a    => vq_a,
112
        q_b    => vq_b);
113
 
114
  end generate i1;
115
 
116
  i2 : if ADDR_WIDTH = 0 generate
117
    -- When ADDR_WIDTH is 0, DP RAM should be simply replaced
118
    -- with a register implemented below
119
 
120
    p1 : process (clk)
121
    begin  -- process p1
122
      if clk'event and clk = '1' then   -- rising clock edge
123
        if we_a = '1' then
124
          reg <= data_a;
125
          q_a <= data_a;
126
          q_b <= data_a;
127
        elsif we_b = '1' then
128
          reg <= data_b;
129
          q_a <= data_b;
130
          q_b <= data_b;
131
        else
132
          q_a <= reg;
133
          q_b <= reg;
134
        end if;
135
      end if;
136
    end process p1;
137
 
138
  end generate i2;
139
 
140
  dbg1 : if SORT_DEBUG generate
141
 
142
    -- Process monitoring read/write accesses to the memory (only for debugging)
143
    p3 : process (clk)
144
      variable rline : line;
145
    begin  -- process p1
146
      if clk'event and clk = '1' then   -- rising clock edge
147
        if(we_a = '1' and we_b = '1') then
148
          write(rline, NAME);
149
          write(rline, ADDR_WIDTH);
150
          write(rline, string'(" Possible write collision!"));
151
          writeline(reports, rline);
152
        end if;
153
 
154
        if we_a = '1' then
155
          write(rline, NAME);
156
          write(rline, ADDR_WIDTH);
157
          write(rline, string'(" WR_A:"));
158
          wrstlv(rline, addr_a(ADDR_WIDTH-1 downto 0));
159
          write(rline, string'(" VAL:"));
160
          wrstlv(rline, tdata_a);
161
          writeline(reports, rline);
162
        end if;
163
        if we_b = '1' then
164
          write(rline, NAME);
165
          write(rline, ADDR_WIDTH);
166
          write(rline, string'(" WR_B:"));
167
          wrstlv(rline, addr_b(ADDR_WIDTH-1 downto 0));
168
          write(rline, string'(" VAL:"));
169
          wrstlv(rline, tdata_b);
170
          writeline(reports, rline);
171
        end if;
172
      end if;
173
    end process p3;
174
  end generate dbg1;
175
end rtl;

powered by: WebSVN 2.1.0

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