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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [arbiter/] [arbiter_ibus.v] - Blame information for rev 448

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

Line No. Rev Author Line
1 361 julius
//////////////////////////////////////////////////////////////////////
2
///                                                               //// 
3
/// Wishbone arbiter, burst-compatible                            ////
4
///                                                               ////
5
/// Simple arbiter, single master, dual slave, primarily for      ////
6
/// processor instruction bus, providing access to one main       ////
7
/// memory server and one ROM                                     ////
8
///                                                               ////
9
/// Julius Baxter, julius@opencores.org                           ////
10
///                                                               ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2009, 2010 Authors and OPENCORES.ORG           ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
`include "orpsoc-defines.v"
38
// One master, 2 slaves.
39
module arbiter_ibus
40
  (
41
   // instruction bus in
42
   // Wishbone Master interface
43
   wbm_adr_o,
44
   wbm_dat_o,
45
   wbm_sel_o,
46
   wbm_we_o,
47
   wbm_cyc_o,
48
   wbm_stb_o,
49
   wbm_cti_o,
50
   wbm_bte_o,
51
 
52
   wbm_dat_i,
53
   wbm_ack_i,
54
   wbm_err_i,
55
   wbm_rty_i,
56
 
57
 
58
   // Slave one
59
   // Wishbone Slave interface
60
   wbs0_adr_i,
61
   wbs0_dat_i,
62
   wbs0_sel_i,
63
   wbs0_we_i,
64
   wbs0_cyc_i,
65
   wbs0_stb_i,
66
   wbs0_cti_i,
67
   wbs0_bte_i,
68
 
69
   wbs0_dat_o,
70
   wbs0_ack_o,
71
   wbs0_err_o,
72
   wbs0_rty_o,
73
 
74
   // Slave two
75
   // Wishbone Slave interface
76
   wbs1_adr_i,
77
   wbs1_dat_i,
78
   wbs1_sel_i,
79
   wbs1_we_i,
80
   wbs1_cyc_i,
81
   wbs1_stb_i,
82
   wbs1_cti_i,
83
   wbs1_bte_i,
84
 
85
   wbs1_dat_o,
86
   wbs1_ack_o,
87
   wbs1_err_o,
88
   wbs1_rty_o,
89
 
90
   wb_clk,
91
   wb_rst
92
   );
93
 
94
 
95
   parameter wb_dat_width = 32;
96
   parameter wb_adr_width = 32;
97
 
98
   parameter wb_addr_match_width = 8;
99
 
100
   parameter slave0_adr = 8'hf0; // FLASH ROM
101
   parameter slave1_adr = 8'h00; // Main memory (SDRAM/FPGA SRAM)
102
 
103
`define WB_ARB_ADDR_MATCH_SEL wb_adr_width-1:wb_adr_width-wb_addr_match_width
104
 
105
   input wb_clk;
106
   input wb_rst;
107
 
108
 
109
   // WB Master
110
   input [wb_adr_width-1:0] wbm_adr_o;
111
   input [wb_dat_width-1:0] wbm_dat_o;
112
   input [3:0]               wbm_sel_o;
113
   input                    wbm_we_o;
114
   input                    wbm_cyc_o;
115
   input                    wbm_stb_o;
116
   input [2:0]               wbm_cti_o;
117
   input [1:0]               wbm_bte_o;
118
   output [wb_dat_width-1:0] wbm_dat_i;
119
   output                    wbm_ack_i;
120
   output                    wbm_err_i;
121
   output                    wbm_rty_i;
122
 
123
   // WB Slave 0
124
   output [wb_adr_width-1:0] wbs0_adr_i;
125
   output [wb_dat_width-1:0] wbs0_dat_i;
126
   output [3:0]       wbs0_sel_i;
127
   output                    wbs0_we_i;
128
   output                    wbs0_cyc_i;
129
   output                    wbs0_stb_i;
130
   output [2:0]       wbs0_cti_i;
131
   output [1:0]       wbs0_bte_i;
132
   input [wb_dat_width-1:0]  wbs0_dat_o;
133
   input                     wbs0_ack_o;
134
   input                     wbs0_err_o;
135
   input                     wbs0_rty_o;
136
 
137
   // WB Slave 1
138
   output [wb_adr_width-1:0] wbs1_adr_i;
139
   output [wb_dat_width-1:0] wbs1_dat_i;
140
   output [3:0]       wbs1_sel_i;
141
   output                    wbs1_we_i;
142
   output                    wbs1_cyc_i;
143
   output                    wbs1_stb_i;
144
   output [2:0]       wbs1_cti_i;
145
   output [1:0]       wbs1_bte_i;
146
   input [wb_dat_width-1:0]  wbs1_dat_o;
147
   input                     wbs1_ack_o;
