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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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