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 33

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

Line No. Rev Author Line
1 24 edn_walter
`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, num_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("nic_drv_bfm/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
        num_rx = 0;
47
        while (!eof_rx & !$feof(feeder_file_rx))
48
        begin : fileread_loop
49
            // skip frame header (8+4)*8
50
            start_addr_rx = $ftell(feeder_file_rx);
51
            $fseek(feeder_file_rx, 8+4, 1);
52
            // get frame length big endian 4*8
53
            r_rx = $fread(packet_leng_rx, feeder_file_rx);
54
            packet_leng_rx = pcap_endian_rx?
55
                               {packet_leng_rx[31:24], packet_leng_rx[23:16], packet_leng_rx[15: 8], packet_leng_rx[ 7: 0]}:
56
                               {packet_leng_rx[ 7: 0], packet_leng_rx[15: 8], packet_leng_rx[23:16], packet_leng_rx[31:24]};
57
            // check whether end of file
58
            if (r_rx == 0)
59
            begin
60
                eof_rx = 1;
61
                @(posedge gmii_rxclk_offset);
62
                gmii_rxctrl = 1'b0;
63
                gmii_rxdata = 8'h00;
64
                disable fileread_loop;
65
            end
66
            // send ifg 96bit=12*8
67
            repeat (12)
68
            begin
69
                @(posedge gmii_rxclk_offset)
70
                gmii_rxctrl = 1'b0;
71
                gmii_rxdata = 8'h00;
72
            end
73
            // send frame preamble and sfd 5555555d=4*8
74
            repeat (3)
75
            begin
76
                @(posedge gmii_rxclk_offset);
77
                gmii_rxctrl = 1'b1;
78
                gmii_rxdata = 8'h55;
79
            end
80
                @(posedge gmii_rxclk_offset)
81
                gmii_rxctrl = 1'b1;
82
                gmii_rxdata = 8'h5d;
83
            // send frame content
84
            for (index_rx=0; index_rx<packet_leng_rx; index_rx=index_rx+1)
85
            begin
86
                r_rx = $fread(packet_byte_rx, feeder_file_rx);
87
                @(posedge gmii_rxclk_offset);
88
                gmii_rxctrl = 1'b1;
89
                gmii_rxdata = packet_byte_rx;
90
                // check whether end of file
91
                if (r_rx == 0)
92
                begin
93
                    eof_rx = 1;
94
                    @(posedge gmii_rxclk_offset);
95
                    gmii_rxctrl = 1'b0;
96
                    gmii_rxdata = 8'h00;
97
                    disable fileread_loop;
98
                end
99
            end
100
            end_addr_rx = $ftell(feeder_file_rx);
101
            num_rx = num_rx + 1;
102
        end
103
        $fclose(feeder_file_rx);
104
        gmii_rxctrl = 1'b0;
105
        gmii_rxdata = 8'h00;
106
    end
107
end
108
 
109
 
110
endmodule

powered by: WebSVN 2.1.0

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