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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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