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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [sim/] [Testbench_AltGXB_1000BaseX.sv] - Diff between revs 9 and 15

Only display areas with differences | Details | Blame | View Log

Rev 9 Rev 15
/*
/*
Developed by Jeff Lieu (lieumychuong@gmail.com)
Developed by Jeff Lieu (lieumychuong@gmail.com)
File            :
File            :
Description     :
Description     :
        In this test, we use Altera Tranceiver as Link Partner
        In this test, we use Altera Tranceiver as Link Partner
        Configure bothside to be 1000BaseX Mode
        Configure bothside to be 1000BaseX Mode
Remarks         :
Remarks         :
        There seems to be a bug in Altera's core, tx path
        There seems to be a bug in Altera's core, tx path
        - The Tx Path sometime omits 1 pre-ample octet depending on the cycle that TxEN is aserted.
        - The Tx Path sometime omits 1 pre-ample octet depending on the cycle that TxEN is aserted.
        - At the transmit task, the #8 delay will have effect on the Altera's core. Without delay,
        - At the transmit task, the #8 delay will have effect on the Altera's core. Without delay,
                the first packet is transmitted with the first octet somehow removed (you can confirm this
                the first packet is transmitted with the first octet somehow removed (you can confirm this
                by looking at the Codegroup that is input of u0SGMII/u0Receive/
                by looking at the Codegroup that is input of u0SGMII/u0Receive/
        - With the delay on, the first packet is fine, but the second packet has some problem.
        - With the delay on, the first packet is fine, but the second packet has some problem.
        - This has something todo with the alignment of the TxEN,
        - This has something todo with the alignment of the TxEN,
                I'm not sure whether the MAC layer is responsible for aligning TxEN's assertion or not.
                I'm not sure whether the MAC layer is responsible for aligning TxEN's assertion or not.
        - This test only Transmits normal frame, i.e no Carrier Extension or Error Propagation
        - This test only Transmits normal frame, i.e no Carrier Extension or Error Propagation
        - The Path of U0 --> U1 is ok.
        - The Path of U0 --> U1 is ok.
        - Testing with Version 11.1sp2 core seems to be ok, this problem is not found
        - Testing with Version 11.1sp2 core seems to be ok, this problem is not found
Revision        :
Revision        :
        Date    Author  Description
        Date    Author  Description
*/
*/
`timescale 1ns/1ps
`timescale 1ns/1ps
`include "SGMIIDefs.v"
`include "SGMIIDefs.v"
module mSGMIITestbench();
module mSGMIITestbench();
`include "Veritil.v"
`include "Veritil.v"
reg r_Reset_L;
reg r_Reset_L;
reg r_Clk125M;
reg r_Clk125M;
reg r_Clk50M;
reg r_Clk50M;
wire                    w_u1RxClk;
wire                    w_u1RxClk;
wire                    w_u1TxClk;
wire                    w_u1TxClk;
wire                    w_u1RxDV;
wire                    w_u1RxDV;
wire                    w_u1RxER;
wire                    w_u1RxER;
wire [07:00]    w8_u1RxD;
wire [07:00]    w8_u1RxD;
wire [07:00]    w8_u1TxD;
wire [07:00]    w8_u1TxD;
wire                    w_u1TxEN;
wire                    w_u1TxEN;
wire                    w_u1TxER;
wire                    w_u1TxER;
wire                    w_u0RxDV;
wire                    w_u0RxDV;
wire                    w_u0RxER;
wire                    w_u0RxER;
wire [07:00]    w8_u0RxD;
wire [07:00]    w8_u0RxD;
wire [07:00]    w8_u0TxD;
wire [07:00]    w8_u0TxD;
wire                    w_u0TxEN;
wire                    w_u0TxEN;
wire                    w_u0TxER;
wire                    w_u0TxER;
wire w_u0WbCyc, w_u0WbAck, w_u0WbStb, w_u0WbWEn;
wire w_u0WbCyc, w_u0WbAck, w_u0WbStb, w_u0WbWEn;
wire [31:00] w32_u0WbAddr, w32_u0WbWrData, w32_u0WbRdData;
wire [31:00] w32_u0WbAddr, w32_u0WbWrData, w32_u0WbRdData;
wire w_u1WbCyc, w_u1WbAck, w_u1WbStb, w_u1WbWEn;
wire w_u1WbCyc, w_u1WbAck, w_u1WbStb, w_u1WbWEn;
wire [31:00] w32_u1WbAddr, w32_u1WbWrData, w32_u1WbRdData;
wire [31:00] w32_u1WbAddr, w32_u1WbWrData, w32_u1WbRdData;
wire w_u0ANDone,w_u1ANDone;
wire w_u0ANDone,w_u1ANDone;
`define tstcfg_Normal           0
`define tstcfg_Normal           0
`define tstcfg_CarrierExt       1
`define tstcfg_CarrierExt       1
`define tstcfg_BurstTrans       2
`define tstcfg_BurstTrans       2
`define tstcfg_ErrorProp1       3
`define tstcfg_ErrorProp1       3
`define tstcfg_ErrorProp2       4
`define tstcfg_ErrorProp2       4
`define tstcfg_SizeXShort       0
`define tstcfg_SizeXShort       0
`define tstcfg_SizeShort        1
`define tstcfg_SizeShort        1
`define tstcfg_SizeMedium       2
`define tstcfg_SizeMedium       2
`define tstcfg_SizeLarge        3
`define tstcfg_SizeLarge        3
`define tstcfg_SizeXLarge       4
`define tstcfg_SizeXLarge       4
`define tstcfg_1000X            0
`define tstcfg_1000X            0
`define tstcfg_SGMII1G          1
`define tstcfg_SGMII1G          1
`define tstcfg_SGMII100M        2
`define tstcfg_SGMII100M        2
integer tstcfg_Standard;
integer tstcfg_Standard;
integer tstcfg_PktSize;
integer tstcfg_PktSize;
integer tstcfg_Type;
integer tstcfg_Type;
integer tstcfg_Seed;
integer tstcfg_Seed;
integer tstcfg_TxPktCnt;
integer tstcfg_TxPktCnt;
integer tstcfg_RxPktCnt;
integer tstcfg_RxPktCnt;
        reg [15:00] r16_CoreVersion;
        reg [15:00] r16_CoreVersion;
        wire [01:00] w2_u0Speed;
        wire [01:00] w2_u0Speed;
        initial r_Clk125M <= 1'b0;
        initial r_Clk125M <= 1'b0;
        initial r_Clk50M <= 1'b0;
        initial r_Clk50M <= 1'b0;
        always@*
        always@*
                #4 r_Clk125M <= ~r_Clk125M;
                #4 r_Clk125M <= ~r_Clk125M;
        always@*
        always@*
                #10 r_Clk50M <= ~r_Clk50M;
                #10 r_Clk50M <= ~r_Clk50M;
        wire w_u0Rx,w_u0Tx;
        wire w_u0Rx,w_u0Tx;
        wire w_u1Rx,w_u1Tx;
        wire w_u1Rx,w_u1Tx;
                initial
                initial
                        begin
                        begin
                                $display("------------------------------------");
                                $display("------------------------------------");
                                $display("-------Subtleware Ltd Pte 2012------");
                                $display("-------Subtleware Ltd Pte 2012------");
                                $display("--Testing SGMII in 1000Gb Mode------");
                                $display("--Testing SGMII in 1000Gb Mode------");
                                $display("------------------------------------");
                                $display("------------------------------------");
                                u0WishboneMstr.tsk_Read((10<<2),r16_CoreVersion);
 
                                $display("---Core Version : %x", r16_CoreVersion);
 
                                tstcfg_TxPktCnt = 0;
                                tstcfg_TxPktCnt = 0;
                                tstcfg_RxPktCnt = 0;
                                tstcfg_RxPktCnt = 0;
                                r_Reset_L <= 1'b0;
                                r_Reset_L <= 1'b0;
                                #1000;
                                #1000;
                                r_Reset_L <= 1'b1;
                                r_Reset_L <= 1'b1;
 
                                u0WishboneMstr.tsk_Read((10<<2),r16_CoreVersion);
 
                                $display("---Core Version : %x", r16_CoreVersion);
                                tsk_Setup();
                                tsk_Setup();
                        end
                        end
        mWishboneMstr u0WishboneMstr(
        mWishboneMstr u0WishboneMstr(
        .o_WbCyc        (w_u0WbCyc),
        .o_WbCyc        (w_u0WbCyc),
        .o_WbStb        (w_u0WbStb),
        .o_WbStb        (w_u0WbStb),
        .o_WbWEn        (w_u0WbWEn),
        .o_WbWEn        (w_u0WbWEn),
        .ov_WbAddr      (w32_u0WbAddr),
        .ov_WbAddr      (w32_u0WbAddr),
        .ov_WbWrData(w32_u0WbWrData),
        .ov_WbWrData(w32_u0WbWrData),
        .iv_WbRdData(w32_u0WbRdData),
        .iv_WbRdData(w32_u0WbRdData),
        .i_Ack          (w_u0WbAck),
        .i_Ack          (w_u0WbAck),
        .i_Stall        (1'b0),
        .i_Stall        (1'b0),
        .i_Rty          (1'b0),
        .i_Rty          (1'b0),
        .i_Clk          (w_u0GMIIClk));
        .i_Clk          (w_u0GMIIClk));
        mWishboneMstr u1WishboneMstr(
        mWishboneMstr u1WishboneMstr(
        .o_WbCyc        (w_u1WbCyc),
        .o_WbCyc        (w_u1WbCyc),
        .o_WbStb        (w_u1WbStb),
        .o_WbStb        (w_u1WbStb),
        .o_WbWEn        (w_u1WbWEn),
        .o_WbWEn        (w_u1WbWEn),
        .ov_WbAddr      (w32_u1WbAddr),
        .ov_WbAddr      (w32_u1WbAddr),
        .ov_WbWrData(w32_u1WbWrData),
        .ov_WbWrData(w32_u1WbWrData),
        .iv_WbRdData(w32_u1WbRdData),
        .iv_WbRdData(w32_u1WbRdData),
        .i_Ack          (w_u1WbAck),
        .i_Ack          (w_u1WbAck),
        .i_Stall        (1'b0),
        .i_Stall        (1'b0),
        .i_Rty          (1'b0),
        .i_Rty          (1'b0),
        .i_Clk          (w_u1RxClk));
        .i_Clk          (w_u1RxClk));
        //Tranceiver Interface
        //Tranceiver Interface
        mSGMII u0SGMII (
        mSGMII u0SGMII (
        .i_SerRx                        (w_u0Rx),
        .i_SerRx                        (w_u0Rx),
        .o_SerTx                        (w_u0Tx),
        .o_SerTx                        (w_u0Tx),
        .i_CalClk                       (r_Clk50M),
        .i_CalClk                       (r_Clk50M),
        .i_RefClk125M           (r_Clk125M),
        .i_RefClk125M           (r_Clk125M),
        .i_ARstHardware_L       (r_Reset_L),
        .i_ARstHardware_L       (r_Reset_L),
        //Local BUS interface
        //Local BUS interface
        //Wishbonebus, single transaction mode (non-pipeline slave)
        //Wishbonebus, single transaction mode (non-pipeline slave)
        .i_Cyc          (w_u0WbCyc),
        .i_Cyc          (w_u0WbCyc),
        .i_Stb          (w_u0WbStb),
        .i_Stb          (w_u0WbStb),
        .i_WEn          (w_u0WbWEn),
        .i_WEn          (w_u0WbWEn),
        .i32_WrData     (w32_u0WbWrData),
        .i32_WrData     (w32_u0WbWrData),
        .iv_Addr        (w32_u0WbAddr[7:0]),
        .iv_Addr        (w32_u0WbAddr[7:0]),
        .o32_RdData     (w32_u0WbRdData),
        .o32_RdData     (w32_u0WbRdData),
        .o_Ack          (w_u0WbAck),
        .o_Ack          (w_u0WbAck),
        .i_Mdc          (1'b0),
        .i_Mdc          (1'b0),
        .io_Mdio        (),
        .io_Mdio        (),
        .i_PhyLink      (1'b1),
        .i_PhyLink      (1'b1),
        .i2_PhySpeed(2'b00),
        .i2_PhySpeed(2'b00),
        .i_PhyDuplex(1'b0),
        .i_PhyDuplex(1'b0),
        //Status
        //Status
        .o_ANDone       (w_u0ANDone),
        .o_ANDone       (w_u0ANDone),
        .o_Linkup       (w_u0LinkUp),
        .o_Linkup       (w_u0LinkUp),
        .o2_SGMIISpeed  (w2_u0Speed),
        .o2_SGMIISpeed  (w2_u0Speed),
        .o_SGMIIDuplex  (w_u0Duplex),
        .o_SGMIIDuplex  (w_u0Duplex),
        //GMII Interface
        //GMII Interface
        .i8_TxD         (w8_u0TxD),
        .i8_TxD         (w8_u0TxD),
        .i_TxEN         (w_u0TxEN),
        .i_TxEN         (w_u0TxEN),
        .i_TxER         (w_u0TxER),
        .i_TxER         (w_u0TxER),
        .o8_RxD         (w8_u0RxD),
        .o8_RxD         (w8_u0RxD),
        .o_RxDV         (w_u0RxDV),
        .o_RxDV         (w_u0RxDV),
        .o_RxER         (w_u0RxER),
        .o_RxER         (w_u0RxER),
        .o_GMIIClk      (w_u0GMIIClk),
        .o_GMIIClk      (w_u0GMIIClk),
        .o_Col          (),
        .o_Col          (),
        .o_Crs          ());
        .o_Crs          ());
        sgmii u1SGMII (
        sgmii u1SGMII (
        .gmii_rx_d              (w8_u1RxD),
        .gmii_rx_d              (w8_u1RxD),
        .gmii_rx_dv             (w_u1RxDV),
        .gmii_rx_dv             (w_u1RxDV),
        .gmii_rx_err    (w_u1RxER),
        .gmii_rx_err    (w_u1RxER),
        .gmii_tx_d              (w8_u1TxD),
        .gmii_tx_d              (w8_u1TxD),
        .gmii_tx_en             (w_u1TxEN),
        .gmii_tx_en             (w_u1TxEN),
        .gmii_tx_err    (w_u1TxER),
        .gmii_tx_err    (w_u1TxER),
        .tx_clk                 (w_u1TxClk),//output,
        .tx_clk                 (w_u1TxClk),//output,
        .rx_clk                 (w_u1RxClk),
        .rx_clk                 (w_u1RxClk),
        .led_an                 (w_u1ANDone),
        .led_an                 (w_u1ANDone),
        .led_disp_err   (),
        .led_disp_err   (),
        .led_char_err   (),
        .led_char_err   (),
        .led_link               (w_led_link),
        .led_link               (w_led_link),
        .rx_recovclkout (),
        .rx_recovclkout (),
        .rxp                            (w_u1Rx),
        .rxp                            (w_u1Rx),
        .txp                            (w_u1Tx),
        .txp                            (w_u1Tx),
        .pcs_pwrdn_out          (),
        .pcs_pwrdn_out          (),
        .reconfig_fromgxb       (),
        .reconfig_fromgxb       (),
        .reset_tx_clk   (~r_Reset_L),
        .reset_tx_clk   (~r_Reset_L),
        .reset_rx_clk   (~r_Reset_L),
        .reset_rx_clk   (~r_Reset_L),
        .readdata               (w32_u1WbRdData[15:00]),
        .readdata               (w32_u1WbRdData[15:00]),
        .waitrequest    (w_AvlWaitReq),
        .waitrequest    (w_AvlWaitReq),
        .address                (w32_u1WbAddr[6:2]),
        .address                (w32_u1WbAddr[6:2]),
        .read                   (w_AvlRd),
        .read                   (w_AvlRd),
        .writedata              (w32_u1WbWrData[15:00]),
        .writedata              (w32_u1WbWrData[15:00]),
        .write                  (w_AvlWr),
        .write                  (w_AvlWr),
        .clk                    (w_u1RxClk),
        .clk                    (w_u1RxClk),
        .reset                  (~r_Reset_L),
        .reset                  (~r_Reset_L),
        .ref_clk                        (r_Clk125M),
        .ref_clk                        (r_Clk125M),
        .gxb_pwrdn_in           (1'b0),
        .gxb_pwrdn_in           (1'b0),
        .gxb_cal_blk_clk        (r_Clk50M),
        .gxb_cal_blk_clk        (r_Clk50M),
        .reconfig_clk           (r_Clk50M),
        .reconfig_clk           (r_Clk50M),
        .reconfig_togxb         (5'b0),
        .reconfig_togxb         (5'b0),
        .reconfig_busy          ());
        .reconfig_busy          ());
        //MacEmulation
        //MacEmulation
        mMACEmulator u0MacEmulator(
        mMACEmulator u0MacEmulator(
        .i_RxClk        (w_u0GMIIClk),
        .i_RxClk        (w_u0GMIIClk),
        .i_TxClk        (w_u0GMIIClk),
        .i_TxClk        (w_u0GMIIClk),
        .i8_RxD (w8_u0RxD),
        .i8_RxD (w8_u0RxD),
        .i_RxDV (w_u0RxDV),
        .i_RxDV (w_u0RxDV),
        .i_RxER (w_u0RxER),
        .i_RxER (w_u0RxER),
        .o8_TxD (w8_u0TxD),
        .o8_TxD (w8_u0TxD),
        .o_TxEN (w_u0TxEN),
        .o_TxEN (w_u0TxEN),
        .o_TxER (w_u0TxER),
        .o_TxER (w_u0TxER),
        .i_Reset_L(r_Reset_L));
        .i_Reset_L(r_Reset_L));
         mMACEmulator u1MacEmulator(
         mMACEmulator u1MacEmulator(
        .i_RxClk        (w_u1RxClk),
        .i_RxClk        (w_u1RxClk),
        .i_TxClk        (w_u1TxClk),
        .i_TxClk        (w_u1TxClk),
        .i8_RxD (w8_u1RxD),
        .i8_RxD (w8_u1RxD),
        .i_RxDV (w_u1RxDV),
        .i_RxDV (w_u1RxDV),
        .i_RxER (w_u1RxER),
        .i_RxER (w_u1RxER),
        .o8_TxD (w8_u1TxD),
        .o8_TxD (w8_u1TxD),
        .o_TxEN (w_u1TxEN),
        .o_TxEN (w_u1TxEN),
        .o_TxER (w_u1TxER),
        .o_TxER (w_u1TxER),
        .i_Reset_L(r_Reset_L));
        .i_Reset_L(r_Reset_L));
        //This portion translate Wishbone Signal to Avalon Signal
        //This portion translate Wishbone Signal to Avalon Signal
        assign w_AvlWr = w_u1WbStb & w_u1WbCyc & w_u1WbWEn;
        assign w_AvlWr = w_u1WbStb & w_u1WbCyc & w_u1WbWEn;
        assign w_AvlRd = w_u1WbStb & w_u1WbCyc & (~w_u1WbWEn);
        assign w_AvlRd = w_u1WbStb & w_u1WbCyc & (~w_u1WbWEn);
        assign w_u1WbAck = ~w_AvlWaitReq;
        assign w_u1WbAck = ~w_AvlWaitReq;
        assign w_u0Rx = w_u1Tx;
        assign w_u0Rx = w_u1Tx;
        assign w_u1Rx = w_u0Tx;
        assign w_u1Rx = w_u0Tx;
        reg [7:0]       r8_TxBuffer[0:1023][0:10000];
        reg [7:0]       r8_TxBuffer[0:1023][0:10000];
        integer         s32_TxCarrierExtCycles[0:1023];
        integer         s32_TxCarrierExtCycles[0:1023];
        integer         s32_TxCarrierErrCycles[0:1023];
        integer         s32_TxCarrierErrCycles[0:1023];
        reg [7:0]       r8_u0RxBuffer[0:1023][0:10000];
        reg [7:0]       r8_u0RxBuffer[0:1023][0:10000];
        reg [7:0]       r8_u1RxBuffer[0:1023][0:10000];
        reg [7:0]       r8_u1RxBuffer[0:1023][0:10000];
        reg [15:00] r16_u0Ability;
        reg [15:00] r16_u0Ability;
        reg [15:00] r16_u1Ability;
        reg [15:00] r16_u1Ability;
        reg [31:00] r32_ReadData;
        reg [31:00] r32_ReadData;
        integer I;
        integer I;
        integer length;
        integer length;
        integer u0RxPktCnt,u1RxPktCnt;
        integer u0RxPktCnt,u1RxPktCnt;
        integer u0ExtCycles,u1ExtCycles;
        integer u0ExtCycles,u1ExtCycles;
        integer u0ErrCycles,u1ErrCycles;
        integer u0ErrCycles,u1ErrCycles;
        integer u0FrameSize,u1FrameSize;
        integer u0FrameSize,u1FrameSize;
        initial
        initial
                begin
                begin
                        length = 100;
                        length = 100;
                        #100;
                        #100;
                        $display("Waiting for Auto Negotiation Done");
                        $display("Waiting for Auto Negotiation Done");
                        #100;
                        #100;
                        while(w_u0ANDone==1'b0)
                        while(w_u0ANDone==1'b0)
                                begin
                                begin
                                @(posedge w_u0GMIIClk);#1;
                                @(posedge w_u0GMIIClk);#1;
                                end
                                end
                        //Verify link partner ability
                        //Verify link partner ability
                        u0WishboneMstr.tsk_Read(16'h14,r32_ReadData);
                        u0WishboneMstr.tsk_Read(16'h14,r32_ReadData);
                        `CheckE(r32_ReadData,r16_u1Ability,"Link Partner Advertised Ability")
                        `CheckE(r32_ReadData,r16_u1Ability,"Link Partner Advertised Ability")
                        u1WishboneMstr.tsk_Read(16'h14,r32_ReadData);
                        u1WishboneMstr.tsk_Read(16'h14,r32_ReadData);
                        `CheckE(r32_ReadData,r16_u0Ability,"Link Partner Advertised Ability")
                        `CheckE(r32_ReadData,r16_u0Ability,"Link Partner Advertised Ability")
                        #1000;
                        #1000;
                        $display("Start Generating Scenarios");
                        $display("Start Generating Scenarios");
                        for(I=0;I<1000;I=I+1)
                        for(I=0;I<1000;I=I+1)
                                        tsk_ScenariosGenerator();
                                        tsk_ScenariosGenerator();
                        $display("Test Result: %s (Error Count = %d)",ErrorCnt>0?"FAILED":"PASSED",ErrorCnt);
                        $display("Test Result: %s (Error Count = %d)",ErrorCnt>0?"FAILED":"PASSED",ErrorCnt);
                        #3000;
                        #3000;
                end
                end
                initial
                initial
                        begin:u1Receiving
                        begin:u1Receiving
                        u1RxPktCnt=0;
                        u1RxPktCnt=0;
                        $display("Waiting for Auto Negotiation Done");
                        $display("Waiting for Auto Negotiation Done");
                        #100;
                        #100;
                        while(w_u1ANDone==1'b0)
                        while(w_u1ANDone==1'b0)
                                begin
                                begin
                                @(posedge w_u1RxClk);#1;
                                @(posedge w_u1RxClk);#1;
                                end
                                end
                        forever
                        forever
                                begin
                                begin
                                u1MacEmulator.tsk_ReceivePkt(r8_u1RxBuffer[u1RxPktCnt],u1FrameSize,u1ExtCycles,u1ErrCycles);
                                u1MacEmulator.tsk_ReceivePkt(r8_u1RxBuffer[u1RxPktCnt],u1FrameSize,u1ExtCycles,u1ErrCycles);
                                u1FrameSize--;
                                u1FrameSize--;
                                while(u1FrameSize>=0)
                                while(u1FrameSize>=0)
                                        begin
                                        begin
                                                `CheckF(r8_u1RxBuffer[u1RxPktCnt][u1FrameSize],r8_TxBuffer[u1RxPktCnt][u1FrameSize],"Received byte")
                                                `CheckF(r8_u1RxBuffer[u1RxPktCnt][u1FrameSize],r8_TxBuffer[u1RxPktCnt][u1FrameSize],"Received byte")
                                                u1FrameSize--;
                                                u1FrameSize--;
                                        end
                                        end
                                u1RxPktCnt=u1RxPktCnt+1;
                                u1RxPktCnt=u1RxPktCnt+1;
                                $display("u1: Checked Pkt %d",u1RxPktCnt);
                                $display("u1: Checked Pkt %d",u1RxPktCnt);
                                end
                                end
                        end
                        end
                initial
                initial
                        begin:u0Receiving
                        begin:u0Receiving
                        u0RxPktCnt=0;
                        u0RxPktCnt=0;
                        $display("Waiting for Auto Negotiation Done");
                        $display("Waiting for Auto Negotiation Done");
                        #100;
                        #100;
                        while(w_u0ANDone==1'b0)
                        while(w_u0ANDone==1'b0)
                                begin
                                begin
                                @(posedge w_u0GMIIClk);#1;
                                @(posedge w_u0GMIIClk);#1;
                                end
                                end
                        forever
                        forever
                                begin
                                begin
                                u0MacEmulator.tsk_ReceivePkt(r8_u0RxBuffer[u0RxPktCnt],u0FrameSize,u0ExtCycles,u0ErrCycles);
                                u0MacEmulator.tsk_ReceivePkt(r8_u0RxBuffer[u0RxPktCnt],u0FrameSize,u0ExtCycles,u0ErrCycles);
                                u0FrameSize--;
                                u0FrameSize--;
                                while(u0FrameSize>=0)
                                while(u0FrameSize>=0)
                                        begin
                                        begin
                                                `CheckF(r8_u0RxBuffer[u0RxPktCnt][u0FrameSize],r8_TxBuffer[u0RxPktCnt][u0FrameSize],"Received byte")
                                                `CheckF(r8_u0RxBuffer[u0RxPktCnt][u0FrameSize],r8_TxBuffer[u0RxPktCnt][u0FrameSize],"Received byte")
                                                u0FrameSize--;
                                                u0FrameSize--;
                                        end
                                        end
                                u0RxPktCnt=u0RxPktCnt+1;
                                u0RxPktCnt=u0RxPktCnt+1;
                                $display("u0: Checked Pkt %d",u0RxPktCnt);
                                $display("u0: Checked Pkt %d",u0RxPktCnt);
                                end
                                end
                        end
                        end
        task tsk_Setup;
        task tsk_Setup;
                begin
                begin
                //U1 is ALTERA's
                //U1 is ALTERA's
                u1WishboneMstr.tsk_Read(7'b10001_00,r16_CoreVersion);
                u1WishboneMstr.tsk_Read(7'b10001_00,r16_CoreVersion);
                $display("Altera SGMII Core Version %x",r16_CoreVersion);
                $display("Altera SGMII Core Version %x",r16_CoreVersion);
                u1WishboneMstr.tsk_Write(0,32'h0000_1000);                                      //Enable Auto-Negotiation
                u1WishboneMstr.tsk_Write(0,32'h0000_1000);                                      //Enable Auto-Negotiation
                r16_u1Ability=16'h01E0;
                r16_u1Ability=16'h01E0;
                u1WishboneMstr.tsk_Write(7'b00100_00,r16_u1Ability);            //Set Dev Ability
                u1WishboneMstr.tsk_Write(7'b00100_00,r16_u1Ability);            //Set Dev Ability
                u1WishboneMstr.tsk_Write(7'b10010_00,32'h01E2);                         //Set Link Timer to 10000 ns
                u1WishboneMstr.tsk_Write(7'b10010_00,32'h01E2);                         //Set Link Timer to 10000 ns
                u1WishboneMstr.tsk_Write(7'b10011_00,32'h0000);
                u1WishboneMstr.tsk_Write(7'b10011_00,32'h0000);
                u1WishboneMstr.tsk_Read(7'b10010_00,r16_CoreVersion);
                u1WishboneMstr.tsk_Read(7'b10010_00,r16_CoreVersion);
                $display("Link Timer 0 %x",r16_CoreVersion);
                $display("Link Timer 0 %x",r16_CoreVersion);
                u1WishboneMstr.tsk_Read(7'b10011_00,r16_CoreVersion);
                u1WishboneMstr.tsk_Read(7'b10011_00,r16_CoreVersion);
                $display("Link Timer 1 %x",r16_CoreVersion);
                $display("Link Timer 1 %x",r16_CoreVersion);
                u1WishboneMstr.tsk_Write(7'b10100_00,{27'h0,1'b1,4'b1000});     //Enable 1000BASE-X Mode
                u1WishboneMstr.tsk_Write(7'b10100_00,{27'h0,1'b1,4'b1000});     //Enable 1000BASE-X Mode
                u1WishboneMstr.tsk_Read(7'b10100_00,r16_CoreVersion);
                u1WishboneMstr.tsk_Read(7'b10100_00,r16_CoreVersion);
                $display("Mode Register 1 %x",r16_CoreVersion);
                $display("Mode Register 1 %x",r16_CoreVersion);
                //U0 is MINE
                //U0 is MINE
                r16_u0Ability=16'h01E0;
                r16_u0Ability=16'h01E0;
                u0WishboneMstr.tsk_Write(7'b00100_00,r16_u0Ability);            //Set Dev Ability
                u0WishboneMstr.tsk_Write(7'b00100_00,r16_u0Ability);            //Set Dev Ability
                u0WishboneMstr.tsk_Write((8<<2),32'h0000_01E2);                         //Set Link Timer to 2500 ns
                u0WishboneMstr.tsk_Write((8<<2),32'h0000_01E2);                         //Set Link Timer to 2500 ns
                u0WishboneMstr.tsk_Write((9<<2),32'h0000_0000);
                u0WishboneMstr.tsk_Write((9<<2),32'h0000_0000);
                u0WishboneMstr.tsk_Write((31<<2),32'h0000);                                     //Enable 1000BASE-X
                u0WishboneMstr.tsk_Write((31<<2),32'h0000);                                     //Enable 1000BASE-X
                $display("Restart PHY auto-nego");
                $display("Restart PHY auto-nego");
                u0WishboneMstr.tsk_Write(0,32'h0000_1200);                                      //Restart Auto-negotiation
                u0WishboneMstr.tsk_Write(0,32'h0000_1200);                                      //Restart Auto-negotiation
                end
                end
        endtask
        endtask
        task tsk_ScenariosGenerator;
        task tsk_ScenariosGenerator;
                //Generate Type of Transmission
                //Generate Type of Transmission
                begin
                begin
                tstcfg_Seed = $random;
                tstcfg_Seed = $random;
                tstcfg_Type        = $dist_uniform(tstcfg_Seed,0,4);
                tstcfg_Type        = $dist_uniform(tstcfg_Seed,0,4);
                tstcfg_Type             = `tstcfg_Normal;
                tstcfg_Type             = `tstcfg_Normal;
                case(tstcfg_Type)
                case(tstcfg_Type)
                `tstcfg_Normal: begin $display("Transmit Type Normal"); tsk_TransmitNormal(); end
                `tstcfg_Normal: begin $display("Transmit Type Normal"); tsk_TransmitNormal(); end
                `tstcfg_BurstTrans: begin $display("Transmit Type Burst"); tsk_TransmitBurst(); end
                `tstcfg_BurstTrans: begin $display("Transmit Type Burst"); tsk_TransmitBurst(); end
                `tstcfg_CarrierExt: begin $display("Transmit Type Carrier Extension"); tsk_TransmitCarrExt(); end
                `tstcfg_CarrierExt: begin $display("Transmit Type Carrier Extension"); tsk_TransmitCarrExt(); end
                `tstcfg_ErrorProp1: begin $display("Transmit Type Error Prop within Frame"); tsk_TransmitErrInFrame(); end
                `tstcfg_ErrorProp1: begin $display("Transmit Type Error Prop within Frame"); tsk_TransmitErrInFrame(); end
                `tstcfg_ErrorProp2: begin $display("Transmit Type Error Prop out of Frame"); tsk_TransmitErrOutFrame();end
                `tstcfg_ErrorProp2: begin $display("Transmit Type Error Prop out of Frame"); tsk_TransmitErrOutFrame();end
                endcase
                endcase
                end
                end
        endtask
        endtask
        task tsk_TransmitNormal;
        task tsk_TransmitNormal;
                integer PktSize;
                integer PktSize;
                integer PktNum;
                integer PktNum;
                integer PktIFG;
                integer PktIFG;
                integer Idx;
                integer Idx;
                integer Octet;
                integer Octet;
        begin
        begin
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                for(Idx=0;Idx
                for(Idx=0;Idx
                begin
                begin
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
                        case(tstcfg_PktSize)
                        case(tstcfg_PktSize)
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        endcase
                        endcase
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=(PktSize&32'h1)?1:0;
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=(PktSize&32'h1)?1:0;
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=0;
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=0;
                        for(Octet=0;Octet
                        for(Octet=0;Octet
                                begin
                                begin
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
                                end
                                end
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
                        //Transmit:
                        //Transmit:
                        fork
                        fork
                                begin
                                begin
                                $display("u0: Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
                                $display("u0: Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
                                u0MacEmulator.tsk_TransmitPkt(r8_TxBuffer[tstcfg_TxPktCnt+Idx],PktSize,PktIFG);
                                u0MacEmulator.tsk_TransmitPkt(r8_TxBuffer[tstcfg_TxPktCnt+Idx],PktSize,PktIFG);
                                end
                                end
                                begin
                                begin
                                $display("u1: Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
                                $display("u1: Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
                                //#8;           //If You Remove This Delay, you will have error in first packet.
                                //#8;           //If You Remove This Delay, you will have error in first packet.
                                u1MacEmulator.tsk_TransmitPkt(r8_TxBuffer[tstcfg_TxPktCnt+Idx],PktSize,PktIFG);
                                u1MacEmulator.tsk_TransmitPkt(r8_TxBuffer[tstcfg_TxPktCnt+Idx],PktSize,PktIFG);
                                end
                                end
                        join
                        join
                end
                end
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
        end
        end
        endtask
        endtask
        task tsk_TransmitBurst;
        task tsk_TransmitBurst;
        integer PktSize;
        integer PktSize;
        integer PktNum;
        integer PktNum;
        integer PktIFG;
        integer PktIFG;
        integer Idx;
        integer Idx;
        integer Octet;
        integer Octet;
        integer ExtCycles;
        integer ExtCycles;
        integer TotalExtCycles;
        integer TotalExtCycles;
        integer TotalBytes;
        integer TotalBytes;
        integer PktStartOffset;
        integer PktStartOffset;
        begin
        begin
                PktNum = $dist_uniform(tstcfg_Seed,1,6);//From 1 to 10
                PktNum = $dist_uniform(tstcfg_Seed,1,6);//From 1 to 10
                PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                s32_TxCarrierExtCycles[tstcfg_TxPktCnt]=0;
                s32_TxCarrierExtCycles[tstcfg_TxPktCnt]=0;
                TotalBytes=0;
                TotalBytes=0;
                TotalExtCycles=0;
                TotalExtCycles=0;
                PktStartOffset=0;
                PktStartOffset=0;
                $display("Bursting : %d packets",PktNum);
                $display("Bursting : %d packets",PktNum);
                for(Idx=0;Idx
                for(Idx=0;Idx
                begin
                begin
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,3);                                //Nojumbo
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,3);                                //Nojumbo
                        ExtCycles = $dist_uniform(tstcfg_Seed,3,5);//Burst must have at least 2 /R/ interpacket R
                        ExtCycles = $dist_uniform(tstcfg_Seed,3,5);//Burst must have at least 2 /R/ interpacket R
                        case(tstcfg_PktSize)
                        case(tstcfg_PktSize)
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        endcase
                        endcase
                        TotalExtCycles=TotalExtCycles+ExtCycles;
                        TotalExtCycles=TotalExtCycles+ExtCycles;
                        TotalBytes = TotalBytes+PktSize;
                        TotalBytes = TotalBytes+PktSize;
                        //Generate Packet
                        //Generate Packet
                        for(Octet=0;Octet
                        for(Octet=0;Octet
                                begin
                                begin
                                if(Octet<7)
                                if(Octet<7)
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=8'h55;
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=8'h55;
                                else if(Octet==7)
                                else if(Octet==7)
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=8'hD5;
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=8'hD5;
                                else
                                else
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=$random;
                                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+Octet]=$random;
                                end
                                end
                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+9]=((PktSize & 32'hFF00)>>8);
                        r8_TxBuffer[tstcfg_TxPktCnt][PktStartOffset+9]=((PktSize & 32'hFF00)>>8);
                        //Transmit:
                        //Transmit:
                        $display("Not complete task");
                        $display("Not complete task");
                        $display("Sender        : Sending Packet %d (part %d) Size %d",tstcfg_TxPktCnt,Idx,PktSize);
                        $display("Sender        : Sending Packet %d (part %d) Size %d",tstcfg_TxPktCnt,Idx,PktSize);
                end
                end
                //Send Interframe Gap
                //Send Interframe Gap
                s32_TxCarrierErrCycles[tstcfg_TxPktCnt]=0;
                s32_TxCarrierErrCycles[tstcfg_TxPktCnt]=0;
                s32_TxCarrierExtCycles[tstcfg_TxPktCnt]=((TotalBytes+TotalExtCycles)&32'h1)?(TotalExtCycles+1):TotalExtCycles;
                s32_TxCarrierExtCycles[tstcfg_TxPktCnt]=((TotalBytes+TotalExtCycles)&32'h1)?(TotalExtCycles+1):TotalExtCycles;
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+1;
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+1;
        end
        end
        endtask
        endtask
        task tsk_TransmitCarrExt;
        task tsk_TransmitCarrExt;
        integer PktSize;
        integer PktSize;
        integer PktNum;
        integer PktNum;
        integer PktIFG;
        integer PktIFG;
        integer Idx;
        integer Idx;
        integer Octet;
        integer Octet;
        integer ExtCycles;
        integer ExtCycles;
        begin
        begin
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                for(Idx=0;Idx
                for(Idx=0;Idx
                begin
                begin
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
                        ExtCycles = $dist_uniform(tstcfg_Seed,1,100);//From 2 to 10
                        ExtCycles = $dist_uniform(tstcfg_Seed,1,100);//From 2 to 10
                        case(tstcfg_PktSize)
                        case(tstcfg_PktSize)
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        endcase
                        endcase
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=((PktSize+ExtCycles)&32'h1)?ExtCycles+1:ExtCycles;
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=((PktSize+ExtCycles)&32'h1)?ExtCycles+1:ExtCycles;
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=0;
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=0;
                        //Generate Packet
                        //Generate Packet
                        for(Octet=0;Octet
                        for(Octet=0;Octet
                                begin
                                begin
                                if(Octet<7)
                                if(Octet<7)
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
                                else if(Octet==7)
                                else if(Octet==7)
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
                                else
                                else
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
                                end
                                end
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
                        //Transmit:
                        //Transmit:
                        $display("Not complete task");
                        $display("Not complete task");
                        $display("Sender        : Sending Packet %d Size %d",(tstcfg_TxPktCnt+Idx),PktSize);
                        $display("Sender        : Sending Packet %d Size %d",(tstcfg_TxPktCnt+Idx),PktSize);
                end
                end
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
        end
        end
        endtask
        endtask
        task tsk_TransmitErrInFrame;
        task tsk_TransmitErrInFrame;
                integer PktSize;
                integer PktSize;
                integer PktNum;
                integer PktNum;
                integer PktIFG;
                integer PktIFG;
                integer Idx;
                integer Idx;
                integer Octet;
                integer Octet;
                integer ErrorCycle;
                integer ErrorCycle;
                integer ErrorPos;
                integer ErrorPos;
        begin
        begin
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                ErrorCycle = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                ErrorCycle = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                for(Idx=0;Idx
                for(Idx=0;Idx
                begin
                begin
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
                        case(tstcfg_PktSize)
                        case(tstcfg_PktSize)
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        endcase
                        endcase
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=(PktSize&32'h1)?1:0;
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=(PktSize&32'h1)?1:0;
                        ErrorPos = $dist_uniform(tstcfg_Seed,1,(PktSize-ErrorCycle));
                        ErrorPos = $dist_uniform(tstcfg_Seed,1,(PktSize-ErrorCycle));
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=ErrorCycle;
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=ErrorCycle;
                        for(Octet=0;Octet
                        for(Octet=0;Octet
                                begin
                                begin
                                if(Octet<7)
                                if(Octet<7)
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
                                else if(Octet==7)
                                else if(Octet==7)
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
                                else
                                else
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
                                end
                                end
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
                        //Transmit:
                        //Transmit:
                        $display("Not complete task");
                        $display("Not complete task");
                $display("Sender        : Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
                $display("Sender        : Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
                end
                end
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
        end
        end
        endtask
        endtask
        task tsk_TransmitErrOutFrame;
        task tsk_TransmitErrOutFrame;
                integer PktSize;
                integer PktSize;
                integer PktNum;
                integer PktNum;
                integer PktIFG;
                integer PktIFG;
                integer Idx;
                integer Idx;
                integer Octet;
                integer Octet;
                integer ErrorCycle;
                integer ErrorCycle;
                integer ErrorPos;
                integer ErrorPos;
                integer ExtCycles;
                integer ExtCycles;
        begin
        begin
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                PktNum = $dist_uniform(tstcfg_Seed,1,10);//From 1 to 10
                for(Idx=0;Idx
                for(Idx=0;Idx
                begin
                begin
                        ExtCycles = $dist_uniform(tstcfg_Seed,7,20);
                        ExtCycles = $dist_uniform(tstcfg_Seed,7,20);
                        ErrorCycle = $dist_uniform(tstcfg_Seed,1,3);//From 1 to 10
                        ErrorCycle = $dist_uniform(tstcfg_Seed,1,3);//From 1 to 10
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                        PktIFG = $dist_uniform(tstcfg_Seed,10,14);//From 2 to 10
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
                        tstcfg_PktSize = $dist_uniform(tstcfg_Seed,0,4);
                        case(tstcfg_PktSize)
                        case(tstcfg_PktSize)
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeXShort      : PktSize = $dist_uniform(tstcfg_Seed,64,128);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeShort       : PktSize = $dist_uniform(tstcfg_Seed,128,512);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeMedium      : PktSize = $dist_uniform(tstcfg_Seed,512,1024);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeLarge       : PktSize = $dist_uniform(tstcfg_Seed,1024,1518);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        `tstcfg_SizeXLarge      : PktSize = $dist_uniform(tstcfg_Seed,1518,9000);
                        endcase
                        endcase
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=((PktSize+ExtCycles)&32'h1)?(ExtCycles+1):ExtCycles;
                        s32_TxCarrierExtCycles[tstcfg_TxPktCnt+Idx]=((PktSize+ExtCycles)&32'h1)?(ExtCycles+1):ExtCycles;
                        ErrorPos = $dist_uniform(tstcfg_Seed,3,(ExtCycles-ErrorCycle));
                        ErrorPos = $dist_uniform(tstcfg_Seed,3,(ExtCycles-ErrorCycle));
                        $display("----Ext = %d, Error = %d",ExtCycles,ErrorCycle);
                        $display("----Ext = %d, Error = %d",ExtCycles,ErrorCycle);
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=ErrorCycle;
                        s32_TxCarrierErrCycles[tstcfg_TxPktCnt+Idx]=ErrorCycle;
                        for(Octet=0;Octet
                        for(Octet=0;Octet
                                begin
                                begin
                                if(Octet<7)
                                if(Octet<7)
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'h55;
                                else if(Octet==7)
                                else if(Octet==7)
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=8'hD5;
                                else
                                else
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
                                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][Octet]=$random;
                                end
                                end
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][8]=PktSize & 32'h00FF;
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
                        r8_TxBuffer[tstcfg_TxPktCnt+Idx][9]=((PktSize & 32'hFF00)>>8);
                        //Transmit:
                        //Transmit:
                $display("Not complete task");
                $display("Not complete task");
                $display("Sender        : Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
                $display("Sender        : Sending Packet %d Size %d",tstcfg_TxPktCnt+Idx,PktSize);
                end
                end
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
                tstcfg_TxPktCnt = tstcfg_TxPktCnt+PktNum;
        end
        end
        endtask
        endtask
        //Informatiion
        //Informatiion
        always@(*)
        always@(*)
        begin
        begin
                if(w_u0LinkUp==1'b1) $display("Link Acquired"); else $display("Link Dropped");
                if(w_u0LinkUp==1'b1) $display("Link Acquired"); else $display("Link Dropped");
                if(w_u0ANDone==1'b1) begin
                if(w_u0ANDone==1'b1) begin
                        $display("Auto-nego completes");
                        $display("Auto-nego completes");
                        $display("Link Speed %d Mbps",(w2_u0Speed==2'b10)?1000:100);
                        $display("Link Speed %d Mbps",(w2_u0Speed==2'b10)?1000:100);
                        $display("Link Duplex %s ",w_u0Duplex?"Full":"Half");
                        $display("Link Duplex %s ",w_u0Duplex?"Full":"Half");
                        end
                        end
        end
        end
        reg [15:00] r16_LpAbility;
        reg [15:00] r16_LpAbility;
        initial
        initial
                begin
                begin
                forever
                forever
                        begin
                        begin
                        #1000;
                        #1000;
                        u1WishboneMstr.tsk_Read(7'b00101_00,r16_LpAbility);             //Enable SGMII Mode, Speed 1000Gb, Full Duplex
                        u1WishboneMstr.tsk_Read(7'b00101_00,r16_LpAbility);             //Enable SGMII Mode, Speed 1000Gb, Full Duplex
                        //$display("Partner Ability %x",r16_LpAbility);
                        //$display("Partner Ability %x",r16_LpAbility);
                        end
                        end
                end
                end
endmodule
endmodule
//TODO Test case Loopback
//TODO Test case Loopback
//TODO Test Auto Negotiation                                                                                                    (Good)
//TODO Test Auto Negotiation                                                                                                    (Good)
//TODO Test Restart Auto Negotiation                                                                                    (Good)
//TODO Test Restart Auto Negotiation                                                                                    (Good)
//TODO Test case 1) Basic, Random size packets from 16 bytes to 10000 bytes
//TODO Test case 1) Basic, Random size packets from 16 bytes to 10000 bytes
//TODO Test case 2) Carrier Extension,  figure 35-6
//TODO Test case 2) Carrier Extension,  figure 35-6
//TODO Test case 3) Burst transmission, figure 35-7
//TODO Test case 3) Burst transmission, figure 35-7
//TODO Test case 4) Error Propagation with in aframe, figure 35-4
//TODO Test case 4) Error Propagation with in aframe, figure 35-4
//TODO Test case 5) Error Propagation with carrier extension, figure 35-4
//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.