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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_iwb_biu.v] - Blame information for rev 10

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

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
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
////   - 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
////                                                              ////
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
// Revision 1.1  2003/12/05 00:12:08  lampret
53
// New wb_biu for iwb interface.
54
//
55
// Revision 1.6.4.1  2003/07/08 15:36:37  lampret
56
// Added embedded memory QMEM.
57
//
58
// Revision 1.6  2003/04/07 20:57:46  lampret
59
// Fixed OR1200_CLKDIV_x_SUPPORTED defines. Fixed order of ifdefs.
60
//
61
// Revision 1.5  2002/12/08 08:57:56  lampret
62
// Added optional support for WB B3 specification (xwb_cti_o, xwb_bte_o). Made xwb_cab_o optional.
63
//
64
// Revision 1.4  2002/09/16 03:09:16  lampret
65
// Fixed a combinational loop.
66
//
67
// Revision 1.3  2002/08/12 05:31:37  lampret
68
// Added optional retry counter for wb_rty_i. Added graceful termination for aborted transfers.
69
//
70
// Revision 1.2  2002/07/14 22:17:17  lampret
71
// Added simple trace buffer [only for Xilinx Virtex target]. Fixed instruction fetch abort when new exception is recognized.
72
//
73
// Revision 1.1  2002/01/03 08:16:15  lampret
74
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
75
//
76
// Revision 1.12  2001/11/22 13:42:51  lampret
77
// Added wb_cyc_o assignment after it was removed by accident.
78
//
79
// Revision 1.11  2001/11/20 21:28:10  lampret
80
// Added optional sampling of inputs.
81
//
82
// Revision 1.10  2001/11/18 11:32:00  lampret
83
// OR1200_REGISTERED_OUTPUTS can now be enabled.
84
//
85
// Revision 1.9  2001/10/21 17:57:16  lampret
86
// 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.
87
//
88
// Revision 1.8  2001/10/14 13:12:10  lampret
89
// MP3 version.
90
//
91
// Revision 1.1.1.1  2001/10/06 10:18:35  igorm
92
// no message
93
//
94
// Revision 1.3  2001/08/09 13:39:33  lampret
95
// Major clean-up.
96
//
97
// Revision 1.2  2001/07/22 03:31:54  lampret
98
// Fixed RAM's oen bug. Cache bypass under development.
99
//
100
// Revision 1.1  2001/07/20 00:46:23  lampret
101
// Development version of RTL. Libraries are missing.
102
//
103
//
104
 
105
// synopsys translate_off
106
`include "timescale.v"
107
// synopsys translate_on
108
`include "or1200_defines.v"
109
 
110
module or1200_iwb_biu(
111
        // RISC clock, reset and clock control
112
        clk, rst, clmode,
113
 
114
        // WISHBONE interface
115
        wb_clk_i, wb_rst_i, wb_ack_i, wb_err_i, wb_rty_i, wb_dat_i,
116
        wb_cyc_o, wb_adr_o, wb_stb_o, wb_we_o, wb_sel_o, wb_dat_o,
117
`ifdef OR1200_WB_CAB
118
        wb_cab_o,
119
`endif
120
`ifdef OR1200_WB_B3
121
        wb_cti_o, wb_bte_o,
122
`endif
123
 
124
        // Internal RISC bus
125
        biu_dat_i, biu_adr_i, biu_cyc_i, biu_stb_i, biu_we_i, biu_sel_i, biu_cab_i,
126
        biu_dat_o, biu_ack_o, biu_err_o
127
);
128
 
129
parameter dw = `OR1200_OPERAND_WIDTH;
130
parameter aw = `OR1200_OPERAND_WIDTH;
131
 
132
//
133
// RISC clock, reset and clock control
134
//
135
input                   clk;            // RISC clock
136
input                   rst;            // RISC reset
137
input   [1:0]            clmode;         // 00 WB=RISC, 01 WB=RISC/2, 10 N/A, 11 WB=RISC/4
138
 
