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

Subversion Repositories or1200_hp

[/] [or1200_hp/] [trunk/] [rtl/] [rtl_cm2/] [verilog/] [or1200_wb_biu.v] - Blame information for rev 2

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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