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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [lib/] [wb_crossbar.v] - Blame information for rev 74

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

Line No. Rev Author Line
1 70 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Tubo 8051 cores common library Module                       ////
4
////                                                              ////
5
////  This file is part of the Turbo 8051 cores project           ////
6
////  http://www.opencores.org/cores/turbo8051/                   ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Turbo 8051 definitions.                                     ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@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
/**********************************************
45
      Web-bone cross bar M-Master By S-Slave
46
**********************************************/
47
 
48
module wb_crossbar (
49
 
50
              rst_n               ,
51
              clk                 ,
52
 
53
 
54
    // Master Interface Signal
55
              wbd_taddr_master    ,
56
              wbd_din_master      ,
57
              wbd_dout_master     ,
58
              wbd_adr_master      ,
59
              wbd_be_master       ,
60
              wbd_we_master       ,
61
              wbd_ack_master      ,
62
              wbd_stb_master      ,
63
              wbd_cyc_master      ,
64
              wbd_err_master      ,
65
              wbd_rty_master      ,
66
 
67
    // Slave Interface Signal
68
              wbd_din_slave       ,
69
              wbd_dout_slave      ,
70
              wbd_adr_slave       ,
71
              wbd_be_slave        ,
72
              wbd_we_slave        ,
73
              wbd_ack_slave       ,
74
              wbd_stb_slave       ,
75
              wbd_cyc_slave       ,
76
              wbd_err_slave       ,
77
              wbd_rty_slave
78
         );
79
 
80
parameter WB_SLAVE   = 4 ;
81
parameter WB_MASTER  = 4 ;
82
 
83
parameter D_WD    = 16; // Data Width
84
parameter BE_WD   = 2;  // Byte Enable
85
parameter ADR_WD  = 28; // Address Width
86
parameter TAR_WD  = 4;  // Target Width
87
 
88
input                  clk; // CLK_I The clock input [CLK_I] coordinates all activities 
89
                            // for the internal logic within the WISHBONE interconnect. 
90
                            // All WISHBONE output signals are registered at the 
91
                            // rising edge of [CLK_I]. 
92
                            // All WISHBONE input signals must be stable before the 
93
                            // rising edge of [CLK_I]. 
94
input                  rst_n; // RST_I The reset input [RST_I] forces the WISHBONE interface 
95
                            // to restart. Furthermore, all internal self-starting state 
96
                            // machines will be forced into an initial state. 
97
 
98
input [(WB_MASTER *TAR_WD)-1:0] wbd_taddr_master; // target address from master 
99
input [WB_MASTER-1:0]  wbd_stb_master;
100
                    // STB_O The strobe output [STB_O] indicates a valid data 
101
                    // transfer cycle. It is used to qualify various other signals 
102
                    // on the interface such as [SEL_O(7..0)]. The SLAVE must 
103
                    // assert either the [ACK_I], [ERR_I] or [RTY_I] signals in 
104
                    // response to every assertion of the [STB_O] signal. 
105
output [WB_SLAVE-1:0]  wbd_stb_slave;
106
                    // STB_O The strobe output [STB_O] indicates a valid data 
107
                    // transfer cycle. It is used to qualify various other signals 
108
                    // on the interface such as [SEL_O(7..0)]. The SLAVE must 
109
                    // assert either the [ACK_I], [ERR_I] or [RTY_I] signals in 
110
                    // response to every assertion of the [STB_O] signal. 
111
 
112
input [WB_MASTER-1:0]   wbd_we_master;
113
                    // WE_O The write enable output [WE_O] indicates whether the 
114
                    // current local bus cycle is a READ or WRITE cycle. The 
115
                    // signal is negated during READ cycles, and is asserted 
116
                    // during WRITE cycles. 
117
output [WB_SLAVE-1:0]   wbd_we_slave;
118
                    // WE_O The write enable output [WE_O] indicates whether the 
119
                    // current local bus cycle is a READ or WRITE cycle. The 
120
                    // signal is negated during READ cycles, and is asserted 
121
                    // during WRITE cycles. 
122
 
123
output [WB_MASTER-1:0]  wbd_ack_master;
124
                    // The acknowledge input [ACK_I], when asserted, 
125
                    // indicates the termination of a normal bus cycle. 
126
                    // Also see the [ERR_I] and [RTY_I] signal descriptions. 
127
input [WB_SLAVE-1:0]  wbd_ack_slave;
128
                    // The acknowledge input [ACK_I], when asserted, 
129
                    // indicates the termination of a normal bus cycle. 
130
                    // Also see the [ERR_I] and [RTY_I] signal descriptions. 
131
 
132
input [(WB_MASTER *ADR_WD)-1:0] wbd_adr_master;
133
                    // The address output array [ADR_O(63..0)] is used 
134
                    // to pass a binary address, with the most significant 
