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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_wb_biu.v] - Blame information for rev 609

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's WISHBONE BIU                                       ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6 258 julius
////  http://opencores.org/project,or1k                           ////
7 10 unneback
////                                                              ////
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
//
50 142 marcus.erl
// $Log: or1200_wb_biu.v,v $
51
// Revision 2.0  2010/06/30 11:00:00  ORSoC
52
// Major update: 
53
// Structure reordered and bugs fixed. 
54
//
55 10 unneback
 
56
// synopsys translate_off
57
`include "timescale.v"
58
// synopsys translate_on
59
`include "or1200_defines.v"
60
 
61
module or1200_wb_biu(
62 258 julius
                     // RISC clock, reset and clock control
63
                     clk, rst, clmode,
64 10 unneback
 
65 258 julius
                     // WISHBONE interface
66
                     wb_clk_i, wb_rst_i, wb_ack_i, wb_err_i, wb_rty_i, wb_dat_i,
67
                     wb_cyc_o, wb_adr_o, wb_stb_o, wb_we_o, wb_sel_o, wb_dat_o,
68 10 unneback
`ifdef OR1200_WB_CAB
69 258 julius
                     wb_cab_o,
70 10 unneback
`endif
71
`ifdef OR1200_WB_B3
72 258 julius
                     wb_cti_o, wb_bte_o,
73 10 unneback
`endif
74
 
75 258 julius
                     // Internal RISC bus
76
                     biu_dat_i, biu_adr_i, biu_cyc_i, biu_stb_i, biu_we_i, biu_sel_i, biu_cab_i,
77
                     biu_dat_o, biu_ack_o, biu_err_o
78
                     );
79 10 unneback
 
80 258 julius
   parameter dw = `OR1200_OPERAND_WIDTH;
81
   parameter aw = `OR1200_OPERAND_WIDTH;
82 481 julius
   parameter bl = 4; /* Can currently be either 4 or 8 - the two optional line
83
                      sizes for the OR1200. */
84
 
85
 
86 258 julius
   //
87
   // RISC clock, reset and clock control
88
   //
89
   input                                clk;            // RISC clock
90
   input                                rst;            // RISC reset
91
   input [1:0]                           clmode;         // 00 WB=RISC, 01 WB=RISC/2, 10 N/A, 11 WB=RISC/4
92 10 unneback
 
93 258 julius
   //
94
   // WISHBONE interface
95
   //
96
   input                                wb_clk_i;       // clock input
97
   input                                wb_rst_i;       // reset input
98
   input                                wb_ack_i;       // normal termination
99
   input                                wb_err_i;       // termination w/ error
100
   input                                wb_rty_i;       // termination w/ retry
101
   input [dw-1:0]                        wb_dat_i;       // input data bus
102
   output                               wb_cyc_o;       // cycle valid output
103
   output [aw-1:0]                       wb_adr_o;       // address bus outputs
104
   output                               wb_stb_o;       // strobe output
105
   output                               wb_we_o;        // indicates write transfer
106
   output [3:0]                  wb_sel_o;       // byte select outputs
107
   output [dw-1:0]                       wb_dat_o;       // output data bus
108 10 unneback
`ifdef OR1200_WB_CAB
109 258 julius
   output                               wb_cab_o;       // consecutive address burst
110 10 unneback
`endif
111
`ifdef OR1200_WB_B3
112 258 julius
   output [2:0]                  wb_cti_o;       // cycle type identifier
113
   output [1:0]                  wb_bte_o;       // burst type extension
114 10 unneback
`endif
115
 
116 258 julius
   //
117
   // Internal RISC interface
118
   //
119
   input [dw-1:0]                        biu_dat_i;      // input data bus
120
   input [aw-1:0]                        biu_adr_i;      // address bus
121
   input                                biu_cyc_i;      // WB cycle
122
   input                                biu_stb_i;      // WB strobe
123
   input                                biu_we_i;       // WB write enable
124
   input                                biu_cab_i;      // CAB input
125
   input [3:0]                           biu_sel_i;      // byte selects
126
   output [31:0]                         biu_dat_o;      // output data bus
127
   output                               biu_ack_o;      // ack output
