OpenCores

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [sim/] [tsu/] [tsu_queue_tb.v] - Blame information for rev 43

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

Line No. Rev Author Line
1 34 edn_walter
/*
2 38 edn_walter
 * tsu_queue_tb.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 4 ash_riple
`timescale 1ns/1ns
23
 
24
module tsu_queue_tb;
25
 
26 5 ash_riple
reg         rst;
27
wire        gmii_rxclk;
28
wire        gmii_rxctrl;
29
wire [ 7:0] gmii_rxdata;
30
wire        gmii_txclk;
31
wire        gmii_txctrl;
32
wire [ 7:0] gmii_txdata;
33
reg         rtc_timer_clk;
34
reg  [79:0] rtc_timer_in;
35 37 edn_walter
reg          q_rd_clk;
36
reg          q_rd_en;
37
wire [  7:0] q_rd_stat;
38
wire [127:0] q_rd_data;
39 4 ash_riple
 
40
initial begin
41 8 edn_walter
  // emulate the hardware behavior when power-up
42 4 ash_riple
  DUT_RX.ts_ack = 1'b0;
43 13 edn_walter
  DUT_TX.ts_ack = 1'b0;
44 4 ash_riple
 
45
      rst = 1'b0;
46
  #10 rst = 1'b1;
47
  #20 rst = 1'b0;
48
end
49
 
50
initial begin
51 5 ash_riple
             q_rd_clk = 1'b0;
52
  forever #5 q_rd_clk = !q_rd_clk;
53
end
54
 
55
initial begin
56 4 ash_riple
             rtc_timer_clk = 1'b0;
57
  forever #4 rtc_timer_clk = !rtc_timer_clk;
58
end
59
 
60
initial begin
61
                                   rtc_timer_in = 80'd0;
62
  forever @(posedge rtc_timer_clk) rtc_timer_in = rtc_timer_in +1;
63
end
64
 
65 15 edn_walter
tsu DUT_RX
66 4 ash_riple
  (
67
    .rst(rst),
68
 
69
    .gmii_clk(gmii_rxclk),
70
    .gmii_ctrl(gmii_rxctrl),
71
    .gmii_data(gmii_rxdata),
72
 
73 43 edn_walter
    .ptp_msgid_mask(8'b11111111),
74
 
75 4 ash_riple
    .rtc_timer_clk(rtc_timer_clk),
76 32 edn_walter
    .rtc_timer_in(rtc_timer_in),
77 5 ash_riple
 
78
    .q_rst(rst),
79
    .q_rd_clk(q_rd_clk),
80
    .q_rd_en(q_rd_en),
81
    .q_rd_stat(q_rd_stat),
82
    .q_rd_data(q_rd_data)
83 4 ash_riple
  );
84
 
85
gmii_rx_bfm BFM_RX
86
  (
87
    .gmii_rxclk(gmii_rxclk),
88
    .gmii_rxctrl(gmii_rxctrl),
89
    .gmii_rxdata(gmii_rxdata)
90
  );
91
 
92 13 edn_walter
 
93 15 edn_walter
tsu DUT_TX
94 4 ash_riple
  (
95
    .rst(rst),
96
 
97
    .gmii_clk(gmii_txclk),
98
    .gmii_ctrl(gmii_txctrl),
99
    .gmii_data(gmii_txdata),
100
 
101 43 edn_walter
    .ptp_msgid_mask(8'b11111111),
102
 
103 4 ash_riple
    .rtc_timer_clk(rtc_timer_clk),
104 32 edn_walter
    .rtc_timer_in(rtc_timer_in),
105 5 ash_riple
 
106
    .q_rst(rst),
107
    .q_rd_clk(q_rd_clk),
108
    .q_rd_en(),
109
    .q_rd_stat(),
110
    .q_rd_data()
111 4 ash_riple
  );
112
 
113
gmii_tx_bfm BFM_TX
114
  (
115
    .gmii_txclk(gmii_txclk),
116
    .gmii_txctrl(gmii_txctrl),
117
    .gmii_txdata(gmii_txdata)
118
  );
119
 
120 36 edn_walter
integer rx_ptp_event_cnt, rx_ptp_mismatch_cnt;
121
integer ref_file_handle_rx, return_fscanf_rx, ref_num_rx;
122 35 edn_walter
initial begin
123 36 edn_walter
  rx_ptp_event_cnt = 0;
124
  rx_ptp_mismatch_cnt = 0;
125
  ref_file_handle_rx = $fopen("ptpdv2_rx.txt","r");
126 35 edn_walter
  forever @(posedge DUT_RX.q_wr_en) begin
127
    rx_ptp_event_cnt = rx_ptp_event_cnt + 1;
128 36 edn_walter
    return_fscanf_rx = $fscanf(ref_file_handle_rx, "%d", ref_num_rx);
129
    if (BFM_RX.num_rx != ref_num_rx) begin
130
      $warning("%d %d", BFM_RX.num_rx, ref_num_rx);
131
      rx_ptp_mismatch_cnt = rx_ptp_mismatch_cnt + 1;
132
    end
133 35 edn_walter
  end
134 36 edn_walter
  $fclose(ref_file_handle_rx);
135 35 edn_walter
end
136 13 edn_walter
 
137 36 edn_walter
integer tx_ptp_event_cnt, tx_ptp_mismatch_cnt;
138
integer ref_file_handle_tx, return_fscanf_tx, ref_num_tx;
139 35 edn_walter
initial begin
140 36 edn_walter
  tx_ptp_event_cnt = 0;
141
  tx_ptp_mismatch_cnt = 0;
142
  ref_file_handle_tx = $fopen("ptpdv2_tx.txt","r");
143 35 edn_walter
  forever @(posedge DUT_TX.q_wr_en) begin
144
    tx_ptp_event_cnt = tx_ptp_event_cnt + 1;
145 36 edn_walter
    return_fscanf_tx = $fscanf(ref_file_handle_tx, "%d", ref_num_tx);
146
    if (BFM_TX.num_tx != ref_num_tx) begin
147
      $warning("%d %d", BFM_TX.num_tx, ref_num_tx);
148
      tx_ptp_mismatch_cnt = tx_ptp_mismatch_cnt + 1;
149
    end
150 35 edn_walter
  end
151 36 edn_walter
  $fclose(ref_file_handle_tx);
152 35 edn_walter
end
153
 
154 36 edn_walter
initial begin
155
  fork
156
    @(posedge BFM_RX.eof_rx);
157
    @(posedge BFM_TX.eof_tx);
158
  join
159
 
160
  if (rx_ptp_event_cnt == 0)
161
    $display("RX Parser Test Fail: found 0 PTP-EVENT!");
162
 
163
  if (tx_ptp_event_cnt == 0)
164
    $display("TX Parser Test Fail: found 0 PTP-EVENT!");
165
 
166
  if      (rx_ptp_mismatch_cnt > 0)
167
    $display("Rx Parser Mismatch Found: RX-PTP-EVENT-MISMATCH = %d", rx_ptp_mismatch_cnt);
168
  else if (tx_ptp_mismatch_cnt > 0)
169
    $display("Tx Parser Mismatch Found: TX-PTP-EVENT-MISMATCH = %d", tx_ptp_mismatch_cnt);
170
  else
171
    $display("RX and TX Parser Test Pass:\n RX-PTP-EVENT = %d\n TX-PTP-EVENT = %d", rx_ptp_event_cnt, tx_ptp_event_cnt);
172
 
173
  #100 $stop;
174
end
175
 
176 4 ash_riple
endmodule
177
 

powered by: WebSVN 2.1.0

© copyright 1999-2014 OpenCores.org, equivalent to ORSoC AB, all rights reserved. OpenCores®, registered trademark.