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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_26/] [or1200/] [rtl/] [verilog/] [or1200_wb_biu.v] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's WISHBONE BIU                                       ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Implements WISHBONE interface                               ////
10
////                                                              ////
11
////  To Do:                                                      ////
12 1054 lampret
////   - if biu_cyc/stb are deasserted and wb_ack_i is asserted   ////
13
////   and this happens even before aborted_r is asssrted,        ////
14
////   wb_ack_i will be delivered even though transfer is         ////
15
////   internally considered already aborted. However most        ////
16
////   wb_ack_i are externally registered and delayed. Normally   ////
17
////   this shouldn't cause any problems.                         ////
18 504 lampret
////                                                              ////
19
////  Author(s):                                                  ////
20
////      - Damjan Lampret, lampret@opencores.org                 ////
21
////                                                              ////
22
//////////////////////////////////////////////////////////////////////
23
////                                                              ////
24
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
25
////                                                              ////
26
//// This source file may be used and distributed without         ////
27
//// restriction provided that this copyright statement is not    ////
28
//// removed from the file and that any derivative work contains  ////
29
//// the original copyright notice and the associated disclaimer. ////
30
////                                                              ////
31
//// This source file is free software; you can redistribute it   ////
32
//// and/or modify it under the terms of the GNU Lesser General   ////
33
//// Public License as published by the Free Software Foundation; ////
34
//// either version 2.1 of the License, or (at your option) any   ////
35
//// later version.                                               ////
36
////                                                              ////
37
//// This source is distributed in the hope that it will be       ////
38
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
39
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
40
//// PURPOSE.  See the GNU Lesser General Public License for more ////
41
//// details.                                                     ////
42
////                                                              ////
43
//// You should have received a copy of the GNU Lesser General    ////
44
//// Public License along with this source; if not, download it   ////
45
//// from http://www.opencores.org/lgpl.shtml                     ////
46
////                                                              ////
47
//////////////////////////////////////////////////////////////////////
48
//
49
// CVS Revision History
50
//
51
// $Log: not supported by cvs2svn $
52 1171 lampret
// Revision 1.6  2003/04/07 20:57:46  lampret
53
// Fixed OR1200_CLKDIV_x_SUPPORTED defines. Fixed order of ifdefs.
54
//
55 1140 lampret
// Revision 1.5  2002/12/08 08:57:56  lampret
56
// Added optional support for WB B3 specification (xwb_cti_o, xwb_bte_o). Made xwb_cab_o optional.
57
//
58 1104 lampret
// Revision 1.4  2002/09/16 03:09:16  lampret
59
// Fixed a combinational loop.
60
//
61 1054 lampret
// Revision 1.3  2002/08/12 05:31:37  lampret
62
// Added optional retry counter for wb_rty_i. Added graceful termination for aborted transfers.
63
//
64 943 lampret
// Revision 1.2  2002/07/14 22:17:17  lampret
65
// Added simple trace buffer [only for Xilinx Virtex target]. Fixed instruction fetch abort when new exception is recognized.
66
//
67 895 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
68
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
69
//
70 504 lampret
// Revision 1.12  2001/11/22 13:42:51  lampret
71
// Added wb_cyc_o assignment after it was removed by accident.
72
//
73
// Revision 1.11  2001/11/20 21:28:10  lampret
74
// Added optional sampling of inputs.
75
//
76
// Revision 1.10  2001/11/18 11:32:00  lampret
77
// OR1200_REGISTERED_OUTPUTS can now be enabled.
78
//
79
// Revision 1.9  2001/10/21 17:57:16  lampret
80
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
81
//
82
// Revision 1.8  2001/10/14 13:12:10  lampret
83
// MP3 version.
84
//
85
// Revision 1.1.1.1  2001/10/06 10:18:35  igorm
86
// no message
87
//
88
// Revision 1.3  2001/08/09 13:39:33  lampret
89
// Major clean-up.
90
//
91
// Revision 1.2  2001/07/22 03:31:54  lampret
92
// Fixed RAM's oen bug. Cache bypass under development.
93
//
94
// Revision 1.1  2001/07/20 00:46:23  lampret
95
// Development version of RTL. Libraries are missing.
96
//
97
//
98
 