128
   output                               biu_err_o;      // err output
129 10 unneback
 
130 258 julius
   //
131
   // Registers
132
   //
133
   wire                                 wb_ack;         // normal termination
134
   reg [aw-1:0]                  wb_adr_o;       // address bus outputs
135
   reg                                  wb_cyc_o;       // cycle output
136
   reg                                  wb_stb_o;       // strobe output
137
   reg                                  wb_we_o;        // indicates write transfer
138
   reg [3:0]                             wb_sel_o;       // byte select outputs
139 10 unneback
`ifdef OR1200_WB_CAB
140 258 julius
   reg                                  wb_cab_o;       // CAB output
141 10 unneback
`endif
142
`ifdef OR1200_WB_B3
143 258 julius
   reg [2:0]                             wb_cti_o;       // cycle type identifier
144
   reg [1:0]                             wb_bte_o;       // burst type extension
145 10 unneback
`endif
146 258 julius
`ifdef OR1200_NO_DC
147
   reg [dw-1:0]                  wb_dat_o;       // output data bus
148
`else
149
   assign wb_dat_o = biu_dat_i;    // No register on this - straight from DCRAM
150
`endif
151
 
152 10 unneback
`ifdef OR1200_WB_RETRY
153 258 julius
   reg [`OR1200_WB_RETRY-1:0]            retry_cnt;      // Retry counter
154 10 unneback
`else
155 258 julius
   wire                                 retry_cnt;
156
   assign retry_cnt = 1'b0;
157 10 unneback
`endif
158 142 marcus.erl
`ifdef OR1200_WB_B3
159 481 julius
   reg [3:0]                             burst_len;      // burst counter
160 10 unneback
`endif
161
 
162 258 julius
   reg                                  biu_stb_reg;    // WB strobe
163
   wire                                 biu_stb;        // WB strobe
164
   reg                                  wb_cyc_nxt;     // next WB cycle value
165
   reg                                  wb_stb_nxt;     // next WB strobe value
166
   reg [2:0]                             wb_cti_nxt;     // next cycle type identifier value
167 10 unneback
 
168 258 julius
   reg                                  wb_ack_cnt;     // WB ack toggle counter
169
   reg                                  wb_err_cnt;     // WB err toggle counter
170
   reg                                  wb_rty_cnt;     // WB rty toggle counter
171
   reg                                  biu_ack_cnt;    // BIU ack toggle counter
172
   reg                                  biu_err_cnt;    // BIU err toggle counter
173
   reg                                  biu_rty_cnt;    // BIU rty toggle counter
174
   wire                                 biu_rty;        // BIU rty indicator
175 10 unneback
 
176 258 julius
   reg [1:0]                             wb_fsm_state_cur;       // WB FSM - surrent state
177
   reg [1:0]                             wb_fsm_state_nxt;       // WB FSM - next state
178
   wire [1:0]                            wb_fsm_idle     = 2'h0; // WB FSM state - IDLE
179
   wire [1:0]                            wb_fsm_trans    = 2'h1; // WB FSM state - normal TRANSFER
180
   wire [1:0]                            wb_fsm_last     = 2'h2; // EB FSM state - LAST transfer
181 10 unneback
 
182 258 julius
   //
183
   // WISHBONE I/F <-> Internal RISC I/F conversion
184
   //
185
   //assign wb_ack = wb_ack_i;
186
   assign wb_ack = wb_ack_i & !wb_err_i & !wb_rty_i;
187 10 unneback
 
188 258 julius
   //
189
   // WB FSM - register part
190
   // 
191 358 julius
   always @(posedge wb_clk_i or `OR1200_RST_EVENT wb_rst_i) begin
192
      if (wb_rst_i == `OR1200_RST_VALUE)
193 258 julius
        wb_fsm_state_cur <=  wb_fsm_idle;
194
      else
195
        wb_fsm_state_cur <=  wb_fsm_state_nxt;
196
   end
197 10 unneback
 
198 258 julius
   //
199
   // WB burst tength counter
200
   // 
201 358 julius
   always @(posedge wb_clk_i or `OR1200_RST_EVENT wb_rst_i) begin