135
                    // address bit at the higher numbered end of the signal array. 
136
                    // The lower array boundary is specific to the data port size. 
137
                    // The higher array boundary is core-specific. 
138
                    // In some cases (such as FIFO interfaces) 
139
                    // the array may not be present on the interface. 
140
 
141
output [(WB_SLAVE *ADR_WD)-1:0] wbd_adr_slave;
142
                    // The address output array [ADR_O(63..0)] is used 
143
                    // to pass a binary address, with the most significant 
144
                    // address bit at the higher numbered end of the signal array. 
145
                    // The lower array boundary is specific to the data port size. 
146
                    // The higher array boundary is core-specific. 
147
                    // In some cases (such as FIFO interfaces) 
148
                    // the array may not be present on the interface. 
149
 
150
input [(WB_MASTER * BE_WD)-1:0] wbd_be_master; // Byte Enable 
151
                    // SEL_O(7..0) The select output array [SEL_O(7..0)] indicates 
152
                    // where valid data is expected on the [DAT_I(63..0)] signal 
153
                    // array during READ cycles, and where it is placed on the 
154
                    // [DAT_O(63..0)] signal array during WRITE cycles. 
155
                    // Also see the [DAT_I(63..0)], [DAT_O(63..0)] and [STB_O] 
156
                    // signal descriptions.
157
output [(WB_SLAVE * BE_WD)-1:0] wbd_be_slave; // Byte Enable  
158
                    // SEL_O(7..0) The select output array [SEL_O(7..0)] indicates 
159
                    // where valid data is expected on the [DAT_I(63..0)] signal 
160
                    // array during READ cycles, and where it is placed on the 
161
                    // [DAT_O(63..0)] signal array during WRITE cycles. 
162
                    // Also see the [DAT_I(63..0)], [DAT_O(63..0)] and [STB_O] 
163
                    // signal descriptions.
164
 
165
input [WB_SLAVE -1:0] wbd_cyc_master;
166
                    // CYC_O The cycle output [CYC_O], when asserted, 
167
                    // indicates that a valid bus cycle is in progress. 
168
                    // The signal is asserted for the duration of all bus cycles. 
169
                    // For example, during a BLOCK transfer cycle there can be 
170
                    // multiple data transfers. The [CYC_O] signal is asserted 
171
                    // during the first data transfer, and remains asserted 
172
                    // until the last data transfer. The [CYC_O] signal is useful 
173
                    // for interfaces with multi-port interfaces 
174
                    // (such as dual port memories). In these cases, 
175
                    // the [CYC_O] signal requests use of a common bus from an 
176
                    // arbiter. Once the arbiter grants the bus to the MASTER, 
177
                    // it is held until [CYC_O] is negated. 
178
output [WB_SLAVE -1:0] wbd_cyc_slave;
179
                    // CYC_O The cycle output [CYC_O], when asserted, 
180
                    // indicates that a valid bus cycle is in progress. 
181
                    // The signal is asserted for the duration of all bus cycles. 
182
                    // For example, during a BLOCK transfer cycle there can be 
183
                    // multiple data transfers. The [CYC_O] signal is asserted 
184
                    // during the first data transfer, and remains asserted 
185
                    // until the last data transfer. The [CYC_O] signal is useful 
186
                    // for interfaces with multi-port interfaces 
187
                    // (such as dual port memories). In these cases, 
188
                    // the [CYC_O] signal requests use of a common bus from an 
189
                    // arbiter. Once the arbiter grants the bus to the MASTER, 
190
                    // it is held until [CYC_O] is negated. 
191
 
192
input [(WB_MASTER * D_WD)-1:0] wbd_din_master;
193
                    // DAT_I(63..0) The data input array [DAT_I(63..0)] is 
194
                    // used to pass binary data. The array boundaries are 
195
                    // determined by the port size. Also see the [DAT_O(63..0)] 
196
                    // and [SEL_O(7..0)] signal descriptions. 
197
 
198
output [(WB_SLAVE * D_WD)-1:0] wbd_din_slave;
199
                    // DAT_I(63..0) The data input array [DAT_I(63..0)] is 
200
                    // used to pass binary data. The array boundaries are 
201
                    // determined by the port size. Also see the [DAT_O(63..0)] 
202
                    // and [SEL_O(7..0)] signal descriptions. 
203
 
204
output [(WB_MASTER * D_WD)-1:0] wbd_dout_master;
205
                    // DAT_O(63..0) The data output array [DAT_O(63..0)] is 
206
                    // used to pass binary data. The array boundaries are 
207
                    // determined by the port size. Also see the [DAT_I(63..0)] 
208
                         // and [SEL_O(7..0)] signal descriptions. 
209
input [(WB_SLAVE * D_WD)-1:0] wbd_dout_slave;
210
                    // DAT_O(63..0) The data output array [DAT_O(63..0)] is 
