1 |
2 |
btltz |
//File name=Module=SwitchMatrix 2005-04-10 btltz@mail.china.com btltz from CASIC
|
2 |
|
|
//Description: buffered digital SwitchMatrix
|
3 |
|
|
// * 16 x 16 switch connecting sixteen 9-bit FIFO I/O ports to
|
4 |
|
|
// sixteen 9-bit output ports with 16 x 16 x ?? = 256 syn buffers. buffered each point
|
5 |
|
|
//Abbreviations: crd --- credit
|
6 |
|
|
// alw --- allow
|
7 |
|
|
//Origin: SpaceWire Std - Draft-1(Clause 8)of ECSS(European Cooperation for Space Standardization),ESTEC,ESA.
|
8 |
|
|
// SpaceWire Router Requirements Specification Issue 1 Rev 5. Astrium & University of Dundee
|
9 |
|
|
//TODO: make rtl faster
|
10 |
|
|
////////////////////////////////////////////////////////////////////////////////////
|
11 |
|
|
//
|
12 |
|
|
/*synthesis translate off*/
|
13 |
|
|
`timescale 1ns/100ps
|
14 |
|
|
/*synthesis translate on */
|
15 |
|
|
`define reset 1 // WISHBONE standard reset
|
16 |
|
|
|
17 |
|
|
module SwitchMatrix #(parameter BW=10, PORTNUM=16, AW=4, // (1byte + 1)Byte-WIDTH 16x16 crossbar swith
|
18 |
|
|
CellDepth =255, // 16x16 beffers x (255Byte x 10-bit / Cell)
|
19 |
|
|
WCCNT = (CellDepth ==255 ? 8 :
|
20 |
|
|
(CellDepth ==511 ? 9 :
|
21 |
|
|
(CellDepth == 1023 ? 10 : 'bx )) ),
|
22 |
|
|
WIDTH_CRD = (CellDepth ==255 && PORTNUM ==16) ? 12 : //255depth x16ports = 4080 Bbytes/column
|
23 |
|
|
((CellDepth ==511 && PORTNUM ==16) ? 13 : //511depth x 16ports = 8176 Bbytes/column
|
24 |
|
|
((CellDepth == 1023 && PORTNUM == 16) ? 14 :
|
25 |
|
|
((CellDepth ==255 && PORTNUM ==8) ? 11 :
|
26 |
|
|
((CellDepth ==511 && PORTNUM ==8) ? 12 :
|
27 |
|
|
((CellDepth ==1023 && PORTNUM ==8) ? 13 :'bx )))))
|
28 |
|
|
)
|
29 |
|
|
( // Byte width data input(output) from(to) FIFO
|
30 |
|
|
output reg [BW-1:0] do [0:PORTNUM-1],
|
31 |
|
|
input [BW-1:0] di [0:PORTNUM-1],
|
32 |
|
|
|
33 |
|
|
output [PORTNUM-1:0] PHasData_o, //a output port has data to transmit
|
34 |
|
|
// Configuration Port
|
35 |
|
|
//output [WIDTH_CRD-1:0] crd_o [0:PORTNUM-1], // credit output back to each in line
|
36 |
|
|
output reg [PORTNUM-1:0] sop_ack_o, //level
|
37 |
|
|
input [PORTNUM-1:0] sop_req_i, //pulse
|
38 |
|
|
input [PORTNUM-1:0] eop_i, //pulse
|
39 |
|
|
input [AW-1:0] out_addr_i [0:PORTNUM], //select output column
|
40 |
|
|
//input [PORTNUM-1:0] ld_inaddr_i, ld_outaddr_i,
|
41 |
|
|
//System interface
|
42 |
|
|
input reset, gclk
|
43 |
|
|
);
|
44 |
|
|
|
45 |
|
|
parameter True = 1;
|
46 |
|
|
parameter False = 0;
|
47 |
|
|
|
48 |
|
|
// unsuported ports array declaration
|
49 |
|
|
input [BW-1:0] do [0:PORTNUM-1];
|
50 |
|
|
wire [BW-1:0] di [0:PORTNUM-1];
|
51 |
|
|
|
52 |
|
|
// Register to provide address when write(read) line(column).
|
53 |
|
|
// Each output port = 1 column
|
54 |
|
|
reg [AW-1:0] SelColumn [0:PORTNUM-1]; // for line cells selection//bit width ,depth
|
55 |
|
|
reg [AW-1:0] SelColine [0:PORTNUM-1]; // for MUXes select lines in a column
|
56 |
|
|
wire [PORTNUM-1:0] ld_SelColumn = sop_req_i;
|
57 |
|
|
wire [PORTNUM-1:0] ld_SelColine; // load select lines in a column
|
58 |
|
|
|
59 |
|
|
wire [AW1:0] ScheOut; //output from the schedule.Determine which line in a column has priority
|
60 |
|
|
|
61 |
|
|
//opposite line| each column
|
62 |
|
|
wire [BW-1:0] CellOut [0:PORTNUM] [0:PORTNUM]; //16x16 *9 from cell fifo to MUXes
|
63 |
|
|
wire [WCCNT-1:0] CellCnt [0:PORTNUM] [0:PORTNUM]; //data num(vectors) in each switch cell
|
64 |
|
|
// Cell Control Lines
|
65 |
|
|
reg [PORTNUM-1:0] wr_en [0:PORTNUM-1];
|
66 |
|
|
reg [PORTNUM-1:0] rd_en [0:PORTNUM-1];
|
67 |
|
|
wire [PORTNUM-1:0] clrCell[0:PORTNUM];
|
68 |
|
|
wire [PORTNUM-1:0] CellEmpty [0:PORTNUM];
|
69 |
|
|
wire [PORTNUM-1:0] CellFull [0:PORTNUM];
|
70 |
|
|
wire [PORTNUM-1:0] CellAfull [0:PORTNUM]; // buffer cell almost full
|
71 |
|
|
wire [PORTNUM-1:0] CellAempty [0:PORTNUM]; // buffer cell almost empty
|
72 |
|
|
|
73 |
|
|
wire [PORTNUM-1:0] CellHasData [0:PORTNUM] = ~CellEmpty; //? is the syntax right ?
|
74 |
|
|
wire [PORTNUM-1:0] CellHasSpc [0:PORTNUM] = ~CellFull;
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
// signal for Matrix Output management
|
78 |
|
|
reg [PORTNUM-1:0] columnHasData;
|
79 |
|
|
wire [PORTNUM-1:0] ColumnOE = columnHasData;
|
80 |
|
|
assign PHasData_o = columnHasData; //Port Has Data.Synchronous output to write Tx FIFO
|
81 |
|
|
|
82 |
|
|
// reg [WIDTH_CRD-1:0] crdcnt [0:PORTNUM-1];//credit counter
|
83 |
|
|
// assign crd_o = crdcnt;
|
84 |
|
|
|
85 |
|
|
/////////////////////////////////////
|
86 |
|
|
// Config input/output address REGs
|
87 |
|
|
//
|
88 |
|
|
always @(posedge gclk)
|
89 |
|
|
begin
|
90 |
|
|
integer i=0;
|
91 |
|
|
if(reset)
|
92 |
|
|
begin
|
93 |
|
|
SelColumn <= 0;
|
94 |
|
|
SelLine <= 0;
|
95 |
|
|
end
|
96 |
|
|
else begin
|
97 |
|
|
for (i=0; i<PORTNUM; i=i+1 )
|
98 |
|
|
begin
|
99 |
|
|
if( ld_SelColumn[i] == True ) // ld_SelColumn = sop_req_i; Note taht the addr must be valid.
|
100 |
|
|
SelColumn[i] <= out_addr_i[i]; // Address Vector load
|
101 |
|
|
if( ld_SelColine[i] == True ) // if the scheduler load output address.
|
102 |
|
|
SelColine[i] <= ScheOut [i]; // Address Vector load
|
103 |
|
|
end
|
104 |
|
|
end
|
105 |
|
|
end
|
106 |
|
|
|
107 |
|
|
///////////////////////
|
108 |
|
|
// Matrix Cell buffers
|
109 |
|
|
//
|
110 |
|
|
// note: should select devices that have true dual port RAM
|
111 |
|
|
|
112 |
|
|
generate
|
113 |
|
|
begin:GEN_Cell
|
114 |
|
|
genvar i,k;
|
115 |
|
|
for (i=0; i<PORTNUM; i=i+1) // i : each column
|
116 |
|
|
begin
|
117 |
|
|
for (k=0; k<PORTNUM; k=k+1) // k : in a column(sel line)
|
118 |
|
|
begin
|
119 |
|
|
eth_fifo #(parameter DATA_WIDTH=BW, DEPTH=CellDepth) // byte width=9, depth=? undetermined
|
120 |
|
|
Cell_Fifo_Array
|
121 |
|
|
(.data_in ( di[k] ), // different colum has same data input line
|
122 |
|
|
.data_out( CellOut[i][k] ),// k assign to 1 column,i assign to n columns.L<-R
|
123 |
|
|
.write ( wr_en[i][k] ),
|
124 |
|
|
.read ( rd_en[i][k] ),
|
125 |
|
|
.clear ( clrCell[i][k] ),
|
126 |
|
|
.almost_full ( CellAfull[i][k] ),
|
127 |
|
|
.full ( CellFull[i][k] ),
|
128 |
|
|
.almost_empty( CellAempty[i][k] ),
|
129 |
|
|
.empty ( CellEmpty[i][k] ),
|
130 |
|
|
.gclk ( gclk ),
|
131 |
|
|
.reset( reset ),
|
132 |
|
|
.cnt( CellCnt[i][k] ) //may be usable
|
133 |
|
|
);
|
134 |
|
|
end //end 1 column (16x1 )
|
135 |
|
|
end //end 1 array (16x16)
|
136 |
|
|
end //end GEN_Cell
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
/////////////////////////////////////////
|
141 |
|
|
// Distribute lines data
|
142 |
|
|
// to the Matrix Cell
|
143 |
|
|
reg [PORTNUM-1:0] wpen ; // Write Packages Enable
|
144 |
|
|
|
145 |
|
|
//register sop_req_i or eop_i pulse
|
146 |
|
|
always @(posedge gclk)
|
147 |
|
|
begin
|
148 |
|
|
integer k;
|
149 |
|
|
if(reset==`reset)
|
150 |
|
|
wpen <= 0;
|
151 |
|
|
else begin
|
152 |
|
|
for(k=0; k<PORTNUM; k=k+1)
|
153 |
|
|
begin
|
154 |
|
|
if(eop_i[k])
|
155 |
|
|
wpen[k] <= 1'b0;
|
156 |
|
|
else if(sop_req_i[k])
|
157 |
|
|
wpen[k] <= 1'b1;
|
158 |
|
|
end
|
159 |
|
|
end
|
160 |
|
|
end
|
161 |
|
|
|
162 |
|
|
reg [PORTNUM-1:0] wr__; // level signal
|
163 |
|
|
|
164 |
|
|
always @(*)
|
165 |
|
|
begin
|
166 |
|
|
for (k =0; k <PORTNUM; k =k+1)
|
167 |
|
|
wr__[k] = ( wpen[k] ==False || eop_i[k]) ? 0 :
|
168 |
|
|
( ( wpen[k] ==True && eop_i[k] ==False ) ? 1'b1 : 'bx );
|
169 |
|
|
end
|
170 |
|
|
|
171 |
|
|
//decode config addr according to the external controller
|
172 |
|
|
//(and the package addr head). Generate cell "we" signals array.
|
173 |
|
|
always @(*)
|
174 |
|
|
begin
|
175 |
|
|
integer i,k;
|
176 |
|
|
for (i=0; i<PORTNUM; i=i+1) // i : each column
|
177 |
|
|
begin
|
178 |
|
|
for (k=0; k<PORTNUM; k=k+1) // k : lines in a column(sel line)
|
179 |
|
|
begin
|
180 |
|
|
wr_en[i][k] = ( wr__[i] // write to x column
|
181 |
|
|
&& SelColine[i] ==k // select a line in a column
|
182 |
|
|
&& CellHasSpc[i][k] ==True // that cell is not full
|
183 |
|
|
)
|
184 |
|
|
? 1'b1 : 1'b0;
|
185 |
|
|
sop_ack_o[i] = (SelColine[i] ==k // "select a line" must has been configed
|
186 |
|
|
&& CellHasSpc[i][k] ==True // that cell is not full
|
187 |
|
|
)
|
188 |
|
|
? 1'b1 : 1'b0;
|
189 |
|
|
end
|
190 |
|
|
end
|
191 |
|
|
end
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
/////////////////////////
|
195 |
|
|
// Read enable to Tx Fifo
|
196 |
|
|
//
|
197 |
|
|
////////////////////
|
198 |
|
|
// Credit collecting credit information to The Input Line
|
199 |
|
|
// Output Schedulers are responsible for selecting eligible
|
200 |
|
|
|
201 |
|
|
always @ (*)
|
202 |
|
|
begin
|
203 |
|
|
integer m;
|
204 |
|
|
for(m=0; m<PORTNUM; m=m+1)
|
205 |
|
|
columnHasData[m] = | celHasData[m];
|
206 |
|
|
// cellHasData[m][0] || cellHasData[m][1] || ...|| cellHasData[m][15]
|
207 |
|
|
end
|
208 |
|
|
|
209 |
|
|
//////////////////////////////
|
210 |
|
|
// 16 Output column Schedulers
|
211 |
|
|
//
|
212 |
|
|
//////////////////////////////
|
213 |
|
|
// 1 scheduler is responsible to 32 cell in a column
|
214 |
|
|
|
215 |
|
|
generate
|
216 |
|
|
begin:GEN_Schedulers
|
217 |
|
|
for (i=0; i<PORTNUM; i=i+1) // i : each column
|
218 |
|
|
begin
|
219 |
|
|
for (k=0; k<PORTNUM; k=k+1) // k : in a column(sel line)
|
220 |
|
|
begin
|
221 |
|
|
CSer #() inst_CSer
|
222 |
|
|
( .ld_SelCoLine_o( ld_SelColine ),
|
223 |
|
|
.empty_i(CellEmpty[i][k] ), // one-hot input
|
224 |
|
|
.Aempty_i(CellAfull[i][k]), // one-hot
|
225 |
|
|
.addr_o( ScheOut[i] ),
|
226 |
|
|
.reset(reset)
|
227 |
|
|
.gclk(gclk)
|
228 |
|
|
);
|
229 |
|
|
end // end lines in a column
|
230 |
|
|
end // end columns
|
231 |
|
|
end
|
232 |
|
|
endgenerate
|
233 |
|
|
|
234 |
|
|
////////////////////////////
|
235 |
|
|
// 16 outputs
|
236 |
|
|
//
|
237 |
|
|
always @(*)
|
238 |
|
|
begin
|
239 |
|
|
integer n;
|
240 |
|
|
for (n=0; n<PORTNUM; n=n+1)
|
241 |
|
|
begin
|
242 |
|
|
if(columOE)
|
243 |
|
|
do[n] = CellOut[SelLine][n]; // n : (port0 -> port15)
|
244 |
|
|
else
|
245 |
|
|
do[n] = 'b0; // 10'b p0_0000_0000
|
246 |
|
|
end // EOP = 10'b p1_0000_0000
|
247 |
|
|
end
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
/*///////////////
|
251 |
|
|
// Functions
|
252 |
|
|
//
|
253 |
|
|
function [15:0] greyiDEC4_16; //Grey code input decoder
|
254 |
|
|
input [3:0] in;
|
255 |
|
|
begin
|
256 |
|
|
case (in)
|
257 |
|
|
4'b0000 : greyiDEC4_16 = 16'h1;
|
258 |
|
|
4'b0001 : greyiDEC4_16 = 16'h2;
|
259 |
|
|
4'b0011 : greyiDEC4_16 = 16'h4;
|
260 |
|
|
4'b0010 : greyiDEC4_16 = 16'h8;
|
261 |
|
|
4'b0110 : greyiDEC4_16 = 16'h10;
|
262 |
|
|
4'b0111 : greyiDEC4_16 = 16'h20;
|
263 |
|
|
4'b0101 : greyiDEC4_16 = 16'h40;
|
264 |
|
|
4'b0100 : greyiDEC4_16 = 16'h80;
|
265 |
|
|
4'b1100 : greyiDEC4_16 = 16'h100;
|
266 |
|
|
4'b1101 : greyiDEC4_16 = 16'h200;
|
267 |
|
|
4'b1111 : greyiDEC4_16 = 16'h400;
|
268 |
|
|
4'b1110 : greyiDEC4_16 = 16'h800;
|
269 |
|
|
4'b1010 : greyiDEC4_16 = 16'h1000;
|
270 |
|
|
4'b1011 : greyiDEC4_16 = 16'h2000;
|
271 |
|
|
4'b1001 : greyiDEC4_16 = 16'h4000;
|
272 |
|
|
4'b1000 : greyiDEC4_16 = 16'h8000;
|
273 |
|
|
default : greyiDEC4_16 = 'bx;
|
274 |
|
|
endcase
|
275 |
|
|
end
|
276 |
|
|
endfunction */
|
277 |
|
|
|
278 |
|
|
endmodule
|
279 |
|
|
|
280 |
|
|
`undef reset
|