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

Subversion Repositories embedded_risc

[/] [embedded_risc/] [trunk/] [Verilog/] [lru_data_cache.v] - Blame information for rev 27

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 hosseinami
/**********************************************************
2
 MODULE:                Sub Level Least Recently Used Data Cache
3
 
4
 FILE NAME:     lru_data_cache.v
5
 VERSION:       1.0
6
 DATE:          May 7th, 2002
7
 AUTHOR:                Hossein Amidi
8
 COMPANY:
9
 CODE TYPE:     Register Transfer Level
10
 
11
 DESCRIPTION:   This module is the top level RTL code of LRU
12
 Data Cache verilog code.
13
 
14
 It will instantiate the following blocks in the ASIC:
15
 
16
 1)     Data Cache Way 0
17
 2)     Data Cache Way 1
18
 3)     Data Cache Way 2
19
 4)     Data Cache Way 3
20
 
21
 
22
 Hossein Amidi
23
 (C) April 2002
24
 
25
*********************************************************/
26
 
27
// DEFINES
28
`timescale 1ns / 10ps
29
 
30
// TOP MODULE
31
module lru_data_cache(// Inputs
32
                                                reset,
33
                                                clk0,
34
                                                cache_host_addr,
35
                                                cache_host_cmd,
36
                                                cache_request,
37
                                                cache_host_datain,
38
                                                cache_bus_grant,
39
                                                cache_datain,
40
                                                // Outputs
41
                                                cache_host_dataout,
42
                                                cache_hit,
43
                                                cache_miss,
44
                                                cache_bus_request,
45
                                                cache_addr,
46
                                                cache_cmd,
47
                                                cache_dataout
48
                                                );
49
 
50
 
51
// Parameter
52
`include        "parameter.v"
53
 
54
// Inputs
55
input reset;
56
input clk0;
57
input [padd_size - 1 : 0]cache_host_addr;
58
input [cmd_size  - 1 : 0]cache_host_cmd;
59
input cache_request;
60
input [data_size - 1 : 0]cache_host_datain;
61
input cache_bus_grant;
62
input [data_size - 1 : 0]cache_datain;
63
 
64
// Outputs
65
output [data_size - 1 : 0]cache_host_dataout;
66
output cache_hit;
67
output cache_miss;
68
output cache_bus_request;
69
output [padd_size - 1 : 0]cache_addr;
70
output [cmd_size  - 1 : 0]cache_cmd;
71
output [data_size - 1 : 0]cache_dataout;
72
 
73
// Signal Declarations
74
wire reset;
75
wire clk0;
76
wire [padd_size - 1 : 0]cache_host_addr;
77
wire [cmd_size  - 1 : 0]cache_host_cmd;
78
wire cache_request;
79
wire [data_size - 1 : 0]cache_host_datain;
80
wire cache_bus_grant;
81
wire [data_size - 1 : 0]cache_datain;
82
 
83
reg [data_size - 1 : 0]cache_host_dataout;
84
reg cache_hit;
85
reg cache_miss;
86
wire cache_bus_request;
87
reg [padd_size - 1 : 0]cache_addr;
88
reg [cmd_size  - 1 : 0]cache_cmd;
89
reg [data_size - 1 : 0]cache_dataout;
90
 
91
wire [cache_line_size - 1 : 0]data_cache_datain_way0;
92
wire [cache_line_size - 1 : 0]data_cache_datain_way1;
93
wire [cache_line_size - 1 : 0]data_cache_datain_way2;
94
wire [cache_line_size - 1 : 0]data_cache_datain_way3;
95
wire [cache_line_size - 1 : 0]data_cache_dataout_way0;
96
wire [cache_line_size - 1 : 0]data_cache_dataout_way1;
97
wire [cache_line_size - 1 : 0]data_cache_dataout_way2;
98
wire [cache_line_size - 1 : 0]data_cache_dataout_way3;
99
 
100
wire cache_wr;
101
reg  [cache_valid - 1 : 0]valid0;
102
reg  [cache_valid - 1 : 0]valid1;
103
reg  [cache_valid - 1 : 0]valid2;
104
reg  [cache_valid - 1 : 0]valid3;
105
wire [cache_tag - 1 : 0]tag;
106
wire [cache_tag - 1 : 0]read_tag0;
107
wire [cache_tag - 1 : 0]read_tag1;
108
wire [cache_tag - 1 : 0]read_tag2;
109
wire [cache_tag - 1 : 0]read_tag3;
110
 
