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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_icache.v] - Blame information for rev 88

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 67 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 instruction cache                                      ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  8051 instruction cache                                      ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Simon Teran, simont@opencores.org                     ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43 62 simont
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47 88 simont
// Revision 1.3  2003/01/13 14:14:41  simont
48
// replace some modules
49
//
50 82 simont
// Revision 1.2  2002/10/24 13:34:02  simont
51
// add parameters for instruction cache
52
//
53 67 simont
// Revision 1.1  2002/10/23 16:55:36  simont
54
// fix bugs in instruction interface
55 62 simont
//
56 67 simont
//
57 62 simont
 
58
// synopsys translate_off
59
`include "oc8051_timescale.v"
60
// synopsys translate_on
61
 
62
 
63
module oc8051_icache (rst, clk, adr_i, dat_o,stb_i, ack_o, cyc_i,
64
        dat_i, cyc_o, adr_o, ack_i, stb_o);
65
//
66
// rst           (in)  reset - pin
67
// clk           (in)  clock - pini
68
input rst, clk;
69
 
70
//
71
// interface to oc8051 cpu
72
//
73
// adr_i    (in)  address
74
// dat_o    (out) data output
75
// stb_i    (in)  strobe
76
// ack_o    (out) acknowledge
77
// cyc_i    (in)  cycle
78
input stb_i, cyc_i;
79
input [15:0] adr_i;
80
output ack_o;
81
output [31:0] dat_o;
82
reg [31:0] dat_o;
83
 
84
//
85
// interface to instruction rom
86
//
87
// adr_o    (out) address
88
// dat_i    (in)  data input
89
// stb_o    (out) strobe
90
// ack_i    (in) acknowledge
91
// cyc_o    (out)  cycle
92
input ack_i;
93
input [31:0] dat_i;
94
output stb_o, cyc_o;
95
output [15:0] adr_o;
96 67 simont
//reg [15:0] adr_o;
97 62 simont
reg stb_o, cyc_o;
98
 
99 67 simont
parameter ADR_WIDTH = 6; // cache address wihth
100
parameter LINE_WIDTH = 2; // line address width (2 => 4x32)
101
parameter BL_WIDTH = ADR_WIDTH - LINE_WIDTH; // block address width
102
parameter BL_NUM = 15; // number of blocks (2^BL_WIDTH-1)
103
parameter CACHE_RAM = 64; // cache ram x 32 (2^ADR_WIDTH)
104
 
105 62 simont
//
106
// internal buffers adn wires
107
//
108 67 simont
// con_buf control buffer, contains upper addresses [15:ADDR_WIDTH1] in cache
109
reg [13-ADR_WIDTH:0] con_buf [BL_NUM:0];
110 88 simont
// valid[x]=1 if block x is valid;
111
reg [BL_NUM:0] valid;
112 62 simont
// con0, con2 contain temporal control information of current address and corrent address+2
113 67 simont
// part of con_buf memory
114
reg [14-ADR_WIDTH:0] con0, con2;
115
//current upper address,
116
reg [13-ADR_WIDTH:0] cadr0, cadr2;
117 62 simont
reg stb_b;
118 67 simont
// byte_select in 32 bit line (adr_i[1:0])
119 62 simont
reg [1:0] byte_sel;
120 67 simont
// read cycle
121
reg [LINE_WIDTH-1:0] cyc;
122
// data input from cache ram
123 62 simont
reg [31:0] data1_i;
124 67 simont
// temporaly data from ram
125 62 simont
reg [15:0] tmp_data1;
126
reg wr1, wr1_t, stb_it;
127
 
128
wire [31:0] data0, data1_o;
129
wire cy, cy1;
130 67 simont
wire [BL_WIDTH-1:0] adr_i2;
131 62 simont
wire hit, hit_l, hit_h;
132 67 simont
wire [ADR_WIDTH-1:0] adr_r, addr1;
133
reg [ADR_WIDTH-1:0] adr_w;
134 62 simont
reg [15:0] mis_adr;
135
wire [15:0] data1;
136 67 simont
wire [LINE_WIDTH-1:0] adr_r1;
137 62 simont
 
138 67 simont
 
139
assign cy = &adr_i[LINE_WIDTH+1:1];
140
assign {cy1, adr_i2} = {1'b0, adr_i[ADR_WIDTH+1:LINE_WIDTH+2]}+cy;
141 62 simont
assign hit_l =(con0=={cadr0,1'b1});
142
assign hit_h =(con2=={cadr2,1'b1});
143
assign hit = hit_l && hit_h;
144
 
145 67 simont
assign adr_r = adr_i[ADR_WIDTH+1:2] + adr_i[1];
146 62 simont
assign addr1 = wr1 ? adr_w : adr_r;
147 67 simont
assign adr_r1 = adr_r[LINE_WIDTH-1:0] + 2'b01;
148 62 simont
//assign ack_o = hit;
149
assign ack_o = hit && stb_it;
150
 
151
assign data1 = wr1_t ? tmp_data1 : data1_o[31:16];
152
 
153 67 simont
assign adr_o = {mis_adr[15:LINE_WIDTH+2], cyc, 2'b00};
154
 
155
 
156
oc8051_cache_ram oc8051_cache_ram1(.clk(clk), .rst(rst), .addr0(adr_i[ADR_WIDTH+1:2]),
157
       .addr1(addr1), .data0(data0), .data1_o(data1_o), .data1_i(data1_i),
158 62 simont
       .wr1(wr1));
159
 
160 67 simont
defparam oc8051_cache_ram1.ADR_WIDTH = ADR_WIDTH;
161
defparam oc8051_cache_ram1.CACHE_RAM = CACHE_RAM;
162
 
163 62 simont
always @(stb_b or data0 or data1 or byte_sel)
164
begin
165
  if (stb_b) begin
166
    case (byte_sel)
167 88 simont
      2'b00  : dat_o = data0;
168
      2'b01  : dat_o = {data0[23:0], data1[15:8]};
169
      2'b10  : dat_o = {data0[15:0], data1};
170
      default: dat_o = {data0[ 7:0], data1, 8'h00};
171 62 simont
    endcase
172 67 simont
  end else begin
173 62 simont
    dat_o = 32'h0;
174
  end
175
end
176
 
177
always @(posedge clk or posedge rst)
178
begin
179 88 simont
  if (rst)
180
    begin
181
        con0 <= #1 9'h0;
182
        con2 <= #1 9'h0;
183
    end
184
  else
185
    begin
186
        con0 <= #1 {con_buf[adr_i[ADR_WIDTH+1:LINE_WIDTH+2]], valid[adr_i[ADR_WIDTH+1:LINE_WIDTH+2]]};
187
        con2 <= #1 {con_buf[adr_i2], valid[adr_i2]};
188
    end
189 62 simont
end
190
 
191
always @(posedge clk or posedge rst)
192
begin
193
  if (rst) begin
194
    cadr0 <= #1 8'h00;
195
    cadr2 <= #1 8'h00;
196
  end else begin
197 67 simont
    cadr0 <= #1 adr_i[15:ADR_WIDTH+2];
198
    cadr2 <= #1 adr_i[15:ADR_WIDTH+2]+ cy1;
199 62 simont
  end
200
end
201
 
202
always @(posedge clk or posedge rst)
203
begin
204
  if (rst) begin
205
    stb_b <= #1 1'b0;
206 67 simont
    byte_sel <= #1 2'b00;
207 62 simont
  end else begin
208
    stb_b <= #1 stb_i;
209
    byte_sel <= #1 adr_i[1:0];
210
  end
211
end
212
 
213
always @(posedge clk or posedge rst)
214
begin
215 88 simont
  if (rst)
216
    begin
217
        cyc    <= #1 2'b00;
218
        cyc_o  <= #1 1'b0;
219
        stb_o  <= #1 1'b0;
220
        data1_i<= #1 32'h0;
221
        wr1    <= #1 1'b0;
222
        adr_w  <= #1 6'h0;
223
        valid  <= #1 16'h0;
224
    end
225
  else if (stb_b && !hit && !stb_o && !wr1)
226
    begin
227
        cyc     <= #1 2'b00;
228
        cyc_o   <= #1 1'b1;
229
        stb_o   <= #1 1'b1;
230
        data1_i <= #1 32'h0;
231
        wr1     <= #1 1'b0;
232
    end
233
  else if (stb_o && ack_i)
234
    begin
235
        data1_i<= #1 dat_i;
236
        wr1    <= #1 1'b1;
237
        adr_w  <= #1 adr_o[ADR_WIDTH+1:2];
238
 
239
        if (&cyc)
240
          begin
241
              cyc   <= #1 2'b00;
242
              cyc_o <= #1 1'b0;
243
              stb_o <= #1 1'b0;
244
//              con_buf[mis_adr[ADR_WIDTH+1:LINE_WIDTH+2]] <= #1 mis_adr[15:ADR_WIDTH+2];
245
              valid[mis_adr[ADR_WIDTH+1:LINE_WIDTH+2]] <= #1 1'b1;
246
          end
247
        else
248
          begin
249
              cyc   <= #1 cyc + 1'b1;
250
              cyc_o <= #1 1'b1;
251
              stb_o <= #1 1'b1;
252
          end
253
 
254
 
255
/*    case (cyc)
256
      2'b00: begin
257
        cyc <= #1 2'b01;
258
        cyc_o <= #1 1'b1;
259
        stb_o <= #1 1'b1;
260
      end
261
      2'b01: begin
262
        cyc <= #1 2'b10;
263
        cyc_o <= #1 1'b1;
264
        stb_o <= #1 1'b1;
265
      end
266
      2'b10: begin
267
        cyc <= #1 2'b11;
268
        cyc_o <= #1 1'b1;
269
        stb_o <= #1 1'b1;
270
      end
271
      default: begin
272 67 simont
        cyc <= #1 2'b00;
273
        cyc_o <= #1 1'b0;
274
        stb_o <= #1 1'b0;
275 88 simont
        con_buf[mis_adr[7:4]] <= #1 mis_adr[15:8];
276
        valid[mis_adr[7:4]] <= #1 1'b1;
277
      end
278
    endcase*/
279 67 simont
    end
280 88 simont
  else
281 62 simont
    wr1 <= #1 1'b0;
282
end
283
 
284 88 simont
//rih
285
always @(posedge clk)
286
  if ( ~(stb_b && !hit && !stb_o && !wr1) & (stb_o && ack_i & &cyc) )
287
    con_buf[mis_adr[ADR_WIDTH+1:LINE_WIDTH+2]] <= #1 mis_adr[15:ADR_WIDTH+2];
288
 
289
 
290 62 simont
always @(posedge clk or posedge rst)
291
begin
292
  if (rst)
293 88 simont
    mis_adr <= #1 1'b0;
294 62 simont
  else if (!hit_l)
295
    mis_adr <= #1 adr_i;
296
  else if (!hit_h)
297 67 simont
    mis_adr <= #1 adr_i+'d2;
298
end
299 62 simont
 
300
always @(posedge clk or posedge rst)
301
begin
302
  if (rst)
303 88 simont
    tmp_data1 <= #1 1'b0;
304 62 simont
  else if (!hit_h && wr1 && (cyc==adr_r1))
305
    tmp_data1 <= #1 dat_i[31:16];
306
  else if (!hit_l && hit_h && wr1)
307
    tmp_data1 <= #1 data1_o[31:16];
308 67 simont
end
309 62 simont
 
310
always @(posedge clk or posedge rst)
311
begin
312
  if (rst) begin
313
    wr1_t <= #1 1'b0;
314
    stb_it <= #1 1'b0;
315
  end else begin
316
    wr1_t <= #1 wr1;
317 67 simont
    stb_it <= #1 stb_i;
318 62 simont
  end
319
end
320
 
321
endmodule
322 88 simont
 

powered by: WebSVN 2.1.0

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