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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [src/] [components/] [BRAM/] [generic_memory_block.vhdl] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 lcdsgmtr
LIBRARY ieee;
2
USE ieee.std_logic_1164.ALL;
3
USE ieee.numeric_std.ALL;
4
USE work.hexio.ALL;
5
 
6
ENTITY generic_memory_block IS
7
 
8
  -- Memory component based upon Xilinx Spartan-6 block RAM
9
  -- Maximum capacity is 16k words
10
  -- This component can be initialised by passing a file name as a generic
11
  -- parameter.
12
 
13
  GENERIC (
14
    init_data : cstr_array_type;
15
    w_data    : NATURAL RANGE 1 TO 32 := 16;
16
    w_addr    : NATURAL RANGE 8 TO 14 := 10);
17
  PORT (
18
    clk : IN  STD_LOGIC;
19
    we  : IN  STD_LOGIC;
20
    a1  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Data port address
21
    a2  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Instruction port address
22
    d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port input
23
    q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port output
24
    q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
25
 
26
END generic_memory_block;
27
 
28
ARCHITECTURE Behavioral OF generic_memory_block IS
29
 
30
  SIGNAL mem : cstr_array_type(0 TO (2**w_addr) - 1) := init_data;
31
 
32
  SIGNAL address_reg_1 : STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);
33
  SIGNAL address_reg_2 : STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);
34
 
35
BEGIN  -- Behavioral
36
 
37
  -- purpose: Try to describe a proper block ram without needing to instantiate a BRAM
38
  -- type   : sequential
39
  -- inputs : clk, we, a1, a2, d1
40
  -- outputs: q1, q2
41
  MP1 : PROCESS (clk, address_reg_1, address_reg_2, mem)
42
  BEGIN  -- PROCESS MP1
43
 
44
    -- Reading
45
    q1 <= STD_LOGIC_VECTOR(to_unsigned(mem(to_integer(UNSIGNED(address_reg_1))), w_data));
46
    q2 <= STD_LOGIC_VECTOR(to_unsigned(mem(to_integer(UNSIGNED(address_reg_2))), w_data));
47
    IF rising_edge(clk) THEN            -- rising clock edge
48
 
49
      -- These work like the block RAM registers
50
      address_reg_1 <= a1;
51
      address_reg_2 <= a2;
52
 
53
      -- Writing
54
      IF we = '1' THEN
55
        mem(to_integer(UNSIGNED(a1))) <= to_integer(UNSIGNED(d1));
56
      END IF;
57
 
58
    END IF;
59
 
60
  END PROCESS MP1;
61
 
62
END Behavioral;

powered by: WebSVN 2.1.0

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