148
   input                     wbs1_err_o;
149
   input                     wbs1_rty_o;
150
 
151
   wire [1:0]                 slave_sel; // One bit per slave
152
 
153
   reg                       watchdog_err;
154
 
155
`ifdef ARBITER_IBUS_WATCHDOG
156
   reg [`ARBITER_IBUS_WATCHDOG_TIMER_WIDTH:0]  watchdog_timer;
157
   reg                       wbm_stb_r; // Register strobe
158
   wire                      wbm_stb_edge; // Detect its edge
159
   reg                       wbm_stb_edge_r, wbm_ack_i_r; // Reg these, better timing
160
 
161
   always @(posedge wb_clk)
162
     wbm_stb_r <= wbm_stb_o;
163
 
164
   assign wbm_stb_edge = (wbm_stb_o & !wbm_stb_r);
165
 
166
   always @(posedge wb_clk)
167
     wbm_stb_edge_r <= wbm_stb_edge;
168
 
169
   always @(posedge wb_clk)
170
     wbm_ack_i_r <= wbm_ack_i;
171
 
172
 
173
   // Counter logic
174
   always @(posedge wb_clk)
175
     if (wb_rst) watchdog_timer <= 0;
176
     else if (wbm_ack_i_r) // When we see an ack, turn off timer
177
       watchdog_timer <= 0;
178
     else if (wbm_stb_edge_r) // New access means start timer again
179
       watchdog_timer <= 1;
180
     else if (|watchdog_timer) // Continue counting if counter > 0
181
       watchdog_timer <= watchdog_timer + 1;
182
 
183
   always @(posedge wb_clk)
184
     watchdog_err <= (&watchdog_timer);
185
 
186
`else // !`ifdef ARBITER_IBUS_WATCHDOG
187
 
188
   always @(posedge wb_clk)
189
     watchdog_err <= 0;
190
 
191
`endif // !`ifdef ARBITER_IBUS_WATCHDOG
192
 
193
 
194
 
195
`ifdef ARBITER_IBUS_REGISTERING
196
 
197
   // Master input registers
198
   reg [wb_adr_width-1:0]    wbm_adr_o_r;
199
   reg [wb_dat_width-1:0]    wbm_dat_o_r;
200
   reg [3:0]                  wbm_sel_o_r;
201
   reg                       wbm_we_o_r;
202
   reg                       wbm_cyc_o_r;
203
   reg                       wbm_stb_o_r;
204
   reg [2:0]                  wbm_cti_o_r;
205
   reg [1:0]                  wbm_bte_o_r;
206
   // Slave output registers
207
   reg [wb_dat_width-1:0]    wbs0_dat_o_r;
208
   reg                       wbs0_ack_o_r;
209
   reg                       wbs0_err_o_r;
210
   reg                       wbs0_rty_o_r;
211
   reg [wb_dat_width-1:0]    wbs1_dat_o_r;
212
   reg                       wbs1_ack_o_r;
213
   reg                       wbs1_err_o_r;
214
   reg                       wbs1_rty_o_r;
215
 
216
   wire                      wbm_ack_i_pre_reg;
217
 
218
 
219
 
220
   // Register master input signals
221
   always @(posedge wb_clk)
222
     begin
223
        wbm_adr_o_r <= wbm_adr_o;
224
        wbm_dat_o_r <= wbm_dat_o;
225
        wbm_sel_o_r <= wbm_sel_o;
226
        wbm_we_o_r <= wbm_we_o;
227
        wbm_cyc_o_r <= wbm_cyc_o;
228
        wbm_stb_o_r <= wbm_stb_o & !wbm_ack_i_pre_reg & !wbm_ack_i;//classic
229
        wbm_cti_o_r <= wbm_cti_o;
230
        wbm_bte_o_r <= wbm_bte_o;
231
 
232
        // Slave signals
233
        wbs0_dat_o_r <= wbs0_dat_o;
234
        wbs0_ack_o_r <= wbs0_ack_o;
235
        wbs0_err_o_r <= wbs0_err_o;
236
        wbs0_rty_o_r <= wbs0_rty_o;
237
        wbs1_dat_o_r <= wbs1_dat_o;
238
        wbs1_ack_o_r <= wbs1_ack_o;
239
        wbs1_err_o_r <= wbs1_err_o;
240
        wbs1_rty_o_r <= wbs1_rty_o;
241
 
242
     end // always @ (posedge wb_clk)
243
 
244
   // Slave select
245
   assign slave_sel[0] = wbm_adr_o_r[`WB_ARB_ADDR_MATCH_SEL] ==
246
                         slave0_adr;
247
 