202
      if (wb_rst_i == `OR1200_RST_VALUE) begin
203 481 julius
         burst_len <= 0;
204 258 julius
      end
205
      else begin
206
         // burst counter
207
         if (wb_fsm_state_cur == wb_fsm_idle)
208 481 julius
           burst_len <=  bl[3:0] - 2;
209 258 julius
         else if (wb_stb_o & wb_ack)
210 481 julius
           burst_len <=  burst_len - 1;
211 258 julius
      end
212
   end
213 10 unneback
 
214 258 julius
   // 
215
   // WB FSM - combinatorial part
216
   // 
217
   always @(wb_fsm_state_cur or burst_len or wb_err_i or wb_rty_i or wb_ack or
218
            wb_cti_o or wb_sel_o or wb_stb_o or wb_we_o or biu_cyc_i or
219
            biu_stb or biu_cab_i or biu_sel_i or biu_we_i) begin
220
      // States of WISHBONE Finite State Machine
221
      case(wb_fsm_state_cur)
222 142 marcus.erl
        // IDLE 
223
        wb_fsm_idle : begin
224 258 julius
           wb_cyc_nxt = biu_cyc_i & biu_stb;
225
           wb_stb_nxt = biu_cyc_i & biu_stb;
226
           wb_cti_nxt = {!biu_cab_i, 1'b1, !biu_cab_i};
227
           if (biu_cyc_i & biu_stb)
228
             wb_fsm_state_nxt = wb_fsm_trans;
229
           else
230
             wb_fsm_state_nxt = wb_fsm_idle;
231 142 marcus.erl
        end
232
        // normal TRANSFER
233
        wb_fsm_trans : begin
234 258 julius
           wb_cyc_nxt = !wb_stb_o | !wb_err_i & !wb_rty_i &
235
                        !(wb_ack & wb_cti_o == 3'b111);
236
 
237
           wb_stb_nxt = !wb_stb_o | !wb_err_i & !wb_rty_i & !wb_ack |
238 481 julius
                        !wb_err_i & !wb_rty_i & wb_cti_o == 3'b010 ;
239 258 julius
           wb_cti_nxt[2] = wb_stb_o & wb_ack & burst_len == 'h0 | wb_cti_o[2];
240
           wb_cti_nxt[1] = 1'b1  ;
241
           wb_cti_nxt[0] = wb_stb_o & wb_ack & burst_len == 'h0 | wb_cti_o[0];
242 481 julius
 
243 258 julius
           if ((!biu_cyc_i | !biu_stb | !biu_cab_i | biu_sel_i != wb_sel_o |
244
                biu_we_i != wb_we_o) & wb_cti_o == 3'b010)
245
             wb_fsm_state_nxt = wb_fsm_last;
246
           else if ((wb_err_i | wb_rty_i | wb_ack & wb_cti_o==3'b111) &
247
                    wb_stb_o)
248
             wb_fsm_state_nxt = wb_fsm_idle;
249
           else
250
             wb_fsm_state_nxt = wb_fsm_trans;
251 142 marcus.erl
        end
252
        // LAST transfer
253
        wb_fsm_last : begin
254 258 julius
           wb_cyc_nxt = !wb_stb_o | !wb_err_i & !wb_rty_i &
255
                        !(wb_ack & wb_cti_o == 3'b111);
256
           wb_stb_nxt = !wb_stb_o | !wb_err_i & !wb_rty_i &
257
                        !(wb_ack & wb_cti_o == 3'b111);
258
           wb_cti_nxt[2] = wb_ack & wb_stb_o | wb_cti_o[2];
259
           wb_cti_nxt[1] = 1'b1                  ;
260
           wb_cti_nxt[0] = wb_ack & wb_stb_o | wb_cti_o[0];
261
           if ((wb_err_i | wb_rty_i | wb_ack & wb_cti_o == 3'b111) & wb_stb_o)
262
             wb_fsm_state_nxt = wb_fsm_idle;
263
           else
264
             wb_fsm_state_nxt = wb_fsm_last;
265 142 marcus.erl
        end
266
        // default state
267
        default:begin
268 258 julius
           wb_cyc_nxt = 1'bx;
269
           wb_stb_nxt = 1'bx;
270
           wb_cti_nxt = 3'bxxx;
271
           wb_fsm_state_nxt = 2'bxx;
272 142 marcus.erl
        end
273 258 julius
      endcase
274
   end
275 10 unneback
 
276 258 julius
   //
277
   // WB FSM - output signals
278
   // 
279 358 julius
   always @(posedge wb_clk_i or `OR1200_RST_EVENT wb_rst_i) begin
