OpenCores

Subversion Repositories ha1588

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

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

Line No. Rev Author Line
1 34 edn_walter
/*
2
 * $gmii_tx_bfm.v
3
 *
4 37 edn_walter
 * Copyright (c) 2012, BABY&HW. All rights reserved.
5 34 edn_walter
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301  USA
20
 */
21
 
22 24 edn_walter
`timescale 1ns/1ns
23
 
24
module gmii_tx_bfm
25
  (
26
    output           gmii_txclk,
27
    output reg       gmii_txctrl,
28
    output reg [7:0] gmii_txdata
29
  );
30
 
31
reg gmii_txclk_offset;
32
initial begin
33
               gmii_txclk_offset = 1'b0;
34
    forever #4 gmii_txclk_offset = !gmii_txclk_offset;
35
end
36
assign #2 gmii_txclk = gmii_txclk_offset;
37
 
38 37 edn_walter
integer feeder_file_tx, r_tx, s_tx;
39 24 edn_walter
integer start_addr_tx, end_addr_tx;
40
integer index_tx, num_tx;
41
reg eof_tx;
42
reg pcap_endian_tx;
43
reg [31:0] pcap_4bytes_tx;
44
reg [31:0] packet_leng_tx;
45
reg [ 7:0] packet_byte_tx;
46
initial
47
begin : feeder_tx
48
    gmii_txctrl   = 1'b0;
49
    gmii_txdata = 4'd0;
50
    #100;
51
    feeder_file_tx = $fopen("nic_drv_bfm/ptpdv2_tx.pcap","rb");
52
    if (feeder_file_tx == 0)
53
    begin
54
        $display("Failed to open ptpdv2_tx.pcap!");
55
        disable feeder_tx;
56
    end
57
    else
58
    begin
59
        // test pcap file endian
60
        r_tx = $fread(pcap_4bytes_tx, feeder_file_tx);
61
        pcap_endian_tx = (pcap_4bytes_tx == 32'ha1b2c3d4)? 1:0;
62 37 edn_walter
        s_tx = $fseek(feeder_file_tx, -4, 1);
63 24 edn_walter
        // skip pcap file header 24*8
64 37 edn_walter
        s_tx = $fseek(feeder_file_tx, 24, 1);
65 24 edn_walter
        // read packet content
66
        eof_tx = 0;
67
        num_tx = 0;
68
        while (!eof_tx & !$feof(feeder_file_tx))
69
        begin : fileread_loop
70
            // skip frame header (8+4)*8
71
            start_addr_tx = $ftell(feeder_file_tx);
72 37 edn_walter
            s_tx = $fseek(feeder_file_tx, 8+4, 1);
73 24 edn_walter
            // get frame length big endian 4*8
74
            r_tx = $fread(packet_leng_tx, feeder_file_tx);
75
            packet_leng_tx = pcap_endian_tx?
76
                               {packet_leng_tx[31:24], packet_leng_tx[23:16], packet_leng_tx[15: 8], packet_leng_tx[ 7: 0]}:
77
                               {packet_leng_tx[ 7: 0], packet_leng_tx[15: 8], packet_leng_tx[23:16], packet_leng_tx[31:24]};
78
            // check whether end of file
79
            if (r_tx == 0)
80
            begin
81
                eof_tx = 1;
82
                @(posedge gmii_txclk_offset);
83
                gmii_txctrl = 1'b0;
84
                gmii_txdata = 8'h00;
85
                disable fileread_loop;
86
            end
87
            // send ifg 96bit=12*8
88
            repeat (12)
89
            begin
90
                @(posedge gmii_txclk_offset)
91
                gmii_txctrl = 1'b0;
92
                gmii_txdata = 8'h00;
93
            end
94
            // send frame preamble and sfd 5555555d=4*8
95
            repeat (3)
96
            begin
97
                @(posedge gmii_txclk_offset);
98
                gmii_txctrl = 1'b1;
99
                gmii_txdata = 8'h55;
100
            end
101
                @(posedge gmii_txclk_offset)
102
                gmii_txctrl = 1'b1;
103
                gmii_txdata = 8'h5d;
104
            // send frame content
105
            for (index_tx=0; index_tx<packet_leng_tx; index_tx=index_tx+1)
106
            begin
107
                r_tx = $fread(packet_byte_tx, feeder_file_tx);
108
                @(posedge gmii_txclk_offset);
109
                gmii_txctrl = 1'b1;
110
                gmii_txdata = packet_byte_tx;
111
                // check whether end of file
112
                if (r_tx == 0)
113
                begin
114
                    eof_tx = 1;
115
                    @(posedge gmii_txclk_offset);
116
                    gmii_txctrl = 1'b0;
117
                    gmii_txdata = 8'h00;
118
                    disable fileread_loop;
119
                end
120
            end
121
            end_addr_tx = $ftell(feeder_file_tx);
122
            num_tx = num_tx + 1;
123
        end
124
        $fclose(feeder_file_tx);
125
        gmii_txctrl = 1'b0;
126
        gmii_txdata = 8'h00;
127
    end
128
end
129
 
130
 
131
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2014 OpenCores.org, equivalent to ORSoC AB, all rights reserved. OpenCores®, registered trademark.