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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [riverlib/] [cache/] [cache_top.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
-----------------------------------------------------------------------------
2
--! @file
3
--! @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
--! @author    Sergey Khabarov - sergeykhbr@gmail.com
5
--! @brief     Memory Cache Top level.
6
------------------------------------------------------------------------------
7
 
8
library ieee;
9
use ieee.std_logic_1164.all;
10
library commonlib;
11
use commonlib.types_common.all;
12
--! RIVER CPU specific library.
13
library riverlib;
14
--! RIVER CPU configuration constants.
15
use riverlib.river_cfg.all;
16
 
17
 
18
entity CacheTop is
19
  port (
20
    i_clk : in std_logic;                              -- CPU clock
21
    i_nrst : in std_logic;                             -- Reset. Active LOW.
22
    -- Control path:
23
    i_req_ctrl_valid : in std_logic;
24
    i_req_ctrl_addr : in std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
25
    o_req_ctrl_ready : out std_logic;
26
    o_resp_ctrl_valid : out std_logic;
27
    o_resp_ctrl_addr : out std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
28
    o_resp_ctrl_data : out std_logic_vector(31 downto 0);
29
    i_resp_ctrl_ready : in std_logic;
30
    -- Data path:
31
    i_req_data_valid : in std_logic;
32
    i_req_data_write : in std_logic;
33
    i_req_data_size : in std_logic_vector(1 downto 0);
34
    i_req_data_addr : in std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
35
    i_req_data_data : in std_logic_vector(RISCV_ARCH-1 downto 0);
36
    o_req_data_ready : out std_logic;
37
    o_resp_data_valid : out std_logic;
38
    o_resp_data_addr : out std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
39
    o_resp_data_data : out std_logic_vector(RISCV_ARCH-1 downto 0);
40
    i_resp_data_ready : in std_logic;
41
    -- Memory interface:
42
    i_req_mem_ready : in std_logic;                                   -- AXI request was accepted
43
    o_req_mem_valid : out std_logic;
44
    o_req_mem_write : out std_logic;
45
    o_req_mem_addr : out std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
46
    o_req_mem_strob : out std_logic_vector(BUS_DATA_BYTES-1 downto 0);
47
    o_req_mem_data : out std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
48
    i_resp_mem_data_valid : in std_logic;
49
    i_resp_mem_data : in std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
50
    -- Debug signals:
51
    o_istate : out std_logic_vector(1 downto 0);                      -- ICache state machine value
52
    o_dstate : out std_logic_vector(1 downto 0);                      -- DCache state machine value
53
    o_cstate : out std_logic_vector(1 downto 0)                       -- cachetop state machine value
54
  );
55
end;
56
 
57
architecture arch_CacheTop of CacheTop is
58
  constant State_Idle : std_logic_vector(1 downto 0) := "00";
59
  constant State_IMem : std_logic_vector(1 downto 0) := "01";
60
  constant State_DMem : std_logic_vector(1 downto 0) := "10";
61
 
62
  type CacheOutputType is record
63
      req_mem_valid : std_logic;
64
      req_mem_write : std_logic;
65
      req_mem_addr : std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
66
      req_mem_strob : std_logic_vector(BUS_DATA_BYTES-1 downto 0);
67
      req_mem_wdata : std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
68
  end record;
69
 
70
  type RegistersType is record
71
      state : std_logic_vector(1 downto 0);
72
  end record;
73
 
74
  signal i :  CacheOutputType;
75
  signal d :  CacheOutputType;
76
  signal r, rin : RegistersType;
77
  -- Memory Control interface:
78
  signal w_ctrl_resp_mem_data_valid : std_logic;
79
  signal wb_ctrl_resp_mem_data : std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
80
  signal w_ctrl_req_ready : std_logic;
81
  -- Memory Data interface:
82
  signal w_data_resp_mem_data_valid : std_logic;
83
  signal wb_data_resp_mem_data : std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
84
  signal w_data_req_ready : std_logic;
85
 
86
  component ICache is port (
87
    i_clk : in std_logic;
88
    i_nrst : in std_logic;
89
    i_req_ctrl_valid : in std_logic;
90
    i_req_ctrl_addr : in std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
91
    o_req_ctrl_ready : out std_logic;
92
    o_resp_ctrl_valid : out std_logic;
93
    o_resp_ctrl_addr : out std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
94
    o_resp_ctrl_data : out std_logic_vector(31 downto 0);
95
    i_resp_ctrl_ready : in std_logic;
96
    i_req_mem_ready : in std_logic;
97
    o_req_mem_valid : out std_logic;
98
    o_req_mem_write : out std_logic;
99
    o_req_mem_addr : out std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
100
    o_req_mem_strob : out std_logic_vector(BUS_DATA_BYTES-1 downto 0);
101
    o_req_mem_data : out std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
102
    i_resp_mem_data_valid : in std_logic;
103
    i_resp_mem_data : in std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
104
    o_istate : out std_logic_vector(1 downto 0)
105
  );
106
  end component;
107
 
108
  component DCache is port (
109
    i_clk : in std_logic;
110
    i_nrst : in std_logic;
111
    i_req_data_valid : in std_logic;
112
    i_req_data_write : in std_logic;
113
    i_req_data_sz : in std_logic_vector(1 downto 0);
114
    i_req_data_addr : in std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
115
    i_req_data_data : in std_logic_vector(RISCV_ARCH-1 downto 0);
116
    o_req_data_ready : out std_logic;
117
    o_resp_data_valid : out std_logic;
118
    o_resp_data_addr : out std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
119
    o_resp_data_data : out std_logic_vector(RISCV_ARCH-1 downto 0);
120
    i_resp_data_ready : in std_logic;
121
    i_req_mem_ready : in std_logic;
122
    o_req_mem_valid : out std_logic;
123
    o_req_mem_write : out std_logic;
124
    o_req_mem_addr : out std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
125
    o_req_mem_strob : out std_logic_vector(BUS_DATA_BYTES-1 downto 0);
126
    o_req_mem_data : out std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
127
    i_resp_mem_data_valid : in std_logic;
128
    i_resp_mem_data : in std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
129
    o_dstate : out std_logic_vector(1 downto 0)
130
  );
131
  end component;
132
 
133
begin
134
 
135
    i0 : ICache port map (
136
        i_clk => i_clk,
137
        i_nrst => i_nrst,
138
        i_req_ctrl_valid => i_req_ctrl_valid,
139
        i_req_ctrl_addr => i_req_ctrl_addr,
140
        o_req_ctrl_ready => o_req_ctrl_ready,
141
        o_resp_ctrl_valid => o_resp_ctrl_valid,
142
        o_resp_ctrl_addr => o_resp_ctrl_addr,
143
        o_resp_ctrl_data => o_resp_ctrl_data,
144
        i_resp_ctrl_ready => i_resp_ctrl_ready,
145
        i_req_mem_ready => w_ctrl_req_ready,
146
        o_req_mem_valid => i.req_mem_valid,
147
        o_req_mem_write => i.req_mem_write,
148
        o_req_mem_addr => i.req_mem_addr,
149
        o_req_mem_strob => i.req_mem_strob,
150
        o_req_mem_data => i.req_mem_wdata,
151
        i_resp_mem_data_valid => w_ctrl_resp_mem_data_valid,
152
        i_resp_mem_data => wb_ctrl_resp_mem_data,
153
        o_istate => o_istate);
154
 
155
    d0 : DCache port map (
156
        i_clk => i_clk,
157
        i_nrst => i_nrst,
158
        i_req_data_valid => i_req_data_valid,
159
        i_req_data_write => i_req_data_write,
160
        i_req_data_sz => i_req_data_size,
161
        i_req_data_addr => i_req_data_addr,
162
        i_req_data_data => i_req_data_data,
163
        o_req_data_ready => o_req_data_ready,
164
        o_resp_data_valid => o_resp_data_valid,
165
        o_resp_data_addr => o_resp_data_addr,
166
        o_resp_data_data => o_resp_data_data,
167
        i_resp_data_ready => i_resp_data_ready,
168
        i_req_mem_ready => w_data_req_ready,
169
        o_req_mem_valid => d.req_mem_valid,
170
        o_req_mem_write => d.req_mem_write,
171
        o_req_mem_addr => d.req_mem_addr,
172
        o_req_mem_strob => d.req_mem_strob,
173
        o_req_mem_data => d.req_mem_wdata,
174
        i_resp_mem_data_valid => w_data_resp_mem_data_valid,
175
        i_resp_mem_data => wb_data_resp_mem_data,
176
        o_dstate => o_dstate);
177
 
178
  comb : process(i_nrst, i_req_mem_ready, i_resp_mem_data_valid, i_resp_mem_data,
179
                 i, d, r)
180
    variable v : RegistersType;
181
    variable w_mem_write : std_logic;
182
    variable wb_mem_addr : std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
183
    variable wb_mem_strob : std_logic_vector(BUS_DATA_BYTES-1 downto 0);
184
    variable wb_mem_wdata : std_logic_vector(BUS_DATA_WIDTH-1 downto 0);
185
  begin
186
 
187
    v := r;
188
 
189
    w_mem_write := '0';
190
    wb_mem_addr := (others => '0');
191
    wb_mem_strob := (others => '0');
192
    wb_mem_wdata := (others => '0');
193
 
194
    w_data_req_ready <= '0';
195
    w_data_resp_mem_data_valid <= '0';
196
    wb_data_resp_mem_data <= (others => '0');
197
    w_ctrl_req_ready <= '0';
198
    w_ctrl_resp_mem_data_valid <= '0';
199
    wb_ctrl_resp_mem_data <= (others => '0');
200
 
201
    case r.state is
202
    when State_Idle =>
203
        if d.req_mem_valid = '1' then
204
          w_data_req_ready <= i_req_mem_ready;
205
          w_mem_write := d.req_mem_write;
206
          wb_mem_addr := d.req_mem_addr;
207
          wb_mem_strob := d.req_mem_strob;
208
          wb_mem_wdata := d.req_mem_wdata;
209
          if i_req_mem_ready = '1' then
210
            v.state := State_DMem;
211
          end if;
212
        elsif i.req_mem_valid = '1' then
213
          w_ctrl_req_ready <= i_req_mem_ready;
214
          w_mem_write := i.req_mem_write;
215
          wb_mem_addr := i.req_mem_addr;
216
          wb_mem_strob := i.req_mem_strob;
217
          wb_mem_wdata := i.req_mem_wdata;
218
          if i_req_mem_ready = '1' then
219
            v.state := State_IMem;
220
          end if;
221
        end if;
222
 
223
    when State_DMem =>
224
        w_data_req_ready <= i_req_mem_ready;
225
        w_mem_write := d.req_mem_write;
226
        wb_mem_addr := d.req_mem_addr;
227
        wb_mem_strob := d.req_mem_strob;
228
        wb_mem_wdata := d.req_mem_wdata;
229
        if i_resp_mem_data_valid = '1' then
230
          if (not d.req_mem_valid and i.req_mem_valid) = '1' then
231
            v.state := State_IMem;
232
            w_data_req_ready <= '0';
233
            w_ctrl_req_ready <= i_req_mem_ready;
234
            w_mem_write := i.req_mem_write;
235
            wb_mem_addr := i.req_mem_addr;
236
            wb_mem_strob := i.req_mem_strob;
237
            wb_mem_wdata := i.req_mem_wdata;
238
          elsif (d.req_mem_valid or i.req_mem_valid) = '0' then
239
            v.state := State_Idle;
240
          end if;
241
        end if;
242
        w_data_resp_mem_data_valid <= i_resp_mem_data_valid;
243
        wb_data_resp_mem_data <= i_resp_mem_data;
244
 
245
    when State_IMem =>
246
        w_ctrl_req_ready <= i_req_mem_ready;
247
        w_mem_write := i.req_mem_write;
248
        wb_mem_addr := i.req_mem_addr;
249
        wb_mem_strob := i.req_mem_strob;
250
        wb_mem_wdata := i.req_mem_wdata;
251
        if i_resp_mem_data_valid = '1' then
252
          if d.req_mem_valid = '1' then
253
            v.state := State_DMem;
254
            w_data_req_ready <= i_req_mem_ready;
255
            w_ctrl_req_ready <= '0';
256
            w_mem_write := d.req_mem_write;
257
            wb_mem_addr := d.req_mem_addr;
258
            wb_mem_strob := d.req_mem_strob;
259
            wb_mem_wdata := d.req_mem_wdata;
260
          elsif (d.req_mem_valid or i.req_mem_valid) = '0' then
261
            v.state := State_Idle;
262
          end if;
263
        end if;
264
        w_ctrl_resp_mem_data_valid <= i_resp_mem_data_valid;
265
        wb_ctrl_resp_mem_data <= i_resp_mem_data;
266
 
267
    when others =>
268
    end case;
269
 
270
    if i_nrst = '0' then
271
        v.state := State_Idle;
272
    end if;
273
 
274
    o_req_mem_valid <= i.req_mem_valid or d.req_mem_valid;
275
    o_req_mem_write <= w_mem_write;
276
    o_req_mem_addr <= wb_mem_addr;
277
    o_req_mem_strob <= wb_mem_strob;
278
    o_req_mem_data <= wb_mem_wdata;
279
    o_cstate <= r.state;
280
 
281
    rin <= v;
282
  end process;
283
 
284
  -- registers:
285
  regs : process(i_clk)
286
  begin
287
     if rising_edge(i_clk) then
288
        r <= rin;
289
     end if;
290
  end process;
291
 
292
end;

powered by: WebSVN 2.1.0

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