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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [system/] [wishbone_arbiter.v] - Blame information for rev 14

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

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Wishbone Arbiter                                            //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Arbitrates between two wishbone masters and 13 wishbone     //
10
//  slave modules. The ethernet MAC wishbone master is given    //
11
//  priority over the Amber core.                               //
12
//                                                              //
13
//  Author(s):                                                  //
14
//      - Conor Santifort, csantifort.amber@gmail.com           //
15
//                                                              //
16
//////////////////////////////////////////////////////////////////
17
//                                                              //
18
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
19
//                                                              //
20
// This source file may be used and distributed without         //
21
// restriction provided that this copyright statement is not    //
22
// removed from the file and that any derivative work contains  //
23
// the original copyright notice and the associated disclaimer. //
24
//                                                              //
25
// This source file is free software; you can redistribute it   //
26
// and/or modify it under the terms of the GNU Lesser General   //
27
// Public License as published by the Free Software Foundation; //
28
// either version 2.1 of the License, or (at your option) any   //
29
// later version.                                               //
30
//                                                              //
31
// This source is distributed in the hope that it will be       //
32
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
33
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
34
// PURPOSE.  See the GNU Lesser General Public License for more //
35
// details.                                                     //
36
//                                                              //
37
// You should have received a copy of the GNU Lesser General    //
38
// Public License along with this source; if not, download it   //
39
// from http://www.opencores.org/lgpl.shtml                     //
40
//                                                              //
41
//////////////////////////////////////////////////////////////////
42
 
43
 
44
module wishbone_arbiter (
45
input                   i_wb_clk,     // WISHBONE clock
46
 
47
// WISHBONE master 0 - Amber
48
input       [31:0]      i_m0_wb_adr,
49
input       [3:0]       i_m0_wb_sel,
50
input                   i_m0_wb_we,
51
output      [31:0]      o_m0_wb_dat,
52
input       [31:0]      i_m0_wb_dat,
53
input                   i_m0_wb_cyc,
54
input                   i_m0_wb_stb,
55
output                  o_m0_wb_ack,
56
output                  o_m0_wb_err,
57
 
58
 
59
// WISHBONE master 1 - Ethmac
60
input       [31:0]      i_m1_wb_adr,
61
input       [3:0]       i_m1_wb_sel,
62
input                   i_m1_wb_we,
63
output      [31:0]      o_m1_wb_dat,
64
input       [31:0]      i_m1_wb_dat,
65
input                   i_m1_wb_cyc,
66
input                   i_m1_wb_stb,
67
output                  o_m1_wb_ack,
68
output                  o_m1_wb_err,
69
 
70
 
71
// WISHBONE slave 0 - Ethmac
72
output      [31:0]      o_s0_wb_adr,
73
output      [3:0]       o_s0_wb_sel,
74
output                  o_s0_wb_we,
75
input       [31:0]      i_s0_wb_dat,
76
output      [31:0]      o_s0_wb_dat,
77
output                  o_s0_wb_cyc,
78
output                  o_s0_wb_stb,
79
input                   i_s0_wb_ack,
80
input                   i_s0_wb_err,
81
 
82
 
83
// WISHBONE slave 1 - Boot Memory
84
output      [31:0]      o_s1_wb_adr,
85
output      [3:0]       o_s1_wb_sel,
86
output                  o_s1_wb_we,
87
input       [31:0]      i_s1_wb_dat,
88
output      [31:0]      o_s1_wb_dat,
89
output                  o_s1_wb_cyc,
90
output                  o_s1_wb_stb,
91
input                   i_s1_wb_ack,
92
input                   i_s1_wb_err,
93
 
94
 
95
// WISHBONE slave 2 - Main Memory
96
output      [31:0]      o_s2_wb_adr,
97
output      [3:0]       o_s2_wb_sel,
98
output                  o_s2_wb_we,
99
input       [31:0]      i_s2_wb_dat,
100
output      [31:0]      o_s2_wb_dat,
101
output                  o_s2_wb_cyc,
102
output                  o_s2_wb_stb,
103
input                   i_s2_wb_ack,
104
input                   i_s2_wb_err,
105
 
106
 
107
// WISHBONE slave 3 - UART 0
108
output      [31:0]      o_s3_wb_adr,
109
output      [3:0]       o_s3_wb_sel,
110
output                  o_s3_wb_we,
111
input       [31:0]      i_s3_wb_dat,
112
output      [31:0]      o_s3_wb_dat,
113
output                  o_s3_wb_cyc,
114
output                  o_s3_wb_stb,
115
input                   i_s3_wb_ack,
116
input                   i_s3_wb_err,
117
 
118
 
119
// WISHBONE slave 4 - UART 1
120
output      [31:0]      o_s4_wb_adr,
121
output      [3:0]       o_s4_wb_sel,
122
output                  o_s4_wb_we,
123
input       [31:0]      i_s4_wb_dat,
124
output      [31:0]      o_s4_wb_dat,
125
output                  o_s4_wb_cyc,
126
output                  o_s4_wb_stb,
127
input                   i_s4_wb_ack,
128
input                   i_s4_wb_err,
129
 
130
 
131
// WISHBONE slave 5 - Test Module
132
output      [31:0]      o_s5_wb_adr,
133
output      [3:0]       o_s5_wb_sel,
134
output                  o_s5_wb_we,
135
input       [31:0]      i_s5_wb_dat,
136
output      [31:0]      o_s5_wb_dat,
137
output                  o_s5_wb_cyc,
138
output                  o_s5_wb_stb,
139
input                   i_s5_wb_ack,
140
input                   i_s5_wb_err,
141
 
142
 
143
// WISHBONE slave 6 - Timer Module
144
output      [31:0]      o_s6_wb_adr,
145
output      [3:0]       o_s6_wb_sel,
146
output                  o_s6_wb_we,
147
input       [31:0]      i_s6_wb_dat,
148
output      [31:0]      o_s6_wb_dat,
149
output                  o_s6_wb_cyc,
150
output                  o_s6_wb_stb,
151
input                   i_s6_wb_ack,
152
input                   i_s6_wb_err,
153
 
154
 
155
 // WISHBONE slave 7 - Interrupt Controller
156
output      [31:0]      o_s7_wb_adr,
157
output      [3:0]       o_s7_wb_sel,
158
output                  o_s7_wb_we,
159
input       [31:0]      i_s7_wb_dat,
160
output      [31:0]      o_s7_wb_dat,
161
output                  o_s7_wb_cyc,
162
output                  o_s7_wb_stb,
163
input                   i_s7_wb_ack,
164
input                   i_s7_wb_err
165
);
166
 
