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 54

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 edn_walter
/*
2 38 edn_walter
 * gmii_tx_bfm.v
3 34 edn_walter
 *
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 54 edn_walter
    parameter        giga_mode = 1;
31 24 edn_walter
 
32
reg gmii_txclk_offset;
33
initial begin
34
               gmii_txclk_offset = 1'b0;
35
    forever #4 gmii_txclk_offset = !gmii_txclk_offset;
36
end
37
assign #2 gmii_txclk = gmii_txclk_offset;
38
 
39 37 edn_walter
integer feeder_file_tx, r_tx, s_tx;
40 24 edn_walter
integer start_addr_tx, end_addr_tx;
41
integer index_tx, num_tx;
42
reg eof_tx;
43
reg pcap_endian_tx;
44
reg [31:0] pcap_4bytes_tx;
45
reg [31:0] packet_leng_tx;
46
reg [ 7:0] packet_byte_tx;
47 54 edn_walter
 
48
generate
49
if (giga_mode) begin
50 24 edn_walter
initial
51
begin : feeder_tx
52
    gmii_txctrl   = 1'b0;
53 54 edn_walter
    gmii_txdata = 8'd0;
54 24 edn_walter
    #100;
55
    feeder_file_tx = $fopen("nic_drv_bfm/ptpdv2_tx.pcap","rb");
56
    if (feeder_file_tx == 0)
57
    begin
58
        $display("Failed to open ptpdv2_tx.pcap!");
59
        disable feeder_tx;
60
    end
61
    else
62
    begin
63
        // test pcap file endian
64
        r_tx = $fread(pcap_4bytes_tx, feeder_file_tx);
65
        pcap_endian_tx = (pcap_4bytes_tx == 32'ha1b2c3d4)? 1:0;
66 37 edn_walter
        s_tx = $fseek(feeder_file_tx, -4, 1);
67 24 edn_walter
        // skip pcap file header 24*8
68 37 edn_walter
        s_tx = $fseek(feeder_file_tx, 24, 1);
69 24 edn_walter
        // read packet content
70
        eof_tx = 0;
71
        num_tx = 0;
72
        while (!eof_tx & !$feof(feeder_file_tx))
73
        begin : fileread_loop
74
            // skip frame header (8+4)*8
75
            start_addr_tx = $ftell(feeder_file_tx);
76 37 edn_walter
            s_tx = $fseek(feeder_file_tx, 8+4, 1);
77 24 edn_walter
            // get frame length big endian 4*8
78
            r_tx = $fread(packet_leng_tx, feeder_file_tx);
79
            packet_leng_tx = pcap_endian_tx?
80
                               {packet_leng_tx[31:24], packet_leng_tx[23:16], packet_leng_tx[15: 8], packet_leng_tx[ 7: 0]}:
81
                               {packet_leng_tx[ 7: 0], packet_leng_tx[15: 8], packet_leng_tx[23:16], packet_leng_tx[31:24]};
82
            // check whether end of file
83
            if (r_tx == 0)
84
            begin
85
                eof_tx = 1;
86
                @(posedge gmii_txclk_offset);
87
                gmii_txctrl = 1'b0;
88
                gmii_txdata = 8'h00;
89
                disable fileread_loop;
90
            end
91
            // send ifg 96bit=12*8
92
            repeat (12)
93
            begin
94
                @(posedge gmii_txclk_offset)
95
                gmii_txctrl = 1'b0;
96
                gmii_txdata = 8'h00;
97
            end
98 52 edn_walter
            // send frame preamble and sfd 55555555555555d5=8*8
99
            repeat (7)
100 24 edn_walter
            begin
101
                @(posedge gmii_txclk_offset);
102
                gmii_txctrl = 1'b1;
103
                gmii_txdata = 8'h55;
104
            end
105
                @(posedge gmii_txclk_offset)
106
                gmii_txctrl = 1'b1;
107 52 edn_walter
                gmii_txdata = 8'hd5;
108 24 edn_walter
            // send frame content
109
            for (index_tx=0; index_tx<packet_leng_tx; index_tx=index_tx+1)
110
            begin
111
                r_tx = $fread(packet_byte_tx, feeder_file_tx);
112
                @(posedge gmii_txclk_offset);
113
                gmii_txctrl = 1'b1;
114
                gmii_txdata = packet_byte_tx;
115
                // check whether end of file
116
                if (r_tx == 0)
117
                begin
118
                    eof_tx = 1;
119
                    @(posedge gmii_txclk_offset);
120
                    gmii_txctrl = 1'b0;
121
                    gmii_txdata = 8'h00;
122
                    disable fileread_loop;
123
                end
124
            end
125
            end_addr_tx = $ftell(feeder_file_tx);
126
            num_tx = num_tx + 1;
127
        end
128
        $fclose(feeder_file_tx);
129
        gmii_txctrl = 1'b0;
130
        gmii_txdata = 8'h00;
131
    end
132
end
133 54 edn_walter
end
134
else begin
135
initial
136
begin : feeder_tx
137
    gmii_txctrl = 1'b0;
138
    gmii_txdata = 4'd0;
139
    #100;
140
    feeder_file_tx = $fopen("nic_drv_bfm/ptpdv2_tx.pcap","rb");
141
    if (feeder_file_tx == 0)
142
    begin
143
        $display("Failed to open ptpdv2_tx.pcap!");
144
        disable feeder_tx;
145
    end
146
    else
147
    begin
148
        // test pcap file endian
149
        r_tx = $fread(pcap_4bytes_tx, feeder_file_tx);
150
        pcap_endian_tx = (pcap_4bytes_tx == 32'ha1b2c3d4)? 1:0;
151
        s_tx = $fseek(feeder_file_tx, -4, 1);
152
        // skip pcap file header 24*8
153
        s_tx = $fseek(feeder_file_tx, 24, 1);
154
        // read packet content
155
        eof_tx = 0;
156
        num_tx = 0;
157
        while (!eof_tx & !$feof(feeder_file_tx))
158
        begin : fileread_loop
159
            // skip frame header (8+4)*8
160
            start_addr_tx = $ftell(feeder_file_tx);
161
            s_tx = $fseek(feeder_file_tx, 8+4, 1);
162
            // get frame length big endian 4*8
163
            r_tx = $fread(packet_leng_tx, feeder_file_tx);
164
            packet_leng_tx = pcap_endian_tx?
165
                               {packet_leng_tx[31:24], packet_leng_tx[23:16], packet_leng_tx[15: 8], packet_leng_tx[ 7: 0]}:
166
                               {packet_leng_tx[ 7: 0], packet_leng_tx[15: 8], packet_leng_tx[23:16], packet_leng_tx[31:24]};
167
            // check whether end of file
168
            if (r_tx == 0)
169
            begin
170
                eof_tx = 1;
171
                @(posedge gmii_txclk_offset);
172
                gmii_txctrl = 1'b0;
173
                gmii_txdata = 4'h0;
174
                @(posedge gmii_txclk_offset);
175
                gmii_txctrl = 1'b0;
176
                gmii_txdata = 4'h0;
177
                disable fileread_loop;
178
            end
179
            // send ifg 96bit=12*8
180
            repeat (12)
181
            begin
182
                @(posedge gmii_txclk_offset)
183
                gmii_txctrl = 1'b0;
184
                gmii_txdata = 4'h0;
185
                @(posedge gmii_txclk_offset)
186
                gmii_txctrl = 1'b0;
187
                gmii_txdata = 4'h0;
188
            end
189
            // send frame preamble and sfd 55555555555555d5=8*8
190
            repeat (7)
191
            begin
192
                @(posedge gmii_txclk_offset);
193
                gmii_txctrl = 1'b1;
194
                gmii_txdata = 4'h5;
195
                @(posedge gmii_txclk_offset);
196
                gmii_txctrl = 1'b1;
197
                gmii_txdata = 4'h5;
198
            end
199
                @(posedge gmii_txclk_offset)
200
                gmii_txctrl = 1'b1;
201
                gmii_txdata = 4'h5;
202
                @(posedge gmii_txclk_offset)
203
                gmii_txctrl = 1'b1;
204
                gmii_txdata = 4'hd;
205
            // send frame content
206
            for (index_tx=0; index_tx<packet_leng_tx; index_tx=index_tx+1)
207
            begin
208
                r_tx = $fread(packet_byte_tx, feeder_file_tx);
209
                @(posedge gmii_txclk_offset);
210
                gmii_txctrl = 1'b1;
211
                gmii_txdata = packet_byte_tx[3:0];
212
                @(posedge gmii_txclk_offset);
213
                gmii_txctrl = 1'b1;
214
                gmii_txdata = packet_byte_tx[7:4];
215
                // check whether end of file
216
                if (r_tx == 0)
217
                begin
218
                    eof_tx = 1;
219
                    @(posedge gmii_txclk_offset);
220
                    gmii_txctrl = 1'b0;
221
                    gmii_txdata = 4'h0;
222
                    @(posedge gmii_txclk_offset);
223
                    gmii_txctrl = 1'b0;
224
                    gmii_txdata = 4'h0;
225
                    disable fileread_loop;
226
                end
227
            end
228
            end_addr_tx = $ftell(feeder_file_tx);
229
            num_tx = num_tx + 1;
230
        end
231
        $fclose(feeder_file_tx);
232
        gmii_txctrl = 1'b0;
233
        gmii_txdata = 4'h0;
234
    end
235
end
236
end
237
endgenerate
238 24 edn_walter
 
239
endmodule

powered by: WebSVN 2.1.0

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