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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [lib/] [wb_crossbar.v] - Blame information for rev 10

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

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

powered by: WebSVN 2.1.0

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