99
// synopsys translate_off
100
`include "timescale.v"
101
// synopsys translate_on
102
`include "or1200_defines.v"
103
 
104
module or1200_wb_biu(
105
        // RISC clock, reset and clock control
106
        clk, rst, clmode,
107
 
108
        // WISHBONE interface
109
        wb_clk_i, wb_rst_i, wb_ack_i, wb_err_i, wb_rty_i, wb_dat_i,
110 1104 lampret
        wb_cyc_o, wb_adr_o, wb_stb_o, wb_we_o, wb_sel_o, wb_dat_o,
111
`ifdef OR1200_WB_CAB
112
        wb_cab_o,
113
`endif
114
`ifdef OR1200_WB_B3
115
        wb_cti_o, wb_bte_o,
116
`endif
117 504 lampret
 
118
        // Internal RISC bus
119
        biu_dat_i, biu_adr_i, biu_cyc_i, biu_stb_i, biu_we_i, biu_sel_i, biu_cab_i,
120
        biu_dat_o, biu_ack_o, biu_err_o
121
);
122
 
123
parameter dw = `OR1200_OPERAND_WIDTH;
124
parameter aw = `OR1200_OPERAND_WIDTH;
125
 
126
//
127
// RISC clock, reset and clock control
128
//
129
input                   clk;            // RISC clock
130
input                   rst;            // RISC reset
131
input   [1:0]            clmode;         // 00 WB=RISC, 01 WB=RISC/2, 10 N/A, 11 WB=RISC/4
132
 
133
//
134
// WISHBONE interface
135
//
136
input                   wb_clk_i;       // clock input
137
input                   wb_rst_i;       // reset input
138
input                   wb_ack_i;       // normal termination
139
input                   wb_err_i;       // termination w/ error
140
input                   wb_rty_i;       // termination w/ retry
141
input   [dw-1:0] wb_dat_i;       // input data bus
142
output                  wb_cyc_o;       // cycle valid output
143
output  [aw-1:0] wb_adr_o;       // address bus outputs
144
output                  wb_stb_o;       // strobe output
145
output                  wb_we_o;        // indicates write transfer
146
output  [3:0]            wb_sel_o;       // byte select outputs
147 1104 lampret
output  [dw-1:0] wb_dat_o;       // output data bus
148
`ifdef OR1200_WB_CAB
149 504 lampret
output                  wb_cab_o;       // consecutive address burst
150 1104 lampret
`endif
151
`ifdef OR1200_WB_B3
152
output  [2:0]            wb_cti_o;       // cycle type identifier
153
output  [1:0]            wb_bte_o;       // burst type extension
154
`endif
155 504 lampret
 
156
//
157
// Internal RISC interface
158
//
159
input   [dw-1:0] biu_dat_i;      // input data bus
160
input   [aw-1:0] biu_adr_i;      // address bus
161
input                   biu_cyc_i;      // WB cycle
162
input                   biu_stb_i;      // WB strobe
163
input                   biu_we_i;       // WB write enable
164
input                   biu_cab_i;      // CAB input
165
input   [3:0]            biu_sel_i;      // byte selects
166
output  [31:0]           biu_dat_o;      // output data bus
167
output                  biu_ack_o;      // ack output
168
output                  biu_err_o;      // err output
169
 
