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

Subversion Repositories openriscdevboard

[/] [openriscdevboard/] [trunk/] [cyc2-openrisc/] [rtl/] [or1200/] [or1200_wb_biu.v] - Blame information for rev 3

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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