280
      if (wb_rst_i == `OR1200_RST_VALUE) begin
281 258 julius
         wb_cyc_o       <=  1'b0;
282
         wb_stb_o       <=  1'b0;
283
         wb_cti_o       <=  3'b111;
284 481 julius
         wb_bte_o       <=  (bl==8) ? 2'b10 : (bl==4) ? 2'b01 : 2'b00;
285 142 marcus.erl
`ifdef OR1200_WB_CAB
286 258 julius
         wb_cab_o       <=  1'b0;
287 10 unneback
`endif
288 258 julius
         wb_we_o                <=  1'b0;
289
         wb_sel_o       <=  4'hf;
290
         wb_adr_o       <=  {aw{1'b0}};
291
`ifdef OR1200_NO_DC
292
         wb_dat_o       <=  {dw{1'b0}};
293
`endif
294
      end
295
      else begin
296
         wb_cyc_o       <=  wb_cyc_nxt;
297 481 julius
 
298 258 julius
         if (wb_ack & wb_cti_o == 3'b111)
299
           wb_stb_o        <=  1'b0;
300
         else
301
           wb_stb_o        <=  wb_stb_nxt;
302 481 julius
`ifndef OR1200_NO_BURSTS
303 258 julius
         wb_cti_o       <=  wb_cti_nxt;
304 481 julius
`endif
305
         wb_bte_o       <=  (bl==8) ? 2'b10 : (bl==4) ? 2'b01 : 2'b00;
306 142 marcus.erl
`ifdef OR1200_WB_CAB
307 258 julius
         wb_cab_o       <=  biu_cab_i;
308 10 unneback
`endif
309 258 julius
         // we and sel - set at beginning of access 
310
         if (wb_fsm_state_cur == wb_fsm_idle) begin
311
            wb_we_o             <=  biu_we_i;
312
            wb_sel_o    <=  biu_sel_i;
313
         end
314
         // adr - set at beginning of access and changed at every termination 
315
         if (wb_fsm_state_cur == wb_fsm_idle) begin
316
            wb_adr_o    <=  biu_adr_i;
317
         end
318
         else if (wb_stb_o & wb_ack) begin
319 481 julius
            if (bl==4) begin
320
               wb_adr_o[3:2]    <=  wb_adr_o[3:2] + 1;
321
            end
322
            if (bl==8) begin
323
               wb_adr_o[4:2]    <=  wb_adr_o[4:2] + 1;
324
            end
325 258 julius
         end
326
`ifdef OR1200_NO_DC
327
         // dat - write data changed after avery subsequent write access
328
         if (!wb_stb_o) begin
329
            wb_dat_o    <=  biu_dat_i;
330
         end
331
`endif
332
      end
333
   end
334 10 unneback
 
335 258 julius
   //
336
   // WB & BIU termination toggle counters
337
   // 
338 358 julius
   always @(posedge wb_clk_i or `OR1200_RST_EVENT wb_rst_i) begin
339
      if (wb_rst_i == `OR1200_RST_VALUE) begin
340 258 julius
         wb_ack_cnt     <=  1'b0;
341
         wb_err_cnt     <=  1'b0;
342
         wb_rty_cnt     <=  1'b0;
343
      end
344
      else begin
345
         // WB ack toggle counter
346 364 julius
         if (wb_fsm_state_cur == wb_fsm_idle | !(|clmode))
347 258 julius
           wb_ack_cnt   <=  1'b0;
348
         else if (wb_stb_o & wb_ack)
349
           wb_ack_cnt   <=  !wb_ack_cnt;
350
         // WB err toggle counter
351 364 julius
         if (wb_fsm_state_cur == wb_fsm_idle | !(|clmode))
352 258 julius
           wb_err_cnt   <=  1'b0;
353
         else if (wb_stb_o & wb_err_i)
354
           wb_err_cnt   <=  !wb_err_cnt;
355
         // WB rty toggle counter
356 364 julius
         if (wb_fsm_state_cur == wb_fsm_idle | !(|clmode))
357 258 julius
           wb_rty_cnt   <=  1'b0;
358
         else if (wb_stb_o & wb_rty_i)
359
           wb_rty_cnt   <=  !wb_rty_cnt;
360
      end
361
   end
362 10 unneback
 
363 358 julius
   always @(posedge clk or `OR1200_RST_EVENT rst) begin
364
      if (rst == `OR1200_RST_VALUE) begin
365 258 julius
         biu_stb_reg    <=  1'b0;
366
         biu_ack_cnt    <=  1'b0;
367
         biu_err_cnt    <=  1'b0;
368
         biu_rty_cnt    <=  1'b0;
369 142 marcus.erl
`ifdef OR1200_WB_RETRY
370 258 julius
         retry_cnt      <= {`OR1200_WB_RETRY{1'b0}};
371 10 unneback
`endif
372 258 julius
      end
373
      else begin
374
         // BIU strobe
375
         if (biu_stb_i & !biu_cab_i & biu_ack_o)
376
           biu_stb_reg  <=  1'b0;
377
         else
378
           biu_stb_reg  <=  biu_stb_i;
379
         // BIU ack toggle counter
380 364 julius
         if (wb_fsm_state_cur == wb_fsm_idle | !(|clmode))
381 258 julius
           biu_ack_cnt  <=  1'b0 ;
382
         else if (biu_ack_o)
383
           biu_ack_cnt  <=  !biu_ack_cnt ;
384
         // BIU err toggle counter
385 364 julius
         if (wb_fsm_state_cur == wb_fsm_idle | !(|clmode))
386 258 julius
           biu_err_cnt  <=  1'b0 ;
387
         else if (wb_err_i & biu_err_o)
388
           biu_err_cnt  <=  !biu_err_cnt ;
389
         // BIU rty toggle counter
390 364 julius
         if (wb_fsm_state_cur == wb_fsm_idle | !(|clmode))
391 258 julius
           biu_rty_cnt  <=  1'b0 ;
392
         else if (biu_rty)
393
           biu_rty_cnt  <=  !biu_rty_cnt ;
394 142 marcus.erl
`ifdef OR1200_WB_RETRY
395 258 julius
         if (biu_ack_o | biu_err_o)
396
           retry_cnt    <=  {`OR1200_WB_RETRY{1'b0}};
397
         else if (biu_rty)
398
           retry_cnt    <=  retry_cnt + 1'b1;
399 10 unneback
`endif
400 258 julius
      end
401
   end
402 10 unneback
 
403 258 julius
   assign biu_stb = biu_stb_i & biu_stb_reg;
404 10 unneback
 
405 258 julius
   //
406
   // Input BIU data bus
407
   //
408
   assign       biu_dat_o       = wb_dat_i;
409 10 unneback
 
410 258 julius
   //
411
   // Input BIU termination signals 
412
   //
413
   assign       biu_rty         = (wb_fsm_state_cur == wb_fsm_trans) & wb_rty_i & wb_stb_o & (wb_rty_cnt ~^ biu_rty_cnt);
414
   assign       biu_ack_o       = (wb_fsm_state_cur == wb_fsm_trans) & wb_ack & wb_stb_o & (wb_ack_cnt ~^ biu_ack_cnt);
415
   assign       biu_err_o       = (wb_fsm_state_cur == wb_fsm_trans) & wb_err_i & wb_stb_o & (wb_err_cnt ~^ biu_err_cnt)
416 142 marcus.erl
`ifdef OR1200_WB_RETRY
417 258 julius
     | biu_rty & retry_cnt[`OR1200_WB_RETRY-1];
418 10 unneback
`else
419 258 julius
   ;
420 10 unneback
`endif
421
 
422
 
423
endmodule

powered by: WebSVN 2.1.0

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