170
//
171
// Registers
172
//
173
reg     [1:0]            valid_div;      // Used for synchronization
174
`ifdef OR1200_REGISTERED_OUTPUTS
175
reg     [aw-1:0] wb_adr_o;       // address bus outputs
176
reg                     wb_cyc_o;       // cycle output
177
reg                     wb_stb_o;       // strobe output
178
reg                     wb_we_o;        // indicates write transfer
179
reg     [3:0]            wb_sel_o;       // byte select outputs
180 1104 lampret
`ifdef OR1200_WB_CAB
181 504 lampret
reg                     wb_cab_o;       // CAB output
182 1104 lampret
`endif
183
`ifdef OR1200_WB_B3
184
reg     [1:0]            burst_len;      // burst counter
185
reg     [2:0]            wb_cti_o;       // cycle type identifier
186
`endif
187 504 lampret
reg     [dw-1:0] wb_dat_o;       // output data bus
188
`endif
189
`ifdef OR1200_REGISTERED_INPUTS
190
reg                     long_ack_o;     // normal termination
191
reg                     long_err_o;     // error termination
192
reg     [dw-1:0] biu_dat_o;      // output data bus
193
`else
194
wire                    long_ack_o;     // normal termination
195
wire                    long_err_o;     // error termination
196
`endif
197 943 lampret
wire                    aborted;        // Graceful abort
198
reg                     aborted_r;      // Graceful abort
199
wire                    retry;          // Retry
200
`ifdef OR1200_WB_RETRY
201
reg     [`OR1200_WB_RETRY-1:0] retry_cntr;       // Retry counter
202
`endif
203 504 lampret
 
204
//
205
// WISHBONE I/F <-> Internal RISC I/F conversion
206
//
207
 
208
//
209
// Address bus
210
//
211
`ifdef OR1200_REGISTERED_OUTPUTS
212
always @(posedge wb_clk_i or posedge wb_rst_i)
213
        if (wb_rst_i)
214
                wb_adr_o <= #1 {aw{1'b0}};
215 943 lampret
        else if ((biu_cyc_i & biu_stb_i) & ~wb_ack_i & ~aborted & ~(wb_stb_o & ~wb_ack_i))
216 504 lampret
                wb_adr_o <= #1 biu_adr_i;
217
`else
218
assign wb_adr_o = biu_adr_i;
219
`endif
220
 
221
//
222
// Input data bus
223
//
224
`ifdef OR1200_REGISTERED_INPUTS
225
always @(posedge wb_clk_i or posedge wb_rst_i)
226
        if (wb_rst_i)
227
                biu_dat_o <= #1 32'h0000_0000;
228
        else if (wb_ack_i)
229
                biu_dat_o <= #1 wb_dat_i;
230
`else
231
assign biu_dat_o = wb_dat_i;
232
`endif
233
 
234
//
235
// Output data bus
236
//
237
`ifdef OR1200_REGISTERED_OUTPUTS
238
always @(posedge wb_clk_i or posedge wb_rst_i)
239
        if (wb_rst_i)
240
                wb_dat_o <= #1 {dw{1'b0}};
241 943 lampret
        else if ((biu_cyc_i & biu_stb_i) & ~wb_ack_i & ~aborted)
242 504 lampret
                wb_dat_o <= #1 biu_dat_i;
243
`else
244
assign wb_dat_o = biu_dat_i;
245
`endif
246
 
247
//
248
// Valid_div counts RISC clock cycles by modulo 4
249
// and is used to synchronize external WB i/f to
250
// RISC clock
251
//
252
always @(posedge clk or posedge rst)
253
        if (rst)
254
                valid_div <= #1 2'b0;
255
        else
256 1171 lampret
                valid_div <= #1 valid_div + 1'd1;
257 504 lampret
 
258
//
259
// biu_ack_o is one RISC clock cycle long long_ack_o.
260
// long_ack_o is one, two or four RISC clock cycles long because
261
// WISHBONE can work at 1, 1/2 or 1/4 RISC clock.
262
//
263
assign biu_ack_o = long_ack_o
264 1140 lampret
`ifdef OR1200_CLKDIV_2_SUPPORTED
265
                & (valid_div[0] | ~clmode[0])
266 504 lampret
`ifdef OR1200_CLKDIV_4_SUPPORTED
267
                & (valid_div[1] | ~clmode[1])
268
`endif
269
`endif
270
                ;
271
 
272
//
273
// Acknowledgment of the data to the RISC
274
//
275
// long_ack_o
276
//
277
`ifdef OR1200_REGISTERED_INPUTS
278
always @(posedge wb_clk_i or posedge wb_rst_i)
279
        if (wb_rst_i)
280
                long_ack_o <= #1 1'b0;
281
        else
282 943 lampret
                long_ack_o <= #1 wb_ack_i & ~aborted;
283 504 lampret
`else
284 1054 lampret
assign long_ack_o = wb_ack_i & ~aborted_r;
285 504 lampret
`endif
286
 
287
//
288
// biu_err_o is one RISC clock cycle long long_err_o.
289
// long_err_o is one, two or four RISC clock cycles long because
290
// WISHBONE can work at 1, 1/2 or 1/4 RISC clock.
291
//
292
assign biu_err_o = long_err_o
293 1140 lampret
`ifdef OR1200_CLKDIV_2_SUPPORTED
294
                & (valid_div[0] | ~clmode[0])
295 504 lampret
`ifdef OR1200_CLKDIV_4_SUPPORTED
296
                & (valid_div[1] | ~clmode[1])
297
`endif
298
`endif
299
                ;
300
 
301
//
302
// Error termination
303
//
304
// long_err_o
305
//
306
`ifdef OR1200_REGISTERED_INPUTS
307
always @(posedge wb_clk_i or posedge wb_rst_i)
308
        if (wb_rst_i)
309
                long_err_o <= #1 1'b0;
310
        else
311 943 lampret
                long_err_o <= #1 wb_err_i & ~aborted;
312 504 lampret
`else
313 1054 lampret
assign long_err_o = wb_err_i & ~aborted_r;
314 504 lampret
`endif
315
 
316
//
317 943 lampret
// Retry counter
318
//
319
// Assert 'retry' when 'wb_rty_i' is sampled high and keep it high
320
// until retry counter doesn't expire
321
// 
322
`ifdef OR1200_WB_RETRY
323
assign retry = wb_rty_i | (|retry_cntr);
324
`else
325
assign retry = 1'b0;
326
`endif
327
`ifdef OR1200_WB_RETRY
328
always @(posedge wb_clk_i or posedge wb_rst_i)
329
        if (wb_rst_i)
330
                retry_cntr <= #1 1'b0;
331
        else if (wb_rty_i)
332
                retry_cntr <= #1 {`OR1200_WB_RETRY{1'b1}};
333
        else if (retry_cntr)
334
                retry_cntr <= #1 retry_cntr - 7'd1;
335
`endif
336
 
337
//
338
// Graceful completion of aborted transfers
339
//
340
// Assert 'aborted' when 1) current transfer is in progress (wb_stb_o; which
341
// we know is only asserted together with wb_cyc_o) 2) and in next WB clock cycle
342
// wb_stb_o would be deasserted (biu_cyc_i and biu_stb_i are low) 3) and
343
// there is no termination of current transfer in this WB clock cycle (wb_ack_i
344
// and wb_err_i are low).
345 1054 lampret
// 'aborted_r' is registered 'aborted' and extended until this "aborted" transfer
346 943 lampret
// is properly terminated with wb_ack_i/wb_err_i.
347
// 
348 1054 lampret
assign aborted = wb_stb_o & ~(biu_cyc_i & biu_stb_i) & ~(wb_ack_i | wb_err_i);
349 943 lampret
always @(posedge wb_clk_i or posedge wb_rst_i)
350
        if (wb_rst_i)
351
                aborted_r <= #1 1'b0;
352
        else if (wb_ack_i | wb_err_i)
353
                aborted_r <= #1 1'b0;
354
        else if (aborted)
355
                aborted_r <= #1 1'b1;
356
 
357
//
358 504 lampret
// WB cyc_o
359
//
360 943 lampret
// Either 1) normal transfer initiated by biu_cyc_i (and biu_cab_i if
361
// bursts are enabled) and possibly suspended by 'retry'
362
// or 2) extended "aborted" transfer
363
//
364 504 lampret
`ifdef OR1200_REGISTERED_OUTPUTS
365
always @(posedge wb_clk_i or posedge wb_rst_i)
366
        if (wb_rst_i)
367
                wb_cyc_o <= #1 1'b0;
368
        else
369 895 lampret
`ifdef OR1200_NO_BURSTS
370 943 lampret
                wb_cyc_o <= #1 biu_cyc_i & ~wb_ack_i & ~retry | aborted & ~wb_ack_i;
371 895 lampret
`else
372 943 lampret
                wb_cyc_o <= #1 biu_cyc_i & ~wb_ack_i & ~retry | biu_cab_i | aborted & ~wb_ack_i;
373 895 lampret
`endif
374 504 lampret
`else
375 895 lampret
`ifdef OR1200_NO_BURSTS
376 943 lampret
assign wb_cyc_o = biu_cyc_i & ~retry;
377 895 lampret
`else
378 943 lampret
assign wb_cyc_o = biu_cyc_i | biu_cab_i & ~retry;
379 504 lampret
`endif
380 895 lampret
`endif
381 504 lampret
 
382
//
383
// WB stb_o
384
//
385
`ifdef OR1200_REGISTERED_OUTPUTS
386
always @(posedge wb_clk_i or posedge wb_rst_i)
387
        if (wb_rst_i)
388
                wb_stb_o <= #1 1'b0;
389
        else
390 943 lampret
                wb_stb_o <= #1 (biu_cyc_i & biu_stb_i) & ~wb_ack_i & ~retry | aborted & ~wb_ack_i;
391 504 lampret
`else
392
assign wb_stb_o = biu_cyc_i & biu_stb_i;
393
`endif
394
 
395
//
396
// WB we_o
397
//
398
`ifdef OR1200_REGISTERED_OUTPUTS
399
always @(posedge wb_clk_i or posedge wb_rst_i)
400
        if (wb_rst_i)
401
                wb_we_o <= #1 1'b0;
402
        else
403 943 lampret
                wb_we_o <= #1 biu_cyc_i & biu_stb_i & biu_we_i | aborted & wb_we_o;
404 504 lampret
`else
405
assign wb_we_o = biu_cyc_i & biu_stb_i & biu_we_i;
406
`endif
407
 
408
//
409
// WB sel_o
410
//
411
`ifdef OR1200_REGISTERED_OUTPUTS
412
always @(posedge wb_clk_i or posedge wb_rst_i)
413
        if (wb_rst_i)
414
                wb_sel_o <= #1 4'b0000;
415
        else
416
                wb_sel_o <= #1 biu_sel_i;
417
`else
418
assign wb_sel_o = biu_sel_i;
419
`endif
420
 
421 1104 lampret
`ifdef OR1200_WB_CAB
422 504 lampret
//
423
// WB cab_o
424
//
425
`ifdef OR1200_REGISTERED_OUTPUTS
426
always @(posedge wb_clk_i or posedge wb_rst_i)
427
        if (wb_rst_i)
428
                wb_cab_o <= #1 1'b0;
429
        else
430
                wb_cab_o <= #1 biu_cab_i;
431
`else
432
assign wb_cab_o = biu_cab_i;
433
`endif
434 1104 lampret
`endif
435 504 lampret
 
436 1104 lampret
`ifdef OR1200_WB_B3
437
//
438
// Count burst beats
439
//
440
always @(posedge wb_clk_i or posedge wb_rst_i)
441
        if (wb_rst_i)
442
                burst_len <= #1 2'b00;
443
        else if (biu_cab_i && burst_len && wb_ack_i)
444
                burst_len <= #1 burst_len - 1'b1;
445
        else if (~biu_cab_i)
446
                burst_len <= #1 2'b11;
447
 
448
//
449
// WB cti_o
450
//
451
`ifdef OR1200_REGISTERED_OUTPUTS
452
always @(posedge wb_clk_i or posedge wb_rst_i)
453
        if (wb_rst_i)
454
                wb_cti_o <= #1 3'b000;  // classic cycle
455
`ifdef OR1200_NO_BURSTS
456
        else
457
                wb_cti_o <= #1 3'b111;  // end-of-burst
458
`else
459
        else if (biu_cab_i && burst_len[1])
460
                wb_cti_o <= #1 3'b010;  // incrementing burst cycle
461
        else if (biu_cab_i && wb_ack_i)
462
                wb_cti_o <= #1 3'b111;  // end-of-burst
463
`endif  // OR1200_NO_BURSTS
464
`else
465
Unsupported !!!;
466
`endif
467
 
468
//
469
// WB bte_o
470
//
471
assign wb_bte_o = 2'b01;        // 4-beat wrap burst
472
 
473
`endif  // OR1200_WB_B3
474
 
475 504 lampret
endmodule

powered by: WebSVN 2.1.0

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