211
                    // used to pass binary data. The array boundaries are 
212
                    // determined by the port size. Also see the [DAT_I(63..0)] 
213
                    // and [SEL_O(7..0)] signal descriptions. 
214
 
215
output [WB_MASTER -1:0]  wbd_err_master;
216
                    // ERR_I The error input [ERR_I] indicates an abnormal 
217
                    // cycle termination. The source of the error, and the 
218
                    // response generated by the MASTER is defined by the IP core 
219
                    // supplier in the WISHBONE DATASHEET. Also see the [ACK_I] 
220
                    // and [RTY_I] signal descriptions. 
221
input [WB_SLAVE -1:0]  wbd_err_slave;
222
                    // ERR_I The error input [ERR_I] indicates an abnormal 
223
                    // cycle termination. The source of the error, and the 
224
                    // response generated by the MASTER is defined by the IP core 
225
                    // supplier in the WISHBONE DATASHEET. Also see the [ACK_I] 
226
                    // and [RTY_I] signal descriptions. 
227
 
228
output [WB_MASTER -1:0]   wbd_rty_master;
229
                    // RTY_I The retry input [RTY_I] indicates that the indicates 
230
                    // that the interface is not ready to accept or send data, and 
231
                    // that the cycle should be retried. When and how the cycle is 
232
                    // retried is defined by the IP core supplier in the WISHBONE 
233
                    // DATASHEET. Also see the [ERR_I] and [RTY_I] signal 
234
                    // descriptions. 
235
input [WB_SLAVE -1:0]   wbd_rty_slave;
236
                    // RTY_I The retry input [RTY_I] indicates that the indicates 
237
                    // that the interface is not ready to accept or send data, and 
238
                    // that the cycle should be retried. When and how the cycle is 
239
                    // retried is defined by the IP core supplier in the WISHBONE 
240
                    // DATASHEET. Also see the [ERR_I] and [RTY_I] signal 
241
                    // descriptions. 
242
 
243
 
244
reg  [WB_MASTER-1:0]  wbd_ack_master;
245
reg  [WB_MASTER-1:0]  wbd_err_master;
246
reg  [WB_MASTER-1:0]  wbd_rty_master;
247
 
248
 
249
reg  [WB_MASTER-1:0]  master_busy; // master busy flag
250
reg  [WB_SLAVE-1:0]   slave_busy;  // slave busy flag
251
reg  [TAR_WD -1:0]     master_mx_id[WB_MASTER-1:0];
252
reg  [TAR_WD -1:0]     slave_mx_id [WB_SLAVE-1:0];
253
 
254
reg  [TAR_WD-1 :0]     cur_target_id;
255 74 dinesha
wire  [TAR_WD-1:0]     wbd_taddr_master_t[WB_MASTER:0]; // target address from master 
256 70 dinesha
wire  [D_WD-1:0]       wbd_din_master_t[WB_MASTER-1:0]; // target address from master 
257
reg   [D_WD-1:0]       wbd_dout_master_t[WB_MASTER-1:0]; // target address from master 
258
wire  [ADR_WD-1:0]     wbd_adr_master_t[WB_MASTER-1:0]; // target address from master 
259
wire  [BE_WD-1:0]      wbd_be_master_t[WB_MASTER-1:0]; // target address from master 
260
 
261
 
262
reg  [WB_SLAVE-1:0]  wbd_stb_slave;
263
reg  [WB_SLAVE-1:0]  wbd_we_slave;
264
reg  [WB_SLAVE-1:0]  wbd_cyc_slave;
265
wire [D_WD-1:0]      wbd_dout_slave_t[WB_SLAVE-1:0]; // target data towards master 
266
 
267
 
268
reg   [D_WD-1:0]     wbd_din_slave_t[WB_SLAVE-1:0]; // target address from master 
269
reg   [ADR_WD-1:0]    wbd_adr_slave_t[WB_SLAVE-1:0]; // target address from master 
270
reg   [BE_WD-1:0]     wbd_be_slave_t[WB_SLAVE-1:0]; // target address from master 
271
 
272
integer i,k,l;
273
 
274
 
275
/**********************************************************
276
   Re-Arraging the array in seperate two dimensional information
277
***********************************************************/
278
 
279
genvar j,m;
280
generate
281
 
282
  // Connect the Master Mux
283
  for(j=0; j < WB_MASTER ; j = j + 1) begin : master_expand
284
     assign wbd_taddr_master_t[j] = wbd_taddr_master[((j+1)*TAR_WD)-1:j * TAR_WD];
285
     assign wbd_din_master_t[j]  = wbd_din_master[((j+1)*D_WD)-1:j * D_WD];