248
   assign slave_sel[1] = wbm_adr_o_r[`WB_ARB_ADDR_MATCH_SEL] ==
249
                         slave1_adr;
250
 
251
   // Slave out assigns
252
   assign wbs0_adr_i = wbm_adr_o_r;
253
   assign wbs0_dat_i = wbm_dat_o_r;
254
   assign wbs0_we_i = wbm_dat_o_r;
255
   assign wbs0_sel_i = wbm_sel_o_r;
256
   assign wbs0_cti_i = wbm_cti_o_r;
257
   assign wbs0_bte_i = wbm_bte_o_r;
258
   assign wbs0_cyc_i = wbm_cyc_o_r & slave_sel[0];
259
   assign wbs0_stb_i = wbm_stb_o_r & slave_sel[0];
260
 
261
   assign wbs1_adr_i = wbm_adr_o_r;
262
   assign wbs1_dat_i = wbm_dat_o_r;
263
   assign wbs1_we_i = wbm_dat_o_r;
264
   assign wbs1_sel_i = wbm_sel_o_r;
265
   assign wbs1_cti_i = wbm_cti_o_r;
266
   assign wbs1_bte_i = wbm_bte_o_r;
267
   assign wbs1_cyc_i = wbm_cyc_o_r & slave_sel[1];
268
   assign wbs1_stb_i = wbm_stb_o_r & slave_sel[1];
269
 
270
   // Master out assigns
271
   // Don't care about none selected...
272
   assign wbm_dat_i = slave_sel[1] ? wbs1_dat_o_r :
273
                      wbs0_dat_o_r ;
274
 
275
   assign wbm_ack_i = (slave_sel[0] & wbs0_ack_o_r) |
276
                      (slave_sel[1] & wbs1_ack_o_r)
277
     ;
278
 
279
   assign wbm_err_i = (slave_sel[0] & wbs0_err_o_r) |
280
                      (slave_sel[1] & wbs1_err_o_r) |
281
                      watchdog_err;
282
 
283
   assign wbm_rty_i = (slave_sel[0] & wbs0_rty_o_r) |
284
                      (slave_sel[1] & wbs1_rty_o_r);
285
 
286
   // Non-registered ack
287
   assign wbm_ack_i_pre_reg = (slave_sel[0] & wbs0_ack_o) |
288
                              (slave_sel[1] & wbs1_ack_o);
289
 
290
`else // !`ifdef ARBITER_IBUS_REGISTERING
291
 
292
   // Slave select
293
   assign slave_sel[0] = wbm_adr_o[`WB_ARB_ADDR_MATCH_SEL] ==
294
                         slave0_adr;
295
 
296
   assign slave_sel[1] = wbm_adr_o[`WB_ARB_ADDR_MATCH_SEL] ==
297
                         slave1_adr;
298
 
299
   // Slave out assigns
300
   assign wbs0_adr_i = wbm_adr_o;
301
   assign wbs0_dat_i = wbm_dat_o;
302 363 julius
   assign wbs0_we_i  = wbm_we_o;
303 361 julius
   assign wbs0_sel_i = wbm_sel_o;
304
   assign wbs0_cti_i = wbm_cti_o;
305
   assign wbs0_bte_i = wbm_bte_o;
306
   assign wbs0_cyc_i = wbm_cyc_o & slave_sel[0];
307
   assign wbs0_stb_i = wbm_stb_o & slave_sel[0];
308
 
309
   assign wbs1_adr_i = wbm_adr_o;
310
   assign wbs1_dat_i = wbm_dat_o;
311 363 julius
   assign wbs1_we_i  = wbm_we_o;
312 361 julius
   assign wbs1_sel_i = wbm_sel_o;
313
   assign wbs1_cti_i = wbm_cti_o;
314
   assign wbs1_bte_i = wbm_bte_o;
315
   assign wbs1_cyc_i = wbm_cyc_o & slave_sel[1];
316
   assign wbs1_stb_i = wbm_stb_o & slave_sel[1];
317
 
318
   // Master out assigns
319
   // Don't care about none selected...
320
   assign wbm_dat_i = slave_sel[1] ? wbs1_dat_o :
321
                      wbs0_dat_o ;
322
 
323
   assign wbm_ack_i = (slave_sel[0] & wbs0_ack_o) |
324
                      (slave_sel[1] & wbs1_ack_o);
325
 
326
 
327
   assign wbm_err_i = (slave_sel[0] & wbs0_err_o) |
328
                      (slave_sel[1] & wbs1_err_o) |
329
                      watchdog_err;
330
 
331
   assign wbm_rty_i = (slave_sel[0] & wbs0_rty_o) |
332
                      (slave_sel[1] & wbs1_rty_o);
333
 
334
 
335
`endif
336
endmodule // arbiter_ibus
337
 

powered by: WebSVN 2.1.0

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