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

Subversion Repositories ha1588

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

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_rx_bfm
4
  (
5
    output           gmii_rxclk,
6
    output reg       gmii_rxctrl,
7
    output reg [7:0] gmii_rxdata
8
  );
9
 
10
reg gmii_rxclk_offset;
11
initial begin
12
               gmii_rxclk_offset = 1'b0;
13
    forever #4 gmii_rxclk_offset = !gmii_rxclk_offset;
14
end
15
assign #2 gmii_rxclk = gmii_rxclk_offset;
16
 
17
integer feeder_file_rx, r_rx;
18
integer start_addr_rx, end_addr_rx;
19
integer index_rx;
20
reg eof_rx;
21
reg pcap_endian_rx;
22
reg [31:0] pcap_4bytes_rx;
23
reg [31:0] packet_leng_rx;
24
reg [ 7:0] packet_byte_rx;
25
initial
26
begin : feeder_rx
27
    gmii_rxctrl   = 1'b0;
28
    gmii_rxdata = 4'd0;
29
    #100;
30
    feeder_file_rx = $fopen("ptpdv2_rx.pcap","rb");
31
    if (feeder_file_rx == 0)
32
    begin
33
        $display("Failed to open ptpdv2_rx.pcap!");
34
        disable feeder_rx;
35
    end
36
    else
37
    begin
38
        // test pcap file endian
39
        r_rx = $fread(pcap_4bytes_rx, feeder_file_rx);
40
        pcap_endian_rx = (pcap_4bytes_rx == 32'ha1b2c3d4)? 1:0;
41
        $fseek(feeder_file_rx, -4, 1);
42
        // skip pcap file header 24*8
43
        $fseek(feeder_file_rx, 24, 1);
44
        // read packet content
45
        eof_rx = 0;
46
        while (!eof_rx & !$feof(feeder_file_rx))
47
        begin : fileread_loop
48
            // skip frame header (8+4)*8
49
            start_addr_rx = $ftell(feeder_file_rx);
50
            $fseek(feeder_file_rx, 8+4, 1);
51
            // get frame length big endian 4*8
52
            r_rx = $fread(packet_leng_rx, feeder_file_rx);
53
            packet_leng_rx = pcap_endian_rx?
54
                               {packet_leng_rx[31:24], packet_leng_rx[23:16], packet_leng_rx[15: 8], packet_leng_rx[ 7: 0]}:
55
                               {packet_leng_rx[ 7: 0], packet_leng_rx[15: 8], packet_leng_rx[23:16], packet_leng_rx[31:24]};
56
            // check whether end of file
57
            if (r_rx == 0)
58
            begin
59
                eof_rx = 1;
60
                @(posedge gmii_rxclk_offset);
61
                gmii_rxctrl = 1'b0;
62
                gmii_rxdata = 8'h00;
63
                disable fileread_loop;
64
            end
65
            // send ifg 96bit=12*8
66
            repeat (12)
67
            begin
68
                @(posedge gmii_rxclk_offset)
69
                gmii_rxctrl = 1'b0;
70
                gmii_rxdata = 8'h00;
71
            end
72
            // send frame pre-amble 555555d5=4*8
73
            repeat (3)
74
            begin
75
                @(posedge gmii_rxclk_offset);
76
                gmii_rxctrl = 1'b1;
77
                gmii_rxdata = 8'h55;
78
            end
79
                @(posedge gmii_rxclk_offset)
80
                gmii_rxctrl = 1'b1;
81
                gmii_rxdata = 8'hd5;
82
            // send frame content
83
            for (index_rx=0; index_rx<packet_leng_rx; index_rx=index_rx+1)
84
            begin
85
                r_rx = $fread(packet_byte_rx, feeder_file_rx);
86
                @(posedge gmii_rxclk_offset);
87
                gmii_rxctrl = 1'b1;
88
                gmii_rxdata = packet_byte_rx;
89
                // check whether end of file
90
                if (r_rx == 0)
91
                begin
92
                    eof_rx = 1;
93
                    @(posedge gmii_rxclk_offset);
94
                    gmii_rxctrl = 1'b0;
95
                    gmii_rxdata = 8'h00;
96
                    disable fileread_loop;
97
                end
98
            end
99
            end_addr_rx = $ftell(feeder_file_rx);
100
        end
101
        $fclose(feeder_file_rx);
102
        gmii_rxctrl = 1'b0;
103
        gmii_rxdata = 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.