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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [sim/] [Testbench_AltGXB_1000BaseX.sv] - Blame information for rev 6

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

Line No. Rev Author Line
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
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
433
                                end
434
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
435
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
436
                        //Transmit:
437
 
438
                        fork
439
                                begin
440
                                $display("u0: Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
441
                                u0MacEmulator.tsk_TransmitPkt(r8_TxBuffer[tstcfg_TxPktCnt+Idx],PktSize,PktIFG);
442
                                end
443
                                begin
444 6 jefflieu
                                $display("u1: Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
445
                                //#8;           //If You Remove This Delay, you will have error in first packet.
446
                                u1MacEmulator.tsk_TransmitPkt(r8_TxBuffer[tstcfg_TxPktCnt+Idx],PktSize,PktIFG);
447 4 jefflieu
                                end
448
                        join
449
 
450
 
451
                end
452
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
453
 
454
        end
455
        endtask
456
 
457
 
458
        task tsk_TransmitBurst;
459
        integer PktSize;
460
        integer PktNum;
461
        integer PktIFG;
462
        integer Idx;
463
        integer Octet;
464
        integer ExtCycles;
465
        integer TotalExtCycles;
466
        integer TotalBytes;
467
        integer PktStartOffset;
468
        begin
469
                PktNum = $dist_uniform(tstcfg_Seed,1,6);//From 1 to 10
470
                PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
471
                s32_TxCarrierExtCycles[tstcfg_TxPktCnt]=0;
472
                TotalBytes=0;
473
                TotalExtCycles=0;
474
                PktStartOffset=0;
475
                $display("Bursting : %d packets",PktNum);
476
                for(Idx=0;Idx
477
                begin
478
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,3);                                //Nojumbo
479
                        ExtCycles = $dist_uniform(tstcfg_Seed,3,5);//Burst must have at least 2 /R/ interpacket R
480
 
481
                        case(tstcfg_PktSize)
482
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
483
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
484
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
485
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
486
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
487
                        endcase
488
 
489
                        TotalExtCycles=TotalExtCycles+ExtCycles;
490
                        TotalBytes = TotalBytes+PktSize;
491
 
492
                        //Generate Packet
493
                        for(Octet=0;Octet
494
                                begin
495
                                if(Octet<7)
496
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=8'h55;
497
                                else if(Octet==7)
498
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=8'hD5;
499
                                else
500
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=$random;
501
                                end
502
                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+8]=PktSize & 32'h00FF;
503
                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+9]=((PktSize & 32'hFF00)>>8);
504
                        //Transmit:
505
                        $display("Not complete task");
506
                        $display("Sender        : Sending Packet %d (part %d) Size %d",tstcfg_TxPktCnt,Idx,PktSize);
507
                end
508
                //Send Interframe Gap
509
                s32_TxCarrierErrCycles[tstcfg_TxPktCnt]=0;
510
                s32_TxCarrierExtCycles[tstcfg_TxPktCnt]=((TotalBytes+TotalExtCycles)&32'h1)?(TotalExtCycles+1):TotalExtCycles;
511
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+1;
512
        end
513
        endtask
514
 
515
        task tsk_TransmitCarrExt;
516
        integer PktSize;
517
        integer PktNum;
518
        integer PktIFG;
519
        integer Idx;
520
        integer Octet;
521
        integer ExtCycles;
522
        begin
523
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
524
                for(Idx=0;Idx
525
                begin
526
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
527
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
528
                        ExtCycles = $dist_uniform(tstcfg_Seed,1,100);//From 2 to 10
529
 
530
                        case(tstcfg_PktSize)
531
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
532
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
533
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
534
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
535
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
536
                        endcase
537
 
538
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=((PktSize+ExtCycles)&32'h1)?ExtCycles+1:ExtCycles;
539
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=0;
540
                        //Generate Packet
541
                        for(Octet=0;Octet
542
                                begin
543
                                if(Octet<7)
544
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
545
                                else if(Octet==7)
546
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
547
                                else
548
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
549
                                end
550
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
551
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
552
                        //Transmit:
553
                        $display("Not complete task");
554
                        $display("Sender        : Sending Packet %d Size %d",(tstcfg_TxPktCnt+Idx),PktSize);
555
                end
556
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
557
        end
558
        endtask
559
 
560
        task tsk_TransmitErrInFrame;
561
                integer PktSize;
562
                integer PktNum;
563
                integer PktIFG;
564
                integer Idx;
565
                integer Octet;
566
                integer ErrorCycle;
567
                integer ErrorPos;
568
        begin
569
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
570
                ErrorCycle = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
571
 
572
                for(Idx=0;Idx
573
                begin
574
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
575
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
576
 
577
                        case(tstcfg_PktSize)
578
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
579
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
580
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
581
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
582
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
583
                        endcase
584
 
585
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=(PktSize&32'h1)?1:0;
586
                        ErrorPos = $dist_uniform(tstcfg_Seed,1,(PktSize-ErrorCycle));
587
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=ErrorCycle;
588
                        for(Octet=0;Octet
589
                                begin
590
                                if(Octet<7)
591
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
592
                                else if(Octet==7)
593
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
594
                                else
595
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
596
                                end
597
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
598
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
599
                        //Transmit:
600
                        $display("Not complete task");
601
 
602
                $display("Sender        : Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
603
                end
604
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
605
 
606
        end
607
        endtask
608
 
609
        task tsk_TransmitErrOutFrame;
610
                integer PktSize;
611
                integer PktNum;
612
                integer PktIFG;
613
                integer Idx;
614
                integer Octet;
615
                integer ErrorCycle;
616
                integer ErrorPos;
617
                integer ExtCycles;
618
        begin
619
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
620
 
621
                for(Idx=0;Idx
622
                begin
623
                        ExtCycles = $dist_uniform(tstcfg_Seed,7,20);
624
                        ErrorCycle = $dist_uniform(tstcfg_Seed,1,3);//From 1 to 10
625
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
626
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
627
                        case(tstcfg_PktSize)
628
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
629
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
630
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
631
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
632
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
633
                        endcase
634
 
635
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=((PktSize+ExtCycles)&32'h1)?(ExtCycles+1):ExtCycles;
636
                        ErrorPos = $dist_uniform(tstcfg_Seed,3,(ExtCycles-ErrorCycle));
637
                        $display("----Ext = %d, Error = %d",ExtCycles,ErrorCycle);
638
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=ErrorCycle;
639
                        for(Octet=0;Octet
640
                                begin
641
                                if(Octet<7)
642
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
643
                                else if(Octet==7)
644
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
645
                                else
646
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
647
                                end
648
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
649
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
650
                        //Transmit:
651
                $display("Not complete task");
652
 
653
                $display("Sender        : Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
654
                end
655
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
656
 
657
        end
658
        endtask
659
 
660
 
661
        //Informatiion
662
        always@(*)
663
        begin
664
                if(w_u0LinkUp==1'b1) $display("Link Acquired"); else $display("Link Dropped");
665
                if(w_u0ANDone==1'b1) begin
666
                        $display("Auto-nego completes");
667
                        $display("Link Speed %d Mbps",(w2_u0Speed==2'b10)?1000:100);
668
                        $display("Link Duplex %s ",w_u0Duplex?"Full":"Half");
669
                        end
670
        end
671
 
672
        reg [15:00] r16_LpAbility;
673
        initial
674
                begin
675
 
676
                forever
677
                        begin
678
                        #1000;
679
                        u1WishboneMstr.tsk_Read(7'b00101_00,r16_LpAbility);             //Enable SGMII Mode, Speed 1000Gb, Full Duplex
680
                        //$display("Partner Ability %x",r16_LpAbility);
681
                        end
682
                end
683
 
684
endmodule
685
 
686
//TODO Test case Loopback
687
//TODO Test Auto Negotiation                                                                                                    (Good)
688
//TODO Test Restart Auto Negotiation                                                                                    (Good)
689
//TODO Test case 1) Basic, Random size packets from 16 bytes to 10000 bytes
690
//TODO Test case 2) Carrier Extension,  figure 35-6
691
//TODO Test case 3) Burst transmission, figure 35-7
692
//TODO Test case 4) Error Propagation with in aframe, figure 35-4
693
//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.