1 |
4 |
jefflieu |
/*
|
2 |
|
|
Developed by Jeff Lieu (lieumychuong@gmail.com)
|
3 |
|
|
|
4 |
|
|
File :
|
5 |
|
|
Description :
|
6 |
|
|
In this test, we use Altera Tranceiver as Link Partner
|
7 |
|
|
Configure bothside to be 1000BaseX Mode
|
8 |
|
|
|
9 |
|
|
Remarks :
|
10 |
|
|
There seems to be a bug in Altera's core, tx path
|
11 |
|
|
- The Tx Path sometime omits 1 pre-ample octet depending on the cycle that TxEN is aserted.
|
12 |
|
|
- At the transmit task, the #8 delay will have effect on the Altera's core. Without delay,
|
13 |
|
|
the first packet is transmitted with the first octet somehow removed (you can confirm this
|
14 |
|
|
by looking at the Codegroup that is input of u0SGMII/u0Receive/
|
15 |
|
|
- With the delay on, the first packet is fine, but the second packet has some problem.
|
16 |
|
|
- This has something todo with the alignment of the TxEN,
|
17 |
|
|
I'm not sure whether the MAC layer is responsible for aligning TxEN's assertion or not.
|
18 |
|
|
- This test only Transmits normal frame, i.e no Carrier Extension or Error Propagation
|
19 |
|
|
|
20 |
|
|
- The Path of U0 --> U1 is ok.
|
21 |
|
|
|
22 |
|
|
Revision :
|
23 |
|
|
Date Author Description
|
24 |
|
|
|
25 |
|
|
*/
|
26 |
|
|
`timescale 1ns/1ps
|
27 |
|
|
`include "SGMIIDefs.v"
|
28 |
|
|
|
29 |
|
|
module mSGMIITestbench();
|
30 |
|
|
`include "Veritil.v"
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
reg r_Reset_L;
|
34 |
|
|
reg r_Clk125M;
|
35 |
|
|
reg r_Clk50M;
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
wire w_u1RxClk;
|
39 |
|
|
wire w_u1TxClk;
|
40 |
|
|
wire w_u1RxDV;
|
41 |
|
|
wire w_u1RxER;
|
42 |
|
|
wire [07:00] w8_u1RxD;
|
43 |
|
|
wire [07:00] w8_u1TxD;
|
44 |
|
|
wire w_u1TxEN;
|
45 |
|
|
wire w_u1TxER;
|
46 |
|
|
|
47 |
|
|
wire w_u0RxDV;
|
48 |
|
|
wire w_u0RxER;
|
49 |
|
|
wire [07:00] w8_u0RxD;
|
50 |
|
|
wire [07:00] w8_u0TxD;
|
51 |
|
|
wire w_u0TxEN;
|
52 |
|
|
wire w_u0TxER;
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
wire w_u0WbCyc, w_u0WbAck, w_u0WbStb, w_u0WbWEn;
|
56 |
|
|
wire [31:00] w32_u0WbAddr, w32_u0WbWrData, w32_u0WbRdData;
|
57 |
|
|
wire w_u1WbCyc, w_u1WbAck, w_u1WbStb, w_u1WbWEn;
|
58 |
|
|
wire [31:00] w32_u1WbAddr, w32_u1WbWrData, w32_u1WbRdData;
|
59 |
|
|
wire w_u0ANDone,w_u1ANDone;
|
60 |
|
|
|
61 |
|
|
`define tstcfg_Normal 0
|
62 |
|
|
`define tstcfg_CarrierExt 1
|
63 |
|
|
`define tstcfg_BurstTrans 2
|
64 |
|
|
`define tstcfg_ErrorProp1 3
|
65 |
|
|
`define tstcfg_ErrorProp2 4
|
66 |
|
|
`define tstcfg_SizeXShort 0
|
67 |
|
|
`define tstcfg_SizeShort 1
|
68 |
|
|
`define tstcfg_SizeMedium 2
|
69 |
|
|
`define tstcfg_SizeLarge 3
|
70 |
|
|
`define tstcfg_SizeXLarge 4
|
71 |
|
|
|
72 |
|
|
`define tstcfg_1000X 0
|
73 |
|
|
`define tstcfg_SGMII1G 1
|
74 |
|
|
`define tstcfg_SGMII100M 2
|
75 |
|
|
|
76 |
|
|
integer tstcfg_Standard;
|
77 |
|
|
|
78 |
|
|
integer tstcfg_PktSize;
|
79 |
|
|
integer tstcfg_Type;
|
80 |
|
|
integer tstcfg_Seed;
|
81 |
|
|
integer tstcfg_TxPktCnt;
|
82 |
|
|
integer tstcfg_RxPktCnt;
|
83 |
|
|
|
84 |
|
|
reg [15:00] r16_CoreVersion;
|
85 |
|
|
wire [01:00] w2_u0Speed;
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
initial r_Clk125M <= 1'b0;
|
89 |
|
|
initial r_Clk50M <= 1'b0;
|
90 |
|
|
always@*
|
91 |
|
|
#4 r_Clk125M <= ~r_Clk125M;
|
92 |
|
|
|
93 |
|
|
always@*
|
94 |
|
|
#10 r_Clk50M <= ~r_Clk50M;
|
95 |
|
|
|
96 |
|
|
wire w_u0Rx,w_u0Tx;
|
97 |
|
|
wire w_u1Rx,w_u1Tx;
|
98 |
|
|
|
99 |
|
|
initial
|
100 |
|
|
begin
|
101 |
|
|
$display("------------------------------------");
|
102 |
|
|
$display("-------Subtleware Ltd Pte 2012------");
|
103 |
|
|
$display("--Testing SGMII in 1000Gb Mode------");
|
104 |
|
|
$display("------------------------------------");
|
105 |
|
|
u0WishboneMstr.tsk_Read((10<<2),r16_CoreVersion);
|
106 |
|
|
$display("---Core Version : %x", r16_CoreVersion);
|
107 |
|
|
tstcfg_TxPktCnt = 0;
|
108 |
|
|
tstcfg_RxPktCnt = 0;
|
109 |
|
|
r_Reset_L <= 1'b0;
|
110 |
|
|
#1000;
|
111 |
|
|
r_Reset_L <= 1'b1;
|
112 |
|
|
tsk_Setup();
|
113 |
|
|
end
|
114 |
|
|
|
115 |
|
|
mWishboneMstr u0WishboneMstr(
|
116 |
|
|
.o_WbCyc (w_u0WbCyc),
|
117 |
|
|
.o_WbStb (w_u0WbStb),
|
118 |
|
|
.o_WbWEn (w_u0WbWEn),
|
119 |
|
|
.ov_WbAddr (w32_u0WbAddr),
|
120 |
|
|
.ov_WbWrData(w32_u0WbWrData),
|
121 |
|
|
.iv_WbRdData(w32_u0WbRdData),
|
122 |
|
|
.i_Ack (w_u0WbAck),
|
123 |
|
|
.i_Stall (1'b0),
|
124 |
|
|
.i_Rty (1'b0),
|
125 |
|
|
.i_Clk (w_u0GMIIClk));
|
126 |
|
|
|
127 |
|
|
mWishboneMstr u1WishboneMstr(
|
128 |
|
|
.o_WbCyc (w_u1WbCyc),
|
129 |
|
|
.o_WbStb (w_u1WbStb),
|
130 |
|
|
.o_WbWEn (w_u1WbWEn),
|
131 |
|
|
.ov_WbAddr (w32_u1WbAddr),
|
132 |
|
|
.ov_WbWrData(w32_u1WbWrData),
|
133 |
|
|
.iv_WbRdData(w32_u1WbRdData),
|
134 |
|
|
.i_Ack (w_u1WbAck),
|
135 |
|
|
.i_Stall (1'b0),
|
136 |
|
|
.i_Rty (1'b0),
|
137 |
|
|
.i_Clk (w_u1RxClk));
|
138 |
|
|
|
139 |
|
|
//Tranceiver Interface
|
140 |
|
|
mSGMII u0SGMII (
|
141 |
|
|
.i_SerRx (w_u0Rx),
|
142 |
|
|
.o_SerTx (w_u0Tx),
|
143 |
|
|
.i_CalClk (r_Clk50M),
|
144 |
|
|
.i_RefClk125M (r_Clk125M),
|
145 |
|
|
.i_ARstHardware_L (r_Reset_L),
|
146 |
|
|
|
147 |
|
|
//Local BUS interface
|
148 |
|
|
//Wishbonebus, single transaction mode (non-pipeline slave)
|
149 |
|
|
.i_Cyc (w_u0WbCyc),
|
150 |
|
|
.i_Stb (w_u0WbStb),
|
151 |
|
|
.i_WEn (w_u0WbWEn),
|
152 |
|
|
.i32_WrData (w32_u0WbWrData),
|
153 |
|
|
.iv_Addr (w32_u0WbAddr[7:0]),
|
154 |
|
|
.o32_RdData (w32_u0WbRdData),
|
155 |
|
|
.o_Ack (w_u0WbAck),
|
156 |
|
|
|
157 |
|
|
.i_Mdc (1'b0),
|
158 |
|
|
.io_Mdio (),
|
159 |
|
|
|
160 |
|
|
.i_PhyLink (1'b1),
|
161 |
|
|
.i2_PhySpeed(2'b00),
|
162 |
|
|
.i_PhyDuplex(1'b0),
|
163 |
|
|
//Status
|
164 |
|
|
.o_ANDone (w_u0ANDone),
|
165 |
|
|
.o_Linkup (w_u0LinkUp),
|
166 |
|
|
.o2_SGMIISpeed (w2_u0Speed),
|
167 |
|
|
.o_SGMIIDuplex (w_u0Duplex),
|
168 |
|
|
|
169 |
|
|
//GMII Interface
|
170 |
|
|
.i8_TxD (w8_u0TxD),
|
171 |
|
|
.i_TxEN (w_u0TxEN),
|
172 |
|
|
.i_TxER (w_u0TxER),
|
173 |
|
|
.o8_RxD (w8_u0RxD),
|
174 |
|
|
.o_RxDV (w_u0RxDV),
|
175 |
|
|
.o_RxER (w_u0RxER),
|
176 |
|
|
.o_GMIIClk (w_u0GMIIClk),
|
177 |
|
|
.o_Col (),
|
178 |
|
|
.o_Crs ());
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
sgmii u1SGMII (
|
183 |
|
|
.gmii_rx_d (w8_u1RxD),
|
184 |
|
|
.gmii_rx_dv (w_u1RxDV),
|
185 |
|
|
.gmii_rx_err (w_u1RxER),
|
186 |
|
|
|
187 |
|
|
.gmii_tx_d (w8_u1TxD),
|
188 |
|
|
.gmii_tx_en (w_u1TxEN),
|
189 |
|
|
.gmii_tx_err (w_u1TxER),
|
190 |
|
|
|
191 |
|
|
.tx_clk (w_u1TxClk),//output,
|
192 |
|
|
.rx_clk (w_u1RxClk),
|
193 |
|
|
.led_an (w_u1ANDone),
|
194 |
|
|
.led_disp_err (),
|
195 |
|
|
.led_char_err (),
|
196 |
|
|
.led_link (w_led_link),
|
197 |
|
|
.rx_recovclkout (),
|
198 |
|
|
|
199 |
|
|
.rxp (w_u1Rx),
|
200 |
|
|
.txp (w_u1Tx),
|
201 |
|
|
.pcs_pwrdn_out (),
|
202 |
|
|
.reconfig_fromgxb (),
|
203 |
|
|
|
204 |
|
|
.reset_tx_clk (~r_Reset_L),
|
205 |
|
|
.reset_rx_clk (~r_Reset_L),
|
206 |
|
|
|
207 |
|
|
.readdata (w32_u1WbRdData[15:00]),
|
208 |
|
|
.waitrequest (w_AvlWaitReq),
|
209 |
|
|
.address (w32_u1WbAddr[6:2]),
|
210 |
|
|
.read (w_AvlRd),
|
211 |
|
|
.writedata (w32_u1WbWrData[15:00]),
|
212 |
|
|
.write (w_AvlWr),
|
213 |
|
|
.clk (w_u1RxClk),
|
214 |
|
|
.reset (~r_Reset_L),
|
215 |
|
|
|
216 |
|
|
.ref_clk (r_Clk125M),
|
217 |
|
|
.gxb_pwrdn_in (1'b0),
|
218 |
|
|
.gxb_cal_blk_clk (r_Clk50M),
|
219 |
|
|
.reconfig_clk (r_Clk50M),
|
220 |
|
|
.reconfig_togxb (5'b0),
|
221 |
|
|
.reconfig_busy ());
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
//MacEmulation
|
225 |
|
|
mMACEmulator u0MacEmulator(
|
226 |
|
|
.i_RxClk (w_u0GMIIClk),
|
227 |
|
|
.i_TxClk (w_u0GMIIClk),
|
228 |
|
|
|
229 |
|
|
.i8_RxD (w8_u0RxD),
|
230 |
|
|
.i_RxDV (w_u0RxDV),
|
231 |
|
|
.i_RxER (w_u0RxER),
|
232 |
|
|
.o8_TxD (w8_u0TxD),
|
233 |
|
|
.o_TxEN (w_u0TxEN),
|
234 |
|
|
.o_TxER (w_u0TxER),
|
235 |
|
|
|
236 |
|
|
.i_Reset_L(r_Reset_L));
|
237 |
|
|
|
238 |
|
|
mMACEmulator u1MacEmulator(
|
239 |
|
|
.i_RxClk (w_u1RxClk),
|
240 |
|
|
.i_TxClk (w_u1TxClk),
|
241 |
|
|
.i8_RxD (w8_u1RxD),
|
242 |
|
|
.i_RxDV (w_u1RxDV),
|
243 |
|
|
.i_RxER (w_u1RxER),
|
244 |
|
|
.o8_TxD (w8_u1TxD),
|
245 |
|
|
.o_TxEN (w_u1TxEN),
|
246 |
|
|
.o_TxER (w_u1TxER),
|
247 |
|
|
|
248 |
|
|
.i_Reset_L(r_Reset_L));
|
249 |
|
|
|
250 |
|
|
|
251 |
|
|
|
252 |
|
|
//This portion translate Wishbone Signal to Avalon Signal
|
253 |
|
|
assign w_AvlWr = w_u1WbStb & w_u1WbCyc & w_u1WbWEn;
|
254 |
|
|
assign w_AvlRd = w_u1WbStb & w_u1WbCyc & (~w_u1WbWEn);
|
255 |
|
|
assign w_u1WbAck = ~w_AvlWaitReq;
|
256 |
|
|
|
257 |
|
|
assign w_u0Rx = w_u1Tx;
|
258 |
|
|
assign w_u1Rx = w_u0Tx;
|
259 |
|
|
|
260 |
|
|
reg [7:0] r8_TxBuffer[0:1023][0:10000];
|
261 |
|
|
integer s32_TxCarrierExtCycles[0:1023];
|
262 |
|
|
integer s32_TxCarrierErrCycles[0:1023];
|
263 |
|
|
reg [7:0] r8_u0RxBuffer[0:1023][0:10000];
|
264 |
|
|
reg [7:0] r8_u1RxBuffer[0:1023][0:10000];
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
reg [15:00] r16_u0Ability;
|
268 |
|
|
reg [15:00] r16_u1Ability;
|
269 |
|
|
reg [31:00] r32_ReadData;
|
270 |
|
|
integer I;
|
271 |
|
|
integer length;
|
272 |
|
|
integer u0RxPktCnt,u1RxPktCnt;
|
273 |
|
|
integer u0ExtCycles,u1ExtCycles;
|
274 |
|
|
integer u0ErrCycles,u1ErrCycles;
|
275 |
|
|
integer u0FrameSize,u1FrameSize;
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
initial
|
279 |
|
|
begin
|
280 |
|
|
length = 100;
|
281 |
|
|
|
282 |
|
|
#100;
|
283 |
|
|
|
284 |
|
|
$display("Waiting for Auto Negotiation Done");
|
285 |
|
|
#100;
|
286 |
|
|
while(w_u0ANDone==1'b0)
|
287 |
|
|
begin
|
288 |
|
|
@(posedge w_u0GMIIClk);#1;
|
289 |
|
|
end
|
290 |
|
|
|
291 |
|
|
//Verify link partner ability
|
292 |
|
|
u0WishboneMstr.tsk_Read(16'h14,r32_ReadData);
|
293 |
|
|
`CheckE(r32_ReadData,r16_u1Ability,"Link Partner Advertised Ability")
|
294 |
|
|
u1WishboneMstr.tsk_Read(16'h14,r32_ReadData);
|
295 |
|
|
`CheckE(r32_ReadData,r16_u0Ability,"Link Partner Advertised Ability")
|
296 |
|
|
|
297 |
|
|
#1000;
|
298 |
|
|
$display("Start Generating Scenarios");
|
299 |
|
|
for(I=0;I<1000;I=I+1)
|
300 |
|
|
tsk_ScenariosGenerator();
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
$display("Test Result: %s (Error Count = %d)",ErrorCnt>0?"FAILED":"PASSED",ErrorCnt);
|
304 |
|
|
#3000;
|
305 |
|
|
end
|
306 |
|
|
|
307 |
|
|
initial
|
308 |
|
|
begin:u1Receiving
|
309 |
|
|
u1RxPktCnt=0;
|
310 |
|
|
$display("Waiting for Auto Negotiation Done");
|
311 |
|
|
#100;
|
312 |
|
|
while(w_u1ANDone==1'b0)
|
313 |
|
|
begin
|
314 |
|
|
@(posedge w_u1RxClk);#1;
|
315 |
|
|
end
|
316 |
|
|
forever
|
317 |
|
|
begin
|
318 |
|
|
u1MacEmulator.tsk_ReceivePkt(r8_u1RxBuffer[u1RxPktCnt],u1FrameSize,u1ExtCycles,u1ErrCycles);
|
319 |
|
|
u1FrameSize--;
|
320 |
|
|
while(u1FrameSize>=0)
|
321 |
|
|
begin
|
322 |
|
|
`CheckF(r8_u1RxBuffer[u1RxPktCnt][u1FrameSize],r8_TxBuffer[u1RxPktCnt][u1FrameSize],"Received byte")
|
323 |
|
|
u1FrameSize--;
|
324 |
|
|
end
|
325 |
|
|
u1RxPktCnt=u1RxPktCnt+1;
|
326 |
|
|
$display("u1: Checked Pkt %d",u1RxPktCnt);
|
327 |
|
|
end
|
328 |
|
|
|
329 |
|
|
end
|
330 |
|
|
|
331 |
|
|
initial
|
332 |
|
|
begin:u0Receiving
|
333 |
|
|
u0RxPktCnt=0;
|
334 |
|
|
$display("Waiting for Auto Negotiation Done");
|
335 |
|
|
#100;
|
336 |
|
|
while(w_u0ANDone==1'b0)
|
337 |
|
|
begin
|
338 |
|
|
@(posedge w_u0GMIIClk);#1;
|
339 |
|
|
end
|
340 |
|
|
forever
|
341 |
|
|
begin
|
342 |
|
|
u0MacEmulator.tsk_ReceivePkt(r8_u0RxBuffer[u0RxPktCnt],u0FrameSize,u0ExtCycles,u0ErrCycles);
|
343 |
|
|
u0FrameSize--;
|
344 |
|
|
while(u0FrameSize>=0)
|
345 |
|
|
begin
|
346 |
|
|
`CheckF(r8_u0RxBuffer[u0RxPktCnt][u0FrameSize],r8_TxBuffer[u0RxPktCnt][u0FrameSize],"Received byte")
|
347 |
|
|
u0FrameSize--;
|
348 |
|
|
end
|
349 |
|
|
u0RxPktCnt=u0RxPktCnt+1;
|
350 |
|
|
$display("u0: Checked Pkt %d",u0RxPktCnt);
|
351 |
|
|
end
|
352 |
|
|
|
353 |
|
|
end
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
task tsk_Setup;
|
358 |
|
|
begin
|
359 |
|
|
//U1 is ALTERA's
|
360 |
|
|
u1WishboneMstr.tsk_Read(7'b10001_00,r16_CoreVersion);
|
361 |
|
|
$display("Altera SGMII Core Version %x",r16_CoreVersion);
|
362 |
|
|
|
363 |
|
|
u1WishboneMstr.tsk_Write(0,32'h0000_1000); //Enable Auto-Negotiation
|
364 |
|
|
r16_u1Ability=16'h01E0;
|
365 |
|
|
u1WishboneMstr.tsk_Write(7'b00100_00,r16_u1Ability); //Set Dev Ability
|
366 |
|
|
|
367 |
|
|
u1WishboneMstr.tsk_Write(7'b10010_00,32'h01E2); //Set Link Timer to 10000 ns
|
368 |
|
|
u1WishboneMstr.tsk_Write(7'b10011_00,32'h0000);
|
369 |
|
|
u1WishboneMstr.tsk_Read(7'b10010_00,r16_CoreVersion);
|
370 |
|
|
$display("Link Timer 0 %x",r16_CoreVersion);
|
371 |
|
|
u1WishboneMstr.tsk_Read(7'b10011_00,r16_CoreVersion);
|
372 |
|
|
$display("Link Timer 1 %x",r16_CoreVersion);
|
373 |
|
|
u1WishboneMstr.tsk_Write(7'b10100_00,{27'h0,1'b1,4'b1000}); //Enable 1000BASE-X Mode
|
374 |
|
|
u1WishboneMstr.tsk_Read(7'b10100_00,r16_CoreVersion);
|
375 |
|
|
$display("Mode Register 1 %x",r16_CoreVersion);
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
//U0 is MINE
|
379 |
|
|
r16_u0Ability=16'h01E0;
|
380 |
|
|
u0WishboneMstr.tsk_Write(7'b00100_00,r16_u0Ability); //Set Dev Ability
|
381 |
|
|
u0WishboneMstr.tsk_Write((8<<2),32'h0000_01E2); //Set Link Timer to 2500 ns
|
382 |
|
|
u0WishboneMstr.tsk_Write((9<<2),32'h0000_0000);
|
383 |
|
|
u0WishboneMstr.tsk_Write((31<<2),32'h0000); //Enable 1000BASE-X
|
384 |
|
|
$display("Restart PHY auto-nego");
|
385 |
|
|
u0WishboneMstr.tsk_Write(0,32'h0000_1200); //Restart Auto-negotiation
|
386 |
|
|
|
387 |
|
|
end
|
388 |
|
|
endtask
|
389 |
|
|
|
390 |
|
|
task tsk_ScenariosGenerator;
|
391 |
|
|
//Generate Type of Transmission
|
392 |
|
|
begin
|
393 |
|
|
tstcfg_Seed = $random;
|
394 |
|
|
tstcfg_Type = $dist_uniform(tstcfg_Seed,0,4);
|
395 |
|
|
tstcfg_Type = `tstcfg_Normal;
|
396 |
|
|
case(tstcfg_Type)
|
397 |
|
|
`tstcfg_Normal: begin $display("Transmit Type Normal"); tsk_TransmitNormal(); end
|
398 |
|
|
`tstcfg_BurstTrans: begin $display("Transmit Type Burst"); tsk_TransmitBurst(); end
|
399 |
|
|
`tstcfg_CarrierExt: begin $display("Transmit Type Carrier Extension"); tsk_TransmitCarrExt(); end
|
400 |
|
|
`tstcfg_ErrorProp1: begin $display("Transmit Type Error Prop within Frame"); tsk_TransmitErrInFrame(); end
|
401 |
|
|
`tstcfg_ErrorProp2: begin $display("Transmit Type Error Prop out of Frame"); tsk_TransmitErrOutFrame();end
|
402 |
|
|
endcase
|
403 |
|
|
|
404 |
|
|
end
|
405 |
|
|
endtask
|
406 |
|
|
|
407 |
|
|
task tsk_TransmitNormal;
|
408 |
|
|
integer PktSize;
|
409 |
|
|
integer PktNum;
|
410 |
|
|
integer PktIFG;
|
411 |
|
|
integer Idx;
|
412 |
|
|
integer Octet;
|
413 |
|
|
begin
|
414 |
|
|
PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
|
415 |
|
|
for(Idx=0;Idx
|
416 |
|
|
begin
|
417 |
|
|
PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
|
418 |
|
|
tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
|
419 |
|
|
|
420 |
|
|
case(tstcfg_PktSize)
|
421 |
|
|
`tstcfg_SizeXShort : PktSize = $dist_uniform(tstcfg_Seed,64,128);
|
422 |
|
|
`tstcfg_SizeShort : PktSize = $dist_uniform(tstcfg_Seed,128,512);
|
423 |
|
|
`tstcfg_SizeMedium : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
|
424 |
|
|
`tstcfg_SizeLarge : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
|
425 |
|
|
`tstcfg_SizeXLarge : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
|
426 |
|
|
endcase
|
427 |
|
|
|
428 |
|
|
s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=(PktSize&32'h1)?1:0;
|
429 |
|
|
s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=0;
|
430 |
|
|
for(Octet=0;Octet
|
431 |
|
|
begin
|
432 |
|
|
if(Octet<7)
|
433 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
|
434 |
|
|
else if(Octet==7)
|
435 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
|
436 |
|
|
else
|
437 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
|
438 |
|
|
end
|
439 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
|
440 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
|
441 |
|
|
//Transmit:
|
442 |
|
|
|
443 |
|
|
fork
|
444 |
|
|
begin
|
445 |
|
|
$display("u0: Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
|
446 |
|
|
u0MacEmulator.tsk_TransmitPkt(r8_TxBuffer[tstcfg_TxPktCnt+Idx],PktSize,PktIFG);
|
447 |
|
|
end
|
448 |
|
|
begin
|
449 |
|
|
//$display("u1: Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
|
450 |
|
|
#8; //If You Remove This Delay, you will have error in first packet.
|
451 |
|
|
//u1MacEmulator.tsk_TransmitPkt(r8_TxBuffer[tstcfg_TxPktCnt+Idx],PktSize,PktIFG);
|
452 |
|
|
end
|
453 |
|
|
join
|
454 |
|
|
|
455 |
|
|
|
456 |
|
|
end
|
457 |
|
|
tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
|
458 |
|
|
|
459 |
|
|
end
|
460 |
|
|
endtask
|
461 |
|
|
|
462 |
|
|
|
463 |
|
|
task tsk_TransmitBurst;
|
464 |
|
|
integer PktSize;
|
465 |
|
|
integer PktNum;
|
466 |
|
|
integer PktIFG;
|
467 |
|
|
integer Idx;
|
468 |
|
|
integer Octet;
|
469 |
|
|
integer ExtCycles;
|
470 |
|
|
integer TotalExtCycles;
|
471 |
|
|
integer TotalBytes;
|
472 |
|
|
integer PktStartOffset;
|
473 |
|
|
begin
|
474 |
|
|
PktNum = $dist_uniform(tstcfg_Seed,1,6);//From 1 to 10
|
475 |
|
|
PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
|
476 |
|
|
s32_TxCarrierExtCycles[tstcfg_TxPktCnt]=0;
|
477 |
|
|
TotalBytes=0;
|
478 |
|
|
TotalExtCycles=0;
|
479 |
|
|
PktStartOffset=0;
|
480 |
|
|
$display("Bursting : %d packets",PktNum);
|
481 |
|
|
for(Idx=0;Idx
|
482 |
|
|
begin
|
483 |
|
|
tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,3); //Nojumbo
|
484 |
|
|
ExtCycles = $dist_uniform(tstcfg_Seed,3,5);//Burst must have at least 2 /R/ interpacket R
|
485 |
|
|
|
486 |
|
|
case(tstcfg_PktSize)
|
487 |
|
|
`tstcfg_SizeXShort : PktSize = $dist_uniform(tstcfg_Seed,64,128);
|
488 |
|
|
`tstcfg_SizeShort : PktSize = $dist_uniform(tstcfg_Seed,128,512);
|
489 |
|
|
`tstcfg_SizeMedium : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
|
490 |
|
|
`tstcfg_SizeLarge : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
|
491 |
|
|
`tstcfg_SizeXLarge : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
|
492 |
|
|
endcase
|
493 |
|
|
|
494 |
|
|
TotalExtCycles=TotalExtCycles+ExtCycles;
|
495 |
|
|
TotalBytes = TotalBytes+PktSize;
|
496 |
|
|
|
497 |
|
|
//Generate Packet
|
498 |
|
|
for(Octet=0;Octet
|
499 |
|
|
begin
|
500 |
|
|
if(Octet<7)
|
501 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=8'h55;
|
502 |
|
|
else if(Octet==7)
|
503 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=8'hD5;
|
504 |
|
|
else
|
505 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=$random;
|
506 |
|
|
end
|
507 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+8]=PktSize & 32'h00FF;
|
508 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+9]=((PktSize & 32'hFF00)>>8);
|
509 |
|
|
//Transmit:
|
510 |
|
|
$display("Not complete task");
|
511 |
|
|
$display("Sender : Sending Packet %d (part %d) Size %d",tstcfg_TxPktCnt,Idx,PktSize);
|
512 |
|
|
end
|
513 |
|
|
//Send Interframe Gap
|
514 |
|
|
s32_TxCarrierErrCycles[tstcfg_TxPktCnt]=0;
|
515 |
|
|
s32_TxCarrierExtCycles[tstcfg_TxPktCnt]=((TotalBytes+TotalExtCycles)&32'h1)?(TotalExtCycles+1):TotalExtCycles;
|
516 |
|
|
tstcfg_TxPktCnt = tstcfg_TxPktCnt+1;
|
517 |
|
|
end
|
518 |
|
|
endtask
|
519 |
|
|
|
520 |
|
|
task tsk_TransmitCarrExt;
|
521 |
|
|
integer PktSize;
|
522 |
|
|
integer PktNum;
|
523 |
|
|
integer PktIFG;
|
524 |
|
|
integer Idx;
|
525 |
|
|
integer Octet;
|
526 |
|
|
integer ExtCycles;
|
527 |
|
|
begin
|
528 |
|
|
PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
|
529 |
|
|
for(Idx=0;Idx
|
530 |
|
|
begin
|
531 |
|
|
PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
|
532 |
|
|
tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
|
533 |
|
|
ExtCycles = $dist_uniform(tstcfg_Seed,1,100);//From 2 to 10
|
534 |
|
|
|
535 |
|
|
case(tstcfg_PktSize)
|
536 |
|
|
`tstcfg_SizeXShort : PktSize = $dist_uniform(tstcfg_Seed,64,128);
|
537 |
|
|
`tstcfg_SizeShort : PktSize = $dist_uniform(tstcfg_Seed,128,512);
|
538 |
|
|
`tstcfg_SizeMedium : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
|
539 |
|
|
`tstcfg_SizeLarge : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
|
540 |
|
|
`tstcfg_SizeXLarge : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
|
541 |
|
|
endcase
|
542 |
|
|
|
543 |
|
|
s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=((PktSize+ExtCycles)&32'h1)?ExtCycles+1:ExtCycles;
|
544 |
|
|
s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=0;
|
545 |
|
|
//Generate Packet
|
546 |
|
|
for(Octet=0;Octet
|
547 |
|
|
begin
|
548 |
|
|
if(Octet<7)
|
549 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
|
550 |
|
|
else if(Octet==7)
|
551 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
|
552 |
|
|
else
|
553 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
|
554 |
|
|
end
|
555 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
|
556 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
|
557 |
|
|
//Transmit:
|
558 |
|
|
$display("Not complete task");
|
559 |
|
|
$display("Sender : Sending Packet %d Size %d",(tstcfg_TxPktCnt+Idx),PktSize);
|
560 |
|
|
end
|
561 |
|
|
tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
|
562 |
|
|
end
|
563 |
|
|
endtask
|
564 |
|
|
|
565 |
|
|
task tsk_TransmitErrInFrame;
|
566 |
|
|
integer PktSize;
|
567 |
|
|
integer PktNum;
|
568 |
|
|
integer PktIFG;
|
569 |
|
|
integer Idx;
|
570 |
|
|
integer Octet;
|
571 |
|
|
integer ErrorCycle;
|
572 |
|
|
integer ErrorPos;
|
573 |
|
|
begin
|
574 |
|
|
PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
|
575 |
|
|
ErrorCycle = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
|
576 |
|
|
|
577 |
|
|
for(Idx=0;Idx
|
578 |
|
|
begin
|
579 |
|
|
PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
|
580 |
|
|
tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
|
581 |
|
|
|
582 |
|
|
case(tstcfg_PktSize)
|
583 |
|
|
`tstcfg_SizeXShort : PktSize = $dist_uniform(tstcfg_Seed,64,128);
|
584 |
|
|
`tstcfg_SizeShort : PktSize = $dist_uniform(tstcfg_Seed,128,512);
|
585 |
|
|
`tstcfg_SizeMedium : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
|
586 |
|
|
`tstcfg_SizeLarge : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
|
587 |
|
|
`tstcfg_SizeXLarge : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
|
588 |
|
|
endcase
|
589 |
|
|
|
590 |
|
|
s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=(PktSize&32'h1)?1:0;
|
591 |
|
|
ErrorPos = $dist_uniform(tstcfg_Seed,1,(PktSize-ErrorCycle));
|
592 |
|
|
s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=ErrorCycle;
|
593 |
|
|
for(Octet=0;Octet
|
594 |
|
|
begin
|
595 |
|
|
if(Octet<7)
|
596 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
|
597 |
|
|
else if(Octet==7)
|
598 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
|
599 |
|
|
else
|
600 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
|
601 |
|
|
end
|
602 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
|
603 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
|
604 |
|
|
//Transmit:
|
605 |
|
|
$display("Not complete task");
|
606 |
|
|
|
607 |
|
|
$display("Sender : Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
|
608 |
|
|
end
|
609 |
|
|
tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
|
610 |
|
|
|
611 |
|
|
end
|
612 |
|
|
endtask
|
613 |
|
|
|
614 |
|
|
task tsk_TransmitErrOutFrame;
|
615 |
|
|
integer PktSize;
|
616 |
|
|
integer PktNum;
|
617 |
|
|
integer PktIFG;
|
618 |
|
|
integer Idx;
|
619 |
|
|
integer Octet;
|
620 |
|
|
integer ErrorCycle;
|
621 |
|
|
integer ErrorPos;
|
622 |
|
|
integer ExtCycles;
|
623 |
|
|
begin
|
624 |
|
|
PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
|
625 |
|
|
|
626 |
|
|
for(Idx=0;Idx
|
627 |
|
|
begin
|
628 |
|
|
ExtCycles = $dist_uniform(tstcfg_Seed,7,20);
|
629 |
|
|
ErrorCycle = $dist_uniform(tstcfg_Seed,1,3);//From 1 to 10
|
630 |
|
|
PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
|
631 |
|
|
tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
|
632 |
|
|
case(tstcfg_PktSize)
|
633 |
|
|
`tstcfg_SizeXShort : PktSize = $dist_uniform(tstcfg_Seed,64,128);
|
634 |
|
|
`tstcfg_SizeShort : PktSize = $dist_uniform(tstcfg_Seed,128,512);
|
635 |
|
|
`tstcfg_SizeMedium : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
|
636 |
|
|
`tstcfg_SizeLarge : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
|
637 |
|
|
`tstcfg_SizeXLarge : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
|
638 |
|
|
endcase
|
639 |
|
|
|
640 |
|
|
s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=((PktSize+ExtCycles)&32'h1)?(ExtCycles+1):ExtCycles;
|
641 |
|
|
ErrorPos = $dist_uniform(tstcfg_Seed,3,(ExtCycles-ErrorCycle));
|
642 |
|
|
$display("----Ext = %d, Error = %d",ExtCycles,ErrorCycle);
|
643 |
|
|
s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=ErrorCycle;
|
644 |
|
|
for(Octet=0;Octet
|
645 |
|
|
begin
|
646 |
|
|
if(Octet<7)
|
647 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
|
648 |
|
|
else if(Octet==7)
|
649 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
|
650 |
|
|
else
|
651 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
|
652 |
|
|
end
|
653 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
|
654 |
|
|
r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
|
655 |
|
|
//Transmit:
|
656 |
|
|
$display("Not complete task");
|
657 |
|
|
|
658 |
|
|
$display("Sender : Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
|
659 |
|
|
end
|
660 |
|
|
tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
|
661 |
|
|
|
662 |
|
|
end
|
663 |
|
|
endtask
|
664 |
|
|
|
665 |
|
|
|
666 |
|
|
//Informatiion
|
667 |
|
|
always@(*)
|
668 |
|
|
begin
|
669 |
|
|
if(w_u0LinkUp==1'b1) $display("Link Acquired"); else $display("Link Dropped");
|
670 |
|
|
if(w_u0ANDone==1'b1) begin
|
671 |
|
|
$display("Auto-nego completes");
|
672 |
|
|
$display("Link Speed %d Mbps",(w2_u0Speed==2'b10)?1000:100);
|
673 |
|
|
$display("Link Duplex %s ",w_u0Duplex?"Full":"Half");
|
674 |
|
|
end
|
675 |
|
|
end
|
676 |
|
|
|
677 |
|
|
reg [15:00] r16_LpAbility;
|
678 |
|
|
initial
|
679 |
|
|
begin
|
680 |
|
|
|
681 |
|
|
forever
|
682 |
|
|
begin
|
683 |
|
|
#1000;
|
684 |
|
|
u1WishboneMstr.tsk_Read(7'b00101_00,r16_LpAbility); //Enable SGMII Mode, Speed 1000Gb, Full Duplex
|
685 |
|
|
//$display("Partner Ability %x",r16_LpAbility);
|
686 |
|
|
end
|
687 |
|
|
end
|
688 |
|
|
|
689 |
|
|
endmodule
|
690 |
|
|
|
691 |
|
|
//TODO Test case Loopback
|
692 |
|
|
//TODO Test Auto Negotiation (Good)
|
693 |
|
|
//TODO Test Restart Auto Negotiation (Good)
|
694 |
|
|
//TODO Test case 1) Basic, Random size packets from 16 bytes to 10000 bytes
|
695 |
|
|
//TODO Test case 2) Carrier Extension, figure 35-6
|
696 |
|
|
//TODO Test case 3) Burst transmission, figure 35-7
|
697 |
|
|
//TODO Test case 4) Error Propagation with in aframe, figure 35-4
|
698 |
|
|
//TODO Test case 5) Error Propagation with carrier extension, figure 35-4
|