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 1104

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

powered by: WebSVN 2.1.0

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