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

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [sim/] [top/] [nic_drv_bfm/] [gmii_rx_bfm.v] - Blame information for rev 67

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

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

powered by: WebSVN 2.1.0

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