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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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