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

Subversion Repositories heap_sorter

[/] [heap_sorter/] [trunk/] [simplified_version/] [src/] [dpram4.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wzab
-- Simulation model of the dual port RAM (DP RAM) with single clock
2
-- and with "read-after-write" operation.
3
-- This file was combined from multiple descriptions and models of dual port RAMs
4
-- which I was able to find in the Internet and in the documentation provided
5
-- by vendors like Xilinx or Altera.
6
-- Therefore the only thing I can do is to publish it as PUBLIC DOMAIN
7
--
8
-- Please note, that for synthesis you should replace this file with
9
-- another DP RAM wrapper inferring the real DP RAM
10
library ieee;
11
use ieee.std_logic_1164.all;
12
use ieee.numeric_std.all;
13
 
14
entity dp_ram_scl is
15
 
16
  generic
17
    (
18
      DATA_WIDTH : natural;
19
      ADDR_WIDTH : natural
20
      );
21
 
22
  port
23
    (
24
      clk    : in  std_logic;
25
      addr_a : in  std_logic_vector(ADDR_WIDTH-1 downto 0);
26
      addr_b : in  std_logic_vector(ADDR_WIDTH-1 downto 0);
27
      data_a : in  std_logic_vector((DATA_WIDTH-1) downto 0);
28
      data_b : in  std_logic_vector((DATA_WIDTH-1) downto 0);
29
      we_a   : in  std_logic := '1';
30
      we_b   : in  std_logic := '1';
31
      q_a    : out std_logic_vector((DATA_WIDTH -1) downto 0);
32
      q_b    : out std_logic_vector((DATA_WIDTH -1) downto 0)
33
      );
34
 
35
end dp_ram_scl;
36
 
37
architecture rtl of dp_ram_scl is
38
 
39
  signal    v_addr_a :  natural range 0 to 2**ADDR_WIDTH - 1;
40
  signal    v_addr_b :  natural range 0 to 2**ADDR_WIDTH - 1;
41
  subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
42
  type memory_t is array((2**ADDR_WIDTH-1) downto 0) of word_t;
43
 
44 7 wzab
  signal ram : memory_t := (others => (others=>'1'));  -- For debugging - initialize
45
                                               -- simulated RAM with all ones
46 2 wzab
 
47
begin
48
 
49
  v_addr_a <= to_integer(unsigned(addr_a(ADDR_WIDTH-1 downto 0)));
50
  v_addr_b <= to_integer(unsigned(addr_b(ADDR_WIDTH-1 downto 0)));
51
 
52
  process(clk)
53
  begin
54
 
55
    if(rising_edge(clk)) then
56
      -- Port A
57
      if(we_a = '1') then
58
        ram(v_addr_a) <= data_a;
59
        -- read-after-write behavior
60
        q_a <= data_a;
61
      else
62
        -- simulate "unknown" value when the same address is written via one port
63
        -- and immediately read via another port
64
        if we_b='1' and v_addr_a=v_addr_b then
65
          q_a <= (others => 'X');
66
        else
67
          q_a <= ram(v_addr_a);
68
        end if;
69
      end if;
70
      -- Port B 
71
      if(we_b = '1') then
72
        ram(v_addr_b) <= data_b;
73
        -- read-after-write behavior
74
        q_b         <= data_b;
75
      else
76
        -- simulate "unknown" value when the same address is written via one port
77
        -- and immediately read via another port
78
        if we_a='1' and v_addr_a=v_addr_b then
79
          q_b <= (others => 'X');
80
        else
81
          q_b <= ram(v_addr_b);
82
        end if;
83
      end if;
84
    end if;
85
  end process;
86
 
87
end rtl;

powered by: WebSVN 2.1.0

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