167
`include "memory_configuration.v"
168
reg         m0_wb_cyc_r = 'd0;
169
reg         m1_wb_cyc_r = 'd0;
170
wire        m0_in_cycle;
171
wire        m1_in_cycle;
172
wire        current_master;
173
reg         current_master_r = 'd0;
174
wire        next_master;
175
wire        select_master;
176
wire [3:0]  current_slave;
177
 
178
wire [31:0] master_adr;
179
wire [3:0]  master_sel;
180
wire        master_we;
181
wire [31:0] master_wdat;
182
wire        master_cyc;
183
wire        master_stb;
184
wire [31:0] master_rdat;
185
wire        master_ack;
186
wire        master_err;
187
 
188
// Arbitrate between m0 and m1. Ethmac (m0) always gets priority
189
assign next_master    = i_m0_wb_cyc ? 1'd0 : 1'd1;
190
 
191
// Use cyc signal for arbitration so block accesses are not split up
192
assign m0_in_cycle    = m0_wb_cyc_r && i_m0_wb_cyc;
193
assign m1_in_cycle    = m1_wb_cyc_r && i_m1_wb_cyc;
194
 
195
// only select a new bus master when the current bus master
196
// de-asserts the cyc signal
197
assign select_master  = current_master_r ? !m1_in_cycle : !m0_in_cycle;
198
assign current_master = select_master ? next_master : current_master_r;
199
 
200
 
201
always @( posedge i_wb_clk )
202
    begin
203
    current_master_r    <= current_master;
204
    m0_wb_cyc_r         <= i_m0_wb_cyc;
205
    m1_wb_cyc_r         <= i_m1_wb_cyc;
206
    end
207
 
208
 
209
// Arbitrate between slaves
210
assign current_slave = in_ethmac   ( master_adr ) ? 4'd0  :  // Ethmac
211
                       in_boot_mem ( master_adr ) ? 4'd1  :  // Boot memory
212
                       in_main_mem ( master_adr ) ? 4'd2  :  // Main memory
213
                       in_uart0    ( master_adr ) ? 4'd3  :  // UART 0
214
                       in_uart1    ( master_adr ) ? 4'd4  :  // UART 1
215
                       in_test     ( master_adr ) ? 4'd5  :  // Test Module
216
                       in_tm       ( master_adr ) ? 4'd6  :  // Timer Module
217
                       in_ic       ( master_adr ) ? 4'd7  :  // Interrupt Controller
218
                                                    4'd2  ;  // default to main memory
219
 
220
 
221
assign master_adr   = current_master ? i_m1_wb_adr : i_m0_wb_adr ;
222
// Switch endianess of ethmac Master
223
assign master_sel   = current_master ? i_m1_wb_sel : {i_m0_wb_sel[0], i_m0_wb_sel[1],
224
                                                      i_m0_wb_sel[2], i_m0_wb_sel[3]};
225
assign master_wdat  = current_master ? i_m1_wb_dat : {i_m0_wb_dat[7:0],  i_m0_wb_dat[15:8],
226
                                                      i_m0_wb_dat[23:16],i_m0_wb_dat[31:24]} ;
227
assign master_we    = current_master ? i_m1_wb_we  : i_m0_wb_we  ;
228
assign master_cyc   = current_master ? i_m1_wb_cyc : i_m0_wb_cyc ;
229
assign master_stb   = current_master ? i_m1_wb_stb : i_m0_wb_stb ;
230
 
231
 
232
// Ethmac Slave outputs
233
assign o_s0_wb_adr  = master_adr;
234
assign o_s0_wb_dat  = master_wdat;
235
assign o_s0_wb_sel  = master_sel;
236
assign o_s0_wb_we   = current_slave == 4'd0 ? master_we  : 1'd0;
237
assign o_s0_wb_cyc  = current_slave == 4'd0 ? master_cyc : 1'd0;
238
assign o_s0_wb_stb  = current_slave == 4'd0 ? master_stb : 1'd0;
239
 
240
// Boot Memory outputs
241
assign o_s1_wb_adr  = master_adr;
242
assign o_s1_wb_dat  = master_wdat;
243
assign o_s1_wb_sel  = master_sel;
244
assign o_s1_wb_we   = current_slave == 4'd1 ? master_we  : 1'd0;
245
assign o_s1_wb_cyc  = current_slave == 4'd1 ? master_cyc : 1'd0;
246
assign o_s1_wb_stb  = current_slave == 4'd1 ? master_stb : 1'd0;
247
 
248
// Main Memory Outputs
249
assign o_s2_wb_adr  = master_adr;
250
assign o_s2_wb_dat  = master_wdat;
251
assign o_s2_wb_sel  = master_sel;
252
assign o_s2_wb_we   = current_slave == 4'd2 ? master_we  : 1'd0;
253
assign o_s2_wb_cyc  = current_slave == 4'd2 ? master_cyc : 1'd0;
254
assign o_s2_wb_stb  = current_slave == 4'd2 ? master_stb : 1'd0;
255
 
256
// UART0 Outputs
257
assign o_s3_wb_adr  = master_adr;
258
assign o_s3_wb_dat  = master_wdat;
259
assign o_s3_wb_sel  = master_sel;
260
assign o_s3_wb_we   = current_slave == 4'd3 ? master_we  : 1'd0;
261
assign o_s3_wb_cyc  = current_slave == 4'd3 ? master_cyc : 1'd0;
262
assign o_s3_wb_stb  = current_slave == 4'd3 ? master_stb : 1'd0;
263
 
264
// UART1 Outputs
265
assign o_s4_wb_adr  = master_adr;
266
assign o_s4_wb_dat  = master_wdat;
267
assign o_s4_wb_sel  = master_sel;
268
assign o_s4_wb_we   = current_slave == 4'd4 ? master_we  : 1'd0;
269
assign o_s4_wb_cyc  = current_slave == 4'd4 ? master_cyc : 1'd0;
270
assign o_s4_wb_stb  = current_slave == 4'd4 ? master_stb : 1'd0;
271
 
272
// Test Module Outputs
273
assign o_s5_wb_adr  = master_adr;
274
assign o_s5_wb_dat  = master_wdat;
275
assign o_s5_wb_sel  = master_sel;
276
assign o_s5_wb_we   = current_slave == 5'd5 ? master_we  : 1'd0;
277
assign o_s5_wb_cyc  = current_slave == 5'd5 ? master_cyc : 1'd0;
278
assign o_s5_wb_stb  = current_slave == 5'd5 ? master_stb : 1'd0;
279
 
280
// Timers Outputs
281
assign o_s6_wb_adr  = master_adr;
282
assign o_s6_wb_dat  = master_wdat;
283
assign o_s6_wb_sel  = master_sel;
284
assign o_s6_wb_we   = current_slave == 6'd6 ? master_we  : 1'd0;
285
assign o_s6_wb_cyc  = current_slave == 6'd6 ? master_cyc : 1'd0;
286
assign o_s6_wb_stb  = current_slave == 6'd6 ? master_stb : 1'd0;
287
 
288
// Interrupt Controller
289
assign o_s7_wb_adr  = master_adr;
290
assign o_s7_wb_dat  = master_wdat;
291
assign o_s7_wb_sel  = master_sel;
292
assign o_s7_wb_we   = current_slave == 4'd7 ? master_we  : 1'd0;
293
assign o_s7_wb_cyc  = current_slave == 4'd7 ? master_cyc : 1'd0;
294
assign o_s7_wb_stb  = current_slave == 4'd7 ? master_stb : 1'd0;
295
 
296
 
297
// Master Outputs
298
assign master_rdat  = current_slave == 4'd0  ? i_s0_wb_dat  :
299
                      current_slave == 4'd1  ? i_s1_wb_dat  :
300
                      current_slave == 4'd2  ? i_s2_wb_dat  :
301
                      current_slave == 4'd3  ? i_s3_wb_dat  :
302
                      current_slave == 4'd4  ? i_s4_wb_dat  :
303
                      current_slave == 4'd5  ? i_s5_wb_dat  :
304
                      current_slave == 4'd6  ? i_s6_wb_dat  :
305
                      current_slave == 4'd7  ? i_s7_wb_dat  :
306
                                               i_s2_wb_dat  ;
307
 
308
 
309
assign master_ack   = current_slave == 4'd0  ? i_s0_wb_ack  :
310
                      current_slave == 4'd1  ? i_s1_wb_ack  :
311
                      current_slave == 4'd2  ? i_s2_wb_ack  :
312
                      current_slave == 4'd3  ? i_s3_wb_ack  :
313
                      current_slave == 4'd4  ? i_s4_wb_ack  :
314
                      current_slave == 4'd5  ? i_s5_wb_ack  :
315
                      current_slave == 4'd6  ? i_s6_wb_ack  :
316
                      current_slave == 4'd7  ? i_s7_wb_ack  :
317
                                               i_s2_wb_ack  ;
318
 
319
 
320
assign master_err   = current_slave == 4'd0  ? i_s0_wb_err  :
321
                      current_slave == 4'd1  ? i_s1_wb_err  :
322
                      current_slave == 4'd2  ? i_s2_wb_err  :
323
                      current_slave == 4'd3  ? i_s3_wb_err  :
324
                      current_slave == 4'd4  ? i_s4_wb_err  :
325
                      current_slave == 4'd5  ? i_s5_wb_err  :
326
                      current_slave == 4'd6  ? i_s6_wb_err  :
327
                      current_slave == 4'd7  ? i_s7_wb_err  :
328
                                               i_s2_wb_err  ;
329
 
330
 
331
// Ethmac Master Outputs
332
// Switch endianess of ethmac Master
333
assign o_m0_wb_dat  = {master_rdat[7:0], master_rdat[15:8],
334
                       master_rdat[23:16],master_rdat[31:24]};
335
assign o_m0_wb_ack  = current_master  ? 1'd0 : master_ack ;
336
assign o_m0_wb_err  = current_master  ? 1'd0 : master_err ;
337
 
338
// Amber Master Outputs
339
assign o_m1_wb_dat  = master_rdat;
340
assign o_m1_wb_ack  = current_master  ?  master_ack : 1'd0 ;
341
assign o_m1_wb_err  = current_master  ?  master_err : 1'd0 ;
342
 
343
endmodule
344
 

powered by: WebSVN 2.1.0

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