286
     assign wbd_adr_master_t[j]  = wbd_adr_master[((j+1)*ADR_WD)-1:j * ADR_WD];
287
     assign wbd_be_master_t[j]   = wbd_be_master[((j+1)*BE_WD)-1:j * BE_WD];
288
 
289
     assign wbd_dout_master[((j+1)*D_WD)-1:j * D_WD] = wbd_dout_master_t[j];
290
  end
291
 
292
  // Connect the Slave Mux
293
  for(m=0; m < WB_SLAVE ; m = m + 1) begin : slave_expand
294
     assign wbd_din_slave[((m+1)*D_WD)-1:m * D_WD]        = wbd_din_slave_t[m];
295
     assign wbd_adr_slave[((m+1)*ADR_WD)-1:m * ADR_WD]   = wbd_adr_slave_t[m];
296
     assign wbd_be_slave[((m+1)*BE_WD)-1:m * BE_WD]      = wbd_be_slave_t[m];
297
 
298
     assign wbd_dout_slave_t[m]   = wbd_dout_slave[((m+1)*D_WD)-1:m * D_WD];
299
 
300
  end
301
endgenerate
302
 
303
always @*   begin
304
   for(k = 0; k < WB_MASTER; k = k + 1) begin
305
      if(master_busy[k] == 1) begin
306
         wbd_dout_master_t[k] = wbd_dout_slave_t[master_mx_id[k]];
307
         wbd_ack_master[k]    = wbd_ack_slave[master_mx_id[k]];
308
         wbd_err_master[k]    = wbd_err_slave[master_mx_id[k]];
309
         wbd_rty_master[k]    = wbd_rty_slave[master_mx_id[k]];
310
      end else begin
311
         wbd_dout_master_t[k] = 0;
312
         wbd_ack_master[k]    = 0;
313
         wbd_err_master[k]    = 0;
314
         wbd_rty_master[k]    = 0;
315
      end
316
   end
317
   for(l = 0; l < WB_SLAVE; l = l + 1) begin
318
      if(slave_busy[l] == 1) begin
319
         wbd_din_slave_t[l]  = wbd_din_master_t[slave_mx_id[l]];
320
         wbd_adr_slave_t[l]  = wbd_adr_master_t[slave_mx_id[l]];
321
         wbd_be_slave_t[l]   = wbd_be_master_t[slave_mx_id[l]];
322
         wbd_stb_slave[l]    = wbd_stb_master[slave_mx_id[l]];
323
         wbd_we_slave[l]     = wbd_we_master[slave_mx_id[l]];
324
         wbd_cyc_slave[l]    = wbd_cyc_master[slave_mx_id[l]];
325
      end else begin
326
         wbd_din_slave_t[l]  = 0;
327
         wbd_adr_slave_t[l]  = 0;
328
         wbd_be_slave_t[l]   = 0;
329
         wbd_stb_slave[l]    = 0;
330
         wbd_we_slave[l]     = 0;
331
         wbd_cyc_slave[l]    = 0;
332
      end
333
   end
334
end
335
 
336
/*******************************************************
337
   Parsing through the master and deciding on mux connectio
338
   Step-1: analysis the master from 0 to total master
339
   Step-2: If the previously master is not busy,
340
           Then check for any new request from the master and
341
           check corresponding slave is free or not. If there is
342
           master request and requesting slave is free.
343
           Then set the master max id to slave id &
344
           requesting slave to master number & set the master
345
           and slave busy flag
346
   Step-3: If the previous state of master is busy and bus-cycle
347
           is de-asserted, then reset the master and corresponding
348
           slave busy flag
349
 
350
*********************************************************/
351
 
352
always @(negedge rst_n or posedge clk) begin
353
   if(rst_n == 0) begin
354
      master_busy   = 0;
355
      slave_busy    = 0;
356
      cur_target_id = 0;
357
 
358
   end
359
   else begin
360
      for(i = 0; i < WB_MASTER; i = i + 1) begin
361
         cur_target_id                     = wbd_taddr_master_t[i];
362
         if(master_busy[i] == 0) begin
363
            if(wbd_stb_master[i] & slave_busy[cur_target_id] == 0) begin
364
               master_mx_id[i] <= cur_target_id;
365
               slave_mx_id [cur_target_id] = i;
366
               slave_busy[cur_target_id]   = 1;
367
               master_busy[i]              = 1;
368
               // synopsys translate_off
369
               // $display("%m:%t: Locking Master : %d with Slave : %d",$time,i,cur_target_id);
370
               // synopsys translate_on
371
            end
372
         end else if(wbd_cyc_master[i] == 0) begin
373
            master_busy[i]            = 0;
374
            slave_busy[cur_target_id] = 0;
375
         end
376
      end
377
   end
378
end
379
 
380
 
381
 
382
endmodule

powered by: WebSVN 2.1.0

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