111
/********* Internal Register of Data cache configuration *********/
112
reg [cache_reg_width - 1 : 0] cache_register [cache_reg_depth - 1 : 0];
113
 
114
 
115
 
116
// Assignment statments
117
assign cache_bus_request = cache_miss;
118
assign cache_wr = (cache_host_cmd == 010) ? 1'b1 : 1'b0;
119
 
120
assign tag = cache_host_addr[23:5];
121
assign read_tag0 = data_cache_dataout_way0[50:32];
122
assign read_tag1 = data_cache_dataout_way1[50:32];
123
assign read_tag2 = data_cache_dataout_way2[50:32];
124
assign read_tag3 = data_cache_dataout_way3[50:32];
125
assign data_cache_datain_way0 = ({valid0,tag,cache_datain});
126
assign data_cache_datain_way1 = ({valid1,tag,cache_datain});
127
assign data_cache_datain_way2 = ({valid2,tag,cache_datain});
128
assign data_cache_datain_way3 = ({valid3,tag,cache_datain});
129
 
130
/********************************** Sub Level Instantiation *********************************/
131
 
132
 
133
data_cache_way0 data_cache_way0_0 (// Input
134
                                                                                                                                .A(cache_host_addr[4:0]),
135
                                                                                                                                .CLK(clk0),
136
                                                                                                                                .D(data_cache_datain_way0),
137
                                                                                                                                .WE(cache_wr),
138
                                                                                                                                .SPO(data_cache_dataout_way0));
139
 
140
 
141
data_cache_way1 data_cache_way1_0 (// Input
142
                                                                                                                                .A(cache_host_addr[4:0]),
143
                                                                                                                                .CLK(clk0),
144
                                                                                                                                .D(data_cache_datain_way1),
145
                                                                                                                                .WE(cache_wr),
146
                                                                                                                                .SPO(data_cache_dataout_way1));
147
 
148
 
149
data_cache_way2 data_cache_way2_0 (// Input
150
                                                                                                                                .A(cache_host_addr[4:0]),
151
                                                                                                                                .CLK(clk0),
152
                                                                                                                                .D(data_cache_datain_way2),
153
                                                                                                                                .WE(cache_wr),
154
                                                                                                                                .SPO(data_cache_dataout_way2));
155
 
156
 
157
data_cache_way3 data_cache_way3_0 (// Input
158
                                                                                                                                .A(cache_host_addr[4:0]),
159
                                                                                                                                .CLK(clk0),
160
                                                                                                                                .D(data_cache_datain_way3),
161
                                                                                                                                .WE(cache_wr),
162
                                                                                                                                .SPO(data_cache_dataout_way3));
163
 
164
 
165
 
