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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [or1200/] [rtl/] [verilog/] [or1200_iwb_biu.v] - Blame information for rev 12

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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