139
//
140
// WISHBONE interface
141
//
142
input                   wb_clk_i;       // clock input
143
input                   wb_rst_i;       // reset input
144
input                   wb_ack_i;       // normal termination
145
input                   wb_err_i;       // termination w/ error
146
input                   wb_rty_i;       // termination w/ retry
147
input   [dw-1:0] wb_dat_i;       // input data bus
148
output                  wb_cyc_o;       // cycle valid output
149
output  [aw-1:0] wb_adr_o;       // address bus outputs
150
output                  wb_stb_o;       // strobe output
151
output                  wb_we_o;        // indicates write transfer
152
output  [3:0]            wb_sel_o;       // byte select outputs
153
output  [dw-1:0] wb_dat_o;       // output data bus
154
`ifdef OR1200_WB_CAB
155
output                  wb_cab_o;       // consecutive address burst
156
`endif
157
`ifdef OR1200_WB_B3
158
output  [2:0]            wb_cti_o;       // cycle type identifier
159
output  [1:0]            wb_bte_o;       // burst type extension
160
`endif
161
 
162
//
163
// Internal RISC interface
164
//
165
input   [dw-1:0] biu_dat_i;      // input data bus
166
input   [aw-1:0] biu_adr_i;      // address bus
167
input                   biu_cyc_i;      // WB cycle
168
input                   biu_stb_i;      // WB strobe
169
input                   biu_we_i;       // WB write enable
170
input                   biu_cab_i;      // CAB input
171
input   [3:0]            biu_sel_i;      // byte selects
172
output  [31:0]           biu_dat_o;      // output data bus
173
output                  biu_ack_o;      // ack output
174
output                  biu_err_o;      // err output
175
 
