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

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [sim/] [top/] [nic_drv_bfm/] [gmii_tx_bfm.v] - Blame information for rev 33

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

Line No. Rev Author Line
1 24 edn_walter
`timescale 1ns/1ns
2
 
3
module gmii_tx_bfm
4
  (
5
    output           gmii_txclk,
6
    output reg       gmii_txctrl,
7
    output reg [7:0] gmii_txdata
8
  );
9
 
10
reg gmii_txclk_offset;
11
initial begin
12
               gmii_txclk_offset = 1'b0;
13
    forever #4 gmii_txclk_offset = !gmii_txclk_offset;
14
end
15
assign #2 gmii_txclk = gmii_txclk_offset;
16
 
17
integer feeder_file_tx, r_tx;
18
integer start_addr_tx, end_addr_tx;
19
integer index_tx, num_tx;
20
reg eof_tx;
21
reg pcap_endian_tx;
22
reg [31:0] pcap_4bytes_tx;
23
reg [31:0] packet_leng_tx;
24
reg [ 7:0] packet_byte_tx;
25
initial
26
begin : feeder_tx
27
    gmii_txctrl   = 1'b0;
28
    gmii_txdata = 4'd0;
29
    #100;
30
    feeder_file_tx = $fopen("nic_drv_bfm/ptpdv2_tx.pcap","rb");
31
    if (feeder_file_tx == 0)
32
    begin
33
        $display("Failed to open ptpdv2_tx.pcap!");
34
        disable feeder_tx;
35
    end
36
    else
37
    begin
38
        // test pcap file endian
39
        r_tx = $fread(pcap_4bytes_tx, feeder_file_tx);
40
        pcap_endian_tx = (pcap_4bytes_tx == 32'ha1b2c3d4)? 1:0;
41
        $fseek(feeder_file_tx, -4, 1);
42
        // skip pcap file header 24*8
43
        $fseek(feeder_file_tx, 24, 1);
44
        // read packet content
45
        eof_tx = 0;
46
        num_tx = 0;
47
        while (!eof_tx & !$feof(feeder_file_tx))
48
        begin : fileread_loop
49
            // skip frame header (8+4)*8
50
            start_addr_tx = $ftell(feeder_file_tx);
51
            $fseek(feeder_file_tx, 8+4, 1);
52
            // get frame length big endian 4*8
53
            r_tx = $fread(packet_leng_tx, feeder_file_tx);
54
            packet_leng_tx = pcap_endian_tx?
55
                               {packet_leng_tx[31:24], packet_leng_tx[23:16], packet_leng_tx[15: 8], packet_leng_tx[ 7: 0]}:
56
                               {packet_leng_tx[ 7: 0], packet_leng_tx[15: 8], packet_leng_tx[23:16], packet_leng_tx[31:24]};
57
            // check whether end of file
58
            if (r_tx == 0)
59
            begin
60
                eof_tx = 1;
61
                @(posedge gmii_txclk_offset);
62
                gmii_txctrl = 1'b0;
63
                gmii_txdata = 8'h00;
64
                disable fileread_loop;
65
            end
66
            // send ifg 96bit=12*8
67
            repeat (12)
68
            begin
69
                @(posedge gmii_txclk_offset)
70
                gmii_txctrl = 1'b0;
71
                gmii_txdata = 8'h00;
72
            end
73
            // send frame preamble and sfd 5555555d=4*8
74
            repeat (3)
75
            begin
76
                @(posedge gmii_txclk_offset);
77
                gmii_txctrl = 1'b1;
78
                gmii_txdata = 8'h55;
79
            end
80
                @(posedge gmii_txclk_offset)
81
                gmii_txctrl = 1'b1;
82
                gmii_txdata = 8'h5d;
83
            // send frame content
84
            for (index_tx=0; index_tx<packet_leng_tx; index_tx=index_tx+1)
85
            begin
86
                r_tx = $fread(packet_byte_tx, feeder_file_tx);
87
                @(posedge gmii_txclk_offset);
88
                gmii_txctrl = 1'b1;
89
                gmii_txdata = packet_byte_tx;
90
                // check whether end of file
91
                if (r_tx == 0)
92
                begin
93
                    eof_tx = 1;
94
                    @(posedge gmii_txclk_offset);
95
                    gmii_txctrl = 1'b0;
96
                    gmii_txdata = 8'h00;
97
                    disable fileread_loop;
98
                end
99
            end
100
            end_addr_tx = $ftell(feeder_file_tx);
101
            num_tx = num_tx + 1;
102
        end
103
        $fclose(feeder_file_tx);
104
        gmii_txctrl = 1'b0;
105
        gmii_txdata = 8'h00;
106
    end
107
end
108
 
109
 
110
endmodule

powered by: WebSVN 2.1.0

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