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

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [sim/] [tsu/] [gmii_tx_bfm.v] - Blame information for rev 11

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

Line No. Rev Author Line
1 4 ash_riple
`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;
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("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
        while (!eof_tx & !$feof(feeder_file_tx))
47
        begin : fileread_loop
48
            // skip frame header (8+4)*8
49
            start_addr_tx = $ftell(feeder_file_tx);
50
            $fseek(feeder_file_tx, 8+4, 1);
51
            // get frame length big endian 4*8
52
            r_tx = $fread(packet_leng_tx, feeder_file_tx);
53
            packet_leng_tx = pcap_endian_tx?
54
                               {packet_leng_tx[31:24], packet_leng_tx[23:16], packet_leng_tx[15: 8], packet_leng_tx[ 7: 0]}:
55
                               {packet_leng_tx[ 7: 0], packet_leng_tx[15: 8], packet_leng_tx[23:16], packet_leng_tx[31:24]};
56
            // check whether end of file
57
            if (r_tx == 0)
58
            begin
59
                eof_tx = 1;
60
                @(posedge gmii_txclk_offset);
61
                gmii_txctrl = 1'b0;
62
                gmii_txdata = 8'h00;
63
                disable fileread_loop;
64
            end
65
            // send ifg 96bit=12*8
66
            repeat (12)
67
            begin
68
                @(posedge gmii_txclk_offset)
69
                gmii_txctrl = 1'b0;
70
                gmii_txdata = 8'h00;
71
            end
72
            // send frame pre-amble 555555d5=4*8
73
            repeat (3)
74
            begin
75
                @(posedge gmii_txclk_offset);
76
                gmii_txctrl = 1'b1;
77
                gmii_txdata = 8'h55;
78
            end
79
                @(posedge gmii_txclk_offset)
80
                gmii_txctrl = 1'b1;
81
                gmii_txdata = 8'hd5;
82
            // send frame content
83
            for (index_tx=0; index_tx<packet_leng_tx; index_tx=index_tx+1)
84
            begin
85
                r_tx = $fread(packet_byte_tx, feeder_file_tx);
86
                @(posedge gmii_txclk_offset);
87
                gmii_txctrl = 1'b1;
88
                gmii_txdata = packet_byte_tx;
89
                // check whether end of file
90
                if (r_tx == 0)
91
                begin
92
                    eof_tx = 1;
93
                    @(posedge gmii_txclk_offset);
94
                    gmii_txctrl = 1'b0;
95
                    gmii_txdata = 8'h00;
96
                    disable fileread_loop;
97
                end
98
            end
99
            end_addr_tx = $ftell(feeder_file_tx);
100
        end
101
        $fclose(feeder_file_tx);
102
        gmii_txctrl = 1'b0;
103
        gmii_txdata = 8'h00;
104
    end
105
    #100 $stop;
106
end
107
 
108
 
109
endmodule

powered by: WebSVN 2.1.0

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