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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [sim/] [Testbench_AltGXB_SGMII100Mbps.sv] - Blame information for rev 11

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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