176
//
177
// Registers
178
//
179
reg     [1:0]            valid_div;      // Used for synchronization
180
`ifdef OR1200_REGISTERED_OUTPUTS
181
reg     [aw-1:0] wb_adr_o;       // address bus outputs
182
reg                     wb_cyc_o;       // cycle output
183
reg                     wb_stb_o;       // strobe output
184
reg                     wb_we_o;        // indicates write transfer
185
reg     [3:0]            wb_sel_o;       // byte select outputs
186
`ifdef OR1200_WB_CAB
187
reg                     wb_cab_o;       // CAB output
188
`endif
189
`ifdef OR1200_WB_B3
190
reg     [1:0]            burst_len;      // burst counter
191
reg     [2:0]            wb_cti_o;       // cycle type identifier
192
`endif
193
reg     [dw-1:0] wb_dat_o;       // output data bus
194
`endif
195
`ifdef OR1200_REGISTERED_INPUTS
196
reg                     long_ack_o;     // normal termination
197
reg                     long_err_o;     // error termination
198
reg     [dw-1:0] biu_dat_o;      // output data bus
199
`else
200
wire                    long_ack_o;     // normal termination
201
wire                    long_err_o;     // error termination
202
`endif
203
wire                    aborted;        // Graceful abort
204
reg                     aborted_r;      // Graceful abort
205
wire                    retry;          // Retry
206
`ifdef OR1200_WB_RETRY
207
reg     [`OR1200_WB_RETRY-1:0] retry_cntr;       // Retry counter
208
`endif
209
reg                     previous_complete;
210
wire                    same_addr;
211
wire                    repeated_access;
212
reg                     repeated_access_ack;
213
reg     [dw-1:0] wb_dat_r;       // saved previous data read
214
 
215
//
216
// WISHBONE I/F <-> Internal RISC I/F conversion
217
//
218
 
219
//
220
// Address bus
221
//
222
`ifdef OR1200_REGISTERED_OUTPUTS
223
always @(posedge wb_clk_i or posedge wb_rst_i)
224
        if (wb_rst_i)
225
                wb_adr_o <= #1 {aw{1'b0}};
226
        else if ((biu_cyc_i & biu_stb_i) & ~wb_ack_i & ~aborted & ~(wb_stb_o & ~wb_ack_i) | biu_cab_i & (previous_complete | biu_ack_o))
227
                wb_adr_o <= #1 biu_adr_i;
228
`else
229
assign wb_adr_o = biu_adr_i;
230
`endif
231
 
232
//
233
// Same access as previous one, store previous read data
234
//
235
assign same_addr = wb_adr_o == biu_adr_i;
236
assign repeated_access = same_addr & previous_complete;
237
always @(posedge wb_clk_i or posedge wb_rst_i)
238
        if (wb_rst_i)
239
                wb_dat_r <= #1 32'h0000_0000;
240
        else if (wb_ack_i)
241
                wb_dat_r <= #1 wb_dat_i;
242
 
243
always @(posedge clk or posedge rst)
244
        if (rst)
245
                repeated_access_ack <= #1 1'b0;
246
        else if (repeated_access & biu_cyc_i & biu_stb_i)
247
                repeated_access_ack <= #1 1'b1;
248
        else
249
                repeated_access_ack <= #1 1'b0;
250
 
251
//
252
// Previous access completed
253
//
254
always @(posedge wb_clk_i or posedge wb_rst_i)
255
        if (wb_rst_i)
256
                previous_complete <= #1 1'b1;
257
        else if (wb_ack_i & biu_cyc_i & biu_stb_i)
258
                previous_complete <= #1 1'b1;
259
        else if ((biu_cyc_i & biu_stb_i) & ~wb_ack_i & ~aborted & ~(wb_stb_o & ~wb_ack_i))
260
                previous_complete <= #1 1'b0;
261
 
262
//
263
// Input data bus
264
//
265
`ifdef OR1200_REGISTERED_INPUTS
266
always @(posedge wb_clk_i or posedge wb_rst_i)
267
        if (wb_rst_i)
268
                biu_dat_o <= #1 32'h0000_0000;
269
        else if (wb_ack_i)
270
                biu_dat_o <= #1 wb_dat_i;
271
`else
272
assign biu_dat_o = repeated_access_ack ? wb_dat_r : wb_dat_i;
273
`endif
274
 
275
//
276
// Output data bus
277
//
278
`ifdef OR1200_REGISTERED_OUTPUTS
279
always @(posedge wb_clk_i or posedge wb_rst_i)
280
        if (wb_rst_i)
281
                wb_dat_o <= #1 {dw{1'b0}};
282
        else if ((biu_cyc_i & biu_stb_i) & ~wb_ack_i & ~aborted)
283
                wb_dat_o <= #1 biu_dat_i;
284
`else
285
assign wb_dat_o = biu_dat_i;
286
`endif
287
 
288
//
289
// Valid_div counts RISC clock cycles by modulo 4
290
// and is used to synchronize external WB i/f to
291
// RISC clock
292
//
293
always @(posedge clk or posedge rst)
294
        if (rst)
295
                valid_div <= #1 2'b0;
296
        else
297
                valid_div <= #1 valid_div + 1'd1;
298
 
299
//
300
// biu_ack_o is one RISC clock cycle long long_ack_o.
301
// long_ack_o is one, two or four RISC clock cycles long because
302
// WISHBONE can work at 1, 1/2 or 1/4 RISC clock.
303
//
304
assign biu_ack_o = (repeated_access_ack | long_ack_o) & ~aborted_r
305
`ifdef OR1200_CLKDIV_2_SUPPORTED
306
                & (valid_div[0] | ~clmode[0])
307
`ifdef OR1200_CLKDIV_4_SUPPORTED
308
                & (valid_div[1] | ~clmode[1])
309
`endif
310
`endif
311
                ;
312
 
313
//
314
// Acknowledgment of the data to the RISC
315
//
316
// long_ack_o
317
//
318
`ifdef OR1200_REGISTERED_INPUTS
319
always @(posedge wb_clk_i or posedge wb_rst_i)
320
        if (wb_rst_i)
321
                long_ack_o <= #1 1'b0;
322
        else
323
                long_ack_o <= #1 wb_ack_i & ~aborted;
324
`else
325
assign long_ack_o = wb_ack_i;
326
`endif
327
 
328
//
329
// biu_err_o is one RISC clock cycle long long_err_o.
330
// long_err_o is one, two or four RISC clock cycles long because
331
// WISHBONE can work at 1, 1/2 or 1/4 RISC clock.
332
//
333
assign biu_err_o = long_err_o
334
`ifdef OR1200_CLKDIV_2_SUPPORTED
335
                & (valid_div[0] | ~clmode[0])
336
`ifdef OR1200_CLKDIV_4_SUPPORTED
337
                & (valid_div[1] | ~clmode[1])
338
`endif
339
`endif
340
                ;
341
 
342
//
343
// Error termination
344
//
345
// long_err_o
346
//
347
`ifdef OR1200_REGISTERED_INPUTS
348
always @(posedge wb_clk_i or posedge wb_rst_i)
349
        if (wb_rst_i)
350
                long_err_o <= #1 1'b0;
351
        else
352
                long_err_o <= #1 wb_err_i & ~aborted;
353
`else
354
assign long_err_o = wb_err_i & ~aborted_r;
355
`endif
356
 
357
//
358
// Retry counter
359
//
360
// Assert 'retry' when 'wb_rty_i' is sampled high and keep it high
361
// until retry counter doesn't expire
362
// 
363
`ifdef OR1200_WB_RETRY
364
assign retry = wb_rty_i | (|retry_cntr);
365
`else
366
assign retry = 1'b0;
367
`endif
368
`ifdef OR1200_WB_RETRY
369
always @(posedge wb_clk_i or posedge wb_rst_i)
370
        if (wb_rst_i)
371
                retry_cntr <= #1 1'b0;
372
        else if (wb_rty_i)
373
                retry_cntr <= #1 {`OR1200_WB_RETRY{1'b1}};
374
        else if (retry_cntr)
375
                retry_cntr <= #1 retry_cntr - 7'd1;
376
`endif
377
 
378
//
379
// Graceful completion of aborted transfers
380
//
381
// Assert 'aborted' when 1) current transfer is in progress (wb_stb_o; which
382
// we know is only asserted together with wb_cyc_o) 2) and in next WB clock cycle
383
// wb_stb_o would be deasserted (biu_cyc_i and biu_stb_i are low) 3) and
384
// there is no termination of current transfer in this WB clock cycle (wb_ack_i
385
// and wb_err_i are low).
386
// 'aborted_r' is registered 'aborted' and extended until this "aborted" transfer
387
// is properly terminated with wb_ack_i/wb_err_i.
388
// 
389
assign aborted = wb_stb_o & ~(biu_cyc_i & biu_stb_i) & ~(wb_ack_i | wb_err_i);
390
always @(posedge wb_clk_i or posedge wb_rst_i)
391
        if (wb_rst_i)
392
                aborted_r <= #1 1'b0;
393
        else if (wb_ack_i | wb_err_i)
394
                aborted_r <= #1 1'b0;
395
        else if (aborted)
396
                aborted_r <= #1 1'b1;
397
 
398
//
399
// WB cyc_o
400
//
401
// Either 1) normal transfer initiated by biu_cyc_i (and biu_cab_i if
402
// bursts are enabled) and possibly suspended by 'retry'
403
// or 2) extended "aborted" transfer
404
//
405
`ifdef OR1200_REGISTERED_OUTPUTS
406
always @(posedge wb_clk_i or posedge wb_rst_i)
407
        if (wb_rst_i)
408
                wb_cyc_o <= #1 1'b0;
409
        else
410
`ifdef OR1200_NO_BURSTS
411
                wb_cyc_o <= #1 biu_cyc_i & ~wb_ack_i & ~retry & ~repeated_access | aborted & ~wb_ack_i;
412
`else
413
                wb_cyc_o <= #1 biu_cyc_i & ~wb_ack_i & ~retry & ~repeated_access | biu_cab_i | aborted & ~wb_ack_i;
414
`endif
415
`else
416
`ifdef OR1200_NO_BURSTS
417
assign wb_cyc_o = biu_cyc_i & ~retry;
418
`else
419
assign wb_cyc_o = biu_cyc_i | biu_cab_i & ~retry;
420
`endif
421
`endif
422
 
423
//
424
// WB stb_o
425
//
426
`ifdef OR1200_REGISTERED_OUTPUTS
427
always @(posedge wb_clk_i or posedge wb_rst_i)
428
        if (wb_rst_i)
429
                wb_stb_o <= #1 1'b0;
430
        else
431
                wb_stb_o <= #1 (biu_cyc_i & biu_stb_i) & ~wb_ack_i & ~retry & ~repeated_access | aborted & ~wb_ack_i;
432
`else
433
assign wb_stb_o = biu_cyc_i & biu_stb_i;
434
`endif
435
 
436
//
437
// WB we_o
438
//
439
`ifdef OR1200_REGISTERED_OUTPUTS
440
always @(posedge wb_clk_i or posedge wb_rst_i)
441
        if (wb_rst_i)
442
                wb_we_o <= #1 1'b0;
443
        else
444
                wb_we_o <= #1 biu_cyc_i & biu_stb_i & biu_we_i | aborted & wb_we_o;
445
`else
446
assign wb_we_o = biu_cyc_i & biu_stb_i & biu_we_i;
447
`endif
448
 
449
//
450
// WB sel_o
451
//
452
`ifdef OR1200_REGISTERED_OUTPUTS
453
always @(posedge wb_clk_i or posedge wb_rst_i)
454
        if (wb_rst_i)
455
                wb_sel_o <= #1 4'b0000;
456
        else
457
                wb_sel_o <= #1 biu_sel_i;
458
`else
459
assign wb_sel_o = biu_sel_i;
460
`endif
461
 
462
`ifdef OR1200_WB_CAB
463
//
464
// WB cab_o
465
//
466
`ifdef OR1200_REGISTERED_OUTPUTS
467
always @(posedge wb_clk_i or posedge wb_rst_i)
468
        if (wb_rst_i)
469
                wb_cab_o <= #1 1'b0;
470
        else
471
                wb_cab_o <= #1 biu_cab_i;
472
`else
473
assign wb_cab_o = biu_cab_i;
474
`endif
475
`endif
476
 
477
`ifdef OR1200_WB_B3
478
//
479
// Count burst beats
480
//
481
always @(posedge wb_clk_i or posedge wb_rst_i)
482
        if (wb_rst_i)
483
                burst_len <= #1 2'b00;
484
        else if (biu_cab_i && burst_len && wb_ack_i)
485
                burst_len <= #1 burst_len - 1'b1;
486
        else if (~biu_cab_i)
487
                burst_len <= #1 2'b11;
488
 
489
//
490
// WB cti_o
491
//
492
`ifdef OR1200_REGISTERED_OUTPUTS
493
always @(posedge wb_clk_i or posedge wb_rst_i)
494
        if (wb_rst_i)
495
                wb_cti_o <= #1 3'b000;  // classic cycle
496
`ifdef OR1200_NO_BURSTS
497
        else
498
                wb_cti_o <= #1 3'b111;  // end-of-burst
499
`else
500
        else if (biu_cab_i && burst_len[1])
501
                wb_cti_o <= #1 3'b010;  // incrementing burst cycle
502
        else if (biu_cab_i && wb_ack_i)
503
                wb_cti_o <= #1 3'b111;  // end-of-burst
504
`endif  // OR1200_NO_BURSTS
505
`else
506
Unsupported !!!;
507
`endif
508
 
509
//
510
// WB bte_o
511
//
512
assign wb_bte_o = 2'b01;        // 4-beat wrap burst
513
 
514
`endif  // OR1200_WB_B3
515
 
516
endmodule

powered by: WebSVN 2.1.0

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