166
// Generate the LRU talbe
167
always @(posedge reset or posedge clk0)
168
begin
169
        if(reset == 1'b1)
170
        begin
171
                valid0 <= 2'b00;
172
                valid1 <= 2'b00;
173
                valid2 <= 2'b10;
174
                valid3 <= 2'b10;
175
        end
176
        else
177
                if((cache_wr == 1'b1) && (valid0 == 2'b00))
178
                        valid0 <= 2'b01;
179
                else
180
                if((cache_wr == 1'b1) && (valid0 == 2'b01))
181
                        valid0 <= 2'b00;
182
                else
183
                if((cache_wr == 1'b1) && (valid1 == 2'b00))
184
                        valid1 <= 2'b01;
185
                else
186
                if((cache_wr == 1'b1) && (valid1 == 2'b01))
187
                        valid1 <= 2'b00;
188
                else
189
                if((cache_wr == 1'b1) && (valid2 == 2'b10))
190
                        valid2 <= 2'b11;
191
                else
192
                if((cache_wr == 1'b1) && (valid2 == 2'b11))
193
                        valid2 <= 2'b10;
194
                else
195
                if((cache_wr == 1'b1) && (valid3 == 2'b10))
196
                        valid3 <= 2'b11;
197
                else
198
                if((cache_wr == 1'b1) && (valid3 == 2'b11))
199
                        valid3 <= 2'b10;
200
end
201
 
202
 
203
// Check for cache way validity, if matches generate the cache hit signal
204
// else generate cache miss signal
205
always @(posedge reset or posedge clk0)
206
begin
207
        if(reset == 1'b1)
208
                cache_dataout <= 32'h0;
209
        else
210
        if((cache_request == 1'b1) && (cache_host_cmd == 001) && (read_tag0 == cache_host_addr[23:5]))
211
        begin
212
                cache_hit <= 1'b1;
213
                cache_dataout <= data_cache_dataout_way0[31:0];
214
        end
215
        else
216
        if((cache_request == 1'b1) && (cache_host_cmd == 001) && (read_tag1 == cache_host_addr[23:5]))
217
        begin
218
                cache_hit <= 1'b1;
219
                cache_dataout <= data_cache_dataout_way1[31:0];
220
        end
221
        else
222
        if((cache_request == 1'b1) && (cache_host_cmd == 001) && (read_tag2 == cache_host_addr[23:5]))
223
        begin
224
                cache_hit <= 1'b1;
225
                cache_dataout <= data_cache_dataout_way2[31:0];
226
        end
227
        else
228
        if((cache_request == 1'b1) && (cache_host_cmd == 001) && (read_tag3 == cache_host_addr[23:5]))
229
        begin
230
                cache_hit <= 1'b1;
231
                cache_dataout <= data_cache_dataout_way3[31:0];
232
        end
233
        else
234
        if((cache_request == 1'b1) && (cache_host_cmd == 001))
235
        begin
236
                cache_miss <= 1'b1;
237
                cache_hit  <= 1'b0;
238
                cache_dataout <= 32'h0;
239
        end
240
        else
241
        begin
242
                cache_miss <= 1'b0;
243
                cache_hit  <= 1'b0;
244
                cache_dataout <= 32'h0;
245
        end
246
end
247
 
248
 
249
// Access to internal register by CPU address and command signals (write/read)
250
always @(posedge reset or posedge clk0)
251
begin
252
        if(reset == 1'b1)
253
        begin
254
                cache_host_dataout <= 32'h0;
255
                cache_register[0] <= 32'h0;
256
                cache_register[1] <= 32'h0;
257
                cache_register[2] <= 32'h0;
258
                cache_register[3] <= 32'h0;
259
                cache_register[4] <= 32'h0;
260
                cache_register[5] <= 32'h0;
261
                cache_register[6] <= 32'h0;
262
                cache_register[7] <= 32'h0;
263
        end
264
        else
265
        begin
266
                if(cache_host_cmd == 3'b010)    // Write from Host to Cache internal Registers
267
                begin
268
                        case (cache_host_addr)
269
 
270
                                24'h080010:     cache_register[0] <= cache_host_datain;  // Status Register
271
                                24'h080011:     cache_register[1] <= cache_host_datain; // Read Master Start Address
272
                                24'h080012:     cache_register[2] <= cache_host_datain; // Write Master Start Address
273
                                24'h080013:     cache_register[3] <= cache_host_datain; // Length in Bytes
274
                                24'h080014:     cache_register[4] <= cache_host_datain; // Reserved
275
                                24'h080015:     cache_register[5] <= cache_host_datain;         // Reserved
276
                                24'h080016:     cache_register[6] <= cache_host_datain; // Control
277
                                24'h080017:     cache_register[7] <= cache_host_datain;         // Reserved
278
                        endcase
279
                end
280
                else
281
                if(cache_host_cmd == 3'b001)    // Read from Cache internal Registers to Host
282
                begin
283
                        case (cache_host_addr)
284
 
285
                                24'h080010:     cache_host_dataout <= cache_register[0];
286
                                24'h080011:     cache_host_dataout <= cache_register[1];
287
                                24'h080012:     cache_host_dataout <= cache_register[2];
288
                                24'h080013:     cache_host_dataout <= cache_register[3];
289
                                24'h080014:     cache_host_dataout <= cache_register[4];
290
                                24'h080015:     cache_host_dataout <= cache_register[5];
291
                                24'h080016:     cache_host_dataout <= cache_register[6];
292
                                24'h080017:     cache_host_dataout <= cache_register[7];
293
                        endcase
294
                end
295
        end
296
end
297
 
298
 
299
always @(posedge reset or posedge clk0)
300
begin
301
        if(reset == 1'b1)
302
        begin
303
                cache_addr <= 24'h0;
304
                cache_cmd <= 3'h0;
305
        end
306
        else
307
        begin
308
                cache_addr <= cache_bus_grant & cache_host_addr;
309
                cache_cmd <= cache_bus_grant & cache_host_cmd;
310
        end
311
end
312
 
313
endmodule

powered by: WebSVN 2.1.0

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