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

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [sim/] [tsu/] [gmii_rx_bfm.v] - Blame information for rev 34

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

Line No. Rev Author Line
1 34 edn_walter
/*
2
 * $gmii_rx_bfm.v
3
 *
4
 * Copyright (c) 2012, BBY&HW. All rights reserved.
5
 *
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 4 ash_riple
`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
 
31
reg gmii_rxclk_offset;
32
initial begin
33
               gmii_rxclk_offset = 1'b0;
34
    forever #4 gmii_rxclk_offset = !gmii_rxclk_offset;
35
end
36
assign #2 gmii_rxclk = gmii_rxclk_offset;
37
 
38
integer feeder_file_rx, r_rx;
39
integer start_addr_rx, end_addr_rx;
40 13 edn_walter
integer index_rx, num_rx;
41 4 ash_riple
reg eof_rx;
42
reg pcap_endian_rx;
43
reg [31:0] pcap_4bytes_rx;
44
reg [31:0] packet_leng_rx;
45
reg [ 7:0] packet_byte_rx;
46
initial
47
begin : feeder_rx
48 13 edn_walter
    gmii_rxctrl = 1'b0;
49 4 ash_riple
    gmii_rxdata = 4'd0;
50
    #100;
51
    feeder_file_rx = $fopen("ptpdv2_rx.pcap","rb");
52
    if (feeder_file_rx == 0)
53
    begin
54
        $display("Failed to open ptpdv2_rx.pcap!");
55
        disable feeder_rx;
56
    end
57
    else
58
    begin
59
        // test pcap file endian
60
        r_rx = $fread(pcap_4bytes_rx, feeder_file_rx);
61
        pcap_endian_rx = (pcap_4bytes_rx == 32'ha1b2c3d4)? 1:0;
62
        $fseek(feeder_file_rx, -4, 1);
63
        // skip pcap file header 24*8
64
        $fseek(feeder_file_rx, 24, 1);
65
        // read packet content
66
        eof_rx = 0;
67 13 edn_walter
        num_rx = 0;
68 4 ash_riple
        while (!eof_rx & !$feof(feeder_file_rx))
69
        begin : fileread_loop
70
            // skip frame header (8+4)*8
71
            start_addr_rx = $ftell(feeder_file_rx);
72
            $fseek(feeder_file_rx, 8+4, 1);
73
            // get frame length big endian 4*8
74
            r_rx = $fread(packet_leng_rx, feeder_file_rx);
75
            packet_leng_rx = pcap_endian_rx?
76
                               {packet_leng_rx[31:24], packet_leng_rx[23:16], packet_leng_rx[15: 8], packet_leng_rx[ 7: 0]}:
77
                               {packet_leng_rx[ 7: 0], packet_leng_rx[15: 8], packet_leng_rx[23:16], packet_leng_rx[31:24]};
78
            // check whether end of file
79
            if (r_rx == 0)
80
            begin
81
                eof_rx = 1;
82
                @(posedge gmii_rxclk_offset);
83
                gmii_rxctrl = 1'b0;
84
                gmii_rxdata = 8'h00;
85
                disable fileread_loop;
86
            end
87
            // send ifg 96bit=12*8
88
            repeat (12)
89
            begin
90
                @(posedge gmii_rxclk_offset)
91
                gmii_rxctrl = 1'b0;
92
                gmii_rxdata = 8'h00;
93
            end
94 13 edn_walter
            // send frame preamble and sfd 5555555d=4*8
95 4 ash_riple
            repeat (3)
96
            begin
97
                @(posedge gmii_rxclk_offset);
98
                gmii_rxctrl = 1'b1;
99
                gmii_rxdata = 8'h55;
100
            end
101
                @(posedge gmii_rxclk_offset)
102
                gmii_rxctrl = 1'b1;
103 13 edn_walter
                gmii_rxdata = 8'h5d;
104 4 ash_riple
            // send frame content
105
            for (index_rx=0; index_rx<packet_leng_rx; index_rx=index_rx+1)
106
            begin
107
                r_rx = $fread(packet_byte_rx, feeder_file_rx);
108
                @(posedge gmii_rxclk_offset);
109
                gmii_rxctrl = 1'b1;
110
                gmii_rxdata = packet_byte_rx;
111
                // check whether end of file
112
                if (r_rx == 0)
113
                begin
114
                    eof_rx = 1;
115
                    @(posedge gmii_rxclk_offset);
116
                    gmii_rxctrl = 1'b0;
117
                    gmii_rxdata = 8'h00;
118
                    disable fileread_loop;
119
                end
120
            end
121
            end_addr_rx = $ftell(feeder_file_rx);
122 13 edn_walter
            num_rx = num_rx + 1;
123 4 ash_riple
        end
124
        $fclose(feeder_file_rx);
125
        gmii_rxctrl = 1'b0;
126
        gmii_rxdata = 8'h00;
127
    end
128
end
129
 
130
 
131
endmodule

powered by: WebSVN 2.1.0

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