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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [src/] [components/] [BRAM/] [cache.vhdl] - Blame information for rev 30

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 lcdsgmtr
LIBRARY ieee;
2
USE ieee.std_logic_1164.ALL;
3
 
4
ENTITY cache IS
5
 
6
  PORT (
7
    clk     : IN  STD_LOGIC;
8
    address : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);
9
    instr   : OUT STD_LOGIC_VECTOR(15 DOWNTO 0));
10
 
11
END ENTITY cache;
12
 
13
ARCHITECTURE Behavioral OF cache IS
14
 
15
  COMPONENT cache_block IS
16
    -- Cache memory block of 512x16
17
    GENERIC (
18
      w_data : NATURAL RANGE 1 TO 32 := 16;
19
      w_addr : NATURAL RANGE 8 TO 14 := 9);
20
    PORT (
21
      clk : IN  STD_LOGIC;
22
      we  : IN  STD_LOGIC;
23
      a1  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Data port address
24
      a2  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Instruction port address
25
      d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port input
26
      q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port output
27
      q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
28
 
29
  END COMPONENT cache_block;
30
 
31
  SIGNAL column : STD_LOGIC_VECTOR(2 DOWNTO 0);
32
  SIGNAL row    : STD_LOGIC_VECTOR(8 DOWNTO 0);
33
  SIGNAL tag    : STD_LOGIC_VECTOR(2 DOWNTO 0);
34
 
35
  SIGNAL address_reg : STD_LOGIC_VECTOR(15 DOWNTO 0);
36
  SIGNAL instr_out   : ARRAY(0 TO 7) OF STD_LOGIC_VECTOR(15 DOWNTO 0);
37
 
38
BEGIN  -- ARCHITECTURE Behavioral
39
 
40
  -- purpose: Register the input address at the same time it is
41
  -- registered in the block RAM
42
  -- type   : sequential
43
  -- inputs : clk, rst, address
44
  -- outputs: address_reg
45
  AR1 : PROCESS (clk) IS
46
  BEGIN  -- PROCESS AR1
47
    IF rising_edge(clk) THEN
48
      address_reg <= address;
49
    END IF;
50
  END PROCESS AR1;
51
 
52
  -- Split the supplied address into three pieces
53
  column <= address_reg(2 DOWNTO 0);
54
  row    <= address_reg(11 DOWNTO 3);
55
  tag    <= address_reg(14 DOWNTO 12);
56
 
57
  -- Control data block with valid bits and tags
58
  CB1 : cache_block
59
    GENERIC MAP (
60
      w_data => 4,
61
      w_addr => 9)
62
    PORT MAP (
63
      clk => clk,
64
      we  => we,
65
      a1  => row,
66
      a2  => (OTHERS => '0'),
67
      d1  => tag,
68
      q1  => cmp);
69
 
70
  -- Generate the cache memory in 8 columns
71
  C1 : FOR i IN 0 TO 7 GENERATE
72
 
73
    B0 : cache_block
74
      GENERIC MAP (
75
        w_data => 16,
76
        w_addr => 9)
77
      PORT MAP (
78
        clk => clk,
79
        we  => we,
80
        a1  => row,
81
        a2  => (OTHERS => '0'),
82
        d1  => d1,
83
        q1  => instr_out(i));
84
 
85
  END GENERATE C1;
86
 
87
  -- Select the instruction output based upon the column
88
  WITH column SELECT
89
    instr <=
90
    instr_out(0) WHEN "000",
91
    instr_out(1) WHEN "001",
92
    instr_out(2) WHEN "010",
93
    instr_out(3) WHEN "011",
94
    instr_out(4) WHEN "100",
95
    instr_out(5) WHEN "101",
96
    instr_out(6) WHEN "110",
97
    instr_out(7) WHEN "111";
98
 
99
END ARCHITECTURE Behavioral;

powered by: WebSVN 2.1.0

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